diff --git a/pom.xml b/pom.xml index e3be914..a830ebe 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.sefiraat DankTech - 1.2.1 + 1.2.2 diff --git a/src/main/java/io/github/sefiraat/danktech/finals/ItemStacks.java b/src/main/java/io/github/sefiraat/danktech/finals/ItemStacks.java index 914517d..b9d52ce 100644 --- a/src/main/java/io/github/sefiraat/danktech/finals/ItemStacks.java +++ b/src/main/java/io/github/sefiraat/danktech/finals/ItemStacks.java @@ -33,6 +33,7 @@ public static ItemStack getCell(int level, DankTech plugin) { public static ItemStack getShallowDank(int level, DankTech plugin) { ItemStack dank = createSkull(getDankTexture(level)); makeDank(dank, plugin); + makeShallow(dank, plugin); setDankLevel(dank, plugin, level); ItemMeta m = dank.getItemMeta(); m.setDisplayName(getDankNameBold(level)); @@ -43,6 +44,7 @@ public static ItemStack getShallowDank(int level, DankTech plugin) { public static ItemStack getShallowTrash(int level, DankTech plugin) { ItemStack trash = createSkull(getTrashTexture(level)); makeTrash(trash, plugin); + makeShallow(trash, plugin); setTrashLevel(trash, plugin, level); ItemMeta m = trash.getItemMeta(); m.setDisplayName(getTrashNameBold(level)); diff --git a/src/main/java/io/github/sefiraat/danktech/finals/Messages.java b/src/main/java/io/github/sefiraat/danktech/finals/Messages.java index 3b0852b..9f7530b 100644 --- a/src/main/java/io/github/sefiraat/danktech/finals/Messages.java +++ b/src/main/java/io/github/sefiraat/danktech/finals/Messages.java @@ -25,7 +25,7 @@ private Messages() { public static final String MESSAGE_COMMAND_PACK_NO_EXIST = PREFIX + ERROR + "Yeah, packs only go from 1 to 9 dummy :)"; public static String messageCommandPackGiven(long packID) { - return (PREFIX + SUCCESS + "Pack created. ID: " + packID); + return (PREFIX + SUCCESS + "Dank Pack created. ID: " + packID); } public static String messageCommandTrashGiven(long trashID) { diff --git a/src/main/java/io/github/sefiraat/danktech/implementation/dankpacks/DankPack.java b/src/main/java/io/github/sefiraat/danktech/implementation/dankpacks/DankPack.java index 2b2e3c0..623a542 100644 --- a/src/main/java/io/github/sefiraat/danktech/implementation/dankpacks/DankPack.java +++ b/src/main/java/io/github/sefiraat/danktech/implementation/dankpacks/DankPack.java @@ -24,7 +24,6 @@ private DankPack() { public static ItemStack getDankPack(@Nonnull Integer level, @Nonnull Long packID, @Nonnull DankTech parent, @Nullable Player p) { ItemStack dank = SkullCreator.itemFromBase64(getDankTexture(level)); - if (!parent.getInstance().getDankStorageConfig().contains(CONFIG_GETTER_SECTION_DANK_ID + "." + packID)) { setupSection(parent.getInstance().getDankStorageConfig(), packID, level); parent.saveDankStorageConfig(); diff --git a/src/main/java/io/github/sefiraat/danktech/listeners/CraftListener.java b/src/main/java/io/github/sefiraat/danktech/listeners/CraftListener.java index e2afa1b..3bdf280 100644 --- a/src/main/java/io/github/sefiraat/danktech/listeners/CraftListener.java +++ b/src/main/java/io/github/sefiraat/danktech/listeners/CraftListener.java @@ -20,6 +20,8 @@ import org.bukkit.persistence.PersistentDataType; import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; import static io.github.sefiraat.danktech.finals.Constants.*; import static io.github.sefiraat.danktech.finals.ItemDetails.getDankNameBold; @@ -48,6 +50,16 @@ public void onPreCraft(PrepareItemCraftEvent e) { } ItemStack c = contents[4]; + List cells = new ArrayList<>(); + + cells.add(contents[0]); + cells.add(contents[1]); + cells.add(contents[2]); + cells.add(contents[3]); + cells.add(contents[5]); + cells.add(contents[6]); + cells.add(contents[7]); + cells.add(contents[8]); NamespacedKey levelDankKey = new NamespacedKey(parent.getInstance(), KEY_LEVEL_DANK); NamespacedKey idDankKey = new NamespacedKey(parent.getInstance(), KEY_ID_DANK); @@ -59,23 +71,27 @@ public void onPreCraft(PrepareItemCraftEvent e) { // Core denotes a DANK PACK craft int dankLevel = 1; - long dankID = -1; + long dankID = 0; if (c.getType() == Materials.DANK_CORE_MATERIAL) { - dankID = getNextPackID(parent); + // dankID = getNextPackID(parent); } else { dankLevel = c.getItemMeta().getPersistentDataContainer().get(levelDankKey, PersistentDataType.INTEGER) + 1; dankID = c.getItemMeta().getPersistentDataContainer().get(idDankKey, PersistentDataType.LONG); } - if (cellMatchLevel(dankLevel, contents, parent)) { + if (cellMatchLevel(dankLevel, cells, parent)) { ItemStack r = ItemStacks.getShallowDank(dankLevel, parent); ItemMeta im = r.getItemMeta(); im.getPersistentDataContainer().set(levelDankKey, PersistentDataType.INTEGER, dankLevel); im.getPersistentDataContainer().set(idDankKey, PersistentDataType.LONG, dankID); r.setItemMeta(im); e.getInventory().setResult(r); + } else { + e.getInventory().setResult(new ItemStack(Material.AIR)); } + + } else if (c.getType() == Materials.TRASH_CORE_MATERIAL || c.getItemMeta().getPersistentDataContainer().has(levelTrashKey, PersistentDataType.INTEGER)) { // Core denotes a DANK TRASH craft @@ -89,7 +105,7 @@ public void onPreCraft(PrepareItemCraftEvent e) { trashID = c.getItemMeta().getPersistentDataContainer().get(idTrashKey, PersistentDataType.LONG); } - if (cellMatchLevel(trashLevel, contents, parent)) { + if (cellMatchLevel(trashLevel, cells, parent)) { ItemStack r = ItemStacks.getShallowTrash(trashLevel, parent); ItemMeta im = r.getItemMeta(); im.getPersistentDataContainer().set(levelTrashKey, PersistentDataType.INTEGER, trashLevel); @@ -105,7 +121,7 @@ public void onPreCraft(PrepareItemCraftEvent e) { public void onCraft(CraftItemEvent e) { if (e.getWhoClicked() instanceof Player) { Player p = (Player) e.getWhoClicked(); - if (e.getInventory().getResult() != null) { + if (e.getInventory().getResult() != null && e.getInventory().getResult().getType() != Material.AIR) { ItemStack res = e.getInventory().getResult(); NamespacedKey dankKey = new NamespacedKey(parent.getInstance(), KEY_LEVEL_DANK); boolean hasDankKey = res.getItemMeta().getPersistentDataContainer().has(dankKey, PersistentDataType.INTEGER); @@ -169,25 +185,11 @@ public void onCraft(CraftItemEvent e) { p.sendMessage(Messages.MESSAGE_CRAFT_UPGRADE_TRASH); } } - } else { - p.sendMessage("Result is false?"); } } } - public boolean isResultDank(Material m) { - return m == Materials.DANK_1 || - m == Materials.DANK_2 || - m == Materials.DANK_3 || - m == Materials.DANK_4 || - m == Materials.DANK_5 || - m == Materials.DANK_6 || - m == Materials.DANK_7 || - m == Materials.DANK_8 || - m == Materials.DANK_9; - } - - public boolean cellMatchLevel(Integer level, ItemStack[] itemStacks, DankTech plugin) { + public boolean cellMatchLevel(Integer level, List itemStacks, DankTech plugin) { NamespacedKey keyLevel = new NamespacedKey(plugin,"cell-level"); for (ItemStack i : itemStacks) { if (i.hasItemMeta() && i.getItemMeta().getPersistentDataContainer().has(keyLevel,PersistentDataType.INTEGER)) { @@ -195,6 +197,8 @@ public boolean cellMatchLevel(Integer level, ItemStack[] itemStacks, DankTech pl if (!stackLevel.equals(level)) { return false; } + } else { + return false; } } return true; diff --git a/src/main/java/io/github/sefiraat/danktech/listeners/ItemRightClickListener.java b/src/main/java/io/github/sefiraat/danktech/listeners/ItemRightClickListener.java index 4da7259..d02aa3c 100644 --- a/src/main/java/io/github/sefiraat/danktech/listeners/ItemRightClickListener.java +++ b/src/main/java/io/github/sefiraat/danktech/listeners/ItemRightClickListener.java @@ -34,6 +34,7 @@ import static io.github.sefiraat.danktech.implementation.gui.DankGUI.getDankGUI; import static io.github.sefiraat.danktech.implementation.gui.DankTrashGUI.getTrashGUI; import static io.github.sefiraat.danktech.misc.Config.*; +import static io.github.sefiraat.danktech.misc.ContainerStorage.isShallow; public class ItemRightClickListener implements Listener { @@ -54,12 +55,14 @@ public void onRightClick(PlayerInteractEvent e) { return; } if (ContainerStorage.isDank(i, parent.getInstance())) { - e.setCancelled(true); handleDank(e, i, p); + e.setCancelled(true); + return; } if (ContainerStorage.isTrash(i, parent.getInstance())) { - e.setCancelled(true); handleTrash(e, i, p); + e.setCancelled(true); + return; } } } @@ -72,6 +75,9 @@ private void handleDank(PlayerInteractEvent e, ItemStack i, Player p) { if (ContainerStorage.getDankId(i, parent) == 0) { replaceDank(i, p, true); return; + } else if (isShallow(i, parent)) { + replaceAndUpgradeDank(i, p, false); + return; } if (p.isSneaking() && canPlaceBlacklist(p)) { switch (e.getAction()) { @@ -121,10 +127,9 @@ private boolean isOldDank(ItemStack i) { private void replaceDank(ItemStack i, Player player, boolean isNew) { - ContainerStorage.getDankLevel(i, parent); - int level = ContainerStorage.getDankLevel(i, parent); long id = 0; + if (isNew) { id = getNextPackID(parent); } else { @@ -142,6 +147,25 @@ private void replaceDank(ItemStack i, Player player, boolean isNew) { player.sendMessage(Messages.messageCommandPackUpdated(id)); } + private void replaceAndUpgradeDank(ItemStack i, Player player, boolean isNew) { + + int level = ContainerStorage.getDankLevel(i, parent); + long id = ContainerStorage.getDankId(i, parent); + i.setAmount(0); + + ConfigurationSection c = parent.getDankStorageConfig().getConfigurationSection(CONFIG_GETTER_SECTION_DANK_ID + "." + id); + c.set(CONFIG_GETTER_VAL_LEVEL, level); + c.set(CONFIG_GETTER_VAL_SLOT + level + "." + CONFIG_GETTER_VAL_STACK, null); + c.set(CONFIG_GETTER_VAL_SLOT + level + "." + CONFIG_GETTER_VAL_VOLUME , 0); + ItemStack dank = DankPack.getDankPack(level, id, parent, player); + ItemMeta m = dank.getItemMeta(); + m.setDisplayName(getDankNameBold(level)); + m.setLore(ItemDetails.getDankLore(level, id, null)); + dank.setItemMeta(m); + player.getInventory().setItem(player.getInventory().getHeldItemSlot(), dank); + player.sendMessage(Messages.MESSAGE_CRAFT_UPGRADE_PACK); + } + private void replaceTrash(ItemStack i, Player player, boolean isNew) { ContainerStorage.getTrashLevel(i, parent); diff --git a/src/main/java/io/github/sefiraat/danktech/misc/ContainerStorage.java b/src/main/java/io/github/sefiraat/danktech/misc/ContainerStorage.java index b3d00ec..7337c09 100644 --- a/src/main/java/io/github/sefiraat/danktech/misc/ContainerStorage.java +++ b/src/main/java/io/github/sefiraat/danktech/misc/ContainerStorage.java @@ -55,6 +55,16 @@ public static void removeData(ItemStack i, NamespacedKey key) { i.setItemMeta(im); } + public static boolean isShallow(ItemStack i, DankTech plugin) { + NamespacedKey key = new NamespacedKey(plugin.getInstance(),"is-shallow"); + return containerHasData(i, key, PersistentDataType.INTEGER); + } + + public static void makeShallow(ItemStack i, DankTech plugin) { + NamespacedKey key = new NamespacedKey(plugin.getInstance(),"is-shallow"); + setData(i, key, 1); + } + public static boolean isDank(ItemStack i, DankTech plugin) { NamespacedKey key = new NamespacedKey(plugin.getInstance(),"is-dank"); return containerHasData(i, key, PersistentDataType.INTEGER); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b597a9c..599a9c7 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,3 +5,27 @@ GENERAL: - "ExampleWorld" BLACKLISTED_WORLDS_PICKUP_ITEMS: - "ExampleWorld" +TEXTS_NOT_YET_IMPLEMENTED: + MESSAGES: + COMMANDS: + MESSAGE_COMMAND_SUBCOMMAND: "Please select a valid sub command" + MESSAGE_COMMAND_SELECT_ITEM: "Please select an item type" + MESSAGE_COMMAND_PACK_NO_EXIST: "Yeah, packs only go from 1 to 9 dummy :)" + MESSAGE_COMMAND_DANK_PACK_GIVEN: + MESSAGE_COMMAND_TRASH_PACK_GIVEN: + MESSAGE_COMMAND_PACK_UPDATED: + EVENTS: + MESSAGE_EVENT_OPEN_DANK_PACK: + MESSAGE_EVENT_OPEN_TRASH_PACK: + MESSAGE_EVENT_INPUT_EXISTING: + MESSAGE_EVENT_INPUT_THIS_DANK: + MESSAGE_EVENT_WITHDRAW_NO_SPACE: + MESSAGE_EVENT_SLOT_NOT_ASSIGNED: + MESSAGE_EVENT_SLOT_CANT_PLACE: + MESSAGE_EVENT_SLOT_NO_MORE_ITEMS: + MESSAGE_EVENT_SLOT_CHANGED: + CRAFTING: + MESSAGE_CRAFT_NEW_PACK: + MESSAGE_CRAFT_UPGRADE_PACK: + MESSAGE_CRAFT_NEW_TRASH: + MESSAGE_CRAFT_UPGRADE_TRASH: \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 77b5915..a638e11 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: DankTech -version: 1.2.1 +version: 1.2.2 main: io.github.sefiraat.danktech.DankTech api-version: 1.16 softdepend: