Skip to content

Commit

Permalink
Shallow upgrading and catching all caught
Browse files Browse the repository at this point in the history
1.8 - 1.13 servers should work correctly now
  • Loading branch information
BuildTools committed May 12, 2021
1 parent ae15e21 commit 530431c
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.sefiraat</groupId>
<artifactId>DankTech</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +50,16 @@ public void onPreCraft(PrepareItemCraftEvent e) {
}

ItemStack c = contents[4];
List<ItemStack> 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);
Expand All @@ -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

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -169,32 +185,20 @@ 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<ItemStack> itemStacks, DankTech plugin) {
NamespacedKey keyLevel = new NamespacedKey(plugin,"cell-level");
for (ItemStack i : itemStacks) {
if (i.hasItemMeta() && i.getItemMeta().getPersistentDataContainer().has(keyLevel,PersistentDataType.INTEGER)) {
Integer stackLevel = i.getItemMeta().getPersistentDataContainer().get(keyLevel,PersistentDataType.INTEGER);
if (!stackLevel.equals(level)) {
return false;
}
} else {
return false;
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}
}
}
Expand All @@ -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()) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 530431c

Please sign in to comment.