diff --git a/src/main/java/com/selfcoders/talkingmobs/EventListener.java b/src/main/java/com/selfcoders/talkingmobs/EventListener.java index 93ef528..9920fa8 100644 --- a/src/main/java/com/selfcoders/talkingmobs/EventListener.java +++ b/src/main/java/com/selfcoders/talkingmobs/EventListener.java @@ -10,19 +10,23 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; +import java.util.List; + /** * Class providing all event listeners required for the plugin */ class EventListener implements Listener { private final Message message; + private final TalkingMobs plugin; /** * Constructor of the class * * @param messageInstance The instance of the Message class */ - EventListener(Message messageInstance) { + EventListener(Message messageInstance, TalkingMobs pluginInstance) { message = messageInstance; + plugin = pluginInstance; } @EventHandler @@ -30,13 +34,19 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { Entity entity = event.getEntity(); CreatureSpawnEvent.SpawnReason spawnReason = event.getSpawnReason(); - if (spawnReason == CreatureSpawnEvent.SpawnReason.SPAWNER || spawnReason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG || spawnReason == CreatureSpawnEvent.SpawnReason.CUSTOM) { + List allowedSpawnReasons = plugin.getConfig().getStringList("events.spawned"); + + if (allowedSpawnReasons.contains(spawnReason.name())) { message.sendMessage(entity, Message.EventType.spawned); } } @EventHandler public void onEntityAttacked(EntityDamageByEntityEvent event) { + if (!plugin.getConfig().getBoolean("events.attacked")) { + return; + } + Entity damager = event.getDamager(); Entity entity = event.getEntity(); @@ -47,6 +57,10 @@ public void onEntityAttacked(EntityDamageByEntityEvent event) { @EventHandler public void onEntityKilled(EntityDeathEvent event) { + if (!plugin.getConfig().getBoolean("events.killed")) { + return; + } + LivingEntity entity = event.getEntity(); Player killer = entity.getKiller(); @@ -57,6 +71,10 @@ public void onEntityKilled(EntityDeathEvent event) { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (!plugin.getConfig().getBoolean("events.interacted")) { + return; + } + message.sendMessage(event.getRightClicked(), event.getPlayer(), Message.EventType.interacted); } } \ No newline at end of file diff --git a/src/main/java/com/selfcoders/talkingmobs/TalkingMobs.java b/src/main/java/com/selfcoders/talkingmobs/TalkingMobs.java index 62a7a58..03af1a5 100644 --- a/src/main/java/com/selfcoders/talkingmobs/TalkingMobs.java +++ b/src/main/java/com/selfcoders/talkingmobs/TalkingMobs.java @@ -20,7 +20,7 @@ public void onEnable() { saveConfig(); PluginManager pluginManager = getServer().getPluginManager(); - pluginManager.registerEvents(new EventListener(message), this); + pluginManager.registerEvents(new EventListener(message, this), this); } @Override diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b4cf0f9..986fbd6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,6 +2,18 @@ # Only players in this range to the talking mob will see the message maxDistance: 0 +# Define which events should show messages +# Everything except for "spawned" is a boolean (true or false). +# The "spawned" event expects a list of spawn reasons (see https://jd.bukkit.org/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html for possible spawn reasons). +events: + attacked: true + interacted: true + killed: true + spawned: + - CUSTOM + - SPAWNER + - SPAWNER_EGG + # How to format the messages # %mobname% is replaced with the name of the talking mob # %message% is replaced with the message