From 95833a46228762f4d05a8a962c7603a6fdc26b40 Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 17 Jul 2020 10:24:43 -0500 Subject: [PATCH 01/12] 1.16.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 43226e7..9b11b32 100644 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,7 @@ org.spigotmc spigot - 1.15 + 1.16.1 provided From 883db72391c9d80ef4f0e96639c9bb8041a7f059 Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 10 Jul 2020 11:44:38 +0200 Subject: [PATCH 02/12] Change lore when removing category from Kit --- .../java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java b/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java index 20bf5cb..fc6b4f2 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java +++ b/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java @@ -84,6 +84,8 @@ public class KitGeneralOptionsGui extends Gui { guiManager.showGUI(event.player, gui); } else if (event.clickType == ClickType.RIGHT) { kit.setCategory(null); + updateItemLore(event.slot, plugin.getLocale().getMessage("interface.kitoptions.categorylore") + .processPlaceholder("category", kit.getCategory() == null ? "none" : kit.getCategory().getName()).getMessage().split("\\|")); } }); From eff33eccedb9ab1ceff2e493711c0f48390561ea Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 17 Jul 2020 20:26:49 +0200 Subject: [PATCH 03/12] fix display error for chance in item lores --- src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java index bc8d74c..d010b25 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java +++ b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java @@ -350,6 +350,7 @@ public class KitEditorGui extends DoubleGui { switch (action) { case CHANCE_UP: case CHANCE_DOWN: + System.out.println("chance"); if (action == Action.CHANCE_UP) item.setChance(item.getChance() >= 100 ? 5 : (item.getChance() + 5)); else @@ -422,7 +423,8 @@ public class KitEditorGui extends DoubleGui { if (meta.hasLore()) itemLore = meta.getLore(); else itemLore = new ArrayList<>(); itemLore.add(TextUtils.convertToInvisibleLoreString("----")); - itemLore.add(ChatColor.GRAY.toString() + plugin.getLocale().getMessage("general.type.chance") + ": " + ChatColor.GOLD.toString() + item.getChance() + "%"); + itemLore.add(ChatColor.GRAY.toString() + plugin.getLocale().getMessage("general.type.chance").getMessage().replaceFirst("^" + ChatColor.RESET.toString(), "") + + ": " + ChatColor.GOLD.toString() + item.getChance() + "%"); //TODO use a placeholder message in locales if (isInFunction) { itemLore.addAll(Arrays.asList(plugin.getLocale().getMessage("interface.kiteditor.itemfunctionlore") .processPlaceholder("item", item.getDisplayItem() == null ? "" : item.getDisplayItem().name()) From 45abf15c4c6920117ca31590be11dad698eb915f Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 17 Jul 2020 22:45:26 +0200 Subject: [PATCH 04/12] remove debug --- src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java index d010b25..aaa7922 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java +++ b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java @@ -350,7 +350,6 @@ public class KitEditorGui extends DoubleGui { switch (action) { case CHANCE_UP: case CHANCE_DOWN: - System.out.println("chance"); if (action == Action.CHANCE_UP) item.setChance(item.getChance() >= 100 ? 5 : (item.getChance() + 5)); else From 8c9f756e6baecf612d3728696ddd91cd65812498 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 20 Jul 2020 14:55:27 +0200 Subject: [PATCH 05/12] Adjust kitAmount for Roulette Option --- .../com/songoda/ultimatekits/kit/Kit.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index 8b2d74b..9c9ddb6 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -84,7 +84,7 @@ public class Kit { private boolean hasRoom(Player player, int itemAmount) { int space = 0; - for (ItemStack content : player.getInventory().getContents()) { + for (ItemStack content : player.getInventory().getStorageContents()) { if (content == null) { space++; } @@ -285,7 +285,15 @@ public class Kit { } private boolean giveKit(Player player, int itemAmount, int kitAmount) { - if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player, itemAmount)) { + List innerContents = new ArrayList<>(getContents()); + int kitSize = innerContents.size(); + + // Amount of items from the kit to give to the player. + if (kitAnimation == KitAnimation.ROULETTE) itemAmount = 1; //TODO how about kitAmount > 1? generateRandomItem() will only give 1 random item instead of kitAmount + int itemGiveAmount = itemAmount > 0 ? itemAmount : kitSize; + if (kitAmount > 0) itemGiveAmount = itemGiveAmount * kitAmount; + + if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player, itemGiveAmount)) { plugin.getLocale().getMessage("event.claim.full").sendPrefixedMessage(player); return false; } @@ -293,13 +301,6 @@ public class Kit { if (Settings.SOUNDS_ENABLED.getBoolean() && kitAnimation == KitAnimation.NONE) CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F); - List innerContents = new ArrayList<>(getContents()); - int kitSize = innerContents.size(); - - // Amount of items from the kit to give to the player. - int itemGiveAmount = itemAmount > 0 ? itemAmount : kitSize; - if (kitAmount > 0) itemGiveAmount = itemGiveAmount * kitAmount; - return generateRandomItem(innerContents, itemGiveAmount, player); } From d9311737339808c5215834b6ef4a9b8a6e260977 Mon Sep 17 00:00:00 2001 From: Brianna Date: Mon, 20 Jul 2020 09:28:00 -0500 Subject: [PATCH 06/12] Moved to NBT from Invisible Strings. --- .../ultimatekits/gui/KitEditorGui.java | 5 +- .../ultimatekits/gui/KitSelectorGui.java | 3 +- .../ultimatekits/gui/PreviewKitGui.java | 2 +- .../handlers/DisplayItemHandler.java | 27 +++++-- .../com/songoda/ultimatekits/kit/Kit.java | 3 +- .../com/songoda/ultimatekits/kit/KitItem.java | 78 ++++++++++--------- 6 files changed, 70 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java index aaa7922..845fa17 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java +++ b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java @@ -338,7 +338,8 @@ public class KitEditorGui extends DoubleGui { ItemMeta meta = itemStack.getItemMeta(); List newLore = new ArrayList<>(); for (String line : meta.getLore()) { - if (TextUtils.convertFromInvisibleString(line).equals("----")) break; + if (line.contains("Moveable")) continue; + if (line.equals(TextUtils.formatText("&8----"))) break; newLore.add(line); } meta.setLore(newLore); @@ -421,7 +422,7 @@ public class KitEditorGui extends DoubleGui { if (meta.hasLore()) itemLore = meta.getLore(); else itemLore = new ArrayList<>(); - itemLore.add(TextUtils.convertToInvisibleLoreString("----")); + itemLore.add(TextUtils.formatText("&8----")); itemLore.add(ChatColor.GRAY.toString() + plugin.getLocale().getMessage("general.type.chance").getMessage().replaceFirst("^" + ChatColor.RESET.toString(), "") + ": " + ChatColor.GOLD.toString() + item.getChance() + "%"); //TODO use a placeholder message in locales if (isInFunction) { diff --git a/src/main/java/com/songoda/ultimatekits/gui/KitSelectorGui.java b/src/main/java/com/songoda/ultimatekits/gui/KitSelectorGui.java index 86b0c89..07d7a75 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/KitSelectorGui.java +++ b/src/main/java/com/songoda/ultimatekits/gui/KitSelectorGui.java @@ -144,8 +144,7 @@ public class KitSelectorGui extends Gui { .processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage(); setButton(row, col, GuiUtils.createButtonItem( - kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK, - TextUtils.convertToInvisibleString(kitItem + ":") + kitTitle, + kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK,kitTitle, getKitLore(kit)), event -> { if (event.clickType == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) { diff --git a/src/main/java/com/songoda/ultimatekits/gui/PreviewKitGui.java b/src/main/java/com/songoda/ultimatekits/gui/PreviewKitGui.java index 74df10b..fca5689 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/PreviewKitGui.java +++ b/src/main/java/com/songoda/ultimatekits/gui/PreviewKitGui.java @@ -118,7 +118,7 @@ public class PreviewKitGui extends Gui { || (Settings.DONT_PREVIEW_COMMANDS.getBoolean() && item.getType() == Material.PAPER && item.getItemMeta().hasDisplayName() - && item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command")))) { + && item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command").getMessage()))) { setItem(row, col, AIR); } else if (item.getAmount() <= 64) { // display item diff --git a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java index 1efdba5..c894764 100644 --- a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java +++ b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java @@ -1,5 +1,7 @@ package com.songoda.ultimatekits.handlers; +import com.songoda.core.nms.NmsManager; +import com.songoda.core.nms.nbt.NBTItem; import com.songoda.core.utils.TextUtils; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; @@ -15,6 +17,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; +import java.util.Collections; import java.util.List; /** @@ -62,19 +65,24 @@ public class DisplayItemHandler { if (!kitBlockData.isDisplayingItems()) e.remove(); - int inum = Integer.parseInt(i.getItemStack().getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "")) + 1; + + NBTItem nbtItem = NmsManager.getNbt().of(i.getItemStack()); + int inum = nbtItem.has("num") ? nbtItem.getNBTObject("num").asInt() + 1 : 0; + if (inum > list.size()) inum = 1; - ItemStack is = list.get(inum - 1); + ItemStack is = list.get(inum); if (kitBlockData.isItemOverride()) { if (kit.getDisplayItem() != null) is = kit.getDisplayItem().getItem(); } - ItemMeta meta = is.getItemMeta(); is.setAmount(1); - meta.setDisplayName(TextUtils.convertToInvisibleString(Integer.toString(inum))); + ItemMeta meta = is.getItemMeta(); + meta.setDisplayName(null); is.setItemMeta(meta); - i.setItemStack(is); + nbtItem = NmsManager.getNbt().of(is); + nbtItem.set("num", inum); + i.setItemStack(nbtItem.finish()); i.setPickupDelay(9999); return; } @@ -83,13 +91,18 @@ public class DisplayItemHandler { ItemStack is = list.get(0); is.setAmount(1); ItemMeta meta = is.getItemMeta(); - meta.setDisplayName(TextUtils.convertFromInvisibleString("0")); + meta.setLore(Collections.singletonList("Display Item")); is.setItemMeta(meta); + + NBTItem nbtItem = NmsManager.getNbt().of(is); + nbtItem.set("num", 0); + Bukkit.getScheduler().runTask(instance, () -> { - Item item = location.getWorld().dropItem(location.add(0, 1, 0), list.get(0)); + Item item = location.getWorld().dropItem(location.add(0, 1, 0), nbtItem.finish()); Vector vec = new Vector(0, 0, 0); item.setVelocity(vec); item.setPickupDelay(9999); + item.setCustomName(null); item.setMetadata("US_EXEMPT", new FixedMetadataValue(UltimateKits.getInstance(), true)); item.setMetadata("displayItem", new FixedMetadataValue(UltimateKits.getInstance(), true)); item.setMetadata("betterdrops_ignore", new FixedMetadataValue(UltimateKits.getInstance(), true)); diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index 9c9ddb6..87cfb02 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -217,7 +217,8 @@ public class Kit { ItemMeta meta = is.getItemMeta(); List newLore = new ArrayList<>(); for (String line : meta.getLore()) { - if (TextUtils.convertFromInvisibleString(line).equals("----")) break; + if (line.contains("Moveable")) continue; + if (line.equals(TextUtils.formatText("&8----"))) break; newLore.add(line); } meta.setLore(newLore); diff --git a/src/main/java/com/songoda/ultimatekits/kit/KitItem.java b/src/main/java/com/songoda/ultimatekits/kit/KitItem.java index e8b3993..5401306 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/KitItem.java +++ b/src/main/java/com/songoda/ultimatekits/kit/KitItem.java @@ -1,5 +1,7 @@ package com.songoda.ultimatekits.kit; +import com.songoda.core.nms.NmsManager; +import com.songoda.core.nms.nbt.NBTItem; import com.songoda.core.utils.TextUtils; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.type.KitContent; @@ -13,9 +15,7 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.*; public class KitItem { @@ -32,26 +32,13 @@ public class KitItem { } public KitItem(ItemStack item, String line) { - ItemStack itemStack = item.clone(); - ItemMeta meta = itemStack.getItemMeta(); - if (itemStack.hasItemMeta() && meta.hasDisplayName() && meta.getDisplayName().contains(";")) { - translateLine(meta.getDisplayName()); - } + translateTags(item); processContent(line, null); } public KitItem(ItemStack item) { - ItemStack itemStack = item.clone(); - ItemMeta meta = itemStack.getItemMeta(); - if (itemStack.hasItemMeta() && meta.hasDisplayName() && meta.getDisplayName().contains(";")) { - String translated = translateLine(meta.getDisplayName()).replace(TextUtils.convertToInvisibleString("faqe"), ""); - if (translated.equalsIgnoreCase(WordUtils.capitalize(item.getType().toString().toLowerCase().replace("_", " ")))) - meta.setDisplayName(null); - else - meta.setDisplayName(translated); - itemStack.setItemMeta(meta); - } - processContent(null, itemStack); + translateTags(item); + processContent(null, item.clone()); } private void processContent(String line, ItemStack item) { @@ -65,6 +52,18 @@ public class KitItem { } } + private void translateTags(ItemStack item) { + NBTItem nbtItem = NmsManager.getNbt().of(item); + if (nbtItem.has("chance")) + chance = nbtItem.getNBTObject("chance").asDouble(); + if (nbtItem.has("display-item")) + displayItem = Material.valueOf(nbtItem.getNBTObject("display-item").asString()); + if (nbtItem.has("display-name")) + displayName = nbtItem.getNBTObject("display-name").asString(); + if (nbtItem.has("display-lore")) + displayLore = nbtItem.getNBTObject("display-lore").asString(); + } + private String translateLine(String line) { String[] lineSplit = line.trim().split(";", 2); String[] kitOptions = lineSplit[0].replace(String.valueOf(ChatColor.COLOR_CHAR), "").split("~"); @@ -94,7 +93,19 @@ public class KitItem { return lineSplit[1]; } - private String compileOptions() { + private ItemStack compileOptions(ItemStack item) { + NBTItem nbtItem = NmsManager.getNbt().of(item); + if (chance != 0) + nbtItem.set("chance", chance); + if (displayItem != null) + nbtItem.set("display-item", displayItem.name()); + if (displayName != null) + nbtItem.set("display-name", displayName); + if (displayLore != null) + nbtItem.set("display-lore", displayLore); + return nbtItem.finish(); + } + private String compileOptionsText() { String line = ""; if (chance != 0) line += "chance:" + chance; @@ -114,7 +125,7 @@ public class KitItem { public String getSerialized() { if (chance == 0 && displayItem == null && displayName == null && displayLore == null) return this.content.getSerialized(); - return compileOptions() + ";" + this.content.getSerialized(); + return compileOptionsText() + ";" + this.content.getSerialized(); } public double getChance() { @@ -155,17 +166,15 @@ public class KitItem { public ItemStack getMoveableItem() { if (content == null) return null; - ItemStack item = content.getItemForDisplay(); + ItemStack item = content.getItemForDisplay().clone(); ItemMeta meta = item.getItemMeta(); - if (chance != 0 || displayItem != null || displayName != null || displayLore != null) { - String capitalizedName = meta.hasDisplayName() ? meta.getDisplayName() : - WordUtils.capitalize(item.getType().toString().toLowerCase().replace("_", " ")); - if (capitalizedName.contains(TextUtils.convertToInvisibleString(";faqe"))) - capitalizedName = meta.getDisplayName().split(TextUtils.convertToInvisibleString(";faqe"))[1]; - meta.setDisplayName(TextUtils.convertToInvisibleString(compileOptions() + ";faqe") + capitalizedName); - } + List lore = meta.hasLore() && meta.getLore().get(0).equals(TextUtils.formatText("&8&oMoveable")) + ? new ArrayList<>() : new ArrayList<>(Collections.singletonList(TextUtils.formatText("&8&oMoveable"))); + if (meta.hasLore()) + lore.addAll(meta.getLore()); + meta.setLore(lore); item.setItemMeta(meta); - return item; + return compileOptions(item); } public ItemStack getItemForDisplay() { @@ -181,19 +190,18 @@ public class KitItem { meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName)); } if (displayLore != null) { - meta.setLore(Arrays.asList(ChatColor.translateAlternateColorCodes('&', displayLore))); + meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', displayLore))); } if (UltimateKits.getInstance().getConfig().getBoolean("Main.Display Chance In Preview")) { ArrayDeque lore; - if (meta.hasLore()) { + if (meta.hasLore()) lore = new ArrayDeque<>(meta.getLore()); - } else { + else lore = new ArrayDeque<>(); - } if (!lore.isEmpty()) lore.addFirst(""); - lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance") + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%"); + lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance").getMessage() + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%"); meta.setLore(new ArrayList<>(lore)); } From c23802ec6983d0272d2c7be06c50fd05ec782de9 Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 17 Jul 2020 21:09:05 -0500 Subject: [PATCH 07/12] Count failed chances as successful attempts. --- src/main/java/com/songoda/ultimatekits/kit/Kit.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index 87cfb02..d0a2f73 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -306,7 +306,6 @@ public class Kit { } private boolean generateRandomItem(List innerContents, int itemGiveAmount, Player player) { - if (innerContents.size() != itemGiveAmount || kitAnimation != KitAnimation.NONE) Collections.shuffle(innerContents); @@ -314,8 +313,8 @@ public class Kit { if (itemGiveAmount == 0) break; double ch = item.getChance() == 0 ? 100 : item.getChance(); double rand = Math.random() * 100; + itemGiveAmount--; if (rand < ch || ch == 100) { - itemGiveAmount--; ItemStack parseStack = item.getContent().process(player); if (kitAnimation != KitAnimation.NONE) { From 9574a237d0e846acf3c0a4da6a0053bb7cc6699d Mon Sep 17 00:00:00 2001 From: Retro Pronghorn Date: Thu, 30 Apr 2020 22:25:11 +0000 Subject: [PATCH 08/12] fix(Roulette Kit): Don't check for entire space of kit free when using the kit roulette option. --- src/main/java/com/songoda/ultimatekits/kit/Kit.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index d0a2f73..157b449 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -90,6 +90,9 @@ public class Kit { } } + // Since roulette only gives one item, we don't need to check if the user has room for the whole kit. + if (kitAnimation == KitAnimation.ROULETTE && space >= 1) + return true; return space >= itemAmount; } From a54eddc3e7ddf6c3d58a6978c386ef36a5b52924 Mon Sep 17 00:00:00 2001 From: Brianna Date: Mon, 20 Jul 2020 09:28:47 -0500 Subject: [PATCH 09/12] Removed autosave feature. --- src/main/java/com/songoda/ultimatekits/UltimateKits.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/songoda/ultimatekits/UltimateKits.java b/src/main/java/com/songoda/ultimatekits/UltimateKits.java index 0e762e6..9a21c44 100644 --- a/src/main/java/com/songoda/ultimatekits/UltimateKits.java +++ b/src/main/java/com/songoda/ultimatekits/UltimateKits.java @@ -182,7 +182,6 @@ public class UltimateKits extends SongodaPlugin { displayItemHandler.start(); particleHandler.start(); - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> saveKits(false), 6000, 6000); } @Override From 5a1643c59d386e3b46de4985344e0f6c8c8a0c29 Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 17 Jul 2020 20:47:29 -0500 Subject: [PATCH 10/12] Moved kit keys to nbt. --- .../songoda/ultimatekits/UltimateKits.java | 4 +- .../com/songoda/ultimatekits/key/Key.java | 56 +++++++++++-------- .../com/songoda/ultimatekits/kit/Kit.java | 28 +++++----- .../ultimatekits/settings/Settings.java | 2 + src/main/resources/en_US.lang | 29 ++++------ 5 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/UltimateKits.java b/src/main/java/com/songoda/ultimatekits/UltimateKits.java index 9a21c44..52b1e43 100644 --- a/src/main/java/com/songoda/ultimatekits/UltimateKits.java +++ b/src/main/java/com/songoda/ultimatekits/UltimateKits.java @@ -301,8 +301,9 @@ public class UltimateKits extends SongodaPlugin { for (String keyName : keyFile.getConfigurationSection("Keys").getKeys(false)) { int amt = keyFile.getInt("Keys." + keyName + ".Item Amount"); int kitAmount = keyFile.getInt("Keys." + keyName + ".Amount of kit received"); + boolean enchanted = keyFile.getBoolean("Keys." + keyName + ".Enchanted"); - Key key = new Key(keyName, amt, kitAmount); + Key key = new Key(keyName, amt, kitAmount, enchanted); keyManager.addKey(key); } } @@ -507,6 +508,7 @@ public class UltimateKits extends SongodaPlugin { keyFile.set("Keys.Ultra.Amount of kit received", 1); keyFile.set("Keys.Insane.Item Amount", -1); keyFile.set("Keys.Insane.Amount of kit received", 2); + keyFile.set("Keys.Insane.Enchanted", true); } private void checkCrateDefaults() { diff --git a/src/main/java/com/songoda/ultimatekits/key/Key.java b/src/main/java/com/songoda/ultimatekits/key/Key.java index 859e6f3..b538148 100644 --- a/src/main/java/com/songoda/ultimatekits/key/Key.java +++ b/src/main/java/com/songoda/ultimatekits/key/Key.java @@ -1,57 +1,62 @@ package com.songoda.ultimatekits.key; +import com.songoda.core.nms.NmsManager; +import com.songoda.core.nms.nbt.NBTItem; +import com.songoda.core.utils.ItemUtils; import com.songoda.core.utils.TextUtils; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; +import com.songoda.ultimatekits.settings.Settings; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; -import org.bukkit.ChatColor; public class Key { // The name of the key. - private String name; + private final String name; // The amount of items this key will give you. -1 is all; - private int amount; + private final int amount; + + // Should the key be enchanted? + private final boolean enchanted; // The amount of kit given when the key is used. - private int kitAmount; + private final int kitAmount; - public Key(String name, int amount, int kitAmount) { + public Key(String name, int amount, int kitAmount, boolean enchanted) { this.name = name; this.amount = amount; this.kitAmount = kitAmount; + this.enchanted = enchanted; } - - public ItemStack getKeyItem(Kit kit, int amt) { + public ItemStack getKeyItem(Kit kit, int amount) { UltimateKits plugin = UltimateKits.getInstance(); - ItemStack is = new ItemStack(Material.TRIPWIRE_HOOK, amt); + ItemStack item = Settings.KEY_MATERIAL.getMaterial().getItem(); + item.setAmount(amount); - String kitName; - if (kit != null) - kitName = TextUtils.formatText(kit.getName(), true); - else - kitName = "Any"; + String kitName = kit != null ? TextUtils.formatText(kit.getName(), true) + : plugin.getLocale().getMessage("general.type.any").getMessage(); - ItemMeta meta = is.getItemMeta(); + ItemMeta meta = item.getItemMeta(); meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title") .processPlaceholder("kit", kitName).getMessage()); - meta.addEnchant(Enchantment.DURABILITY, 1, true); + if (enchanted) + ItemUtils.addGlow(item); + List lore = new ArrayList<>(); - lore.add(ChatColor.YELLOW + name + " " + ChatColor.WHITE + "Key"); + lore.add(plugin.getLocale().getMessage("interface.key.name") + .processPlaceholder("name", name).getMessage()); String desc1 = plugin.getLocale().getMessage("interface.key.description1") .processPlaceholder("kit", kitName).getMessage(); - if (kitName.equals("Any")) + if (kit == null) desc1 = desc1.replaceAll("\\[.*?\\]", ""); else desc1 = desc1.replace("[", "").replace("]", ""); @@ -66,12 +71,15 @@ public class Key { .processPlaceholder("amt", this.kitAmount).getMessage()); meta.setLore(lore); - is.setItemMeta(meta); + item.setItemMeta(meta); - return is; + NBTItem nbtItem = NmsManager.getNbt().of(item); + nbtItem.set("key", name); + nbtItem.set("kit", kit == null ? "ANY" : kit.getName()); + + return nbtItem.finish(); } - public String getName() { return name; } @@ -83,4 +91,8 @@ public class Key { public int getKitAmount() { return kitAmount; } + + public boolean isEnchanted() { + return enchanted; + } } diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index 157b449..36c8e08 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -7,6 +7,8 @@ import com.songoda.core.configuration.Config; import com.songoda.core.gui.Gui; import com.songoda.core.gui.GuiManager; import com.songoda.core.hooks.EconomyManager; +import com.songoda.core.nms.NmsManager; +import com.songoda.core.nms.nbt.NBTItem; import com.songoda.core.utils.ItemUtils; import com.songoda.core.utils.TextUtils; import com.songoda.ultimatekits.UltimateKits; @@ -99,27 +101,25 @@ public class Kit { public void processKeyUse(Player player) { ItemStack item = player.getItemInHand(); - if (item.getType() != Material.TRIPWIRE_HOOK || !item.hasItemMeta()) { + NBTItem nbtItem = NmsManager.getNbt().of(item); + + if (!nbtItem.has("key") || !nbtItem.has("kit")) return; - } - Key key = plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", "")); - // This is some legacy support crap. - String title = plugin.getLocale().getMessage("interface.key.title") - .processPlaceholder("kit", name).getMessage(); - if (title.startsWith(ChatColor.COLOR_CHAR + "f")) - title = title.substring(2); + String keyName = nbtItem.getNBTObject("key").asString(); + String kitName = nbtItem.getNBTObject("kit").asString(); - String titleAny = plugin.getLocale().getMessage("interface.key.title") - .processPlaceholder("kit", "Any").getMessage(); - if (titleAny.startsWith(ChatColor.COLOR_CHAR + "f")) - titleAny = titleAny.substring(2); + boolean any = kitName.equals("ANY"); + Key key = plugin.getKeyManager().getKey(keyName); - if (!item.getItemMeta().getDisplayName().equals(title) - && !item.getItemMeta().getDisplayName().equals(titleAny)) { + if (key == null && !any) + return; + + if (!any && !kitName.equals(name)) { plugin.getLocale().getMessage("event.crate.wrongkey").sendPrefixedMessage(player); return; } + if (giveKit(player, key)) { plugin.getLocale().getMessage("event.key.success") .processPlaceholder("kit", name).sendPrefixedMessage(player); diff --git a/src/main/java/com/songoda/ultimatekits/settings/Settings.java b/src/main/java/com/songoda/ultimatekits/settings/Settings.java index 1a5785a..8b8346f 100644 --- a/src/main/java/com/songoda/ultimatekits/settings/Settings.java +++ b/src/main/java/com/songoda/ultimatekits/settings/Settings.java @@ -22,6 +22,8 @@ public class Settings { public static final ConfigSetting CHANCE_IN_PREVIEW = new ConfigSetting(config, "Main.Display Chance In Preview", true); public static final ConfigSetting CURRENCY_SYMBOL = new ConfigSetting(config, "Main.Currency Symbol", "$"); public static final ConfigSetting STARTER_KIT = new ConfigSetting(config, "Main.Starter Kit", "none"); + public static final ConfigSetting KEY_MATERIAL = new ConfigSetting(config, "Main.Key Material", "TRIPWIRE_HOOK", + "What type of material should be used for kit keys?"); public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(), "Which economy plugin should be used?", diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index b355918..e82214b 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -10,9 +10,8 @@ general: money: '&6Money' link: '&9Link' free: Free - + any: Any # Interface Messages - interface: selector: kit: '&c%kit%' @@ -51,19 +50,19 @@ interface: 'no': '&c&lNo' key: title: '&5%kit% &fKit Key' - description1: '&rRight-Click on [a ]&c&l%kit%&r kit' - description2: '&rand receive its contents!' - description3: '&rand receive some of its contents!' - description4: '&rGives kit &c&l%amt% &rtimes.' + name: '&e%name% &fKey' + description1: '&fRight-Click on [a ]&c&l%kit%&f kit' + description2: '&fand receive its contents!' + description3: '&fand receive some of its contents!' + description4: '&fGives kit &c&l%amt% &ftimes.' crate: title: '&5%kit% &f%crate% Crate' - description1: '&rRight-Click to open' - description2: '&rand receive its contents!' - description3: '&rand receive some of its contents!' - description4: '&rLeft-Click to preview' - -# Administrative interfaces + description1: '&fRight-Click to open' + description2: '&fand receive its contents!' + description3: '&fand receive some of its contents!' + description4: '&fLeft-Click to preview' + # Administrative interfaces kitblock: title: '&8This contains &a%kit%' switchtype: '&5&lSwitch kit type' @@ -164,9 +163,7 @@ interface: switchtokitfunctionslore: '&7Click to switch back|&7to the kit functions.' itemfunctionlore: '&7Display Item: &6%item%|&7Display Name: &6%name%|&7Display Lore: &6%lore%||&7Left-Click: &6To set a display item.|&7Middle-Click: &6To set a display name.|&7Right-Click: &6To set display lore.|&7Shift-Click: &6To set chance.||&7Display options only show up on display.|&7This can be useful if you want to explain|&7What an item does without putting it in the|&7permanent lore.||&6Leave function mode to move items.' saved: '&8Changes to &a%kit% &8saved successfully.' - # Command Messages - command: general: noperms: '&cYou do not have permission to do that!' @@ -179,9 +176,7 @@ command: crate: given: '&9Gave &7%player% &9crate &7%crate% &9for kit &7%kit%.' doesntexist: '&cThis crate is not loaded.' - # Event Messages - event: preview: kit: '&9You are now previewing kit &7%kit%&9.' @@ -208,4 +203,4 @@ event: cancelled: '&cPurchase Canceled.' key: given: '&9You have received a &a%kit% &9kit key.' - success: '&9You have successfully redeemed a key for the kit &7%kit%&9.' \ No newline at end of file + success: '&9You have successfully redeemed a key for the kit &7%kit%&9.' From f0a124857f446301c155dd0d47a830c7df530fdf Mon Sep 17 00:00:00 2001 From: Brianna Date: Mon, 20 Jul 2020 13:23:49 -0500 Subject: [PATCH 11/12] Fix issue with Kit Display. --- .../com/songoda/ultimatekits/handlers/DisplayItemHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java index c894764..e4f9f1a 100644 --- a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java +++ b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java @@ -67,11 +67,11 @@ public class DisplayItemHandler { NBTItem nbtItem = NmsManager.getNbt().of(i.getItemStack()); - int inum = nbtItem.has("num") ? nbtItem.getNBTObject("num").asInt() + 1 : 0; + int inum = nbtItem.has("num") ? nbtItem.getNBTObject("num").asInt() + 1 : 1; if (inum > list.size()) inum = 1; - ItemStack is = list.get(inum); + ItemStack is = list.get(inum - 1); if (kitBlockData.isItemOverride()) { if (kit.getDisplayItem() != null) is = kit.getDisplayItem().getItem(); From 56008872b14365d4a7857d99090b1e1594dde83a Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 17 Jul 2020 21:13:24 -0500 Subject: [PATCH 12/12] version 2.6.7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9b11b32..f4bc658 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda UltimateKits 4.0.0 - 2.6.6 + 2.6.7 clean install UltimateKits-${project.version}