Solved PlayerInteractEvent Is checking for OP - I didn't tell it to?

Discussion in 'Plugin Development' started by ImaTimelord7, May 1, 2015.

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

    ImaTimelord7

    I am trying to change the way a furnace works for a larger project. However, this piece of code only works when a player is OP? And when a player is not OP nothing happens. I have no idea why its doing this, it shouldn't check for OP as I am not telling it to.. Any help is great. Thanks in advance.
    Code:
    @EventHandler
        public void OpenSmeltingGUI(PlayerInteractEvent e) { // GUI Open
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getClickedBlock().getType() == Material.FURNACE) {
                    e.setCancelled(true);
                    SmeltingGUI(e.getPlayer());
                }
            }
        }
     
  2. Offline

    HungerCraftNL

    Any other plugins that you are using on your server?
     
  3. Offline

    ImaTimelord7

    @HungerCraftNL Just checked again, but nope, just this one plugin on my test server.
    Also, there is no other PlayerInteractEvent's in the plugin.
     
  4. Offline

    BrickBoy55

  5. Offline

    ImaTimelord7

    Sure, here are the 3 GUI methods:
    Code:
    @EventHandler
        public void OpenSmeltingGUI(PlayerInteractEvent e) { // GUI Open
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getClickedBlock().getType() == Material.FURNACE) {
                    e.setCancelled(true);
                    SmeltingGUI(e.getPlayer());
                }
            }
        }
       
        private void SmeltingGUI(Player player) { // Smelting GUI
            Inventory inv = Bukkit.createInventory(null,  9, "Smelting.");
           
            ItemStack Item3 = new ItemStack(Material.REDSTONE);
            ItemMeta Item3Meta = Item3.getItemMeta();
            Item3Meta.setDisplayName(ChatColor.WHITE + "Bronze Ingot");
            Item3.setItemMeta(Item3Meta);
            ItemStack Item4 = new ItemStack(Material.IRON_INGOT);
            ItemMeta Item4Meta = Item4.getItemMeta();
            Item4Meta.setDisplayName(ChatColor.WHITE + "Iron Ingot");
            Item4.setItemMeta(Item4Meta);
            ItemStack Item5 = new ItemStack(Material.GHAST_TEAR);
            ItemMeta Item5Meta = Item5.getItemMeta();
            Item5Meta.setDisplayName(ChatColor.WHITE + "Steel Ingot");
            Item5.setItemMeta(Item5Meta);
            ItemStack Item6 = new ItemStack(Material.GOLD_INGOT);
            ItemMeta Item6Meta = Item6.getItemMeta();
            Item6Meta.setDisplayName(ChatColor.WHITE + "Gold Ingot");
            Item6.setItemMeta(Item6Meta);       
            ItemStack Item7 = new ItemStack(Material.QUARTZ);
            ItemMeta Item7Meta = Item7.getItemMeta();
            Item7Meta.setDisplayName(ChatColor.WHITE + "Cobalt Ingot");
            Item7.setItemMeta(Item7Meta);
           
            inv.setItem(0, Item3);
            inv.setItem(1, Item4);
            inv.setItem(2, Item5);
            inv.setItem(3, Item6);
            inv.setItem(4, Item7);
           
            player.openInventory(inv);
        }
       
        @EventHandler
        public void InventoryClick(InventoryClickEvent e) { // Smelting GUI Click
            Player p = (Player) e.getWhoClicked();
            PlayerInventory inv = p.getInventory();
            String name = e.getCurrentItem().getItemMeta().getDisplayName();
           
            if(e.getInventory().getTitle().contains("Smelting.")) {
                e.setCancelled(true);
           
                if (name.contains(ChatColor.WHITE + "Bronze Ingot")) {
                    p.closeInventory();
                    if (inv.contains(Material.REDSTONE_ORE) && inv.contains(Material.LAPIS_ORE)) {
                        p.sendMessage(ChatColor.WHITE + "You put some copper and tin ore into the furnace...");
                        inv.all(Material.REDSTONE_ORE).remove(1);
                        inv.all(Material.LAPIS_ORE).remove(1);
                        inv.addItem(BronzeIngot());
                    }else{ p.sendMessage("You need both copper and tin ore to smelt bronze!"); }
                   
                }else if (name.contains(ChatColor.WHITE + "Iron Ingot")) {
                    p.closeInventory();
                    if (inv.contains(Material.IRON_ORE)) {
                        p.sendMessage(ChatColor.WHITE + "You put some iron ore into the furnace...");
                        inv.all(Material.IRON_ORE).remove(1);
                        inv.addItem(IronIngot());
                    }else{ p.sendMessage("You don't have any iron ore!"); }
                   
                }else if (name.contains(ChatColor.WHITE + "Steel Ingot")) {
                    p.closeInventory();
                    if (inv.contains(Material.IRON_ORE) && inv.contains(Material.COAL)) {
                        p.sendMessage(ChatColor.WHITE + "You put some coal and iron ore into the furnace...");
                        inv.all(Material.IRON_ORE).remove(1);
                        inv.all(Material.COAL).remove(1);
                        inv.addItem(SteelIngot());
                    }else{ p.sendMessage("You need both iron ore and coal to smelt Steel!"); }
                   
                }else if (name.contains(ChatColor.WHITE + "Gold Ingot")) {
                    p.closeInventory();
                    if (inv.contains(Material.GOLD_ORE)) {
                        p.sendMessage(ChatColor.WHITE + "You put some gold ore into the furnace...");
                        inv.all(Material.GOLD_ORE).remove(1);
                        inv.addItem(GoldIngot());
                    }else{ p.sendMessage("You don't have any gold ore!"); }
                   
                }else if (name.contains(ChatColor.WHITE + "Cobalt Ingot")) {
                    p.closeInventory();
                    if (inv.contains(Material.QUARTZ_ORE)) {
                        p.sendMessage(ChatColor.WHITE + "You put some cobalt ore into the furnace...");
                        inv.all(Material.QUARTZ_ORE).remove(1);
                        inv.addItem(CobaltIngot());
                    }else{ p.sendMessage("You don't have any cobalt ore!"); }
                }
            }
        }
     
  6. What you could do is debug a litte place some sendMessage and see where it cuts off
     
  7. Offline

    BrickBoy55

    @ImaTimelord7

    Sorry, no idea. I thought maybe one of the methods would have a check, but I guess not.
     
  8. Offline

    ImaTimelord7

    @megamichiel
    Code:
    @EventHandler
        public void OpenSmeltingGUI(PlayerInteractEvent e) { // GUI Open
            Player p = e.getPlayer();
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                p.sendMessage("1");
                if (e.getClickedBlock().getType() == Material.FURNACE) {
                    p.sendMessage("2");
                    e.setCancelled(true);
                    SmeltingGUI(e.getPlayer());
                }
            }
        }
    Both 1 and 2 show up when I right click a furnace while OP
    But neither show when I right click a furnace while not OP

    This is weird, why is it checking for op?
    Again, no other plugins running and no other PlayerInteractEvents in this plugin.
     
  9. @ImaTimelord7
    It might be a bukkit-side bug then, what version are you using?
     
  10. Offline

    Zombie_Striker

    Please remove all other plugins and see if that fixes your problem. If not, then it is a problem with your main server jar.
     
  11. Offline

    Zombie_Striker

    @megamichiel Alright, then it is a problem with the main .jar file
     
  12. Offline

    ImaTimelord7

    @megamichiel @Zombie_Striker
    Sorry guys, been a while, not sure what happened, but I tried the code and it worked all of a sudden. Thanks to everyone who helped.
     
Thread Status:
Not open for further replies.

Share This Page