Right Click block W/ Specific Name

Discussion in 'Spigot Plugin Development' started by ula492, Jun 5, 2016.

  1. So, ive been trying to figure it out. How would I go by getting the block that a player clicks, with the specific name.
    I tried this. Not work.
    Code (Text):
    if (p.getItemInHand().getItemMeta().getDisplayName().contains("┬žaVoting Crate Key") && e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if(e.getClickedBlock().getType().getData().getName().toLowerCase().contains("voting crate")) {
                    e.setCancelled(true);
                   p.sendMessage(Prefix + "You are opening a ┬žaVoting Crate");
                }
            }
     
  2. Correct me if I'm wrong, but I don't think the blocks still have a name once placed
     
  3. Sw4p

    Supporter

    They do not. You would have to create an array of locations or something and check if the location clicked equals that of your voting create.
     
  4. Hmm, if u make a new item stack, give ur self the block. Then place it, it keeps the name. I just thought it still worked since it has the name still.
     
  5. You mean something like get the name of the block as string without _? Example: Instead of DIAMOND_BLOCK Diamond Block?
    Then you should create a hashmap<Material, String> with all the names of all the blocks :p
     
  6. Sw4p

    Supporter

    You wouldnt need to do this as it have a name() method and it returns string which has replace and Upper/Lower case methods. You just need to get creative.
     
  7. That's right. But for example, the material LEAVES2 has a number 2. It's useless to add a method just for that item. My method could be connected to a Config.yml that allows you to add the materials that are clickable or not ;)
     
  8. Sw4p

    Supporter

    True, i have always just put a check for anything not string and remove it so it that case it would just return "Leaves". Both ideas work depends what your going for.
     
  9. or make an armorstand in the chest, when player clicks that armor stand it opens the GUI, Just a theory,
     
  10. Sw4p

    Supporter

    Yes but adds unnecessary entities to the world so lots of these might lag a bit for players. But then you could add an item to its helmet like i do in my Itemcase plugin in my sig, to display something. This sparks ideas for me. thank you.
     
  11. If you want interactive menus do this...

    You just have to replace the part that he does on onCommand to the event PlayerInteractEvent
     
    • Agree Agree x 1
  12. Make a command that adds the location of the crate to a list when you right click it or hardcode the crate locations.
    Then, on interact you check if the clicked location is contained in the crate location data using the lists in the configs, if it is, which crate type by checking the list in the configs.
    Then it opens a GUI or whatever you want to do for that.