Skip to content

Commit

Permalink
Added dynamic-count itemflag
Browse files Browse the repository at this point in the history
  • Loading branch information
RockinChaos committed Jan 12, 2024
1 parent a4f8da9 commit 8f21c98
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ private void setNameData(final Player player, final ItemStack reviseItem, final
}
tempMeta.setDisplayName(StringUtils.translateLayout(ItemHandler.cutDelay(nameString), player) + itemData);
reviseItem.setItemMeta(tempMeta);
reviseItem.setAmount(this.itemMap.getCount(player)); // Temporary, implementation for a list of animated item count is planned.
if (this.itemMap.isDynamicCount()) { // Better but still temporary--implementation for a list of animated item count is planned.
reviseItem.setAmount(this.itemMap.getCount(player));
}
}
}

Expand Down
96 changes: 58 additions & 38 deletions src/main/java/me/RockinChaos/itemjoin/item/ItemMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public class ItemMap implements Cloneable {
private boolean noRepairing = false;
private boolean animate = false;
private boolean dynamic = false;
private boolean dynamicCount = false;
private boolean glowing = false;
private boolean overwritable = false;
private boolean blockPlacement = false;
Expand Down Expand Up @@ -462,46 +463,47 @@ private void setTeleportArrow() {
private void setItemflags() {
if (this.nodeLocation.getString(".itemflags") != null) {
this.itemflags = this.nodeLocation.getString(".itemflags");
this.vanillaItem = StringUtils.containsIgnoreCase(this.itemflags, "vanilla");
this.vanillaStatus = StringUtils.containsIgnoreCase(this.itemflags, "vanilla-status");
this.vanillaControl = StringUtils.containsIgnoreCase(this.itemflags, "vanilla-control");
this.disposable = StringUtils.containsIgnoreCase(this.itemflags, "disposable");
this.blockPlacement = StringUtils.containsIgnoreCase(this.itemflags, "placement");
this.blockMovement = StringUtils.containsIgnoreCase(this.itemflags, "inventory-modify") || StringUtils.containsIgnoreCase(this.itemflags, "inventory-close");
this.blockEquip = StringUtils.containsIgnoreCase(this.itemflags, "cancel-equip");
this.closeInventory = StringUtils.containsIgnoreCase(this.itemflags, "inventory-close");
this.itemChangeable = StringUtils.containsIgnoreCase(this.itemflags, "allow-modifications") || StringUtils.containsIgnoreCase(this.itemflags, "item-changeable");
this.alwaysGive = StringUtils.containsIgnoreCase(this.itemflags, "always-give");
this.autoRemove = StringUtils.containsIgnoreCase(this.itemflags, "auto-remove");
this.stackable = StringUtils.containsIgnoreCase(this.itemflags, "stackable");
this.notHat = StringUtils.containsIgnoreCase(this.itemflags, "not-hat");
this.selectable = StringUtils.containsIgnoreCase(this.itemflags, "selectable");
this.splittable = StringUtils.containsIgnoreCase(this.itemflags, "splittable");
this.dynamic = StringUtils.containsIgnoreCase(this.itemflags, "dynamic");
this.animate = StringUtils.containsIgnoreCase(this.itemflags, "animate");
this.glowing = StringUtils.containsIgnoreCase(this.itemflags, "glowing") || StringUtils.containsIgnoreCase(this.itemflags, "glow");
this.giveNext = StringUtils.containsIgnoreCase(this.itemflags, "give-next");
this.moveNext = StringUtils.containsIgnoreCase(this.itemflags, "move-next");
this.dropFull = StringUtils.containsIgnoreCase(this.itemflags, "drop-full");
this.itemStore = StringUtils.containsIgnoreCase(this.itemflags, "item-store");
this.itemModify = StringUtils.containsIgnoreCase(this.itemflags, "item-modifiable");
this.noCrafting = StringUtils.containsIgnoreCase(this.itemflags, "item-craftable");
this.noRepairing = StringUtils.containsIgnoreCase(this.itemflags, "item-repairable");
this.cancelEvents = StringUtils.containsIgnoreCase(this.itemflags, "cancel-events");
this.countLock = StringUtils.containsIgnoreCase(this.itemflags, "count-lock");
this.teleportArrow = StringUtils.containsIgnoreCase(this.itemflags, "teleport");
this.overwritable = StringUtils.containsIgnoreCase(this.itemflags, "overwrite");
this.ipLimited = StringUtils.containsIgnoreCase(this.itemflags, "ip-limit");
this.deathKeepable = StringUtils.containsIgnoreCase(this.itemflags, "death-keep");
this.deathDroppable = StringUtils.containsIgnoreCase(this.itemflags, "death-drops");
this.selfDroppable = StringUtils.containsIgnoreCase(this.itemflags, "self-drops");
this.vanillaItem = StringUtils.splitIgnoreCase(this.itemflags, "vanilla", ",");
this.vanillaStatus = StringUtils.splitIgnoreCase(this.itemflags, "vanilla-status", ",");
this.vanillaControl = StringUtils.splitIgnoreCase(this.itemflags, "vanilla-control", ",");
this.disposable = StringUtils.splitIgnoreCase(this.itemflags, "disposable", ",");
this.blockPlacement = StringUtils.splitIgnoreCase(this.itemflags, "placement", ",");
this.blockMovement = StringUtils.splitIgnoreCase(this.itemflags, "inventory-modify", ",") || StringUtils.splitIgnoreCase(this.itemflags, "inventory-close", ",");
this.blockEquip = StringUtils.splitIgnoreCase(this.itemflags, "cancel-equip", ",");
this.closeInventory = StringUtils.splitIgnoreCase(this.itemflags, "inventory-close", ",");
this.itemChangeable = StringUtils.splitIgnoreCase(this.itemflags, "item-changeable", ",");
this.alwaysGive = StringUtils.splitIgnoreCase(this.itemflags, "always-give", ",");
this.autoRemove = StringUtils.splitIgnoreCase(this.itemflags, "auto-remove", ",");
this.stackable = StringUtils.splitIgnoreCase(this.itemflags, "stackable", ",");
this.notHat = StringUtils.splitIgnoreCase(this.itemflags, "not-hat", ",");
this.selectable = StringUtils.splitIgnoreCase(this.itemflags, "selectable", ",");
this.splittable = StringUtils.splitIgnoreCase(this.itemflags, "splittable", ",");
this.animate = StringUtils.splitIgnoreCase(this.itemflags, "animate", ",");
this.dynamic = StringUtils.splitIgnoreCase(this.itemflags, "dynamic", ",");
this.dynamicCount = StringUtils.splitIgnoreCase(this.itemflags, "dynamic-count", ",");
this.glowing = StringUtils.splitIgnoreCase(this.itemflags, "glowing", ",");
this.giveNext = StringUtils.splitIgnoreCase(this.itemflags, "give-next", ",");
this.moveNext = StringUtils.splitIgnoreCase(this.itemflags, "move-next", ",");
this.dropFull = StringUtils.splitIgnoreCase(this.itemflags, "drop-full", ",");
this.itemStore = StringUtils.splitIgnoreCase(this.itemflags, "item-store", ",");
this.itemModify = StringUtils.splitIgnoreCase(this.itemflags, "item-modifiable", ",");
this.noCrafting = StringUtils.splitIgnoreCase(this.itemflags, "item-craftable", ",");
this.noRepairing = StringUtils.splitIgnoreCase(this.itemflags, "item-repairable", ",");
this.cancelEvents = StringUtils.splitIgnoreCase(this.itemflags, "cancel-events", ",");
this.countLock = StringUtils.splitIgnoreCase(this.itemflags, "count-lock", ",");
this.teleportArrow = StringUtils.splitIgnoreCase(this.itemflags, "teleport", ",");
this.overwritable = StringUtils.splitIgnoreCase(this.itemflags, "overwrite", ",");
this.ipLimited = StringUtils.splitIgnoreCase(this.itemflags, "ip-limit", ",");
this.deathKeepable = StringUtils.splitIgnoreCase(this.itemflags, "death-keep", ",");
this.deathDroppable = StringUtils.splitIgnoreCase(this.itemflags, "death-drops", ",");
this.selfDroppable = StringUtils.splitIgnoreCase(this.itemflags, "self-drops", ",");

// Shared with Triggers //
this.setOnlyFirstJoin((StringUtils.containsIgnoreCase(this.itemflags, "first-join") || this.onlyFirstJoin));
this.setOnlyFirstLife((StringUtils.containsIgnoreCase(this.itemflags, "first-life") || this.onlyFirstLife));
this.onlyFirstWorld = (StringUtils.containsIgnoreCase(this.itemflags, "first-world") || this.onlyFirstWorld);
this.AllowOpBypass = (StringUtils.containsIgnoreCase(this.itemflags, "AllowOpBypass") || this.AllowOpBypass);
this.CreativeBypass = (StringUtils.containsIgnoreCase(this.itemflags, "CreativeBypass") || this.CreativeBypass);
this.setOnlyFirstJoin((StringUtils.splitIgnoreCase(this.itemflags, "first-join", ",") || this.onlyFirstJoin));
this.setOnlyFirstLife((StringUtils.splitIgnoreCase(this.itemflags, "first-life", ",") || this.onlyFirstLife));
this.onlyFirstWorld = (StringUtils.splitIgnoreCase(this.itemflags, "first-world", ",") || this.onlyFirstWorld);
this.AllowOpBypass = (StringUtils.splitIgnoreCase(this.itemflags, "AllowOpBypass", ",") || this.AllowOpBypass);
this.CreativeBypass = (StringUtils.splitIgnoreCase(this.itemflags, "CreativeBypass", ",") || this.CreativeBypass);
}
}

Expand Down Expand Up @@ -770,6 +772,15 @@ public void setAnimate(final boolean bool) {
this.animate = bool;
}

/**
* Sets the Dynamic Count Flag.
*
* @param bool - The value to be set.
*/
public void setDynamicCount(final boolean bool) {
this.dynamicCount = bool;
}

/**
* Sets the Inventory Close Flag.
*
Expand Down Expand Up @@ -3371,6 +3382,15 @@ public boolean isDynamic() {
return this.dynamic;
}

/**
* Checks if the Dynamic Count Flag is enabled.
*
* @return If it is enabled.
*/
public boolean isDynamicCount() {
return this.dynamicCount;
}

/**
* Sets the Dynamic Flag.
*
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/me/RockinChaos/itemjoin/utils/menus/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4903,13 +4903,6 @@ private static void flagPane(final Player player, final ItemMap itemMap) {
itemMap.setEquip(!itemMap.isEquip());
flagPane(player, itemMap);
}));
flagPane.addButton(new Button(ItemHandler.getItem("NAME_TAG", 1, itemMap.isDynamic(), false, "&a&l&nDynamic", "&7",
"&a&lTrue&f: &7Allows the item to dynamically", "&7update every 100 ticks", "&7Useful for updating placeholders.", "&7",
"&c&lFalse&f: &7Item will not update its name, lore, etc.", "&7",
"&9&lENABLED: &a" + (itemMap.isDynamic() + "").toUpperCase()), event -> {
itemMap.setDynamic(!itemMap.isDynamic());
flagPane(player, itemMap);
}));
flagPane.addButton(new Button(ItemHandler.getItem("EGG", 1, itemMap.isAnimated(), false, "&a&l&nAnimate", "&7",
"&a&lTrue&f: &7Allows the item to animate between", "&7its different iterations defined", "&7under the animations tab.", "&7",
"&c&lFalse&f: &7Item will not animate.", "&7",
Expand All @@ -4930,6 +4923,20 @@ private static void flagPane(final Player player, final ItemMap itemMap) {
}
flagPane(player, itemMap);
}));
flagPane.addButton(new Button(ItemHandler.getItem("NAME_TAG", 1, itemMap.isDynamic(), false, "&a&l&nDynamic", "&7",
"&a&lTrue&f: &7Allows the item to dynamically", "&7update every 100 ticks", "&7Useful for updating placeholders.", "&7",
"&c&lFalse&f: &7Item will not update its name, lore, etc.", "&7",
"&9&lENABLED: &a" + (itemMap.isDynamic() + "").toUpperCase()), event -> {
itemMap.setDynamic(!itemMap.isDynamic());
flagPane(player, itemMap);
}));
flagPane.addButton(new Button(ItemHandler.getItem("NAME_TAG", 4, itemMap.isDynamicCount(), false, "&a&l&nDynamic Count", "&7",
"&a&lTrue&f: &7When an item dynamically updates", "&7the items count will be reset to its default.", "&7Only functions with the dynamic or animate itemflag.", "&7",
"&c&lFalse&f: &7The item will keep its existing count.", "&7",
"&9&lENABLED: &a" + (itemMap.isDynamicCount() + "").toUpperCase()), event -> {
itemMap.setDynamicCount(!itemMap.isDynamicCount());
flagPane(player, itemMap);
}));
flagPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "CHEST_MINECART" : "342"), 1, itemMap.isItemStore(), false, "&a&l&nItem Store", "&7",
"&a&lTrue&f:&7 Prevents the storage of the item in any containers.", "&7Such as chests, armor stands, anvils, etc.", "&7",
"&c&lFalse&f:&7 The item can be stored in containers.", "&7",
Expand Down Expand Up @@ -5056,7 +5063,7 @@ private static void flagPane(final Player player, final ItemMap itemMap) {
itemMap.setSplittable(!itemMap.isSplittable());
flagPane(player, itemMap);
}));
flagPane.addButton(new Button(fillerPaneBItem), 32);
flagPane.addButton(new Button(fillerPaneBItem), 31);
});
flagPane.open(player);
}
Expand Down Expand Up @@ -5113,6 +5120,9 @@ private static void setItemFlags(final ItemMap itemMap) {
if (itemMap.isDynamic()) {
itemflags += "DYNAMIC, ";
}
if (itemMap.isDynamicCount()) {
itemflags += "DYNAMIC-COUNT, ";
}
if (itemMap.isAnimated()) {
itemflags += "ANIMATE, ";
}
Expand Down Expand Up @@ -7544,7 +7554,7 @@ private static void recipePane(final Player player, final ItemMap itemMap) {
if (stack1 != null) {
ItemMeta meta = stack1.getItemMeta();
if (meta != null) {
stack1 = ItemHandler.addLore(stack1, "&9&lDISPLAY: &f" + meta.getDisplayName(), "&7", "&7*Create a recipe that can be used.");
ItemHandler.addLore(stack1, "&9&lDISPLAY: &f" + meta.getDisplayName(), "&7", "&7*Create a recipe that can be used.");
meta.setDisplayName(StringUtils.translateLayout((itemMap.getRecipe().get(0).size() > i ? "&e&l" + itemMap.getRecipe().get(0).get(i) : "&e&lX"), player));
stack1.setItemMeta(meta);

Expand Down

0 comments on commit 8f21c98

Please sign in to comment.