Discussion in 'Spigot Plugin Development' started by zLegendXP, Jul 2, 2018.

  1. So I'm making a plugin and so I have kits. The kits have names and I made an inventory GUI so u can select one. I have an inventory and the items in it have the name of the kits. When I click the kit and get the items display name It says that there is no kit with that name even though I know with my own eyes that the names are exactly the same. CODE:

    Inv class:

    if(!e.getInventory().getName().equals(KitManager.getInstance().getKitSelector().getName())) return;
    if(!e.getCurrentItem().hasItemMeta()) return;
    Player p = (Player) e.getWhoClicked();
    Kit kit = KitManager.getInstance().getKit(e.getCursor().getItemMeta().getDisplayName());
    //if(kit == null) return;
    Arena a = ArenaManager.getInstance().getArena(p);
    if(a == null) return;
    a.addPlayer(p, kit);

    KitManager method:

    public Kit getKit(String name) {
    for(Kit kit : kits) {
    if(kit.getName().equalsIgnoreCase(name)) {
    return kit;
    return null;
    The getKit works with strings off signs and stuff but ut doesn't work in the inventory :(
    Also the display name isn't null I can broadcast it and its the right kit
    #1 zLegendXP, Jul 2, 2018
    Last edited: Jul 2, 2018
  2. There is a code box, there are also sites. Please format your code into a code box or onto a site.
    It's actually readable then.
  3. Bump. no one knows why? is it a bug. what am I doing wrong
  4. I don't know if you have colored the display names inside the inventory, but if you have you might want to strip them first with #stripColor() from the ChatColor enum and then check / get the according kit via the name
    • Agree Agree x 1
  5. TheJavaHacker


    1. Don't bump threads before 24 hours have passed.
    2. Post your ENTIRE code AND Console logs for me to look at.
    3. If you don't know how to debug a very simple null pointer, go have a look at some online tutorials for dealing with them.
    • Agree Agree x 1
    • Winner Winner x 1
    • Informative Informative x 1
  6. Choco


    You literally commented out the null check. If you're certain that there is a kit with that name, I would put money on KitManager#getInstance() returning "new KitManager()" or #getDisplayName() having colour (ultimately messing up the search because colour codes are considered part of the String)
  7. I tried chatcolor.reset and nothing happened. before I had the check if its null I took it out to see the error. the kitmanager class works perfectly
  8. does stripColor remove the color?
  9. Stripping the color does not remove the color of the String displayed. It just returns a String which has been stripped (meaning in plain text without any colors, bold, italic, etc.) to work with
  10. so if the item I clicked was light purple and I stripped it would it work?