Check that an Item Frame is in an X location

Discussion in 'Spigot Plugin Development' started by PabloGamer380YT, Jun 3, 2017.

  1. Hi Guys, I'm trying to make a code, which detects if the player is clicking a frame item in a location, that would be set in the config.yml and that when you click, if the Frame item is in that Location set in the config.yml that sends you a message

    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    Block b = event.getClickedBlock();
    World w = Bukkit.getWorld(plugin.getConfig().getString("ItemFrame.World"));
    double x = plugin.getConfig().getDouble("ItemFrame.X");
    double y = plugin.getConfig().getDouble("ItemFrame.Y");
    double z = plugin.getConfig().getDouble("ItemFrame.Z");
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if ((event.getClickedBlock().getType() == Material.ITEM_FRAME)) {
    if (w == b.getWorld() && x == b.getX() && y == b.getY() && z == b.getZ()) {
    p.sendMessage("errortest1");
    }
    }
    }
    }
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    First of all, indentation mate.
    Second, have you considered saving the UUID of the entity instead? It exists across restarts, and can be saved as a string.
     
    • Agree Agree x 1
  3. To save the UUID of an entity ?? Until now I find out that you can do that, I was trying to do it through a location, because I think it's easier.
     
  4. I also have to imagine there's an event for right-clicking an item frame- maybe InteractAtEntity ?
     
  5. Itemframes are not blocks, they are entitys.
     
  6. Couldn't you just check if the player right-clicked the item frame with PlayerInteractEvent?
     
  7. You Need to Check nearbyentitys from your Location