From 675492b6675519f49bd1712552f114bf207f1b24 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 24 Feb 2016 22:00:30 +0100 Subject: [PATCH] Fixed some modifiers --- .../dre2n/dungeonsxl/command/DCommand.java | 4 +- .../dre2n/dungeonsxl/config/WorldConfig.java | 2 +- .../dungeonsxl/dungeon/DLootInventory.java | 2 +- .../dre2n/dungeonsxl/dungeon/EditWorld.java | 2 +- src/io/github/dre2n/dungeonsxl/game/Game.java | 38 +++++++++++++++ .../dre2n/dungeonsxl/game/GameChest.java | 2 +- .../dre2n/dungeonsxl/game/GameWorld.java | 47 +++++++++++++++---- .../dre2n/dungeonsxl/global/DPortal.java | 2 +- .../dre2n/dungeonsxl/global/GroupSign.java | 6 +-- .../dre2n/dungeonsxl/global/LeaveSign.java | 2 +- .../dungeonsxl/listener/BlockListener.java | 2 +- .../dungeonsxl/listener/CommandListener.java | 2 +- .../dungeonsxl/listener/PlayerListener.java | 4 +- .../github/dre2n/dungeonsxl/mob/DMobType.java | 2 +- .../dre2n/dungeonsxl/player/DGroup.java | 4 +- .../dre2n/dungeonsxl/player/DPlayer.java | 4 +- .../dre2n/dungeonsxl/player/DSavePlayer.java | 2 +- .../dungeonsxl/requirement/Requirement.java | 2 +- .../dre2n/dungeonsxl/reward/Reward.java | 2 +- .../github/dre2n/dungeonsxl/sign/DSign.java | 2 +- .../dre2n/dungeonsxl/task/LazyUpdateTask.java | 2 +- .../dungeonsxl/task/RedstoneEventTask.java | 2 +- .../dungeonsxl/task/WorldUnloadTask.java | 2 +- .../dre2n/dungeonsxl/trigger/Trigger.java | 2 +- 24 files changed, 104 insertions(+), 37 deletions(-) diff --git a/src/io/github/dre2n/dungeonsxl/command/DCommand.java b/src/io/github/dre2n/dungeonsxl/command/DCommand.java index ed9a6369..770a3b95 100644 --- a/src/io/github/dre2n/dungeonsxl/command/DCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/DCommand.java @@ -10,8 +10,8 @@ import org.bukkit.entity.Player; public abstract class DCommand { - static DungeonsXL plugin = DungeonsXL.getPlugin(); - static MessageConfig messageConfig = plugin.getMessageConfig(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static MessageConfig messageConfig = plugin.getMessageConfig(); public boolean costsMoney; private String command; diff --git a/src/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/src/io/github/dre2n/dungeonsxl/config/WorldConfig.java index 3ed4c4b0..9e094bc8 100644 --- a/src/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/src/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -30,7 +30,7 @@ import org.bukkit.inventory.ItemStack; public class WorldConfig { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); @Deprecated public static WorldConfig defaultConfig = new WorldConfig(); diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java b/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java index 86a40561..17d8d3f2 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java @@ -12,7 +12,7 @@ import org.bukkit.inventory.ItemStack; public class DLootInventory { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); private Inventory inventory; private InventoryView inventoryView; diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java b/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java index 1fe8f6b5..0f9ea6b1 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class EditWorld { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); // Variables private World world; diff --git a/src/io/github/dre2n/dungeonsxl/game/Game.java b/src/io/github/dre2n/dungeonsxl/game/Game.java index 2b0064e6..c149e88a 100644 --- a/src/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/io/github/dre2n/dungeonsxl/game/Game.java @@ -1,12 +1,17 @@ package io.github.dre2n.dungeonsxl.game; +import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.player.DGroup; import java.util.ArrayList; import java.util.List; +import org.bukkit.entity.Player; + public class Game { + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); + private List dGroups = new ArrayList(); private GameType type; @@ -58,4 +63,37 @@ public class Game { this.type = type; } + /** + * @return if the DGroup list is empty + */ + public boolean isEmpty() { + return dGroups.isEmpty(); + } + + // Static + + public static Game getByDGroup(DGroup dGroup) { + for (Game game : plugin.getGames()) { + if (game.getDGroups().contains(dGroup)) { + return game; + } + } + + return null; + } + + public static Game getByPlayer(Player player) { + return getByDGroup(DGroup.getByPlayer(player)); + } + + public static Game getByGameWorld(GameWorld gameWorld) { + for (Game game : plugin.getGames()) { + if (game.getDGroups().get(0).getGameWorld().equals(gameWorld)) { + return game; + } + } + + return null; + } + } diff --git a/src/io/github/dre2n/dungeonsxl/game/GameChest.java b/src/io/github/dre2n/dungeonsxl/game/GameChest.java index dc077748..fdda6728 100644 --- a/src/io/github/dre2n/dungeonsxl/game/GameChest.java +++ b/src/io/github/dre2n/dungeonsxl/game/GameChest.java @@ -22,7 +22,7 @@ import org.bukkit.inventory.ItemStack; public class GameChest { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); // Variables private boolean used = false; diff --git a/src/io/github/dre2n/dungeonsxl/game/GameWorld.java b/src/io/github/dre2n/dungeonsxl/game/GameWorld.java index 8d0875e1..4826d361 100644 --- a/src/io/github/dre2n/dungeonsxl/game/GameWorld.java +++ b/src/io/github/dre2n/dungeonsxl/game/GameWorld.java @@ -10,6 +10,7 @@ import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent; import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent; import io.github.dre2n.dungeonsxl.mob.DMob; +import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.sign.DSign; @@ -41,7 +42,7 @@ import org.bukkit.entity.Spider; public class GameWorld { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); // Variables private Game game; @@ -60,7 +61,7 @@ public class GameWorld { private CopyOnWriteArrayList signClass = new CopyOnWriteArrayList(); private CopyOnWriteArrayList dMobs = new CopyOnWriteArrayList(); - //TODO: Killed mobs + // TODO: Killed mobs private CopyOnWriteArrayList gameChests = new CopyOnWriteArrayList(); private CopyOnWriteArrayList dSigns = new CopyOnWriteArrayList(); private WorldConfig worldConfig; @@ -512,17 +513,17 @@ public class GameWorld { } } - public static boolean canPlayDungeon(String dungeon, Player player) { + public static boolean canPlayDungeon(String map, Player player) { if (player.hasPermission("dxl.ignoretimelimit")) { return true; } - if (new File(plugin.getDataFolder() + "/maps/" + dungeon).isDirectory()) { - WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + dungeon, "config.yml")); + if (new File(plugin.getDataFolder() + "/maps/" + map).isDirectory()) { + WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + map, "config.yml")); if (worldConfig.getTimeToNextPlay() != 0) { // read PlayerConfig - long time = getPlayerTime(dungeon, player); + long time = getPlayerTime(map, player); if (time != -1) { if (time + worldConfig.getTimeToNextPlay() * 1000 * 60 * 60 > System.currentTimeMillis()) { return false; @@ -537,6 +538,20 @@ public class GameWorld { return true; } + public static boolean canPlayDungeon(String dungeon, DGroup dGroup) { + if (dGroup.getCaptain().hasPermission("dxl.ignoretimelimit")) { + return true; + } + + for (Player player : dGroup.getPlayers()) { + if ( !canPlayDungeon(dungeon, player)) { + return false; + } + } + + return true; + } + public static long getPlayerTime(String dungeon, Player player) { File file = new File(plugin.getDataFolder() + "/maps/" + dungeon, "players.yml"); @@ -559,16 +574,16 @@ public class GameWorld { return -1; } - public static boolean checkRequirements(String dungeon, Player player) { + public static boolean checkRequirements(String map, Player player) { if (player.hasPermission("dxl.ignorerequirements")) { return true; } - if (new File(plugin.getDataFolder() + "/maps/" + dungeon).isDirectory() == false) { + if (new File(plugin.getDataFolder() + "/maps/" + map).isDirectory() == false) { return false; } - WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + dungeon, "config.yml")); + WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + map, "config.yml")); for (Requirement requirement : worldConfig.getRequirements()) { RequirementCheckEvent event = new RequirementCheckEvent(requirement, player); @@ -634,4 +649,18 @@ public class GameWorld { return true; } + public static boolean checkRequirements(String map, DGroup dGroup) { + if (dGroup.getCaptain().hasPermission("dxl.ignorerequirements")) { + return true; + } + + for (Player player : dGroup.getPlayers()) { + if ( !checkRequirements(map, player)) { + return false; + } + } + + return true; + } + } diff --git a/src/io/github/dre2n/dungeonsxl/global/DPortal.java b/src/io/github/dre2n/dungeonsxl/global/DPortal.java index 3be39efb..26bc5381 100644 --- a/src/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/src/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -16,7 +16,7 @@ import org.bukkit.entity.Player; public class DPortal { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); private World world; private Block block1; diff --git a/src/io/github/dre2n/dungeonsxl/global/GroupSign.java b/src/io/github/dre2n/dungeonsxl/global/GroupSign.java index d73f4cf7..a3f5d40b 100644 --- a/src/io/github/dre2n/dungeonsxl/global/GroupSign.java +++ b/src/io/github/dre2n/dungeonsxl/global/GroupSign.java @@ -21,7 +21,7 @@ import org.bukkit.entity.Player; public class GroupSign { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); // Sign Labels public static final String IS_PLAYING = ChatColor.DARK_RED + "Is Playing"; @@ -313,7 +313,7 @@ public class GroupSign { } public static GroupSign getSign(Block block) { - if (block.getType() != Material.WALL_SIGN) { + if ( !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) { return null; } @@ -510,7 +510,7 @@ public class GroupSign { } public static void load(FileConfiguration configFile) { - for (World world : DungeonsXL.getPlugin().getServer().getWorlds()) { + for (World world : plugin.getServer().getWorlds()) { if ( !configFile.contains("groupsign." + world.getName())) { continue; } diff --git a/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java b/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java index 7486b108..ea54bba6 100644 --- a/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java +++ b/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java @@ -16,7 +16,7 @@ import org.bukkit.entity.Player; public class LeaveSign { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); private Sign sign; diff --git a/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java index 02b5f925..eab748e8 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -32,7 +32,7 @@ import org.bukkit.event.block.SignChangeEvent; public class BlockListener implements Listener { - DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); @EventHandler(priority = EventPriority.HIGH) public void onPhysics(BlockPhysicsEvent event) { diff --git a/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java b/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java index 83b5aa06..a0f7e7ac 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java @@ -14,7 +14,7 @@ import org.bukkit.entity.Player; public class CommandListener implements CommandExecutor { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); @Override public boolean onCommand(CommandSender sender, Command cmd_notused, String arg, String[] args) { diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 3d154dae..a242202a 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -51,8 +51,8 @@ import org.bukkit.inventory.meta.BookMeta; public class PlayerListener implements Listener { - static DungeonsXL plugin = DungeonsXL.getPlugin(); - static MessageConfig messageConfig = plugin.getMessageConfig(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static MessageConfig messageConfig = plugin.getMessageConfig(); @EventHandler(priority = EventPriority.HIGH) public void onDeath(PlayerDeathEvent event) { diff --git a/src/io/github/dre2n/dungeonsxl/mob/DMobType.java b/src/io/github/dre2n/dungeonsxl/mob/DMobType.java index f4234913..e966ead9 100644 --- a/src/io/github/dre2n/dungeonsxl/mob/DMobType.java +++ b/src/io/github/dre2n/dungeonsxl/mob/DMobType.java @@ -26,7 +26,7 @@ import org.bukkit.inventory.meta.ItemMeta; public class DMobType { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); private String name; private EntityType type; diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index 80f99ea7..38674bc9 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -27,8 +27,8 @@ import org.bukkit.entity.Player; public class DGroup { - static DungeonsXL plugin = DungeonsXL.getPlugin(); - static MessageConfig messageConfig = plugin.getMessageConfig(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static MessageConfig messageConfig = plugin.getMessageConfig(); private String name; private Player captain; diff --git a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java index 975c0b4c..435e9a69 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java @@ -46,8 +46,8 @@ import org.bukkit.potion.PotionEffect; public class DPlayer { - static DungeonsXL plugin = DungeonsXL.getPlugin(); - static MessageConfig messageConfig = plugin.getMessageConfig(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static MessageConfig messageConfig = plugin.getMessageConfig(); // Variables private Player player; diff --git a/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java b/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java index 6d7d1450..d76f61d9 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java @@ -21,7 +21,7 @@ import org.bukkit.potion.PotionEffect; public class DSavePlayer { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); private static CopyOnWriteArrayList savePlayers = new CopyOnWriteArrayList(); diff --git a/src/io/github/dre2n/dungeonsxl/requirement/Requirement.java b/src/io/github/dre2n/dungeonsxl/requirement/Requirement.java index cb1d9941..e091d54e 100644 --- a/src/io/github/dre2n/dungeonsxl/requirement/Requirement.java +++ b/src/io/github/dre2n/dungeonsxl/requirement/Requirement.java @@ -10,7 +10,7 @@ import io.github.dre2n.dungeonsxl.event.requirement.RequirementRegistrationEvent public abstract class Requirement { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); public static Requirement create(RequirementType type) { Requirement requirement = null; diff --git a/src/io/github/dre2n/dungeonsxl/reward/Reward.java b/src/io/github/dre2n/dungeonsxl/reward/Reward.java index 2b22d59a..4da2991b 100644 --- a/src/io/github/dre2n/dungeonsxl/reward/Reward.java +++ b/src/io/github/dre2n/dungeonsxl/reward/Reward.java @@ -13,7 +13,7 @@ import io.github.dre2n.dungeonsxl.reward.RewardTypeDefault; public abstract class Reward { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); public static Reward create(RewardType type) { Reward reward = null; diff --git a/src/io/github/dre2n/dungeonsxl/sign/DSign.java b/src/io/github/dre2n/dungeonsxl/sign/DSign.java index 99ab1a48..23e06dfc 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/DSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/DSign.java @@ -15,7 +15,7 @@ import org.bukkit.entity.Player; public abstract class DSign { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); private Sign sign; private GameWorld gameWorld; diff --git a/src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java b/src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java index 9df6d545..2a0d379c 100644 --- a/src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java +++ b/src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java @@ -8,7 +8,7 @@ import org.bukkit.scheduler.BukkitRunnable; public class LazyUpdateTask extends BukkitRunnable { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); @Override public void run() { diff --git a/src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java b/src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java index b37c503f..5a2a20ac 100644 --- a/src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java +++ b/src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java @@ -9,7 +9,7 @@ import org.bukkit.scheduler.BukkitRunnable; public class RedstoneEventTask extends BukkitRunnable { - private final Block block; + private Block block; public RedstoneEventTask(final Block block) { this.block = block; diff --git a/src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java b/src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java index 2219183d..c42bd544 100644 --- a/src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java +++ b/src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java @@ -9,7 +9,7 @@ import org.bukkit.scheduler.BukkitRunnable; public class WorldUnloadTask extends BukkitRunnable { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); @Override public void run() { diff --git a/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java b/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java index 746e3e0f..34007433 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java @@ -15,7 +15,7 @@ import org.bukkit.entity.Player; public abstract class Trigger { - static DungeonsXL plugin = DungeonsXL.getPlugin(); + protected static DungeonsXL plugin = DungeonsXL.getPlugin(); private boolean triggered; private Player player; // Holds Player for Player specific Triggers