diff --git a/pom.xml b/pom.xml index 860e1323..358796a7 100644 --- a/pom.xml +++ b/pom.xml @@ -48,10 +48,15 @@ io.github.dre2n.commons io.github.dre2n.dungeonsxl + + io.github.dre2n.caliburn + io.github.dre2n.dungeonsxl.util.caliburn + io.github.dre2n:commons + io.github.dre2n:caliburn @@ -78,6 +83,16 @@ commons 1.0-SNAPSHOT + + io.github.dre2n + caliburn + 0.1.4 + + + io.github.dre2n + itemsxl + 0.1.4 + io.github.dre2n commandsxl @@ -86,7 +101,7 @@ net.citizensnpcs citizensapi - 2.0.17-SNAPSHOT + 2.0.18-SNAPSHOT provided diff --git a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 9a1ebf64..eb33550c 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl; +import io.github.dre2n.caliburn.CaliburnAPI; import io.github.dre2n.commons.command.BRCommands; import io.github.dre2n.commons.compatibility.Internals; import io.github.dre2n.commons.config.MessageConfig; @@ -53,6 +54,7 @@ import io.github.dre2n.dungeonsxl.task.WorldUnloadTask; import io.github.dre2n.dungeonsxl.trigger.TriggerTypes; import io.github.dre2n.dungeonsxl.world.EditWorld; import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.itemsxl.ItemsXL; import java.io.File; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -77,6 +79,8 @@ public class DungeonsXL extends BRPlugin { public static File MOBS; public static File SIGNS; + private CaliburnAPI caliburn; + private GlobalData globalData; private MainConfig mainConfig; private MessageConfig messageConfig; @@ -304,6 +308,24 @@ public class DungeonsXL extends BRPlugin { return instance; } + /** + * @return the loaded instance of CaliburnAPI + */ + public CaliburnAPI getCaliburnAPI() { + return caliburn; + } + + /** + * load / reload a new instance of CaliburnAPI + */ + public void loadCaliburnAPI() { + if (manager.isPluginEnabled("ItemsXL")) { + this.caliburn = ItemsXL.getInstance().getAPI(); + } else { + this.caliburn = new CaliburnAPI(this); + } + } + /** * @return the loaded instance of GlobalData */ diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java b/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java index 30ef52bf..9d238163 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java @@ -23,8 +23,6 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @author Daniel Saukel diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index 0f3c9eb9..aa19fe9c 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -16,6 +16,8 @@ */ package io.github.dre2n.dungeonsxl.config; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Version; import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; @@ -25,6 +27,7 @@ import io.github.dre2n.dungeonsxl.requirement.FeeLevelRequirement; import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement; import io.github.dre2n.dungeonsxl.requirement.GroupSizeRequirement; import io.github.dre2n.dungeonsxl.requirement.Requirement; +import io.github.dre2n.dungeonsxl.util.DeserialisazionUtil; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -32,10 +35,10 @@ import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.GameMode; -import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.inventory.ItemStack; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel @@ -43,6 +46,7 @@ import org.bukkit.configuration.file.YamlConfiguration; public class WorldConfig extends GameRules { DungeonsXL plugin = DungeonsXL.getInstance(); + CompatibilityHandler compat = CompatibilityHandler.getInstance(); private File file; @@ -79,13 +83,10 @@ public class WorldConfig extends GameRules { /* Secure Objects */ if (configFile.contains("secureObjects")) { List secureObjectList = configFile.getStringList("secureObjects"); - for (String id : secureObjectList) { - if (Material.getMaterial(NumberUtil.parseInt(id)) != null) { - secureObjects.add(Material.getMaterial(NumberUtil.parseInt(id))); - - } else if (Material.getMaterial(id) != null) { - secureObjects.add(Material.getMaterial(id)); - } + if (Version.andHigher(Version.MC1_9).contains(compat.getVersion())) { + secureObjects = plugin.getCaliburnAPI().getItems().deserializeStackList(secureObjectList); + } else { + secureObjects = DeserialisazionUtil.deserializeStackList(secureObjectList); } } @@ -244,14 +245,13 @@ public class WorldConfig extends GameRules { configFile.set("message." + msgs, this.msgs.get(msgs)); } - // Secure Objects - CopyOnWriteArrayList secureObjectsids = new CopyOnWriteArrayList<>(); + List secureObjectIds = new ArrayList<>(); - for (Material mat : secureObjects) { - secureObjectsids.add(mat.getId()); + for (ItemStack item : secureObjects) { + secureObjectIds.add(plugin.getCaliburnAPI().getItems().getCustomItemId(item)); } - configFile.set("secureObjects", secureObjectsids); + configFile.set("secureObjects", secureObjectIds); // Invited Players configFile.set("invitedPlayers", invitedPlayers); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index b79c2917..686bf150 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl.game; +import io.github.dre2n.caliburn.item.UniversalItem; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; @@ -24,7 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import org.bukkit.GameMode; -import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; /** * @author Daniel Saukel @@ -109,7 +110,7 @@ public class GameRules { /* Misc */ protected Map msgs; - protected List secureObjects; + protected List secureObjects; /* Getters and setters */ // keepInventory @@ -315,7 +316,7 @@ public class GameRules { /** * @return the objects to get passed to another player of the group when this player leaves */ - public List getSecureObjects() { + public List getSecureObjects() { return secureObjects; } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 8683ec54..e01b5965 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -350,8 +350,8 @@ public class PlayerListener implements Listener { Game game = Game.getByWorld(gamePlayer.getWorld()); - for (Material material : game.getRules().getSecureObjects()) { - if (material == event.getItemDrop().getItemStack().getType()) { + for (ItemStack item : game.getRules().getSecureObjects()) { + if (event.getItemDrop().getItemStack().isSimilar(item)) { event.setCancelled(true); MessageUtil.sendMessage(player, DMessages.ERROR_DROP.getMessage()); return; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java index 8804bfef..e902336e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java @@ -18,7 +18,6 @@ package io.github.dre2n.dungeonsxl.listener; import io.github.dre2n.dungeonsxl.world.EditWorld; import io.github.dre2n.dungeonsxl.world.GameWorld; -import org.bukkit.World; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java b/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java index 3cc21341..3b4a837d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java @@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.mob; import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; -import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.world.GameWorld; import java.io.File; @@ -46,8 +45,6 @@ import org.bukkit.inventory.meta.ItemMeta; */ public class DMobType { - static DungeonsXL plugin = DungeonsXL.getInstance(); - private String name; private EntityType type; @@ -75,7 +72,7 @@ public class DMobType { /** * @param name - * the name of the Announcer + * the name of the DMobType * @param config * the config that stores the information */ @@ -178,7 +175,7 @@ public class DMobType { /* Add Item to the drops map */ item.setItemMeta(itemMeta); - getDrops().put(item, chance); + drops.put(item, chance); } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java index 176671ec..aec84025 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java @@ -16,7 +16,10 @@ */ package io.github.dre2n.dungeonsxl.player; -import io.github.dre2n.dungeonsxl.util.ItemUtil; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Version; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.util.DeserialisazionUtil; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -29,6 +32,9 @@ import org.bukkit.inventory.ItemStack; */ public class DClass { + DungeonsXL plugin = DungeonsXL.getInstance(); + CompatibilityHandler compat = CompatibilityHandler.getInstance(); + private String name; private List items = new ArrayList<>(); @@ -42,7 +48,13 @@ public class DClass { this.name = name; if (config.contains("items")) { - items = ItemUtil.fromConfig(config); + List itemList = config.getStringList("items"); + + if (Version.andHigher(Version.MC1_9).contains(compat.getVersion())) { + items = plugin.getCaliburnAPI().getItems().deserializeStackList(itemList); + } else { + items = DeserialisazionUtil.deserializeStackList(itemList); + } } if (config.contains("dog")) { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java index dbd9c3d3..b8f886d8 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java @@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.player.DClass; import io.github.dre2n.dungeonsxl.world.GameWorld; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.block.Sign; /** diff --git a/src/main/java/io/github/dre2n/dungeonsxl/util/ItemUtil.java b/src/main/java/io/github/dre2n/dungeonsxl/util/DeserialisazionUtil.java similarity index 86% rename from src/main/java/io/github/dre2n/dungeonsxl/util/ItemUtil.java rename to src/main/java/io/github/dre2n/dungeonsxl/util/DeserialisazionUtil.java index 8e7bb4d2..95215d00 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/util/ItemUtil.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/util/DeserialisazionUtil.java @@ -17,21 +17,21 @@ package io.github.dre2n.dungeonsxl.util; import io.github.dre2n.commons.util.NumberUtil; +import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; /** + * Deprecated deserialization methods for compatibility with 1.7.8-1.8.x + * * @author Frank Baumann, Daniel Saukel */ @Deprecated -public class ItemUtil { +public class DeserialisazionUtil { - public static List fromConfig(ConfigurationSection configSectionClasses) { - List items = configSectionClasses.getStringList("items"); - CopyOnWriteArrayList itemStacks = new CopyOnWriteArrayList<>(); + public static List deserializeStackList(List items) { + List itemStacks = new ArrayList<>(); for (String item : items) { String[] itemSplit = item.split(","); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java index 0906da81..a5d9b0f1 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java @@ -44,7 +44,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.block.Block; @@ -53,6 +52,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Spider; +import org.bukkit.inventory.ItemStack; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel @@ -71,7 +71,7 @@ public class GameWorld { private Location locStart; private boolean isPlaying = false; private int id; - private List secureObjects = new ArrayList<>(); + private List secureObjects = new ArrayList<>(); private CopyOnWriteArrayList loadedChunks = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList signClass = new CopyOnWriteArrayList<>(); @@ -244,7 +244,7 @@ public class GameWorld { /** * @return the secureObjects */ - public List getSecureObjects() { + public List getSecureObjects() { return secureObjects; } @@ -252,7 +252,7 @@ public class GameWorld { * @param secureObjects * the secureObjects to set */ - public void setSecureObjects(List secureObjects) { + public void setSecureObjects(List secureObjects) { this.secureObjects = secureObjects; } @@ -539,10 +539,7 @@ public class GameWorld { /* Statics */ public static GameWorld getByWorld(World world) { for (GameWorld gameWorld : plugin.getGameWorlds()) { - if (gameWorld.getWorld() == null) { - continue; - - } else if (gameWorld.getWorld().equals(world)) { + if (gameWorld.getWorld() != null && gameWorld.getWorld().equals(world)) { return gameWorld; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 04f8c93f..83bb3d74 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ version: ${project.version} authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] description: ${project.description} website: ${project.url} -softdepend: [BlueRoseCommons, CommandsXL, Vault, CustomMobs, InsaneMobs, MythicMobs] +softdepend: [BlueRoseCommons, CommandsXL, ItemsXL, Vault, CustomMobs, InsaneMobs, MythicMobs] commands: dungeonsxl: description: Reference command for DungeonsXL.