Making custom item names

Discussion in 'Plugin Development' started by Mineblemone, Jun 22, 2013.

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

    TheTrixsta


    Maturity now thats what I like to see

    But I believe you can do
    Code:
    Itemstack.getItemMeta().setDisplayName("Item name");
    in this case you wouldn't need to set the item meta


    Could of handled that a little better though

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  2. TheTrixsta pkt Alex5657
    Here is my listener class:
    Code:
     
    package com.hotmail.labs.af.custominfoplugin;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryOpenEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
     
    public class minilisten implements Listener {
    @EventHandler
    public void join(PlayerJoinEvent event) {
            ItemStack emerald = new ItemStack(Material.EMERALD, 1);
            ItemMeta bm = emerald.getItemMeta();
            bm.setDisplayName(ChatColor.GREEN + "Click to go to"+ ChatColor.RED+"Infected");
            emerald.setItemMeta(bm);
            event.getPlayer().getInventory().addItem(emerald);
        }
    public void onInventoryOpen(InventoryOpenEvent Evt) {
    Evt.setCancelled(true);
    }
     
     
    }
    
    And my reference to it in onEnable:
    Code:
    public void onEnable(){
    getServer().getPluginManager().registerEvents(new minilisten(), this);
    Map<String, String> status = new HashMap<String, String>();
    status.put("infectedStatus", "Ready");
    String infectedStatus = status.get("infectedStatus");
    this.saveDefaultConfig();
     
       
    } 
    
    It still doesn't work...
     
  3. Offline

    TheTrixsta

    TheTrixsta pkt Alex5657
    Here is my listener class:
    Code:
    package com.hotmail.labs.af.custominfoplugin;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryOpenEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
     
    public class minilisten implements Listener {
    @EventHandler
    public void join(PlayerJoinEvent event) {
            ItemStack emerald = new ItemStack(Material.EMERALD, 1);
            ItemMeta bm = emerald.getItemMeta();
            bm.setDisplayName(ChatColor.GREEN + "Click to go to"+ ChatColor.RED+"Infected");
            emerald.setItemMeta(bm);
            event.getPlayer().getInventory().addItem(emerald);
        }
     
    @EventHandler
    public void onInventoryOpen(InventoryOpenEvent Evt) {
        Evt.setCancelled(true);
    }
    }
    
    And my reference to it in onEnable:
    Code:
     
    String infectedStatus = "";
     
    public void onEnable(){
    getServer().getPluginManager().registerEvents(new minilisten(), this);
    status = "Ready"
    this.saveDefaultConfig();
    }
    
    I Edited your code above
     
  4. TheTrixsta
    Ok, but that has nothing to do with the main problem, but thanks for that.
    Anyways, I'm getting this log:
    Code:
    22.06 15:44:09 [Server] INFO ... 14 more
    22.06 15:44:09 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:195)
    22.06 15:44:09 [Server] INFO at java.lang.Class.forName(Class.java:266)
    22.06 15:44:09 [Server] INFO at java.lang.Class.forName0(Native Method)
    22.06 15:44:09 [Server] INFO Caused by: java.lang.ClassNotFoundException: com/hotmail/labs/af/custominfoplugin/Cipmain
    22.06 15:44:09 [Server] INFO at fy.run(SourceFile:849)
    22.06 15:44:09 [Server] INFO at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:497)
    22.06 15:44:09 [Server] INFO at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:599)
    22.06 15:44:09 [Server] INFO at ho.r(DedicatedServer.java:270)
    22.06 15:44:09 [Server] INFO at ho.al(DedicatedServer.java:308)
    22.06 15:44:09 [Server] INFO at x.a(CommandHandler.java:14)
    22.06 15:44:09 [Server] INFO at keepcalm.mods.bukkit.nmsforge.CommandHandlerImpl.a(CommandHandlerImpl.java:92)
    22.06 15:44:09 [Server] INFO at keepcalm.mods.bukkit.forgeHandler.commands.CommandExecutor2CommandBase.b(CommandExecutor2CommandBase.java:105)
    22.06 15:44:09 [Server] INFO at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
    22.06 15:44:09 [Server] INFO at org.bukkit.Bukkit.reload(Bukkit.java:184)
    22.06 15:44:09 [Server] INFO at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:791)
    22.06 15:44:09 [Server] INFO at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:808)
    22.06 15:44:09 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:232)
    22.06 15:44:09 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:307)
    22.06 15:44:09 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:206)
    22.06 15:44:09 [Server] INFO org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: com/hotmail/labs/af/custominfoplugin/Cipmain
    22.06 15:44:09 [Server] SEVERE Could not load './plugins/minigames.jar' in folder './plugins'
    
    But I know it should be working, since I checked that the files are included and the plugin.yml is correct

    anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  5. Offline

    TheTrixsta

    Code:
    22.06 15:44:09 [Server] INFO Caused by: java.lang.ClassNotFoundException: com/hotmail/labs/af/custominfoplugin/Cipmain
    Theres your "Caused by", so basically the class Cipmain is trying to be accessed but it cant be found
     
  6. But why TheTrixsta ?
    I'm doing everything right, I even looked inside my jar and the class is there in the right package.
     
  7. Offline

    TheTrixsta


    are the versions of craftbukkit you are using to develop and run the server to test the plugin the same?
     
  8. TheTrixsta
    Well umm no.

    I made it the same version. It still isn't working?
    pkt TheTrixsta bitWolfy

    Ok so::
    The plugin is working, it gives an emerald on player login.
    But, for some reason it is not named.
    Please help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  9. Offline

    pkt

    post code?
     
  10. pkt
    oh woops
    Heres my listener:
    Code:
    package com.hotmail.labs.af.walrusmanager;
     
    import java.util.Arrays;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryOpenEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
     
    public class minilisten implements Listener {
    @EventHandler
    public void join(PlayerJoinEvent event) {
    Bukkit.broadcastMessage("test");
            ItemStack walrus = new ItemStack(Material.EMERALD, 1);
            ItemMeta bm = walrus.getItemMeta();
            bm.setDisplayName("Click to go to: Infected");
            bm.setLore(Arrays.asList("Click to go to: Infected"));
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(walrus);
            
        }
    public void onInventoryOpen(InventoryOpenEvent Evt) {
    Evt.setCancelled(true);
    }
     
     
     
    }
    
    Inventory Open Cancel event doesn't work either.
     
  11. Offline

    pkt

    You forgot to do walrus.setItemMeta(bm); :p
     
  12. Woooops

    pkt
    the thing is, my broadcast message, clearinventory and cancel inventory open aren't working.

    pkt Nope. It still does EXACTLY what it did before.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  13. Offline

    TheTrixsta

    You have to use the "@EventListener" over your openInventory method
     
  14. Offline

    pkt

    I've tested that broadcast message does work, but the inventory.clear() method only clears the players hand for some reason... you may have to make a for loop to look through the players inventory and remove all items
     
  15. pkt TheTrixsta
    I have got the clear inventory and broadcast working.
    However the item is STILL not named....
     
  16. Offline

    pkt

    Make sure you are setting the meta in the right place, code processes in order. put it between
    bm.setLore(Arrays.asList("Click to go to: Infected")); and event.getPlayer().getInventory().clear();
     
  17. Offline

    TheTrixsta

    Mineblemone Before you clear the player's inventory, walrus.setItemMeta(bm);
     
    pkt likes this.
  18. TheTrixsta pkt
    Here is my code that doesn't work:
    Code:
    public void join(PlayerJoinEvent event) {
     
            ItemStack walrus = new ItemStack(Material.EMERALD, 1);
            ItemMeta bm = walrus.getItemMeta();
            bm.setDisplayName("Click to go to: Infected");
            bm.setLore(Arrays.asList("Click to go to: Infected"));
            walrus.setItemMeta(bm);
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(walrus);
            
     
        }
    
     
  19. Offline

    TheTrixsta


    You don't even need to set the item lore lol
     
  20. TheTrixsta
    I've removed it, still doesn't work.

    Please can someone helP?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  21. Offline

    pkt

    EventHandler or register listener, which one do you not have?
     
  22. pkt
    Both?
    I use @EventHandler and my class implements listener.
     
Thread Status:
Not open for further replies.

Share This Page