Solved I can't make a player open a crafting table

Discussion in 'Spigot Plugin Development' started by bramar, Feb 2, 2020.

?

Do you know how to fix this

Poll closed Feb 3, 2020.
  1. Yes... but actually no

    1 vote(s)
    100.0%
  2. No... but actually yes

    0 vote(s)
    0.0%
  3. What is this?

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. I made a plugin called 'Armor++'. The plugin recreates the famous BlockArmor mod. I want to create a crafting armor that opens a workbench when you sneak and worn the armor. I tried to do that but it doesn't work (I tried it in 1.15.2)
    The code that i wrote is:
    Code (Java):
    public void craftArmor() {
            for(Player p : Bukkit.getOnlinePlayers()) {
                try {
                    String name1 = p.getInventory().getHelmet().getItemMeta().getDisplayName();
                    String name2 = p.getInventory().getChestplate().getItemMeta().getDisplayName();
                    String name3 = p.getInventory().getLeggings().getItemMeta().getDisplayName();
                    String name4 = p.getInventory().getBoots().getItemMeta().getDisplayName();
                    if(name1.equalsIgnoreCase("Crafting Helmet") && name2.equalsIgnoreCase("Crafting Chestplate") && name3.equalsIgnoreCase("Crafting Leggings") && name4.equalsIgnoreCase("Crafting Boots")) {
                        String lore1 = p.getInventory().getHelmet().getItemMeta().getLore().get(0);
                        String lore2 = p.getInventory().getChestplate().getItemMeta().getLore().get(0);
                        String lore3 = p.getInventory().getLeggings().getItemMeta().getLore().get(0);
                        String lore4 = p.getInventory().getBoots().getItemMeta().getLore().get(0);
                        if(lore1.equalsIgnoreCase(ChatColor.GOLD + "Crafter - Opens a crafting screen") && lore2.equalsIgnoreCase(ChatColor.GOLD + "Crafter - Opens a crafting screen") && lore3.equalsIgnoreCase(ChatColor.GOLD + "Crafter - Opens a crafting screen") && lore4.equalsIgnoreCase(ChatColor.GOLD + "Crafter - Opens a crafting screen")) {
                            if(p.isSneaking() == true) {
                                p.openWorkbench(p.getLocation(), true);
                            }
                        }
                    }
                }catch(NullPointerException e) {
                   
                }
            }
        }
    Can anyone help me?
     
  2. Have you tried sending the player a message or debugging to the console to make sure your event is firing properly?
     
  3. Yes, it works in 1.14.4. But somehow doesn't work in 1.15.2
     
  4. According to the JavaDoc
    Code (Text):

    @Nullable
    @Nullable InventoryView openWorkbench(@Nullable
                                         @Nullable Location location,
                                         boolean force)
    Opens an empty workbench inventory window with the player's inventory on the bottom.
    Parameters:

    location - The location to attach it to. If null, the player's location is used.
    force - If false, and there is no workbench block at the location, no inventory will be opened and null will be returned.
    Not sure if this means there must be a workbench at the location if you set the force to be true
     
  5. nvm... I put the wrong lore lol
     
  6. thought it was something like that :p no worries
     
Thread Status:
Not open for further replies.