Skip to content

Commit

Permalink
CaliburnAPI / ItemsXL integration. Closes #74; closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed May 31, 2016
1 parent cd19d8c commit 68b8426
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 45 deletions.
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@
<pattern>io.github.dre2n.commons</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl</shadedPattern>
</relocation>
<relocation>
<pattern>io.github.dre2n.caliburn</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.caliburn</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>io.github.dre2n:commons</include>
<include>io.github.dre2n:caliburn</include>
</includes>
</artifactSet>
</configuration>
Expand All @@ -78,6 +83,16 @@
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</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>
<groupId>io.github.dre2n</groupId>
<artifactId>commandsxl</artifactId>
Expand All @@ -86,7 +101,7 @@
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId>
<version>2.0.17-SNAPSHOT</version>
<version>2.0.18-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,6 +54,7 @@
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;
Expand All @@ -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;
Expand Down Expand Up @@ -304,6 +308,24 @@ public static DungeonsXL getInstance() {
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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
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
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,24 +27,26 @@
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;
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
*/
public class WorldConfig extends GameRules {

DungeonsXL plugin = DungeonsXL.getInstance();
CompatibilityHandler compat = CompatibilityHandler.getInstance();

private File file;

Expand Down Expand Up @@ -79,13 +83,10 @@ public void load(ConfigurationSection configFile) {
/* Secure Objects */
if (configFile.contains("secureObjects")) {
List<String> 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);
}
}

Expand Down Expand Up @@ -244,14 +245,13 @@ public void save() {
configFile.set("message." + msgs, this.msgs.get(msgs));
}

// Secure Objects
CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<>();
List<String> 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);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +25,7 @@
import java.util.List;
import java.util.Map;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

/**
* @author Daniel Saukel
Expand Down Expand Up @@ -109,7 +110,7 @@ public class GameRules {

/* Misc */
protected Map<Integer, String> msgs;
protected List<Material> secureObjects;
protected List<ItemStack> secureObjects;

/* Getters and setters */
// keepInventory
Expand Down Expand Up @@ -315,7 +316,7 @@ public void setMsg(String msg, int id) {
/**
* @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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ public void onDropItem(PlayerDropItemEvent event) {

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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;
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand All @@ -46,8 +45,6 @@
*/
public class DMobType {

static DungeonsXL plugin = DungeonsXL.getInstance();

private String name;
private EntityType type;

Expand Down Expand Up @@ -75,7 +72,7 @@ public DMobType(File file) {

/**
* @param name
* the name of the Announcer
* the name of the DMobType
* @param config
* the config that stores the information
*/
Expand Down Expand Up @@ -178,7 +175,7 @@ public DMobType(String name, FileConfiguration config) {

/* Add Item to the drops map */
item.setItemMeta(itemMeta);
getDrops().put(item, chance);
drops.put(item, chance);
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +32,9 @@
*/
public class DClass {

DungeonsXL plugin = DungeonsXL.getInstance();
CompatibilityHandler compat = CompatibilityHandler.getInstance();

private String name;

private List<ItemStack> items = new ArrayList<>();
Expand All @@ -42,7 +48,13 @@ public DClass(String name, FileConfiguration config) {
this.name = name;

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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> fromConfig(ConfigurationSection configSectionClasses) {
List<String> items = configSectionClasses.getStringList("items");
CopyOnWriteArrayList<ItemStack> itemStacks = new CopyOnWriteArrayList<>();
public static List<ItemStack> deserializeStackList(List<String> items) {
List<ItemStack> itemStacks = new ArrayList<>();

for (String item : items) {
String[] itemSplit = item.split(",");
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
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;
Expand All @@ -53,6 +52,7 @@
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
Expand All @@ -71,7 +71,7 @@ public class GameWorld {
private Location locStart;
private boolean isPlaying = false;
private int id;
private List<Material> secureObjects = new ArrayList<>();
private List<ItemStack> secureObjects = new ArrayList<>();
private CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<>();

private CopyOnWriteArrayList<Sign> signClass = new CopyOnWriteArrayList<>();
Expand Down Expand Up @@ -244,15 +244,15 @@ public void setId(int id) {
/**
* @return the secureObjects
*/
public List<Material> getSecureObjects() {
public List<ItemStack> getSecureObjects() {
return secureObjects;
}

/**
* @param secureObjects
* the secureObjects to set
*/
public void setSecureObjects(List<Material> secureObjects) {
public void setSecureObjects(List<ItemStack> secureObjects) {
this.secureObjects = secureObjects;
}

Expand Down Expand Up @@ -539,10 +539,7 @@ public void load(String name) {
/* 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;
}
}
Expand Down
Loading

0 comments on commit 68b8426

Please sign in to comment.