Compare commits

..
7 Commits
Author SHA1 Message Date
auto 9d39e4cc7a Add GiveSpawner command and enhance spawner functionalities
Implemented the GiveSpawner command to allow players to receive specific mob spawners. Added validation and namespaced key handling for mob types and entities to ensure proper functionality when placing spawners. Refactored existing code to use the new EntityTypeChecker utility.
2024-10-19 19:10:37 +02:00
auto 8d804c95ba Fix incorrect attribute modification calculation
Correct the calculation of the value to be added to an attribute. Adjusted the logging statement to reflect the new calculation method, ensuring accurate debug information.
2024-10-19 00:10:23 +02:00
auto 85bafe43a8 Fix incorrect attribute modification calculation
Correct the calculation of the value to be added to an attribute. Adjusted the logging statement to reflect the new calculation method, ensuring accurate debug information.
2024-10-19 00:08:34 +02:00
auto 54fa8c2f81 Fix incorrect attribute modification calculation
Correct the calculation of the value to be added to an attribute. Adjusted the logging statement to reflect the new calculation method, ensuring accurate debug information.
2024-10-19 00:06:34 +02:00
auto 7704d75960 Update debug log message in EntityAttributeModifier
Changed the debug log message to reflect the addition operation for attributes, providing clearer information during debugging and better tracing of value changes.
2024-10-19 00:02:20 +02:00
auto 2c3174d24f Fix retrieving attribute from config
The code now uses String.format for constructing attribute and value keys in configuration sections. This change improves readability and maintainability of the code. It ensures consistency in the construction of these strings.
2024-10-18 23:58:21 +02:00
auto c8cb2309f6 Rename and enhance AttributeModifier
Renamed AttributeModifier to EntityAttributeModifier for clarity. Added Main dependency and improved attribute setting logic with namespaced keys for better error handling and debugging. Updated MobTypes to pass Main instance accordingly.
2024-10-18 22:59:47 +02:00
10 changed files with 294 additions and 68 deletions
+12 -7
View File
@@ -6,6 +6,7 @@ import com.alttd.custommobs.config.Messages;
import com.alttd.custommobs.config.MobTypes; import com.alttd.custommobs.config.MobTypes;
import com.alttd.custommobs.listeners.SpawnerListener; import com.alttd.custommobs.listeners.SpawnerListener;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@Slf4j @Slf4j
@@ -15,22 +16,26 @@ public class Main extends JavaPlugin {
public void onEnable() { public void onEnable() {
log.info("Plugin enabled!"); log.info("Plugin enabled!");
reloadConfigs(); reloadConfigs();
registerEvents();
registerCommands(); NamespacedKey mobTypeKey = new NamespacedKey(this, "mob-type");
NamespacedKey entityKey = new NamespacedKey(this, "entity-type");
registerEvents(mobTypeKey, entityKey);
registerCommands(mobTypeKey, entityKey);
} }
private void registerCommands() { private void registerCommands(NamespacedKey mobTypeKey, NamespacedKey entityKey) {
new CommandManager(this); new CommandManager(this, mobTypeKey, entityKey);
} }
private void registerEvents() { private void registerEvents(NamespacedKey mobTypeKey, NamespacedKey entityKey) {
getServer().getPluginManager().registerEvents(new SpawnerListener(this), this); getServer().getPluginManager().registerEvents(new SpawnerListener(this, mobTypeKey, entityKey), this);
} }
public void reloadConfigs() { public void reloadConfigs() {
Config.reload(); Config.reload();
Messages.reload(); Messages.reload();
MobTypes.reload(); MobTypes.reload(this);
} }
@Override @Override
@@ -1,34 +0,0 @@
package com.alttd.custommobs.abilities.modifiers;
import com.alttd.custommobs.abilities.EntityModifier;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.LivingEntity;
@Slf4j
public class AttributeModifier implements EntityModifier {
private final double value;
private final Attribute attribute;
public AttributeModifier(Attribute attribute, double value) {
this.value = value;
this.attribute = attribute;
}
@Override
public void apply(LivingEntity entity) {
AttributeInstance attributeInstance = entity.getAttribute(attribute);
if (attributeInstance == null) {
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
return;
}
attributeInstance.setBaseValue(value);
}
@Override
public String getName() {
return attribute.name();
}
}
@@ -0,0 +1,49 @@
package com.alttd.custommobs.abilities.modifiers;
import com.alttd.custommobs.Main;
import com.alttd.custommobs.abilities.EntityModifier;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.entity.LivingEntity;
@Slf4j
public class EntityAttributeModifier implements EntityModifier {
private final double value;
private final Attribute attribute;
private final Main main;
public EntityAttributeModifier(Main main, Attribute attribute, double value) {
this.main = main;
this.value = value;
this.attribute = attribute;
}
@Override
public void apply(LivingEntity entity) {
AttributeInstance attributeInstance = entity.getAttribute(attribute);
if (attributeInstance == null) {
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
return;
}
double add = value - attributeInstance.getValue();
log.info("DEBUG: Adding {} to attribute {}", add, attribute.name());
NamespacedKey namespacedKey = NamespacedKey.fromString("cm", main);
if (namespacedKey == null) {
log.error("Namespaced key was null when applying attribute modifier");
return;
}
AttributeModifier attributeModifier = new AttributeModifier(namespacedKey,
add,
AttributeModifier.Operation.ADD_NUMBER);
attributeInstance.addModifier(attributeModifier);
}
@Override
public String getName() {
return attribute.name();
}
}
@@ -1,10 +1,12 @@
package com.alttd.custommobs.commands; package com.alttd.custommobs.commands;
import com.alttd.custommobs.Main; import com.alttd.custommobs.Main;
import com.alttd.custommobs.commands.subcommands.GiveSpawner;
import com.alttd.custommobs.commands.subcommands.Spawn; import com.alttd.custommobs.commands.subcommands.Spawn;
import com.alttd.custommobs.config.Messages; import com.alttd.custommobs.config.Messages;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.bukkit.NamespacedKey;
import org.bukkit.command.*; import org.bukkit.command.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -19,7 +21,7 @@ import java.util.stream.Collectors;
public class CommandManager implements CommandExecutor, TabExecutor { public class CommandManager implements CommandExecutor, TabExecutor {
private final List<SubCommand> subCommands; private final List<SubCommand> subCommands;
public CommandManager(Main main) { public CommandManager(Main main, @NotNull NamespacedKey mobTypeKey, @NotNull NamespacedKey entityKey) {
PluginCommand command = main.getCommand("custommobs"); PluginCommand command = main.getCommand("custommobs");
if (command == null) { if (command == null) {
subCommands = null; subCommands = null;
@@ -31,7 +33,8 @@ public class CommandManager implements CommandExecutor, TabExecutor {
command.setAliases(List.of("cm")); command.setAliases(List.of("cm"));
subCommands = Arrays.asList( subCommands = Arrays.asList(
new Spawn(main) new Spawn(main),
new GiveSpawner(main, mobTypeKey, entityKey)
); );
} }
@@ -0,0 +1,105 @@
package com.alttd.custommobs.commands.subcommands;
import com.alttd.custommobs.Main;
import com.alttd.custommobs.abilities.MobType;
import com.alttd.custommobs.commands.SubCommand;
import com.alttd.custommobs.config.Messages;
import com.alttd.custommobs.config.MobTypes;
import com.alttd.custommobs.utility.EntityTypeChecker;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@Slf4j
public class GiveSpawner extends SubCommand {
private final Main main;
private final NamespacedKey mobTypeKey;
private final NamespacedKey entityKey;
public GiveSpawner(Main main, @NotNull NamespacedKey mobTypeKey, @NotNull NamespacedKey entityKey) {
this.main = main;
this.mobTypeKey = mobTypeKey;
this.entityKey = entityKey;
}
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
if (!(commandSender instanceof Player player)) {
commandSender.sendRichMessage(Messages.GENERIC.PLAYER_ONLY);
return true;
}
if (args.length != 3) {
return false;
}
Optional<MobType> optionalMobType = MobTypes.MOB_TYPES.get(args[1]);
if (optionalMobType.isEmpty()) {
return false;
}
try {
EntityType entityType = EntityType.valueOf(args[2]);
if (!entityType.isSpawnable() || !EntityTypeChecker.isMob(entityType)) {
return false;
}
} catch (IllegalArgumentException e) {
log.info("DEBUG: Invalid mob type {}", args[2]);
return false;
}
ItemStack spawner = new ItemStack(Material.SPAWNER);
ItemMeta meta = spawner.getItemMeta();
meta.displayName(MiniMessage.miniMessage().deserialize(Messages.GIVE_SPAWNER.SPAWNER_NAME, TagResolver.resolver(
Placeholder.parsed("entity", args[2]),
Placeholder.parsed("mob_type", args[1])
)));
PersistentDataContainer persistentDataContainer = meta.getPersistentDataContainer();
persistentDataContainer.set(mobTypeKey, PersistentDataType.STRING, args[1]);
persistentDataContainer.set(entityKey, PersistentDataType.STRING, args[2]);
spawner.setItemMeta(meta);
if (!player.getInventory().addItem(spawner).isEmpty()) {
player.sendRichMessage(Messages.GIVE_SPAWNER.FULL_INVENTORY);
return true;
}
player.sendRichMessage(Messages.GIVE_SPAWNER.GIVEN, TagResolver.resolver(
Placeholder.parsed("entity", args[2]),
Placeholder.parsed("mob_type", args[1])
));
return true;
}
@Override
public String getName() {
return "give_spawner";
}
@Override
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
return switch (args.length) {
case 2 -> MobTypes.MOB_TYPES.getAllMobTypes();
case 3 -> Arrays.stream(EntityType.values()).map(EntityType::name).toList();
default -> List.of();
};
}
@Override
public String getHelpMessage() {
return Messages.HELP.GIVE_SPAWNER;
}
}
@@ -6,6 +6,7 @@ import com.alttd.custommobs.abilities.MobTypeApplier;
import com.alttd.custommobs.commands.SubCommand; import com.alttd.custommobs.commands.SubCommand;
import com.alttd.custommobs.config.Messages; import com.alttd.custommobs.config.Messages;
import com.alttd.custommobs.config.MobTypes; import com.alttd.custommobs.config.MobTypes;
import com.alttd.custommobs.utility.EntityTypeChecker;
import com.alttd.custommobs.utility.SpawnableTargetBlock; import com.alttd.custommobs.utility.SpawnableTargetBlock;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -46,7 +47,7 @@ public class Spawn extends SubCommand {
log.info("DEBUG: Invalid mob type {}", args[2]); log.info("DEBUG: Invalid mob type {}", args[2]);
return false; return false;
} }
if (!entityType.isSpawnable() || !isMob(entityType)) { if (!entityType.isSpawnable() || !EntityTypeChecker.isMob(entityType)) {
return false; return false;
} }
@@ -87,22 +88,6 @@ public class Spawn extends SubCommand {
} }
} }
public boolean isMob(EntityType entityType) {
if (entityType == null) {
return false;
}
try {
Class<? extends Entity> entityClass = entityType.getEntityClass();
if (entityClass == null) {
return false;
}
Class<?> mobEntityClass = Class.forName("org.bukkit.entity." + entityClass.getSimpleName());
return Mob.class.isAssignableFrom(mobEntityClass);
} catch (ClassNotFoundException e) {
return false;
}
}
private void spawnMob(World world, Location location, EntityType entityType, MobType mobType) { private void spawnMob(World world, Location location, EntityType entityType, MobType mobType) {
if (entityType.getEntityClass() == null) { if (entityType.getEntityClass() == null) {
log.warn("Tried to spawn entity with null entity class {}", entityType.name()); log.warn("Tried to spawn entity with null entity class {}", entityType.name());
@@ -1,6 +1,7 @@
package com.alttd.custommobs.config; package com.alttd.custommobs.config;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
@@ -29,12 +30,14 @@ public class Messages extends AbstractConfig {
public static String HELP_MESSAGE_WRAPPER = "<gold>Main help:\n<commands></gold>"; public static String HELP_MESSAGE_WRAPPER = "<gold>Main help:\n<commands></gold>";
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/cm help</gold></green>"; public static String HELP_MESSAGE = "<green>Show this menu: <gold>/cm help</gold></green>";
public static String SPAWN = "<green>Spawn a mob of a specific type: <gold>/cm spawn <mob_type> <mob> [<world> <x> <y> <z>]</gold></green>"; public static String SPAWN = "<green>Spawn a mob of a specific type: <gold>/cm spawn <mob_type> <mob> [<world> <x> <y> <z>]</gold></green>";
public static String GIVE_SPAWNER = "<green>Give a mob spawner for a mob of a specific type: <gold>/cm givespawner <mob_type> <mob></green>";
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static void load() { private static void load() {
HELP_MESSAGE_WRAPPER = config.getString(prefix, "help-wrapper", HELP_MESSAGE_WRAPPER); HELP_MESSAGE_WRAPPER = config.getString(prefix, "help-wrapper", HELP_MESSAGE_WRAPPER);
HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE); HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE);
SPAWN = config.getString(prefix, "spawn", SPAWN); SPAWN = config.getString(prefix, "spawn", SPAWN);
GIVE_SPAWNER = config.getString(prefix, "give-spawner", GIVE_SPAWNER);
} }
} }
@@ -52,4 +55,31 @@ public class Messages extends AbstractConfig {
PLAYER_NOT_FOUND = config.getString(prefix, "player-only", PLAYER_NOT_FOUND); PLAYER_NOT_FOUND = config.getString(prefix, "player-only", PLAYER_NOT_FOUND);
} }
} }
public static class GIVE_SPAWNER {
private static final String prefix = "give-spawner.";
public static String FULL_INVENTORY = "<red>You inventory is full so the spawner was not given</red>";
public static String GIVEN = "<green>You have been given a <entity> spawner for type <mob_type></green>";
public static String SPAWNER_NAME = "<gold><entity> <mob_type> spawner</gold>";
@SuppressWarnings("unused")
private static void load() {
FULL_INVENTORY = config.getString(prefix, "full-inventory", FULL_INVENTORY);
GIVEN = config.getString(prefix, "given", GIVEN);
SPAWNER_NAME = config.getString(prefix, "spawner-name", SPAWNER_NAME);
}
}
public static class PLACE_SPAWNER {
private static final String prefix = "place-spawner.";
public static String INVALID_MOB_TYPE = "<red>This spawner has an invalid mob type (<mob-type>)</red>";
public static String INVALID_ENTITY_TYPE = "<red>This spawner has an invalid entity type (<entity-type>)</red>";
@SuppressWarnings("unused")
private static void load() {
INVALID_MOB_TYPE = config.getString(prefix, "invalid-mob-type", INVALID_MOB_TYPE);
INVALID_ENTITY_TYPE = config.getString(prefix, "invalid-entity-type", INVALID_ENTITY_TYPE);
}
}
} }
@@ -1,7 +1,8 @@
package com.alttd.custommobs.config; package com.alttd.custommobs.config;
import com.alttd.custommobs.Main;
import com.alttd.custommobs.abilities.Ability; import com.alttd.custommobs.abilities.Ability;
import com.alttd.custommobs.abilities.modifiers.AttributeModifier; import com.alttd.custommobs.abilities.modifiers.EntityAttributeModifier;
import com.alttd.custommobs.abilities.EntityModifier; import com.alttd.custommobs.abilities.EntityModifier;
import com.alttd.custommobs.abilities.MobType; import com.alttd.custommobs.abilities.MobType;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
@@ -16,19 +17,21 @@ import java.util.*;
@Slf4j @Slf4j
public class MobTypes extends AbstractConfig { public class MobTypes extends AbstractConfig {
static MobTypes config; static MobTypes config;
private final Main main;
MobTypes() { MobTypes(Main main) {
super( super(
new File(File.separator new File(File.separator
+ "mnt" + File.separator + "mnt" + File.separator
+ "configs" + File.separator + "configs" + File.separator
+ "custommobs"), + "custommobs"),
"mob-types.yml"); "mob-types.yml");
this.main = main;
} }
public static void reload() { public static void reload(Main main) {
log.info("Reloading mob types"); log.info("Reloading mob types");
config = new MobTypes(); config = new MobTypes(main);
config.readConfig(MobTypes.class, null); config.readConfig(MobTypes.class, null);
} }
@@ -64,11 +67,11 @@ public class MobTypes extends AbstractConfig {
.toList(); .toList();
List<EntityModifier> entityModifiers = new ArrayList<>(); List<EntityModifier> entityModifiers = new ArrayList<>();
config.getConfigurationSection(prefix + key + ".modifiers").getKeys(false).forEach(modifier -> { config.getConfigurationSection(prefix + key + ".modifiers").getKeys(false).forEach(modifier -> {
String attribute = config.getString(prefix + key + ".modifiers." + modifier, "attribute", null); String attribute = config.getString(String.format("%s%s.modifiers.%s.", prefix, key, modifier), "attribute", null);
if (attribute == null) { if (attribute == null) {
return; return;
} }
EntityModifier value = getAttribute(attribute, config.getDouble(prefix + key + ".modifiers." + modifier, "value", 1)); EntityModifier value = getAttribute(attribute, config.getDouble(String.format("%s%s.modifiers.%s.", prefix, key, modifier), "value", 1));
if (value == null) if (value == null)
return; return;
entityModifiers.add(value); entityModifiers.add(value);
@@ -80,7 +83,7 @@ public class MobTypes extends AbstractConfig {
private static EntityModifier getAttribute(String attributeName, double value) { private static EntityModifier getAttribute(String attributeName, double value) {
try { try {
Attribute attribute = Attribute.valueOf(attributeName); Attribute attribute = Attribute.valueOf(attributeName);
return new AttributeModifier(attribute, value); return new EntityAttributeModifier(config.main, attribute, value);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
log.error("Invalid attribute {}", attributeName, e); log.error("Invalid attribute {}", attributeName, e);
return null; return null;
@@ -3,14 +3,26 @@ package com.alttd.custommobs.listeners;
import com.alttd.custommobs.Main; import com.alttd.custommobs.Main;
import com.alttd.custommobs.abilities.MobType; import com.alttd.custommobs.abilities.MobType;
import com.alttd.custommobs.abilities.MobTypeApplier; import com.alttd.custommobs.abilities.MobTypeApplier;
import com.alttd.custommobs.config.Messages;
import com.alttd.custommobs.config.MobTypes; import com.alttd.custommobs.config.MobTypes;
import com.alttd.custommobs.utility.EntityTypeChecker;
import io.papermc.paper.persistence.PersistentDataContainerView;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Sign;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -19,9 +31,13 @@ import java.util.Optional;
public class SpawnerListener implements Listener { public class SpawnerListener implements Listener {
private final MobTypeApplier mobTypeApplier; private final MobTypeApplier mobTypeApplier;
private final NamespacedKey mobTypeKey;
private final NamespacedKey entityKey;
public SpawnerListener(Main main) { public SpawnerListener(Main main, @NotNull NamespacedKey mobTypeKey, @NotNull NamespacedKey entityKey) {
mobTypeApplier = new MobTypeApplier(main); mobTypeApplier = new MobTypeApplier(main);
this.mobTypeKey = mobTypeKey;
this.entityKey = entityKey;
} }
@EventHandler @EventHandler
@@ -48,4 +64,44 @@ public class SpawnerListener implements Listener {
mobTypeApplier.apply(livingEntity, mobType); mobTypeApplier.apply(livingEntity, mobType);
} }
@EventHandler
public void onSpawnerPlace(BlockPlaceEvent event) {
ItemStack itemInHand = event.getItemInHand();
if (!itemInHand.getType().equals(org.bukkit.Material.SPAWNER)) {
return;
}
PersistentDataContainerView persistentDataContainer = itemInHand.getPersistentDataContainer();
if (!persistentDataContainer.has(mobTypeKey) || !persistentDataContainer.has(entityKey)) {
return;
}
String mobType = persistentDataContainer.get(mobTypeKey, PersistentDataType.STRING);
String entityTypeName = persistentDataContainer.get(entityKey, PersistentDataType.STRING);
if (mobType == null || entityTypeName == null) {
return;
}
Optional<MobType> optionalMobType = MobTypes.MOB_TYPES.get(mobType);
if (optionalMobType.isEmpty()) {
event.getPlayer().sendRichMessage(Messages.PLACE_SPAWNER.INVALID_MOB_TYPE, Placeholder.parsed("mob-type", mobType));
return;
}
EntityType entityType;
try {
entityType = EntityType.valueOf(entityTypeName);
if (!entityType.isSpawnable() || !EntityTypeChecker.isMob(entityType)) {
event.getPlayer().sendRichMessage(Messages.PLACE_SPAWNER.INVALID_ENTITY_TYPE, Placeholder.parsed("entity-type", entityTypeName));
return;
}
} catch (IllegalArgumentException e) {
log.info("DEBUG: Invalid mob type {}", entityTypeName);
return;
}
if (event.getBlock().getState() instanceof CreatureSpawner spawner) {
spawner.setSpawnedType(entityType);
} else {
log.info("Actual bock state {}", event.getBlock().getState().getClass().getName());
}
}
} }
@@ -0,0 +1,24 @@
package com.alttd.custommobs.utility;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Mob;
public class EntityTypeChecker {
public static boolean isMob(EntityType entityType) {
if (entityType == null) {
return false;
}
try {
Class<? extends Entity> entityClass = entityType.getEntityClass();
if (entityClass == null) {
return false;
}
Class<?> mobEntityClass = Class.forName("org.bukkit.entity." + entityClass.getSimpleName());
return Mob.class.isAssignableFrom(mobEntityClass);
} catch (ClassNotFoundException e) {
return false;
}
}
}