Solved Having trouble comparing 2 different variable, one from block and one from config

Discussion in 'Plugin Development' started by harvmaster, Jul 28, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    harvmaster

    Hi I have been making a custom enchants plugin and a dungeon plugin linked together and I am having trouble with an if statement to check if both coordinates from the chest and the config are equal to eachother.

    Code:
    public class DungeonChests implements Listener {
       
        public static HashMap<String, Integer> DungeonsOnCooldown = new HashMap<String, Integer>();
       
        @EventHandler
        public void DungeonChestEvent(PlayerInteractEvent event) {
           
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                Block block = (Block) event.getClickedBlock();
                if (block.getType() == Material.CHEST){
                   
                    //CustomEnchants.plugin.reloadConfig();
                    event.getPlayer().sendMessage(ChatColor.GREEN + "You got this far - Hasnt checked config");
                    String theChestName = ((Chest)block.getState()).getBlockInventory().getTitle();
                    event.getPlayer().sendMessage(theChestName);
               
                    if (CustomEnchants.plugin.getConfig().getConfigurationSection("dungeons." + theChestName) != null) {
                       
                       
                        int _ChestX = CustomEnchants.plugin.getConfig().getInt("dungeon." + theChestName + ".x");
                        int _ChestY = CustomEnchants.plugin.getConfig().getInt("dungeon." + theChestName + ".y");
                        int _ChestZ = CustomEnchants.plugin.getConfig().getInt("dungeon." + theChestName + ".z");
                        double chestX = block.getLocation().getX();
                        double chestY = block.getLocation().getX();
                        double chestZ = block.getLocation().getX();
                       
                        event.getPlayer().sendMessage(ChatColor.GREEN + "You got this far - checking if the chest's coords are right");
                       
                        if ((int)chestX == _ChestX && (int) chestY == _ChestY && (int) chestZ == _ChestZ) {
                           
                            if (DungeonsOnCooldown.containsKey(theChestName)) {
                                event.getPlayer().sendMessage(ChatColor.DARK_RED + "Sorry, but this chest has already been looted today");
                            } else {
                               
                                Bukkit.broadcastMessage(ChatColor.GOLD + "#########################################");
                                Bukkit.broadcastMessage(ChatColor.GOLD + "#                                       #");
                                Bukkit.broadcastMessage(ChatColor.GOLD + "#" + event.getPlayer().getName() + " has congured the " + theChestName);
                                Bukkit.broadcastMessage(ChatColor.GOLD + "#                                       #");
                                Bukkit.broadcastMessage(ChatColor.GOLD + "#########################################");
                               
                                DungeonsOnCooldown.put(theChestName, 2);
                               
                               
                               
                            }
                        }
                    }
                }
            }
        }
    }
    Any help and or advice for making the code better is much appreciated,
    Thanks in advanced, Harvmaster
     
  2. @harvmaster
    if (CustomEnchants.plugin.getConfig().getConfigurationSection("dungeons." + theChestName) != null)
    int _ChestX = CustomEnchants.plugin.getConfig().getInt("dungeon." + theChestName + ".x");
     
  3. Offline

    harvmaster

    @megamichiel Thanks you for that, I had been trying to figure this out for ages.

    P.s. I was looking at what you wrote for ages just trying to figure out what you were talking about, but I eventually worked it out xD
     
Thread Status:
Not open for further replies.

Share This Page