From b175b2b50ba9bfc72958b5af54b1465800964353 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 26 Jul 2016 14:44:39 +0200 Subject: [PATCH 01/57] Add setup() method to requirement API --- .../dre2n/dungeonsxl/config/WorldConfig.java | 23 ++----------------- .../requirement/FeeLevelRequirement.java | 18 +++++++++++---- .../requirement/FeeMoneyRequirement.java | 18 +++++++++++---- .../requirement/GroupSizeRequirement.java | 18 +++++++++++---- .../requirement/PermissionRequirement.java | 6 +++++ .../dungeonsxl/requirement/Requirement.java | 3 +++ .../requirement/AwesomenessRequirement.java | 18 +++++++++++---- 7 files changed, 63 insertions(+), 41 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index 10e3b7ab..d9e8888b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -25,12 +25,7 @@ import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.game.GameType; -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.PermissionRequirement; import io.github.dre2n.dungeonsxl.requirement.Requirement; -import io.github.dre2n.dungeonsxl.requirement.RequirementTypeDefault; import io.github.dre2n.dungeonsxl.util.DeserializationUtil; import java.io.File; import java.io.IOException; @@ -187,24 +182,10 @@ public class WorldConfig extends GameRules { requirements = new ArrayList<>(); } + ConfigurationSection requirementSection = configFile.getConfigurationSection("requirements"); for (String identifier : configFile.getConfigurationSection("requirements").getKeys(false)) { Requirement requirement = Requirement.create(plugin.getRequirementTypes().getByIdentifier(identifier)); - - // Check for built-in requirements - if (requirement.getType() == RequirementTypeDefault.FEE_MONEY) { - ((FeeMoneyRequirement) requirement).setFee(configFile.getDouble("requirements.feeMoney")); - - } else if (requirement.getType() == RequirementTypeDefault.FEE_LEVEL) { - ((FeeLevelRequirement) requirement).setFee(configFile.getInt("requirements.feeLevel")); - - } else if (requirement.getType() == RequirementTypeDefault.GROUP_SIZE) { - ((GroupSizeRequirement) requirement).setMinimum(configFile.getInt("requirements.groupSize.minimum")); - ((GroupSizeRequirement) requirement).setMaximum(configFile.getInt("requirements.groupSize.maximum")); - - } else if (requirement.getType() == RequirementTypeDefault.PERMISSION) { - ((PermissionRequirement) requirement).setPermissions(configFile.getStringList("requirements.permission")); - } - + requirement.setup(requirementSection); requirements.add(requirement); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java index e36173f4..a40af95e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java @@ -20,6 +20,7 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DSavePlayer; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; /** @@ -31,6 +32,7 @@ public class FeeLevelRequirement extends Requirement { private int fee; + /* Getters and setters */ /** * @return the fee */ @@ -46,6 +48,17 @@ public class FeeLevelRequirement extends Requirement { this.fee = fee; } + @Override + public RequirementType getType() { + return type; + } + + /* Actions */ + @Override + public void setup(ConfigurationSection config) { + fee = config.getInt("feeLevel"); + } + @Override public boolean check(Player player) { return player.getLevel() >= fee; @@ -63,9 +76,4 @@ public class FeeLevelRequirement extends Requirement { MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.REQUIREMENT_FEE, fee + " levels")); } - @Override - public RequirementType getType() { - return type; - } - } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeMoneyRequirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeMoneyRequirement.java index 1098d485..e6efe73d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeMoneyRequirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeMoneyRequirement.java @@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.requirement; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; /** @@ -29,6 +30,7 @@ public class FeeMoneyRequirement extends Requirement { private double fee; + /* Getters and setters */ /** * @return the fee */ @@ -44,6 +46,17 @@ public class FeeMoneyRequirement extends Requirement { this.fee = fee; } + @Override + public RequirementType getType() { + return type; + } + + /* Actions */ + @Override + public void setup(ConfigurationSection config) { + fee = config.getDouble("feeMoney"); + } + @Override public boolean check(Player player) { if (plugin.getEconomyProvider() == null) { @@ -63,9 +76,4 @@ public class FeeMoneyRequirement extends Requirement { MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.REQUIREMENT_FEE, plugin.getEconomyProvider().format(fee))); } - @Override - public RequirementType getType() { - return type; - } - } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java index dc49a700..1e9adc45 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java @@ -17,6 +17,7 @@ package io.github.dre2n.dungeonsxl.requirement; import io.github.dre2n.dungeonsxl.player.DGroup; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; /** @@ -59,6 +60,18 @@ public class GroupSizeRequirement extends Requirement { this.maximum = maximum; } + @Override + public RequirementType getType() { + return type; + } + + /* Actions */ + @Override + public void setup(ConfigurationSection config) { + minimum = config.getInt("groupSize.minimum"); + maximum = config.getInt("groupSize.maximum"); + } + @Override public boolean check(Player player) { DGroup dGroup = DGroup.getByPlayer(player); @@ -70,9 +83,4 @@ public class GroupSizeRequirement extends Requirement { public void demand(Player player) { } - @Override - public RequirementType getType() { - return type; - } - } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java index 5523cd73..2b0c169e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java @@ -19,6 +19,7 @@ package io.github.dre2n.dungeonsxl.requirement; import io.github.dre2n.dungeonsxl.player.DPermissions; import java.util.ArrayList; import java.util.List; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; /** @@ -52,6 +53,11 @@ public class PermissionRequirement extends Requirement { } /* Actions */ + @Override + public void setup(ConfigurationSection config) { + permissions = config.getStringList("permission"); + } + @Override public boolean check(Player player) { for (String permission : permissions) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java index 340f29d7..7ef734ee 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java @@ -22,6 +22,7 @@ import io.github.dre2n.dungeonsxl.event.requirement.RequirementRegistrationEvent import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; /** @@ -56,6 +57,8 @@ public abstract class Requirement { } /* Abstracts */ + public abstract void setup(ConfigurationSection config); + public abstract boolean check(Player player); public abstract void demand(Player player); diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/requirement/AwesomenessRequirement.java b/core/src/test/java/io/github/dre2n/dungeonsxl/requirement/AwesomenessRequirement.java index a2a0ef9c..5053c3e2 100644 --- a/core/src/test/java/io/github/dre2n/dungeonsxl/requirement/AwesomenessRequirement.java +++ b/core/src/test/java/io/github/dre2n/dungeonsxl/requirement/AwesomenessRequirement.java @@ -17,6 +17,7 @@ package io.github.dre2n.dungeonsxl.requirement; import io.github.dre2n.commons.util.messageutil.MessageUtil; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; /** @@ -28,6 +29,7 @@ public class AwesomenessRequirement extends Requirement { private int level; + /* Getters and setters */ /** * @return the awesomeness level */ @@ -43,6 +45,17 @@ public class AwesomenessRequirement extends Requirement { this.level = level; } + @Override + public RequirementType getType() { + return type; + } + + /* Actions */ + @Override + public void setup(ConfigurationSection config) { + this.level = config.getInt("awesomeness"); + } + @Override public boolean check(Player player) { // Code that checks if the player has the requirement @@ -55,9 +68,4 @@ public class AwesomenessRequirement extends Requirement { // Code that removes the requirement if it is a fee } - @Override - public RequirementType getType() { - return type; - } - } From 3366f6b88397fbdcc849e46f5d3b02f7a1c3c75c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 26 Jul 2016 19:47:55 +0200 Subject: [PATCH 02/57] Rewrote player persistence system; close #117 --- abstract/pom.xml | 2 +- core/pom.xml | 2 +- .../github/dre2n/dungeonsxl/DungeonsXL.java | 3 - .../dungeonsxl/command/ReloadCommand.java | 1 - .../dre2n/dungeonsxl/config/DMessages.java | 1 + .../dre2n/dungeonsxl/config/PlayerData.java | 297 ++++++++++++- .../dungeonsxl/listener/PlayerListener.java | 20 +- .../dre2n/dungeonsxl/player/DEditPlayer.java | 4 +- .../dre2n/dungeonsxl/player/DGamePlayer.java | 4 +- .../dungeonsxl/player/DGlobalPlayer.java | 59 +++ .../dungeonsxl/player/DInstancePlayer.java | 31 +- .../dre2n/dungeonsxl/player/DPlayers.java | 37 -- .../dre2n/dungeonsxl/player/DSavePlayer.java | 399 ------------------ .../requirement/FeeLevelRequirement.java | 7 +- craftbukkit_1_10_R1/pom.xml | 2 +- craftbukkit_1_9_R1/pom.xml | 2 +- craftbukkit_1_9_R2/pom.xml | 2 +- pom.xml | 2 +- shade/pom.xml | 2 +- 19 files changed, 370 insertions(+), 507 deletions(-) delete mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/player/DSavePlayer.java diff --git a/abstract/pom.xml b/abstract/pom.xml index a7936f3d..924caced 100644 --- a/abstract/pom.xml +++ b/abstract/pom.xml @@ -8,6 +8,6 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/core/pom.xml b/core/pom.xml index d074bf05..6bfb8d3e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index edd5a20a..ba6a9560 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -39,7 +39,6 @@ import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.player.DPlayers; -import io.github.dre2n.dungeonsxl.player.DSavePlayer; import io.github.dre2n.dungeonsxl.requirement.RequirementTypes; import io.github.dre2n.dungeonsxl.reward.DLootInventory; import io.github.dre2n.dungeonsxl.reward.RewardTypes; @@ -280,14 +279,12 @@ public class DungeonsXL extends BRPlugin { // Save and load public void saveData() { protections.saveAll(); - DSavePlayer.save(); dWorlds.saveAll(); } public void loadData() { protections.loadAll(); dPlayers.loadAll(); - DSavePlayer.load(); dWorlds.check(); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java index ff60988d..290304cd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java @@ -23,7 +23,6 @@ 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.player.DPermissions; -import java.io.File; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.plugin.PluginManager; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 31e5dbe3..47f3445c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -140,6 +140,7 @@ public enum DMessages implements Messages { LOG_ERROR_SIGN_SETUP("Log_Error_SignSetup", "&4A sign at &6&v1&4 is erroneous!"), LOG_GENERATE_NEW_WORLD("Log_GenerateNewWorld", "&6Generating new world..."), LOG_IMPORT_WORLD("Log_ImportWorld", "&6Importing world..."), + LOG_KILLED_CORRUPTED_PLAYER("Log_KilledCorruptedPlayer", "&4Killed player &6&v1 &4because the data to restore his main inventory is corrupted :("), LOG_NEW_MAP("Log_NewDungeon", "&6Creating new map."), LOG_NEW_PLAYER_DATA("Log_NewPlayerData", "&6A new player data file has been created and saved as &v1."), LOG_WORLD_GENERATION_FINISHED("Log_WorldGenerationFinished", "&6World generation finished!"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java index 9d238163..880e04c3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java @@ -17,12 +17,22 @@ package io.github.dre2n.dungeonsxl.config; import io.github.dre2n.commons.config.BRConfig; +import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; /** * @author Daniel Saukel @@ -31,8 +41,25 @@ public class PlayerData extends BRConfig { DungeonsXL plugin = DungeonsXL.getInstance(); - public static final int CONFIG_VERSION = 1; + public static final int CONFIG_VERSION = 2; + public static final String PREFIX_STATE_PERSISTENCE = "savePlayer."; + public static final String PREFIX_STATS = "stats."; + + // State persistence + private Location oldLocation; + private List oldInventory; + private List oldArmor; + private ItemStack oldOffHand; + private int oldLvl; + private float oldExp; + private double oldHealth; + private int oldFoodLevel; + private int oldFireTicks; + private GameMode oldGameMode; + private Collection oldPotionEffects; + + // Stats private Map timeLastPlayed = new HashMap<>(); public PlayerData(File file) { @@ -44,6 +71,179 @@ public class PlayerData extends BRConfig { load(); } + /* Getters and setters */ + /** + * @return if the player was in a game when he left the game + */ + public boolean wasInGame() { + return config.contains(PREFIX_STATE_PERSISTENCE); + } + + /** + * @return the old location + */ + public Location getOldLocation() { + return oldLocation; + } + + /** + * @param location + * the location to set + */ + public void setOldLocation(Location location) { + oldLocation = location; + } + + /** + * @return the items in the old inventory + */ + public List getOldInventory() { + return oldInventory; + } + + /** + * @param inventory + * the inventory to set + */ + public void setOldInventory(List inventory) { + oldInventory = inventory; + } + + /** + * @return the items in the old armor slots + */ + public List getOldArmor() { + return oldArmor; + } + + /** + * @param inventory + * the inventory to set + */ + public void setOldArmor(List inventory) { + oldArmor = inventory; + } + + /** + * @return the items in the old off-hand slot + */ + public ItemStack getOldOffHand() { + return oldOffHand; + } + + /** + * @param offHand + * the off hand item to set + */ + public void setOldOffHand(ItemStack offHand) { + oldOffHand = offHand; + } + + /** + * @return the old level + */ + public int getOldLevel() { + return oldLvl; + } + + /** + * @param level + * the level to set + */ + public void setOldLevel(int level) { + oldLvl = level; + } + + /** + * @return the old exp + */ + public float getOldExp() { + return oldExp; + } + + /** + * @param exp + * the amount of exp to set + */ + public void setOldExp(float exp) { + oldExp = exp; + } + + /** + * @return the old health + */ + public double getOldHealth() { + return oldHealth; + } + + /** + * @param health + * the health to set + */ + public void setOldHealth(double health) { + oldHealth = health; + } + + /** + * @return the old food level + */ + public int getOldFoodLevel() { + return oldFoodLevel; + } + + /** + * @param foodLevel + * the food level to set + */ + public void setOldFoodLevel(int foodLevel) { + oldFoodLevel = foodLevel; + } + + /** + * @return the old fire ticks + */ + public int getOldFireTicks() { + return oldFireTicks; + } + + /** + * @param fireTicks + * the fire ticks to set + */ + public void setFireTicks(int fireTicks) { + oldFireTicks = fireTicks; + } + + /** + * @return the old GameMode + */ + public GameMode getOldGameMode() { + return oldGameMode; + } + + /** + * @param gameMode + * the GameMode to set + */ + public void setOldGameMode(GameMode gameMode) { + oldGameMode = gameMode; + } + + /** + * @return the old potion effects + */ + public Collection getOldPotionEffects() { + return oldPotionEffects; + } + + /** + * @param potionEffects + * the potion effects to set + */ + public void setOldPotionEffects(Collection potionEffects) { + oldPotionEffects = potionEffects; + } + /** * @return a map of the player's finished dungeons with dates. */ @@ -76,6 +276,7 @@ public class PlayerData extends BRConfig { save(); } + /* Actions */ /** * @param dungeon * the finished dungeon @@ -87,8 +288,8 @@ public class PlayerData extends BRConfig { @Override public void initialize() { - if (!config.contains("timeLastPlayed")) { - config.createSection("timeLastPlayed"); + if (!config.contains(PREFIX_STATS + "timeLastPlayed")) { + config.createSection(PREFIX_STATS + "timeLastPlayed"); } if (!file.exists()) { @@ -104,17 +305,99 @@ public class PlayerData extends BRConfig { @Override public void load() { - if (config.isConfigurationSection("timeLastPlayed")) { - for (String key : config.getConfigurationSection("timeLastPlayed").getKeys(false)) { - timeLastPlayed.put(key, config.getLong("timeLastPlayed." + key)); + if (config.isConfigurationSection(PREFIX_STATS + "timeLastPlayed")) { + for (String key : config.getConfigurationSection(PREFIX_STATS + "timeLastPlayed").getKeys(false)) { + timeLastPlayed.put(key, config.getLong(PREFIX_STATS + "timeLastPlayed." + key)); } } + + if (!wasInGame()) { + return; + } + + oldInventory = (List) config.get(PREFIX_STATE_PERSISTENCE + "oldInventory"); + oldArmor = (List) config.get(PREFIX_STATE_PERSISTENCE + "oldArmor"); + oldOffHand = (ItemStack) config.get(PREFIX_STATE_PERSISTENCE + "oldOffHand"); + + oldLvl = config.getInt(PREFIX_STATE_PERSISTENCE + "oldLvl"); + oldExp = config.getInt(PREFIX_STATE_PERSISTENCE + "oldExp"); + oldHealth = config.getInt(PREFIX_STATE_PERSISTENCE + "oldHealth"); + oldFoodLevel = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFoodLevel"); + oldFireTicks = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFireTicks"); + + if (EnumUtil.isValidEnum(GameMode.class, config.getString(PREFIX_STATE_PERSISTENCE + "oldGameMode"))) { + oldGameMode = GameMode.valueOf(config.getString(PREFIX_STATE_PERSISTENCE + "oldGameMode")); + } else { + oldGameMode = GameMode.SURVIVAL; + } + oldPotionEffects = (Collection) config.get(PREFIX_STATE_PERSISTENCE + "oldPotionEffects"); + + oldLocation = (Location) config.get(PREFIX_STATE_PERSISTENCE + "oldLocation"); + if (oldLocation.getWorld() == null) { + oldLocation = plugin.getServer().getWorlds().get(0).getSpawnLocation(); + } } @Override public void save() { - config.set("timeLastPlayed", timeLastPlayed); + config.set(PREFIX_STATS + "timeLastPlayed", timeLastPlayed); super.save(); } + /** + * Saves the player's data to the file. + * + * @param player + * the Player to save + */ + public void savePlayerState(Player player) { + oldGameMode = player.getGameMode(); + oldFireTicks = player.getFireTicks(); + oldFoodLevel = player.getFoodLevel(); + oldHealth = player.getHealth(); + oldExp = player.getExp(); + oldLvl = player.getLevel(); + oldArmor = new ArrayList<>(Arrays.asList(player.getInventory().getArmorContents())); + oldInventory = new ArrayList<>(Arrays.asList(player.getInventory().getContents())); + oldOffHand = player.getInventory().getItemInOffHand(); + oldLocation = player.getLocation(); + oldPotionEffects = player.getActivePotionEffects(); + + config.set(PREFIX_STATE_PERSISTENCE + "oldGameMode", oldGameMode.toString()); + config.set(PREFIX_STATE_PERSISTENCE + "oldFireTicks", oldFireTicks); + config.set(PREFIX_STATE_PERSISTENCE + "oldFoodLevel", oldFoodLevel); + config.set(PREFIX_STATE_PERSISTENCE + "oldHealth", oldHealth); + config.set(PREFIX_STATE_PERSISTENCE + "oldExp", oldExp); + config.set(PREFIX_STATE_PERSISTENCE + "oldLvl", oldLvl); + config.set(PREFIX_STATE_PERSISTENCE + "oldArmor", oldArmor); + config.set(PREFIX_STATE_PERSISTENCE + "oldInventory", oldInventory); + config.set(PREFIX_STATE_PERSISTENCE + "oldOffHand", oldOffHand); + config.set(PREFIX_STATE_PERSISTENCE + "oldLocation", oldLocation); + config.set(PREFIX_STATE_PERSISTENCE + "oldPotionEffects", oldPotionEffects); + + save(); + } + + /** + * Removes the state data from the file + */ + public void clearPlayerState() { + oldGameMode = null; + oldFireTicks = 0; + oldFoodLevel = 0; + oldHealth = 0; + oldExp = 0; + oldLvl = 0; + oldArmor = null; + oldInventory = null; + oldOffHand = null; + oldLocation = null; + oldPotionEffects = null; + + if (wasInGame()) { + config.set("savePlayer", null); + } + save(); + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index fbc16e4f..73cdbbbe 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -35,7 +35,6 @@ import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.player.DPlayers; -import io.github.dre2n.dungeonsxl.player.DSavePlayer; import io.github.dre2n.dungeonsxl.reward.DLootInventory; import io.github.dre2n.dungeonsxl.reward.RewardChest; import io.github.dre2n.dungeonsxl.sign.OpenDoorSign; @@ -45,7 +44,6 @@ import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.ArrayList; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -486,25 +484,13 @@ public class PlayerListener implements Listener { if (dPlayer != null) { DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer()); if (dGroup != null) { - dGroup.getPlayers().remove(dPlayer.getPlayer()); - dGroup.getPlayers().add(player); + dGroup.removePlayer(dPlayer.getPlayer()); + dGroup.addPlayer(player); } dPlayer.setPlayer(player); // Check offlineTime dPlayer.setOfflineTime(0); - - } else { - DSavePlayer dSavePlayer = dPlayers.getDSavePlayerByPlayer(player); - - Location target = Bukkit.getServer().getWorlds().get(0).getSpawnLocation(); - if (dSavePlayer != null) { - target = dSavePlayer.getOldLocation(); - } - - if (DEditWorld.getByWorld(player.getWorld()) != null || DGameWorld.getByWorld(player.getWorld()) != null) { - player.teleport(target); - } } // Tutorial Mode @@ -547,7 +533,7 @@ public class PlayerListener implements Listener { } if (dGroup.getGameWorld() == null) { - dGroup.setGameWorld(plugin.getDWorlds().getResourceByName(DGroup.getByPlayer(player).getMapName()).instantiateAsGameWorld());// TO DO + dGroup.setGameWorld(plugin.getDWorlds().getResourceByName(DGroup.getByPlayer(player).getMapName()).instantiateAsGameWorld()); dGroup.getGameWorld().setTutorial(true); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java index 8e5bfbab..5afc050e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java @@ -106,7 +106,7 @@ public class DEditPlayer extends DInstancePlayer { */ public void escape() { delete(); - getSavePlayer().reset(false); + reset(false); } public void poke(Block block) { @@ -142,7 +142,7 @@ public class DEditPlayer extends DInstancePlayer { public void leave() { delete(); - getSavePlayer().reset(false); + reset(false); DEditWorld editWorld = DEditWorld.getByWorld(getWorld()); if (editWorld != null) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 17e9f175..10c84ff1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -381,9 +381,9 @@ public class DGamePlayer extends DInstancePlayer { delete(); if (finished) { - getSavePlayer().reset(rules.getKeepInventoryOnFinish()); + reset(rules.getKeepInventoryOnFinish()); } else { - getSavePlayer().reset(rules.getKeepInventoryOnEscape()); + reset(rules.getKeepInventoryOnEscape()); } // Permission bridge diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index c90270b0..0e164d46 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -16,12 +16,19 @@ */ package io.github.dre2n.dungeonsxl.player; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Version; +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.PlayerData; import io.github.dre2n.dungeonsxl.global.DPortal; import java.io.File; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; /** * Represents a player in the non-DXL worlds of the server. @@ -45,8 +52,16 @@ public class DGlobalPlayer { private ItemStack[] respawnArmor; public DGlobalPlayer(Player player) { + this(player, false); + } + + public DGlobalPlayer(Player player, boolean reset) { this.player = player; + loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml")); + if (reset && data.wasInGame()) { + reset(false); + } plugin.getDPlayers().addPlayer(this); } @@ -63,6 +78,7 @@ public class DGlobalPlayer { plugin.getDPlayers().addPlayer(this); } + /* Getters and setters */ /** * @return the Bukkit player */ @@ -213,4 +229,47 @@ public class DGlobalPlayer { return DPermissions.hasPermission(player, permission); } + /* Actions */ + /** + * Respawns the player at his old position before he was in a dungeon + */ + public void reset(boolean keepInventory) { + try { + if (!keepInventory) { + while (data.getOldInventory().size() > 36) { + data.getOldInventory().remove(36); + } + player.getInventory().setContents(data.getOldInventory().toArray(new ItemStack[36])); + player.getInventory().setArmorContents(data.getOldArmor().toArray(new ItemStack[4])); + if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { + player.getInventory().setItemInOffHand(data.getOldOffHand()); + } + player.setLevel(data.getOldLevel()); + player.setExp(data.getOldExp()); + player.setHealth(data.getOldHealth()); + player.setFoodLevel(data.getOldFoodLevel()); + player.setGameMode(data.getOldGameMode()); + player.setFireTicks(data.getOldFireTicks()); + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + + player.addPotionEffects(data.getOldPotionEffects()); + } + + if (data.getOldLocation().getWorld() != null) { + PlayerUtil.secureTeleport(player, data.getOldLocation()); + } else { + PlayerUtil.secureTeleport(player, Bukkit.getWorlds().get(0).getSpawnLocation()); + } + + } catch (NullPointerException exception) { + exception.printStackTrace(); + player.setHealth(0); + MessageUtil.log(plugin, DMessages.LOG_KILLED_CORRUPTED_PLAYER.getMessage(player.getName())); + } + + data.clearPlayerState(); + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java index 8acdc41d..275e6c70 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java @@ -16,8 +16,6 @@ */ package io.github.dre2n.dungeonsxl.player; -import io.github.dre2n.commons.compatibility.CompatibilityHandler; -import io.github.dre2n.commons.compatibility.Version; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; @@ -27,41 +25,16 @@ import org.bukkit.potion.PotionEffect; */ public abstract class DInstancePlayer extends DGlobalPlayer { - private DSavePlayer savePlayer; private World world; private boolean inDungeonChat = false; DInstancePlayer(Player player, World world) { - super(player); - - double health = player.getHealth(); - if (!Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { - savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), null, player.getLevel(), - player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects()); - } else { - savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getInventory().getItemInOffHand(), player.getLevel(), - player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects()); - } - + super(player, false); this.world = world; + getData().savePlayerState(player); } /* Getters and setters */ - /** - * @return the savePlayer - */ - public DSavePlayer getSavePlayer() { - return savePlayer; - } - - /** - * @param savePlayer - * the savePlayer to set - */ - public void setSavePlayer(DSavePlayer savePlayer) { - this.savePlayer = savePlayer; - } - /** * @return * the instance diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java index d632be1c..9619af11 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java @@ -28,7 +28,6 @@ import org.bukkit.entity.Player; public class DPlayers { private CopyOnWriteArrayList dGlobalPlayers = new CopyOnWriteArrayList<>(); - private CopyOnWriteArrayList dSavePlayers = new CopyOnWriteArrayList<>(); /** * @return the DGlobalPlayer which represents the player @@ -111,42 +110,6 @@ public class DPlayers { dGlobalPlayers.remove(player); } - /** - * @return the DSavePlayer that represents the player - */ - public DSavePlayer getDSavePlayerByPlayer(Player player) { - for (DSavePlayer dSavePlayer : dSavePlayers) { - if (dSavePlayer.getName().equals(player.getName())) { - return dSavePlayer; - } - } - - return null; - } - - /** - * @return the dSavePlayers - */ - public List getDSavePlayers() { - return dSavePlayers; - } - - /** - * @param dSavePlayer - * the dSavePlayer to add - */ - public void addDSavePlayer(DSavePlayer dSavePlayer) { - dSavePlayers.add(dSavePlayer); - } - - /** - * @param dSavePlayer - * the dSavePlayer to remove - */ - public void removeDSavePlayer(DSavePlayer dSavePlayer) { - dSavePlayers.remove(dSavePlayer); - } - /** * Load all players */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DSavePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DSavePlayer.java deleted file mode 100644 index d6fef445..00000000 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DSavePlayer.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (C) 2012-2016 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package io.github.dre2n.dungeonsxl.player; - -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.playerutil.PlayerUtil; -import io.github.dre2n.dungeonsxl.DungeonsXL; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; - -/** - * Represents a player in a GameWorld who went offline. - * - * @author Frank Baumann, Tobias Schmitz, Milan Albrecht, Daniel Saukel - */ -public class DSavePlayer { - - static DungeonsXL plugin = DungeonsXL.getInstance(); - static DPlayers dPlayers = plugin.getDPlayers(); - - // Variables - private String name; - private String uuid; - - private Location oldLocation; - private List oldInventory; - private List oldArmor; - private ItemStack oldOffHand; - private int oldLvl; - private int oldExp; - private double oldHealth; - private int oldFoodLevel; - private int oldFireTicks; - private GameMode oldGameMode; - private Collection oldPotionEffects; - - public DSavePlayer(String name, UUID uuid, Location oldLocation, ArrayList oldInventory, ArrayList oldArmor, ItemStack oldOffHand, int oldLvl, int oldExp, double oldHealth, int oldFoodLevel, int oldFireTicks, - GameMode oldGameMode, Collection oldPotionEffects) { - this.name = name; - this.uuid = uuid.toString(); - - this.oldLocation = oldLocation; - this.oldInventory = oldInventory; - this.oldArmor = oldArmor; - this.oldOffHand = oldOffHand; - this.oldExp = oldExp; - this.oldHealth = oldHealth; - this.oldFoodLevel = oldFoodLevel; - this.oldGameMode = oldGameMode; - this.oldLvl = oldLvl; - this.oldFireTicks = oldFireTicks; - this.oldPotionEffects = oldPotionEffects; - - save(); - dPlayers.addDSavePlayer(this); - } - - public DSavePlayer(String name, UUID uuid, Location oldLocation, ItemStack[] oldInventory, ItemStack[] oldArmor, ItemStack oldOffHand, int oldLvl, int oldExp, double oldHealth, int oldFoodLevel, int oldFireTicks, - GameMode oldGameMode, Collection oldPotionEffects) { - this(name, uuid, oldLocation, new ArrayList<>(Arrays.asList(oldInventory)), new ArrayList<>(Arrays.asList(oldArmor)), oldOffHand, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGameMode, oldPotionEffects); - } - - /* Getters and setters */ - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the uuid - */ - public UUID getUniqueId() { - return UUID.fromString(uuid); - } - - /** - * @return the old location - */ - public Location getOldLocation() { - return oldLocation; - } - - /** - * @param location - * the location to set - */ - public void setOldLocation(Location location) { - oldLocation = location; - } - - /** - * @return the items in the old inventory - */ - public List getOldInventory() { - return oldInventory; - } - - /** - * @param inventory - * the inventory to set - */ - public void setOldInventory(List inventory) { - oldInventory = inventory; - } - - /** - * @return the items in the old armor slots - */ - public List getOldArmor() { - return oldArmor; - } - - /** - * @param inventory - * the inventory to set - */ - public void setOldArmor(List inventory) { - oldArmor = inventory; - } - - /** - * @return the items in the old off-hand slot - */ - public ItemStack getOldOffHand() { - return oldOffHand; - } - - /** - * @param offHand - * the off hand item to set - */ - public void setOldOffHand(ItemStack offHand) { - oldOffHand = offHand; - } - - /** - * @return the old level - */ - public int getOldLevel() { - return oldLvl; - } - - /** - * @param level - * the level to set - */ - public void setOldLevel(int level) { - oldLvl = level; - } - - /** - * @return the old exp - */ - public int getOldExp() { - return oldExp; - } - - /** - * @param exp - * the amount of exp to set - */ - public void setOldExp(int exp) { - oldExp = exp; - } - - /** - * @return the old health - */ - public double getOldHealth() { - return oldHealth; - } - - /** - * @param health - * the health to set - */ - public void setOldHealth(double health) { - oldHealth = health; - } - - /** - * @return the old food level - */ - public int getOldFoodLevel() { - return oldFoodLevel; - } - - /** - * @param foodLevel - * the food level to set - */ - public void setOldFoodLevel(int foodLevel) { - oldFoodLevel = foodLevel; - } - - /** - * @return the old fire ticks - */ - public int getOldFireTicks() { - return oldFireTicks; - } - - /** - * @param fireTicks - * the fire ticks to set - */ - public void setFireTicks(int fireTicks) { - oldFireTicks = fireTicks; - } - - /** - * @return the old GameMode - */ - public GameMode getOldGameMode() { - return oldGameMode; - } - - /** - * @param gameMode - * the GameMode to set - */ - public void setOldGameMode(GameMode gameMode) { - oldGameMode = gameMode; - } - - /** - * @return the old potion effects - */ - public Collection getOldPotionEffects() { - return oldPotionEffects; - } - - /** - * @param potionEffects - * the potion effects to set - */ - public void setOldPotionEffects(Collection potionEffects) { - oldPotionEffects = potionEffects; - } - - /* Actions */ - public void reset(boolean keepInventory) { - Player player = plugin.getServer().getPlayer(name); - boolean offline = false; - if (player == null) { - player = PlayerUtil.getOfflinePlayer(name, UUID.fromString(uuid), oldLocation); - offline = true; - } - if (player == null) { - return; - } - - try { - if (!keepInventory) { - while (oldInventory.size() > 36) { - oldInventory.remove(36); - } - player.getInventory().setContents(oldInventory.toArray(new ItemStack[36])); - player.getInventory().setArmorContents(oldArmor.toArray(new ItemStack[4])); - if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { - player.getInventory().setItemInOffHand(oldOffHand); - } - player.setTotalExperience(oldExp); - player.setLevel(oldLvl); - player.setHealth(oldHealth); - player.setFoodLevel(oldFoodLevel); - player.setGameMode(oldGameMode); - player.setFireTicks(oldFireTicks); - for (PotionEffect effect : player.getActivePotionEffects()) { - player.removePotionEffect(effect.getType()); - } - // Causes NPE if offline - if (!offline) { - player.addPotionEffects(oldPotionEffects); - - } else { - player.saveData(); - } - } - - if (!offline && oldLocation.getWorld() != null) { - PlayerUtil.secureTeleport(player, oldLocation); - } else { - PlayerUtil.secureTeleport(player, Bukkit.getWorlds().get(0).getSpawnLocation()); - } - - } catch (NullPointerException exception) { - plugin.getLogger().info("Corrupted playerdata detected and removed!"); - } - - save(); - dPlayers.removeDSavePlayer(this); - } - - /* Statics */ - @Deprecated - public static void save() { - FileConfiguration configFile = new YamlConfiguration(); - - for (DSavePlayer savePlayer : dPlayers.getDSavePlayers()) { - configFile.set(savePlayer.name + ".uuid", savePlayer.uuid); - configFile.set(savePlayer.name + ".oldGameMode", savePlayer.oldGameMode.toString()); - configFile.set(savePlayer.name + ".oldFireTicks", savePlayer.oldFireTicks); - configFile.set(savePlayer.name + ".oldFoodLevel", savePlayer.oldFoodLevel); - configFile.set(savePlayer.name + ".oldHealth", savePlayer.oldHealth); - configFile.set(savePlayer.name + ".oldExp", savePlayer.oldExp); - configFile.set(savePlayer.name + ".oldLvl", savePlayer.oldLvl); - configFile.set(savePlayer.name + ".oldArmor", savePlayer.oldArmor); - configFile.set(savePlayer.name + ".oldInventory", savePlayer.oldInventory); - configFile.set(savePlayer.name + ".oldOffHand", savePlayer.oldOffHand); - configFile.set(savePlayer.name + ".oldLocation.x", savePlayer.oldLocation.getX()); - configFile.set(savePlayer.name + ".oldLocation.y", savePlayer.oldLocation.getY()); - configFile.set(savePlayer.name + ".oldLocation.z", savePlayer.oldLocation.getZ()); - configFile.set(savePlayer.name + ".oldLocation.yaw", savePlayer.oldLocation.getYaw()); - configFile.set(savePlayer.name + ".oldLocation.pitch", savePlayer.oldLocation.getPitch()); - configFile.set(savePlayer.name + ".oldLocation.world", savePlayer.oldLocation.getWorld().getName()); - configFile.set(savePlayer.name + ".oldPotionEffects", savePlayer.oldPotionEffects); - } - - try { - configFile.save(new File(plugin.getDataFolder(), "savePlayers.yml")); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Deprecated - public static void load() { - FileConfiguration configFile = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "savePlayers.yml")); - - for (String name : configFile.getKeys(false)) { - // Load uuid - UUID uuid = UUID.fromString(configFile.getString(name + ".uuid")); - - // Load inventory data - ArrayList oldInventory = (ArrayList) configFile.get(name + ".oldInventory"); - ArrayList oldArmor = (ArrayList) configFile.get(name + ".oldArmor"); - ItemStack oldOffHand = (ItemStack) configFile.get(name + ".oldOffHand"); - - // Load other data - int oldLvl = configFile.getInt(name + ".oldLvl"); - int oldExp = configFile.getInt(name + ".oldExp"); - int oldHealth = configFile.getInt(name + ".oldHealth"); - int oldFoodLevel = configFile.getInt(name + ".oldFoodLevel"); - int oldFireTicks = configFile.getInt(name + ".oldFireTicks"); - GameMode oldGameMode = GameMode.SURVIVAL; - if (EnumUtil.isValidEnum(GameMode.class, configFile.getString(name + ".oldGameMode"))) { - oldGameMode = GameMode.valueOf(configFile.getString(name + ".oldGameMode")); - } - Collection oldPotionEffects = (Collection) configFile.get(name + ".oldPotionEffects"); - - // Location - World world = plugin.getServer().getWorld(configFile.getString(name + ".oldLocation.world")); - if (world == null) { - world = plugin.getServer().getWorlds().get(0); - } - - Location oldLocation = new Location(world, configFile.getDouble(name + ".oldLocation.x"), configFile.getDouble(name + ".oldLocation.y"), configFile.getDouble(name - + ".oldLocation.z"), configFile.getInt(name + ".oldLocation.yaw"), configFile.getInt(name + ".oldLocation.pitch")); - - // Create Player - DSavePlayer savePlayer = new DSavePlayer(name, uuid, oldLocation, oldInventory, oldArmor, oldOffHand, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGameMode, oldPotionEffects); - savePlayer.reset(false); - } - } - -} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java index a40af95e..5688d087 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java @@ -18,8 +18,8 @@ package io.github.dre2n.dungeonsxl.requirement; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.config.PlayerData; import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.player.DSavePlayer; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -70,8 +70,9 @@ public class FeeLevelRequirement extends Requirement { if (dPlayer == null) { return; } - DSavePlayer dSavePlayer = dPlayer.getSavePlayer(); - dSavePlayer.setOldLevel(dSavePlayer.getOldLevel() - fee); + + PlayerData data = dPlayer.getData(); + data.setOldLevel(data.getOldLevel() - fee); MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.REQUIREMENT_FEE, fee + " levels")); } diff --git a/craftbukkit_1_10_R1/pom.xml b/craftbukkit_1_10_R1/pom.xml index ea1a5bd9..df616a42 100644 --- a/craftbukkit_1_10_R1/pom.xml +++ b/craftbukkit_1_10_R1/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/craftbukkit_1_9_R1/pom.xml b/craftbukkit_1_9_R1/pom.xml index f9edf9f0..d3be7605 100644 --- a/craftbukkit_1_9_R1/pom.xml +++ b/craftbukkit_1_9_R1/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/craftbukkit_1_9_R2/pom.xml b/craftbukkit_1_9_R2/pom.xml index 99459d94..b1e69498 100644 --- a/craftbukkit_1_9_R2/pom.xml +++ b/craftbukkit_1_9_R2/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/pom.xml b/pom.xml index a6b4dfd8..bff956df 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT pom DungeonsXL https://dre2n.github.io diff --git a/shade/pom.xml b/shade/pom.xml index d67cf276..23b07e46 100644 --- a/shade/pom.xml +++ b/shade/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT dungeonsxl-${project.version}${buildNo} From 3124a708cc78a06a5c0f1178732e5e6b3596583a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 26 Jul 2016 20:50:18 +0200 Subject: [PATCH 03/57] #116: Added enhanced game rules for block breaking Still requires implementation! --- .../dre2n/dungeonsxl/config/WorldConfig.java | 52 ++++++++++-- .../dre2n/dungeonsxl/game/GameRules.java | 81 ++++++++++++++++--- .../dre2n/dungeonsxl/game/GameType.java | 32 ++++++-- .../dungeonsxl/game/GameTypeDefault.java | 70 +++++++++++----- .../dungeonsxl/listener/BlockListener.java | 2 +- .../dre2n/dungeonsxl/sign/PlaceSign.java | 2 +- .../dre2n/dungeonsxl/world/DGameWorld.java | 1 - .../{game => world}/GamePlaceableBlock.java | 3 +- .../dre2n/dungeonsxl/game/CustomGameType.java | 41 ++++++++-- 9 files changed, 229 insertions(+), 55 deletions(-) rename core/src/main/java/io/github/dre2n/dungeonsxl/{game => world}/GamePlaceableBlock.java (98%) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index d9e8888b..d1f7b65c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -30,10 +30,14 @@ import io.github.dre2n.dungeonsxl.util.DeserializationUtil; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map.Entry; 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; @@ -121,12 +125,7 @@ public class WorldConfig extends GameRules { keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath"); } - /* Build */ - if (configFile.contains("build")) { - build = configFile.getBoolean("build"); - } - - /* GameMode */ + /* World interaction */ if (configFile.contains("gameMode")) { if (EnumUtil.isValidEnum(GameMode.class, configFile.getString("gameMode").toUpperCase())) { gameMode = GameMode.valueOf(configFile.getString("gameMode")); @@ -135,6 +134,47 @@ public class WorldConfig extends GameRules { } } + if (configFile.contains("breakBlocks")) { + breakBlocks = configFile.getBoolean("breakBlocks"); + } + + if (configFile.contains("breakPlacedBlocks")) { + breakPlacedBlocks = configFile.getBoolean("breakPlacedBlocks"); + } + + if (configFile.contains("breakWhitelist")) { + breakWhitelist = new HashMap<>(); + for (Entry entry : configFile.getConfigurationSection("breakWhitelist").getValues(true).entrySet()) { + Material breakable = Material.matchMaterial(entry.getKey()); + + HashSet tools = new HashSet<>(); + if (entry.getValue() instanceof List) { + for (String materialString : (List) entry.getValue()) { + Material tool = Material.matchMaterial(materialString); + if (tool != null) { + tools.add(tool); + } + } + } + + breakWhitelist.put(breakable, tools); + } + } + + if (configFile.contains("placeBlocks")) { + placeBlocks = configFile.getBoolean("placeBlocks"); + } + + if (configFile.contains("placeWhitelist")) { + placeWhitelist = new HashSet<>(); + for (String materialString : configFile.getStringList("placeWhitelist")) { + Material material = Material.matchMaterial(materialString); + if (material != null) { + placeWhitelist.add(material); + } + } + } + /* PvP */ if (configFile.contains("playerVersusPlayer")) { playerVersusPlayer = configFile.getBoolean("playerVersusPlayer"); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 98dc7654..4cbb0fb3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -20,9 +20,12 @@ import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.bukkit.GameMode; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; /** @@ -42,7 +45,11 @@ public class GameRules { /* World interaction */ DEFAULT_VALUES.gameMode = GameMode.SURVIVAL; - DEFAULT_VALUES.build = false; + DEFAULT_VALUES.breakBlocks = false; + DEFAULT_VALUES.breakPlacedBlocks = false; + DEFAULT_VALUES.breakWhitelist = null; + DEFAULT_VALUES.placeBlocks = false; + DEFAULT_VALUES.placeWhitelist = null; /* Fighting */ DEFAULT_VALUES.playerVersusPlayer = false; @@ -81,7 +88,11 @@ public class GameRules { /* World interaction */ protected GameMode gameMode; - protected Boolean build; + protected Boolean breakBlocks; + protected Boolean breakPlacedBlocks; + protected Map> breakWhitelist; + protected Boolean placeBlocks; + protected Set placeWhitelist; /* Fighting */ protected Boolean playerVersusPlayer; @@ -156,10 +167,38 @@ public class GameRules { } /** - * @return if players may build + * @return if all blocks may be destroyed */ - public boolean canBuild() { - return build; + public boolean canBreakBlocks() { + return breakBlocks; + } + + /** + * @return if blocks placed in game may be destroyed + */ + public boolean canBreakPlacedBlocks() { + return breakPlacedBlocks; + } + + /** + * @return the destroyable materials and the materials that may be used to break them or null if any + */ + public Map> getBreakWhitelist() { + return breakWhitelist; + } + + /** + * @return if blocks may be placed + */ + public boolean canPlaceBlocks() { + return placeBlocks; + } + + /** + * @return the placeable materials + */ + public Set getPlaceWhitelist() { + return placeWhitelist; } // Fight @@ -357,8 +396,16 @@ public class GameRules { timeToFinish = defaultValues.getShowTime() ? null : -1; } - if (build == null) { - build = defaultValues.canBuild(); + if (breakBlocks == null) { + breakBlocks = defaultValues.canBreakBlocks(); + } + + if (breakPlacedBlocks == null) { + breakPlacedBlocks = defaultValues.canBreakPlacedBlocks(); + } + + if (placeBlocks == null) { + placeBlocks = defaultValues.canPlaceBlocks(); } if (gameMode == null) { @@ -397,8 +444,24 @@ public class GameRules { gameMode = defaultValues.gameMode; } - if (build == null) { - build = defaultValues.build; + if (breakBlocks == null) { + breakBlocks = defaultValues.breakBlocks; + } + + if (breakPlacedBlocks == null) { + breakPlacedBlocks = defaultValues.breakPlacedBlocks; + } + + if (breakWhitelist == null) { + breakWhitelist = defaultValues.breakWhitelist; + } + + if (placeBlocks == null) { + placeBlocks = defaultValues.placeBlocks; + } + + if (placeWhitelist == null) { + placeWhitelist = defaultValues.placeWhitelist; } /* Fighting */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java index f5f84333..4a7e843c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java @@ -101,15 +101,37 @@ public interface GameType { public void setShowTime(boolean showTime); /** - * @return if players can build + * @return if all blocks may be destroyed */ - public boolean canBuild(); + public boolean canBreakBlocks(); /** - * @param build - * enable / disable building + * @param breakBlocks + * if blocks may be destroyed */ - public void setBuild(boolean build); + public void setBreakBlocks(boolean breakBlocks); + + /** + * @return if blocks placed in game may be destroyed + */ + public boolean canBreakPlacedBlocks(); + + /** + * @param breakPlacedBlocks + * if placed blocks may be destroyed + */ + public void setBreakPlacedBlocks(boolean breakPlacedBlocks); + + /** + * @return if blocks may be placed + */ + public boolean canPlaceBlocks(); + + /** + * @param placeBlocks + * if blocks may be placed + */ + public void setPlaceBlocks(boolean placeBlocks); /** * @return the gameMode diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java index ab131494..4fddf370 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java @@ -23,21 +23,22 @@ import org.bukkit.GameMode; */ public enum GameTypeDefault implements GameType { - ADVENTURE("Adventure", "Adventure", false, false, false, true, false, true, GameMode.ADVENTURE, true), - ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, false, true, true, true, GameMode.ADVENTURE, true), - APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, true, false, false, GameMode.SURVIVAL, true), - APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", true, true, true, true, false, false, GameMode.SURVIVAL, true), - APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", true, true, true, true, true, false, GameMode.SURVIVAL, true), - PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", false, false, true, true, false, false, GameMode.SURVIVAL, true), - PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, false, true, true, false, false, GameMode.SURVIVAL, true), - PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, false, true, true, true, false, GameMode.SURVIVAL, true), - PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, false, false, false, false, false, GameMode.SURVIVAL, true), - PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, false, false, false, false, false, GameMode.SURVIVAL, true), - QUEST("Quest", "Quest", false, false, false, true, false, false, GameMode.SURVIVAL, true), - QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, true, true, false, GameMode.SURVIVAL, true), - TEST("Test", "Test", false, false, false, false, true, true, GameMode.SURVIVAL, false), - TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, GameMode.SURVIVAL, false), - DEFAULT("Default", "Default", false, false, false, true, false, false, GameMode.SURVIVAL, true); + ADVENTURE("Adventure", "Adventure", false, false, false, true, false, true, true, true, GameMode.ADVENTURE, true), + ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, false, true, true, true, true, true, GameMode.ADVENTURE, true), + APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), + APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), + APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", true, true, true, true, true, false, false, false, GameMode.SURVIVAL, true), + BEDWARS("Bedwars", "Bedwars", true, false, false, false, false, false, true, true, GameMode.SURVIVAL, true), + PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), + PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), + PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, false, true, true, true, false, false, false, GameMode.SURVIVAL, true), + PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), + PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), + QUEST("Quest", "Quest", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), + TEST("Test", "Test", false, false, false, false, true, true, true, true, GameMode.SURVIVAL, false), + TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, false), + DEFAULT("Default", "Default", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true); private String displayName; private String signName; @@ -46,11 +47,14 @@ public enum GameTypeDefault implements GameType { private boolean mobWaves; private boolean rewards; private boolean showTime; - private boolean build; + private boolean breakBlocks; + private boolean breakPlacedBlocks; + private boolean placeBlocks; private GameMode gameMode; private boolean lives; - GameTypeDefault(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, boolean showTime, boolean build, GameMode gameMode, boolean lives) { + GameTypeDefault(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, + boolean showTime, boolean breakBlocks, boolean breakPlacedBlocks, boolean placeBlocks, GameMode gameMode, boolean lives) { this.displayName = displayName; this.signName = signName; this.playerVersusPlayer = playerVersusPlayer; @@ -58,7 +62,9 @@ public enum GameTypeDefault implements GameType { this.mobWaves = mobWaves; this.rewards = rewards; this.showTime = showTime; - this.build = build; + this.breakBlocks = breakBlocks; + this.breakPlacedBlocks = breakPlacedBlocks; + this.placeBlocks = placeBlocks; this.gameMode = gameMode; this.lives = lives; } @@ -134,13 +140,33 @@ public enum GameTypeDefault implements GameType { } @Override - public boolean canBuild() { - return build; + public boolean canBreakBlocks() { + return breakBlocks; } @Override - public void setBuild(boolean build) { - this.build = build; + public void setBreakBlocks(boolean breakBlocks) { + this.breakBlocks = breakBlocks; + } + + @Override + public boolean canBreakPlacedBlocks() { + return breakPlacedBlocks; + } + + @Override + public void setBreakPlacedBlocks(boolean breakPlacedBlocks) { + this.breakPlacedBlocks = breakPlacedBlocks; + } + + @Override + public boolean canPlaceBlocks() { + return placeBlocks; + } + + @Override + public void setPlaceBlocks(boolean placeBlocks) { + this.placeBlocks = placeBlocks; } @Override diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java index cdc945fb..763726f7 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -21,7 +21,6 @@ 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.game.Game; -import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock; import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.game.GameTypeDefault; import io.github.dre2n.dungeonsxl.global.DPortal; @@ -36,6 +35,7 @@ import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.task.RedstoneEventTask; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.GamePlaceableBlock; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java index a79527d6..e7a13ae0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java @@ -16,8 +16,8 @@ */ package io.github.dre2n.dungeonsxl.sign; -import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.GamePlaceableBlock; import org.bukkit.Material; import org.bukkit.block.Sign; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index c0cadd6a..c5f98275 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -21,7 +21,6 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent; import io.github.dre2n.dungeonsxl.game.Game; -import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.reward.RewardChest; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GamePlaceableBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java similarity index 98% rename from core/src/main/java/io/github/dre2n/dungeonsxl/game/GamePlaceableBlock.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java index f2fa393b..5f1f324d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GamePlaceableBlock.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java @@ -14,10 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.game; +package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.commons.util.NumberUtil; -import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.HashSet; import java.util.Set; import org.bukkit.Material; diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java index da570b5a..0c79e280 100644 --- a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java +++ b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java @@ -23,7 +23,7 @@ import org.bukkit.GameMode; */ public enum CustomGameType implements GameType { - GHOST("My awesome game type", "Identifier", false, false, false, false, false, false, GameMode.SPECTATOR, false); + GHOST("My awesome game type", "Identifier", false, false, false, false, false, false, false, false, GameMode.SPECTATOR, false); private String displayName; private String signName; @@ -32,11 +32,14 @@ public enum CustomGameType implements GameType { private boolean mobWaves; private boolean rewards; private boolean showTime; - private boolean build; + private boolean breakBlocks; + private boolean breakPlacedBlocks; + private boolean placeBlocks; private GameMode gameMode; private boolean lives; - CustomGameType(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, boolean showTime, boolean build, GameMode gameMode, boolean lives) { + CustomGameType(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, + boolean showTime, boolean breakBlocks, boolean breakPlacedBlocks, boolean placeBlocks, GameMode gameMode, boolean lives) { this.displayName = displayName; this.signName = signName; this.playerVersusPlayer = playerVersusPlayer; @@ -44,7 +47,9 @@ public enum CustomGameType implements GameType { this.mobWaves = mobWaves; this.rewards = rewards; this.showTime = showTime; - this.build = build; + this.breakBlocks = breakBlocks; + this.breakPlacedBlocks = breakPlacedBlocks; + this.placeBlocks = placeBlocks; this.gameMode = gameMode; this.lives = lives; } @@ -120,13 +125,33 @@ public enum CustomGameType implements GameType { } @Override - public boolean canBuild() { - return build; + public boolean canBreakBlocks() { + return breakBlocks; } @Override - public void setBuild(boolean build) { - this.build = build; + public void setBreakBlocks(boolean breakBlocks) { + this.breakBlocks = breakBlocks; + } + + @Override + public boolean canBreakPlacedBlocks() { + return breakPlacedBlocks; + } + + @Override + public void setBreakPlacedBlocks(boolean breakPlacedBlocks) { + this.breakPlacedBlocks = breakPlacedBlocks; + } + + @Override + public boolean canPlaceBlocks() { + return placeBlocks; + } + + @Override + public void setPlaceBlocks(boolean placeBlocks) { + this.placeBlocks = placeBlocks; } @Override From bdf5b54975863fd47957d4859f5cde88564a3790 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 16:13:01 +0200 Subject: [PATCH 04/57] Don't enable performance tweaks if server version is not supported --- .../io/github/dre2n/dungeonsxl/config/DMessages.java | 1 + .../io/github/dre2n/dungeonsxl/config/MainConfig.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 47f3445c..da5c433e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -134,6 +134,7 @@ public enum DMessages implements Messages { GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."), GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"), GROUP_WAVE_FINISHED("Group_WaveFinished", "&6Your group finished wave no. &4&v1&6. The next one is going to start in &4&v2&6 seconds."), + LOG_DISABLED_TWEAKS("Log_DisabledTweaks", "&4Disabled performance tweaks because there is no support for this server software."), LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"), LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"), LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as console!"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index a16ba0f1..320d4f3f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -16,8 +16,11 @@ */ package io.github.dre2n.dungeonsxl.config; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Internals; import io.github.dre2n.commons.config.BRConfig; import io.github.dre2n.commons.util.EnumUtil; +import io.github.dre2n.commons.util.messageutil.MessageUtil; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -496,7 +499,12 @@ public class MainConfig extends BRConfig { } if (config.contains("tweaksEnabled")) { - tweaksEnabled = config.getBoolean("tweaksEnabled"); + if (Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals())) { + tweaksEnabled = config.getBoolean("tweaksEnabled"); + } else { + tweaksEnabled = false; + MessageUtil.log(DMessages.LOG_DISABLED_TWEAKS.getMessage()); + } } if (config.contains("secureMode.enabled")) { From 5b77ab4e8c615e039c58622aaa8460f092489cf1 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 16:13:37 +0200 Subject: [PATCH 05/57] Fix NPE if class sign uses an unknown class --- .../dre2n/dungeonsxl/sign/ClassesSign.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java index 13eba0ff..63b8831b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java @@ -59,13 +59,17 @@ public class ClassesSign extends DSign { @Override public void onInit() { - getSign().setLine(0, ChatColor.DARK_BLUE + "############"); - getSign().setLine(1, ChatColor.DARK_GREEN + dClass.getName()); - getSign().setLine(2, ""); - getSign().setLine(3, ChatColor.DARK_BLUE + "############"); - getSign().update(); + if (dClass != null) { + getSign().setLine(0, ChatColor.DARK_BLUE + "############"); + getSign().setLine(1, ChatColor.DARK_GREEN + dClass.getName()); + getSign().setLine(2, ""); + getSign().setLine(3, ChatColor.DARK_BLUE + "############"); + getSign().update(); + getGameWorld().getClassesSigns().add(getSign()); - getGameWorld().getClassesSigns().add(getSign()); + } else { + markAsErroneous(); + } } @Override From 80ceb79b5d9084a911838529ea2fdb7b4d90eac6 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 16:14:50 +0200 Subject: [PATCH 06/57] Implement simple break / place game rules --- .../dre2n/dungeonsxl/game/GameRules.java | 2 +- .../dre2n/dungeonsxl/game/GameType.java | 36 +++++----- .../dungeonsxl/game/GameTypeDefault.java | 66 ++++++++++--------- .../dungeonsxl/global/GlobalProtection.java | 19 +++++- .../dungeonsxl/listener/BlockListener.java | 55 ++-------------- .../dre2n/dungeonsxl/player/DGroup.java | 15 +---- .../dre2n/dungeonsxl/sign/ReadySign.java | 2 +- .../dre2n/dungeonsxl/world/DGameWorld.java | 58 ++++++++++++++++ .../dre2n/dungeonsxl/game/CustomGameType.java | 58 ++++++++-------- 9 files changed, 168 insertions(+), 143 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 4cbb0fb3..a211ad58 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -392,7 +392,7 @@ public class GameRules { friendlyFire = defaultValues.isFriendlyFire(); } - if (timeToFinish == null) { + if (timeToFinish == null && defaultValues.getShowTime() != null) { timeToFinish = defaultValues.getShowTime() ? null : -1; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java index 4a7e843c..cef39160 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java @@ -48,90 +48,90 @@ public interface GameType { /** * @return the playerVersusPlayer */ - public boolean isPlayerVersusPlayer(); + public Boolean isPlayerVersusPlayer(); /** * @param playerVersusPlayer * the playerVersusPlayer to set */ - public void setPlayerVersusPlayer(boolean playerVersusPlayer); + public void setPlayerVersusPlayer(Boolean playerVersusPlayer); /** * @return the friendlyFire */ - public boolean isFriendlyFire(); + public Boolean isFriendlyFire(); /** * @param friendlyFire * the friendlyFire to set */ - public void setFriendlyFire(boolean friendlyFire); + public void setFriendlyFire(Boolean friendlyFire); /** * @return the mobWaves */ - public boolean hasMobWaves(); + public Boolean hasMobWaves(); /** * @param mobWaves * enable / disable mob waves */ - public void setMobWaves(boolean mobWaves); + public void setMobWaves(Boolean mobWaves); /** * @return if players get rewards after the dungeon */ - public boolean hasRewards(); + public Boolean hasRewards(); /** * @param rewards * enable / disable rewards */ - public void setRewards(boolean rewards); + public void setRewards(Boolean rewards); /** * @return if players shall see how long they play */ - public boolean getShowTime(); + public Boolean getShowTime(); /** * @param showTime * set if players shall see how long they play */ - public void setShowTime(boolean showTime); + public void setShowTime(Boolean showTime); /** * @return if all blocks may be destroyed */ - public boolean canBreakBlocks(); + public Boolean canBreakBlocks(); /** * @param breakBlocks * if blocks may be destroyed */ - public void setBreakBlocks(boolean breakBlocks); + public void setBreakBlocks(Boolean breakBlocks); /** * @return if blocks placed in game may be destroyed */ - public boolean canBreakPlacedBlocks(); + public Boolean canBreakPlacedBlocks(); /** * @param breakPlacedBlocks * if placed blocks may be destroyed */ - public void setBreakPlacedBlocks(boolean breakPlacedBlocks); + public void setBreakPlacedBlocks(Boolean breakPlacedBlocks); /** * @return if blocks may be placed */ - public boolean canPlaceBlocks(); + public Boolean canPlaceBlocks(); /** * @param placeBlocks * if blocks may be placed */ - public void setPlaceBlocks(boolean placeBlocks); + public void setPlaceBlocks(Boolean placeBlocks); /** * @return the gameMode @@ -147,12 +147,12 @@ public interface GameType { /** * @return if players lose lives */ - public boolean hasLives(); + public Boolean hasLives(); /** * @param lives * set if the gametype uses player lives */ - public void setLives(boolean lives); + public void setLives(Boolean lives); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java index 4fddf370..2777cddb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java @@ -38,23 +38,24 @@ public enum GameTypeDefault implements GameType { QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), TEST("Test", "Test", false, false, false, false, true, true, true, true, GameMode.SURVIVAL, false), TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, false), - DEFAULT("Default", "Default", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true); + DEFAULT("Default", "Default", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + CUSTOM("Custom", "Custom"); private String displayName; private String signName; - private boolean playerVersusPlayer; - private boolean friendlyFire; - private boolean mobWaves; - private boolean rewards; - private boolean showTime; - private boolean breakBlocks; - private boolean breakPlacedBlocks; - private boolean placeBlocks; + private Boolean playerVersusPlayer; + private Boolean friendlyFire; + private Boolean mobWaves; + private Boolean rewards; + private Boolean showTime; + private Boolean breakBlocks; + private Boolean breakPlacedBlocks; + private Boolean placeBlocks; private GameMode gameMode; - private boolean lives; + private Boolean lives; - GameTypeDefault(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, - boolean showTime, boolean breakBlocks, boolean breakPlacedBlocks, boolean placeBlocks, GameMode gameMode, boolean lives) { + GameTypeDefault(String displayName, String signName, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, + Boolean showTime, Boolean breakBlocks, Boolean breakPlacedBlocks, Boolean placeBlocks, GameMode gameMode, Boolean lives) { this.displayName = displayName; this.signName = signName; this.playerVersusPlayer = playerVersusPlayer; @@ -69,6 +70,11 @@ public enum GameTypeDefault implements GameType { this.lives = lives; } + GameTypeDefault(String displayName, String signName) { + this.displayName = displayName; + this.signName = signName; + } + @Override public String getDisplayName() { return displayName; @@ -90,82 +96,82 @@ public enum GameTypeDefault implements GameType { } @Override - public boolean isPlayerVersusPlayer() { + public Boolean isPlayerVersusPlayer() { return playerVersusPlayer; } @Override - public void setPlayerVersusPlayer(boolean playerVersusPlayer) { + public void setPlayerVersusPlayer(Boolean playerVersusPlayer) { this.playerVersusPlayer = playerVersusPlayer; } @Override - public boolean isFriendlyFire() { + public Boolean isFriendlyFire() { return friendlyFire; } @Override - public void setFriendlyFire(boolean friendlyFire) { + public void setFriendlyFire(Boolean friendlyFire) { this.friendlyFire = friendlyFire; } @Override - public boolean hasMobWaves() { + public Boolean hasMobWaves() { return mobWaves; } @Override - public void setMobWaves(boolean mobWaves) { + public void setMobWaves(Boolean mobWaves) { this.mobWaves = mobWaves; } @Override - public boolean hasRewards() { + public Boolean hasRewards() { return rewards; } @Override - public void setRewards(boolean rewards) { + public void setRewards(Boolean rewards) { this.rewards = rewards; } @Override - public boolean getShowTime() { + public Boolean getShowTime() { return showTime; } @Override - public void setShowTime(boolean showTime) { + public void setShowTime(Boolean showTime) { this.showTime = showTime; } @Override - public boolean canBreakBlocks() { + public Boolean canBreakBlocks() { return breakBlocks; } @Override - public void setBreakBlocks(boolean breakBlocks) { + public void setBreakBlocks(Boolean breakBlocks) { this.breakBlocks = breakBlocks; } @Override - public boolean canBreakPlacedBlocks() { + public Boolean canBreakPlacedBlocks() { return breakPlacedBlocks; } @Override - public void setBreakPlacedBlocks(boolean breakPlacedBlocks) { + public void setBreakPlacedBlocks(Boolean breakPlacedBlocks) { this.breakPlacedBlocks = breakPlacedBlocks; } @Override - public boolean canPlaceBlocks() { + public Boolean canPlaceBlocks() { return placeBlocks; } @Override - public void setPlaceBlocks(boolean placeBlocks) { + public void setPlaceBlocks(Boolean placeBlocks) { this.placeBlocks = placeBlocks; } @@ -180,12 +186,12 @@ public enum GameTypeDefault implements GameType { } @Override - public boolean hasLives() { + public Boolean hasLives() { return lives; } @Override - public void setLives(boolean lives) { + public void setLives(Boolean lives) { this.lives = lives; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java index 42e30ba5..e081bcbd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java @@ -5,7 +5,10 @@ */ package io.github.dre2n.dungeonsxl.global; +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.player.DGlobalPlayer; import java.io.File; import java.util.Collection; import org.bukkit.World; @@ -54,6 +57,7 @@ public abstract class GlobalProtection { return id; } + /* Actions */ /** * Delete this protection. */ @@ -61,7 +65,6 @@ public abstract class GlobalProtection { protections.removeProtection(this); } - /* Abstracts */ /** * Save the data to the default file */ @@ -77,6 +80,20 @@ public abstract class GlobalProtection { save(YamlConfiguration.loadConfiguration(file)); } + public boolean onBreak(DGlobalPlayer dPlayer) { + if (dPlayer.isInBreakMode()) { + delete(); + MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(DMessages.PLAYER_PROTECTED_BLOCK_DELETED)); + MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(DMessages.CMD_BREAK_PROTECTED_MODE)); + dPlayer.setInBreakMode(false); + return false; + + } else { + return true; + } + } + + /* Abstracts */ /** * @param config * the config to save the protection to diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java index 763726f7..b55c7fca 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -20,9 +20,6 @@ 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.game.Game; -import io.github.dre2n.dungeonsxl.game.GameType; -import io.github.dre2n.dungeonsxl.game.GameTypeDefault; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GameSign; import io.github.dre2n.dungeonsxl.global.GlobalProtection; @@ -35,8 +32,6 @@ import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.task.RedstoneEventTask; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; -import io.github.dre2n.dungeonsxl.world.GamePlaceableBlock; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -80,16 +75,9 @@ public class BlockListener implements Listener { GlobalProtection protection = plugin.getGlobalProtections().getByBlock(event.getBlock()); if (protection != null) { - if (dGlobalPlayer.isInBreakMode()) { - protection.delete(); - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.PLAYER_PROTECTED_BLOCK_DELETED)); - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.CMD_BREAK_PROTECTED_MODE)); - dGlobalPlayer.setInBreakMode(false); - - } else { + if (protection.onBreak(dGlobalPlayer)) { event.setCancelled(true); } - return; } @@ -103,24 +91,7 @@ public class BlockListener implements Listener { // Deny DGameWorld block breaking DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld()); if (gameWorld != null) { - for (DSign dSign : gameWorld.getDSigns()) { - if (dSign.getSign().equals(block)) { - event.setCancelled(true); - return; - } - } - - Game game = gameWorld.getGame(); - if (game != null) { - GameType gameType = game.getType(); - if (gameType == GameTypeDefault.DEFAULT) { - event.setCancelled(!game.getRules().canBuild()); - - } else if (!gameType.canBuild()) { - event.setCancelled(true); - } - - } else { + if (gameWorld.onBreak(player, block)) { event.setCancelled(true); } } @@ -136,27 +107,9 @@ public class BlockListener implements Listener { return; } - Game game = gameWorld.getGame(); - if (game != null) { - if (game.getRules().canBuild() || GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gameWorld)) { - return; - } + if (gameWorld.onPlace(event.getPlayer(), block, event.getBlockAgainst(), event.getItemInHand())) { + event.setCancelled(true); } - - // Workaround for a bug that would allow 3-Block-high jumping - Location loc = event.getPlayer().getLocation(); - if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) { - if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) { - if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) { - loc.setX(block.getX() + 0.5); - loc.setY(block.getY()); - loc.setZ(block.getZ() + 0.5); - event.getPlayer().teleport(loc); - } - } - } - - event.setCancelled(true); } @EventHandler(priority = EventPriority.NORMAL) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 1b9c8c29..c707d6b0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -658,18 +658,9 @@ public class DGroup { requirement.demand(player); } - GameType gameType = game.getType(); - if (gameType == GameTypeDefault.DEFAULT) { - player.setGameMode(rules.getGameMode()); - if (rules.isTimeIsRunning()) { - timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20); - } - - } else { - player.setGameMode(gameType.getGameMode()); - if (gameType.getShowTime()) { - timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20); - } + player.setGameMode(rules.getGameMode()); + if (rules.isTimeIsRunning()) { + timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20); } // Permission bridge diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java index d3719748..65de59da 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java @@ -88,7 +88,7 @@ public class ReadySign extends DSign { gameType = plugin.getGameTypes().getBySign(this); } else { - gameType = GameTypeDefault.DEFAULT; + gameType = GameTypeDefault.CUSTOM; } if (!lines[2].isEmpty()) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index c5f98275..3052f17f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -21,6 +21,7 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent; import io.github.dre2n.dungeonsxl.game.Game; +import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.reward.RewardChest; @@ -37,15 +38,18 @@ import io.github.dre2n.dungeonsxl.trigger.TriggerType; import io.github.dre2n.dungeonsxl.trigger.TriggerTypeDefault; import java.io.File; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.entity.Spider; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; @@ -60,6 +64,7 @@ public class DGameWorld extends DInstanceWorld { private boolean isPlaying = false; // TO DO: Which lists actually need to be CopyOnWriteArrayLists? + private List placedBlocks = new LinkedList<>(); private CopyOnWriteArrayList placeableBlocks = new CopyOnWriteArrayList<>(); private List secureObjects = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList loadedChunks = new CopyOnWriteArrayList<>(); @@ -451,6 +456,59 @@ public class DGameWorld extends DInstanceWorld { } } + public boolean onBreak(Player player, Block block) { + for (DSign dSign : dSigns) { + if (dSign.getSign().getBlock().equals(block)) { + return true; + } + } + + for (RewardChest rChest : rewardChests) { + if (rChest.getChest().getBlock().equals(block)) { + return true; + } + } + + Game game = getGame(); + if (game != null) { + GameRules rules = game.getRules(); + if (rules.canBreakBlocks()) { + return (false); + } else if (rules.canBreakPlacedBlocks()) { + return (!placedBlocks.contains(block)); + } + } + + return true; + } + + public boolean onPlace(Player player, Block block, Block against, ItemStack hand) { + // Workaround for a bug that would allow 3-Block-high jumping + Location loc = player.getLocation(); + if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) { + if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) { + if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) { + loc.setX(block.getX() + 0.5); + loc.setY(block.getY()); + loc.setZ(block.getZ() + 0.5); + player.teleport(loc); + } + } + } + + Game game = getGame(); + if (game == null) { + return true; + } + + if (game.getRules().canPlaceBlocks() || GamePlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) { + placedBlocks.add(block); + return false; + } + + return true; + } + /* Statics */ /** * @param world diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java index 0c79e280..16a14714 100644 --- a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java +++ b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java @@ -27,19 +27,19 @@ public enum CustomGameType implements GameType { private String displayName; private String signName; - private boolean playerVersusPlayer; - private boolean friendlyFire; - private boolean mobWaves; - private boolean rewards; - private boolean showTime; - private boolean breakBlocks; - private boolean breakPlacedBlocks; - private boolean placeBlocks; + private Boolean playerVersusPlayer; + private Boolean friendlyFire; + private Boolean mobWaves; + private Boolean rewards; + private Boolean showTime; + private Boolean breakBlocks; + private Boolean breakPlacedBlocks; + private Boolean placeBlocks; private GameMode gameMode; - private boolean lives; + private Boolean lives; - CustomGameType(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, - boolean showTime, boolean breakBlocks, boolean breakPlacedBlocks, boolean placeBlocks, GameMode gameMode, boolean lives) { + CustomGameType(String displayName, String signName, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, + Boolean showTime, Boolean breakBlocks, Boolean breakPlacedBlocks, Boolean placeBlocks, GameMode gameMode, Boolean lives) { this.displayName = displayName; this.signName = signName; this.playerVersusPlayer = playerVersusPlayer; @@ -75,82 +75,82 @@ public enum CustomGameType implements GameType { } @Override - public boolean isPlayerVersusPlayer() { + public Boolean isPlayerVersusPlayer() { return playerVersusPlayer; } @Override - public void setPlayerVersusPlayer(boolean playerVersusPlayer) { + public void setPlayerVersusPlayer(Boolean playerVersusPlayer) { this.playerVersusPlayer = playerVersusPlayer; } @Override - public boolean isFriendlyFire() { + public Boolean isFriendlyFire() { return friendlyFire; } @Override - public void setFriendlyFire(boolean friendlyFire) { + public void setFriendlyFire(Boolean friendlyFire) { this.friendlyFire = friendlyFire; } @Override - public boolean hasMobWaves() { + public Boolean hasMobWaves() { return mobWaves; } @Override - public void setMobWaves(boolean mobWaves) { + public void setMobWaves(Boolean mobWaves) { this.mobWaves = mobWaves; } @Override - public boolean hasRewards() { + public Boolean hasRewards() { return rewards; } @Override - public void setRewards(boolean rewards) { + public void setRewards(Boolean rewards) { this.rewards = rewards; } @Override - public boolean getShowTime() { + public Boolean getShowTime() { return showTime; } @Override - public void setShowTime(boolean showTime) { + public void setShowTime(Boolean showTime) { this.showTime = showTime; } @Override - public boolean canBreakBlocks() { + public Boolean canBreakBlocks() { return breakBlocks; } @Override - public void setBreakBlocks(boolean breakBlocks) { + public void setBreakBlocks(Boolean breakBlocks) { this.breakBlocks = breakBlocks; } @Override - public boolean canBreakPlacedBlocks() { + public Boolean canBreakPlacedBlocks() { return breakPlacedBlocks; } @Override - public void setBreakPlacedBlocks(boolean breakPlacedBlocks) { + public void setBreakPlacedBlocks(Boolean breakPlacedBlocks) { this.breakPlacedBlocks = breakPlacedBlocks; } @Override - public boolean canPlaceBlocks() { + public Boolean canPlaceBlocks() { return placeBlocks; } @Override - public void setPlaceBlocks(boolean placeBlocks) { + public void setPlaceBlocks(Boolean placeBlocks) { this.placeBlocks = placeBlocks; } @@ -165,12 +165,12 @@ public enum CustomGameType implements GameType { } @Override - public boolean hasLives() { + public Boolean hasLives() { return lives; } @Override - public void setLives(boolean lives) { + public void setLives(Boolean lives) { this.lives = lives; } From 914c31a92ffa9508b7bdb36c776f4d7ffff0c926 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 17:02:10 +0200 Subject: [PATCH 07/57] Implement break / place whitelists --- .../dre2n/dungeonsxl/world/DGameWorld.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index 3052f17f..cc441f7b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -38,11 +38,15 @@ import io.github.dre2n.dungeonsxl.trigger.TriggerType; import io.github.dre2n.dungeonsxl.trigger.TriggerTypeDefault; import java.io.File; import java.util.ArrayList; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -470,12 +474,31 @@ public class DGameWorld extends DInstanceWorld { } Game game = getGame(); - if (game != null) { - GameRules rules = game.getRules(); - if (rules.canBreakBlocks()) { - return (false); - } else if (rules.canBreakPlacedBlocks()) { + if (game == null) { + return true; + } + + GameRules rules = game.getRules(); + if (!rules.canBreakBlocks() && !rules.canBreakPlacedBlocks()) { + return true; + } + + Map> whitelist = rules.getBreakWhitelist(); + Material material = block.getType(); + Material breakTool = player.getItemInHand().getType(); + + if (whitelist == null) { + if (rules.canBreakPlacedBlocks()) { return (!placedBlocks.contains(block)); + } else if (rules.canBreakBlocks()) { + return false; + } + + } else if (whitelist.containsKey(material) && whitelist.get(material) == null | whitelist.get(material).isEmpty() | whitelist.get(material).contains(breakTool)) { + if (rules.canBreakPlacedBlocks()) { + return (!placedBlocks.contains(block)); + } else if (rules.canBreakBlocks()) { + return false; } } @@ -501,7 +524,13 @@ public class DGameWorld extends DInstanceWorld { return true; } - if (game.getRules().canPlaceBlocks() || GamePlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) { + GameRules rules = game.getRules(); + if (!rules.canPlaceBlocks() && !GamePlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) { + return true; + } + + Set whitelist = rules.getPlaceWhitelist(); + if (whitelist == null || whitelist.contains(block.getType())) { placedBlocks.add(block); return false; } From f1de40ef2f7ffeb910aa7ba340b28bf0694a51a8 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 17:27:52 +0200 Subject: [PATCH 08/57] Don't register permissions once again on /dxl reload --- core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index ba6a9560..68cb22d6 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -131,6 +131,7 @@ public class DungeonsXL extends BRPlugin { super.onEnable(); instance = this; + DPermissions.register(); initFolders(); loadCore(); @@ -257,7 +258,6 @@ public class DungeonsXL extends BRPlugin { loadMainConfig(new File(getDataFolder(), "config.yml")); // Load Language 2 loadMessageConfig(new File(LANGUAGES, mainConfig.getLanguage() + ".yml")); - DPermissions.register(); loadGameTypes(); loadRequirementTypes(); loadRewardTypes(); From 0da5d76742c397aaa84bafccca30ad41cf971e8a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 17:28:11 +0200 Subject: [PATCH 09/57] #122 LeaveSign --- .../dre2n/dungeonsxl/global/LeaveSign.java | 65 +++++++++---------- .../dungeonsxl/listener/PlayerListener.java | 5 +- 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java index ac5218c4..f3cd41b7 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java @@ -44,14 +44,7 @@ public class LeaveSign extends GlobalProtection { setText(); } - public void setText() { - sign.setLine(0, ChatColor.BLUE + "############"); - sign.setLine(1, ChatColor.DARK_GREEN + "Leave"); - sign.setLine(2, ""); - sign.setLine(3, ChatColor.BLUE + "############"); - sign.update(); - } - + /* Getters and setters */ @Override public Set getBlocks() { if (blocks == null) { @@ -64,6 +57,34 @@ public class LeaveSign extends GlobalProtection { return blocks; } + /* Actions */ + public void setText() { + sign.setLine(0, ChatColor.BLUE + "############"); + sign.setLine(1, ChatColor.DARK_GREEN + "Leave"); + sign.setLine(2, ""); + sign.setLine(3, ChatColor.BLUE + "############"); + sign.update(); + } + + public void onPlayerInteract(Player player) { + DGamePlayer dplayer = DGamePlayer.getByPlayer(player); + + if (dplayer != null) { + dplayer.leave(); + return; + + } else { + DGroup group = DGroup.getByPlayer(player); + if (group != null) { + group.removePlayer(player); + MessageUtil.sendMessage(player, DMessages.PLAYER_LEAVE_GROUP.getMessage()); + return; + } + } + + return; + } + @Override public void save(FileConfiguration config) { String preString = "protections.leaveSigns." + sign.getWorld().getName() + "." + getId(); @@ -89,32 +110,4 @@ public class LeaveSign extends GlobalProtection { return null; } - /* SUBJECT TO CHANGE */ - @Deprecated - public static boolean playerInteract(Block block, Player player) { - - LeaveSign leaveSign = getByBlock(block); - - if (leaveSign == null) { - return false; - } - - DGamePlayer dplayer = DGamePlayer.getByPlayer(player); - - if (dplayer != null) { - dplayer.leave(); - return true; - - } else { - DGroup dgroup = DGroup.getByPlayer(player); - if (dgroup != null) { - dgroup.removePlayer(player); - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.PLAYER_LEAVE_GROUP)); - return true; - } - } - - return false; - } - } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 73cdbbbe..3dfe7871 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -264,8 +264,9 @@ public class PlayerListener implements Listener { event.setCancelled(true); } - // Leave Sign - if (LeaveSign.playerInteract(event.getClickedBlock(), player)) { + LeaveSign leaveSign = LeaveSign.getByBlock(clickedBlock); + if (leaveSign != null) { + leaveSign.onPlayerInteract(player); event.setCancelled(true); } From a3590fff1ee65938fec7aae118df52361d0666f9 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 23:53:02 +0200 Subject: [PATCH 10/57] #102: Restructured events --- .../dungeonsxl/command/LeaveCommand.java | 4 +- .../event/dgroup/DGroupDisbandEvent.java | 1 + .../event/dgroup/DGroupScoreEvent.java | 90 +++++++++++++++++++ .../instance/DInstancePlayerEvent.java | 40 +++++++++ .../DInstancePlayerUpdateEvent.java} | 7 +- .../instance/edit/DEditPlayerEscapeEvent.java | 54 +++++++++++ .../instance/edit/DEditPlayerEvent.java | 40 +++++++++ .../game/DGamePlayerDeathEvent.java} | 7 +- .../game/DGamePlayerEscapeEvent.java} | 8 +- .../instance/game/DGamePlayerEvent.java | 40 +++++++++ .../game/DGamePlayerFinishEvent.java} | 6 +- 11 files changed, 282 insertions(+), 15 deletions(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupScoreEvent.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerEvent.java rename core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/{DPlayerUpdateEvent.java => instance/DInstancePlayerUpdateEvent.java} (90%) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java rename core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/{DPlayerDeathEvent.java => instance/game/DGamePlayerDeathEvent.java} (87%) rename core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/{DPlayerEscapeEvent.java => instance/game/DGamePlayerEscapeEvent.java} (83%) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerEvent.java rename core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/{DPlayerFinishEvent.java => instance/game/DGamePlayerFinishEvent.java} (89%) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java index ab290a7e..a717c3e2 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java @@ -20,8 +20,8 @@ import io.github.dre2n.commons.command.BRCommand; 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.event.dplayer.DPlayerEscapeEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.edit.DEditPlayerEscapeEvent; import io.github.dre2n.dungeonsxl.player.DEditPlayer; import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DGroup; @@ -67,7 +67,7 @@ public class LeaveCommand extends BRCommand { return; } - DPlayerEscapeEvent dPlayerEscapeEvent = new DPlayerEscapeEvent(dPlayer); + DEditPlayerEscapeEvent dPlayerEscapeEvent = new DEditPlayerEscapeEvent((DEditPlayer) dPlayer); plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent); DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup); plugin.getServer().getPluginManager().callEvent(dPlayerLeaveDGroupEvent); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java index d4095dda..db058c68 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java @@ -31,6 +31,7 @@ public class DGroupDisbandEvent extends DGroupEvent implements Cancellable { COMMAND, DUNGEON_FINISHED, GROUP_IS_EMPTY, + LOST, CUSTOM } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupScoreEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupScoreEvent.java new file mode 100644 index 00000000..177ac98e --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupScoreEvent.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.event.dgroup; + +import io.github.dre2n.dungeonsxl.player.DGroup; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * @author Daniel Saukel + */ +public class DGroupScoreEvent extends DGroupEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private Player scorer; + private DGroup loserGroup; + + public DGroupScoreEvent(DGroup dGroup, Player scorer, DGroup loserGroup) { + super(dGroup); + this.scorer = scorer; + this.loserGroup = loserGroup; + } + + /** + * @return the creator + */ + public Player getScorer() { + return scorer; + } + + /** + * @param scorer + * the scoerer to set + */ + public void setCreator(Player scorer) { + this.scorer = scorer; + } + + /** + * @return the group that lost a score to the scorers + */ + public DGroup getLoserGroup() { + return loserGroup; + } + + /** + * @param loserGroup + * the group that lost a score to the scorers to set + */ + public void setLoserGroup(DGroup loserGroup) { + this.loserGroup = loserGroup; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerEvent.java new file mode 100644 index 00000000..82b5b6c8 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.event.dplayer.instance; + +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEvent; +import io.github.dre2n.dungeonsxl.player.DInstancePlayer; + +/** + * @author Daniel Saukel + */ +public abstract class DInstancePlayerEvent extends DPlayerEvent { + + public DInstancePlayerEvent(DInstancePlayer dPlayer) { + super(dPlayer); + } + + @Override + public DInstancePlayer getDPlayer() { + return (DInstancePlayer) dPlayer; + } + + public void setDPlayer(DInstancePlayer dPlayer) { + this.dPlayer = dPlayer; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerUpdateEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerUpdateEvent.java similarity index 90% rename from core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerUpdateEvent.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerUpdateEvent.java index b66554ea..5728e029 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerUpdateEvent.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerUpdateEvent.java @@ -14,8 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.event.dplayer; +package io.github.dre2n.dungeonsxl.event.dplayer.instance; +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEvent; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -23,7 +24,7 @@ import org.bukkit.event.HandlerList; /** * @author Daniel Saukel */ -public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable { +public class DInstancePlayerUpdateEvent extends DPlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; @@ -35,7 +36,7 @@ public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable { private boolean kick; private boolean triggerAllInDistance; - public DPlayerUpdateEvent(DInstancePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) { + public DInstancePlayerUpdateEvent(DInstancePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) { super(dPlayer); this.locationValid = locationValid; this.teleportWolf = teleportWolf; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java new file mode 100644 index 00000000..e97cbfdc --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.event.dplayer.instance.edit; + +import io.github.dre2n.dungeonsxl.player.DEditPlayer; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * @author Daniel Saukel + */ +public class DEditPlayerEscapeEvent extends DEditPlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + public DEditPlayerEscapeEvent(DEditPlayer dPlayer) { + super(dPlayer); + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java new file mode 100644 index 00000000..0990eff9 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.event.dplayer.instance.edit; + +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEvent; +import io.github.dre2n.dungeonsxl.player.DEditPlayer; + +/** + * @author Daniel Saukel + */ +public abstract class DEditPlayerEvent extends DPlayerEvent { + + public DEditPlayerEvent(DEditPlayer dPlayer) { + super(dPlayer); + } + + @Override + public DEditPlayer getDPlayer() { + return (DEditPlayer) dPlayer; + } + + public void setDPlayer(DEditPlayer dPlayer) { + this.dPlayer = dPlayer; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerDeathEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerDeathEvent.java similarity index 87% rename from core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerDeathEvent.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerDeathEvent.java index 7bf80bdb..7fc55ed2 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerDeathEvent.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerDeathEvent.java @@ -14,8 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.event.dplayer; +package io.github.dre2n.dungeonsxl.event.dplayer.instance.game; +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEvent; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -24,7 +25,7 @@ import org.bukkit.event.entity.PlayerDeathEvent; /** * @author Daniel Saukel */ -public class DPlayerDeathEvent extends DPlayerEvent implements Cancellable { +public class DGamePlayerDeathEvent extends DPlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; @@ -32,7 +33,7 @@ public class DPlayerDeathEvent extends DPlayerEvent implements Cancellable { private PlayerDeathEvent bukkitEvent; private int lostLives; - public DPlayerDeathEvent(DGamePlayer dPlayer, PlayerDeathEvent bukkitEvent, int lostLives) { + public DGamePlayerDeathEvent(DGamePlayer dPlayer, PlayerDeathEvent bukkitEvent, int lostLives) { super(dPlayer); this.bukkitEvent = bukkitEvent; this.lostLives = lostLives; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerEscapeEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerEscapeEvent.java similarity index 83% rename from core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerEscapeEvent.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerEscapeEvent.java index 354d86a1..ea9df568 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerEscapeEvent.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerEscapeEvent.java @@ -14,21 +14,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.event.dplayer; +package io.github.dre2n.dungeonsxl.event.dplayer.instance.game; -import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; +import io.github.dre2n.dungeonsxl.player.DGamePlayer; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; /** * @author Daniel Saukel */ -public class DPlayerEscapeEvent extends DPlayerEvent implements Cancellable { +public class DGamePlayerEscapeEvent extends DGamePlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - public DPlayerEscapeEvent(DGlobalPlayer dPlayer) { + public DGamePlayerEscapeEvent(DGamePlayer dPlayer) { super(dPlayer); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerEvent.java new file mode 100644 index 00000000..12fe140c --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.event.dplayer.instance.game; + +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEvent; +import io.github.dre2n.dungeonsxl.player.DGamePlayer; + +/** + * @author Daniel Saukel + */ +public abstract class DGamePlayerEvent extends DPlayerEvent { + + public DGamePlayerEvent(DGamePlayer dPlayer) { + super(dPlayer); + } + + @Override + public DGamePlayer getDPlayer() { + return (DGamePlayer) dPlayer; + } + + public void setDPlayer(DGamePlayer dPlayer) { + this.dPlayer = dPlayer; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerFinishEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerFinishEvent.java similarity index 89% rename from core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerFinishEvent.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerFinishEvent.java index 0e07ff1d..aea65090 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerFinishEvent.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerFinishEvent.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.event.dplayer; +package io.github.dre2n.dungeonsxl.event.dplayer.instance.game; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import org.bukkit.event.Cancellable; @@ -23,7 +23,7 @@ import org.bukkit.event.HandlerList; /** * @author Daniel Saukel */ -public class DPlayerFinishEvent extends DPlayerEvent implements Cancellable { +public class DGamePlayerFinishEvent extends DGamePlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; @@ -31,7 +31,7 @@ public class DPlayerFinishEvent extends DPlayerEvent implements Cancellable { private boolean first; private boolean hasToWait; - public DPlayerFinishEvent(DGamePlayer dPlayer, boolean first, boolean hasToWait) { + public DGamePlayerFinishEvent(DGamePlayer dPlayer, boolean first, boolean hasToWait) { super(dPlayer); this.first = first; this.hasToWait = hasToWait; From cbf49c5128b5b33ea8e99983f38cfc4269d3e504 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 23:53:19 +0200 Subject: [PATCH 11/57] #102: Added DataReloadEvent --- .../dungeonsxl/command/ReloadCommand.java | 9 +++- .../dungeonsxl/event/DataReloadEvent.java | 50 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/event/DataReloadEvent.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java index 290304cd..90e7fa7a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java @@ -22,6 +22,7 @@ import io.github.dre2n.commons.compatibility.Internals; 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.event.DataReloadEvent; import io.github.dre2n.dungeonsxl.player.DPermissions; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -46,7 +47,13 @@ public class ReloadCommand extends BRCommand { @Override public void onExecute(String[] args, CommandSender sender) { - PluginManager plugins = Bukkit.getServer().getPluginManager(); + PluginManager plugins = Bukkit.getPluginManager(); + + DataReloadEvent event = new DataReloadEvent(); + plugins.callEvent(event); + if (event.isCancelled()) { + return; + } int maps = DungeonsXL.MAPS.listFiles().length; int dungeons = DungeonsXL.DUNGEONS.listFiles().length; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/DataReloadEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/DataReloadEvent.java new file mode 100644 index 00000000..27dff790 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/DataReloadEvent.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.event; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * @author Daniel Saukel + */ +public class DataReloadEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} From 7966636166d35fd051265e23f5d30ba9ac525478 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 23:53:42 +0200 Subject: [PATCH 12/57] Moved "dungeons" folder to "scripts" --- .../java/io/github/dre2n/dungeonsxl/DungeonsXL.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 68cb22d6..04f4da34 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -66,13 +66,13 @@ public class DungeonsXL extends BRPlugin { public static final String[] EXCLUDED_FILES = {"config.yml", "uid.dat", "DXLData.data"}; public static File BACKUPS; - public static File DUNGEONS; public static File LANGUAGES; public static File MAPS; public static File PLAYERS; public static File SCRIPTS; public static File ANNOUNCERS; public static File CLASSES; + public static File DUNGEONS; public static File LOOT_TABLES; public static File MOBS; public static File SIGNS; @@ -198,11 +198,6 @@ public class DungeonsXL extends BRPlugin { BACKUPS.mkdir(); } - DUNGEONS = new File(getDataFolder(), "dungeons"); - if (!DUNGEONS.exists()) { - DUNGEONS.mkdir(); - } - LANGUAGES = new File(getDataFolder(), "languages"); if (!LANGUAGES.exists()) { LANGUAGES.mkdir(); @@ -233,6 +228,11 @@ public class DungeonsXL extends BRPlugin { CLASSES.mkdir(); } + DUNGEONS = new File(SCRIPTS, "dungeons"); + if (!DUNGEONS.exists()) { + DUNGEONS.mkdir(); + } + LOOT_TABLES = new File(SCRIPTS, "loottables"); if (!LOOT_TABLES.exists()) { LOOT_TABLES.mkdir(); From 5704a6987ad4124c0028fc4a830880e74254d163 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 28 Jul 2016 23:54:51 +0200 Subject: [PATCH 13/57] Implemented some new events --- .../github/dre2n/dungeonsxl/listener/PlayerListener.java | 6 +++--- .../io/github/dre2n/dungeonsxl/player/DEditPlayer.java | 4 ++-- .../io/github/dre2n/dungeonsxl/player/DGamePlayer.java | 8 ++++---- .../java/io/github/dre2n/dungeonsxl/player/DGroup.java | 2 -- .../java/io/github/dre2n/dungeonsxl/sign/LeaveSign.java | 6 +++--- .../java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java | 4 ++-- .../dre2n/dungeonsxl/listener/DPlayerListener.java | 9 ++++++--- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 3dfe7871..0a542f71 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -21,7 +21,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.MainConfig; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GameSign; @@ -36,7 +36,7 @@ import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.player.DPlayers; import io.github.dre2n.dungeonsxl.reward.DLootInventory; -import io.github.dre2n.dungeonsxl.reward.RewardChest; +import io.github.dre2n.dungeonsxl.world.block.RewardChest; import io.github.dre2n.dungeonsxl.sign.OpenDoorSign; import io.github.dre2n.dungeonsxl.task.RespawnTask; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; @@ -102,7 +102,7 @@ public class PlayerListener implements Listener { return; } - DPlayerDeathEvent dPlayerDeathEvent = new DPlayerDeathEvent(dPlayer, event, 1); + DGamePlayerDeathEvent dPlayerDeathEvent = new DGamePlayerDeathEvent(dPlayer, event, 1); plugin.getServer().getPluginManager().callEvent(dPlayerDeathEvent); if (dPlayerDeathEvent.isCancelled()) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java index 5afc050e..9d00086b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java @@ -19,7 +19,7 @@ package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent; import io.github.dre2n.dungeonsxl.task.CreateDInstancePlayerTask; import io.github.dre2n.dungeonsxl.world.DEditWorld; import java.util.concurrent.CopyOnWriteArrayList; @@ -183,7 +183,7 @@ public class DEditPlayer extends DInstancePlayer { } } - DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, false, false, false, false, false); + DInstancePlayerUpdateEvent event = new DInstancePlayerUpdateEvent(this, locationValid, false, false, false, false, false); plugin.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 10c84ff1..ff7d990a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -24,9 +24,9 @@ import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupRewardEvent; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerFinishEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerFinishEvent; import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GameRules; @@ -773,7 +773,7 @@ public class DGamePlayer extends DInstancePlayer { } } - DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait); + DGamePlayerFinishEvent dPlayerFinishEvent = new DGamePlayerFinishEvent(this, first, hasToWait); if (dPlayerFinishEvent.isCancelled()) { finished = false; @@ -891,7 +891,7 @@ public class DGamePlayer extends DInstancePlayer { triggerAllInDistance = true; } - DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance); + DInstancePlayerUpdateEvent event = new DInstancePlayerUpdateEvent(this, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance); plugin.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index c707d6b0..3c6a5444 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -27,8 +27,6 @@ import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent; import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GameRules; -import io.github.dre2n.dungeonsxl.game.GameType; -import io.github.dre2n.dungeonsxl.game.GameTypeDefault; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LeaveSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LeaveSign.java index c04bde0b..0cb1e9e8 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LeaveSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LeaveSign.java @@ -16,7 +16,7 @@ */ package io.github.dre2n.dungeonsxl.sign; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.world.DGameWorld; @@ -64,7 +64,7 @@ public class LeaveSign extends DSign { public boolean onPlayerTrigger(Player player) { DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); if (dPlayer != null) { - DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer); + DGamePlayerEscapeEvent event = new DGamePlayerEscapeEvent(dPlayer); plugin.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -80,7 +80,7 @@ public class LeaveSign extends DSign { @Override public void onTrigger() { for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) { - DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer); + DGamePlayerEscapeEvent event = new DGamePlayerEscapeEvent(dPlayer); plugin.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java index e7a13ae0..d7f830d9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java @@ -17,7 +17,7 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.world.DGameWorld; -import io.github.dre2n.dungeonsxl.world.GamePlaceableBlock; +import io.github.dre2n.dungeonsxl.world.block.PlaceableBlock; import org.bukkit.Material; import org.bukkit.block.Sign; @@ -39,7 +39,7 @@ public class PlaceSign extends DSign { @Override public void onInit() { - getGameWorld().getPlaceableBlocks().add(new GamePlaceableBlock(getSign().getBlock(), lines[1], lines[2])); + getGameWorld().getPlaceableBlocks().add(new PlaceableBlock(getSign().getBlock(), lines[1], lines[2])); getSign().getBlock().setType(Material.AIR); } diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/listener/DPlayerListener.java b/core/src/test/java/io/github/dre2n/dungeonsxl/listener/DPlayerListener.java index af128edc..895731ea 100644 --- a/core/src/test/java/io/github/dre2n/dungeonsxl/listener/DPlayerListener.java +++ b/core/src/test/java/io/github/dre2n/dungeonsxl/listener/DPlayerListener.java @@ -19,6 +19,9 @@ package io.github.dre2n.dungeonsxl.listener; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.event.dplayer.*; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.edit.DEditPlayerEscapeEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerFinishEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -30,20 +33,20 @@ public class DPlayerListener implements Listener { DungeonsXL plugin = DungeonsXL.getInstance(); @EventHandler - public void onDeath(DPlayerDeathEvent event) { + public void onDeath(DGamePlayerDeathEvent event) { MessageUtil.log(plugin, "&b== " + event.getEventName() + "=="); MessageUtil.log(plugin, "DPlayer: " + event.getDPlayer().getPlayer().getName()); MessageUtil.log(plugin, "Lost lives: " + event.getLostLives()); } @EventHandler - public void onEscape(DPlayerEscapeEvent event) { + public void onEscape(DEditPlayerEscapeEvent event) { MessageUtil.log(plugin, "&b== " + event.getEventName() + "=="); MessageUtil.log(plugin, "DPlayer: " + event.getDPlayer().getPlayer().getName()); } @EventHandler - public void onFinish(DPlayerFinishEvent event) { + public void onFinish(DGamePlayerFinishEvent event) { MessageUtil.log(plugin, "&b== " + event.getEventName() + "=="); MessageUtil.log(plugin, "DPlayer: " + event.getDPlayer().getPlayer().getName()); MessageUtil.log(plugin, "Player has to wait: " + event.getHasToWait()); From f90d3ad5c7eaa9ba5653939613e7ab54c1bdcb40 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 31 Jul 2016 23:52:33 +0200 Subject: [PATCH 14/57] New game block system; resolves #125 --- .../dungeonsxl/command/LeaveCommand.java | 15 +- .../dre2n/dungeonsxl/config/DMessages.java | 4 + .../dungeonsxl/listener/BlockListener.java | 2 +- .../dungeonsxl/listener/PlayerListener.java | 22 +-- .../dre2n/dungeonsxl/player/DGamePlayer.java | 24 +++ .../github/dre2n/dungeonsxl/sign/BedSign.java | 65 ++++++++ .../dre2n/dungeonsxl/sign/ChestSign.java | 4 +- .../dre2n/dungeonsxl/sign/DSignType.java | 7 +- .../dungeonsxl/sign/DSignTypeDefault.java | 68 ++++---- .../dre2n/dungeonsxl/sign/FlagSign.java | 55 +++++++ .../dre2n/dungeonsxl/sign/OpenDoorSign.java | 53 ++---- .../dre2n/dungeonsxl/sign/PlaceSign.java | 2 +- .../dre2n/dungeonsxl/sign/ProtectionSign.java | 54 +++++++ .../dre2n/dungeonsxl/world/DGameWorld.java | 151 ++++++++++++++---- .../dungeonsxl/world/block/GameBlock.java | 59 +++++++ .../dungeonsxl/world/block/LockedDoor.java | 61 +++++++ .../dungeonsxl/world/block/MultiBlock.java | 31 ++++ .../PlaceableBlock.java} | 19 ++- .../world/block/ProtectedBlock.java | 37 +++++ .../{reward => world/block}/RewardChest.java | 89 +++++------ .../dre2n/dungeonsxl/world/block/TeamBed.java | 96 +++++++++++ .../dungeonsxl/world/block/TeamBlock.java | 50 ++++++ .../dungeonsxl/world/block/TeamFlag.java | 73 +++++++++ .../dungeonsxl/sign/DSignTypeCustom.java | 11 +- 24 files changed, 884 insertions(+), 168 deletions(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/sign/ProtectionSign.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/block/MultiBlock.java rename core/src/main/java/io/github/dre2n/dungeonsxl/world/{GamePlaceableBlock.java => block/PlaceableBlock.java} (94%) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/block/ProtectedBlock.java rename core/src/main/java/io/github/dre2n/dungeonsxl/{reward => world/block}/RewardChest.java (87%) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBlock.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java index a717c3e2..9c170c57 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java @@ -22,7 +22,9 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent; import io.github.dre2n.dungeonsxl.event.dplayer.instance.edit.DEditPlayerEscapeEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; import io.github.dre2n.dungeonsxl.player.DEditPlayer; +import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; @@ -67,12 +69,17 @@ public class LeaveCommand extends BRCommand { return; } - DEditPlayerEscapeEvent dPlayerEscapeEvent = new DEditPlayerEscapeEvent((DEditPlayer) dPlayer); - plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent); + if (dPlayer instanceof DGamePlayer) { + DGamePlayerEscapeEvent dPlayerEscapeEvent = new DGamePlayerEscapeEvent((DGamePlayer) dPlayer); + plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent); + if (dPlayerEscapeEvent.isCancelled()) { + return; + } + } + DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup); plugin.getServer().getPluginManager().callEvent(dPlayerLeaveDGroupEvent); - - if (dPlayerEscapeEvent.isCancelled() || dPlayerLeaveDGroupEvent.isCancelled()) { + if (dPlayerLeaveDGroupEvent.isCancelled()) { return; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index da5c433e..61b84d0e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -86,6 +86,7 @@ public enum DMessages implements Messages { ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4The player &6&v1&4 is not member of the group &6&v2&v4."), ERROR_NOT_INVITED("Error_NotInvited", "&4You are not invited to the group &6&v1&4."), ERROR_NOT_SAVED("Error_NotSaved", "&4The map &6&v1&4 has not been saved to the &6DungeonsXL/maps/ &4folder yet!"), + ERROR_BLOCK_OWN_TEAM("Error_BlockOwnTeam", "&4This block belongs to your own group."), ERROR_READY("Error_Ready", "&4Choose your class first!"), ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"), ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"), @@ -126,8 +127,11 @@ public enum DMessages implements Messages { HELP_CMD_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"), HELP_CMD_TEST("Help_Cmd_Test", "/dxl test - Starts the game in test mode"), HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite [player] [dungeon] - Uninvite a player to edit a dungeon"), + GROUP_BED_DESTROYED("Group_BedDestroyed", "&6The bed of the group &4&v1 &6has been destroyed by &4&v2&6!"), GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"), GROUP_DISBANDED("Group_Disbanded", "&4&v1&6 disbanded the group &4&v2&6."), + GROUP_FLAG_CAPTURED("Group_FlagCaptured", "&4&v1&6 has captured the flag of the group &4&v2&6!"), + GROUP_FLAG_STEALING("Group_FlagStealing", "&4&v1&6 is stealing the flag of the group &4&v2&6!"), GROUP_INVITED_PLAYER("Group_InvitedPlayer", "&4&v1&6 invited the player &4&v2&6 to the group &4&v3&6."), GROUP_JOINED_GAME("Group_JoinedGame", "&6Your group successfully joined the game."), GROUP_UNINVITED_PLAYER("Group_UninvitedPlayer", "&4&v1&6 took back the invitation for &4&v2&6 to the group &4&v3&6."), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java index b55c7fca..cc06ca6c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -91,7 +91,7 @@ public class BlockListener implements Listener { // Deny DGameWorld block breaking DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld()); if (gameWorld != null) { - if (gameWorld.onBreak(player, block)) { + if (gameWorld.onBreak(event)) { event.setCancelled(true); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 0a542f71..62a00305 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -36,13 +36,13 @@ import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.player.DPlayers; import io.github.dre2n.dungeonsxl.reward.DLootInventory; -import io.github.dre2n.dungeonsxl.world.block.RewardChest; -import io.github.dre2n.dungeonsxl.sign.OpenDoorSign; import io.github.dre2n.dungeonsxl.task.RespawnTask; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.block.LockedDoor; +import io.github.dre2n.dungeonsxl.world.block.RewardChest; import java.util.ArrayList; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -117,9 +117,8 @@ public class PlayerListener implements Listener { return; } - dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives()); - if (dPlayer.getLives() != -1) { + dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives()); MessageUtil.sendMessage(player, DMessages.PLAYER_DEATH.getMessage(String.valueOf(dPlayer.getLives()))); if (game.getRules().getKeepInventoryOnDeath()) { @@ -142,6 +141,7 @@ public class PlayerListener implements Listener { Player player = event.getPlayer(); DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player); Block clickedBlock = event.getClickedBlock(); + DGameWorld dGameWorld = DGameWorld.getByWorld(player.getWorld()); if (dGlobalPlayer.isInBreakMode()) { return; @@ -149,7 +149,7 @@ public class PlayerListener implements Listener { if (clickedBlock != null) { // Block Enderchests - if (DGameWorld.getByWorld(player.getWorld()) != null || DEditWorld.getByWorld(player.getWorld()) != null) { + if (dGameWorld != null || DEditWorld.getByWorld(player.getWorld()) != null) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (clickedBlock.getType() == Material.ENDER_CHEST) { if (!DPermissions.hasPermission(player, DPermissions.BYPASS)) { @@ -167,7 +167,7 @@ public class PlayerListener implements Listener { } // Block Dispensers - if (DGameWorld.getByWorld(player.getWorld()) != null) { + if (dGameWorld != null) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (clickedBlock.getType() == Material.DISPENSER) { if (!DPermissions.hasPermission(player, DPermissions.BYPASS)) { @@ -177,6 +177,13 @@ public class PlayerListener implements Listener { } } } + + for (LockedDoor door : dGameWorld.getLockedDoors()) { + if (clickedBlock.equals(door.getBlock()) || clickedBlock.equals(door.getAttachedBlock())) { + event.setCancelled(true); + return; + } + } } // Check Portals @@ -298,9 +305,6 @@ public class PlayerListener implements Listener { } } } - - } else if (OpenDoorSign.isProtected(clickedBlock)) { - event.setCancelled(true); } } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index ff7d990a..2b989c40 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -74,6 +74,8 @@ public class DGamePlayer extends DInstancePlayer { private int initialLives = -1; private int lives; + private DGroup stealing; + public DGamePlayer(Player player, DGameWorld world) { super(player, world.getWorld()); @@ -365,6 +367,28 @@ public class DGamePlayer extends DInstancePlayer { this.lives = lives; } + /** + * @return if the player is stealing a flag + */ + public boolean isStealing() { + return stealing != null; + } + + /** + * @return the group whose flag is stolen + */ + public DGroup getRobbedGroup() { + return stealing; + } + + /** + * @param dGroup + * the group whose flag is stolen + */ + public void setRobbedGroup(DGroup dGroup) { + stealing = dGroup; + } + /* Actions */ @Override public void leave() { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java new file mode 100644 index 00000000..89f6cd74 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.commons.util.BlockUtil; +import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.block.TeamBed; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public class BedSign extends DSign { + + private DSignType type = DSignTypeDefault.BED; + + private int team; + + public BedSign(Sign sign, String[] lines, DGameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* Getters and setters */ + @Override + public DSignType getType() { + return type; + } + + /* Actions */ + @Override + public boolean check() { + return NumberUtil.parseInt(lines[1], -1) != -1; + } + + @Override + public void onInit() { + this.team = NumberUtil.parseInt(lines[1]); + Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); + + if (block.getType() == Material.BED_BLOCK) { + getGameWorld().addGameBlock(new TeamBed(block, getGame().getDGroups().get(team))); + getSign().getBlock().setType(Material.AIR); + } else { + markAsErroneous(); + } + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java index 6816623d..ac804d9b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java @@ -18,8 +18,8 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.loottable.DLootTable; -import io.github.dre2n.dungeonsxl.reward.RewardChest; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.block.RewardChest; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -181,7 +181,7 @@ public class ChestSign extends DSign { itemReward = list.toArray(new ItemStack[list.size()]); } - new RewardChest(chest, getGameWorld(), moneyReward, levelReward, itemReward); + getGameWorld().addGameBlock(new RewardChest(chest, moneyReward, levelReward, itemReward)); getSign().getBlock().setType(Material.AIR); } else { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java index fce73d99..fb5e19de 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java @@ -32,10 +32,15 @@ public interface DSignType { public String getBuildPermission(); /** - * @return the onDungeonInit + * @return if the sign gets initialized when the dungeon is loaded instead of when the game starts */ public boolean isOnDungeonInit(); + /** + * @return if the sign block should be destroyable after the initialization + */ + public boolean isProtected(); + /** * @return the handler */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index b5f2b33d..f1c5f0ba 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -23,45 +23,50 @@ import io.github.dre2n.dungeonsxl.player.DPermissions; */ public enum DSignTypeDefault implements DSignType { - BLOCK("Block", "block", false, BlockSign.class), - CHECKPOINT("Checkpoint", "checkpoint", false, CheckpointSign.class), - CHEST("Chest", "chest", false, ChestSign.class), - CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, ChunkUpdaterSign.class), - CLASSES("Classes", "classes", true, ClassesSign.class), - COMMAND("CMD", "cmd", false, CommandSign.class), - DROP("Drop", "drop", false, DropSign.class), - END("End", "end", false, EndSign.class), - EXTERNAL_MOB("ExternalMob", "mob", false, ExternalMobSign.class), - FLOOR("Floor", "floor", false, FloorSign.class), - HOLOGRAM("Hologram", "hologram", true, HologramSign.class), - INTERACT("Interact", "interact", true, InteractSign.class), - LEAVE("Leave", "leave", true, LeaveSign.class), - LIVES_MODIFIER("Lives", "lives", false, LivesModifierSign.class), - LOBBY("Lobby", "lobby", true, LobbySign.class), - MOB("Mob", "mob", false, DMobSign.class), - MESSAGE("MSG", "msg", false, MessageSign.class), + BED("Bed", "bed", false, false, BedSign.class), + BLOCK("Block", "block", false, true, BlockSign.class), + CHECKPOINT("Checkpoint", "checkpoint", false, false, CheckpointSign.class), + CHEST("Chest", "chest", false, false, ChestSign.class), + CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, false, ChunkUpdaterSign.class), + CLASSES("Classes", "classes", true, true, ClassesSign.class), + COMMAND("CMD", "cmd", false, false, CommandSign.class), + DROP("Drop", "drop", false, false, DropSign.class), + END("End", "end", false, true, EndSign.class), + EXTERNAL_MOB("ExternalMob", "mob", false, false, ExternalMobSign.class), + FLAG("Flag", "flag", false, false, FlagSign.class), + FLOOR("Floor", "floor", false, true, FloorSign.class), + HOLOGRAM("Hologram", "hologram", true, false, HologramSign.class), + INTERACT("Interact", "interact", true, true, InteractSign.class), + LEAVE("Leave", "leave", true, true, LeaveSign.class), + LIVES_MODIFIER("Lives", "lives", false, false, LivesModifierSign.class), + LOBBY("Lobby", "lobby", true, false, LobbySign.class), + MOB("Mob", "mob", false, false, DMobSign.class), + MESSAGE("MSG", "msg", false, false, MessageSign.class), @Deprecated - MYTHIC_MOBS("MythicMobs", "mob", false, ExternalMobSign.class), - OPEN_DOOR("Door", "door", false, OpenDoorSign.class), - PLACE("Place", "place", false, PlaceSign.class), - READY("Ready", "ready", true, ReadySign.class), - REDSTONE("Redstone", "redstone", false, RedstoneSign.class), - SCRIPT("Script", "script", false, ScriptSign.class), - SOUND_MESSAGE("SoundMSG", "soundmsg", false, SoundMessageSign.class), - START("Start", "start", true, StartSign.class), - TELEPORT("Teleport", "teleport", false, TeleportSign.class), - TRIGGER("Trigger", "trigger", true, TriggerSign.class), - WAVE("Wave", "wave", false, WaveSign.class); + MYTHIC_MOBS("MythicMobs", "mob", false, false, ExternalMobSign.class), + OPEN_DOOR("Door", "door", false, false, OpenDoorSign.class), + PLACE("Place", "place", false, false, PlaceSign.class), + PROTECTION("Protection", "protection", false, false, ProtectionSign.class), + READY("Ready", "ready", true, true, ReadySign.class), + REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class), + SCRIPT("Script", "script", false, false, ScriptSign.class), + SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class), + START("Start", "start", true, false, StartSign.class), + TELEPORT("Teleport", "teleport", false, false, TeleportSign.class), + TRIGGER("Trigger", "trigger", true, false, TriggerSign.class), + WAVE("Wave", "wave", false, false, WaveSign.class); private String name; private String buildPermission; private boolean onDungeonInit; + private boolean isProtected; private Class handler; - DSignTypeDefault(String name, String buildPermission, boolean onDungeonInit, Class handler) { + DSignTypeDefault(String name, String buildPermission, boolean onDungeonInit, boolean isProtected, Class handler) { this.name = name; this.buildPermission = buildPermission; this.onDungeonInit = onDungeonInit; + this.isProtected = isProtected; this.handler = handler; } @@ -80,6 +85,11 @@ public enum DSignTypeDefault implements DSignType { return onDungeonInit; } + @Override + public boolean isProtected() { + return isProtected; + } + @Override public Class getHandler() { return handler; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java new file mode 100644 index 00000000..28220cee --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.block.TeamFlag; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public class FlagSign extends DSign { + + private DSignType type = DSignTypeDefault.FLAG; + + private int team; + + public FlagSign(Sign sign, String[] lines, DGameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* Getters and setters */ + @Override + public DSignType getType() { + return type; + } + + /* Actions */ + @Override + public boolean check() { + return NumberUtil.parseInt(lines[1], -1) != -1; + } + + @Override + public void onInit() { + this.team = NumberUtil.parseInt(lines[1]); + getGameWorld().addGameBlock(new TeamFlag(getSign().getBlock(), team, getGame().getDGroups().get(team))); + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java index 942b1272..ddd1033b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java @@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.commons.util.BlockUtil; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.block.LockedDoor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -31,7 +32,7 @@ public class OpenDoorSign extends DSign { private DSignType type = DSignTypeDefault.OPEN_DOOR; - private Block block; + private LockedDoor door; public OpenDoorSign(Sign sign, String[] lines, DGameWorld gameWorld) { super(sign, lines, gameWorld); @@ -41,16 +42,16 @@ public class OpenDoorSign extends DSign { /** * @return the door to open; */ - public Block getBlock() { - return block; + public LockedDoor getDoor() { + return door; } /** - * @param block + * @param door * the door to open */ - public void setBlock(Block block) { - this.block = block; + public void setDoor(LockedDoor door) { + this.door = door; } @Override @@ -69,44 +70,24 @@ public class OpenDoorSign extends DSign { Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); if (block.getState().getData() instanceof Door) { if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) { - this.block = block.getRelative(BlockFace.DOWN); + door = new LockedDoor(block.getRelative(BlockFace.DOWN)); } else { - this.block = block; - + door = new LockedDoor(block); } - } + getGameWorld().addGameBlock(door); - getSign().getBlock().setType(Material.AIR); + getSign().getBlock().setType(Material.AIR); + + } else { + markAsErroneous(); + } } @Override public void onTrigger() { - if (block != null) { - ((Door) block.getState().getData()).setOpen(true); - block.getState().update(true); + if (door != null) { + door.open(); } } - /* Statics */ - /** - * @param block - * the block to check - * @return - * true if the block is openable only with a sign - */ - public static boolean isProtected(Block block) { - DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld()); - if (gameWorld != null) { - for (DSign dSign : gameWorld.getDSigns(DSignTypeDefault.OPEN_DOOR)) { - Block signBlock1 = ((OpenDoorSign) dSign).getBlock(); - Block signBlock2 = signBlock1.getRelative(BlockFace.UP); - if (block.equals(signBlock1) || block.equals(signBlock2)) { - return true; - } - } - } - - return false; - } - } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java index d7f830d9..0fb51287 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java @@ -39,7 +39,7 @@ public class PlaceSign extends DSign { @Override public void onInit() { - getGameWorld().getPlaceableBlocks().add(new PlaceableBlock(getSign().getBlock(), lines[1], lines[2])); + getGameWorld().addGameBlock(new PlaceableBlock(getSign().getBlock(), lines[1], lines[2])); getSign().getBlock().setType(Material.AIR); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ProtectionSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ProtectionSign.java new file mode 100644 index 00000000..2af4d9a4 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ProtectionSign.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.commons.util.BlockUtil; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.block.ProtectedBlock; +import org.bukkit.Material; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public class ProtectionSign extends DSign { + + private DSignType type = DSignTypeDefault.PROTECTION; + + public ProtectionSign(Sign sign, String[] lines, DGameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* Getters and setters */ + @Override + public DSignType getType() { + return type; + } + + /* Actions */ + @Override + public boolean check() { + return true; + } + + @Override + public void onInit() { + getGameWorld().addGameBlock(new ProtectedBlock(BlockUtil.getAttachedBlock(getSign().getBlock()))); + getSign().getBlock().setType(Material.AIR); + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index cc441f7b..98e1ed3d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -24,7 +24,6 @@ import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.player.DGroup; -import io.github.dre2n.dungeonsxl.reward.RewardChest; import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.sign.DSignType; import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; @@ -36,6 +35,13 @@ import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; import io.github.dre2n.dungeonsxl.trigger.Trigger; import io.github.dre2n.dungeonsxl.trigger.TriggerType; import io.github.dre2n.dungeonsxl.trigger.TriggerTypeDefault; +import io.github.dre2n.dungeonsxl.world.block.GameBlock; +import io.github.dre2n.dungeonsxl.world.block.LockedDoor; +import io.github.dre2n.dungeonsxl.world.block.MultiBlock; +import io.github.dre2n.dungeonsxl.world.block.PlaceableBlock; +import io.github.dre2n.dungeonsxl.world.block.RewardChest; +import io.github.dre2n.dungeonsxl.world.block.TeamBed; +import io.github.dre2n.dungeonsxl.world.block.TeamFlag; import java.io.File; import java.util.ArrayList; import java.util.HashSet; @@ -55,6 +61,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Spider; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; @@ -69,12 +76,18 @@ public class DGameWorld extends DInstanceWorld { // TO DO: Which lists actually need to be CopyOnWriteArrayLists? private List placedBlocks = new LinkedList<>(); - private CopyOnWriteArrayList placeableBlocks = new CopyOnWriteArrayList<>(); + + private Set gameBlocks = new HashSet<>(); + private Set lockedDoors = new HashSet<>(); + private Set placeableBlocks = new HashSet<>(); + private Set rewardChests = new HashSet<>(); + private Set teamBeds = new HashSet<>(); + private Set teamFlags = new HashSet<>(); + private List secureObjects = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList loadedChunks = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList classesSigns = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList dMobs = new CopyOnWriteArrayList<>(); - private CopyOnWriteArrayList rewardChests = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList dSigns = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList triggers = new CopyOnWriteArrayList<>(); @@ -163,16 +176,83 @@ public class DGameWorld extends DInstanceWorld { /** * @return the placeableBlocks */ - public CopyOnWriteArrayList getPlaceableBlocks() { + public Set getGameBlocks() { + return gameBlocks; + } + + /** + * @param gameBlock + * the gameBlock to add + */ + public void addGameBlock(GameBlock gameBlock) { + gameBlocks.add(gameBlock); + + if (gameBlock instanceof LockedDoor) { + lockedDoors.add((LockedDoor) gameBlock); + } else if (gameBlock instanceof PlaceableBlock) { + placeableBlocks.add((PlaceableBlock) gameBlock); + } else if (gameBlock instanceof RewardChest) { + rewardChests.add((RewardChest) gameBlock); + } else if (gameBlock instanceof TeamBed) { + teamBeds.add((TeamBed) gameBlock); + } else if (gameBlock instanceof TeamFlag) { + teamFlags.add((TeamFlag) gameBlock); + } + } + + /** + * @param gameBlock + * the gameBlock to remove + */ + public void removeGameBlock(GameBlock gameBlock) { + gameBlocks.remove(gameBlock); + + if (gameBlock instanceof LockedDoor) { + lockedDoors.remove((LockedDoor) gameBlock); + } else if (gameBlock instanceof PlaceableBlock) { + placeableBlocks.remove((PlaceableBlock) gameBlock); + } else if (gameBlock instanceof RewardChest) { + rewardChests.remove((RewardChest) gameBlock); + } else if (gameBlock instanceof TeamBed) { + teamBeds.remove((TeamBed) gameBlock); + } else if (gameBlock instanceof TeamFlag) { + teamFlags.remove((TeamFlag) gameBlock); + } + } + + /** + * @return the rewardChests + */ + public Set getRewardChests() { + return rewardChests; + } + + /** + * @return the locked doors + */ + public Set getLockedDoors() { + return lockedDoors; + } + + /** + * @return the placeable blocks + */ + public Set getPlaceableBlocks() { return placeableBlocks; } /** - * @param placeableBlocks - * the placeableBlocks to set + * @return the team beds */ - public void setPlaceableBlocks(CopyOnWriteArrayList placeableBlocks) { - this.placeableBlocks = placeableBlocks; + public Set getTeamBeds() { + return teamBeds; + } + + /** + * @return the team flags + */ + public Set getTeamFlags() { + return teamFlags; } /** @@ -243,21 +323,6 @@ public class DGameWorld extends DInstanceWorld { dMobs.remove(dMob); } - /** - * @return the rewardChests - */ - public CopyOnWriteArrayList getRewardChests() { - return rewardChests; - } - - /** - * @param rewardChests - * the rewardChests to set - */ - public void setRewardChests(CopyOnWriteArrayList rewardChests) { - this.rewardChests = rewardChests; - } - /** * @return the dSigns */ @@ -460,16 +525,34 @@ public class DGameWorld extends DInstanceWorld { } } - public boolean onBreak(Player player, Block block) { + /** + * Handles what happens when a player breaks a block. + * + * @param event + * the passed Bukkit event + * @return if the event is cancelled + */ + public boolean onBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); for (DSign dSign : dSigns) { - if (dSign.getSign().getBlock().equals(block)) { + if (block.equals(dSign.getSign().getBlock()) && dSign.getType().isProtected()) { return true; } } - for (RewardChest rChest : rewardChests) { - if (rChest.getChest().getBlock().equals(block)) { - return true; + for (GameBlock gameBlock : gameBlocks) { + if (block.equals(gameBlock.getBlock())) { + if (gameBlock.onBreak(event)) { + return true; + } + + } else if (gameBlock instanceof MultiBlock) { + if (block.equals(((MultiBlock) gameBlock).getAttachedBlock())) { + if (gameBlock.onBreak(event)) { + return true; + } + } } } @@ -505,6 +588,16 @@ public class DGameWorld extends DInstanceWorld { return true; } + /** + * Handles what happens when a player places a block. + * + * @param player + * @param block + * @param against + * @param hand + * the event parameters. + * @return if the event is cancelled + */ public boolean onPlace(Player player, Block block, Block against, ItemStack hand) { // Workaround for a bug that would allow 3-Block-high jumping Location loc = player.getLocation(); @@ -525,7 +618,7 @@ public class DGameWorld extends DInstanceWorld { } GameRules rules = game.getRules(); - if (!rules.canPlaceBlocks() && !GamePlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) { + if (!rules.canPlaceBlocks() && !PlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) { return true; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java new file mode 100644 index 00000000..307d7244 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world.block; + +import org.bukkit.block.Block; +import org.bukkit.event.block.BlockBreakEvent; + +/** + * @author Daniel Saukel + */ +public abstract class GameBlock { + + protected Block block; + + public GameBlock(Block block) { + this.block = block; + } + + /* Getters and setters */ + /** + * @return the block + */ + public Block getBlock() { + return block; + } + + /** + * @param block + * the block to set + */ + public void setBlock(Block block) { + this.block = block; + } + + /* Abstracts */ + /** + * Handles what happens when a player breaks the block. + * + * @param event + * the passed Bukkit event + * @return if the event is cancelled + */ + public abstract boolean onBreak(BlockBreakEvent event); + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java new file mode 100644 index 00000000..1db52238 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world.block; + +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.material.Door; + +/** + * @author Daniel Saukel + */ +public class LockedDoor extends GameBlock implements MultiBlock { + + private Block attachedBlock; + + public LockedDoor(Block block) { + super(block); + attachedBlock = getAttachedBlock(); + } + + /* Getters and setters */ + @Override + public Block getAttachedBlock() { + if (attachedBlock != null) { + return attachedBlock; + + } else { + return block.getRelative(BlockFace.UP); + } + } + + /* Actions */ + @Override + public boolean onBreak(BlockBreakEvent event) { + return true; + } + + /** + * Opens the door. + */ + public void open() { + ((Door) block.getState().getData()).setOpen(true); + block.getState().update(true); + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/MultiBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/MultiBlock.java new file mode 100644 index 00000000..cc69dafb --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/MultiBlock.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world.block; + +import org.bukkit.block.Block; + +/** + * In some cases, a "game block" might actually be a structure with multiple blocks, + * like a bed or a door with two halfs. These GameBlocks implement MultiBlock. + * + * @author Daniel Saukel + */ +public interface MultiBlock { + + public Block getAttachedBlock(); + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/PlaceableBlock.java similarity index 94% rename from core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/block/PlaceableBlock.java index 5f1f324d..c0bbeb16 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/PlaceableBlock.java @@ -14,22 +14,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.world; +package io.github.dre2n.dungeonsxl.world.block; import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.HashSet; import java.util.Set; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.event.block.BlockBreakEvent; /** * @author Frank Baumann, Daniel Saukel */ -public class GamePlaceableBlock { +public class PlaceableBlock extends GameBlock { // Variables - private Block block; private Set materials = new HashSet<>(); private boolean onTop = false; @@ -39,8 +40,8 @@ public class GamePlaceableBlock { private boolean onEast = false; private boolean onWest = false; - public GamePlaceableBlock(Block block, String ids, String directions) { - this.block = block; + public PlaceableBlock(Block block, String ids, String directions) { + super(block); // Split ids if (!ids.isEmpty()) { @@ -252,9 +253,15 @@ public class GamePlaceableBlock { } } + /* Actions */ + @Override + public boolean onBreak(BlockBreakEvent event) { + return false; + } + // Can build public static boolean canBuildHere(Block block, BlockFace blockFace, Material mat, DGameWorld gameWorld) { - for (GamePlaceableBlock gamePlacableBlock : gameWorld.getPlaceableBlocks()) { + for (PlaceableBlock gamePlacableBlock : gameWorld.getPlaceableBlocks()) { if (gamePlacableBlock.block.getFace(block) != BlockFace.SELF) { continue; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/ProtectedBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/ProtectedBlock.java new file mode 100644 index 00000000..4509a9b7 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/ProtectedBlock.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world.block; + +import org.bukkit.block.Block; +import org.bukkit.event.block.BlockBreakEvent; + +/** + * @author Daniel Saukel + */ +public class ProtectedBlock extends GameBlock { + + public ProtectedBlock(Block block) { + super(block); + } + + /* Actions */ + @Override + public boolean onBreak(BlockBreakEvent event) { + return true; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardChest.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java similarity index 87% rename from core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardChest.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java index c4c8850a..711a43cd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardChest.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java @@ -14,14 +14,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.reward; +package io.github.dre2n.dungeonsxl.world.block; 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.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; -import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.reward.ItemReward; +import io.github.dre2n.dungeonsxl.reward.LevelReward; +import io.github.dre2n.dungeonsxl.reward.MoneyReward; +import io.github.dre2n.dungeonsxl.reward.Reward; +import io.github.dre2n.dungeonsxl.reward.RewardTypeDefault; import net.milkbowl.vault.item.ItemInfo; import net.milkbowl.vault.item.Items; import org.bukkit.Bukkit; @@ -29,35 +33,34 @@ import org.bukkit.ChatColor; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; /** * @author Frank Baumann, Daniel Saukel */ -public class RewardChest { - +public class RewardChest extends GameBlock { + static DungeonsXL plugin = DungeonsXL.getInstance(); // Variables private boolean used = false; private Chest chest; - private DGameWorld gameWorld; private double moneyReward; private int levelReward; private ItemStack[] itemReward; - - public RewardChest(Block chest, DGameWorld gameWorld, double moneyReward, int levelReward, ItemStack[] itemReward) { + + public RewardChest(Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) { + super(chest); + if (!(chest.getState() instanceof Chest)) { return; } - + this.chest = (Chest) chest.getState(); - this.gameWorld = gameWorld; this.moneyReward = moneyReward; this.levelReward = levelReward; this.itemReward = itemReward; - - gameWorld.getRewardChests().add(this); } /** @@ -90,21 +93,6 @@ public class RewardChest { this.chest = chest; } - /** - * @return the gameWorld - */ - public DGameWorld getGameWorld() { - return gameWorld; - } - - /** - * @param gameWorld - * the gameWorld to set - */ - public void setGameWorld(DGameWorld gameWorld) { - this.gameWorld = gameWorld; - } - /** * @return the moneyReward */ @@ -136,6 +124,11 @@ public class RewardChest { } /* Actions */ + @Override + public boolean onBreak(BlockBreakEvent event) { + return true; + } + /** * @param opener * the player who opens the chest @@ -145,77 +138,77 @@ public class RewardChest { MessageUtil.sendMessage(plugin.getServer().getPlayer(opener.getUniqueId()), DMessages.ERROR_CHEST_IS_OPENED.getMessage()); return; } - + if (chest.getLocation().distance(chest.getLocation()) < 1) { addTreasure(DGroup.getByPlayer(opener)); used = true; } } - + public void addTreasure(DGroup dGroup) { if (dGroup == null) { return; } - + boolean hasMoneyReward = false; boolean hasLevelReward = false; boolean hasItemReward = false; - + for (Reward reward : dGroup.getRewards()) { if (reward.getType() == RewardTypeDefault.MONEY) { hasMoneyReward = true; ((MoneyReward) reward).addMoney(moneyReward); - + } else if (reward.getType() == RewardTypeDefault.LEVEL) { hasLevelReward = true; ((LevelReward) reward).addLevels(levelReward); - + } else if (reward.getType() == RewardTypeDefault.ITEM) { hasItemReward = true; ((ItemReward) reward).addItems(itemReward); } } - + if (!hasMoneyReward) { Reward reward = Reward.create(RewardTypeDefault.MONEY); ((MoneyReward) reward).addMoney(moneyReward); dGroup.addReward(reward); } - + if (!hasLevelReward) { Reward reward = Reward.create(RewardTypeDefault.LEVEL); ((LevelReward) reward).addLevels(levelReward); dGroup.addReward(reward); } - + if (!hasItemReward) { Reward reward = Reward.create(RewardTypeDefault.ITEM); ((ItemReward) reward).addItems(itemReward); dGroup.addReward(reward); } - + for (Player player : dGroup.getPlayers()) { DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); if (dPlayer == null) { continue; } - + if (itemReward != null) { String msg = ""; for (ItemStack itemStack : itemReward) { - + if (itemStack == null) { continue; } - + String name = null; - + if (itemStack.hasItemMeta()) { if (itemStack.getItemMeta().hasDisplayName()) { name = itemStack.getItemMeta().getDisplayName(); } } - + if (name == null) { if (Bukkit.getPluginManager().getPlugin("Vault") != null) { ItemInfo itemInfo = Items.itemByStack(itemStack); @@ -224,30 +217,30 @@ public class RewardChest { } else { name = itemStack.getType().name(); } - + } else { name = itemStack.getType().toString(); } } - + msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ","; } - + if (msg.length() >= 1) { msg = msg.substring(0, msg.length() - 1); } - + MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(msg)); } - + if (moneyReward != 0 && plugin.getEconomyProvider() != null) { MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(plugin.getEconomyProvider().format(moneyReward))); } - + if (levelReward != 0) { MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(levelReward + " levels")); } } } - + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java new file mode 100644 index 00000000..d8d2866a --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world.block; + +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.material.Bed; + +/** + * @author Daniel Saukel + */ +public class TeamBed extends TeamBlock implements MultiBlock { + + private Block attachedBlock; + + public TeamBed(Block block, DGroup owner) { + super(block, owner); + attachedBlock = getAttachedBlock(); + } + + /* Getters and setters */ + public Block getAttachedBlock(Block block) { + if (block.getRelative(BlockFace.EAST).getType() == Material.BED_BLOCK) { + return block.getRelative(BlockFace.EAST); + + } else if (block.getRelative(BlockFace.NORTH).getType() == Material.BED_BLOCK) { + return block.getRelative(BlockFace.NORTH); + + } else if (block.getRelative(BlockFace.WEST).getType() == Material.BED_BLOCK) { + return block.getRelative(BlockFace.WEST); + + } else if (block.getRelative(BlockFace.SOUTH).getType() == Material.BED_BLOCK) { + return block.getRelative(BlockFace.SOUTH); + + } else { + return null; + } + } + + @Override + public Block getAttachedBlock() { + if (attachedBlock != null) { + return attachedBlock; + + } else { + return getAttachedBlock(block); + } + } + + /* Actions */ + @Override + public boolean onBreak(BlockBreakEvent event) { + Player breaker = event.getPlayer(); + if (owner.getPlayers().contains(breaker)) { + MessageUtil.sendMessage(breaker, DMessages.ERROR_BLOCK_OWN_TEAM.getMessage()); + return true; + } + + for (DGamePlayer player : owner.getDGamePlayers()) { + player.setLives(1); + } + + owner.getGameWorld().sendMessage(DMessages.GROUP_BED_DESTROYED.getMessage(owner.getName(), breaker.getName())); + Block block1 = event.getBlock(); + if (((Bed) block1.getState().getData()).isHeadOfBed()) { + Block block2 = getAttachedBlock(block1); + if (block2 != null) { + block2.setType(Material.AIR); + } + } + block1.setType(Material.AIR); + return true; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBlock.java new file mode 100644 index 00000000..6f2ab638 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBlock.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world.block; + +import io.github.dre2n.dungeonsxl.player.DGroup; +import org.bukkit.block.Block; + +/** + * @author Daniel Saukel + */ +public abstract class TeamBlock extends GameBlock { + + protected DGroup owner; + + public TeamBlock(Block block, DGroup owner) { + super(block); + this.owner = owner; + } + + /* Getters and setters */ + /** + * @return the group that owns the flag + */ + public DGroup getOwner() { + return owner; + } + + /** + * @param owner + * the owner group to set + */ + public void setOwner(DGroup owner) { + this.owner = owner; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java new file mode 100644 index 00000000..37ebb4ad --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world.block; + +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.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; + +/** + * @author Daniel Saukel + */ +public class TeamFlag extends TeamBlock { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + public static final int WOOL = 35; + + private byte teamId; + + public TeamFlag(Block block, int teamId, DGroup owner) { + super(block, owner); + this.teamId = plugin.getMainConfig().getGroupColorPriority().get(teamId).byteValue(); + reset(); + } + + /* Actions */ + /** + * Reset a team flag when the capturer dies. + */ + public void reset() { + block.setTypeIdAndData(WOOL, teamId, false); + } + + @Override + public boolean onBreak(BlockBreakEvent event) { + Player breaker = event.getPlayer(); + DGamePlayer gamePlayer = DGamePlayer.getByPlayer(breaker); + if (gamePlayer == null) { + return true; + } + + if (owner.getPlayers().contains(breaker)) { + MessageUtil.sendMessage(breaker, DMessages.ERROR_BLOCK_OWN_TEAM.getMessage()); + return true; + } + + owner.getGameWorld().sendMessage(DMessages.GROUP_FLAG_STEALING.getMessage(breaker.getName(), owner.getName())); + gamePlayer.setRobbedGroup(owner); + event.getBlock().setType(Material.AIR); + return true; + } + +} diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java b/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java index 537fede3..2f45104f 100644 --- a/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java +++ b/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java @@ -23,17 +23,19 @@ import io.github.dre2n.dungeonsxl.player.DPermissions; */ public enum DSignTypeCustom implements DSignType { - CUSTOM("Custom", "custom", false, CustomSign.class); + CUSTOM("Custom", "custom", false, false, CustomSign.class); private String name; private String buildPermission; private boolean onDungeonInit; + private boolean isProtected; private Class handler; - DSignTypeCustom(String name, String buildPermission, boolean onDungeonInit, Class handler) { + DSignTypeCustom(String name, String buildPermission, boolean onDungeonInit, boolean isProtected, Class handler) { this.name = name; this.buildPermission = buildPermission; this.onDungeonInit = onDungeonInit; + this.isProtected = isProtected; this.handler = handler; } @@ -52,6 +54,11 @@ public enum DSignTypeCustom implements DSignType { return onDungeonInit; } + @Override + public boolean isProtected() { + return isProtected; + } + @Override public Class getHandler() { return handler; From b1c49ebc95ef6662555e54a632b2e53751c02c0c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 31 Jul 2016 23:53:07 +0200 Subject: [PATCH 15/57] Create error sign if external mob sign provider is unknown --- .../io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java index c3bdfd1d..eaee9595 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java @@ -229,6 +229,11 @@ public class ExternalMobSign extends DSign implements MobSign { } else { provider = ExternalMobPlugin.MYTHIC_MOBS; } + + if (provider == null) { + markAsErroneous(); + return; + } } } From d22bc7a8eeac82299fa3da45933eecb53a0a1cac Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 31 Jul 2016 23:53:20 +0200 Subject: [PATCH 16/57] Fix /Dxl lives target --- .../java/io/github/dre2n/dungeonsxl/command/LivesCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java index 8bbdb716..74c323c1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java @@ -62,10 +62,10 @@ public class LivesCommand extends BRCommand { DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); if (dPlayer != null) { - MessageUtil.sendMessage(player, DMessages.CMD_LIVES.getMessage(player.getName(), String.valueOf(dPlayer.getLives()))); + MessageUtil.sendMessage(sender, DMessages.CMD_LIVES.getMessage(player.getName(), String.valueOf(dPlayer.getLives()))); } else { - MessageUtil.sendMessage(player, DMessages.ERROR_NOT_IN_DUNGEON.getMessage()); + MessageUtil.sendMessage(sender, DMessages.ERROR_NOT_IN_DUNGEON.getMessage()); } } From 9c9bf05b95aa5274e1311c1dea737801ab904149 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 1 Aug 2016 00:06:31 +0200 Subject: [PATCH 17/57] Fix portal creation NPE --- .../dre2n/dungeonsxl/listener/PlayerListener.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 62a00305..20fa1edd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -176,12 +176,12 @@ public class PlayerListener implements Listener { } } } - } - for (LockedDoor door : dGameWorld.getLockedDoors()) { - if (clickedBlock.equals(door.getBlock()) || clickedBlock.equals(door.getAttachedBlock())) { - event.setCancelled(true); - return; + for (LockedDoor door : dGameWorld.getLockedDoors()) { + if (clickedBlock.equals(door.getBlock()) || clickedBlock.equals(door.getAttachedBlock())) { + event.setCancelled(true); + return; + } } } } From b112b81e51d43760a773e612de97ce6f0a9de166 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 1 Aug 2016 19:08:23 +0200 Subject: [PATCH 18/57] #9: Allow any kind of portal material --- .../dungeonsxl/command/LeaveCommand.java | 1 - .../dungeonsxl/command/PortalCommand.java | 14 +++++- .../dre2n/dungeonsxl/config/DMessages.java | 2 +- .../dre2n/dungeonsxl/global/DPortal.java | 46 ++++++++++++++----- .../dungeonsxl/global/GlobalProtections.java | 6 ++- .../dungeonsxl/listener/BlockListener.java | 21 ++------- .../dungeonsxl/listener/PlayerListener.java | 2 +- 7 files changed, 57 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java index 9c170c57..9f290840 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java @@ -21,7 +21,6 @@ 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.event.dplayer.DPlayerLeaveDGroupEvent; -import io.github.dre2n.dungeonsxl.event.dplayer.instance.edit.DEditPlayerEscapeEvent; import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; import io.github.dre2n.dungeonsxl.player.DEditPlayer; import io.github.dre2n.dungeonsxl.player.DGamePlayer; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/PortalCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/PortalCommand.java index 29f86dd5..9fea17df 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/PortalCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/PortalCommand.java @@ -39,7 +39,7 @@ public class PortalCommand extends BRCommand { public PortalCommand() { setCommand("portal"); setMinArgs(0); - setMaxArgs(0); + setMaxArgs(1); setHelp(DMessages.HELP_CMD_PORTAL.getMessage()); setPermission(DPermissions.PORTAL.getNode()); setPlayerCommand(true); @@ -55,10 +55,20 @@ public class PortalCommand extends BRCommand { return; } + Material material = null; + + if (args.length == 2) { + material = Material.matchMaterial(args[1]); + } + + if (material == null) { + material = Material.PORTAL; + } + DPortal dPortal = dGlobalPlayer.getPortal(); if (dPortal == null) { - dPortal = new DPortal(plugin.getGlobalProtections().generateId(DPortal.class, player.getWorld()), player.getWorld(), false); + dPortal = new DPortal(plugin.getGlobalProtections().generateId(DPortal.class, player.getWorld()), player.getWorld(), material, false); dGlobalPlayer.setCreatingPortal(dPortal); dPortal.setWorld(player.getWorld()); player.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD)); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 61b84d0e..70344bfd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -120,7 +120,7 @@ public enum DMessages implements Messages { HELP_CMD_MAIN("Help_Cmd_Main", "/dxl - General status information"), HELP_CMD_MSG("Help_Cmd_Msg", "/dxl msg [id] '[msg]' - Show or edit a message"), HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play ([dungeon|map]) [name] - Allows the player to play a dungeon without a portal"), - HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal - Creates a portal that leads into a dungeon"), + HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal ([material=portal])- Creates a portal that leads into a dungeon"), HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"), HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"), HELP_CMD_STATUS("Help_Cmd_Status", "/dxl status - Shows the technical status of DungeonsXL"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java index 6d7d7174..82da5340 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -21,8 +21,10 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.util.HashSet; import java.util.Set; import org.bukkit.Location; @@ -39,19 +41,27 @@ public class DPortal extends GlobalProtection { private Block block1; private Block block2; + private Material material = Material.PORTAL; private boolean active; private Set blocks; public DPortal(int id, World world, boolean active) { + this(id, world, Material.PORTAL, active); + } + + public DPortal(int id, World world, Material material, boolean active) { super(world, id); + + this.material = material; this.active = active; } - public DPortal(int id, Block block1, Block block2, boolean active) { + public DPortal(int id, Block block1, Block block2, Material material, boolean active) { super(block1.getWorld(), id); this.block1 = block1; this.block2 = block2; + this.material = material; this.active = active; } @@ -103,12 +113,13 @@ public class DPortal extends GlobalProtection { /** * Create a new DPortal */ - public void create() { + public void create(DGlobalPlayer player) { if (block1 == null || block2 == null) { delete(); return; } + int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ(); int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ(); int xcount = 0, ycount = 0, zcount = 0; @@ -138,11 +149,8 @@ public class DPortal extends GlobalProtection { do { Material type = getWorld().getBlockAt(xx, yy, zz).getType(); - if (type == Material.AIR || type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA || type == Material.SAPLING - || type == Material.WEB || type == Material.LONG_GRASS || type == Material.DEAD_BUSH || type == Material.PISTON_EXTENSION || type == Material.YELLOW_FLOWER - || type == Material.RED_ROSE || type == Material.BROWN_MUSHROOM || type == Material.RED_MUSHROOM || type == Material.TORCH || type == Material.FIRE - || type == Material.CROPS || type == Material.REDSTONE_WIRE || type == Material.REDSTONE_TORCH_OFF || type == Material.SNOW || type == Material.REDSTONE_TORCH_ON) { - getWorld().getBlockAt(xx, yy, zz).setType(Material.PORTAL); + if (!type.isSolid()) { + getWorld().getBlockAt(xx, yy, zz).setType(material, false); } zz = zz + zcount; @@ -153,6 +161,10 @@ public class DPortal extends GlobalProtection { xx = xx + xcount; } while (xx != x2 + xcount); + + if (player != null) { + player.setCreatingPortal(null); + } } /** @@ -186,8 +198,11 @@ public class DPortal extends GlobalProtection { } if (target == null && dGroup.getMapName() != null) { - target = plugin.getDWorlds().getResourceByName(dGroup.getMapName()).instantiateAsGameWorld();//TO DO - dGroup.setGameWorld(target); + DResourceWorld resource = plugin.getDWorlds().getResourceByName(dGroup.getMapName()); + if (resource != null) { + target = resource.instantiateAsGameWorld(); + dGroup.setGameWorld(target); + } } if (target == null) { @@ -197,6 +212,7 @@ public class DPortal extends GlobalProtection { if (game == null) { game = new Game(dGroup, target); + } else { game.setWorld(target); dGroup.setGameWorld(target); @@ -225,20 +241,26 @@ public class DPortal extends GlobalProtection { } String preString = "protections.portals." + getWorld().getName() + "." + getId(); - // Location1 + configFile.set(preString + ".loc1.x", block1.getX()); configFile.set(preString + ".loc1.y", block1.getY()); configFile.set(preString + ".loc1.z", block1.getZ()); - // Location1 + configFile.set(preString + ".loc2.x", block2.getX()); configFile.set(preString + ".loc2.y", block2.getY()); configFile.set(preString + ".loc2.z", block2.getZ()); + + configFile.set(preString + ".material", material.toString()); } @Override public void delete() { protections.removeProtection(this); + if (block1 == null || block2 == null) { + return; + } + int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ(); int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ(); int xcount = 0, ycount = 0, zcount = 0; @@ -269,7 +291,7 @@ public class DPortal extends GlobalProtection { do { Material type = getWorld().getBlockAt(xx, yy, zz).getType(); - if (type == Material.PORTAL) { + if (type == material) { getWorld().getBlockAt(xx, yy, zz).setType(Material.AIR); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java index 5f33e8e2..784cec84 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java @@ -10,6 +10,7 @@ import java.io.File; import java.util.HashSet; import java.util.Set; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -225,8 +226,9 @@ public class GlobalProtections { if (data.contains(preString)) { Block block1 = world.getBlockAt(data.getInt(preString + "loc1.x"), data.getInt(preString + "loc1.y"), data.getInt(preString + "loc1.z")); Block block2 = world.getBlockAt(data.getInt(preString + "loc2.x"), data.getInt(preString + "loc2.y"), data.getInt(preString + "loc2.z")); - DPortal dPortal = new DPortal(id, block1, block2, true); - dPortal.create(); + Material material = Material.getMaterial(data.getString(preString + "material")); + DPortal dPortal = new DPortal(id, block1, block2, material != null ? material : Material.PORTAL, true); + dPortal.create(null); } } while (data.contains(preString)); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java index cc06ca6c..d639695a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -32,6 +32,7 @@ import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.task.RedstoneEventTask; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.DInstanceWorld; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -58,10 +59,6 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onPhysics(BlockPhysicsEvent event) { - if (event.getBlock().getType() != Material.PORTAL) { - return; - } - if (DPortal.getByBlock(event.getBlock()) != null) { event.setCancelled(true); } @@ -199,21 +196,13 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void onSpread(BlockSpreadEvent event) { - Block block = event.getBlock(); - // Block the Spread off Vines - if (block.getType() != Material.VINE) { - return; - } + Block block = event.getSource(); - // Check GameWorlds - DGameWorld gameWorld = DGameWorld.getByWorld(event.getBlock().getWorld()); - if (gameWorld != null) { + DInstanceWorld instance = plugin.getDWorlds().getInstanceByName(block.getWorld().getName()); + if (instance != null && block.getType() == Material.VINE) { event.setCancelled(true); - } - // Check EditWorlds - DEditWorld editWorld = DEditWorld.getByWorld(event.getBlock().getWorld()); - if (editWorld != null) { + } else if (DPortal.getByBlock(block) != null) { event.setCancelled(true); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 20fa1edd..22b90294 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -204,7 +204,7 @@ public class PlayerListener implements Listener { } else if (dPortal.getBlock2() == null) { dPortal.setBlock2(event.getClickedBlock()); dPortal.setActive(true); - dPortal.create(); + dPortal.create(dGlobalPlayer); MessageUtil.sendMessage(player, DMessages.PLAYER_PORTAL_CREATED.getMessage()); } event.setCancelled(true); From b0397cd0c0f942a8202ad27d883e7a5d9b862eaa Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 1 Aug 2016 20:20:17 +0200 Subject: [PATCH 19/57] #9: Fixed rotation bug --- .../io/github/dre2n/dungeonsxl/global/DPortal.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java index 82da5340..a2dcc8fb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -33,6 +33,8 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; +import org.bukkit.material.Directional; +import org.bukkit.material.MaterialData; /** * @author Frank Baumann, Daniel Saukel @@ -119,7 +121,6 @@ public class DPortal extends GlobalProtection { return; } - int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ(); int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ(); int xcount = 0, ycount = 0, zcount = 0; @@ -150,7 +151,12 @@ public class DPortal extends GlobalProtection { do { Material type = getWorld().getBlockAt(xx, yy, zz).getType(); if (!type.isSolid()) { - getWorld().getBlockAt(xx, yy, zz).setType(material, false); + Block block = getWorld().getBlockAt(xx, yy, zz); + block.setType(material, false); + if (player != null && material == Material.PORTAL) { + float yaw = player.getPlayer().getLocation().getYaw(); + block.setData((yaw >= -135 & yaw < -45 || yaw >= -315 & yaw < -225) ? (byte) 2 : 1, false); + } } zz = zz + zcount; From ca272df95a3a59d3f1ba127ba39b2cc643ea6254 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 1 Aug 2016 22:25:50 +0200 Subject: [PATCH 20/57] #9: Fix chat spam --- .../dre2n/dungeonsxl/global/DPortal.java | 2 -- .../dungeonsxl/listener/PlayerListener.java | 28 ++++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java index a2dcc8fb..a70adbb8 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -33,8 +33,6 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; -import org.bukkit.material.Directional; -import org.bukkit.material.MaterialData; /** * @author Frank Baumann, Daniel Saukel diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 22b90294..74fd7ff4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -702,25 +702,27 @@ public class PlayerListener implements Listener { @EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); + DLootInventory inventory = DLootInventory.getByPlayer(player); - - DPortal dPortal = DPortal.getByLocation(player.getEyeLocation()); - //TODO: Fix chat spam - if (dPortal != null) { - dPortal.teleport(player); - return; - } - - if (inventory == null) { - return; - } - - if (player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL + if (inventory != null && player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(-1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) { inventory.setInventoryView(player.openInventory(inventory.getInventory())); inventory.setTime(System.currentTimeMillis()); } + + DPortal dPortal = DPortal.getByLocation(player.getEyeLocation()); + if (dPortal == null) { + return; + } + + Block blockFrom = event.getFrom().getBlock(); + Block blockTo = event.getTo().getBlock(); + if (blockFrom.equals(blockTo)) { + return; + } + + dPortal.teleport(player); } } From 1c848d8690c27084845af6da98d29ea31609e0db Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 1 Aug 2016 22:30:10 +0200 Subject: [PATCH 21/57] Exclude map data folder --- core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 04f4da34..56e0111c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -64,7 +64,7 @@ public class DungeonsXL extends BRPlugin { private static DungeonsXL instance; - public static final String[] EXCLUDED_FILES = {"config.yml", "uid.dat", "DXLData.data"}; + public static final String[] EXCLUDED_FILES = {"config.yml", "uid.dat", "DXLData.data", "data"}; public static File BACKUPS; public static File LANGUAGES; public static File MAPS; From 7d19bb28d73113485a7b9763342edf6f54a582a5 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 1 Aug 2016 22:47:35 +0200 Subject: [PATCH 22/57] Fix dungeon portals teleporting players to the nether; resolves #119; resolves #124 --- .../github/dre2n/dungeonsxl/listener/PlayerListener.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 74fd7ff4..b5db8cb5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -49,6 +49,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -406,7 +407,12 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onPortal(PlayerPortalEvent event) { - if (DPortal.getByLocation(event.getFrom()) != null) { + Block block1 = event.getFrom().getBlock(); + Block block2 = block1.getRelative(BlockFace.WEST); + Block block3 = block1.getRelative(BlockFace.NORTH); + Block block4 = block1.getRelative(BlockFace.EAST); + Block block5 = block1.getRelative(BlockFace.SOUTH); + if (DPortal.getByBlock(block1) != null || DPortal.getByBlock(block2) != null || DPortal.getByBlock(block3) != null || DPortal.getByBlock(block4) != null || DPortal.getByBlock(block5) != null) { event.setCancelled(true); } } From d43234943be42ed0b60f50e25cd52fee5f154ae5 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 1 Aug 2016 23:12:35 +0200 Subject: [PATCH 23/57] Fix open door sign --- .../dre2n/dungeonsxl/sign/OpenDoorSign.java | 19 ++++++++++++++++++- .../dungeonsxl/world/block/LockedDoor.java | 4 +--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java index ddd1033b..602be5bf 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java @@ -33,6 +33,7 @@ public class OpenDoorSign extends DSign { private DSignType type = DSignTypeDefault.OPEN_DOOR; private LockedDoor door; + private boolean active = true; public OpenDoorSign(Sign sign, String[] lines, DGameWorld gameWorld) { super(sign, lines, gameWorld); @@ -54,6 +55,21 @@ public class OpenDoorSign extends DSign { this.door = door; } + /** + * @return if the sign is active + */ + public boolean isActive() { + return active; + } + + /** + * @param active + * toggle the sign active + */ + public void setActive(boolean active) { + this.active = active; + } + @Override public DSignType getType() { return type; @@ -85,8 +101,9 @@ public class OpenDoorSign extends DSign { @Override public void onTrigger() { - if (door != null) { + if (door != null && active) { door.open(); + active = false; } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java index 1db52238..547e95de 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java @@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.world.block; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.material.Door; /** * @author Daniel Saukel @@ -54,8 +53,7 @@ public class LockedDoor extends GameBlock implements MultiBlock { * Opens the door. */ public void open() { - ((Door) block.getState().getData()).setOpen(true); - block.getState().update(true); + block.setData((byte) (block.getData() + 4)); } } From 750db495d6fb83d238edbfdb1b73e2a305e61bbc Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 2 Aug 2016 20:15:03 +0200 Subject: [PATCH 24/57] Bedwars. close #128; close #127 --- README.md | 2 +- .../dre2n/dungeonsxl/announcer/Announcer.java | 2 +- .../dungeonsxl/command/LivesCommand.java | 9 +- .../dre2n/dungeonsxl/config/DMessages.java | 18 ++- .../dre2n/dungeonsxl/config/MainConfig.java | 52 ++++--- .../dre2n/dungeonsxl/config/WorldConfig.java | 4 + .../io/github/dre2n/dungeonsxl/game/Game.java | 41 +++-- .../dre2n/dungeonsxl/game/GameRules.java | 19 ++- .../dre2n/dungeonsxl/game/GameType.java | 11 ++ .../dungeonsxl/game/GameTypeDefault.java | 46 +++--- .../dungeonsxl/listener/PlayerListener.java | 50 +----- .../dre2n/dungeonsxl/player/DEditPlayer.java | 2 +- .../dre2n/dungeonsxl/player/DGamePlayer.java | 143 ++++++++++++++---- .../dungeonsxl/player/DGlobalPlayer.java | 7 + .../dre2n/dungeonsxl/player/DGroup.java | 85 +++++++++-- .../dre2n/dungeonsxl/sign/FlagSign.java | 2 +- .../dungeonsxl/sign/LivesModifierSign.java | 14 +- .../github/dre2n/dungeonsxl/util/DColor.java | 80 ++++++++++ .../dre2n/dungeonsxl/world/block/TeamBed.java | 3 +- .../dungeonsxl/world/block/TeamFlag.java | 7 +- .../dre2n/dungeonsxl/game/CustomGameType.java | 16 +- 21 files changed, 460 insertions(+), 153 deletions(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java diff --git a/README.md b/README.md index 6c3d27bd..60865bf5 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Maven automatically fetches all dependencies and builds DungeonsXL; just run _bu [BRCommons](https://github.com/DRE2N/BRCommons) is a util library for common tasks. DungeonsXL contains BRCommons 1.0.1. #### Caliburn API -[Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.2. +[Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.2.1. ### Java Make sure that your server uses Java 7 or higher. diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java index f867f275..576b41d9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -434,7 +434,7 @@ public class Announcer { boolean full = playerCount >= maxPlayersPerGroup; - ItemStack button = new ItemStack(Material.WOOL, playerCount, plugin.getMainConfig().getGroupColorPriority().get(groupCount)); + ItemStack button = new ItemStack(Material.WOOL, playerCount, plugin.getMainConfig().getGroupColorPriority().get(groupCount).getWoolData()); ItemMeta meta = button.getItemMeta(); meta.setDisplayName(name + (full ? ChatColor.DARK_RED : ChatColor.GREEN) + " [" + playerCount + "/" + maxPlayersPerGroup + "]"); meta.setLore(lore); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java index 74c323c1..aeacfd0f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LivesCommand.java @@ -21,6 +21,7 @@ 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.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPermissions; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -61,11 +62,15 @@ public class LivesCommand extends BRCommand { } DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + DGroup dGroup = dPlayer != null ? dPlayer.getDGroup() : DGroup.getByName(args[1]); if (dPlayer != null) { - MessageUtil.sendMessage(sender, DMessages.CMD_LIVES.getMessage(player.getName(), String.valueOf(dPlayer.getLives()))); + MessageUtil.sendMessage(sender, DMessages.CMD_LIVES_PLAYER.getMessage(dPlayer.getName(), String.valueOf(dPlayer.getLives() == -1 ? "UNLIMITED" : dPlayer.getLives()))); + + } else if (dGroup != null) { + MessageUtil.sendMessage(sender, DMessages.CMD_LIVES_GROUP.getMessage(dGroup.getName(), String.valueOf(dGroup.getLives() == -1 ? "UNLIMITED" : dPlayer.getLives()))); } else { - MessageUtil.sendMessage(sender, DMessages.ERROR_NOT_IN_DUNGEON.getMessage()); + MessageUtil.sendMessage(sender, DMessages.ERROR_NO_SUCH_PLAYER.getMessage(args[1])); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 70344bfd..ea2fdadc 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -41,7 +41,8 @@ public enum DMessages implements Messages { CMD_INVITE_SUCCESS("Cmd_Invite_Success", "&6Player &4&v1&6 was successfully invited to edit the map &4&v2&6."), CMD_KICK_SUCCESS("Cmd_Kick_Success", "&6Successfully attempted to kick &4&v1&6."), CMD_LEAVE_SUCCESS("Cmd_Leave_Success", "&6You have successfully left your group!"), - CMD_LIVES("Cmd_Lives", "&4&v1&6 has &4&v2 &6lives left."), + CMD_LIVES_GROUP("Cmd_Lives_Group", "&4&v1 &6have &4&v2 &6lives left."), + CMD_LIVES_PLAYER("Cmd_Lives_Player", "&4&v1 &6has &4&v2 &6lives left."), CMD_MAIN_WELCOME("Cmd_Main_Welcome", "&7Welcome to &4Dungeons&fXL"), CMD_MAIN_LOADED("Cmd_Main_Loaded", "&eMaps: &o[&v1] &eDungeons: &o[&v2] &eLoaded: &o[&v3] &ePlayers: &o[&v4]"), CMD_MAIN_COMPATIBILITY("Cmd_Main_Compatibility", "&eInternals: &o[&v1] &eVault: &o[&v2] &eItemsXL: &o[&v3]"), @@ -128,12 +129,21 @@ public enum DMessages implements Messages { HELP_CMD_TEST("Help_Cmd_Test", "/dxl test - Starts the game in test mode"), HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite [player] [dungeon] - Uninvite a player to edit a dungeon"), GROUP_BED_DESTROYED("Group_BedDestroyed", "&6The bed of the group &4&v1 &6has been destroyed by &4&v2&6!"), + GROUP_CONGRATS("Group_Congrats", "&6Congratulations!"), + GROUP_CONGRATS_SUB("Group_CongratsSub", "&l&4Your group &v1 &4won the match!"), GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"), + GROUP_DEATH("Group_Death", "&4&v1 &6died. &4&v2 have &4&v3 &6lives left."), + GROUP_DEATH_KICK("Group_DeathKick", "&2&v1 &6was kicked because &4&v2 &6have no lives left."), GROUP_DISBANDED("Group_Disbanded", "&4&v1&6 disbanded the group &4&v2&6."), GROUP_FLAG_CAPTURED("Group_FlagCaptured", "&4&v1&6 has captured the flag of the group &4&v2&6!"), + GROUP_FLAG_LOST("Group_FlagLost", "&4&v1&6 died and lost &4&v2&6's flag."), GROUP_FLAG_STEALING("Group_FlagStealing", "&4&v1&6 is stealing the flag of the group &4&v2&6!"), GROUP_INVITED_PLAYER("Group_InvitedPlayer", "&4&v1&6 invited the player &4&v2&6 to the group &4&v3&6."), GROUP_JOINED_GAME("Group_JoinedGame", "&6Your group successfully joined the game."), + GROUP_KILLED("Group_Killed", "&4&v1 &6was killed by &4&v2&6. &4&v3&6 have &4&v4 &6lives left."), + GROUP_KILLED_KICK("Group_KilledKick", "&4&v1&6 was killed by &4&v2&6. &4&v3 have no lives left."), + GROUP_LIVES_ADDED("Group_LivesAdded", "&6Your group received a bonus of &4&v1&6 lives."), + GROUP_LIVES_REMOVED("Group_LivesRemoved", "&6Your group lost &4&v1&6 lives!"), GROUP_UNINVITED_PLAYER("Group_UninvitedPlayer", "&4&v1&6 took back the invitation for &4&v2&6 to the group &4&v3&6."), GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."), GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"), @@ -151,13 +161,15 @@ public enum DMessages implements Messages { LOG_WORLD_GENERATION_FINISHED("Log_WorldGenerationFinished", "&6World generation finished!"), PLAYER_BLOCK_INFO("Player_BlockInfo", "&6Block ID: &2&v1"), PLAYER_CHECKPOINT_REACHED("Player_CheckpointReached", "&6Checkpoint reached!"), - PLAYER_DEATH("Player_Death", "&6You died, lives left: &2&v1"), - PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1&6 died and lost his last life."), + PLAYER_DEATH("Player_Death", "&4&v1 &6died and has &4&v2 &6lives left."), + PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1 &6lost his last life and was kicked."), PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the dungeon!"), PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."), PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."), PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"), PLAYER_KICKED("Player_Kicked", "&4You have been kicked out of the group &6&v1&4."), + PLAYER_KILLED("Player_Killed", "&4&v1 &6was killed by &4&v2 &6and has &4&v3 &6lives left."), + PLAYER_KILLED_KICK("Player_KilledKick", "&4&v1&6 was killed by &4&v2 &6and lost his last life."), PLAYER_LEAVE_GROUP("Player_LeaveGroup", "&6You have successfully left your group!"), PLAYER_LEFT_GROUP("Player_LeftGroup", "&6Player &4&v1&6 has left the Group!"), PLAYER_LIVES_ADDED("Player_LivesAdded", "&6Received a bonus of &4&v1&6 lives."), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index 320d4f3f..f4ecd5ca 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -21,6 +21,8 @@ import io.github.dre2n.commons.compatibility.Internals; import io.github.dre2n.commons.config.BRConfig; import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.util.DColor; +import static io.github.dre2n.dungeonsxl.util.DColor.*; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -41,7 +43,7 @@ public class MainConfig extends BRConfig { NEVER } - public static final int CONFIG_VERSION = 11; + public static final int CONFIG_VERSION = 12; private String language = "english"; private boolean enableEconomy = false; @@ -53,15 +55,22 @@ public class MainConfig extends BRConfig { private String tutorialEndGroup = "player"; /* Announcers */ - private List groupColorPriority = new ArrayList<>(Arrays.asList( - (short) 11, - (short) 14, - (short) 4, - (short) 5, - (short) 10, - (short) 1, - (short) 0, - (short) 15 + private List groupColorPriority = new ArrayList<>(Arrays.asList( + DARK_BLUE, + LIGHT_RED, + YELLOW, + LIGHT_GREEN, + PURPLE, + ORANGE, + WHITE, + BLACK, + LIGHT_BLUE, + DARK_GREEN, + DARK_RED, + LIGHT_GRAY, + CYAN, + MAGENTA, + DARK_GRAY )); private double announcementInterval = 30; @@ -189,16 +198,16 @@ public class MainConfig extends BRConfig { /** * @return the group colors */ - public List getGroupColorPriority() { + public List getGroupColorPriority() { return groupColorPriority; } /** - * @param dataValues - * wool data values + * @param colors + * the colors to set */ - public void setGroupColorPriority(List dataValues) { - groupColorPriority = dataValues; + public void setGroupColorPriority(List colors) { + groupColorPriority = colors; } /** @@ -392,7 +401,11 @@ public class MainConfig extends BRConfig { } if (!config.contains("groupColorPriority")) { - config.set("groupColorPriority", groupColorPriority); + ArrayList strings = new ArrayList<>(); + for (DColor color : groupColorPriority) { + strings.add(color.toString()); + } + config.set("groupColorPriority", strings); } if (!config.contains("announcementInterval")) { @@ -479,7 +492,12 @@ public class MainConfig extends BRConfig { } if (config.contains("groupColorPriority")) { - groupColorPriority = config.getShortList("groupColorPriority"); + groupColorPriority.clear(); + for (String color : config.getStringList("groupColorPriority")) { + if (EnumUtil.isValidEnum(DColor.class, color)) { + groupColorPriority.add(DColor.valueOf(color)); + } + } } if (config.contains("announcementInterval")) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index d1f7b65c..a4cce5be 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -190,6 +190,10 @@ public class WorldConfig extends GameRules { initialLives = configFile.getInt("initialLives"); } + if (configFile.contains("initialGroupLives")) { + initialGroupLives = configFile.getInt("initialGroupLives"); + } + /* Lobby */ if (configFile.contains("isLobbyDisabled")) { lobbyDisabled = configFile.getBoolean("isLobbyDisabled"); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index d8d2df6a..843635dc 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -57,33 +57,44 @@ public class Game { private Map waveKills = new HashMap<>(); public Game(DGroup dGroup) { - dGroups.add(dGroup); - started = false; - fetchRules(); - plugin.getGames().add(this); + + started = false; + + dGroups.add(dGroup); + dGroup.setGameWorld(world); + fetchRules(); + dGroup.setInitialLives(rules.getInitialGroupLives()); + dGroup.setLives(rules.getInitialGroupLives()); } public Game(DGroup dGroup, DGameWorld world) { - dGroups.add(dGroup); + plugin.getGames().add(this); + started = false; this.world = world; - fetchRules(); - plugin.getGames().add(this); + dGroups.add(dGroup); + dGroup.setGameWorld(world); + fetchRules(); + dGroup.setInitialLives(rules.getInitialGroupLives()); + dGroup.setLives(rules.getInitialGroupLives()); } public Game(DGroup dGroup, String worldName) { plugin.getGames().add(this); - dGroups.add(dGroup); started = false; DResourceWorld resource = plugin.getDWorlds().getResourceByName(worldName); if (resource != null) { world = resource.instantiateAsGameWorld(); } + + dGroups.add(dGroup); dGroup.setGameWorld(world); fetchRules(); + dGroup.setInitialLives(rules.getInitialGroupLives()); + dGroup.setLives(rules.getInitialGroupLives()); } public Game(DGroup dGroup, GameType type, DGameWorld world) { @@ -91,13 +102,19 @@ public class Game { } public Game(List dGroups, GameType type, DGameWorld world) { + plugin.getGames().add(this); + this.dGroups = dGroups; this.type = type; this.world = world; this.started = true; - fetchRules(); - plugin.getGames().add(this); + for (DGroup dGroup : dGroups) { + dGroup.setGameWorld(world); + fetchRules(); + dGroup.setInitialLives(rules.getInitialGroupLives()); + dGroup.setLives(rules.getInitialGroupLives()); + } } /** @@ -113,6 +130,10 @@ public class Game { */ public void addDGroup(DGroup dGroup) { dGroups.add(dGroup); + + dGroup.setGameWorld(world); + dGroup.setInitialLives(rules.getInitialGroupLives()); + dGroup.setLives(rules.getInitialGroupLives()); } /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index a211ad58..96151d7f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -54,7 +54,8 @@ public class GameRules { /* Fighting */ DEFAULT_VALUES.playerVersusPlayer = false; DEFAULT_VALUES.friendlyFire = false; - DEFAULT_VALUES.initialLives = 3; + DEFAULT_VALUES.initialLives = -1; + DEFAULT_VALUES.initialGroupLives = -1; /* Timer */ DEFAULT_VALUES.timeLastPlayed = 0; @@ -98,6 +99,7 @@ public class GameRules { protected Boolean playerVersusPlayer; protected Boolean friendlyFire; protected Integer initialLives; + protected Integer initialGroupLives; /* Timer */ protected Integer timeLastPlayed; @@ -223,6 +225,13 @@ public class GameRules { return initialLives; } + /** + * @return the initial amount of group lives + */ + public int getInitialGroupLives() { + return initialGroupLives; + } + // Timer /** * @return the timeLastPlayed @@ -411,6 +420,10 @@ public class GameRules { if (gameMode == null) { gameMode = defaultValues.getGameMode(); } + + if (initialLives == null) { + initialLives = defaultValues.hasLives() ? null : -1; + } } /** @@ -477,6 +490,10 @@ public class GameRules { initialLives = defaultValues.initialLives; } + if (initialGroupLives == null) { + initialGroupLives = defaultValues.initialGroupLives; + } + /* Timer */ if (timeLastPlayed == null) { timeLastPlayed = defaultValues.timeLastPlayed; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java index cef39160..3063b8b0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java @@ -23,6 +23,17 @@ import org.bukkit.GameMode; */ public interface GameType { + /** + * @return if the game ends when one group is left + */ + public Boolean isLastManStanding(); + + /** + * @param lastManStanding + * set if the game ends when one group is left + */ + public void setLastManStanding(Boolean lastManStanding); + /** * @return the displayName */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java index 2777cddb..74ff6f28 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java @@ -23,26 +23,27 @@ import org.bukkit.GameMode; */ public enum GameTypeDefault implements GameType { - ADVENTURE("Adventure", "Adventure", false, false, false, true, false, true, true, true, GameMode.ADVENTURE, true), - ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, false, true, true, true, true, true, GameMode.ADVENTURE, true), - APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), - APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), - APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", true, true, true, true, true, false, false, false, GameMode.SURVIVAL, true), - BEDWARS("Bedwars", "Bedwars", true, false, false, false, false, false, true, true, GameMode.SURVIVAL, true), - PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), - PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), - PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, false, true, true, true, false, false, false, GameMode.SURVIVAL, true), - PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), - PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), - QUEST("Quest", "Quest", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), - QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), - TEST("Test", "Test", false, false, false, false, true, true, true, true, GameMode.SURVIVAL, false), - TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, false), - DEFAULT("Default", "Default", false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + ADVENTURE("Adventure", "Adventure", false, false, false, false, true, false, true, true, true, GameMode.ADVENTURE, true), + ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, false, false, true, true, true, true, true, GameMode.ADVENTURE, true), + APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), + APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", false, true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), + APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", false, true, true, true, true, true, false, false, false, GameMode.SURVIVAL, true), + BEDWARS("Bedwars", "Bedwars", true, true, false, false, false, false, false, true, true, GameMode.SURVIVAL, false), + PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", true, false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), + PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), + PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, false, false, true, true, true, false, false, false, GameMode.SURVIVAL, true), + PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), + PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), + QUEST("Quest", "Quest", false, false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), + TEST("Test", "Test", false, false, false, false, false, true, true, true, true, GameMode.SURVIVAL, false), + TUTORIAL("Tutorial", "Tutorial", false, false, false, false, true, false, false, false, false, GameMode.SURVIVAL, false), + DEFAULT("Default", "Default", false, false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), CUSTOM("Custom", "Custom"); private String displayName; private String signName; + private Boolean lastManStanding; private Boolean playerVersusPlayer; private Boolean friendlyFire; private Boolean mobWaves; @@ -54,10 +55,11 @@ public enum GameTypeDefault implements GameType { private GameMode gameMode; private Boolean lives; - GameTypeDefault(String displayName, String signName, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, + GameTypeDefault(String displayName, String signName, Boolean lastManStanding, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, Boolean showTime, Boolean breakBlocks, Boolean breakPlacedBlocks, Boolean placeBlocks, GameMode gameMode, Boolean lives) { this.displayName = displayName; this.signName = signName; + this.lastManStanding = lastManStanding; this.playerVersusPlayer = playerVersusPlayer; this.friendlyFire = friendlyFire; this.mobWaves = mobWaves; @@ -75,6 +77,16 @@ public enum GameTypeDefault implements GameType { this.signName = signName; } + @Override + public Boolean isLastManStanding() { + return lastManStanding; + } + + @Override + public void setLastManStanding(Boolean lastManStanding) { + this.lastManStanding = lastManStanding; + } + @Override public String getDisplayName() { return displayName; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index b5db8cb5..f1e5f6b7 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -21,7 +21,6 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.MainConfig; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; -import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GameSign; @@ -87,54 +86,11 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onDeath(PlayerDeathEvent event) { Player player = event.getEntity(); - - DGameWorld gameWorld = DGameWorld.getByWorld(player.getLocation().getWorld()); - if (gameWorld == null) { - return; - } - - Game game = Game.getByGameWorld(gameWorld); - if (game == null) { - return; - } - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); if (dPlayer == null) { return; } - - DGamePlayerDeathEvent dPlayerDeathEvent = new DGamePlayerDeathEvent(dPlayer, event, 1); - plugin.getServer().getPluginManager().callEvent(dPlayerDeathEvent); - - if (dPlayerDeathEvent.isCancelled()) { - return; - } - - if (gameWorld.getGame() != null) { - if (!gameWorld.getGame().getType().hasLives()) { - return; - } - } else { - return; - } - - if (dPlayer.getLives() != -1) { - dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives()); - MessageUtil.sendMessage(player, DMessages.PLAYER_DEATH.getMessage(String.valueOf(dPlayer.getLives()))); - - if (game.getRules().getKeepInventoryOnDeath()) { - dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents()); - dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents()); - // Delete all drops - for (ItemStack item : event.getDrops()) { - item.setType(Material.AIR); - } - } - } - - if (dPlayer.getLives() == 0 && dPlayer.isReady()) { - dPlayer.kill(); - } + dPlayer.onDeath(event); } @EventHandler(priority = EventPriority.HIGHEST) @@ -470,11 +426,11 @@ public class PlayerListener implements Listener { ((DGamePlayer) dPlayer).leave(); } else if (timeUntilKickOfflinePlayer > 0) { - dGroup.sendMessage(DMessages.PLAYER_OFFLINE.getMessage(dPlayer.getPlayer().getName(), String.valueOf(timeUntilKickOfflinePlayer)), player); + dGroup.sendMessage(DMessages.PLAYER_OFFLINE.getMessage(dPlayer.getName(), String.valueOf(timeUntilKickOfflinePlayer)), player); ((DGamePlayer) dPlayer).setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000); } else { - dGroup.sendMessage(DMessages.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getPlayer().getName()), player); + dGroup.sendMessage(DMessages.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getName()), player); } } else if (dPlayer instanceof DEditPlayer) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java index 9d00086b..ea411981 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java @@ -207,7 +207,7 @@ public class DEditPlayer extends DInstancePlayer { public static DEditPlayer getByName(String name) { for (DEditPlayer dPlayer : plugin.getDPlayers().getDEditPlayers()) { - if (dPlayer.getPlayer().getName().equalsIgnoreCase(name)) { + if (dPlayer.getName().equalsIgnoreCase(name)) { return dPlayer; } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 2b989c40..dbddbdbd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -26,6 +26,7 @@ import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupRewardEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent; import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerFinishEvent; import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent; import io.github.dre2n.dungeonsxl.game.Game; @@ -39,6 +40,7 @@ import io.github.dre2n.dungeonsxl.task.CreateDInstancePlayerTask; import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DResourceWorld; +import io.github.dre2n.dungeonsxl.world.block.TeamFlag; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -51,6 +53,7 @@ import org.bukkit.entity.Damageable; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Wolf; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; @@ -62,6 +65,8 @@ import org.bukkit.potion.PotionEffect; public class DGamePlayer extends DInstancePlayer { // Variables + private DGroup dGroup; + private boolean ready = false; private boolean finished = false; @@ -131,6 +136,25 @@ public class DGamePlayer extends DInstancePlayer { } /* Getters and setters */ + @Override + public String getName() { + String name = player.getName(); + if (getDGroup() != null && dGroup.getDColor() != null) { + name = getDGroup().getDColor().getChatColor() + name; + } + return name; + } + + /** + * @return the DGroup of this player + */ + public DGroup getDGroup() { + if (dGroup == null) { + dGroup = DGroup.getByPlayer(player); + } + return dGroup; + } + /** * @param player * the player to set @@ -143,8 +167,7 @@ public class DGamePlayer extends DInstancePlayer { * @return if the player is in test mode */ public boolean isInTestMode() { - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (dGroup == null) { + if (getDGroup() == null) { return false; } @@ -386,6 +409,10 @@ public class DGamePlayer extends DInstancePlayer { * the group whose flag is stolen */ public void setRobbedGroup(DGroup dGroup) { + if (dGroup != null) { + player.getInventory().getHelmet().setType(Material.WOOL); + } + stealing = dGroup; } @@ -400,7 +427,6 @@ public class DGamePlayer extends DInstancePlayer { * if messages should be sent */ public void leave(boolean message) { - plugin.debug.start("DGamePlayer#leave"); GameRules rules = Game.getByWorld(getWorld()).getRules(); delete(); @@ -417,8 +443,7 @@ public class DGamePlayer extends DInstancePlayer { } } - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (dGroup != null) { + if (getDGroup() != null) { dGroup.removePlayer(getPlayer(), message); } @@ -431,7 +456,7 @@ public class DGamePlayer extends DInstancePlayer { reward.giveTo(getPlayer()); } - getData().logTimeLastPlayed(dGroup.getDungeon().getName()); + getData().logTimeLastPlayed(getDGroup().getDungeon().getName()); // Tutorial Permissions if (gameWorld.isTutorial() && plugin.getPermissionProvider() != null && plugin.getPermissionProvider().hasGroupSupport()) { @@ -449,7 +474,7 @@ public class DGamePlayer extends DInstancePlayer { } } - if (dGroup != null) { + if (getDGroup() != null) { if (!dGroup.isEmpty()) { if (dGroup.finishIfMembersFinished()) { return; @@ -483,7 +508,6 @@ public class DGamePlayer extends DInstancePlayer { // ...*flies away* } } - plugin.debug.end("DGamePlayer#leave", true); } public void kill() { @@ -491,7 +515,13 @@ public class DGamePlayer extends DInstancePlayer { plugin.getServer().getPluginManager().callEvent(dPlayerKickEvent); if (!dPlayerKickEvent.isCancelled()) { - MessageUtil.broadcastMessage(DMessages.PLAYER_DEATH_KICK.getMessage(player.getName())); + DGameWorld gameWorld = getDGroup().getGameWorld(); + if (lives != -1) { + gameWorld.sendMessage(DMessages.PLAYER_DEATH_KICK.getMessage(getName())); + } else if (getDGroup().getLives() != -1) { + gameWorld.sendMessage(DMessages.GROUP_DEATH_KICK.getMessage(getName(), dGroup.getName())); + } + GameRules rules = Game.getByPlayer(player).getRules(); leave(); if (rules.getKeepInventoryOnEscape() && rules.getKeepInventoryOnDeath()) { @@ -602,9 +632,7 @@ public class DGamePlayer extends DInstancePlayer { } public void ready(GameType gameType) { - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - - if (dGroup == null) { + if (getDGroup() == null) { return; } @@ -635,12 +663,10 @@ public class DGamePlayer extends DInstancePlayer { } public void respawn() { - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - Location respawn = checkpoint; if (respawn == null) { - respawn = dGroup.getGameWorld().getStartLocation(dGroup); + respawn = getDGroup().getGameWorld().getStartLocation(dGroup); } if (respawn == null) { @@ -669,18 +695,14 @@ public class DGamePlayer extends DInstancePlayer { * the name of the next floor */ public void finishFloor(DResourceWorld specifiedFloor) { - plugin.debug.start("DGamePlayer#finishFloor"); MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_FINISHED_DUNGEON.getMessage()); finished = true; - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (dGroup == null) { - plugin.debug.end("DGamePlayer#finishFloor", true); + if (getDGroup() == null) { return; } if (!dGroup.isPlaying()) { - plugin.debug.end("DGamePlayer#finishFloor", true); return; } @@ -764,20 +786,16 @@ public class DGamePlayer extends DInstancePlayer { * if messages should be sent */ public void finish(boolean message) { - plugin.debug.start("DGamePlayer#finish"); if (message) { MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_FINISHED_DUNGEON.getMessage()); } finished = true; - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (dGroup == null) { - plugin.debug.end("DGamePlayer#finish", true); + if (getDGroup() == null) { return; } if (!dGroup.isPlaying()) { - plugin.debug.end("DGamePlayer#finish", true); return; } @@ -801,12 +819,10 @@ public class DGamePlayer extends DInstancePlayer { if (dPlayerFinishEvent.isCancelled()) { finished = false; - plugin.debug.end("DGamePlayer#finish", true); return; } if (hasToWait) { - plugin.debug.end("DGamePlayer#finish", true); return; } @@ -847,6 +863,72 @@ public class DGamePlayer extends DInstancePlayer { } } + public void onDeath(PlayerDeathEvent event) { + DGameWorld gameWorld = DGameWorld.getByWorld(player.getLocation().getWorld()); + if (gameWorld == null) { + return; + } + + Game game = Game.getByGameWorld(gameWorld); + if (game == null) { + return; + } + + DGamePlayerDeathEvent dPlayerDeathEvent = new DGamePlayerDeathEvent(this, event, 1); + plugin.getServer().getPluginManager().callEvent(dPlayerDeathEvent); + + if (dPlayerDeathEvent.isCancelled()) { + return; + } + + if (lives != -1) { + lives = lives - dPlayerDeathEvent.getLostLives(); + + DGamePlayer killer = DGamePlayer.getByPlayer(player.getKiller()); + if (killer != null) { + gameWorld.sendMessage(DMessages.PLAYER_KILLED.getMessage(getName(), killer.getName(), String.valueOf(lives))); + } else { + gameWorld.sendMessage(DMessages.PLAYER_DEATH.getMessage(getName(), String.valueOf(lives))); + } + + if (game.getRules().getKeepInventoryOnDeath()) { + setRespawnInventory(event.getEntity().getInventory().getContents()); + setRespawnArmor(event.getEntity().getInventory().getArmorContents()); + // Delete all drops + for (ItemStack item : event.getDrops()) { + item.setType(Material.AIR); + } + } + + } else if (getDGroup() != null && dGroup.getLives() != -1) { + dGroup.setLives(dGroup.getLives() - 1); + MessageUtil.broadcastMessage(DMessages.GROUP_DEATH.getMessage(player.getName(), String.valueOf(lives))); + } + + if (isStealing()) { + for (TeamFlag teamFlag : gameWorld.getTeamFlags()) { + if (teamFlag.getOwner().equals(stealing)) { + teamFlag.reset(); + gameWorld.sendMessage(DMessages.GROUP_FLAG_LOST.getMessage(player.getName(), stealing.getName())); + stealing = null; + } + } + } + + if (lives == 0 && ready) { + kill(); + } + + GameType gameType = game.getType(); + if (gameType != null && gameType != GameTypeDefault.CUSTOM) { + if (gameType.isLastManStanding()) { + if (game.getDGroups().size() == 1) { + game.getDGroups().get(0).winGame(); + } + } + } + } + @Override public void update(boolean updateSecond) { boolean locationValid = true; @@ -864,12 +946,10 @@ public class DGamePlayer extends DInstancePlayer { locationValid = false; if (gameWorld != null) { - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - teleportLocation = getCheckpoint(); if (teleportLocation == null) { - teleportLocation = dGroup.getGameWorld().getStartLocation(dGroup); + teleportLocation = getDGroup().getGameWorld().getStartLocation(getDGroup()); } // Don't forget Doge! @@ -959,10 +1039,11 @@ public class DGamePlayer extends DInstancePlayer { public static DGamePlayer getByName(String name) { for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) { - if (dPlayer.getPlayer().getName().equalsIgnoreCase(name)) { + if (dPlayer.getPlayer().getName().equalsIgnoreCase(name) || dPlayer.getName().equalsIgnoreCase(name)) { return dPlayer; } } + return null; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index 0e164d46..a69b9507 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -79,6 +79,13 @@ public class DGlobalPlayer { } /* Getters and setters */ + /** + * @return the player's name + */ + public String getName() { + return player.getName(); + } + /** * @return the Bukkit player */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 3c6a5444..52d201e2 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -31,6 +31,7 @@ import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; import io.github.dre2n.dungeonsxl.task.TimeIsRunningTask; +import io.github.dre2n.dungeonsxl.util.DColor; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.util.ArrayList; @@ -64,6 +65,9 @@ public class DGroup { private List rewards = new ArrayList<>(); private BukkitTask timeIsRunningTask; private DResourceWorld nextFloor; + private DColor color; + private int initialLives = -1; + private int lives = -1; public DGroup(Player player) { this("Group_" + plugin.getDGroups().size(), player); @@ -89,7 +93,6 @@ public class DGroup { } public DGroup(String name, Player captain, List players, String identifier, boolean multiFloor) { - plugin.debug.start("DGroup#init4"); plugin.getDGroups().add(this); this.name = name; @@ -120,14 +123,20 @@ public class DGroup { playing = false; floorCount = 0; - plugin.debug.end("DGroup#init4", true); } // Getters and setters /** - * @return the name + * @return the name; formatted */ public String getName() { + return (color != null ? color.getChatColor().toString() : new String()) + name; + } + + /** + * @return the name; not formatted + */ + public String getRawName() { return name; } @@ -558,6 +567,54 @@ public class DGroup { nextFloor = floor; } + /** + * @return the color that represents this group + */ + public DColor getDColor() { + if (color != null) { + return color; + } else { + return DColor.DEFAULT; + } + } + + /** + * @param color the group color to set + */ + public void setDColor(DColor color) { + this.color = color; + } + + /** + * @return the initial group lives + */ + public int getInitialLives() { + return initialLives; + } + + /** + * @param initialLives + * the initial group lives to set + */ + public void setInitialLives(int initialLives) { + this.initialLives = initialLives; + } + + /** + * @return the group lives + */ + public int getLives() { + return lives; + } + + /** + * @param lives + * the group lives to set + */ + public void setLives(int lives) { + this.lives = lives; + } + /* Actions */ /** * Remove the group from the List @@ -579,11 +636,13 @@ public class DGroup { } public void startGame(Game game) { - plugin.debug.start("DGroup#startGame"); if (game == null) { return; } game.fetchRules(); + GameRules rules = game.getRules(); + + color = plugin.getMainConfig().getGroupColorPriority().get(game.getDGroups().indexOf(this)); for (DGroup dGroup : game.getDGroups()) { if (dGroup == null) { @@ -603,7 +662,6 @@ public class DGroup { } if (!ready) { - plugin.debug.end("DGroup#startGame", true); return; } } @@ -612,7 +670,6 @@ public class DGroup { plugin.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { - plugin.debug.end("DGroup#startGame", true); return; } @@ -643,8 +700,6 @@ public class DGroup { } } - GameRules rules = game.getRules(); - for (Requirement requirement : rules.getRequirements()) { RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player); plugin.getServer().getPluginManager().callEvent(event); @@ -671,7 +726,17 @@ public class DGroup { GroupSign.updatePerGroup(this); nextFloor = null; - plugin.debug.end("DGroup#startGame", true); + initialLives = rules.getInitialGroupLives(); + lives = initialLives; + } + + public void winGame() { + String title = DMessages.GROUP_CONGRATS.getMessage(); + String subtitle = DMessages.GROUP_CONGRATS_SUB.getMessage(getName()); + for (DGamePlayer player : getDGamePlayers()) { + player.leave(false); + MessageUtil.sendTitleMessage(player.getPlayer(), title, subtitle, 20, 20, 100); + } } public boolean checkTime(Game game) { @@ -748,7 +813,7 @@ public class DGroup { /* Statics */ public static DGroup getByName(String name) { for (DGroup dGroup : plugin.getDGroups()) { - if (dGroup.getName().equals(name)) { + if (dGroup.getName().equalsIgnoreCase(name) || dGroup.getRawName().equalsIgnoreCase(name)) { return dGroup; } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java index 28220cee..3b830aa0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java @@ -49,7 +49,7 @@ public class FlagSign extends DSign { @Override public void onInit() { this.team = NumberUtil.parseInt(lines[1]); - getGameWorld().addGameBlock(new TeamFlag(getSign().getBlock(), team, getGame().getDGroups().get(team))); + getGameWorld().addGameBlock(new TeamFlag(getSign().getBlock(), getGame().getDGroups().get(team))); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java index 9772916d..85893417 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java @@ -93,9 +93,7 @@ public class LivesModifierSign extends DSign { break; case GROUP: - for (DGamePlayer dPlayer : DGroup.getByPlayer(player).getDGamePlayers()) { - modifyLives(dPlayer); - } + modifyLives(DGroup.getByPlayer(player)); break; case PLAYER: @@ -119,6 +117,16 @@ public class LivesModifierSign extends DSign { } } + public void modifyLives(DGroup dGroup) { + dGroup.setLives(dGroup.getLives() + lives); + if (lives > 0) { + dGroup.sendMessage(DMessages.GROUP_LIVES_ADDED.getMessage(String.valueOf(lives))); + + } else { + dGroup.sendMessage(DMessages.GROUP_LIVES_REMOVED.getMessage(String.valueOf(-1 * lives))); + } + } + @Override public DSignType getType() { return type; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java b/core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java new file mode 100644 index 00000000..b9aef48f --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.util; + +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; + +/** + * @author Daniel Saukel + */ +public enum DColor { + + BLACK(ChatColor.BLACK, DyeColor.BLACK), + DARK_GRAY(ChatColor.DARK_GRAY, DyeColor.GRAY), + LIGHT_GRAY(ChatColor.GRAY, DyeColor.SILVER), + WHITE(ChatColor.WHITE, DyeColor.WHITE), + DARK_GREEN(ChatColor.DARK_GREEN, DyeColor.GREEN), + LIGHT_GREEN(ChatColor.GREEN, DyeColor.LIME), + CYAN(ChatColor.DARK_AQUA, DyeColor.CYAN), + DARK_BLUE(ChatColor.DARK_BLUE, DyeColor.BLUE), + LIGHT_BLUE(ChatColor.AQUA, DyeColor.LIGHT_BLUE), + PURPLE(ChatColor.DARK_PURPLE, DyeColor.PURPLE), + MAGENTA(ChatColor.LIGHT_PURPLE, DyeColor.MAGENTA), + DARK_RED(ChatColor.DARK_RED, DyeColor.BROWN), + LIGHT_RED(ChatColor.RED, DyeColor.RED), + ORANGE(ChatColor.GOLD, DyeColor.ORANGE), + YELLOW(ChatColor.YELLOW, DyeColor.YELLOW), + DEFAULT(ChatColor.BLUE, DyeColor.PINK); + + private ChatColor chat; + private DyeColor dye; + + DColor(ChatColor chat, DyeColor dye) { + this.chat = chat; + this.dye = dye; + } + + /** + * @return the ChatColor + */ + public ChatColor getChatColor() { + return chat; + } + + /** + * @return the DyeColor + */ + public DyeColor getDyeColor() { + return dye; + } + + /** + * @return the RGB value + */ + public int getRGBColor() { + return dye.getColor().asRGB(); + } + + /** + * @return the wool DV + */ + public byte getWoolData() { + return dye.getWoolData(); + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java index d8d2866a..5e0c666b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java @@ -80,8 +80,9 @@ public class TeamBed extends TeamBlock implements MultiBlock { for (DGamePlayer player : owner.getDGamePlayers()) { player.setLives(1); } + owner.setLives(0); - owner.getGameWorld().sendMessage(DMessages.GROUP_BED_DESTROYED.getMessage(owner.getName(), breaker.getName())); + owner.getGameWorld().sendMessage(DMessages.GROUP_BED_DESTROYED.getMessage(owner.getName(), DGamePlayer.getByPlayer(breaker).getName())); Block block1 = event.getBlock(); if (((Bed) block1.getState().getData()).isHeadOfBed()) { Block block2 = getAttachedBlock(block1); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java index 37ebb4ad..a9e35ee4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java @@ -35,11 +35,8 @@ public class TeamFlag extends TeamBlock { public static final int WOOL = 35; - private byte teamId; - - public TeamFlag(Block block, int teamId, DGroup owner) { + public TeamFlag(Block block, DGroup owner) { super(block, owner); - this.teamId = plugin.getMainConfig().getGroupColorPriority().get(teamId).byteValue(); reset(); } @@ -48,7 +45,7 @@ public class TeamFlag extends TeamBlock { * Reset a team flag when the capturer dies. */ public void reset() { - block.setTypeIdAndData(WOOL, teamId, false); + block.setTypeIdAndData(WOOL, owner.getDColor().getWoolData(), false); } @Override diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java index 16a14714..9d990986 100644 --- a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java +++ b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java @@ -23,10 +23,11 @@ import org.bukkit.GameMode; */ public enum CustomGameType implements GameType { - GHOST("My awesome game type", "Identifier", false, false, false, false, false, false, false, false, GameMode.SPECTATOR, false); + GHOST("My awesome game type", "Identifier", false, false, false, false, false, false, false, false, false, GameMode.SPECTATOR, false); private String displayName; private String signName; + private Boolean lastManStanding; private Boolean playerVersusPlayer; private Boolean friendlyFire; private Boolean mobWaves; @@ -38,10 +39,11 @@ public enum CustomGameType implements GameType { private GameMode gameMode; private Boolean lives; - CustomGameType(String displayName, String signName, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, + CustomGameType(String displayName, String signName, Boolean lastManStanding, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, Boolean showTime, Boolean breakBlocks, Boolean breakPlacedBlocks, Boolean placeBlocks, GameMode gameMode, Boolean lives) { this.displayName = displayName; this.signName = signName; + this.lastManStanding = lastManStanding; this.playerVersusPlayer = playerVersusPlayer; this.friendlyFire = friendlyFire; this.mobWaves = mobWaves; @@ -74,6 +76,16 @@ public enum CustomGameType implements GameType { this.signName = signName; } + @Override + public Boolean isLastManStanding() { + return lastManStanding; + } + + @Override + public void setLastManStanding(Boolean lastManStanding) { + this.lastManStanding = lastManStanding; + } + @Override public Boolean isPlayerVersusPlayer() { return playerVersusPlayer; From 15ae32ae84700a764e93297900bd6053d310a5dd Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 2 Aug 2016 21:04:13 +0200 Subject: [PATCH 25/57] Fix NPE --- .../main/java/io/github/dre2n/dungeonsxl/game/GameRules.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 96151d7f..8868db05 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -422,7 +422,9 @@ public class GameRules { } if (initialLives == null) { - initialLives = defaultValues.hasLives() ? null : -1; + if (defaultValues.hasLives() != null) { + initialLives = defaultValues.hasLives() ? null : -1; + } } } From 6d543c22be7b8dc27e9cc5868422a6782bc9af49 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 2 Aug 2016 21:04:26 +0200 Subject: [PATCH 26/57] Add integration for BossShop; resolves #126 --- .../dre2n/dungeonsxl/sign/BossShopSign.java | 95 +++++++++++++++++++ .../dungeonsxl/sign/DSignTypeDefault.java | 1 + pom.xml | 6 ++ 3 files changed, 102 insertions(+) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java new file mode 100644 index 00000000..d4dc95e4 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; +import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import org.black_ixx.bossshop.BossShop; +import org.black_ixx.bossshop.core.BSShop; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Daniel Saukel + */ +public class BossShopSign extends DSign { + + BossShop bossShop = (BossShop) Bukkit.getPluginManager().getPlugin("BossShop"); + + private DSignType type = DSignTypeDefault.BOSS_SHOP; + + public BossShopSign(Sign sign, String[] lines, DGameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + @Override + public boolean check() { + return true; + } + + @Override + public void onInit() { + if (bossShop.getAPI().getShop(lines[1]) == null) { + markAsErroneous(); + return; + } + + if (!getTriggers().isEmpty()) { + getSign().getBlock().setType(Material.AIR); + return; + } + + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + if (trigger != null) { + trigger.addListener(this); + addTrigger(trigger); + } + + getSign().setLine(0, ChatColor.DARK_BLUE + "############"); + getSign().setLine(1, ChatColor.GREEN + lines[1]); + getSign().setLine(2, ChatColor.GREEN + lines[2]); + getSign().setLine(3, ChatColor.DARK_BLUE + "############"); + getSign().update(); + } + + @Override + public boolean onPlayerTrigger(Player player) { + openShop(player, lines[1]); + return true; + } + + @Override + public DSignType getType() { + return type; + } + + public void openShop(Player player, String shopName) { + BSShop shop = bossShop.getAPI().getShop(shopName); + if (shop != null) { + bossShop.getAPI().openShop(player, shop); + } else { + MessageUtil.sendMessage(player, ChatColor.RED + "Shop " + shopName + " not found..."); + } + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index f1c5f0ba..4690b7ea 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -25,6 +25,7 @@ public enum DSignTypeDefault implements DSignType { BED("Bed", "bed", false, false, BedSign.class), BLOCK("Block", "block", false, true, BlockSign.class), + BOSS_SHOP("BossShop", "bossshop", false, true, BossShopSign.class), CHECKPOINT("Checkpoint", "checkpoint", false, false, CheckpointSign.class), CHEST("Chest", "chest", false, false, ChestSign.class), CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, false, ChunkUpdaterSign.class), diff --git a/pom.xml b/pom.xml index bff956df..6b9b62e3 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,12 @@ BetonQuest 1.8.5 + + org.black_ixx + BossShop + 2.6.9 + provided + From 7abca6543b5af31e13d6209471e1482155a5bb57 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 2 Aug 2016 23:03:24 +0200 Subject: [PATCH 27/57] /dxl enter: Allow player names instead of group names --- .../io/github/dre2n/dungeonsxl/command/EnterCommand.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java index d80d6043..c03052f9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java @@ -24,6 +24,7 @@ import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPermissions; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -51,6 +52,13 @@ public class EnterCommand extends BRCommand { DGroup joining = args.length == 3 ? DGroup.getByName(args[1]) : DGroup.getByPlayer(captain); DGroup target = DGroup.getByName(targetName); + if (target == null) { + Player targetPlayer = Bukkit.getPlayer(targetName); + if (targetPlayer != null) { + target = DGroup.getByPlayer(targetPlayer); + } + } + if (target == null) { MessageUtil.sendMessage(sender, DMessages.ERROR_NO_SUCH_GROUP.getMessage(targetName)); return; From 1a7dbfd434d06b28422b973d42cecb585177d580 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 2 Aug 2016 23:03:34 +0200 Subject: [PATCH 28/57] /dxl group show: Allow player names instead of group names --- .../io/github/dre2n/dungeonsxl/command/GroupCommand.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java index 35a687c8..1fd00b8c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java @@ -26,6 +26,7 @@ import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPermissions; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -99,7 +100,12 @@ public class GroupCommand extends BRCommand { return; } else if (args[1].equalsIgnoreCase("show") && DPermissions.hasPermission(sender, DPermissions.GROUP_ADMIN)) { - showGroup(DGroup.getByName(args[2])); + DGroup group = DGroup.getByName(args[2]); + Player player = Bukkit.getPlayer(args[2]); + if (group == null && player != null) { + group = DGroup.getByPlayer(player); + } + showGroup(group); return; } } From 11f20b4656fee3dcfbcec69439d23d3d2dc829d7 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 2 Aug 2016 23:58:22 +0200 Subject: [PATCH 29/57] Add /dxl rewards command --- .../dre2n/dungeonsxl/command/DCommands.java | 2 + .../dungeonsxl/command/RewardsCommand.java | 66 +++++++++++++++++++ .../dre2n/dungeonsxl/config/DMessages.java | 3 + .../dungeonsxl/player/DGlobalPlayer.java | 24 +++++++ .../dre2n/dungeonsxl/player/DPermissions.java | 1 + .../dre2n/dungeonsxl/reward/ItemReward.java | 11 +++- 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/command/RewardsCommand.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java index 471990c8..c1d97e11 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java @@ -48,6 +48,7 @@ public class DCommands extends BRCommands { public static PlayCommand PLAY = new PlayCommand(); public static PortalCommand PORTAL = new PortalCommand(); public static ReloadCommand RELOAD = new ReloadCommand(); + public static RewardsCommand REWARDS = new RewardsCommand(); public static SaveCommand SAVE = new SaveCommand(); public static StatusCommand STATUS = new StatusCommand(); public static TestCommand TEST = new TestCommand(); @@ -77,6 +78,7 @@ public class DCommands extends BRCommands { PLAY, PORTAL, RELOAD, + REWARDS, SAVE, STATUS, TEST, diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/RewardsCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/RewardsCommand.java new file mode 100644 index 00000000..8bbca2b3 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/RewardsCommand.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.command; + +import io.github.dre2n.commons.command.BRCommand; +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.player.DGlobalPlayer; +import io.github.dre2n.dungeonsxl.player.DPermissions; +import io.github.dre2n.dungeonsxl.reward.DLootInventory; +import java.util.List; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +/** + * @author Daniel Saukel + */ +public class RewardsCommand extends BRCommand { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + public RewardsCommand() { + setCommand("rewards"); + setMinArgs(0); + setMaxArgs(0); + setHelp(DMessages.HELP_CMD_REWARDS.getMessage()); + setPermission(DPermissions.REWARDS.getNode()); + setPlayerCommand(true); + } + + @Override + public void onExecute(String[] args, CommandSender sender) { + Player player = (Player) sender; + DGlobalPlayer dGlobalPlayer = plugin.getDPlayers().getByPlayer(player); + + if (!dGlobalPlayer.hasRewardItemsLeft()) { + MessageUtil.sendMessage(player, DMessages.ERROR_NO_REWARDS_LEFT.getMessage()); + return; + } + + List rewardItems = dGlobalPlayer.getRewardItems(); + List rewards = rewardItems.subList(0, rewardItems.size() > 54 ? 53 : rewardItems.size()); + new DLootInventory(player, rewards.toArray(new ItemStack[54])); + rewardItems.removeAll(rewards); + if (rewardItems.isEmpty()) { + dGlobalPlayer.setRewardItems(null); + } + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index ea2fdadc..410340e2 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -78,6 +78,7 @@ public enum DMessages implements Messages { ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You have no permission to do this!"), ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"), ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"), + ERROR_NO_REWARDS_LEFT("Error_NoRewardsLeft", "&4You do not have any item rewards left."), ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"), ERROR_NO_SUCH_MAP("Error_NoSuchMap", "&4The world &6&v1&4 does not exist!"), ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"), @@ -92,6 +93,7 @@ public enum DMessages implements Messages { ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"), ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"), ERROR_TOO_MANY_INSTANCES("Error_TooManyInstances", "&4There are currently too many maps instantiated. Try it again in a few minutes!"), + ERROR_TOO_MANY_REWARDS("Error_TooManyRewards", "&6You won too many rewards to show all of them in one inventory. Use &4/dxl rewards &6to receive the other ones."), ERROR_TOO_MANY_TUTORIALS("Error_TooManyTutorials", "&4There are currently too many tutorials running. Try it again in a few minutes!"), ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"), HELP_CMD_BREAK("Help_Cmd_Break", "/dxl break - Break a block protected by DungeonsXL"), @@ -123,6 +125,7 @@ public enum DMessages implements Messages { HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play ([dungeon|map]) [name] - Allows the player to play a dungeon without a portal"), HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal ([material=portal])- Creates a portal that leads into a dungeon"), HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"), + HELP_CMD_REWARDS("Help_Cmd_Rewards", "/dxl rewards - Gives all left item rewards to the player"), HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"), HELP_CMD_STATUS("Help_Cmd_Status", "/dxl status - Shows the technical status of DungeonsXL"), HELP_CMD_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index a69b9507..550eb567 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -25,6 +25,7 @@ import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.PlayerData; import io.github.dre2n.dungeonsxl.global.DPortal; import java.io.File; +import java.util.List; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -50,6 +51,7 @@ public class DGlobalPlayer { private ItemStack[] respawnInventory; private ItemStack[] respawnArmor; + private List rewardItems; public DGlobalPlayer(Player player) { this(player, false); @@ -227,6 +229,28 @@ public class DGlobalPlayer { return DPermissions.hasPermission(player, permission); } + /** + * @return the reward items + */ + public List getRewardItems() { + return rewardItems; + } + + /** + * @return if the player has reward items left + */ + public boolean hasRewardItemsLeft() { + return rewardItems != null; + } + + /** + * @param rewardItems + * the reward items to set + */ + public void setRewardItems(List rewardItems) { + this.rewardItems = rewardItems; + } + /** * @param permission * the permission to check diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java index d8857ff0..a5955413 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java @@ -59,6 +59,7 @@ public enum DPermissions { PLAY("play", OP), PORTAL("portal", OP), RELOAD("reload", OP), + REWARDS("rewards", TRUE), SAVE("save", OP), STATUS("status", OP), /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/ItemReward.java b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/ItemReward.java index 494d7b95..bc258c3f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/ItemReward.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/ItemReward.java @@ -16,6 +16,8 @@ */ package io.github.dre2n.dungeonsxl.reward; +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.config.DMessages; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -71,7 +73,14 @@ public class ItemReward extends Reward { /* Actions */ @Override public void giveTo(Player player) { - new DLootInventory(player, getItems()); + if (items.size() <= 54) { + new DLootInventory(player, getItems()); + + } else { + new DLootInventory(player, items.subList(0, 54).toArray(new ItemStack[54])); + plugin.getDPlayers().getByPlayer(player).setRewardItems(items.subList(54, items.size())); + MessageUtil.sendMessage(player, DMessages.ERROR_TOO_MANY_REWARDS.getMessage()); + } } } From 95e4b30e6acfba5f83a87f8f2d2ceae26954864d Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 15:34:37 +0200 Subject: [PATCH 30/57] Fix BossShopSign --- .../dre2n/dungeonsxl/sign/BossShopSign.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java index d4dc95e4..12d45160 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java @@ -17,8 +17,7 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.commons.util.messageutil.MessageUtil; -import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.black_ixx.bossshop.BossShop; @@ -38,10 +37,29 @@ public class BossShopSign extends DSign { private DSignType type = DSignTypeDefault.BOSS_SHOP; + private String shopName; + public BossShopSign(Sign sign, String[] lines, DGameWorld gameWorld) { super(sign, lines, gameWorld); } + /* Getters and setters*/ + /** + * @return the name of the shop + */ + public String getShopName() { + return shopName; + } + + /** + * @param name + * the name of the shop + */ + public void setShopName(String name) { + shopName = name; + } + + /* Actions */ @Override public boolean check() { return true; @@ -54,6 +72,8 @@ public class BossShopSign extends DSign { return; } + shopName = lines[1]; + if (!getTriggers().isEmpty()) { getSign().getBlock().setType(Material.AIR); return; @@ -88,7 +108,7 @@ public class BossShopSign extends DSign { if (shop != null) { bossShop.getAPI().openShop(player, shop); } else { - MessageUtil.sendMessage(player, ChatColor.RED + "Shop " + shopName + " not found..."); + MessageUtil.sendMessage(player, DMessages.ERROR_NO_SUCH_SHOP.getMessage(shopName)); } } From d5715298fd78a09de419acb4e37a0f5511963120 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 15:35:20 +0200 Subject: [PATCH 31/57] Add group score --- .../dungeonsxl/command/GroupCommand.java | 2 ++ .../dre2n/dungeonsxl/config/DMessages.java | 4 ++- .../io/github/dre2n/dungeonsxl/game/Game.java | 4 +++ .../dre2n/dungeonsxl/game/GameRules.java | 26 +++++++++++++++++++ .../dre2n/dungeonsxl/player/DGroup.java | 16 ++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java index 1fd00b8c..96abcd01 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/GroupCommand.java @@ -263,6 +263,8 @@ public class GroupCommand extends BRCommand { MessageUtil.sendMessage(sender, "&bPlayers: &e" + players); MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeonName() == null ? "N/A" : dGroup.getDungeonName())); MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getMapName() == null ? "N/A" : dGroup.getMapName())); + MessageUtil.sendMessage(sender, "&bScore: &e" + (dGroup.getScore() == 0 ? "N/A" : dGroup.getScore())); + MessageUtil.sendMessage(sender, "&bLives: &e" + (dGroup.getLives() == -1 ? "N/A" : dGroup.getLives())); } public void showHelp(String page) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 410340e2..6d64a2a3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -82,6 +82,7 @@ public enum DMessages implements Messages { ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"), ERROR_NO_SUCH_MAP("Error_NoSuchMap", "&4The world &6&v1&4 does not exist!"), ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"), + ERROR_NO_SUCH_SHOP("Error_NoSuchShop", "&4Shop &v1 &4not found..."), ERROR_NOT_CAPTAIN("Error_NotCaptain", "&4You are not the captain of your group!"), ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"), ERROR_NOT_IN_GAME("Error_NotInGame", "&4The group &6&v1&4 is not member of a game."), @@ -136,7 +137,8 @@ public enum DMessages implements Messages { GROUP_CONGRATS_SUB("Group_CongratsSub", "&l&4Your group &v1 &4won the match!"), GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"), GROUP_DEATH("Group_Death", "&4&v1 &6died. &4&v2 have &4&v3 &6lives left."), - GROUP_DEATH_KICK("Group_DeathKick", "&2&v1 &6was kicked because &4&v2 &6have no lives left."), + GROUP_DEATH_KICK("Group_DeathKick", "&4&v1 &6was kicked because &4&v2 &6have no lives left."), + GROUP_DEFEATED("Group_Defeated", "&4The group &4v1 &6is defeated because it lost its last score point."), GROUP_DISBANDED("Group_Disbanded", "&4&v1&6 disbanded the group &4&v2&6."), GROUP_FLAG_CAPTURED("Group_FlagCaptured", "&4&v1&6 has captured the flag of the group &4&v2&6!"), GROUP_FLAG_LOST("Group_FlagLost", "&4&v1&6 died and lost &4&v2&6's flag."), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 843635dc..f1888f89 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -66,6 +66,7 @@ public class Game { fetchRules(); dGroup.setInitialLives(rules.getInitialGroupLives()); dGroup.setLives(rules.getInitialGroupLives()); + dGroup.setScore(rules.getInitialScore()); } public Game(DGroup dGroup, DGameWorld world) { @@ -79,6 +80,7 @@ public class Game { fetchRules(); dGroup.setInitialLives(rules.getInitialGroupLives()); dGroup.setLives(rules.getInitialGroupLives()); + dGroup.setScore(rules.getInitialScore()); } public Game(DGroup dGroup, String worldName) { @@ -95,6 +97,7 @@ public class Game { fetchRules(); dGroup.setInitialLives(rules.getInitialGroupLives()); dGroup.setLives(rules.getInitialGroupLives()); + dGroup.setScore(rules.getInitialScore()); } public Game(DGroup dGroup, GameType type, DGameWorld world) { @@ -114,6 +117,7 @@ public class Game { fetchRules(); dGroup.setInitialLives(rules.getInitialGroupLives()); dGroup.setLives(rules.getInitialGroupLives()); + dGroup.setScore(rules.getInitialScore()); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 8868db05..98007a72 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -56,6 +56,8 @@ public class GameRules { DEFAULT_VALUES.friendlyFire = false; DEFAULT_VALUES.initialLives = -1; DEFAULT_VALUES.initialGroupLives = -1; + DEFAULT_VALUES.initialScore = 3; + DEFAULT_VALUES.scoreGoal = -1; /* Timer */ DEFAULT_VALUES.timeLastPlayed = 0; @@ -100,6 +102,8 @@ public class GameRules { protected Boolean friendlyFire; protected Integer initialLives; protected Integer initialGroupLives; + protected Integer initialScore; + protected Integer scoreGoal; /* Timer */ protected Integer timeLastPlayed; @@ -232,6 +236,20 @@ public class GameRules { return initialGroupLives; } + /** + * @return the initial score + */ + public int getInitialScore() { + return initialScore; + } + + /** + * @return the score goal + */ + public int getScoreGoal() { + return scoreGoal; + } + // Timer /** * @return the timeLastPlayed @@ -496,6 +514,14 @@ public class GameRules { initialGroupLives = defaultValues.initialGroupLives; } + if (initialScore == null) { + initialScore = defaultValues.initialScore; + } + + if (scoreGoal == null) { + scoreGoal = defaultValues.scoreGoal; + } + /* Timer */ if (timeLastPlayed == null) { timeLastPlayed = defaultValues.timeLastPlayed; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 52d201e2..cbc5ac2f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -66,6 +66,7 @@ public class DGroup { private BukkitTask timeIsRunningTask; private DResourceWorld nextFloor; private DColor color; + private int score = 0; private int initialLives = -1; private int lives = -1; @@ -585,6 +586,21 @@ public class DGroup { this.color = color; } + /** + * @return the current score + */ + public int getScore() { + return score; + } + + /** + * @param score + * the score to set + */ + public void setScore(int score) { + this.score = score; + } + /** * @return the initial group lives */ From cb007d736fc0b4c816d9cae242d377d2b7895e0b Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 15:35:44 +0200 Subject: [PATCH 32/57] Fix some messages --- .../java/io/github/dre2n/dungeonsxl/command/EnterCommand.java | 2 +- .../java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java index c03052f9..32ccea28 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EnterCommand.java @@ -86,7 +86,7 @@ public class EnterCommand extends BRCommand { joining.setGameWorld(game.getWorld()); game.addDGroup(joining); - joining.sendMessage(DMessages.CMD_ENTER_SUCCESS.getMessage(joining.getName(), targetName)); + joining.sendMessage(DMessages.CMD_ENTER_SUCCESS.getMessage(joining.getName(), target.getName())); for (Player player : joining.getPlayers()) { DGamePlayer.create(player, game.getWorld(), true); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java index a9e35ee4..6a97c4ce 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java @@ -61,7 +61,7 @@ public class TeamFlag extends TeamBlock { return true; } - owner.getGameWorld().sendMessage(DMessages.GROUP_FLAG_STEALING.getMessage(breaker.getName(), owner.getName())); + owner.getGameWorld().sendMessage(DMessages.GROUP_FLAG_STEALING.getMessage(gamePlayer.getName(), owner.getName())); gamePlayer.setRobbedGroup(owner); event.getBlock().setType(Material.AIR); return true; From af0092ed3827ff9d1f30e5bf9416d1953f22266f Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 15:36:20 +0200 Subject: [PATCH 33/57] GameType improvements --- .../dre2n/dungeonsxl/game/GameGoal.java | 53 ++++++++++++++++ .../dre2n/dungeonsxl/game/GameType.java | 33 ++++------ .../dungeonsxl/game/GameTypeDefault.java | 60 ++++++++----------- .../dre2n/dungeonsxl/player/DGamePlayer.java | 1 - .../dre2n/dungeonsxl/game/CustomGameType.java | 40 +++++-------- 5 files changed, 103 insertions(+), 84 deletions(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java new file mode 100644 index 00000000..ea6ed595 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.game; + +/** + * @author Daniel Saukel + */ +public enum GameGoal { + + /** + * The default goal. + * The game ends when the end is reached. + */ + END, + /** + * The game does not end. + * Instead, the goal is to survive as long as possible to beat a highscore. + */ + HIGHSCORE, + /** + * The game ends when a player dies and only one group is left. + */ + LAST_MAN_STANDING, + /** + * The game ends when a group reachs a specific score. + */ + REACH_SCORE, + /** + * The game ends after a specific time. + * The goal is to get the highest score until then. + */ + TIME_SCORE, + /** + * The game ends after a specific time. + * The goal is to survive until then. + */ + TIME_SURVIVAL; + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java index 3063b8b0..3cc32577 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java @@ -23,17 +23,6 @@ import org.bukkit.GameMode; */ public interface GameType { - /** - * @return if the game ends when one group is left - */ - public Boolean isLastManStanding(); - - /** - * @param lastManStanding - * set if the game ends when one group is left - */ - public void setLastManStanding(Boolean lastManStanding); - /** * @return the displayName */ @@ -56,6 +45,17 @@ public interface GameType { */ public void setSignName(String signName); + /** + * @return the goal of the game + */ + public GameGoal getGameGoal(); + + /** + * @param gameGoal + * the goal of the game to set + */ + public void setGameGoal(GameGoal gameGoal); + /** * @return the playerVersusPlayer */ @@ -78,17 +78,6 @@ public interface GameType { */ public void setFriendlyFire(Boolean friendlyFire); - /** - * @return the mobWaves - */ - public Boolean hasMobWaves(); - - /** - * @param mobWaves - * enable / disable mob waves - */ - public void setMobWaves(Boolean mobWaves); - /** * @return if players get rewards after the dungeon */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java index 74ff6f28..61846d98 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl.game; +import static io.github.dre2n.dungeonsxl.game.GameGoal.*; import org.bukkit.GameMode; /** @@ -23,30 +24,30 @@ import org.bukkit.GameMode; */ public enum GameTypeDefault implements GameType { - ADVENTURE("Adventure", "Adventure", false, false, false, false, true, false, true, true, true, GameMode.ADVENTURE, true), - ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, false, false, true, true, true, true, true, GameMode.ADVENTURE, true), - APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), - APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", false, true, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), - APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", false, true, true, true, true, true, false, false, false, GameMode.SURVIVAL, true), - BEDWARS("Bedwars", "Bedwars", true, true, false, false, false, false, false, true, true, GameMode.SURVIVAL, false), - PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", true, false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), - PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, false, false, true, true, false, false, false, false, GameMode.SURVIVAL, true), - PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, false, false, true, true, true, false, false, false, GameMode.SURVIVAL, true), - PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), - PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, true, false, false, false, false, false, false, false, GameMode.SURVIVAL, true), - QUEST("Quest", "Quest", false, false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), - QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), - TEST("Test", "Test", false, false, false, false, false, true, true, true, true, GameMode.SURVIVAL, false), - TUTORIAL("Tutorial", "Tutorial", false, false, false, false, true, false, false, false, false, GameMode.SURVIVAL, false), - DEFAULT("Default", "Default", false, false, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + ADVENTURE("Adventure", "Adventure", END, false, false, true, false, true, true, true, GameMode.ADVENTURE, true), + ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", TIME_SCORE, false, false, true, true, true, true, true, GameMode.ADVENTURE, true), + APOCALYPSE("Apocalypse", "Apocalypse", HIGHSCORE, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), + APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", LAST_MAN_STANDING, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), + APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", END, true, true, true, false, false, false, false, GameMode.SURVIVAL, true), + APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", TIME_SURVIVAL, true, true, true, true, false, false, false, GameMode.SURVIVAL, true), + BEDWARS("Bedwars", "Bedwars", LAST_MAN_STANDING, true, false, false, false, false, true, true, GameMode.SURVIVAL, false), + PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", LAST_MAN_STANDING, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", TIME_SURVIVAL, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), + PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", LAST_MAN_STANDING, true, false, false, false, false, false, false, GameMode.SURVIVAL, true), + PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", LAST_MAN_STANDING, true, false, false, false, false, false, false, GameMode.SURVIVAL, true), + QUEST("Quest", "Quest", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), + QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", END, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), + TEST("Test", "Test", HIGHSCORE, false, false, false, true, true, true, true, GameMode.SURVIVAL, false), + TUTORIAL("Tutorial", "Tutorial", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, false), + DEFAULT("Default", "Default", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), CUSTOM("Custom", "Custom"); private String displayName; private String signName; - private Boolean lastManStanding; + private GameGoal gameGoal; private Boolean playerVersusPlayer; private Boolean friendlyFire; - private Boolean mobWaves; private Boolean rewards; private Boolean showTime; private Boolean breakBlocks; @@ -55,14 +56,13 @@ public enum GameTypeDefault implements GameType { private GameMode gameMode; private Boolean lives; - GameTypeDefault(String displayName, String signName, Boolean lastManStanding, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, + GameTypeDefault(String displayName, String signName, GameGoal gameGoal, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean rewards, Boolean showTime, Boolean breakBlocks, Boolean breakPlacedBlocks, Boolean placeBlocks, GameMode gameMode, Boolean lives) { this.displayName = displayName; this.signName = signName; - this.lastManStanding = lastManStanding; + this.gameGoal = gameGoal; this.playerVersusPlayer = playerVersusPlayer; this.friendlyFire = friendlyFire; - this.mobWaves = mobWaves; this.rewards = rewards; this.showTime = showTime; this.breakBlocks = breakBlocks; @@ -78,13 +78,13 @@ public enum GameTypeDefault implements GameType { } @Override - public Boolean isLastManStanding() { - return lastManStanding; + public GameGoal getGameGoal() { + return gameGoal; } @Override - public void setLastManStanding(Boolean lastManStanding) { - this.lastManStanding = lastManStanding; + public void setGameGoal(GameGoal gameGoal) { + this.gameGoal = gameGoal; } @Override @@ -127,16 +127,6 @@ public enum GameTypeDefault implements GameType { this.friendlyFire = friendlyFire; } - @Override - public Boolean hasMobWaves() { - return mobWaves; - } - - @Override - public void setMobWaves(Boolean mobWaves) { - this.mobWaves = mobWaves; - } - @Override public Boolean hasRewards() { return rewards; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index dbddbdbd..abdd7e14 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -921,7 +921,6 @@ public class DGamePlayer extends DInstancePlayer { GameType gameType = game.getType(); if (gameType != null && gameType != GameTypeDefault.CUSTOM) { - if (gameType.isLastManStanding()) { if (game.getDGroups().size() == 1) { game.getDGroups().get(0).winGame(); } diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java index 9d990986..cddd9218 100644 --- a/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java +++ b/core/src/test/java/io/github/dre2n/dungeonsxl/game/CustomGameType.java @@ -23,14 +23,13 @@ import org.bukkit.GameMode; */ public enum CustomGameType implements GameType { - GHOST("My awesome game type", "Identifier", false, false, false, false, false, false, false, false, false, GameMode.SPECTATOR, false); + GHOST("My awesome game type", "Identifier", GameGoal.HIGHSCORE, false, false, false, false, false, false, false, GameMode.SPECTATOR, false); private String displayName; private String signName; - private Boolean lastManStanding; + private GameGoal gameGoal; private Boolean playerVersusPlayer; private Boolean friendlyFire; - private Boolean mobWaves; private Boolean rewards; private Boolean showTime; private Boolean breakBlocks; @@ -39,14 +38,13 @@ public enum CustomGameType implements GameType { private GameMode gameMode; private Boolean lives; - CustomGameType(String displayName, String signName, Boolean lastManStanding, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean mobWaves, Boolean rewards, + CustomGameType(String displayName, String signName, GameGoal gameGoal, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean rewards, Boolean showTime, Boolean breakBlocks, Boolean breakPlacedBlocks, Boolean placeBlocks, GameMode gameMode, Boolean lives) { this.displayName = displayName; this.signName = signName; - this.lastManStanding = lastManStanding; + this.gameGoal = gameGoal; this.playerVersusPlayer = playerVersusPlayer; this.friendlyFire = friendlyFire; - this.mobWaves = mobWaves; this.rewards = rewards; this.showTime = showTime; this.breakBlocks = breakBlocks; @@ -56,6 +54,16 @@ public enum CustomGameType implements GameType { this.lives = lives; } + @Override + public GameGoal getGameGoal() { + return gameGoal; + } + + @Override + public void setGameGoal(GameGoal gameGoal) { + this.gameGoal = gameGoal; + } + @Override public String getDisplayName() { return displayName; @@ -76,16 +84,6 @@ public enum CustomGameType implements GameType { this.signName = signName; } - @Override - public Boolean isLastManStanding() { - return lastManStanding; - } - - @Override - public void setLastManStanding(Boolean lastManStanding) { - this.lastManStanding = lastManStanding; - } - @Override public Boolean isPlayerVersusPlayer() { return playerVersusPlayer; @@ -106,16 +104,6 @@ public enum CustomGameType implements GameType { this.friendlyFire = friendlyFire; } - @Override - public Boolean hasMobWaves() { - return mobWaves; - } - - @Override - public void setMobWaves(Boolean mobWaves) { - this.mobWaves = mobWaves; - } - @Override public Boolean hasRewards() { return rewards; From 13a167c7625325ae02f5e7502167b8f93a1f0b70 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 15:36:35 +0200 Subject: [PATCH 34/57] Add capture flag option --- .../dungeonsxl/listener/PlayerListener.java | 10 +++++ .../dre2n/dungeonsxl/player/DGamePlayer.java | 41 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index f1e5f6b7..7e56c210 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -664,6 +664,16 @@ public class PlayerListener implements Listener { @EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); + DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); + DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player); + if (gameWorld != null && gamePlayer != null && gamePlayer.isStealing()) { + DGroup group = gamePlayer.getDGroup(); + Location startLocation = gameWorld.getStartLocation(group); + + if (startLocation.distance(player.getLocation()) < 3) { + gamePlayer.captureFlag(); + } + } DLootInventory inventory = DLootInventory.getByPlayer(player); if (inventory != null && player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index abdd7e14..76452c40 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -30,6 +30,7 @@ import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEv import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerFinishEvent; import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent; import io.github.dre2n.dungeonsxl.game.Game; +import io.github.dre2n.dungeonsxl.game.GameGoal; import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.game.GameTypeDefault; @@ -79,6 +80,7 @@ public class DGamePlayer extends DInstancePlayer { private int initialLives = -1; private int lives; + private ItemStack oldHelmet; private DGroup stealing; public DGamePlayer(Player player, DGameWorld world) { @@ -410,13 +412,49 @@ public class DGamePlayer extends DInstancePlayer { */ public void setRobbedGroup(DGroup dGroup) { if (dGroup != null) { - player.getInventory().getHelmet().setType(Material.WOOL); + oldHelmet = player.getInventory().getHelmet(); + player.getInventory().setHelmet(new ItemStack(Material.WOOL, 1, getDGroup().getDColor().getWoolData())); } stealing = dGroup; } /* Actions */ + public void captureFlag() { + if (stealing == null) { + return; + } + + Game game = Game.getByWorld(getWorld()); + if (game == null) { + return; + } + + game.sendMessage(DMessages.GROUP_FLAG_CAPTURED.getMessage(getName(), stealing.getName())); + + GameRules rules = game.getRules(); + + getDGroup().setScore(getDGroup().getScore() + 1); + if (rules.getScoreGoal() == dGroup.getScore()) { + dGroup.winGame(); + } + + stealing.setScore(stealing.getScore() - 1); + if (stealing.getScore() == -1) { + for (DGamePlayer member : stealing.getDGamePlayers()) { + member.kill(); + } + game.sendMessage(DMessages.GROUP_DEFEATED.getMessage(stealing.getName())); + } + + stealing = null; + player.getInventory().setHelmet(oldHelmet); + + if (game.getDGroups().size() == 1) { + dGroup.winGame(); + } + } + @Override public void leave() { leave(true); @@ -921,6 +959,7 @@ public class DGamePlayer extends DInstancePlayer { GameType gameType = game.getType(); if (gameType != null && gameType != GameTypeDefault.CUSTOM) { + if (gameType.getGameGoal() == GameGoal.LAST_MAN_STANDING) { if (game.getDGroups().size() == 1) { game.getDGroups().get(0).winGame(); } From b746e401556f0063f33bf5548e6d69e1bd9dbc18 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 16:35:08 +0200 Subject: [PATCH 35/57] Fix and improve list command --- .../github/dre2n/dungeonsxl/command/ListCommand.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java index 1551581e..fa9440d1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java @@ -26,6 +26,7 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.DResourceWorld; import io.github.dre2n.dungeonsxl.world.DWorlds; import java.io.File; import java.util.ArrayList; @@ -64,10 +65,10 @@ public class ListCommand extends BRCommand { } ArrayList loadedList = new ArrayList<>(); for (DEditWorld editWorld : worlds.getEditWorlds()) { - loadedList.add(editWorld.getWorld().getWorldFolder().getName()); + loadedList.add(editWorld.getWorld().getWorldFolder().getName() + " / " + editWorld.getName()); } for (DGameWorld gameWorld : worlds.getGameWorlds()) { - loadedList.add(gameWorld.getWorld().getWorldFolder().getName()); + loadedList.add(gameWorld.getWorld().getWorldFolder().getName() + " / " + gameWorld.getName()); } ArrayList toSend = new ArrayList<>(); @@ -132,7 +133,10 @@ public class ListCommand extends BRCommand { for (String map : toSend) { boolean invited = false; if (sender instanceof Player) { - invited = worlds.getResourceByName(map).isInvitedPlayer((Player) sender); + DResourceWorld resource = worlds.getResourceByName(map); + if (resource != null) { + invited = resource.isInvitedPlayer((Player) sender); + } } MessageUtil.sendMessage(sender, "&b" + map + "&7 | &e" + invited); From 670664ca2f8405831b2dbc2325b466f26d51f188 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 16:35:36 +0200 Subject: [PATCH 36/57] Do group size check before initializing team block --- .../main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java | 4 +++- .../main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java index 89f6cd74..8e6f32da 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java @@ -55,7 +55,9 @@ public class BedSign extends DSign { Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); if (block.getType() == Material.BED_BLOCK) { - getGameWorld().addGameBlock(new TeamBed(block, getGame().getDGroups().get(team))); + if (getGame().getDGroups().size() > team) { + getGameWorld().addGameBlock(new TeamBed(block, getGame().getDGroups().get(team))); + } getSign().getBlock().setType(Material.AIR); } else { markAsErroneous(); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java index 3b830aa0..d80d4edd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java @@ -49,7 +49,9 @@ public class FlagSign extends DSign { @Override public void onInit() { this.team = NumberUtil.parseInt(lines[1]); - getGameWorld().addGameBlock(new TeamFlag(getSign().getBlock(), getGame().getDGroups().get(team))); + if (getGame().getDGroups().size() > team) { + getGameWorld().addGameBlock(new TeamFlag(getSign().getBlock(), getGame().getDGroups().get(team))); + } } } From 4cda7078a1949504850f1b6a88c380e4a19d0026 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 16:36:21 +0200 Subject: [PATCH 37/57] Only check for double jump if !placeBlocks --- .../dre2n/dungeonsxl/world/DGameWorld.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index 98e1ed3d..645fe1c0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -70,6 +70,8 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class DGameWorld extends DInstanceWorld { + Game game; + // Variables private boolean tutorial; private boolean isPlaying = false; @@ -104,13 +106,15 @@ public class DGameWorld extends DInstanceWorld { * the Game connected to the DGameWorld */ public Game getGame() { - for (Game game : plugin.getGames()) { - if (game.getWorld() == this) { - return game; + if (game == null) { + for (Game game : plugin.getGames()) { + if (game.getWorld() == this) { + this.game = game; + } } } - return null; + return game; } /** @@ -599,19 +603,6 @@ public class DGameWorld extends DInstanceWorld { * @return if the event is cancelled */ public boolean onPlace(Player player, Block block, Block against, ItemStack hand) { - // Workaround for a bug that would allow 3-Block-high jumping - Location loc = player.getLocation(); - if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) { - if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) { - if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) { - loc.setX(block.getX() + 0.5); - loc.setY(block.getY()); - loc.setZ(block.getZ() + 0.5); - player.teleport(loc); - } - } - } - Game game = getGame(); if (game == null) { return true; @@ -619,6 +610,19 @@ public class DGameWorld extends DInstanceWorld { GameRules rules = game.getRules(); if (!rules.canPlaceBlocks() && !PlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) { + // Workaround for a bug that would allow 3-Block-high jumping + Location loc = player.getLocation(); + if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) { + if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) { + if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) { + loc.setX(block.getX() + 0.5); + loc.setY(block.getY()); + loc.setZ(block.getZ() + 0.5); + player.teleport(loc); + } + } + } + return true; } From 6ae111805697acae2450a0ec3583c920ab7d196e Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 14 Aug 2016 19:46:39 +0200 Subject: [PATCH 38/57] Fix event extension --- .../event/dplayer/instance/DInstancePlayerUpdateEvent.java | 3 +-- .../event/dplayer/instance/game/DGamePlayerDeathEvent.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerUpdateEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerUpdateEvent.java index 5728e029..290b9c5b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerUpdateEvent.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/DInstancePlayerUpdateEvent.java @@ -16,7 +16,6 @@ */ package io.github.dre2n.dungeonsxl.event.dplayer.instance; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEvent; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -24,7 +23,7 @@ import org.bukkit.event.HandlerList; /** * @author Daniel Saukel */ -public class DInstancePlayerUpdateEvent extends DPlayerEvent implements Cancellable { +public class DInstancePlayerUpdateEvent extends DInstancePlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerDeathEvent.java b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerDeathEvent.java index 7fc55ed2..d71f6645 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerDeathEvent.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/event/dplayer/instance/game/DGamePlayerDeathEvent.java @@ -16,7 +16,6 @@ */ package io.github.dre2n.dungeonsxl.event.dplayer.instance.game; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEvent; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -25,7 +24,7 @@ import org.bukkit.event.entity.PlayerDeathEvent; /** * @author Daniel Saukel */ -public class DGamePlayerDeathEvent extends DPlayerEvent implements Cancellable { +public class DGamePlayerDeathEvent extends DGamePlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; From ff7e8dbf5fa7ad784782ee547e939ef5556c2de4 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sat, 20 Aug 2016 23:34:03 +0200 Subject: [PATCH 39/57] Fix compatibility issues with max health lower than 20; resolves #137 --- .../dre2n/dungeonsxl/config/PlayerData.java | 22 ++++++++++++++++++- .../dungeonsxl/player/DGlobalPlayer.java | 1 + .../dungeonsxl/player/DInstancePlayer.java | 17 +++++++------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java index 880e04c3..89a2338a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java @@ -53,6 +53,7 @@ public class PlayerData extends BRConfig { private ItemStack oldOffHand; private int oldLvl; private float oldExp; + private double oldHealthScale; private double oldHealth; private int oldFoodLevel; private int oldFireTicks; @@ -169,6 +170,21 @@ public class PlayerData extends BRConfig { oldExp = exp; } + /** + * @return the old health scale + */ + public double getOldHealthScale() { + return oldHealthScale; + } + + /** + * @param healthScale + * the healthScale to set + */ + public void setOldHealthScale(double healthScale) { + oldHealthScale = healthScale; + } + /** * @return the old health */ @@ -321,7 +337,8 @@ public class PlayerData extends BRConfig { oldLvl = config.getInt(PREFIX_STATE_PERSISTENCE + "oldLvl"); oldExp = config.getInt(PREFIX_STATE_PERSISTENCE + "oldExp"); - oldHealth = config.getInt(PREFIX_STATE_PERSISTENCE + "oldHealth"); + oldHealthScale = config.getDouble(PREFIX_STATE_PERSISTENCE + "oldHealthScale"); + oldHealth = config.getDouble(PREFIX_STATE_PERSISTENCE + "oldHealth"); oldFoodLevel = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFoodLevel"); oldFireTicks = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFireTicks"); @@ -354,6 +371,7 @@ public class PlayerData extends BRConfig { oldGameMode = player.getGameMode(); oldFireTicks = player.getFireTicks(); oldFoodLevel = player.getFoodLevel(); + oldHealthScale = player.getHealthScale(); oldHealth = player.getHealth(); oldExp = player.getExp(); oldLvl = player.getLevel(); @@ -366,6 +384,7 @@ public class PlayerData extends BRConfig { config.set(PREFIX_STATE_PERSISTENCE + "oldGameMode", oldGameMode.toString()); config.set(PREFIX_STATE_PERSISTENCE + "oldFireTicks", oldFireTicks); config.set(PREFIX_STATE_PERSISTENCE + "oldFoodLevel", oldFoodLevel); + config.set(PREFIX_STATE_PERSISTENCE + "oldHealthScale", oldHealthScale); config.set(PREFIX_STATE_PERSISTENCE + "oldHealth", oldHealth); config.set(PREFIX_STATE_PERSISTENCE + "oldExp", oldExp); config.set(PREFIX_STATE_PERSISTENCE + "oldLvl", oldLvl); @@ -385,6 +404,7 @@ public class PlayerData extends BRConfig { oldGameMode = null; oldFireTicks = 0; oldFoodLevel = 0; + oldHealthScale = 0; oldHealth = 0; oldExp = 0; oldLvl = 0; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index 550eb567..9b63640f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -277,6 +277,7 @@ public class DGlobalPlayer { } player.setLevel(data.getOldLevel()); player.setExp(data.getOldExp()); + player.setHealthScale(data.getOldHealthScale()); player.setHealth(data.getOldHealth()); player.setFoodLevel(data.getOldFoodLevel()); player.setGameMode(data.getOldGameMode()); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java index 275e6c70..0c9ee584 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java @@ -77,14 +77,15 @@ public abstract class DInstancePlayer extends DGlobalPlayer { * Clear the player's inventory, potion effects etc. */ public void clearPlayerData() { - getPlayer().getInventory().clear(); - getPlayer().getInventory().setArmorContents(null); - getPlayer().setTotalExperience(0); - getPlayer().setLevel(0); - getPlayer().setHealth(20); - getPlayer().setFoodLevel(20); - for (PotionEffect effect : getPlayer().getActivePotionEffects()) { - getPlayer().removePotionEffect(effect.getType()); + player.getInventory().clear(); + player.getInventory().setArmorContents(null); + player.setTotalExperience(0); + player.setLevel(0); + player.setHealthScale(20); + player.setHealth(20); + player.setFoodLevel(20); + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); } } From cf557a61e2cc769400f0487ac80bf1373bf95eb6 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 24 Aug 2016 16:17:28 +0200 Subject: [PATCH 40/57] Fix games not marked as started --- .../dungeonsxl/listener/EntityListener.java | 70 ++++++++++--------- .../dre2n/dungeonsxl/player/DGamePlayer.java | 2 + 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java index 669c5398..e40f74fb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java @@ -170,52 +170,56 @@ public class EntityListener implements Listener { DGroup attackerDGroup = null; DGroup attackedDGroup = null; - if (attackerEntity instanceof LivingEntity && attackedEntity instanceof LivingEntity) { - if (attackerEntity instanceof Player && attackedEntity instanceof Player) { - attackerPlayer = (Player) attackerEntity; - attackedPlayer = (Player) attackedEntity; + if (!(attackerEntity instanceof LivingEntity) || !(attackedEntity instanceof LivingEntity)) { + return; + } - attackerDGroup = DGroup.getByPlayer(attackerPlayer); - attackedDGroup = DGroup.getByPlayer(attackedPlayer); + if (attackerEntity instanceof Player && attackedEntity instanceof Player) { + attackerPlayer = (Player) attackerEntity; + attackedPlayer = (Player) attackedEntity; - if (!pvp) { + attackerDGroup = DGroup.getByPlayer(attackerPlayer); + attackedDGroup = DGroup.getByPlayer(attackedPlayer); + + if (!pvp) { + event.setCancelled(true); + return; + } + + if (attackerDGroup != null && attackedDGroup != null) { + if (!friendlyFire && attackerDGroup.equals(attackedDGroup)) { event.setCancelled(true); - } - - if (attackerDGroup != null && attackedDGroup != null) { - if (!friendlyFire && attackerDGroup.equals(attackedDGroup)) { - event.setCancelled(true); - } - } - } - - // Check Dogs - if (attackerEntity instanceof Player || attackedEntity instanceof Player) { - for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) { - if (dPlayer.getWolf() != null) { - if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { - event.setCancelled(true); - return; - } - } + return; } } + } + // Check Dogs + if (attackerEntity instanceof Player || attackedEntity instanceof Player) { for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) { if (dPlayer.getWolf() != null) { - if (attackerEntity instanceof Player || attackedEntity instanceof Player) { - if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { - event.setCancelled(true); - return; - } - - } else if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { - event.setCancelled(false); + if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { + event.setCancelled(true); return; } } } } + + for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) { + if (dPlayer.getWolf() != null) { + if (attackerEntity instanceof Player || attackedEntity instanceof Player) { + if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { + event.setCancelled(true); + return; + } + + } else if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { + event.setCancelled(false); + return; + } + } + } } // Deny food in Lobby diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 76452c40..88e1d0d5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -698,6 +698,8 @@ public class DGamePlayer extends DInstancePlayer { respawn(); } } + + game.setStarted(true); } public void respawn() { From 385d32a181ed9b42fb202696496b20eccdf47a32 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 24 Aug 2016 16:23:06 +0200 Subject: [PATCH 41/57] Mark BossShop signs as erroneous if plugin is not available --- .../main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java index 12d45160..65b85851 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BossShopSign.java @@ -67,7 +67,7 @@ public class BossShopSign extends DSign { @Override public void onInit() { - if (bossShop.getAPI().getShop(lines[1]) == null) { + if (bossShop == null || bossShop.getAPI().getShop(lines[1]) == null) { markAsErroneous(); return; } From 0ea47a47e561a2add3eb13d0ec91da375fcbffc2 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 25 Aug 2016 15:48:13 +0200 Subject: [PATCH 42/57] Recoded tutorial system Still issues with PEX + start group --- .../dungeonsxl/command/LeaveCommand.java | 11 ++- .../io/github/dre2n/dungeonsxl/game/Game.java | 22 +++++- .../dungeonsxl/game/GameTypeDefault.java | 1 - .../dungeonsxl/listener/PlayerListener.java | 71 +++---------------- .../dre2n/dungeonsxl/player/DGamePlayer.java | 10 +-- .../dungeonsxl/player/DGlobalPlayer.java | 52 ++++++++++++++ .../dre2n/dungeonsxl/player/DPlayers.java | 24 +++++++ .../dre2n/dungeonsxl/world/DGameWorld.java | 16 ----- 8 files changed, 115 insertions(+), 92 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java index 9f290840..f96a57cb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java @@ -22,6 +22,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent; import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; +import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.player.DEditPlayer; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; @@ -51,14 +52,12 @@ public class LeaveCommand extends BRCommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); + Game game = Game.getByPlayer(player); - if (DGameWorld.getByWorld(player.getWorld()) != null) { - if (DGameWorld.getByWorld(player.getWorld()).isTutorial()) { - MessageUtil.sendMessage(player, DMessages.ERROR_NO_LEAVE_IN_TUTORIAL.getMessage()); - return; - } + if (game.isTutorial()) { + MessageUtil.sendMessage(player, DMessages.ERROR_NO_LEAVE_IN_TUTORIAL.getMessage()); + return; } DGroup dGroup = DGroup.getByPlayer(player); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index f1888f89..ff5cf419 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -47,6 +47,7 @@ public class Game { static DungeonsXL plugin = DungeonsXL.getInstance(); + private boolean tutorial; private List dGroups = new ArrayList<>(); private boolean started; private GameType type = GameTypeDefault.DEFAULT; @@ -59,6 +60,7 @@ public class Game { public Game(DGroup dGroup) { plugin.getGames().add(this); + tutorial = false; started = false; dGroups.add(dGroup); @@ -72,6 +74,7 @@ public class Game { public Game(DGroup dGroup, DGameWorld world) { plugin.getGames().add(this); + tutorial = false; started = false; this.world = world; @@ -86,6 +89,7 @@ public class Game { public Game(DGroup dGroup, String worldName) { plugin.getGames().add(this); + tutorial = false; started = false; DResourceWorld resource = plugin.getDWorlds().getResourceByName(worldName); if (resource != null) { @@ -110,6 +114,7 @@ public class Game { this.dGroups = dGroups; this.type = type; this.world = world; + this.tutorial = false; this.started = true; for (DGroup dGroup : dGroups) { @@ -121,6 +126,21 @@ public class Game { } } + /** + * @return the tutorial + */ + public boolean isTutorial() { + return tutorial; + } + + /** + * @param tutorial + * if the DGameWorld is the tutorial + */ + public void setTutorial(boolean tutorial) { + this.tutorial = tutorial; + } + /** * @return the dGroups */ @@ -455,7 +475,7 @@ public class Game { public static Game getByGameWorld(DGameWorld gameWorld) { for (Game game : plugin.getGames()) { - if (game.getWorld().equals(gameWorld)) { + if (gameWorld.equals(game.getWorld())) { return game; } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java index 61846d98..abf3f1b9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java @@ -39,7 +39,6 @@ public enum GameTypeDefault implements GameType { QUEST("Quest", "Quest", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", END, false, false, true, true, false, false, false, GameMode.SURVIVAL, true), TEST("Test", "Test", HIGHSCORE, false, false, false, true, true, true, true, GameMode.SURVIVAL, false), - TUTORIAL("Tutorial", "Tutorial", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, false), DEFAULT("Default", "Default", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true), CUSTOM("Custom", "Custom"); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 7e56c210..6e2e47a5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -20,7 +20,6 @@ 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.MainConfig; -import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GameSign; @@ -441,79 +440,25 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void onJoin(PlayerJoinEvent event) { - plugin.debug.start("PlayerListener#onJoin"); Player player = event.getPlayer(); - - new DGlobalPlayer(player); - - // Check dPlayers - DGamePlayer dPlayer = DGamePlayer.getByName(player.getName()); - if (dPlayer != null) { - DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer()); - if (dGroup != null) { - dGroup.removePlayer(dPlayer.getPlayer()); - dGroup.addPlayer(player); - } - dPlayer.setPlayer(player); - - // Check offlineTime - dPlayer.setOfflineTime(0); + if (dPlayers.checkPlayer(player)) { + return; + } + + DGlobalPlayer dPlayer = new DGlobalPlayer(player); + if (player.hasPlayedBefore()) { + return; } - // Tutorial Mode if (!plugin.getMainConfig().isTutorialActivated()) { - plugin.debug.end("PlayerListener#onJoin", true); return; } if (DGamePlayer.getByPlayer(player) != null) { - plugin.debug.end("PlayerListener#onJoin", true); return; } - if (plugin.getPermissionProvider() == null || !plugin.getPermissionProvider().hasGroupSupport()) { - plugin.debug.end("PlayerListener#onJoin", true); - return; - } - - if ((plugin.getMainConfig().getTutorialDungeon() == null || plugin.getMainConfig().getTutorialStartGroup() == null || plugin.getMainConfig().getTutorialEndGroup() == null)) { - plugin.debug.end("PlayerListener#onJoin", true); - return; - } - - for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) { - if (!plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) { - continue; - } - - DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false); - - DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN); - plugin.getServer().getPluginManager().callEvent(createEvent); - - if (createEvent.isCancelled()) { - dGroup = null; - } - - if (dGroup == null) { - continue; - } - - if (dGroup.getGameWorld() == null) { - dGroup.setGameWorld(plugin.getDWorlds().getResourceByName(DGroup.getByPlayer(player).getMapName()).instantiateAsGameWorld()); - dGroup.getGameWorld().setTutorial(true); - } - - if (dGroup.getGameWorld() == null) { - MessageUtil.sendMessage(player, DMessages.ERROR_TUTORIAL_NOT_EXIST.getMessage()); - continue; - } - - DGamePlayer.create(player, dGroup.getGameWorld()); - plugin.debug.end("PlayerListener#onJoin", true); - return; - } - plugin.debug.end("PlayerListener#onJoin", true); + dPlayer.startTutorial(); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 88e1d0d5..9da3c6ed 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -465,7 +465,9 @@ public class DGamePlayer extends DInstancePlayer { * if messages should be sent */ public void leave(boolean message) { - GameRules rules = Game.getByWorld(getWorld()).getRules(); + Game game = Game.getByWorld(getWorld()); + DGameWorld gameWorld = game.getWorld(); + GameRules rules = game.getRules(); delete(); if (finished) { @@ -485,11 +487,9 @@ public class DGamePlayer extends DInstancePlayer { dGroup.removePlayer(getPlayer(), message); } - DGameWorld gameWorld = DGameWorld.getByWorld(getWorld()); - Game game = Game.getByGameWorld(gameWorld); if (game != null) { if (finished) { - if (game.getType().hasRewards()) { + if (game.getType() == GameTypeDefault.CUSTOM || game.getType().hasRewards()) { for (Reward reward : rules.getRewards()) { reward.giveTo(getPlayer()); } @@ -497,7 +497,7 @@ public class DGamePlayer extends DInstancePlayer { getData().logTimeLastPlayed(getDGroup().getDungeon().getName()); // Tutorial Permissions - if (gameWorld.isTutorial() && plugin.getPermissionProvider() != null && plugin.getPermissionProvider().hasGroupSupport()) { + if (game.isTutorial() && plugin.getPermissionProvider().hasGroupSupport()) { String endGroup = plugin.getMainConfig().getTutorialEndGroup(); if (plugin.isGroupEnabled(endGroup)) { plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index 9b63640f..46827004 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -23,13 +23,18 @@ import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.PlayerData; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; +import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.global.DPortal; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.io.File; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; +import org.bukkit.scheduler.BukkitRunnable; /** * Represents a player in the non-DXL worlds of the server. @@ -304,4 +309,51 @@ public class DGlobalPlayer { data.clearPlayerState(); } + /** + * Starts the tutorial + */ + public void startTutorial() { + if (plugin.getPermissionProvider() == null || !plugin.getPermissionProvider().hasGroupSupport()) { + return; + } + + final String startGroup = plugin.getMainConfig().getTutorialStartGroup(); + if ((plugin.getMainConfig().getTutorialDungeon() == null || startGroup == null)) { + return; + } + + if (plugin.isGroupEnabled(startGroup)) { + plugin.getPermissionProvider().playerAddGroup(player, startGroup); + } + + DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false); + + DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN); + plugin.getServer().getPluginManager().callEvent(createEvent); + + if (createEvent.isCancelled()) { + dGroup = null; + } + + if (dGroup == null) { + return; + } + + DGameWorld gameWorld = null; + + if (dGroup.getGameWorld() == null) { + DResourceWorld resource = plugin.getDWorlds().getResourceByName(dGroup.getMapName()); + if (resource == null) { + MessageUtil.sendMessage(player, DMessages.ERROR_TUTORIAL_NOT_EXIST.getMessage()); + return; + } + + gameWorld = resource.instantiateAsGameWorld(); + dGroup.setGameWorld(gameWorld); + } + + new Game(dGroup, gameWorld).setTutorial(true); + DGamePlayer.create(player, gameWorld); + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java index 9619af11..8b7cea22 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java @@ -119,4 +119,28 @@ public class DPlayers { } } + /** + * Checks if an old DGamePlayer instance of the user exists. + * If yes, the old Player of the user is replaced with the new object. + * + * @param player + * the player to check + * @return if the player exists + */ + public boolean checkPlayer(Player player) { + DGamePlayer dPlayer = DGamePlayer.getByName(player.getName()); + if (dPlayer == null) { + return false; + } + + DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer()); + if (dGroup != null) { + dGroup.removePlayer(dPlayer.getPlayer()); + dGroup.addPlayer(player); + } + dPlayer.setPlayer(player); + dPlayer.setOfflineTime(0); + return true; + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index 645fe1c0..84055591 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -73,7 +73,6 @@ public class DGameWorld extends DInstanceWorld { Game game; // Variables - private boolean tutorial; private boolean isPlaying = false; // TO DO: Which lists actually need to be CopyOnWriteArrayLists? @@ -117,21 +116,6 @@ public class DGameWorld extends DInstanceWorld { return game; } - /** - * @return the tutorial - */ - public boolean isTutorial() { - return tutorial; - } - - /** - * @param tutorial - * if the DGameWorld is the tutorial - */ - public void setTutorial(boolean tutorial) { - this.tutorial = tutorial; - } - /** * @return the isPlaying */ From 258e115a3854ac2ebcd6a7ef0fedb6ec375c240e Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Fri, 26 Aug 2016 15:42:26 +0200 Subject: [PATCH 43/57] Added some JavaDoc explanations to the classes --- .../io/github/dre2n/dungeonsxl/DungeonsXL.java | 3 +++ .../dre2n/dungeonsxl/announcer/Announcer.java | 2 ++ .../dre2n/dungeonsxl/announcer/Announcers.java | 2 ++ .../dungeonsxl/command/DeletePortalCommand.java | 3 ++- .../dre2n/dungeonsxl/config/DMessages.java | 3 +++ .../dre2n/dungeonsxl/config/DungeonConfig.java | 2 ++ .../dre2n/dungeonsxl/config/GlobalData.java | 2 ++ .../dre2n/dungeonsxl/config/MainConfig.java | 2 ++ .../dre2n/dungeonsxl/config/PlayerData.java | 2 ++ .../dre2n/dungeonsxl/config/SignData.java | 2 ++ .../dre2n/dungeonsxl/config/WorldConfig.java | 4 ++++ .../dre2n/dungeonsxl/dungeon/Dungeon.java | 4 ++++ .../dre2n/dungeonsxl/dungeon/Dungeons.java | 2 ++ .../io/github/dre2n/dungeonsxl/game/Game.java | 3 +++ .../github/dre2n/dungeonsxl/game/GameGoal.java | 2 ++ .../github/dre2n/dungeonsxl/game/GameRules.java | 2 ++ .../github/dre2n/dungeonsxl/game/GameType.java | 2 ++ .../dre2n/dungeonsxl/game/GameTypeDefault.java | 2 ++ .../github/dre2n/dungeonsxl/game/GameTypes.java | 2 ++ .../github/dre2n/dungeonsxl/global/DPortal.java | 2 ++ .../dre2n/dungeonsxl/global/GameSign.java | 2 ++ .../dungeonsxl/global/GlobalProtection.java | 17 ++++++++++++++--- .../dungeonsxl/global/GlobalProtections.java | 17 ++++++++++++++--- .../dre2n/dungeonsxl/global/GroupSign.java | 2 ++ .../dre2n/dungeonsxl/global/LeaveSign.java | 2 ++ .../dre2n/dungeonsxl/loottable/DLootTable.java | 2 ++ .../dre2n/dungeonsxl/loottable/DLootTables.java | 2 ++ .../dungeonsxl/mob/CitizensMobProvider.java | 2 ++ .../mob/CustomExternalMobProvider.java | 2 ++ .../dre2n/dungeonsxl/mob/ExternalMobPlugin.java | 2 ++ .../dungeonsxl/mob/ExternalMobProvider.java | 2 ++ .../dungeonsxl/mob/ExternalMobProviders.java | 2 ++ .../github/dre2n/dungeonsxl/player/DClass.java | 2 ++ .../dre2n/dungeonsxl/player/DClasses.java | 2 ++ .../dre2n/dungeonsxl/player/DEditPlayer.java | 2 +- .../dre2n/dungeonsxl/player/DGlobalPlayer.java | 1 - .../github/dre2n/dungeonsxl/player/DGroup.java | 2 ++ .../dungeonsxl/player/DInstancePlayer.java | 2 ++ .../dre2n/dungeonsxl/player/DPlayers.java | 2 ++ .../dungeonsxl/requirement/Requirement.java | 2 ++ .../dungeonsxl/requirement/RequirementType.java | 2 ++ .../requirement/RequirementTypeDefault.java | 2 ++ .../requirement/RequirementTypes.java | 2 ++ .../github/dre2n/dungeonsxl/reward/Reward.java | 2 ++ .../dre2n/dungeonsxl/reward/RewardType.java | 2 ++ .../dungeonsxl/reward/RewardTypeDefault.java | 2 ++ .../dre2n/dungeonsxl/reward/RewardTypes.java | 2 ++ .../io/github/dre2n/dungeonsxl/sign/DSign.java | 4 +++- .../github/dre2n/dungeonsxl/sign/DSignType.java | 2 ++ .../dre2n/dungeonsxl/sign/DSignTypeDefault.java | 2 ++ .../dre2n/dungeonsxl/sign/DSignTypes.java | 2 ++ .../dre2n/dungeonsxl/sign/SignScript.java | 3 +++ .../dre2n/dungeonsxl/sign/SignScripts.java | 2 ++ .../dre2n/dungeonsxl/trigger/Trigger.java | 2 ++ .../dre2n/dungeonsxl/trigger/TriggerType.java | 2 ++ .../dungeonsxl/trigger/TriggerTypeDefault.java | 2 ++ .../dre2n/dungeonsxl/trigger/TriggerTypes.java | 2 ++ .../io/github/dre2n/dungeonsxl/util/DColor.java | 2 ++ .../dre2n/dungeonsxl/util/ProgressBar.java | 2 ++ .../dre2n/dungeonsxl/world/DEditWorld.java | 3 +++ .../dre2n/dungeonsxl/world/DGameWorld.java | 3 +++ .../dre2n/dungeonsxl/world/DInstanceWorld.java | 2 ++ .../github/dre2n/dungeonsxl/world/DWorlds.java | 2 ++ .../dre2n/dungeonsxl/world/block/GameBlock.java | 2 ++ .../dungeonsxl/world/block/LockedDoor.java | 2 ++ 65 files changed, 162 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 56e0111c..6bef52ee 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -58,6 +58,9 @@ import org.bukkit.event.HandlerList; import org.bukkit.scheduler.BukkitTask; /** + * The main class of DungeonsXL. + * It contains several important instances and the actions when the plugin is enabled / disabled. + * * @author Frank Baumann, Tobias Schmitz, Daniel Saukel */ public class DungeonsXL extends BRPlugin { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java index 576b41d9..80aa9af4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -44,6 +44,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; /** + * Represents a game announcement. + * * @author Daniel Saukel */ public class Announcer { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java index 56283e0a..dc0e8c94 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java @@ -24,6 +24,8 @@ import org.bukkit.ChatColor; import org.bukkit.inventory.Inventory; /** + * Announcer instance manager. + * * @author Daniel Saukel */ public class Announcers { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java index f58aee22..5818e0be 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java @@ -28,8 +28,9 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel - * @deprecated + * @deprecated Use BreakCommand instead. */ +@Deprecated public class DeletePortalCommand extends BRCommand { DungeonsXL plugin = DungeonsXL.getInstance(); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 6d64a2a3..1385c0b3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -24,6 +24,9 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; /** + * An enumeration of all messages. + * The values are fetched from the language file. + * * @author Daniel Saukel */ public enum DMessages implements Messages { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java index 8e9bc752..8bae5ca4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; /** + * Represents a dungeon script. See {@link io.github.dre2n.dungeonsxl.dungeon.Dungeon}. + * * @author Daniel Saukel */ public class DungeonConfig extends BRConfig { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/GlobalData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/GlobalData.java index e3b87277..f6870f3a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/GlobalData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/GlobalData.java @@ -20,6 +20,8 @@ import io.github.dre2n.commons.config.BRConfig; import java.io.File; /** + * Represents the global data.yml. + * * @author Daniel Saukel */ public class GlobalData extends BRConfig { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index f4ecd5ca..57883c00 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -32,6 +32,8 @@ import java.util.Map; import org.bukkit.configuration.ConfigurationSection; /** + * Represents the main config.yml. + * * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ public class MainConfig extends BRConfig { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java index 89a2338a..c0eb556c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java @@ -35,6 +35,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; /** + * Represents a player's persistent data. + * * @author Daniel Saukel */ public class PlayerData extends BRConfig { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/SignData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/SignData.java index 7032840b..733a2307 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/SignData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/SignData.java @@ -30,6 +30,8 @@ import org.bukkit.block.Block; import org.bukkit.block.Sign; /** + * Represents the data file of a dungeon map, mainly to store signs. + * * @author Daniel Saukel */ public class SignData { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index a4cce5be..0020635a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -44,6 +44,10 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; /** + * The world configuration is a simple game rule source. + * Besides game rules, WorldConfig also stores some map specific data such as the invited players. + * It is used directly in dungeon map config.yml files, but also part of dungeon and main config files. + * * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ public class WorldConfig extends GameRules { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java index 4fbcc2fd..9458eb66 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java @@ -21,6 +21,10 @@ import io.github.dre2n.dungeonsxl.config.DungeonConfig; import java.io.File; /** + * Represents a dungeon. + * While multi floor dungeon scripts are represented by {@link io.github.dre2n.dungeonsxl.config.DungeonConfig}, + * single floor dungeons also get a dungeon object without a config file as a placeholder. + * * @author Daniel Saukel */ public class Dungeon { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java index 2f5f8c13..673285d0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.List; /** + * Dungeon instance manager. + * * @author Daniel Saukel */ public class Dungeons { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index ff5cf419..4cd57a54 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -41,6 +41,9 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; /** + * Game mostly stores for which purposes and how a {@link io.github.dre2n.dungeonsxl.dungeon.Dungeon} is used, + * the player groups and the progress. + * * @author Daniel Saukel */ public class Game { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java index ea6ed595..dc50fce3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameGoal.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.game; /** + * A game goal defines what the players have to do in order to finish the game. + * * @author Daniel Saukel */ public enum GameGoal { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 98007a72..0cd6e350 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -29,6 +29,8 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; /** + * See {@link io.github.dre2n.dungeonsxl.config.WorldConfig} + * * @author Daniel Saukel */ public class GameRules { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java index 3cc32577..460d404d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java @@ -19,6 +19,8 @@ package io.github.dre2n.dungeonsxl.game; import org.bukkit.GameMode; /** + * Implement this to create custom game types. + * * @author Daniel Saukel */ public interface GameType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java index abf3f1b9..7bd94403 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java @@ -20,6 +20,8 @@ import static io.github.dre2n.dungeonsxl.game.GameGoal.*; import org.bukkit.GameMode; /** + * Default implementation of {@link io.github.dre2n.dungeonsxl.game.GameType}. + * * @author Daniel Saukel */ public enum GameTypeDefault implements GameType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypes.java index a754b1d7..7590eef5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameTypes.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.List; /** + * GameType instance manager. + * * @author Daniel Saukel */ public class GameTypes { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java index a70adbb8..5dab6fd2 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -35,6 +35,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; /** + * A portal that leads into a dungeon. + * * @author Frank Baumann, Daniel Saukel */ public class DPortal extends GlobalProtection { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java index f8adbdbb..3f98e3c3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java @@ -34,6 +34,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; /** + * Basically a GroupSign, but to form a game of multiple groups. + * * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ public class GameSign extends GlobalProtection { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java index e081bcbd..6b83c1cd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtection.java @@ -1,7 +1,18 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package io.github.dre2n.dungeonsxl.global; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java index 784cec84..a0f97a51 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java @@ -1,7 +1,18 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package io.github.dre2n.dungeonsxl.global; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java index a432c283..f0630ce5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java @@ -33,6 +33,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; /** + * A sign to form a group and to define its dungeon. + * * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ public class GroupSign extends GlobalProtection { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java index f3cd41b7..2f0e38f8 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java @@ -30,6 +30,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; /** + * A sign to leave a group. + * * @author Frank Baumann */ public class LeaveSign extends GlobalProtection { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTable.java b/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTable.java index c8ba5201..4999cf9d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTable.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTable.java @@ -26,6 +26,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; /** + * A loot table for rewards and mob drops. + * * @author Daniel Saukel */ public class DLootTable { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTables.java b/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTables.java index ce6b412f..aa4499fa 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTables.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/loottable/DLootTables.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.List; /** + * DLootTable instance manager. + * * @author Daniel Saukel */ public class DLootTables { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java index 2ab4d8ba..6f2b4cdd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java @@ -26,6 +26,8 @@ import org.bukkit.Location; import org.bukkit.entity.LivingEntity; /** + * ExternalMobProvider implementation for Citizens. + * * @author Daniel Saukel */ public class CitizensMobProvider implements ExternalMobProvider { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CustomExternalMobProvider.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CustomExternalMobProvider.java index 420c4733..4bfe7b7a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CustomExternalMobProvider.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CustomExternalMobProvider.java @@ -21,6 +21,8 @@ import org.bukkit.Bukkit; import org.bukkit.Location; /** + * A custom external mob provider like defined in the main config file. + * * @author Daniel Saukel */ public class CustomExternalMobProvider implements ExternalMobProvider { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobPlugin.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobPlugin.java index dc4d2b24..6457f656 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobPlugin.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobPlugin.java @@ -20,6 +20,8 @@ import org.bukkit.Bukkit; import org.bukkit.Location; /** + * Officially supported external mob plugins. + * * @author Daniel Saukel */ public enum ExternalMobPlugin implements ExternalMobProvider { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProvider.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProvider.java index 395bed8a..20774aed 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProvider.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProvider.java @@ -19,6 +19,8 @@ package io.github.dre2n.dungeonsxl.mob; import org.bukkit.Location; /** + * Implement this to create custom ExternalMobProviders. + * * @author Daniel Saukel */ public interface ExternalMobProvider { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java index 8d5834b2..c0467396 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java @@ -25,6 +25,8 @@ import java.util.Set; import org.bukkit.Bukkit; /** + * ExternalMobProvider instance manager. + * * @author Daniel Saukel */ public class ExternalMobProviders { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java index 79b2e1c2..2a3d07b0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClass.java @@ -29,6 +29,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; /** + * Represents a class and a class script. + * * @author Frank Baumann, Daniel Saukel */ public class DClass { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClasses.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClasses.java index 1de12c19..579e9652 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClasses.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DClasses.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.List; /** + * DClass instance manager. + * * @author Daniel Saukel */ public class DClasses { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java index ea411981..4a891df1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java @@ -33,7 +33,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; /** - * Represents a player in an DEditWorld. + * Represents a player in a DEditWorld. * * @author Daniel Saukel */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index 46827004..21b4adf4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -34,7 +34,6 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; -import org.bukkit.scheduler.BukkitRunnable; /** * Represents a player in the non-DXL worlds of the server. diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index cbc5ac2f..8a73c1a1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -44,6 +44,8 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; /** + * Represents a group of players. + * * @author Frank Baumann, Daniel Saukel */ public class DGroup { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java index 0c9ee584..22e4e5f4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java @@ -21,6 +21,8 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; /** + * Represents a player in an instance. + * * @author Daniel Saukel */ public abstract class DInstancePlayer extends DGlobalPlayer { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java index 8b7cea22..61dca293 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java @@ -23,6 +23,8 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** + * DGlobalPlayer instance manager. + * * @author Daniel Saukel */ public class DPlayers { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java index 7ef734ee..03f9fc4d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/Requirement.java @@ -26,6 +26,8 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; /** + * Extend this to create a custom Requirement. + * * @author Daniel Saukel */ public abstract class Requirement { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementType.java index 58673f0f..afa07d63 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementType.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.requirement; /** + * Implement this to create custom requirement types. + * * @author Daniel Saukel */ public interface RequirementType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java index c4a3a4e0..1a9520b5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.requirement; /** + * Default implementation of RequirementType. + * * @author Daniel Saukel */ public enum RequirementTypeDefault implements RequirementType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypes.java index af0fd890..541b2731 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypes.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.List; /** + * RequirementType instance manager. + * * @author Daniel Saukel */ public class RequirementTypes { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/Reward.java b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/Reward.java index 3e785ebd..74380ed3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/Reward.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/Reward.java @@ -25,6 +25,8 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** + * Extend this to create a custom Reward. + * * @author Daniel Saukel */ public abstract class Reward { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardType.java index e1276978..58e26927 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardType.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.reward; /** + * Implement this to create custom reward types. + * * @author Daniel Saukel */ public interface RewardType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypeDefault.java index adccf29a..c29b719d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypeDefault.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.reward; /** + * Default implementation of RewardType. + * * @author Daniel Saukel */ public enum RewardTypeDefault implements RewardType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java index 82bb20e1..c06062de 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.List; /** + * RewardType instance manager. + * * @author Daniel Saukel */ public class RewardTypes { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSign.java index 39cd1d50..4e26e06e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSign.java @@ -32,6 +32,8 @@ import org.bukkit.block.Sign; import org.bukkit.entity.Player; /** + * Extend this to create a custom DSign. + * * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ public abstract class DSign { @@ -203,7 +205,7 @@ public abstract class DSign { sign.setLine(2, ERROR_2); sign.setLine(3, ERROR_3); sign.update(); - + DMessages.LOG_ERROR_SIGN_SETUP.getMessage(sign.getX() + ", " + sign.getY() + ", " + sign.getZ()); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java index fb5e19de..d081149e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.sign; /** + * Implement this to create custom sign types. + * * @author Daniel Saukel */ public interface DSignType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index 4690b7ea..8910f494 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -19,6 +19,8 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.player.DPermissions; /** + * Default implementation of DSignType. + * * @author Daniel Saukel */ public enum DSignTypeDefault implements DSignType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java index ba1fe6ef..f8ee3b23 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.List; /** + * DSignType instance manager. + * * @author Daniel Saukel */ public class DSignTypes { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScript.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScript.java index bed6f0f8..41b0cdd0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScript.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScript.java @@ -25,6 +25,9 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; /** + * Representation of a sign script. + * Sign scripts allow to merge multiple dungeon signs at one position. + * * @author Daniel Saukel */ public class SignScript { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScripts.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScripts.java index ddb1b237..36088dce 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScripts.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignScripts.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.List; /** + * SignScript instance manager. + * * @author Daniel Saukel */ public class SignScripts { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java index ab912406..18ac75e8 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java @@ -29,6 +29,8 @@ import java.util.Set; import org.bukkit.entity.Player; /** + * Extend this to create a custom Trigger. + * * @author Frank Baumann, Daniel Saukel */ public abstract class Trigger { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerType.java index f869087e..418ceb30 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerType.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerType.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.trigger; /** + * Implement this to create custom trigger types. + * * @author Daniel Saukel */ public interface TriggerType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java index b461cde6..ea13685f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java @@ -17,6 +17,8 @@ package io.github.dre2n.dungeonsxl.trigger; /** + * Default implementation of TriggerType. + * * @author Daniel Saukel */ public enum TriggerTypeDefault implements TriggerType { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java index 965ac63b..76c524ff 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.List; /** + * TriggerType instance manager. + * * @author Daniel Saukel */ public class TriggerTypes { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java b/core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java index b9aef48f..63f9d315 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java @@ -20,6 +20,8 @@ import org.bukkit.ChatColor; import org.bukkit.DyeColor; /** + * Links different color types together. + * * @author Daniel Saukel */ public enum DColor { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/util/ProgressBar.java b/core/src/main/java/io/github/dre2n/dungeonsxl/util/ProgressBar.java index 3e2d4867..93d62940 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/util/ProgressBar.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/util/ProgressBar.java @@ -28,6 +28,8 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; /** + * A boss bar based progress bar. + * * @author Daniel Saukel */ public class ProgressBar extends BukkitRunnable { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DEditWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DEditWorld.java index 7fe6b91f..203daa65 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DEditWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DEditWorld.java @@ -31,6 +31,9 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; /** + * A raw resource world instance to edit the dungeon map. + * There is never more than one DEditWorld per DResourceWorld. + * * @author Frank Baumann, Daniel Saukel */ public class DEditWorld extends DInstanceWorld { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index 84055591..c85ed7e6 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -66,6 +66,9 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; /** + * A playable resource instance. + * There may be any amount of DGameWorlds per DResourceWorld. + * * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ public class DGameWorld extends DInstanceWorld { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java index 84e4ac5a..3f10c676 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java @@ -25,6 +25,8 @@ import org.bukkit.Location; import org.bukkit.World; /** + * An instance of a resource world. + * * @author Daniel Saukel */ public abstract class DInstanceWorld { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java index d8dba9ff..9529f57c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java @@ -30,6 +30,8 @@ import org.bukkit.WorldCreator; import org.bukkit.WorldType; /** + * World instance manager. + * * @author Daniel Saukel */ public class DWorlds { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java index 307d7244..dfa65656 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java @@ -20,6 +20,8 @@ import org.bukkit.block.Block; import org.bukkit.event.block.BlockBreakEvent; /** + * A block that has a special purpose in a game. + * * @author Daniel Saukel */ public abstract class GameBlock { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java index 547e95de..4bbaca58 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java @@ -21,6 +21,8 @@ import org.bukkit.block.BlockFace; import org.bukkit.event.block.BlockBreakEvent; /** + * A locked door that may be opened with a trigger. + * * @author Daniel Saukel */ public class LockedDoor extends GameBlock implements MultiBlock { From 48744a21755529ae3f462bcdedf201bc75aeb5be Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Fri, 2 Sep 2016 20:35:23 +0200 Subject: [PATCH 44/57] Fix /dxl msg if no map config exists; resolves #144 --- .../dre2n/dungeonsxl/command/MsgCommand.java | 2 +- .../dungeonsxl/world/DResourceWorld.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java index 8ca129ab..643dccdc 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java @@ -61,7 +61,7 @@ public class MsgCommand extends BRCommand { try { int id = Integer.parseInt(args[1]); - WorldConfig config = editWorld.getResource().getConfig(); + WorldConfig config = editWorld.getResource().getConfig(true); if (args.length == 2) { String msg = config.getMessage(id); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java index 9375cd6a..02f06c93 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java @@ -25,6 +25,7 @@ import io.github.dre2n.dungeonsxl.player.DEditPlayer; import io.github.dre2n.dungeonsxl.task.BackupResourceTask; import io.github.dre2n.dungeonsxl.util.worldloader.WorldLoader; import java.io.File; +import java.io.IOException; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.WorldCreator; @@ -103,6 +104,27 @@ public class DResourceWorld { * @return the WorldConfig */ public WorldConfig getConfig() { + return getConfig(false); + } + + /** + * @param generate + * if a config should be generated if none exists + * @return the WorldConfig + */ + public WorldConfig getConfig(boolean generate) { + if (config == null) { + File file = new File(folder, "config.yml"); + if (file.exists()) { + try { + file.createNewFile(); + } catch (IOException exception) { + exception.printStackTrace(); + } + } + config = new WorldConfig(file); + } + return config; } From 872fa928d170b809e0b5fd93c4b58dca37f75e96 Mon Sep 17 00:00:00 2001 From: wysohn Date: Fri, 2 Sep 2016 16:47:40 -0700 Subject: [PATCH 45/57] sign need to be handled when it's broken indirect way --- .../dungeonsxl/listener/BlockListener.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java index d639695a..822c33eb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -35,6 +35,7 @@ import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DInstanceWorld; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -50,7 +51,7 @@ import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.SignChangeEvent; /** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel + * @author Frank Baumann, Milan Albrecht, Daniel Saukel, Wooyoung Son */ public class BlockListener implements Listener { @@ -64,6 +65,28 @@ public class BlockListener implements Listener { } } + @EventHandler + public void onBreakWithSignOnIt(BlockBreakEvent event){ + Block block = event.getBlock(); + Player player = event.getPlayer(); + + Block blockAbove = block.getRelative(BlockFace.UP); + //get the above block and return if there is nothing + if(blockAbove == null) + return; + + //return if above block is not a sign + if(blockAbove.getType() != Material.SIGN_POST && blockAbove.getType() != Material.WALL_SIGN) + return; + + //let onBreak() method to handle the sign + BlockBreakEvent bbe = new BlockBreakEvent(blockAbove, player); + onBreak(bbe); + + //follow the onBreak() + event.setCancelled(bbe.isCancelled()); + } + @EventHandler(priority = EventPriority.HIGH) public void onBreak(BlockBreakEvent event) { Block block = event.getBlock(); From 941831643ca7bfa1471998d3a925ae699fc1af6f Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sat, 10 Sep 2016 14:01:11 +0200 Subject: [PATCH 46/57] Fix play command; resolves #151 --- .../dre2n/dungeonsxl/command/EditCommand.java | 10 +++---- .../dungeonsxl/command/LeaveCommand.java | 3 +-- .../dre2n/dungeonsxl/command/PlayCommand.java | 27 +++++++------------ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java index f0d8475a..e16f8c41 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java @@ -63,15 +63,15 @@ public class EditCommand extends BRCommand { return; } - DEditWorld editWorld = resource.instantiateAsEditWorld(); - DGroup dGroup = DGroup.getByPlayer(player); - DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); - - if (!(resource.isInvitedPlayer(player) || DPermissions.hasPermission(player, DPermissions.EDIT))) { + if (!resource.isInvitedPlayer(player) && !DPermissions.hasPermission(player, DPermissions.EDIT)) { MessageUtil.sendMessage(player, DMessages.ERROR_NO_PERMISSIONS.getMessage()); return; } + DEditWorld editWorld = resource.instantiateAsEditWorld(); + DGroup dGroup = DGroup.getByPlayer(player); + DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); + if (dPlayer instanceof DInstancePlayer) { MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage()); return; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java index f96a57cb..e5c120a4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java @@ -29,7 +29,6 @@ import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; -import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -55,7 +54,7 @@ public class LeaveCommand extends BRCommand { DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); Game game = Game.getByPlayer(player); - if (game.isTutorial()) { + if (game != null && game.isTutorial()) { MessageUtil.sendMessage(player, DMessages.ERROR_NO_LEAVE_IN_TUTORIAL.getMessage()); return; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java index 51c532f0..0c10c0b8 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -25,7 +25,9 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DGroup; +import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -49,9 +51,9 @@ public class PlayCommand extends BRCommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); - if (dPlayer != null) { + if (dPlayer instanceof DInstancePlayer) { MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage()); return; } @@ -70,7 +72,7 @@ public class PlayCommand extends BRCommand { mapName = identifier; if (args[1].equalsIgnoreCase("dungeon") || args[1].equalsIgnoreCase("d")) { Dungeon dungeon = plugin.getDungeons().getByName(args[2]); - if (dungeon != null) { + if (dungeon != null && dungeon.isMultiFloor()) { multiFloor = true; mapName = dungeon.getConfig().getStartFloor().getName(); } else { @@ -96,20 +98,9 @@ public class PlayCommand extends BRCommand { } if (dGroup.getMapName() == null) { - if (!multiFloor) { - dGroup.setMapName(identifier); - - } else { + dGroup.setMapName(mapName); + if (multiFloor) { dGroup.setDungeonName(identifier); - Dungeon dungeon = plugin.getDungeons().getByName(identifier); - - if (dungeon != null) { - DungeonConfig config = dungeon.getConfig(); - - if (config != null) { - dGroup.setMapName(config.getStartFloor().getName()); - } - } } } else { @@ -134,11 +125,11 @@ public class PlayCommand extends BRCommand { } if (dGroup.getGameWorld() == null) { - new Game(dGroup, dGroup.getMapName()); + new Game(dGroup, mapName); } if (dGroup.getGameWorld() == null) { - MessageUtil.sendMessage(player, DMessages.ERROR_NOT_SAVED.getMessage(DGroup.getByPlayer(player).getMapName())); + MessageUtil.sendMessage(player, DMessages.ERROR_NOT_SAVED.getMessage(mapName)); dGroup.delete(); return; } From 6224c931db298627ca2cdb01e975424998d58e77 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 11 Sep 2016 14:35:52 +0200 Subject: [PATCH 47/57] Fix loading order; resolves #156 --- .../main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java | 8 ++++---- .../io/github/dre2n/dungeonsxl/command/PlayCommand.java | 1 - .../io/github/dre2n/dungeonsxl/config/DMessages.java | 3 ++- .../io/github/dre2n/dungeonsxl/dungeon/Dungeons.java | 9 +++------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 6bef52ee..95b6e1c6 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -266,7 +266,8 @@ public class DungeonsXL extends BRPlugin { loadRewardTypes(); loadTriggers(); loadDSigns(); - loadDungeons(); + loadDWorlds(MAPS); + loadDungeons(DUNGEONS); loadGlobalProtections(); loadExternalMobProviders(); loadDPlayers(); @@ -275,7 +276,6 @@ public class DungeonsXL extends BRPlugin { loadDLootTables(LOOT_TABLES); loadDMobTypes(MOBS); loadSignScripts(SIGNS); - loadDWorlds(MAPS); loadDCommands(); } @@ -446,8 +446,8 @@ public class DungeonsXL extends BRPlugin { /** * load / reload a new instance of Dungeons */ - public void loadDungeons() { - dungeons = new Dungeons(); + public void loadDungeons(File file) { + dungeons = new Dungeons(file); } /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java index 0c10c0b8..cdf3b311 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -20,7 +20,6 @@ import io.github.dre2n.commons.command.BRCommand; 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.DungeonConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.game.Game; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 1385c0b3..a6764fb5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -157,7 +157,8 @@ public enum DMessages implements Messages { GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"), GROUP_WAVE_FINISHED("Group_WaveFinished", "&6Your group finished wave no. &4&v1&6. The next one is going to start in &4&v2&6 seconds."), LOG_DISABLED_TWEAKS("Log_DisabledTweaks", "&4Disabled performance tweaks because there is no support for this server software."), - LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"), + LOG_ERROR_DUNGEON_SETUP("Log_Error_DungeonSetup", "&4The setup of dungeon &6&v1&4 is incorrect. See https://github.com/DRE2N/DungeonsXL/wiki/dungeon-configuration for reference."), + LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4An error occurred while loading mob.yml: Enchantment &6&v1&4 doesn't exist!"), LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"), LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as console!"), LOG_ERROR_SIGN_SETUP("Log_Error_SignSetup", "&4A sign at &6&v1&4 is erroneous!"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java index 673285d0..638cd2ef 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java @@ -16,7 +16,8 @@ */ package io.github.dre2n.dungeonsxl.dungeon; -import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.config.DMessages; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -30,10 +31,6 @@ public class Dungeons { private List dungeons = new ArrayList<>(); - public Dungeons() { - this(DungeonsXL.DUNGEONS); - } - public Dungeons(File folder) { if (!folder.exists()) { folder.mkdir(); @@ -46,7 +43,7 @@ public class Dungeons { dungeons.add(dungeon); } else { - // debug + MessageUtil.log(DMessages.LOG_ERROR_DUNGEON_SETUP.getMessage(file.getName())); } } } From cd8af052278a9bce2be1d16c3dc3b573c23350c0 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 11 Sep 2016 22:20:29 +0200 Subject: [PATCH 48/57] #154: ResourcePackAPI integration --- README.md | 4 ++++ pom.xml | 11 ++++++++++- shade/pom.xml | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60865bf5..b78fc0b7 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ DungeonsXL also provides custom game mechanics to make these worlds interesting. * Different game types allow you to use your maps dynamically for different purposes. [Read more...](../../wiki/game-types) * Announcements sothat users can join the next match easily. [Read more...](../../wiki/announcements) * Great performance due to a custom, asynchronous world loading and creation method and several other performance tweaks +* Per dungeon resource packs * ...and many more! @@ -72,6 +73,9 @@ Maven automatically fetches all dependencies and builds DungeonsXL; just run _bu #### Caliburn API [Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.2.1. +#### ResourcePackAPI +inventivetalent's [ResourcePackAPI](https://www.spigotmc.org/resources/api-resourcepackapi-1-7-1-8-1-9-1-10.2397/) is an API to set the resourcepack of a player. DungeonsXL contains ResourcePackAPI 2.2.1. + ### Java Make sure that your server uses Java 7 or higher. diff --git a/pom.xml b/pom.xml index 6b9b62e3..5b3a2ba7 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ io.github.dre2n caliburn - 0.2 + 0.2.1 io.github.dre2n @@ -74,6 +74,11 @@ 2.6.9 provided + + org.inventivetalent.resourcepackapi + api + 2.2.1 + @@ -92,6 +97,10 @@ betonquest-repo http://betonquest.betoncraft.pl/mvn + + inventive-repo + http://repo.inventivetalent.org/content/groups/public/ + dre2n-repo http://feuerstern.bplaced.net/repo/ diff --git a/shade/pom.xml b/shade/pom.xml index 23b07e46..f2dad90d 100644 --- a/shade/pom.xml +++ b/shade/pom.xml @@ -29,6 +29,10 @@ io.github.dre2n.commons io.github.dre2n.dungeonsxl.util.commons + + org.inventivetalent.rpapi + io.github.dre2n.dungeonsxl.util.resourcepackapi + @@ -36,6 +40,7 @@ io.github.dre2n:caliburn io.github.dre2n:debukkit io.github.dre2n:dungeonsxl-* + org.inventivetalent.resourcepackapi:api From 65cb1ebd16ece8ae0f5b890b34070248f8ee95f4 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 11 Sep 2016 22:20:52 +0200 Subject: [PATCH 49/57] #154: Resource pack signs --- .../dre2n/dungeonsxl/config/MainConfig.java | 18 ++- .../dungeonsxl/sign/DSignTypeDefault.java | 1 + .../dungeonsxl/sign/ResourcePackSign.java | 104 ++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index 57883c00..e80f8efb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -45,7 +45,7 @@ public class MainConfig extends BRConfig { NEVER } - public static final int CONFIG_VERSION = 12; + public static final int CONFIG_VERSION = 13; private String language = "english"; private boolean enableEconomy = false; @@ -79,6 +79,7 @@ public class MainConfig extends BRConfig { /* Misc */ private boolean sendFloorTitle = true; private Map externalMobProviders = new HashMap<>(); + private Map resourcePacks = new HashMap<>(); /* Performance */ private int maxInstances = 10; @@ -249,6 +250,13 @@ public class MainConfig extends BRConfig { return externalMobProviders; } + /** + * @return the resource pack index + */ + public Map getResourcePacks() { + return resourcePacks; + } + /** * @return the maximum amount of worlds to instantiate at once */ @@ -422,6 +430,10 @@ public class MainConfig extends BRConfig { config.createSection("externalMobProviders"); } + if (!config.contains("resourcePacks")) { + config.createSection("resourcePacks"); + } + if (!config.contains("maxInstances")) { config.set("maxInstances", maxInstances); } @@ -514,6 +526,10 @@ public class MainConfig extends BRConfig { externalMobProviders = config.getConfigurationSection("externalMobProviders").getValues(false); } + if (config.contains("resourcePacks")) { + resourcePacks = config.getConfigurationSection("resourcePacks").getValues(false); + } + if (config.contains("maxInstances")) { maxInstances = config.getInt("maxInstances"); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index 8910f494..9134c3e4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -52,6 +52,7 @@ public enum DSignTypeDefault implements DSignType { PROTECTION("Protection", "protection", false, false, ProtectionSign.class), READY("Ready", "ready", true, true, ReadySign.class), REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class), + RESOURCE_PACK("ResourcePack", "resourcepack", true, true, ResourcePackSign.class), SCRIPT("Script", "script", false, false, ScriptSign.class), SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class), START("Start", "start", true, false, StartSign.class), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java new file mode 100644 index 00000000..c99c1973 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.inventivetalent.rpapi.ResourcePackAPI; + +/** + * @author Daniel Saukel + */ +public class ResourcePackSign extends DSign { + + private DSignType type = DSignTypeDefault.RESOURCE_PACK; + + private String resourcePack; + + public ResourcePackSign(Sign sign, String[] lines, DGameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* Getters and setters */ + @Override + public DSignType getType() { + return type; + } + + /** + * @return the external mob + */ + public String getResourcePack() { + return resourcePack; + } + + /** + * @param resourcePack + * the resource pack to set + */ + public void setExternalMob(String resourcePack) { + this.resourcePack = resourcePack; + } + + /* Actions */ + @Override + public boolean check() { + return plugin.getMainConfig().getResourcePacks().get(lines[1]) != null; + } + + @Override + public void onInit() { + Object url = plugin.getMainConfig().getResourcePacks().get(lines[1]); + + if (url instanceof String) { + resourcePack = (String) url; + + } else { + markAsErroneous(); + return; + } + + if (!getTriggers().isEmpty()) { + getSign().getBlock().setType(Material.AIR); + return; + } + + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + if (trigger != null) { + trigger.addListener(this); + addTrigger(trigger); + } + + String name = lines[1]; + getSign().setLine(0, ChatColor.DARK_BLUE + "############"); + getSign().setLine(1, ChatColor.DARK_GREEN + "Download"); + getSign().setLine(2, ChatColor.DARK_GREEN + name); + getSign().setLine(3, ChatColor.DARK_BLUE + "############"); + getSign().update(); + } + + @Override + public boolean onPlayerTrigger(Player player) { + ResourcePackAPI.setResourcepack(player, resourcePack); + return true; + } + +} From 7066c113b7a0a6df65e8446ebcd2e147f9c75119 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 11 Sep 2016 22:51:59 +0200 Subject: [PATCH 50/57] #154: Added command to download registered RPs --- .../dre2n/dungeonsxl/command/DCommands.java | 2 + .../command/ResourcePackCommand.java | 57 +++++++++++++++++++ .../dre2n/dungeonsxl/player/DPermissions.java | 1 + 3 files changed, 60 insertions(+) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java index c1d97e11..05e41a3a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java @@ -48,6 +48,7 @@ public class DCommands extends BRCommands { public static PlayCommand PLAY = new PlayCommand(); public static PortalCommand PORTAL = new PortalCommand(); public static ReloadCommand RELOAD = new ReloadCommand(); + public static ResourcePackCommand RESOURCE_PACK = new ResourcePackCommand(); public static RewardsCommand REWARDS = new RewardsCommand(); public static SaveCommand SAVE = new SaveCommand(); public static StatusCommand STATUS = new StatusCommand(); @@ -78,6 +79,7 @@ public class DCommands extends BRCommands { PLAY, PORTAL, RELOAD, + RESOURCE_PACK, REWARDS, SAVE, STATUS, diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java new file mode 100644 index 00000000..0043b43a --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.command; + +import io.github.dre2n.commons.command.BRCommand; +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.player.DPermissions; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.inventivetalent.rpapi.ResourcePackAPI; + +/** + * @author Daniel Saukel + */ +public class ResourcePackCommand extends BRCommand { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + public ResourcePackCommand() { + setCommand("resourcepack"); + setMinArgs(1); + setMaxArgs(1); + setHelp(DMessages.HELP_CMD_RESOURCE_PACK.getMessage()); + setPermission(DPermissions.RESOURCE_PACK.getNode()); + setPlayerCommand(true); + } + + @Override + public void onExecute(String[] args, CommandSender sender) { + Player player = (Player) sender; + + String url = (String) plugin.getMainConfig().getResourcePacks().get(args[1]); + if (url == null) { + MessageUtil.sendMessage(sender, DMessages.ERROR_NO_SUCH_RESOURCE_PACK.getMessage(args[1])); + return; + } + + ResourcePackAPI.setResourcepack(player, url); + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java index a5955413..3f345d4a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java @@ -59,6 +59,7 @@ public enum DPermissions { PLAY("play", OP), PORTAL("portal", OP), RELOAD("reload", OP), + RESOURCE_PACK("resourcepack", OP), REWARDS("rewards", TRUE), SAVE("save", OP), STATUS("status", OP), From c79867d44cda3ef7591fa19d5854f52de90a8cce Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 13 Sep 2016 18:39:22 +0200 Subject: [PATCH 51/57] #154: Added reset function --- .../dre2n/dungeonsxl/command/ResourcePackCommand.java | 6 ++++++ .../io/github/dre2n/dungeonsxl/config/DMessages.java | 2 ++ .../github/dre2n/dungeonsxl/sign/ResourcePackSign.java | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java index 0043b43a..6caf1a9c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java @@ -45,6 +45,12 @@ public class ResourcePackCommand extends BRCommand { public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; + if (args[1].equalsIgnoreCase("reset")) { + // Placeholder to reset to default + ResourcePackAPI.setResourcepack(player, "http://google.com"); + return; + } + String url = (String) plugin.getMainConfig().getResourcePacks().get(args[1]); if (url == null) { MessageUtil.sendMessage(sender, DMessages.ERROR_NO_SUCH_RESOURCE_PACK.getMessage(args[1])); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index a6764fb5..ebe2078c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -85,6 +85,7 @@ public enum DMessages implements Messages { ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"), ERROR_NO_SUCH_MAP("Error_NoSuchMap", "&4The world &6&v1&4 does not exist!"), ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"), + ERROR_NO_SUCH_RESOURCE_PACK("Error_NoSuchResourcePack", "&4The resource pack &6&v1 &4is not registered in the main configuration file!"), ERROR_NO_SUCH_SHOP("Error_NoSuchShop", "&4Shop &v1 &4not found..."), ERROR_NOT_CAPTAIN("Error_NotCaptain", "&4You are not the captain of your group!"), ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"), @@ -130,6 +131,7 @@ public enum DMessages implements Messages { HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal ([material=portal])- Creates a portal that leads into a dungeon"), HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"), HELP_CMD_REWARDS("Help_Cmd_Rewards", "/dxl rewards - Gives all left item rewards to the player"), + HELP_CMD_RESOURCE_PACK("Help_Cmd_ResourcePack", "/dxl resourcepack [ID] - Downloads a resourcepack registered in the main configuration file; use 'reset' to reset"), HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"), HELP_CMD_STATUS("Help_Cmd_Status", "/dxl status - Shows the technical status of DungeonsXL"), HELP_CMD_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java index c99c1973..e16436fe 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java @@ -61,12 +61,18 @@ public class ResourcePackSign extends DSign { /* Actions */ @Override public boolean check() { - return plugin.getMainConfig().getResourcePacks().get(lines[1]) != null; + return plugin.getMainConfig().getResourcePacks().get(lines[1]) != null || lines[1].equalsIgnoreCase("reset"); } @Override public void onInit() { - Object url = plugin.getMainConfig().getResourcePacks().get(lines[1]); + Object url = null; + if (lines[1].equalsIgnoreCase("reset")) { + // Placeholder to reset to default + url = "http://google.com"; + } else { + url = plugin.getMainConfig().getResourcePacks().get(lines[1]); + } if (url instanceof String) { resourcePack = (String) url; From 9bfa5876d2dd1a0ff42b4aded2995501044b0dbe Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 27 Sep 2016 12:51:58 +0200 Subject: [PATCH 52/57] Fix 1.8.x- PvE exception; resolves #162 --- core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 95b6e1c6..887ef0f0 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -253,7 +253,9 @@ public class DungeonsXL extends BRPlugin { } public void loadCore() { - loadCaliburnAPI(); + if (Internals.andHigher(Internals.v1_9_R1).contains(compat.getInternals())) { + loadCaliburnAPI(); + } // Load Language loadMessageConfig(new File(LANGUAGES, "english.yml")); // Load Config From 2c1ff4af65e3c3d45ae20e175b3af556c3a3512a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 27 Sep 2016 13:14:29 +0200 Subject: [PATCH 53/57] Backwards compatibility fix --- .../io/github/dre2n/dungeonsxl/command/EditCommand.java | 1 + .../java/io/github/dre2n/dungeonsxl/config/PlayerData.java | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java index e16f8c41..a37b3b82 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java @@ -63,6 +63,7 @@ public class EditCommand extends BRCommand { return; } + org.bukkit.Bukkit.broadcastMessage(resource.getConfig().getInvitedPlayers().toString()); if (!resource.isInvitedPlayer(player) && !DPermissions.hasPermission(player, DPermissions.EDIT)) { MessageUtil.sendMessage(player, DMessages.ERROR_NO_PERMISSIONS.getMessage()); return; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java index c0eb556c..47718931 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java @@ -16,6 +16,8 @@ */ package io.github.dre2n.dungeonsxl.config; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Internals; import io.github.dre2n.commons.config.BRConfig; import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; @@ -42,6 +44,7 @@ import org.bukkit.potion.PotionEffect; public class PlayerData extends BRConfig { DungeonsXL plugin = DungeonsXL.getInstance(); + boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals()); public static final int CONFIG_VERSION = 2; @@ -379,7 +382,9 @@ public class PlayerData extends BRConfig { oldLvl = player.getLevel(); oldArmor = new ArrayList<>(Arrays.asList(player.getInventory().getArmorContents())); oldInventory = new ArrayList<>(Arrays.asList(player.getInventory().getContents())); - oldOffHand = player.getInventory().getItemInOffHand(); + if (is1_9) { + oldOffHand = player.getInventory().getItemInOffHand(); + } oldLocation = player.getLocation(); oldPotionEffects = player.getActivePotionEffects(); From b14ed1fd97bdce1c431ea00f77e9cadd7aeec71c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 28 Sep 2016 17:21:26 +0200 Subject: [PATCH 54/57] Fix invitation system; resolves #141 --- .../java/io/github/dre2n/dungeonsxl/command/EditCommand.java | 1 - .../io/github/dre2n/dungeonsxl/command/InviteCommand.java | 3 ++- .../io/github/dre2n/dungeonsxl/command/UninviteCommand.java | 1 + .../java/io/github/dre2n/dungeonsxl/config/DMessages.java | 4 ++-- .../java/io/github/dre2n/dungeonsxl/config/WorldConfig.java | 4 +++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java index a37b3b82..e16f8c41 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/EditCommand.java @@ -63,7 +63,6 @@ public class EditCommand extends BRCommand { return; } - org.bukkit.Bukkit.broadcastMessage(resource.getConfig().getInvitedPlayers().toString()); if (!resource.isInvitedPlayer(player) && !DPermissions.hasPermission(player, DPermissions.EDIT)) { MessageUtil.sendMessage(player, DMessages.ERROR_NO_PERMISSIONS.getMessage()); return; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/InviteCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/InviteCommand.java index e6b39ff8..90b19bee 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/InviteCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/InviteCommand.java @@ -46,10 +46,11 @@ public class InviteCommand extends BRCommand { @Override public void onExecute(String[] args, CommandSender sender) { DResourceWorld resource = plugin.getDWorlds().getResourceByName(args[2]); - OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]); + OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (resource != null) { if (player != null) { + resource.addInvitedPlayer(player); MessageUtil.sendMessage(sender, DMessages.CMD_INVITE_SUCCESS.getMessage(args[1], args[2])); } else { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/UninviteCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/UninviteCommand.java index 2594d2bf..e83247d1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/UninviteCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/UninviteCommand.java @@ -48,6 +48,7 @@ public class UninviteCommand extends BRCommand { DResourceWorld resource = plugin.getDWorlds().getResourceByName(args[2]); if (resource == null) { MessageUtil.sendMessage(sender, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage(args[2])); + return; } OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index ebe2078c..7c8c08b2 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -54,7 +54,7 @@ public enum DMessages implements Messages { CMD_MSG_UPDATED("Cmd_Msg_Updated", "&6Messages (&4&v1&6) updated!"), CMD_RELOAD_DONE("Cmd_Reload_Done", "&7Successfully reloaded DungeonsXL."), CMD_SAVE_SUCCESS("Cmd_Save_Success", "&6Map saved!"), - CMD_UNINVITE_SUCCESS("Cmd_Uninvite_Success", "&4&v1&6 was successfully uninvited to edit the map &4&v1&6!"), + CMD_UNINVITE_SUCCESS("Cmd_Uninvite_Success", "&4&v1&6's permission to edit the map &4&v2&6 has been removed successfully."), ERROR_BED("Error_Bed", "&4You cannot use a bed while in a dungeon!"), ERROR_CHEST_IS_OPENED("Error_ChestIsOpened", "&4This chest has already been opened."), ERROR_CMD("Error_Cmd", "&4Commands are not allowed while in a dungeon!"), @@ -78,7 +78,7 @@ public enum DMessages implements Messages { ERROR_NO_CONSOLE_COMMAND("Error_NoConsoleCommand", "&6/dxl &v1&4 cannot be executed as console!"), ERROR_NO_GAME("Error_NoGame", "&4You currently do not take part in a game."), ERROR_NO_LEAVE_IN_TUTORIAL("Error_NoLeaveInTutorial", "&4You cannot use this command in the tutorial!"), - ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You have no permission to do this!"), + ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You do not have permission to do this!"), ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"), ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"), ERROR_NO_REWARDS_LEFT("Error_NoRewardsLeft", "&4You do not have any item rewards left."), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index 0020635a..83ccafbb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -311,7 +311,9 @@ public class WorldConfig extends GameRules { * the player's unique ID */ public void addInvitedPlayer(String uuid) { - invitedPlayers.add(uuid); + if (!invitedPlayers.contains(uuid)) { + invitedPlayers.add(uuid); + } } /** From cfec0229a70773d2f3fbdbefbe05f2be691d80b6 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 14 Nov 2016 19:13:58 +0100 Subject: [PATCH 55/57] Initial update to 1.11 --- abstract/pom.xml | 2 +- core/pom.xml | 9 +- .../util/worldloader/WorldLoader.java | 3 + craftbukkit_1_10_R1/pom.xml | 2 +- craftbukkit_1_11_R1/pom.xml | 40 ++++ .../dungeonsxl/util/worldloader/v1_11_R1.java | 199 ++++++++++++++++++ craftbukkit_1_9_R1/pom.xml | 2 +- craftbukkit_1_9_R2/pom.xml | 2 +- pom.xml | 9 +- shade/pom.xml | 9 +- 10 files changed, 267 insertions(+), 10 deletions(-) create mode 100644 craftbukkit_1_11_R1/pom.xml create mode 100644 craftbukkit_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/v1_11_R1.java diff --git a/abstract/pom.xml b/abstract/pom.xml index 924caced..6c1df67b 100644 --- a/abstract/pom.xml +++ b/abstract/pom.xml @@ -8,6 +8,6 @@ io.github.dre2n dungeonsxl - 0.15-SNAPSHOT + 0.15 diff --git a/core/pom.xml b/core/pom.xml index 6bfb8d3e..7001bd95 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.15-SNAPSHOT + 0.15 @@ -40,6 +40,13 @@ jar compile + + io.github.dre2n + dungeonsxl-craftbukkit_1_11_R1 + ${parent.version} + jar + compile + io.github.dre2n dungeonsxl-craftbukkit_1_10_R1 diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/WorldLoader.java b/core/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/WorldLoader.java index 36ffcb41..27c6a8e4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/WorldLoader.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/WorldLoader.java @@ -31,6 +31,9 @@ public class WorldLoader { static { switch (CompatibilityHandler.getInstance().getInternals()) { + case v1_11_R1: + internals = new v1_11_R1(); + break; case v1_10_R1: internals = new v1_10_R1(); break; diff --git a/craftbukkit_1_10_R1/pom.xml b/craftbukkit_1_10_R1/pom.xml index df616a42..7177d9b2 100644 --- a/craftbukkit_1_10_R1/pom.xml +++ b/craftbukkit_1_10_R1/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.15-SNAPSHOT + 0.15 diff --git a/craftbukkit_1_11_R1/pom.xml b/craftbukkit_1_11_R1/pom.xml new file mode 100644 index 00000000..f4eb7f5e --- /dev/null +++ b/craftbukkit_1_11_R1/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + io.github.dre2n + dungeonsxl-craftbukkit_1_11_R1 + ${parent.version} + jar + dungeonsxl-craftbukkit_1_11_R1 + + io.github.dre2n + dungeonsxl + 0.15 + + + + + maven-compiler-plugin + 2.5.1 + + 1.7 + 1.7 + + + + + + + org.bukkit + craftbukkit + 1.11.2-R0.1-SNAPSHOT + provided + + + io.github.dre2n + dungeonsxl-abstract + ${parent.version} + jar + compile + + + diff --git a/craftbukkit_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/v1_11_R1.java b/craftbukkit_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/v1_11_R1.java new file mode 100644 index 00000000..c4222a00 --- /dev/null +++ b/craftbukkit_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/worldloader/v1_11_R1.java @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.util.worldloader; + +import java.io.File; +import java.lang.reflect.Field; +import java.util.Map; +import java.util.logging.Logger; +import net.minecraft.server.v1_11_R1.BlockPosition; +import net.minecraft.server.v1_11_R1.Convertable; +import net.minecraft.server.v1_11_R1.EntityTracker; +import net.minecraft.server.v1_11_R1.EnumDifficulty; +import net.minecraft.server.v1_11_R1.EnumGamemode; +import net.minecraft.server.v1_11_R1.IDataManager; +import net.minecraft.server.v1_11_R1.IProgressUpdate; +import net.minecraft.server.v1_11_R1.MinecraftServer; +import net.minecraft.server.v1_11_R1.ServerNBTManager; +import net.minecraft.server.v1_11_R1.WorldData; +import net.minecraft.server.v1_11_R1.WorldLoaderServer; +import net.minecraft.server.v1_11_R1.WorldManager; +import net.minecraft.server.v1_11_R1.WorldServer; +import net.minecraft.server.v1_11_R1.WorldSettings; +import net.minecraft.server.v1_11_R1.WorldType; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.craftbukkit.v1_11_R1.CraftServer; +import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; +import org.bukkit.event.world.WorldInitEvent; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.PluginManager; + +/** + * @author Daniel Saukel + */ +public class v1_11_R1 extends InternalsProvider { + + MinecraftServer console; + CraftServer server = ((CraftServer) Bukkit.getServer()); + Map worlds; + PluginManager pluginManager = Bukkit.getPluginManager(); + File worldContainer = Bukkit.getWorldContainer(); + Logger logger = Bukkit.getLogger(); + + v1_11_R1() { + try { + Field fConsole = CraftServer.class.getDeclaredField("console"); + fConsole.setAccessible(true); + console = (MinecraftServer) fConsole.get(server); + + Field fWorlds = CraftServer.class.getDeclaredField("worlds"); + fWorlds.setAccessible(true); + worlds = (Map) fWorlds.get(server); + + } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) { + exception.printStackTrace(); + } + } + + @SuppressWarnings("deprecation") + @Override + World createWorld(WorldCreator creator) { + String name = creator.name(); + ChunkGenerator generator = creator.generator(); + File folder = new File(worldContainer, name); + World world = Bukkit.getWorld(name); + WorldType type = WorldType.getType(creator.type().getName()); + boolean generateStructures = creator.generateStructures(); + + if (world != null) { + return world; + } + + if ((folder.exists()) && (!folder.isDirectory())) { + throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); + } + + if (generator == null) { + generator = server.getGenerator(name); + } + + Convertable converter = new WorldLoaderServer(worldContainer, server.getHandle().getServer().getDataConverterManager()); + if (converter.isConvertable(name)) { + logger.info("Converting world '" + name + "'"); + converter.convert(name, new IProgressUpdate() { + private long b = System.currentTimeMillis(); + + @Override + public void a(String s) { + } + + @Override + public void a(int i) { + if (System.currentTimeMillis() - this.b >= 1000L) { + this.b = System.currentTimeMillis(); + MinecraftServer.LOGGER.info("Converting... " + i + "%"); + } + + } + + @Override + public void c(String s) { + } + }); + } + + int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + console.worlds.size(); + boolean used = false; + do { + for (WorldServer server : console.worlds) { + used = server.dimension == dimension; + if (used) { + dimension++; + break; + } + } + } while (used); + boolean hardcore = false; + + IDataManager sdm = new ServerNBTManager(worldContainer, name, true, server.getHandle().getServer().getDataConverterManager()); + WorldData worlddata = sdm.getWorldData(); + WorldSettings worldSettings = null; + if (worlddata == null) { + worldSettings = new WorldSettings(creator.seed(), EnumGamemode.getById(server.getDefaultGameMode().getValue()), generateStructures, hardcore, type); + worldSettings.setGeneratorSettings(creator.generatorSettings()); + worlddata = new WorldData(worldSettings, name); + } + worlddata.checkName(name); // CraftBukkit - Migration did not rewrite the level.dat; This forces 1.8 to take the last loaded world as respawn (in this case the end) + WorldServer internal = (WorldServer) new WorldServer(console, sdm, worlddata, dimension, console.methodProfiler, creator.environment(), generator).b(); + + if (!(worlds.containsKey(name.toLowerCase(java.util.Locale.ENGLISH)))) { + return null; + } + + if (worldSettings != null) { + internal.a(worldSettings); + } + internal.scoreboard = server.getScoreboardManager().getMainScoreboard().getHandle(); + + internal.tracker = new EntityTracker(internal); + internal.addIWorldAccess(new WorldManager(console, internal)); + internal.worldData.setDifficulty(EnumDifficulty.EASY); + internal.setSpawnFlags(true, true); + console.worlds.add(internal); + + if (generator != null) { + internal.getWorld().getPopulators().addAll(generator.getDefaultPopulators(internal.getWorld())); + } + + pluginManager.callEvent(new WorldInitEvent(internal.getWorld())); + logger.info("Preparing start region for level " + (console.worlds.size() - 1) + " (Seed: " + internal.getSeed() + ")"); + + if (internal.getWorld().getKeepSpawnInMemory()) { + short short1 = 196; + long i = System.currentTimeMillis(); + for (int j = -short1; j <= short1; j += 16) { + for (int k = -short1; k <= short1; k += 16) { + long l = System.currentTimeMillis(); + + if (l < i) { + i = l; + } + + if (l > i + 1000L) { + int i1 = (short1 * 2 + 1) * (short1 * 2 + 1); + int j1 = (j + short1) * (short1 * 2 + 1) + k + 1; + + logger.info("Preparing spawn area for " + name + ", " + (j1 * 100 / i1) + "%"); + i = l; + } + + BlockPosition chunkcoordinates = internal.getSpawn(); + try { + internal.getChunkProviderServer().getChunkAt(chunkcoordinates.getX() + j >> 4, chunkcoordinates.getZ() + k >> 4); + } catch (Exception exception) { + } + } + } + } + pluginManager.callEvent(new WorldLoadEvent(internal.getWorld())); + return internal.getWorld(); + } + +} diff --git a/craftbukkit_1_9_R1/pom.xml b/craftbukkit_1_9_R1/pom.xml index d3be7605..5f714f93 100644 --- a/craftbukkit_1_9_R1/pom.xml +++ b/craftbukkit_1_9_R1/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.15-SNAPSHOT + 0.15 diff --git a/craftbukkit_1_9_R2/pom.xml b/craftbukkit_1_9_R2/pom.xml index b1e69498..9ef911b1 100644 --- a/craftbukkit_1_9_R2/pom.xml +++ b/craftbukkit_1_9_R2/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.15-SNAPSHOT + 0.15 diff --git a/pom.xml b/pom.xml index 5b3a2ba7..6086ffaa 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.github.dre2n dungeonsxl - 0.15-SNAPSHOT + 0.15 pom DungeonsXL https://dre2n.github.io @@ -15,6 +15,7 @@ shade core abstract + craftbukkit_1_11_R1 craftbukkit_1_10_R1 craftbukkit_1_9_R2 craftbukkit_1_9_R1 @@ -23,7 +24,7 @@ org.spigotmc spigot-api - 1.10.2-R0.1-SNAPSHOT + 1.11.2-R0.1-SNAPSHOT provided @@ -35,7 +36,7 @@ io.github.dre2n commons - 1.0.1 + 1.0.2 io.github.dre2n @@ -45,7 +46,7 @@ io.github.dre2n caliburn - 0.2.1 + 0.2.2 io.github.dre2n diff --git a/shade/pom.xml b/shade/pom.xml index f2dad90d..7dc80d1e 100644 --- a/shade/pom.xml +++ b/shade/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.15-SNAPSHOT + 0.15 dungeonsxl-${project.version}${buildNo} @@ -64,6 +64,13 @@ jar compile + + io.github.dre2n + dungeonsxl-craftbukkit_1_11_R1 + ${parent.version} + jar + compile + io.github.dre2n dungeonsxl-craftbukkit_1_10_R1 From 3bf7393b8b98c7502202d4435e8f472994fbec87 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 17 Nov 2016 16:15:37 +0100 Subject: [PATCH 56/57] Update to 1.11 --- craftbukkit_1_11_R1/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/craftbukkit_1_11_R1/pom.xml b/craftbukkit_1_11_R1/pom.xml index f4eb7f5e..dc781795 100644 --- a/craftbukkit_1_11_R1/pom.xml +++ b/craftbukkit_1_11_R1/pom.xml @@ -26,7 +26,7 @@ org.bukkit craftbukkit - 1.11.2-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index 6086ffaa..ac8b35e5 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.spigotmc spigot-api - 1.11.2-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT provided From 1ee50390c626af881475026926be338b735a1ca3 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 17 Nov 2016 16:25:20 +0100 Subject: [PATCH 57/57] Update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b78fc0b7..7bf01009 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,10 @@ If you want to learn how to use DungeonsXL step by step, please have a look at t ## Compatibility ### Server -DungeonsXL works with 1.7.8 and higher. However, support for 1.10.x / 1.9.x has a higher priority than support for 1.8.x and lower. See [here](../../wiki/legacy-support) for detailed information. Some cosmetic features require the Spigot API and will therefore not work with CraftBukkit. +DungeonsXL works with 1.7.8 and higher. However, support for 1.11 / 1.10.x / 1.9.x has a higher priority than support for 1.8.x and lower. See [here](../../wiki/legacy-support) for detailed information. Some cosmetic features require the Spigot API and will therefore not work with CraftBukkit. Older versions of DungeonsXL support versions since Minecraft 1.3.x, but of course, they are completely unsupported. -* [1.7.8-1.10.2](../../tree/master) +* [1.7.8-1.11](../../tree/master) * [1.7.5](../../tree/50f772d14281bfe278dba2559d1758cc459c1a30) * [1.7.2](../../tree/eccf82b7335dfb0723e3cd37a57df1a968ea7842) * [1.6.4](../../tree/780145cf783ea76fe1bfee04cf89216bd4f92e1d) @@ -68,10 +68,10 @@ Building DungeonsXL from source requires [Apache Maven](https://maven.apache.org Maven automatically fetches all dependencies and builds DungeonsXL; just run _build.bat_ or enter the command _mvn clean install_. #### BRCommons -[BRCommons](https://github.com/DRE2N/BRCommons) is a util library for common tasks. DungeonsXL contains BRCommons 1.0.1. +[BRCommons](https://github.com/DRE2N/BRCommons) is a util library for common tasks. DungeonsXL contains BRCommons 1.0.2. #### Caliburn API -[Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.2.1. +[Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.2.2. #### ResourcePackAPI inventivetalent's [ResourcePackAPI](https://www.spigotmc.org/resources/api-resourcepackapi-1-7-1-8-1-9-1-10.2397/) is an API to set the resourcepack of a player. DungeonsXL contains ResourcePackAPI 2.2.1.