Consider the summon command as plugin spawning

This commit is contained in:
Joo200 2023-05-31 13:26:05 +02:00
parent 44d0735412
commit 4a26e306b6
2 changed files with 16 additions and 1 deletions

View File

@ -603,7 +603,7 @@ public class WorldGuardEntityListener extends AbstractListener {
WorldConfiguration wcfg = getWorldConfig(event.getEntity().getWorld());
// allow spawning of creatures from plugins
if (!wcfg.blockPluginSpawning && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM) {
if (!wcfg.blockPluginSpawning && Entities.isPluginSpawning(event.getSpawnReason())) {
return;
}

View File

@ -44,6 +44,7 @@ import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.projectiles.ProjectileSource;
@ -230,4 +231,18 @@ public final class Entities {
public static boolean isAoECloud(EntityType type) {
return type == EntityType.AREA_EFFECT_CLOUD;
}
/**
* Check whether the spawn reason should be considered as a "plugin spawning".
* This is true for custom creations or the summon command.
*
* @param spawnReason the reason
* @return true if considerd plugin spawning
*/
public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReason) {
return switch (spawnReason) {
case CUSTOM, COMMAND -> true;
default -> false;
};
}
}