diff --git a/src/main/java/com/gmail/nossr50/McMMO.java b/src/main/java/com/gmail/nossr50/McMMO.java index ed394c5ae..6bddc25e6 100644 --- a/src/main/java/com/gmail/nossr50/McMMO.java +++ b/src/main/java/com/gmail/nossr50/McMMO.java @@ -86,8 +86,8 @@ public class McMMO extends JavaPlugin { private final WorldListener worldListener = new WorldListener(); private final HardcoreListener hardcoreListener = new HardcoreListener(); - public HashMap aliasMap = new HashMap(); //Alias - Command - public HashMap tntTracker = new HashMap(); + private HashMap aliasMap = new HashMap(); //Alias - Command + private HashMap tntTracker = new HashMap(); public static File versionFile; public static Database database; @@ -425,4 +425,63 @@ public class McMMO extends JavaPlugin { getCommand("mchud").setExecutor(new MchudCommand(this)); } + + /** + * Checks to see if the alias map contains the given key. + * + * @param command The command to check + * @return true if the command is in the map, false otherwise + */ + public boolean commandIsAliased(String command) { + return aliasMap.containsKey(command); + } + + /** + * Get the alias of a given command. + * + * @param command The command to retrieve the alias of + * @return the alias of the command + */ + public String getCommandAlias(String command) { + return aliasMap.get(command); + } + + /** + * Add a set of values to the TNT tracker. + * + * @param tntID The EntityID of the TNT + * @param playerName The name of the detonating player + */ + public void addToTNTTracker(int tntID, String playerName) { + tntTracker.put(tntID, playerName); + } + + /** + * Check to see if a given TNT Entity is tracked. + * + * @param tntID The EntityID of the TNT + * @return true if the TNT is being tracked, false otherwise + */ + public boolean tntIsTracked(int tntID) { + return tntTracker.containsKey(tntID); + } + + /** + * Get the player who detonated the TNT. + * + * @param tntID The EntityID of the TNT + * @return the Player who detonated it + */ + public Player getTNTPlayer(int tntID) { + return getServer().getPlayer(tntTracker.get(tntID)); + } + + /** + * Remove TNT from the tracker after it explodes. + * + * @param tntID The EntityID of the TNT + */ + public void removeFromTNTTracker(int tntID) { + tntTracker.remove(tntID); + } } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 7a301b2db..1ac2cc5c3 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -188,8 +188,8 @@ public class EntityListener implements Listener { if (entity instanceof TNTPrimed) { int id = entity.getEntityId(); - if (plugin.tntTracker.containsKey(id)) { - Player player = plugin.tntTracker.get(id); + if (plugin.tntIsTracked(id)) { + Player player = plugin.getTNTPlayer(id); if (Permissions.getInstance().biggerBombs(player)) { BlastMining.biggerBombs(player, event); @@ -210,10 +210,10 @@ public class EntityListener implements Listener { if (event.getEntity() instanceof TNTPrimed) { int id = entity.getEntityId(); - if (plugin.tntTracker.containsKey(id)) { - Player player = plugin.tntTracker.get(id); + if (plugin.tntIsTracked(id)) { + Player player = plugin.getTNTPlayer(id); BlastMining.dropProcessing(player, event); - plugin.tntTracker.remove(id); + plugin.removeFromTNTTracker(id); } } } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 395ef93a1..ea4217885 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -373,13 +373,13 @@ public class PlayerListener implements Listener { String command = message.substring(1).split(" ")[0]; String lowerCaseCommand = command.toLowerCase(); - if (plugin.aliasMap.containsKey(lowerCaseCommand)) { + if (plugin.commandIsAliased(lowerCaseCommand)) { //We should find a better way to avoid string replacement where the alias is equals to the command - if (command.equals(plugin.aliasMap.get(lowerCaseCommand))) { + if (command.equals(plugin.getCommandAlias(lowerCaseCommand))) { return; } - event.setMessage(message.replace(command, plugin.aliasMap.get(lowerCaseCommand))); + event.setMessage(message.replace(command, plugin.getCommandAlias(lowerCaseCommand))); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java index 25c47f96a..eb761dbb0 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java @@ -296,7 +296,7 @@ public class BlastMining { /* Create the TNT entity */ TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class); - plugin.tntTracker.put(tnt.getEntityId(), player); + plugin.addToTNTTracker(tnt.getEntityId(), player.getName()); tnt.setFuseTicks(0); /* Disable the original one */