If I println something it doesnt break

Discussion in 'Plugin Development' started by thechrisanator, Nov 17, 2018.

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

    thechrisanator

    so I have a tool in an inventory, and every time the player uses it by mining, it updates the tool in the inventory. the tool in their hand has lore values, and I clear al the lore values before I give it back to the player.
    the values are never actually cleared unless I print the inventory contents or something similar.

    Code:
    Inventory mtinv = toolinv.get(player.getUniqueId()); //create inventory of mtinv
                                                ItemStack handstack = player.getInventory().getItemInMainHand().clone();
                                                ItemMeta stackmeta = handstack.getItemMeta();
                                                stackmeta.setLore(null);
                                                handstack.setItemMeta(stackmeta);
                                                mtinv.setItem(i, handstack); //replace old item with used item
                                                System.out.println(mtinv.getContents());
                                                toolinv.put(player.getUniqueId(), mtinv); //replace old inv with new inv
                                                break;
    if I dont include the print line, the lore stays on the tools
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    thechrisanator

    @timtower
    the outside inventory still has the item lores in it now.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @thechrisanator What outside inventory? You are showing a random piece of code, don't know what is calling it.
     
  5. Offline

    thechrisanator

    the player has an outside inventory

    Code:
    if (toolinv.containsKey(player.getUniqueId())) { //if the player's mt inv exists
                                        ItemStack givestack = new ItemStack(Material.AIR, 0);
                                        boolean chosentool = false;
                                        for (int i = 0; i < 5; i++) { //this loops through the mt inv, checks which index the current item being used is in, and then updates it
                                            if (toolinv.get(player.getUniqueId()).getItem(i).getType() == player.getInventory().getItemInMainHand().getType()) {
                                                Inventory mtinv = toolinv.get(player.getUniqueId()); //create inventory of mtinv
                                                ItemStack handstack = player.getInventory().getItemInMainHand().clone();
                                                ItemMeta stackmeta = handstack.getItemMeta();
                                                stackmeta.setLore(null);
                                                handstack.setItemMeta(stackmeta);
                                                mtinv.setItem(i, handstack); //replace old item with used item
                                                player.updateInventory();
                                                toolinv.put(player.getUniqueId(), mtinv); //replace old inv with new inv
                                                break;
                                            }
                                        }
    there's the inventory inside a hashmap called toolinv, and then there's the players inventory

    @timtower

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 18, 2018
Thread Status:
Not open for further replies.

Share This Page