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;
}
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);
}
}
Aggregations