Personal Furnace not working

Discussion in 'Plugin Development' started by Alfie Jones, May 25, 2014.

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

    Alfie Jones

    Recently I have been working on my own plugin which will allow a user to view his/her own private furnace just by clicking a furnace. However I cannot work out why my code doesn't work.
    @EventHandler
    publicvoid furnaceEvent(PlayerInteractEvent e ){
    Player p = e.getPlayer();
    Inventory EC = Bukkit.createInventory(null , InventoryType.FURNACE, ChatColor.DARK_GREEN + "Your own furnace");
    if(e.getClickedBlock().equals(Material.FURNACE ));
    e.setCancelled(true);
    p.getPlayer().openInventory(EC);
    }

    Please reply to this thread ASAP with a fix, this will mean a lot to me :)

    Please reply if you know what is going wrong

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  2. Offline

    Alfie Jones

    Please anyone????
     
  3. Offline

    xJeremyCx

    Why is it not working? Is that any error log in console? Did you double check your code? Did you register the event?
    And this one if(e.getClickedBlock().equals(Material.FURNACE )); should be if(e.getClickedBlock().equals(Material.FURNACE )) {e.setCancelled(true);
    p.getPlayer().openInventory(EC);}
     
  4. A Block does not/never equal a Material.
    This is because they don't inherit the same structure.
     
  5. Offline

    FabeGabeMC

    To save the furnace, instead of opening a custom furnace inventory, save the block in a HashMap containing the player's name (String, not Player, will cause lots of data overflow, kinda) and if you want a limit, check if the block count the user has is equal to the limit number, then cancel the hashmap part, but don't cancel the event.
    Kinda like this:
    Code:java
    1. HashMap<String, Block> protect = new HashMap<String, Block>();
    2.  
    3. //Listener
    4. public void onInteract(PlayerInteractEvent e){
    5. Player p = e.getPlayer();
    6. Block b = e.getClickedBlock();
    7. if(b.getType() == Material.FURNACE){
    8. for(Player p : Bukkit.getOnlinePlayers()){
    9. //You know what to do next.
    10. }
    11. }
    12. }
     
  6. Offline

    Alfie Jones

    thanks so much for your help
     
Thread Status:
Not open for further replies.

Share This Page