Solved Why isn't this line of code firing

Discussion in 'Plugin Development' started by falcon2_0, Apr 29, 2014.

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


    First of all: Yes, I registered my events and there are no errors in the console

    This line of code isn't firing:
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3. if (event.getInventory().getName().equalsIgnoreCase("Server Warps")) {
    4. if (event.getCurrentItem().getType() == Material.WATER) {
    5. event.getWhoClicked().closeInventory();
    6. event.getWhoClicked().teleport(new Location(null, 0, 100, 0));
    7. }
    8. }
    9. }

    I made an Inventory called, "Server Warps" and inside it I have a water block. It looks like this:
    When I click on the water, it doesn't teleport me to 0, 100, 0
  2. Offline


    falcon2_0 The Inventory name is colored, therefor it would be the color + "Server Warps", so the first if is never true. See if the String contains Server Warps. Also, you need a check to see if the current item isn't null, and the Location needs a valid world.
  3. Offline

    Windy Day

    I would check your if statements. It may not fire because the inventory name has chat colors you don't check for. If this is not the case put
    System.out.println("if statement #");
    After each if statement and see how far it gets to pinpoint the problem.
  4. Offline


    2. @EventHandler
    3. public void onInventoryClick(InventoryClickEvent event) {
    4. if (event.getInventory().getName().equalsIgnoreCase(ChatColor.BLUE + "" + ChatColor.BOLD + "Server Warps")) {
    5. if (event.getCurrentItem().getType() == Material.WATER) {
    6. event.getWhoClicked().closeInventory();
    7. event.getWhoClicked().teleport(new Location(null, 0, 100, 0));
    8. }
    9. }
    10. }

    As mentioned earlier, Your inventory name has colors, So just make sure that you check for the colors.
  5. Offline


    Thanks! :D Thread Solved!
Thread Status:
Not open for further replies.

Share This Page