Solved LootCrate Help!

Discussion in 'Plugin Help/Development/Requests' started by Lampades, Jan 14, 2016.

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

    Lampades

    This is my listener class
    Code:
    package me.emilio.listener.event.block;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.event.Listener;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import net.md_5.bungee.api.ChatColor;
    
    public class LegendaryDp implements Listener {
        @EventHandler
        public void onRightClickLDPEvent(PlayerInteractEvent event){
            if(event.getAction() == Action.RIGHT_CLICK_AIR){
                ItemStack item = new ItemStack(Material.CHEST, 1);
                ItemMeta meta = item.getItemMeta();
                meta.setDisplayName(ChatColor.GOLD.toString() + ChatColor.BOLD + "Legendary Cosmic Chest " + ChatColor.GRAY
                        + "(Right Click)");
                ArrayList<String> lore = new ArrayList<String>();
                lore.add(ChatColor.GRAY.toString() + "A cache of equipment packaged by");
                lore.add(ChatColor.GRAY.toString() + "the Intergalactic Cosmonaut Station.");
                meta.setLore(lore);
                item.setItemMeta(meta);
                if(event.getPlayer().getItemInHand() == item){
                    Inventory inv = Bukkit.getServer().createInventory(null, 27,ChatColor.DARK_GRAY + "Legendary Cosmic Chest");
                    event.getPlayer().openInventory(inv);
                    }
             
            }
        }
    
    }
    
    What i'm trying to do is whenever I right click the air with the specific chest with the name "Legendary Cosmic Chest" with that lore in my hand, it should open a GUI inventory. Yes, i've included it in my main class as such
    Code:
    @Override
        public void onEnable() {
            myPluginLogger.info("My Plugin is Being Started");
            myPluginLogger.warning("My plugin is being started, watch out!");
            Bukkit.getServer().getPluginManager().registerEvents(new LeaveListener(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new JoinListener(), this);
            registerEvents();
            ChestRightClick();
            [B][I][U]LegendaryDp();[/U][/I][/B]
         
         
        }
    
        @Override
        public void onDisable() {
            myPluginLogger.info("Dude, Plugin is being disabled :(");
        }
    
        public void registerEvents() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new BlockBreak(), this);
        }
    
        public void ChestRightClick() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new me.emilio.listener.event.block.ChestRightClick(), this);
        }
       [B][I][U] public void LegendaryDp() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new me.emilio.listener.event.block.LegendaryDp(), this);
        }[/U][/I][/B]
        
    It is not working. Any help?
     
  2. Offline

    Lolmewn

    Don't compare them using ==, that does a memory location comparison. Instead, use .equals or isSimilar for ItemStacks.
     
    Lampades likes this.
  3. Offline

    Scorpionvssub

    idk why your using all these "voids" for registring when you can do it all without em for registring events/classes/commands.

    as for checking lore you need to get the item in hand getLore check if the lore .equals/.equalsIgnoreCase whatever the lore is, if you use ignorecase caps and colors dont matter as such.

    Also this what u have confuses me but to define an event you must do public void <event name>(EntityInteractEvent event) {
     
  4. Offline

    Lampades

    Last edited: Jan 15, 2016
  5. Offline

    oceantheskatr

    Isn't .equals() supposed to be used for comparing strings, while == should be used for objects?
     
  6. Offline

    Lampades

    Not sure honestly, but either way that fixed it. :p
     
  7. Offline

    Lolmewn

    If you want the exact same object, == will do what you want. .equals will too, as the object's hashcodes are the same. For objects, you usually use ==, also because it is more NPE safe (.equals on null object throws NPE, while == on null object will not - it'll just return false).
     
  8. Offline

    oceantheskatr

Thread Status:
Not open for further replies.

Share This Page