Skip to content

Commit

Permalink
Placeholderapi support was missing in keyLore
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Mar 3, 2024
1 parent 93ed892 commit 910bada
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
Expand Up @@ -36,7 +36,7 @@ public InventoryBuilder build() {
Inventory inventory = getInventory();

for (Crate crate : this.plugin.getCrateManager().getUsableCrates()) {
if (inventory.firstEmpty() >= 0) inventory.setItem(inventory.firstEmpty(), crate.getAdminKey());
if (inventory.firstEmpty() >= 0) inventory.setItem(inventory.firstEmpty(), crate.getAdminKey(getPlayer()));
}

return this;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void onInventoryClick(InventoryClickEvent event) {

switch (clickType) {
case LEFT -> {
ItemStack key = crate.getKey();
ItemStack key = crate.getKey(player);

player.getInventory().addItem(key);

Expand All @@ -102,7 +102,7 @@ public void onInventoryClick(InventoryClickEvent event) {
case RIGHT -> {
this.userManager.addKeys(1, player.getUniqueId(), crate.getName(), KeyType.virtual_key);

ItemStack key = crate.getKey();
ItemStack key = crate.getKey(player);

if (key.getItemMeta() != null) {
HashMap<String, String> placeholders = new HashMap<>();
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class Crate {
private final String keyName;
private final ItemBuilder keyBuilder;
private final ItemStack keyNoNBT;
private final ItemStack adminKey;
private final ItemBuilder adminKey;
private int maxPage = 1;
private final int maxSlots;
private final String previewName;
Expand Down Expand Up @@ -95,7 +95,7 @@ public Crate(String name, String previewName, CrateType crateType, ItemStack key
.addLore("")
.addLore("&7&l(&6&l!&7&l) Left click for Physical Key")
.addLore("&7&l(&6&l!&7&l) Right click for Virtual Key")
.setCrateName(name).build();
.setCrateName(name);
this.file = file;
this.name = name;
this.tiers = tiers != null ? tiers : new ArrayList<>();
Expand Down Expand Up @@ -458,13 +458,20 @@ public CrateType getCrateType() {
public ItemStack getKey() {
return this.keyBuilder.build();
}

/**
* @return the key as an item stack.
*/
public ItemStack getKey(Player player) {
return this.keyBuilder.setTarget(player).build();
}

/**
* @param amount The amount of keys you want.
* @return the key as an item stack.
*/
public ItemStack getKey(int amount) {
ItemBuilder key = this.keyBuilder.setAmount(amount);
public ItemStack getKey(int amount, Player player) {
ItemBuilder key = this.keyBuilder.setTarget(player).setAmount(amount);

return key.build();
}
Expand Down Expand Up @@ -494,7 +501,16 @@ public ItemStack getKeyNoNBT(int amount) {
* @return the itemstack of the key shown in the /cc admin menu.
*/
public ItemStack getAdminKey() {
return this.adminKey;
return this.adminKey.build();
}

/**
* Get the key that shows in the /cc admin menu.
*
* @return the itemstack of the key shown in the /cc admin menu.
*/
public ItemStack getAdminKey(Player player) {
return this.adminKey.setTarget(player).build();
}

/**
Expand Down
Expand Up @@ -4,11 +4,7 @@
import com.badbones69.crazycrates.support.SkullCreator;
import com.ryderbelserion.cluster.utils.DyeUtils;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ArmorMeta;
import org.bukkit.inventory.meta.BannerMeta;
Expand Down
Expand Up @@ -799,7 +799,7 @@ private void addKey(CommandSender sender, Player player, OfflinePlayer offlinePl

if (player != null) {
if (crate.getCrateType() == CrateType.crate_on_the_go) {
player.getInventory().addItem(crate.getKey(amount));
player.getInventory().addItem(crate.getKey(amount, player));
} else {
this.userManager.addKeys(amount, player.getUniqueId(), crate.getName(), type);
}
Expand Down Expand Up @@ -1010,7 +1010,7 @@ public void onAdminCrateGiveAllKeys(CommandSender sender, @Suggestion("key-types
onlinePlayer.sendMessage(Messages.obtaining_keys.getMessage(placeholders, onlinePlayer));

if (crate.getCrateType() == CrateType.crate_on_the_go) {
onlinePlayer.getInventory().addItem(crate.getKey(amount));
onlinePlayer.getInventory().addItem(crate.getKey(amount, onlinePlayer));

return;
}
Expand Down
Expand Up @@ -111,7 +111,7 @@ public void addKeys(int amount, UUID uuid, String crateName, KeyType keyType) {
switch (keyType) {
case physical_key -> {
if (!MiscUtils.isInventoryFull(player)) {
player.getInventory().addItem(crate.getKey(amount));
player.getInventory().addItem(crate.getKey(amount, player));
return;
}

Expand All @@ -129,7 +129,7 @@ public void addKeys(int amount, UUID uuid, String crateName, KeyType keyType) {
return;
}

player.getWorld().dropItem(player.getLocation(), crate.getKey(amount));
player.getWorld().dropItem(player.getLocation(), crate.getKey(amount, player));
}

case virtual_key -> addVirtualKeys(amount, player.getUniqueId(), crate.getName());
Expand Down Expand Up @@ -458,7 +458,7 @@ public void loadOfflinePlayersKeys(Player player, List<Crate> crates) {
if (crate.getCrateType() == CrateType.crate_on_the_go) {
// If the inventory is full, drop the items then stop.
if (MiscUtils.isInventoryFull(player)) {
player.getWorld().dropItemNaturally(player.getLocation(), crate.getKey(amount));
player.getWorld().dropItemNaturally(player.getLocation(), crate.getKey(amount, player));
break;
}
}
Expand All @@ -469,7 +469,7 @@ public void loadOfflinePlayersKeys(Player player, List<Crate> crates) {
// If the crate type is on the go.
if (crate.getCrateType() == CrateType.crate_on_the_go) {
// If the inventory not full, add to inventory.
player.getInventory().addItem(crate.getKey(amount));
player.getInventory().addItem(crate.getKey(amount, player));
} else {
// Otherwise add virtual keys.
addVirtualKeys(amount, uuid, crate.getName());
Expand All @@ -492,15 +492,15 @@ public void loadOfflinePlayersKeys(Player player, List<Crate> crates) {
while (keysGiven < amount) {
// If the inventory is full, drop the remaining keys then stop.
if (MiscUtils.isInventoryFull(player)) {
player.getWorld().dropItemNaturally(player.getLocation(), crate.getKey(amount-keysGiven));
player.getWorld().dropItemNaturally(player.getLocation(), crate.getKey(amount-keysGiven, player));
break;
}

keysGiven++;
}

// If the inventory not full, add to inventory.
player.getInventory().addItem(crate.getKey(keysGiven));
player.getInventory().addItem(crate.getKey(keysGiven, player));

// If keys given is greater or equal than, remove data.
if (keysGiven >= amount) this.data.set("Offline-Players." + uuid + ".Physical." + crate.getName(), null);
Expand Down

0 comments on commit 910bada

Please sign in to comment.