Plugin Help Im Lost With This ;-;

Discussion in 'Plugin Help/Development/Requests' started by MonsterCatcher00, Oct 17, 2016.

Thread Status:
Not open for further replies.
  1. My Code:
    Code:
      @EventHandler
            public void onBlockUse(PlayerInteractEvent event) {
            Player player = event.getPlayer();
    
            Block block = event.getClickedBlock();
            Material material = block.getType();
            if(material == Material.ENDER_PORTAL_FRAME) {
                ItemStack stick = new ItemStack(Material.STICK);
                ItemMeta meta = stick.getItemMeta();
                if(meta.getDisplayName().toString().toLowerCase() == ("transform")); {
                stick.setItemMeta(meta);
                stick.addUnsafeEnchantment(Enchantment.DURABILITY, 5);
                stick.removeEnchantment(Enchantment.DURABILITY);
                player.sendMessage("Block: " + material + "!");
                    }
                }
            }
        }
    Also This Does Nothing:
    Code:
    ItemStack itemstack = new ItemStack(Material.STICK);
               itemstack.setAmount(1);
               player.getInventory().addItem(itemstack);
            ItemStack stick = new ItemStack(Material.STICK);
            ItemMeta meta = stick.getItemMeta();
            meta.setDisplayName("Transform");
            stick.setItemMeta(meta);
     
    Last edited by a moderator: Oct 17, 2016
  2. Online

    timtower Administrator Administrator Moderator

    @MonsterCatcher00 Did you try to update the inventory?
    if(meta.getDisplayName().toString().toLowerCase() == ("transform")); And that compare will always return false.
    Compare strings with equals
     
  3. no Xd

    uh, memory locations? im a begginer ;-;
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Oct 17, 2016
  4. Online

    timtower Administrator Administrator Moderator

    Yes, because you are comparing memory locations, not the value.
    Basic java. And you can also use equalsIgnoreCase
     
  5. i do not get why it doesnt work, and i dont get an idea of how to fix it
     
  6. Online

    timtower Administrator Administrator Moderator

    @MonsterCatcher00 Did you update your code to use equalsIgnoreCase instead of ==?
    If so: post your full code using http://pastebin.com
    And your full server log using the same method.
     
  7. Online

    timtower Administrator Administrator Moderator

    @MonsterCatcher00 I suspect that you aren't registering your event.
    Code:
    if(meta.getDisplayName().toString().toLowerCase() != "transform"); {                 }
    That does nothing, first it will ALWAYS return true now. Even if the display name is "LALALALALA"
    You have a semi-colon after the statement, closes it pretty much.
    You have an empty block behind it.
     
Thread Status:
Not open for further replies.

Share This Page