3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-28 04:20:08 +01:00

Fix incorrect item removing when it renamed. Additional check by unused "LocalizedName" item attribute

Dieser Commit ist enthalten in:
FeozRu 2022-11-27 21:30:12 +05:00
Ursprung 128594cf80
Commit de7c62c65e
2 geänderte Dateien mit 22 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -18,6 +18,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
@ -25,6 +26,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
@ -162,6 +164,25 @@ public class AST extends JavaPlugin {
PlayerInventory i = p.getInventory(); PlayerInventory i = p.getInventory();
for(ArmorStandTool t : ArmorStandTool.values()) { for(ArmorStandTool t : ArmorStandTool.values()) {
i.remove(t.getItem()); i.remove(t.getItem());
Collection<? extends ItemStack> materialItems = i.all(t.getItem().getType()).values();
ItemMeta toolMeta = t.getItem().getItemMeta();
if (toolMeta == null) {
continue;
}
String toolLocalizedName = toolMeta.getLocalizedName();
for (ItemStack invItem : materialItems) {
ItemMeta inventoryItemMeta = invItem.getItemMeta();
if (inventoryItemMeta == null) {
continue;
}
if (toolLocalizedName.equals(inventoryItemMeta.getLocalizedName())) {
i.remove(invItem);
}
}
} }
} }

Datei anzeigen

@ -79,6 +79,7 @@ public enum ArmorStandTool {
if(meta != null) { if(meta != null) {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setLocalizedName("ArmorStandTool");
item.setItemMeta(meta); item.setItemMeta(meta);
} }
this.config_id = config_id; this.config_id = config_id;