Hello! I am making a guard plugin for my server, and I need a way for when a guard obtains a kit, they are linked to the items from the kit, so that they cannot abuse by giving away their items. So, this is what I've come up with
Whenever a guard obtains their kit, I associate a ntb tag with the item, as well as adding some lore that displays the players name.
However, the big issue with this code, is that it will tag every item the guard might have in their inventory, and I obviously only want to tag items from the kit which they just recieved, so I would appriciate if anyone has a solution for this, as I just can't think of any.
Thanks
Java:
@Override
public void giveGuardKit(Player player, String kitName) {
try {
User user = essentials.getUser(player);
Kit kit = new Kit(kitName, essentials);
kit.expandItems(user);
Inventory inventory = player.getInventory();
for (ItemStack item : inventory.getContents()) {
if (item == null) {
continue;
}
ItemMeta meta = item.getItemMeta();
NamespacedKey guardKey = new NamespacedKey(plugin, "is_guard_item");
PersistentDataContainer container = meta.getPersistentDataContainer();
if (container.has(guardKey)) {
continue;
}
List<Component> lore = new ArrayList<>();
lore.add(empty());
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date currentDate = new Date();
String dateString = dateFormat.format(currentDate);
lore.add(text().content("Tilhører: " + player.getName()).color(YELLOW).decoration(ITALIC, false).build());
lore.add(text().content("Dato: " + dateString).color(YELLOW).decoration(ITALIC, false).build());
meta.lore(lore);
NamespacedKey ownerKey = new NamespacedKey(plugin, "owner_uuid");
container.set(guardKey, PersistentDataType.BOOLEAN, true);
container.set(ownerKey, PersistentDataType.STRING, player.getUniqueId().toString());
item.setItemMeta(meta);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Whenever a guard obtains their kit, I associate a ntb tag with the item, as well as adding some lore that displays the players name.
However, the big issue with this code, is that it will tag every item the guard might have in their inventory, and I obviously only want to tag items from the kit which they just recieved, so I would appriciate if anyone has a solution for this, as I just can't think of any.
Thanks