mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-08 11:41:28 +01:00
Optimized conversion system.
This commit is contained in:
parent
b049a16a3a
commit
714536c752
@ -95,6 +95,12 @@ public class UltimateKits extends SongodaPlugin {
|
||||
// Set economy preference
|
||||
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString());
|
||||
|
||||
this.kitManager = new KitManager();
|
||||
this.keyManager = new KeyManager();
|
||||
|
||||
kitConfig.load();
|
||||
Convert.runKitConversions();
|
||||
|
||||
// load kits
|
||||
dataFile.load();
|
||||
checkKeyDefaults();
|
||||
@ -114,10 +120,6 @@ public class UltimateKits extends SongodaPlugin {
|
||||
.addSubCommand(new CommandSet())
|
||||
.addSubCommand(new CommandRemove());
|
||||
|
||||
this.kitManager = new KitManager();
|
||||
this.keyManager = new KeyManager();
|
||||
|
||||
Convert.runKitConversions();
|
||||
|
||||
// Event registration
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
@ -166,6 +168,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
saveKits();
|
||||
dataFile.save();
|
||||
this.dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
saveKits();
|
||||
kitManager.clearKits();
|
||||
HologramManager.removeAllHolograms();
|
||||
}
|
||||
@ -195,7 +198,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
* Register kit into KitManager from Configuration.
|
||||
*/
|
||||
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
int delay = kitConfig.getInt("Kits." + kitName + ".delay");
|
||||
long delay = kitConfig.getLong("Kits." + kitName + ".delay");
|
||||
String title = kitConfig.getString("Kits." + kitName + ".title");
|
||||
String link = kitConfig.getString("Kits." + kitName + ".link");
|
||||
CompatibleMaterial material = kitConfig.contains("Kits." + kitName + ".displayItem")
|
||||
@ -387,10 +390,11 @@ public class UltimateKits extends SongodaPlugin {
|
||||
public void saveKits() {
|
||||
|
||||
// Hot fix for kit file resets.
|
||||
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
if (kitManager.getKits().stream().noneMatch(kit -> kit.getName().equals(kitName)))
|
||||
kitConfig.set("Kits." + kitName, null);
|
||||
}
|
||||
if (kitConfig.contains("Kits"))
|
||||
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
if (kitManager.getKits().stream().noneMatch(kit -> kit.getName().equals(kitName)))
|
||||
kitConfig.set("Kits." + kitName, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Save kit from KitManager to Configuration.
|
||||
|
@ -5,12 +5,14 @@ import com.songoda.ultimatekits.conversion.hooks.CMIHook;
|
||||
import com.songoda.ultimatekits.conversion.hooks.DefaultHook;
|
||||
import com.songoda.ultimatekits.conversion.hooks.EssentialsHook;
|
||||
import com.songoda.ultimatekits.conversion.hooks.UltimateCoreHook;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Convert {
|
||||
|
||||
@ -38,18 +40,19 @@ public class Convert {
|
||||
private static void convertKits(Hook hook) {
|
||||
Set<String> kits = hook.getKits();
|
||||
for (String kit : kits) {
|
||||
List<String> serializedItems = new ArrayList<>();
|
||||
Kit kitObj = UltimateKits.getInstance().getKitManager().addKit(new Kit(kit));
|
||||
if (kitObj == null) continue;
|
||||
for (ItemStack item : hook.getItems(kit)) {
|
||||
serializedItems.add(UltimateKits.getInstance().getItemSerializer().serializeItemStackToJson(item));
|
||||
if (item == null || item.getType() == Material.AIR) continue;
|
||||
kitObj.getContents().add(new KitItem(item));
|
||||
}
|
||||
UltimateKits.getInstance().getKitConfig().set("Kits." + kit + ".items", serializedItems);
|
||||
UltimateKits.getInstance().getKitConfig().set("Kits." + kit + ".delay", hook.getDelay(kit));
|
||||
UltimateKits.getInstance().getKitConfig().set("Kits." + kit + ".price", 0D);
|
||||
kitObj.setDelay(hook.getDelay(kit));
|
||||
}
|
||||
UltimateKits.getInstance().getKitConfig().save();
|
||||
UltimateKits.getInstance().saveKits();
|
||||
}
|
||||
|
||||
private static boolean isInJsonFormat() {
|
||||
if (!UltimateKits.getInstance().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");
|
||||
@ -62,4 +65,4 @@ public class Convert {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.conversion.hooks;
|
||||
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.conversion.Hook;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -26,7 +27,9 @@ public class DefaultHook implements Hook {
|
||||
Set<String> kits = new HashSet<>();
|
||||
|
||||
for (Kits kit : Kits.values()) {
|
||||
kits.add(kit.name().toLowerCase());
|
||||
if (kit == Kits.BRIANNA_1_12 && ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
|| kit == Kits.BRIANNA_1_13 && !ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) continue;
|
||||
kits.add(kit.name().toLowerCase().replace("_1_12", "").replace("_1_13", ""));
|
||||
}
|
||||
|
||||
return kits;
|
||||
@ -51,7 +54,9 @@ 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(0, "{id:\"minecraft:player_head\",Count:1b,tag:{SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[{Signature:\"Zx+6l8ZZACSIdWtHdllX6yqcLWC57ly7CTxO40SVbxwO3D1bMIQOjmeUbq3WkOb9lNIRvtH3oGcC6U9l1vICCIV3/oQZ4hxEs4yxmmGHmsK9Qm/oa4ZfaWNKdjio7kOWBqf8I+0zImXB1ptjAEfRJ1RCIaFW80amWLDeOhDhMfPTEOCP80ZfP29aGd91KPAVYOokvv/SX9BD4OaaStDt5Cbterfz0JwwBoogrYAIrkQuvxYlFkVHL1rO5ygLXiWGvF0lBqpeEX7r3QPT0D9iU92/zQ98v0N1klrOW4eK2tpAuhfI2mJ3nwKUKedssgAhmmEgG/doeByXJMlbfQxEfUifq7lHXm/sVD/Gd9pHJSMGQzenwhitiJpm7XHMRFUAJVi8Gt29TCXektC2E0VlsmDRQDb/fYQRPW2KgXpB2TpHzqFGMTjQCNtp4AEBgxaFrH87nXckkJGY+SFGUvcUE3D0u+026gwDUlrGB1Fr5leOF9tPSSu5r7h5i9t1m/LvO0SwPEl0UzeISX8JaJ0fLkvVmTV/lWGzXAZX7xgte0336uy0zYIovzE3wnDbb5iE9NM6+Zja4zU0PQi19gzK272zoC4SCEh6/h2yhU8cEtl8StoNSCk14puZz/XYCfbLpJBJz8x/E1R8WBbes0G2A5nsQGqMqWl0lz20zNd1eYk=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NTY4MzcwMDk4NjksInByb2ZpbGVJZCI6IjI2MjY5NzRmNTgzODQ0YzY5OTRkZjZjNzIzZDQwYjc5IiwicHJvZmlsZU5hbWUiOiJTb25nb2RhIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8zNTI4ZGZiNGYwZWUxNGQ4ZDhhM2RhMTM4YTYzYjZlOGI1MWJmZTIwNTYxZjhjZTliYjFhOTBhNjhjMTI5NWE1IiwibWV0YWRhdGEiOnsibW9kZWwiOiJzbGltIn19fX0=\"}]},Name:\"Songoda\"},Damage:3}}");
|
||||
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_13(0, "{id:\"minecraft:player_head\",Count:1b,tag:{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==\"}]},Name:\"Brianna\"},Damage:3}}");
|
||||
|
||||
public String[] items;
|
||||
public int delay;
|
||||
|
@ -39,13 +39,13 @@ public class Kit {
|
||||
private final UltimateKits plugin;
|
||||
private double price;
|
||||
private String link, title;
|
||||
private int delay;
|
||||
private long delay;
|
||||
private boolean hidden;
|
||||
private CompatibleMaterial displayItem;
|
||||
private List<KitItem> contents;
|
||||
private KitAnimation kitAnimation;
|
||||
|
||||
public Kit(String name, String title, String link, double price, CompatibleMaterial displayItem, int delay, boolean hidden, List<KitItem> contents, KitAnimation kitAnimation) {
|
||||
public Kit(String name, String title, String link, double price, CompatibleMaterial displayItem, long delay, boolean hidden, List<KitItem> contents, KitAnimation kitAnimation) {
|
||||
this.name = name;
|
||||
this.showableName = TextUtils.formatText(name, true);
|
||||
this.price = price;
|
||||
@ -409,11 +409,11 @@ public class Kit {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(int delay) {
|
||||
public void setDelay(long delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,10 @@ public final class KitManager {
|
||||
private final Map<Location, KitBlockData> kitsAtLocations = new HashMap<>();
|
||||
private final List<Kit> registeredKits = new LinkedList<>();
|
||||
|
||||
public boolean addKit(Kit kit) {
|
||||
if (kit == null) return false;
|
||||
return registeredKits.add(kit);
|
||||
public Kit addKit(Kit kit) {
|
||||
if (kit == null) return null;
|
||||
registeredKits.add(kit);
|
||||
return kit;
|
||||
}
|
||||
|
||||
public void removeKit(Kit kit) {
|
||||
|
Loading…
Reference in New Issue
Block a user