Search in sources :

Example 6 with LogAttachment

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!");
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) LogAttachment(org.cubeengine.module.log.LogAttachment)

Aggregations

LogAttachment (org.cubeengine.module.log.LogAttachment)6 User (org.cubeengine.libcube.service.user.User)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 Command (org.cubeengine.butler.parametric.Command)1 TimeConversionException (org.cubeengine.libcube.util.TimeConversionException)1 Lookup (org.cubeengine.module.log.storage.Lookup)1 QueryParameter (org.cubeengine.module.log.storage.QueryParameter)1 ShowParameter (org.cubeengine.module.log.storage.ShowParameter)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1