use of org.cubeengine.module.log.LogAttachment in project modules-extra by CubeEngine.
the class LogCommands method findLogTool.
@SuppressWarnings("deprecation")
private void findLogTool(User user, Material material) {
ItemStack found = null;
for (ItemStack item : user.getInventory().getContents()) {
if (item != null && item.getType().equals(material) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(toolName)) {
found = item;
break;
}
}
if (found == null) {
found = new ItemStack(material, 1);
ItemMeta meta = found.getItemMeta();
meta.setDisplayName(toolName);
meta.setLore(Arrays.asList("created by " + user.getDisplayName()));
found.setItemMeta(meta);
ItemStack oldItemInHand = user.getItemInHand();
user.setItemInHand(found);
HashMap<Integer, ItemStack> tooMuch = user.getInventory().addItem(oldItemInHand);
for (ItemStack item : tooMuch.values()) {
user.getWorld().dropItemNaturally(user.getLocation(), item);
}
user.updateInventory();
user.sendTranslated(POSITIVE, "Received a new Log-Tool!");
LogAttachment logAttachment = user.attachOrGet(LogAttachment.class, this.module);
logAttachment.createNewLookup(material);
return;
}
user.getInventory().removeItem(found);
ItemStack oldItemInHand = user.getItemInHand();
user.setItemInHand(found);
user.getInventory().addItem(oldItemInHand);
user.updateInventory();
user.sendTranslated(POSITIVE, "Found a Log-Tool in your inventory!");
}
Aggregations