diff --git a/src/main/java/com/mcstaralliance/informdearplayer/InformDearPlayer.java b/src/main/java/com/mcstaralliance/informdearplayer/InformDearPlayer.java index a961190..cdb9e0a 100644 --- a/src/main/java/com/mcstaralliance/informdearplayer/InformDearPlayer.java +++ b/src/main/java/com/mcstaralliance/informdearplayer/InformDearPlayer.java @@ -1,10 +1,13 @@ package com.mcstaralliance.informdearplayer; +import com.mcstaralliance.informdearplayer.listener.PlayerInteractListener; import com.mcstaralliance.informdearplayer.task.CheckRunnable; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; public final class InformDearPlayer extends JavaPlugin { private static InformDearPlayer instance; + @Override public void onEnable() { instance = this; @@ -12,10 +15,11 @@ public void onEnable() { CheckRunnable checkRunnable = new CheckRunnable(); long interval = getConfig().getLong("resource-world-alert.interval"); checkRunnable.runTaskTimer(getInstance(), 5L, interval); + Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), getInstance()); } - public static InformDearPlayer getInstance(){ + public static InformDearPlayer getInstance() { return instance; } } diff --git a/src/main/java/com/mcstaralliance/informdearplayer/listener/PlayerInteractListener.java b/src/main/java/com/mcstaralliance/informdearplayer/listener/PlayerInteractListener.java new file mode 100644 index 0000000..0e30eea --- /dev/null +++ b/src/main/java/com/mcstaralliance/informdearplayer/listener/PlayerInteractListener.java @@ -0,0 +1,28 @@ +package com.mcstaralliance.informdearplayer.listener; + +import com.mcstaralliance.informdearplayer.InformDearPlayer; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; + +public class PlayerInteractListener implements Listener { + FileConfiguration config = InformDearPlayer.getInstance().getConfig(); + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (event.getMaterial() == Material.WOOD_HOE) { + String message = config.getString("resource-world-alert.message"); + player.sendMessage(colorize(message)); + } + } + + + public String colorize(String str) { + return ChatColor.translateAlternateColorCodes('&', str); + } +} diff --git a/src/main/java/com/mcstaralliance/informdearplayer/task/CheckRunnable.java b/src/main/java/com/mcstaralliance/informdearplayer/task/CheckRunnable.java index 1de0636..29016ef 100644 --- a/src/main/java/com/mcstaralliance/informdearplayer/task/CheckRunnable.java +++ b/src/main/java/com/mcstaralliance/informdearplayer/task/CheckRunnable.java @@ -15,14 +15,14 @@ public class CheckRunnable extends BukkitRunnable { @Override public void run() { - informInResourceWord(); + informInResourceWorld(); } public List getOnlinePlayers() { return new ArrayList<>(Bukkit.getOnlinePlayers()); } - public void informInResourceWord() { + public void informInResourceWorld() { for (Player player : getOnlinePlayers()) { String worldName = config.getString("resource-world-alert.world-name"); String message = config.getString("resource-world-alert.message");