CaliburnAPI / ItemsXL integration. Closes #74; closes #15

This commit is contained in:
Daniel Saukel 2016-05-31 18:01:19 +02:00
parent 5f8170e494
commit a97b345b30
13 changed files with 85 additions and 45 deletions

17
pom.xml
View File

@ -48,10 +48,15 @@
<pattern>io.github.dre2n.commons</pattern> <pattern>io.github.dre2n.commons</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl</shadedPattern> <shadedPattern>io.github.dre2n.dungeonsxl</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>io.github.dre2n.caliburn</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.caliburn</shadedPattern>
</relocation>
</relocations> </relocations>
<artifactSet> <artifactSet>
<includes> <includes>
<include>io.github.dre2n:commons</include> <include>io.github.dre2n:commons</include>
<include>io.github.dre2n:caliburn</include>
</includes> </includes>
</artifactSet> </artifactSet>
</configuration> </configuration>
@ -78,6 +83,16 @@
<artifactId>commons</artifactId> <artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>caliburn</artifactId>
<version>0.1.4</version>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>itemsxl</artifactId>
<version>0.1.4</version>
</dependency>
<dependency> <dependency>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>commandsxl</artifactId> <artifactId>commandsxl</artifactId>
@ -86,7 +101,7 @@
<dependency> <dependency>
<groupId>net.citizensnpcs</groupId> <groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId> <artifactId>citizensapi</artifactId>
<version>2.0.17-SNAPSHOT</version> <version>2.0.18-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -16,6 +16,7 @@
*/ */
package io.github.dre2n.dungeonsxl; package io.github.dre2n.dungeonsxl;
import io.github.dre2n.caliburn.CaliburnAPI;
import io.github.dre2n.commons.command.BRCommands; import io.github.dre2n.commons.command.BRCommands;
import io.github.dre2n.commons.compatibility.Internals; import io.github.dre2n.commons.compatibility.Internals;
import io.github.dre2n.commons.config.MessageConfig; 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.trigger.TriggerTypes;
import io.github.dre2n.dungeonsxl.world.EditWorld; import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.world.GameWorld; import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.itemsxl.ItemsXL;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -77,6 +79,8 @@ public class DungeonsXL extends BRPlugin {
public static File MOBS; public static File MOBS;
public static File SIGNS; public static File SIGNS;
private CaliburnAPI caliburn;
private GlobalData globalData; private GlobalData globalData;
private MainConfig mainConfig; private MainConfig mainConfig;
private MessageConfig messageConfig; private MessageConfig messageConfig;
@ -304,6 +308,24 @@ public class DungeonsXL extends BRPlugin {
return instance; 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 * @return the loaded instance of GlobalData
*/ */

View File

@ -23,8 +23,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* @author Daniel Saukel * @author Daniel Saukel

View File

@ -16,6 +16,8 @@
*/ */
package io.github.dre2n.dungeonsxl.config; 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.EnumUtil;
import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL; 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.FeeMoneyRequirement;
import io.github.dre2n.dungeonsxl.requirement.GroupSizeRequirement; import io.github.dre2n.dungeonsxl.requirement.GroupSizeRequirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.util.DeserialisazionUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,10 +35,10 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
/** /**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel * @author Frank Baumann, Milan Albrecht, Daniel Saukel
@ -43,6 +46,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
public class WorldConfig extends GameRules { public class WorldConfig extends GameRules {
DungeonsXL plugin = DungeonsXL.getInstance(); DungeonsXL plugin = DungeonsXL.getInstance();
CompatibilityHandler compat = CompatibilityHandler.getInstance();
private File file; private File file;
@ -79,13 +83,10 @@ public class WorldConfig extends GameRules {
/* Secure Objects */ /* Secure Objects */
if (configFile.contains("secureObjects")) { if (configFile.contains("secureObjects")) {
List<String> secureObjectList = configFile.getStringList("secureObjects"); List<String> secureObjectList = configFile.getStringList("secureObjects");
for (String id : secureObjectList) { if (Version.andHigher(Version.MC1_9).contains(compat.getVersion())) {
if (Material.getMaterial(NumberUtil.parseInt(id)) != null) { secureObjects = plugin.getCaliburnAPI().getItems().deserializeStackList(secureObjectList);
secureObjects.add(Material.getMaterial(NumberUtil.parseInt(id))); } else {
secureObjects = DeserialisazionUtil.deserializeStackList(secureObjectList);
} else if (Material.getMaterial(id) != null) {
secureObjects.add(Material.getMaterial(id));
}
} }
} }
@ -244,14 +245,13 @@ public class WorldConfig extends GameRules {
configFile.set("message." + msgs, this.msgs.get(msgs)); configFile.set("message." + msgs, this.msgs.get(msgs));
} }
// Secure Objects List<String> secureObjectIds = new ArrayList<>();
CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<>();
for (Material mat : secureObjects) { for (ItemStack item : secureObjects) {
secureObjectsids.add(mat.getId()); secureObjectIds.add(plugin.getCaliburnAPI().getItems().getCustomItemId(item));
} }
configFile.set("secureObjects", secureObjectsids); configFile.set("secureObjects", secureObjectIds);
// Invited Players // Invited Players
configFile.set("invitedPlayers", invitedPlayers); configFile.set("invitedPlayers", invitedPlayers);

View File

@ -16,6 +16,7 @@
*/ */
package io.github.dre2n.dungeonsxl.game; package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.caliburn.item.UniversalItem;
import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward; import io.github.dre2n.dungeonsxl.reward.Reward;
@ -24,7 +25,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.inventory.ItemStack;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
@ -109,7 +110,7 @@ public class GameRules {
/* Misc */ /* Misc */
protected Map<Integer, String> msgs; protected Map<Integer, String> msgs;
protected List<Material> secureObjects; protected List<ItemStack> secureObjects;
/* Getters and setters */ /* Getters and setters */
// keepInventory // keepInventory
@ -315,7 +316,7 @@ public class GameRules {
/** /**
* @return the objects to get passed to another player of the group when this player leaves * @return the objects to get passed to another player of the group when this player leaves
*/ */
public List<Material> getSecureObjects() { public List<ItemStack> getSecureObjects() {
return secureObjects; return secureObjects;
} }

View File

@ -350,8 +350,8 @@ public class PlayerListener implements Listener {
Game game = Game.getByWorld(gamePlayer.getWorld()); Game game = Game.getByWorld(gamePlayer.getWorld());
for (Material material : game.getRules().getSecureObjects()) { for (ItemStack item : game.getRules().getSecureObjects()) {
if (material == event.getItemDrop().getItemStack().getType()) { if (event.getItemDrop().getItemStack().isSimilar(item)) {
event.setCancelled(true); event.setCancelled(true);
MessageUtil.sendMessage(player, DMessages.ERROR_DROP.getMessage()); MessageUtil.sendMessage(player, DMessages.ERROR_DROP.getMessage());
return; return;

View File

@ -18,7 +18,6 @@ package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.world.EditWorld; import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.world.GameWorld; import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.EnumUtil;
import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.commons.util.messageutil.MessageUtil; 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.config.DMessages;
import io.github.dre2n.dungeonsxl.world.GameWorld; import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.io.File; import java.io.File;
@ -46,8 +45,6 @@ import org.bukkit.inventory.meta.ItemMeta;
*/ */
public class DMobType { public class DMobType {
static DungeonsXL plugin = DungeonsXL.getInstance();
private String name; private String name;
private EntityType type; private EntityType type;
@ -75,7 +72,7 @@ public class DMobType {
/** /**
* @param name * @param name
* the name of the Announcer * the name of the DMobType
* @param config * @param config
* the config that stores the information * the config that stores the information
*/ */
@ -178,7 +175,7 @@ public class DMobType {
/* Add Item to the drops map */ /* Add Item to the drops map */
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
getDrops().put(item, chance); drops.put(item, chance);
} }
} }
} }

View File

@ -16,7 +16,10 @@
*/ */
package io.github.dre2n.dungeonsxl.player; 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -29,6 +32,9 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class DClass { public class DClass {
DungeonsXL plugin = DungeonsXL.getInstance();
CompatibilityHandler compat = CompatibilityHandler.getInstance();
private String name; private String name;
private List<ItemStack> items = new ArrayList<>(); private List<ItemStack> items = new ArrayList<>();
@ -42,7 +48,13 @@ public class DClass {
this.name = name; this.name = name;
if (config.contains("items")) { if (config.contains("items")) {
items = ItemUtil.fromConfig(config); List<String> 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")) { if (config.contains("dog")) {

View File

@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.player.DClass; import io.github.dre2n.dungeonsxl.player.DClass;
import io.github.dre2n.dungeonsxl.world.GameWorld; import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
/** /**

View File

@ -17,21 +17,21 @@
package io.github.dre2n.dungeonsxl.util; package io.github.dre2n.dungeonsxl.util;
import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.NumberUtil;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* Deprecated deserialization methods for compatibility with 1.7.8-1.8.x
*
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
@Deprecated @Deprecated
public class ItemUtil { public class DeserialisazionUtil {
public static List<ItemStack> fromConfig(ConfigurationSection configSectionClasses) { public static List<ItemStack> deserializeStackList(List<String> items) {
List<String> items = configSectionClasses.getStringList("items"); List<ItemStack> itemStacks = new ArrayList<>();
CopyOnWriteArrayList<ItemStack> itemStacks = new CopyOnWriteArrayList<>();
for (String item : items) { for (String item : items) {
String[] itemSplit = item.split(","); String[] itemSplit = item.split(",");

View File

@ -44,7 +44,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -53,6 +52,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Spider; import org.bukkit.entity.Spider;
import org.bukkit.inventory.ItemStack;
/** /**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel * @author Frank Baumann, Milan Albrecht, Daniel Saukel
@ -71,7 +71,7 @@ public class GameWorld {
private Location locStart; private Location locStart;
private boolean isPlaying = false; private boolean isPlaying = false;
private int id; private int id;
private List<Material> secureObjects = new ArrayList<>(); private List<ItemStack> secureObjects = new ArrayList<>();
private CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList<Sign> signClass = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<Sign> signClass = new CopyOnWriteArrayList<>();
@ -244,7 +244,7 @@ public class GameWorld {
/** /**
* @return the secureObjects * @return the secureObjects
*/ */
public List<Material> getSecureObjects() { public List<ItemStack> getSecureObjects() {
return secureObjects; return secureObjects;
} }
@ -252,7 +252,7 @@ public class GameWorld {
* @param secureObjects * @param secureObjects
* the secureObjects to set * the secureObjects to set
*/ */
public void setSecureObjects(List<Material> secureObjects) { public void setSecureObjects(List<ItemStack> secureObjects) {
this.secureObjects = secureObjects; this.secureObjects = secureObjects;
} }
@ -539,10 +539,7 @@ public class GameWorld {
/* Statics */ /* Statics */
public static GameWorld getByWorld(World world) { public static GameWorld getByWorld(World world) {
for (GameWorld gameWorld : plugin.getGameWorlds()) { for (GameWorld gameWorld : plugin.getGameWorlds()) {
if (gameWorld.getWorld() == null) { if (gameWorld.getWorld() != null && gameWorld.getWorld().equals(world)) {
continue;
} else if (gameWorld.getWorld().equals(world)) {
return gameWorld; return gameWorld;
} }
} }

View File

@ -4,7 +4,7 @@ version: ${project.version}
authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel]
description: ${project.description} description: ${project.description}
website: ${project.url} website: ${project.url}
softdepend: [BlueRoseCommons, CommandsXL, Vault, CustomMobs, InsaneMobs, MythicMobs] softdepend: [BlueRoseCommons, CommandsXL, ItemsXL, Vault, CustomMobs, InsaneMobs, MythicMobs]
commands: commands:
dungeonsxl: dungeonsxl:
description: Reference command for DungeonsXL. description: Reference command for DungeonsXL.