Skip to content

Commit

Permalink
Fix firework spawning (#6764)
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus authored Jun 15, 2024
1 parent 2627c95 commit c6b0bfa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
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) {
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"

0 comments on commit c6b0bfa

Please sign in to comment.