Skip to content

Commit

Permalink
Merge pull request #88 from Relluem94s/feature/RE-184
Browse files Browse the repository at this point in the history
RE-184 Move coins Key
  • Loading branch information
Relluem94 authored Apr 20, 2024
2 parents cd3bfea + 3745552 commit e62141b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static de.relluem94.minecraft.server.spigot.essentials.constants.Constants.PLUGIN_COMMAND_PURSE_TO_ITEM_NOT_ENOUGH_MONEY;
import static de.relluem94.minecraft.server.spigot.essentials.constants.Constants.PLUGIN_COMMAND_PURSE_TO_ITEM_VALUE_INVALID;
import static de.relluem94.minecraft.server.spigot.essentials.constants.CommandNameConstants.PLUGIN_COMMAND_NAME_PURSE;
import static de.relluem94.minecraft.server.spigot.essentials.constants.NamespacedKeyConstants.itemCoins;
import static de.relluem94.minecraft.server.spigot.essentials.helpers.TypeHelper.isPlayer;

import java.util.Collections;
Expand Down Expand Up @@ -88,7 +89,7 @@ public boolean onCommand(@NonNull CommandSender sender, Command command, @NonNul
ItemStack coin = CustomItems.coins.getCustomItem();
ItemMeta im = coin.getItemMeta();
Objects.requireNonNull(im).setLore(Collections.singletonList(String.format(ItemConstants.PLUGIN_ITEM_COINS_LORE, StringHelper.formatInt(coins))));
im.getPersistentDataContainer().set(ItemConstants.PLUGIN_ITEM_COINS_NAMESPACE, PersistentDataType.INTEGER, coins);
im.getPersistentDataContainer().set(itemCoins, PersistentDataType.INTEGER, coins);

coin.setItemMeta(im);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public interface ItemConstants {

String PLUGIN_ITEM_COINS = Constants.PLUGIN_NAME_MONEY;
String PLUGIN_ITEM_COINS_LORE = Constants.PLUGIN_COLOR_MONEY + "%s " + Constants.PLUGIN_NAME_MONEY;
NamespacedKey PLUGIN_ITEM_COINS_NAMESPACE = new NamespacedKey(RelluEssentials.getInstance(), "coins");

String PLUGIN_ITEM_NPC_LORE1 = "§7Click to Spawn";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.bukkit.NamespacedKey;

public interface NamespacedKeyConstants {
NamespacedKey itemCoins = new NamespacedKey(RelluEssentials.getInstance(), "coins");

NamespacedKey itemSellPrice = new NamespacedKey(RelluEssentials.getInstance(), "itemSellPrice");
NamespacedKey itemBuyPrice = new NamespacedKey(RelluEssentials.getInstance(), "itemBuyPrice");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import de.relluem94.minecraft.server.spigot.essentials.CustomItems;
import de.relluem94.minecraft.server.spigot.essentials.RelluEssentials;
import de.relluem94.minecraft.server.spigot.essentials.constants.Constants;
import de.relluem94.minecraft.server.spigot.essentials.constants.ItemConstants;
import de.relluem94.minecraft.server.spigot.essentials.helpers.BagHelper;
import de.relluem94.minecraft.server.spigot.essentials.helpers.ChatHelper;
import de.relluem94.minecraft.server.spigot.essentials.helpers.EnchantmentHelper;
Expand All @@ -38,6 +37,9 @@
import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.BagTypeEntry;
import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.PlayerEntry;
import de.relluem94.rellulib.stores.DoubleStore;

import static de.relluem94.minecraft.server.spigot.essentials.constants.NamespacedKeyConstants.itemCoins;

public class BetterBags implements Listener {

@EventHandler
Expand Down Expand Up @@ -324,8 +326,8 @@ public void onItemCollect(EntityPickupItemEvent e) {
if(CustomItems.coins.almostEquals(is)){
ItemMeta im = is.getItemMeta();

if(im != null && im.getPersistentDataContainer().has(ItemConstants.PLUGIN_ITEM_COINS_NAMESPACE, PersistentDataType.INTEGER)){
int coins = im.getPersistentDataContainer().get(ItemConstants.PLUGIN_ITEM_COINS_NAMESPACE, PersistentDataType.INTEGER) * is.getAmount();
if(im != null && im.getPersistentDataContainer().has(itemCoins, PersistentDataType.INTEGER)){
int coins = im.getPersistentDataContainer().get(itemCoins, PersistentDataType.INTEGER) * is.getAmount();
ChatHelper.sendMessageInActionBar(p, String.format(Constants.PLUGIN_COMMAND_PURSE_GAIN, StringHelper.formatInt(coins), StringHelper.formatDouble(pe.getPurse() + coins)));
pe.setPurse(pe.getPurse() + coins);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static de.relluem94.minecraft.server.spigot.essentials.constants.EventConstants.PLUGIN_EVENT_PROTECT_FLAGS;
import static de.relluem94.minecraft.server.spigot.essentials.constants.EventConstants.PLUGIN_EVENT_PROTECT_RIGHTS;
import static de.relluem94.minecraft.server.spigot.essentials.constants.ItemConstants.PLUGIN_ITEM_AUTOSELLHOPER;
import static de.relluem94.minecraft.server.spigot.essentials.constants.NamespacedKeyConstants.itemCoins;

import java.text.SimpleDateFormat;
import java.util.*;
Expand Down Expand Up @@ -171,7 +172,7 @@ private static boolean sellItem(Inventory inventory, ItemStack is, boolean isSou
ItemStack coin = CustomItems.coins.getCustomItem();
ItemMeta im = coin.getItemMeta();
Objects.requireNonNull(im).setLore(Collections.singletonList(String.format(ItemConstants.PLUGIN_ITEM_COINS_LORE, StringHelper.formatInt(sellPriceItem))));
im.getPersistentDataContainer().set(ItemConstants.PLUGIN_ITEM_COINS_NAMESPACE, PersistentDataType.INTEGER, sellPriceItem);
im.getPersistentDataContainer().set(itemCoins, PersistentDataType.INTEGER, sellPriceItem);

coin.setItemMeta(im);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static de.relluem94.minecraft.server.spigot.essentials.constants.EventConstants.PLUGIN_EVENT_DEATH;
import static de.relluem94.minecraft.server.spigot.essentials.constants.EventConstants.PLUGIN_EVENT_DEATH_TP;
import static de.relluem94.minecraft.server.spigot.essentials.constants.EventConstants.PLUGIN_EVENT_NO_DEATH_MESSAGE;
import static de.relluem94.minecraft.server.spigot.essentials.constants.NamespacedKeyConstants.itemCoins;

import java.util.Random;

Expand Down Expand Up @@ -58,7 +59,7 @@ public void onDeath(PlayerDeathEvent e) {
}

for(ItemStack is : p.getInventory().getContents()){
if(CustomItems.coins.almostEquals(is) && is.getItemMeta().getPersistentDataContainer().has(ItemConstants.PLUGIN_ITEM_COINS_NAMESPACE, PersistentDataType.INTEGER)){
if(CustomItems.coins.almostEquals(is) && is.getItemMeta().getPersistentDataContainer().has(itemCoins, PersistentDataType.INTEGER)){
p.getInventory().remove(is);
}
}
Expand Down

0 comments on commit e62141b

Please sign in to comment.