Search in sources :

Example 1 with PowertoolData

use of org.cubeengine.module.powertools.data.PowertoolData in project modules-extra by CubeEngine.

the class PowertoolCommand method setPowerTool.

private ItemStack setPowerTool(ItemStack item, List<String> newPowerTools) {
    if (newPowerTools == null) {
        item.remove(PowertoolData.class);
    } else {
        item.offer(new PowertoolData(newPowerTools));
    }
    List<Text> lore = item.get(Keys.ITEM_LORE).orElse(null);
    if (lore == null) {
        lore = new ArrayList<>();
    }
    List<Text> newLore = new ArrayList<>();
    for (Text text : lore) {
        if (text.toPlain().equals("PowerTool")) {
            break;
        }
        newLore.add(text);
    }
    if (newPowerTools != null && !newPowerTools.isEmpty()) {
        newLore.add(Text.of(DARK_GREEN, "PowerTool"));
        newLore.addAll(newPowerTools.stream().map(Text::of).collect(toList()));
    }
    if (newLore.isEmpty()) {
        item.remove(LoreData.class);
        return item;
    }
    item.offer(Keys.ITEM_LORE, newLore);
    return item;
}
Also used : PowertoolData(org.cubeengine.module.powertools.data.PowertoolData) IPowertoolData(org.cubeengine.module.powertools.data.IPowertoolData) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text)

Example 2 with PowertoolData

use of org.cubeengine.module.powertools.data.PowertoolData in project modules-extra by CubeEngine.

the class PowertoolCommand method list.

@Alias(value = "ptl")
@Command(desc = "Lists your powertool-bindings.")
@Restricted(value = Player.class, msg = "You already have enough power!")
public void list(Player context, @Flag boolean all) {
    if (all) {
        for (Inventory slot : context.getInventory().slots()) {
            if (slot.peek().isPresent()) {
                ItemStack item = slot.peek().get();
                PowertoolData data = item.get(PowertoolData.class).orElse(null);
                if (data != null) {
                    context.sendMessage(Text.of(GOLD, data.get(Keys.DISPLAY_NAME).orElse(Text.of(materialMatcher.getNameFor(item))), GOLD, ":"));
                    showPowerToolList(context, this.getPowerTools(item), false, false);
                }
            }
        }
        return;
    }
    if (!context.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        i18n.send(context, NEUTRAL, "You do not have an item in your hand.");
    } else {
        this.showPowerToolList(context, this.getPowerTools(context.getItemInHand(HandTypes.MAIN_HAND).get()), false, true);
    }
}
Also used : PowertoolData(org.cubeengine.module.powertools.data.PowertoolData) IPowertoolData(org.cubeengine.module.powertools.data.IPowertoolData) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command) Restricted(org.cubeengine.butler.filter.Restricted) Alias(org.cubeengine.butler.alias.Alias)

Aggregations

IPowertoolData (org.cubeengine.module.powertools.data.IPowertoolData)2 PowertoolData (org.cubeengine.module.powertools.data.PowertoolData)2 ArrayList (java.util.ArrayList)1 Alias (org.cubeengine.butler.alias.Alias)1 Restricted (org.cubeengine.butler.filter.Restricted)1 Command (org.cubeengine.butler.parametric.Command)1 ContainerCommand (org.cubeengine.libcube.service.command.ContainerCommand)1 Inventory (org.spongepowered.api.item.inventory.Inventory)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Text (org.spongepowered.api.text.Text)1