Redesigned the KitItem processing system.

This commit is contained in:
Brianna 2020-04-30 14:56:34 -04:00
parent 8c3d95fb94
commit 43a0cc5732
6 changed files with 63 additions and 30 deletions

View File

@ -98,15 +98,20 @@ public class AnimatedKitGui extends Gui {
// should we try to wrap it up?
if (finish) {
ItemStack item = getItem(13);
KitItem kitItem = items.stream().filter(i -> i.getItem().isSimilar(item)).findFirst().orElse(null);
if(item == null) {
done = true; // idk.
} else if (item.isSimilar(give)) {
if (!done) {
done = true;
if (!Settings.AUTO_EQUIP_ARMOR_ROULETTE.getBoolean() || !ArmorType.equip(player, give)) {
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(give);
for (ItemStack item2 : overfilled.values()) {
player.getWorld().dropItemNaturally(player.getLocation(), item2);
ItemStack processedItem = kitItem.getContent().process(player);
if (processedItem != null) {
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(give);
for (ItemStack item2 : overfilled.values()) {
player.getWorld().dropItemNaturally(player.getLocation(), item2);
}
}
}

View File

@ -322,37 +322,14 @@ public class Kit {
double rand = Math.random() * 100;
if (rand < ch || ch == 100) {
if (item.getContent() instanceof KitContentEconomy) {
try {
EconomyManager.deposit(player, ((KitContentEconomy) item.getContent()).getAmount());
plugin.getLocale().getMessage("event.claim.eco")
.processPlaceholder("amt", Methods.formatEconomy(((KitContentEconomy) item.getContent()).getAmount()))
.sendPrefixedMessage(player);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
itemGiveAmount--;
continue;
} else if (item.getContent() instanceof KitContentCommand) {
String parsed = ((KitContentCommand) item.getContent()).getCommand();
parsed = parsed.replace("{player}", player.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
if (item.getContent() instanceof KitContentEconomy
|| item.getContent() instanceof KitContentCommand) {
item.getContent().process(player);
itemGiveAmount--;
continue;
}
ItemStack parseStack = ((KitContentItem) item.getContent()).getItemStack();
if (parseStack.hasItemMeta() && parseStack.getItemMeta().hasLore()) {
ItemMeta meta = parseStack.getItemMeta();
List<String> newLore = new ArrayList<>();
for (String str : parseStack.getItemMeta().getLore()) {
str = str.replace("{PLAYER}", player.getName()).replace("<PLAYER>", player.getName());
newLore.add(str);
}
meta.setLore(newLore);
parseStack.setItemMeta(meta);
}
ItemStack parseStack = item.getContent().process(player);
if (parseStack.getType() == Material.AIR) continue;

View File

@ -1,5 +1,6 @@
package com.songoda.ultimatekits.kit.type;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public interface KitContent {
@ -8,4 +9,6 @@ public interface KitContent {
ItemStack getItemForDisplay();
ItemStack process(Player player);
}

View File

@ -1,7 +1,9 @@
package com.songoda.ultimatekits.kit.type;
import com.songoda.ultimatekits.UltimateKits;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -40,4 +42,12 @@ public class KitContentCommand implements KitContent {
stack.setItemMeta(meta);
return stack;
}
@Override
public ItemStack process(Player player) {
String parsed = command;
parsed = parsed.replace("{player}", player.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
return null;
}
}

View File

@ -1,7 +1,10 @@
package com.songoda.ultimatekits.kit.type;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.utils.Methods;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -42,4 +45,17 @@ public class KitContentEconomy implements KitContent {
parseStack.setItemMeta(meta);
return parseStack;
}
@Override
public ItemStack process(Player player) {
try {
EconomyManager.deposit(player, amount);
UltimateKits.getInstance().getLocale().getMessage("event.claim.eco")
.processPlaceholder("amt", Methods.formatEconomy(amount))
.sendPrefixedMessage(player);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
return null;
}
}

View File

@ -1,7 +1,12 @@
package com.songoda.ultimatekits.kit.type;
import com.songoda.ultimatekits.UltimateKits;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class KitContentItem implements KitContent {
@ -28,4 +33,21 @@ public class KitContentItem implements KitContent {
public ItemStack getItemForDisplay() {
return itemStack.clone();
}
@Override
public ItemStack process(Player player) {
ItemStack parseStack = itemStack;
if (parseStack.hasItemMeta() && parseStack.getItemMeta().hasLore()) {
ItemMeta meta = parseStack.getItemMeta();
List<String> newLore = new ArrayList<>();
for (String str : parseStack.getItemMeta().getLore()) {
str = str.replace("{PLAYER}", player.getName()).replace("<PLAYER>", player.getName());
newLore.add(str);
}
meta.setLore(newLore);
parseStack.setItemMeta(meta);
}
return parseStack;
}
}