Kit conversion overhaul.

This commit is contained in:
Brianna O'Keefe 2024-03-11 15:20:27 -05:00 committed by Brianna OKeefe
parent 00edbe4b01
commit a7665044cb
7 changed files with 128 additions and 152 deletions

View File

@ -0,0 +1,25 @@
package com.craftaro.ultimatekits.conversion;
import org.bukkit.inventory.ItemStack;
import java.util.LinkedHashSet;
import java.util.Set;
public class ConversionKit {
private final Set<ItemStack> itemStack = new LinkedHashSet<>();
private final long delay;
public ConversionKit(Set<ItemStack> itemStack, long delay) {
this.itemStack.addAll(itemStack);
this.delay = delay;
}
public Set<ItemStack> getItemStacks() {
return this.itemStack;
}
public long getDelay() {
return this.delay;
}
}

View File

@ -12,67 +12,62 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.Set;
import java.util.Map;
public class Convert {
public static void runKitConversions(UltimateKits plugin) {
if (!plugin.getKitConfig().contains("Kits")) {
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
try {
Class.forName("com.earth2me.essentials.metrics.MetricsListener");
} catch (ClassNotFoundException ex) {
convertKits(new EssentialsHook());
convertKits(plugin, new EssentialsHook());
}
}
if (Bukkit.getPluginManager().isPluginEnabled("UltimateCore")) {
convertKits(new UltimateCoreHook());
}
if (Bukkit.getPluginManager().isPluginEnabled("CMI")) {
convertKits(new CMIHook());
}
}
if (!isInJsonFormat()) {
convertKits(new DefaultHook());
if (Bukkit.getPluginManager().isPluginEnabled("UltimateCore"))
convertKits(plugin, new UltimateCoreHook());
if (Bukkit.getPluginManager().isPluginEnabled("CMI"))
convertKits(plugin, new CMIHook());
}
if (!isInJsonFormat(plugin))
convertKits(plugin, new DefaultHook());
}
private static void convertKits(Hook hook) {
private static void convertKits(UltimateKits plugin, Hook hook) {
try {
Set<String> kits = hook.getKits();
for (String kit : kits) {
Kit kitObj = UltimateKits.getInstance().getKitManager().addKit(new Kit(kit));
if (kitObj == null) {
Map<String, ConversionKit> kits = hook.getKits();
for (Map.Entry<String, ConversionKit> entry : kits.entrySet()) {
Kit kitObj = plugin.getKitManager().addKit(new Kit(entry.getKey()));
if (kitObj == null)
continue;
}
for (ItemStack item : hook.getItems(kit)) {
if (item == null || item.getType() == Material.AIR) {
ConversionKit cvt = entry.getValue();
for (ItemStack item : cvt.getItemStacks()) {
if (item == null || item.getType() == Material.AIR)
continue;
}
kitObj.getContents().add(new KitItem(item));
}
kitObj.setDelay(hook.getDelay(kit));
kitObj.setDelay(cvt.getDelay());
}
UltimateKits.getInstance().saveKits(true);
plugin.saveKits(true);
} catch (NoSuchMethodError | NoClassDefFoundError e) {
System.out.println("UltimateKits conversion failed.");
}
}
private static boolean isInJsonFormat() {
if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) {
private static boolean isInJsonFormat(UltimateKits plugin) {
if (!plugin.getKitConfig().contains("Kits"))
return false;
}
for (String kit : UltimateKits.getInstance().getKitConfig().getConfigurationSection("Kits").getKeys(false)) {
if (UltimateKits.getInstance().getKitConfig().contains("Kits." + kit + ".items")) {
List<String> itemList = UltimateKits.getInstance().getKitConfig().getStringList("Kits." + kit + ".items");
if (!itemList.isEmpty()) {
if (itemList.get(0).startsWith("{")) {
for (String kit : plugin.getKitConfig().getConfigurationSection("Kits").getKeys(false))
if (plugin.getKitConfig().contains("Kits." + kit + ".items")) {
List<String> itemList = plugin.getKitConfig().getStringList("Kits." + kit + ".items");
if (!itemList.isEmpty())
if (itemList.get(0).startsWith("{"))
return true;
}
}
}
}
return false;
}

View File

@ -2,12 +2,10 @@ package com.craftaro.ultimatekits.conversion;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
import java.util.Set;
public interface Hook {
Set<String> getKits();
Set<ItemStack> getItems(String kitName);
long getDelay(String kitName);
Map<String, ConversionKit> getKits();
}

View File

@ -2,46 +2,44 @@ package com.craftaro.ultimatekits.conversion.hooks;
import com.Zrips.CMI.CMI;
import com.Zrips.CMI.Modules.Kits.Kit;
import com.craftaro.ultimatekits.conversion.ConversionKit;
import com.craftaro.ultimatekits.conversion.Hook;
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
public class CMIHook implements Hook {
private final CMI cmi;
public CMIHook() {
this.cmi = (CMI) Bukkit.getPluginManager().getPlugin("CMI");
}
public Set<ItemStack> getItems(String kitName) {
Set<ItemStack> stacks = new HashSet<>();
try {
Kit kit = this.cmi.getKitsManager().getKit(kitName, true);
@Override
public Map<String, ConversionKit> getKits() {
Map<String, ConversionKit> kits = new LinkedHashMap<>();
for (String kitName : this.cmi.getKitsManager().getKitMap().keySet()) {
Set<ItemStack> stacks = new HashSet<>();
try {
Kit kit = this.cmi.getKitsManager().getKit(kitName, true);
for (ItemStack item : kit.getItems()) {
if (item != null) {
stacks.add(item);
for (ItemStack item : kit.getItems()) {
if (item != null) {
stacks.add(item);
}
}
}
for (String command : kit.getCommands()) {
stacks.add(new KitContentCommand(command).getItemForDisplay());
for (String command : kit.getCommands()) {
stacks.add(new KitContentCommand(command).getItemForDisplay());
}
} catch (Exception ex) {
ex.printStackTrace();
}
} catch (Exception ex) {
ex.printStackTrace();
kits.put(kitName, new ConversionKit(stacks, this.cmi.getKitsManager().getKit(kitName, true).getDelay()));
}
return stacks;
}
public Set<String> getKits() {
return this.cmi.getKitsManager().getKitMap().keySet();
}
public long getDelay(String kitName) {
return this.cmi.getKitsManager().getKit(kitName, true).getDelay();
return kits;
}
}

View File

@ -1,35 +1,18 @@
package com.craftaro.ultimatekits.conversion.hooks;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.ultimatekits.conversion.ConversionKit;
import com.craftaro.ultimatekits.conversion.Hook;
import com.craftaro.ultimatekits.utils.ItemSerializer;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
public class DefaultHook implements Hook {
public Set<ItemStack> getItems(String kitName) {
Set<ItemStack> items = new HashSet<>();
for (Kits kit : Kits.values()) {
if (!kit.name().equalsIgnoreCase(kitName)) {
continue;
}
for (String string : kit.items) {
items.add(ItemSerializer.deserializeItemStackFromJson(string));
}
}
return items;
}
public Set<String> getKits() {
Set<String> kits = new HashSet<>();
@Override
public Map<String, ConversionKit> getKits() {
Map<String, ConversionKit> kits = new LinkedHashMap<>();
for (Kits kit : Kits.values()) {
if (kit == Kits.BRIANNA_1_12 && ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
continue;
@ -38,22 +21,15 @@ public class DefaultHook implements Hook {
if (kit == Kits.BRIANNA_1_16 && ServerVersion.isServerVersionBelow(ServerVersion.V1_16))
continue;
kits.add(kit.getName());
Set<ItemStack> items = new LinkedHashSet<>();
for (String string : kit.items)
items.add(ItemSerializer.deserializeItemStackFromJson(string));
kits.put(kit.getName(), new ConversionKit(items, kit.getDelay()));
}
return kits;
}
public long getDelay(String kitName) {
for (Kits kit : Kits.values()) {
if (!kit.name().equalsIgnoreCase(kitName)) {
continue;
}
return kit.delay;
}
return 0;
}
public enum Kits {
TOOLS(10, "{id:\"minecraft:stone_pickaxe\",Count:1b}",
"{id:\"minecraft:stone_axe\",Count:1b}",
@ -65,14 +41,14 @@ public class DefaultHook implements Hook {
"{id:\"minecraft:diamond_shovel\",Count:1b,tag:{Enchantments:[{lvl:1s,id:\"minecraft:efficiency\"}]}}",
"{id:\"minecraft:diamond_hoe\",Count:1b,tag:{Enchantments:[{lvl:3s,id:\"minecraft:unbreaking\"}]}}"),
BRIANNA_1_12(0, "{id:\"minecraft:skull\",Count:1b,tag:{SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[0:{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+VDQY8sUKQYacc9ZYDsBncagNO6imX6h6qsDmtTDtliTh8ZzHRIAw/6gQeiODJnOm4PAB2vPnUv0VFAP2awbikJeOSuK3WZsvcUN78+hXLFFtvBUt/oGKpsTj5P//2+qH7QLqmrxFD72jGpmyS8Fp6AHuQqzeHn40isvKT2+oTItFb3wQ3H2QgudGxEhOX6Onz0M2xmH61+HF5ajPS+/2hUl5kjRk8uRLc2AJD162dECdYOUJ8/j47Fl9pJXG1dcG6cGMuRlDAim3AqfdJFTW0CI78YEpTTGZcLL+O+/yUMQD9hOQqjP7y63YIOZ9kAZ7DRzu5hQaHLevhUcTwZnkqs+F9eUuQR00y8PoVoSEOMrV4LIWAJFutdziNZX9I7MI9tJ0x96imA18yYC9Skwx7JHurC1wpdtSqS/F7gCeU3+2QiFufxX9ft9BPHSBX7z08nqQkwxYh0O/06OX+H0NJTLwYrK+hoTXT1A5dNrJIHzGuK9/qUaitH4yz0zv5aGd3vVytdKCULFqOTiqur1QYPvF9sI2fhvfcHqUc30yU1di0Ws5SOQzCAFLOypjUH1ezQMOK+Xy3ixB0a8HXI9RL8ewOvKaVepbWS1vomNNWfiCgpudbLW8x6bPvQLmZn8YWPjCAL0WFycnw8lm6JDg=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]},Name:\"Brianna\"}},Damage:3s}}"),
BRIANNA_1_12(0, "{id:\"minecraft:skull\",Count:1b,tag:{display:{Name:'{\"text\":\"Brianna\"}'},SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[0:{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+V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M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]},Name:\"Brianna\"},Damage:3}}"),
BRIANNA_1_13(0, "{id:\"minecraft:player_head\",Count:1b,tag:{display:{Name:'{\"text\":\"Brianna\"}'},SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+VDQY8sUKQYacc9ZYDsBncagNO6imX6h6qsDmtTDtliTh8ZzHRIAw/6gQeiODJnOm4PAB2vPnUv0VFAP2awbikJeOSuK3WZsvcUN78+hXLFFtvBUt/oGKpsTj5P//2+qH7QLqmrxFD72jGpmyS8Fp6AHuQqzeHn40isvKT2+oTItFb3wQ3H2QgudGxEhOX6Onz0M2xmH61+HF5ajPS+/2hUl5kjRk8uRLc2AJD162dECdYOUJ8/j47Fl9pJXG1dcG6cGMuRlDAim3AqfdJFTW0CI78YEpTTGZcLL+O+/yUMQD9hOQqjP7y63YIOZ9kAZ7DRzu5hQaHLevhUcTwZnkqs+F9eUuQR00y8PoVoSEOMrV4LIWAJFutdziNZX9I7MI9tJ0x96imA18yYC9Skwx7JHurC1wpdtSqS/F7gCeU3+2QiFufxX9ft9BPHSBX7z08nqQkwxYh0O/06OX+H0NJTLwYrK+hoTXT1A5dNrJIHzGuK9/qUaitH4yz0zv5aGd3vVytdKCULFqOTiqur1QYPvF9sI2fhvfcHqUc30yU1di0Ws5SOQzCAFLOypjUH1ezQMOK+Xy3ixB0a8HXI9RL8ewOvKaVepbWS1vomNNWfiCgpudbLW8x6bPvQLmZn8YWPjCAL0WFycnw8lm6JDg=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]}},Damage:3}}"),
BRIANNA_1_16(0, "{id:\"minecraft:player_head\",Count:1b,tag:{SkullOwner:{Id:[I;656807503,1481976518,-1694340157,-169243065],Properties:{textures:[{Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]}}}}");
BRIANNA_1_16(0, "{id:\"minecraft:player_head\",Count:1b,tag:{display:{Name:'{\"text\":\"Brianna\"}'},SkullOwner:{Id:[I;656807503,1481976518,-1694340157,-169243065],Properties:{textures:[{Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]}}}}");
public final String[] items;
public final int delay;
private final String[] items;
private final int delay;
Kits(int delay, String... items) {
this.items = items;
@ -92,5 +68,13 @@ public class DefaultHook implements Hook {
}
return "";
}
public String[] getItems() {
return items;
}
public int getDelay() {
return delay;
}
}
}

View File

@ -1,5 +1,6 @@
package com.craftaro.ultimatekits.conversion.hooks;
import com.craftaro.ultimatekits.conversion.ConversionKit;
import com.craftaro.ultimatekits.conversion.Hook;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.Kit;
@ -9,6 +10,8 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class EssentialsHook implements Hook {
@ -18,48 +21,32 @@ public class EssentialsHook implements Hook {
this.essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
}
public Set<ItemStack> getItems(String kitName) {
Set<ItemStack> stacks = new HashSet<>();
try {
Kit kit = new Kit(kitName, this.essentials);
for (String nonParse : kit.getItems()) {
String[] parts = nonParse.split(" +");
ItemStack item = this.essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
MetaItemStack metaStack = new MetaItemStack(item);
if (parts.length > 2 != nonParse.startsWith("/")) {
try {
metaStack.parseStringMeta(null, true, parts, 2, this.essentials);
} catch (Exception ex) {
ex.printStackTrace();
}
}
stacks.add(metaStack.getItemStack());
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stacks;
}
public Set<String> getKits() {
@Override
public Map<String, ConversionKit> getKits() {
ConfigurationSection cs = this.essentials.getSettings().getKits();
Set<String> kits = new HashSet<>();
Map<String, ConversionKit> kits = new LinkedHashMap<>();
try {
cs.getKeys(false);
for (String name : cs.getKeys(false)) {
Set<ItemStack> stacks = new HashSet<>();
Kit kitObj = new Kit(name, this.essentials);
for (String nonParse : kitObj.getItems()) {
String[] parts = nonParse.split(" +");
ItemStack item = this.essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
MetaItemStack metaStack = new MetaItemStack(item);
if (parts.length > 2 != nonParse.startsWith("/")) {
try {
metaStack.parseStringMeta(null, true, parts, 2, this.essentials);
} catch (Exception ex) {
ex.printStackTrace();
}
}
stacks.add(metaStack.getItemStack());
}
kits.put(name, new ConversionKit(stacks, Integer.toUnsignedLong((int) this.essentials.getSettings().getKit(name).getOrDefault("delay", 0))));
}
} catch (Exception e) {
return kits;
}
kits.addAll(cs.getKeys(false));
return kits;
}
public long getDelay(String kitName) {
Object object = this.essentials.getSettings().getKit(kitName).getOrDefault("delay", 0);
try {
return Integer.toUnsignedLong((int) object);
} catch (Exception ex) {
return (long) object;
}
}
}

View File

@ -2,32 +2,21 @@ package com.craftaro.ultimatekits.conversion.hooks;
import bammerbom.ultimatecore.bukkit.api.UC;
import bammerbom.ultimatecore.bukkit.api.UKit;
import com.craftaro.ultimatekits.conversion.ConversionKit;
import com.craftaro.ultimatekits.conversion.Hook;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
public class UltimateCoreHook implements Hook {
@Override
public Set<String> getKits() {
Set<String> list = new HashSet<>();
public Map<String, ConversionKit> getKits() {
Map<String, ConversionKit> list = new LinkedHashMap<>();
List<UKit> kits = UC.getServer().getKits();
for (UKit kit : kits) {
list.add(kit.getName());
list.put(kit.getName(), new ConversionKit(new HashSet<>(kit.getItems()), 0));
}
return list;
}
@Override
public Set<ItemStack> getItems(String kitName) {
UKit uKit = new UKit(kitName);
return new HashSet<>(uKit.getItems());
}
@Override
public long getDelay(String kitName) {
return 0;
}
}