Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix firework spawning #6764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/main/java/ch/njol/skript/entity/SimpleEntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.ArrayList;
import java.util.List;

import ch.njol.util.Kleenean;
import org.bukkit.World;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Allay;
import org.bukkit.entity.Animals;
Expand Down Expand Up @@ -155,15 +157,13 @@ public final static class SimpleEntityDataInfo {
final String codeName;
final Class<? extends Entity> c;
final boolean isSupertype;
final Kleenean allowSpawning;

SimpleEntityDataInfo(final String codeName, final Class<? extends Entity> c) {
this(codeName, c, false);
}

SimpleEntityDataInfo(final String codeName, final Class<? extends Entity> c, final boolean isSupertype) {
SimpleEntityDataInfo(String codeName, Class<? extends Entity> c, boolean isSupertype, Kleenean allowSpawning) {
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
this.codeName = codeName;
this.c = c;
this.isSupertype = isSupertype;
this.allowSpawning = allowSpawning;
}

@Override
Expand Down Expand Up @@ -191,11 +191,18 @@ public boolean equals(final @Nullable Object obj) {
private final static List<SimpleEntityDataInfo> types = new ArrayList<>();

private static void addSimpleEntity(String codeName, Class<? extends Entity> entityClass) {
types.add(new SimpleEntityDataInfo(codeName, entityClass));
addSimpleEntity(codeName, entityClass, Kleenean.UNKNOWN);
}

/**
* @param allowSpawning Whether to override the default {@link #canSpawn(World)} behavior and allow this entity to be spawned.
*/
private static void addSimpleEntity(String codeName, Class<? extends Entity> entityClass, Kleenean allowSpawning) {
types.add(new SimpleEntityDataInfo(codeName, entityClass, false, allowSpawning));
}

private static void addSuperEntity(String codeName, Class<? extends Entity> entityClass) {
types.add(new SimpleEntityDataInfo(codeName, entityClass, true));
types.add(new SimpleEntityDataInfo(codeName, entityClass, true, Kleenean.UNKNOWN));
}
static {
// Simple Entities
Expand Down Expand Up @@ -238,7 +245,9 @@ private static void addSuperEntity(String codeName, Class<? extends Entity> enti
addSimpleEntity("witch", Witch.class);
addSimpleEntity("wither", Wither.class);
addSimpleEntity("wither skull", WitherSkull.class);
addSimpleEntity("firework", Firework.class);
// bukkit marks fireworks as not spawnable
// see https://hub.spigotmc.org/jira/browse/SPIGOT-7677
addSimpleEntity("firework", Firework.class, Kleenean.TRUE);
addSimpleEntity("endermite", Endermite.class);
addSimpleEntity("armor stand", ArmorStand.class);
addSimpleEntity("shulker", Shulker.class);
Expand Down Expand Up @@ -449,7 +458,16 @@ protected boolean equals_i(final EntityData<?> obj) {
final SimpleEntityData other = (SimpleEntityData) obj;
return info.equals(other.info);
}


@Override
public boolean canSpawn(@Nullable World world) {
if (info.allowSpawning.isUnknown()) // unspecified, refer to default behavior
return super.canSpawn(world);
if (world == null)
return false;
return info.allowSpawning.isTrue();
}

@Override
public Fields serialize() throws NotSerializableException {
final Fields f = super.serialize();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test "can't spawn a firework":

spawn a firework at spawn of world "world"
assert last spawned firework is set with "firework did not spawn"