diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java index 8b14126d..f867f275 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -96,7 +96,7 @@ public class Announcer { Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { - mapName = dungeon.getConfig().getStartFloor(); + mapName = dungeon.getConfig().getStartFloor().getName(); } } else { @@ -137,7 +137,7 @@ public class Announcer { Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { - mapName = dungeon.getConfig().getStartFloor(); + mapName = dungeon.getConfig().getStartFloor().getName(); } } else { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java index 1a128290..5445037e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -27,7 +27,6 @@ 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 io.github.dre2n.dungeonsxl.world.EditWorld; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -73,7 +72,7 @@ public class PlayCommand extends BRCommand { Dungeon dungeon = plugin.getDungeons().getByName(args[2]); if (dungeon != null) { multiFloor = true; - mapName = dungeon.getConfig().getStartFloor(); + mapName = dungeon.getConfig().getStartFloor().getName(); } else { displayHelp(player); return; @@ -108,7 +107,7 @@ public class PlayCommand extends BRCommand { DungeonConfig config = dungeon.getConfig(); if (config != null) { - dGroup.setMapName(config.getStartFloor()); + dGroup.setMapName(config.getStartFloor().getName()); } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index abad9751..0c572d55 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -17,6 +17,7 @@ package io.github.dre2n.dungeonsxl.config; import io.github.dre2n.commons.config.Messages; +import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; @@ -185,6 +186,7 @@ public enum DMessages implements Messages { this.message = message; } + /* Getters and setters */ @Override public String getIdentifier() { return identifier; @@ -205,6 +207,14 @@ public enum DMessages implements Messages { this.message = message; } + /* Actions */ + /** + * Sends the message to the console. + */ + public void debug() { + MessageUtil.log(DungeonsXL.getInstance(), getMessage()); + } + /* Statics */ /** * @param identifer diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java index af3d7e4f..81c717c6 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java @@ -17,6 +17,9 @@ package io.github.dre2n.dungeonsxl.config; import io.github.dre2n.commons.config.BRConfig; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.world.ResourceWorld; +import io.github.dre2n.dungeonsxl.world.Worlds; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -26,11 +29,13 @@ import java.util.List; */ public class DungeonConfig extends BRConfig { + Worlds worlds = DungeonsXL.getInstance().getWorlds(); + public static final int CONFIG_VERSION = 1; - private String startFloor; - private String endFloor; - private List floors = new ArrayList<>(); + private ResourceWorld startFloor; + private ResourceWorld endFloor; + private List floors = new ArrayList<>(); private int floorCount; private boolean removeWhenPlayed; private WorldConfig overrideValues; @@ -48,7 +53,7 @@ public class DungeonConfig extends BRConfig { /** * @return the startFloor */ - public String getStartFloor() { + public ResourceWorld getStartFloor() { return startFloor; } @@ -56,14 +61,14 @@ public class DungeonConfig extends BRConfig { * @param startFloor * the startFloor to set */ - public void setStartFloor(String startFloor) { + public void setStartFloor(ResourceWorld startFloor) { this.startFloor = startFloor; } /** * @return the endFloor */ - public String getEndFloor() { + public ResourceWorld getEndFloor() { return endFloor; } @@ -71,31 +76,31 @@ public class DungeonConfig extends BRConfig { * @param endFloor * the endFloor to set */ - public void setEndFloor(String endFloor) { + public void setEndFloor(ResourceWorld endFloor) { this.endFloor = endFloor; } /** * @return the floors */ - public List getFloors() { + public List getFloors() { return floors; } /** - * @param gameWorld - * the gameWorld to add + * @param resource + * the resource to add */ - public void addFloor(String gameWorld) { - floors.add(gameWorld); + public void addFloor(ResourceWorld resource) { + floors.add(resource); } /** - * @param gameWorld - * the gameWorld to remove + * @param resource + * the resource to remove */ - public void removeFloor(String gameWorld) { - floors.remove(gameWorld); + public void removeFloor(ResourceWorld resource) { + floors.remove(resource); } /** @@ -165,18 +170,36 @@ public class DungeonConfig extends BRConfig { defaultValues = worldConfig; } + /** + * @param resource + * the ResourceWorld to check + * @return true if the floor is either in the list or the start / end floor. + */ + public boolean containsFloor(ResourceWorld resource) { + return floors.contains(resource) || startFloor.equals(resource) || endFloor.equals(resource); + } + + /** + * @param mapName + * the name of the map to check + * @return true if the floor is either in the list or the start / end floor. + */ + public boolean containsFloor(String mapName) { + return containsFloor(worlds.getResourceByName(mapName)); + } + @Override public void initialize() { if (!config.contains("floors")) { - config.set("floors", floors); + config.createSection("floors"); } if (!config.contains("startFloor")) { - config.set("startFloor", startFloor); + config.set("startFloor", startFloor.getName()); } if (!config.contains("endFloor")) { - config.set("endFloor", endFloor); + config.set("endFloor", endFloor.getName()); } if (!config.contains("floorCount")) { @@ -201,15 +224,20 @@ public class DungeonConfig extends BRConfig { @Override public void load() { if (config.contains("floors")) { - floors = config.getStringList("floors"); + for (String floor : config.getStringList("floors")) { + ResourceWorld resource = worlds.getResourceByName(floor); + if (resource != null) { + floors.add(resource); + } + } } if (config.contains("startFloor")) { - startFloor = config.getString("startFloor"); + startFloor = worlds.getResourceByName(config.getString("startFloor")); } if (config.contains("endFloor")) { - endFloor = config.getString("endFloor"); + endFloor = worlds.getResourceByName(config.getString("endFloor")); } if (config.contains("floorCount")) { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java b/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java index 3aca5ae8..f121d86f 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java @@ -63,4 +63,11 @@ public class Dungeon { return config != null; } + /** + * @return false if there are setup errors + */ + public boolean isSetupCorrect() { + return config.getStartFloor() == null || config.getEndFloor() == null; + } + } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java b/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java index 35b5fa10..64b4ad5a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java @@ -36,7 +36,14 @@ public class Dungeons { } for (File file : folder.listFiles()) { - dungeons.add(new Dungeon(file)); + Dungeon dungeon = new Dungeon(file); + + if (dungeon.isSetupCorrect()) { + dungeons.add(dungeon); + + } else { + // debug + } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 194375c8..c4300457 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -236,8 +236,8 @@ public class Game { * * @return the unplayed floors */ - public List getUnplayedFloors() { - List unplayedFloors = new ArrayList<>(); + public List getUnplayedFloors() { + List unplayedFloors = new ArrayList<>(); for (DGroup dGroup : dGroups) { if (dGroup.getUnplayedFloors().size() < unplayedFloors.size()) { unplayedFloors = dGroup.getUnplayedFloors(); @@ -376,7 +376,7 @@ public class Game { } int delay = rules.getTimeToNextWave(); - sendMessage(plugin.getMessageConfig().getMessage(DMessages.GROUP_WAVE_FINISHED, String.valueOf(waveCount), String.valueOf(delay))); + sendMessage(DMessages.GROUP_WAVE_FINISHED.getMessage(String.valueOf(waveCount), String.valueOf(delay))); new BukkitRunnable() { @Override diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java index 28c3561b..24de87e9 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java @@ -65,7 +65,7 @@ public class GameSign extends GlobalProtection { dungeonName = identifier; Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { - mapName = dungeon.getConfig().getStartFloor(); + mapName = dungeon.getConfig().getStartFloor().getName(); } else { mapName = "invalid"; } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java b/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java index fb82873a..a432c283 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java @@ -64,7 +64,7 @@ public class GroupSign extends GlobalProtection { dungeonName = identifier; Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { - mapName = dungeon.getConfig().getStartFloor(); + mapName = dungeon.getConfig().getStartFloor().getName(); } else { mapName = "invalid"; } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 5038cced..3ab757f0 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -639,7 +639,7 @@ public class DGamePlayer extends DInstancePlayer { * @param specifiedFloor * the name of the next floor */ - public void finishFloor(String specifiedFloor) { + public void finishFloor(ResourceWorld specifiedFloor) { MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_FINISHED_DUNGEON.getMessage()); finished = true; @@ -681,7 +681,7 @@ public class DGamePlayer extends DInstancePlayer { DungeonConfig dConfig = dGroup.getDungeon().getConfig(); int random = NumberUtil.generateRandomInt(0, dConfig.getFloors().size()); - String newFloor = dGroup.getUnplayedFloors().get(random); + ResourceWorld newFloor = dGroup.getUnplayedFloors().get(random); if (dConfig.getFloorCount() == dGroup.getFloorCount() - 1) { newFloor = dConfig.getEndFloor(); @@ -689,21 +689,20 @@ public class DGamePlayer extends DInstancePlayer { newFloor = specifiedFloor; } - DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor); + /*DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor); if (event.isCancelled()) { return; } - + */ Game game = dGroup.getGameWorld().getGame(); - dGroup.removeUnplayedFloor(dGroup.getMapName()); - dGroup.setMapName(newFloor); + dGroup.removeUnplayedFloor(dGroup.getGameWorld().getResource(), false); + dGroup.setMapName(newFloor.getName()); - ResourceWorld resource = plugin.getWorlds().getResourceByName(newFloor); GameWorld gameWorld = null; - if (resource != null) { - gameWorld = resource.instantiateAsGameWorld(); + if (newFloor != null) { + gameWorld = newFloor.instantiateAsGameWorld(); } dGroup.setGameWorld(gameWorld); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 004c516c..246e00e4 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -34,6 +34,7 @@ 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.world.GameWorld; +import io.github.dre2n.dungeonsxl.world.ResourceWorld; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -58,13 +59,13 @@ public class DGroup { private Dungeon dungeon; private String dungeonName; private String mapName; - private List unplayedFloors = new ArrayList<>(); + private List unplayedFloors = new ArrayList<>(); private GameWorld gameWorld; private boolean playing; private int floorCount; private List rewards = new ArrayList<>(); private BukkitTask timeIsRunningTask; - private String nextFloor; + private ResourceWorld nextFloor; public DGroup(Player player) { this("Group_" + plugin.getDGroups().size(), player); @@ -110,7 +111,7 @@ public class DGroup { dungeon = plugin.getDungeons().getByName(identifier); if (multiFloor && dungeon != null) { dungeonName = dungeon.getName(); - mapName = dungeon.getConfig().getStartFloor(); + mapName = dungeon.getConfig().getStartFloor().getName(); unplayedFloors = dungeon.getConfig().getFloors(); } else { @@ -379,7 +380,7 @@ public class DGroup { dungeon = plugin.getDungeons().getByName(name); if (dungeon != null) { dungeonName = dungeon.getName(); - mapName = dungeon.getConfig().getStartFloor(); + mapName = dungeon.getConfig().getStartFloor().getName(); unplayedFloors = dungeon.getConfig().getFloors(); } else { @@ -427,26 +428,28 @@ public class DGroup { } /** - * @return the unplayedFloors + * @return the unplayed floors */ - public List getUnplayedFloors() { + public List getUnplayedFloors() { return unplayedFloors; } /** * @param unplayedFloor - * the unplayedFloor to add + * the unplayed floor to add */ - public void addUnplayedFloor(String unplayedFloor) { + public void addUnplayedFloor(ResourceWorld unplayedFloor) { unplayedFloors.add(unplayedFloor); } /** * @param unplayedFloor - * the unplayedFloor to add + * the unplayed floor to remove + * @param force + * remove the floor even if removeWhenPlayed is disabled */ - public void removeUnplayedFloor(String unplayedFloor) { - if (getDungeon().getConfig().getRemoveWhenPlayed()) { + public void removeUnplayedFloor(ResourceWorld unplayedFloor, boolean force) { + if (getDungeon().getConfig().getRemoveWhenPlayed() || force) { unplayedFloors.remove(unplayedFloor); } } @@ -543,7 +546,7 @@ public class DGroup { /** * @return the next floor the group will enter */ - public String getNextFloor() { + public ResourceWorld getNextFloor() { return nextFloor; } @@ -551,7 +554,7 @@ public class DGroup { * @param floor * the next floor to set */ - public void setNextFloor(String floor) { + public void setNextFloor(ResourceWorld floor) { nextFloor = floor; } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/FloorSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/FloorSign.java index 26464656..7df50a06 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/FloorSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/FloorSign.java @@ -19,6 +19,7 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.dungeonsxl.world.ResourceWorld; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Sign; @@ -31,12 +32,27 @@ public class FloorSign extends DSign { private DSignType type = DSignTypeDefault.FLOOR; - private String floor; + private ResourceWorld floor; public FloorSign(Sign sign, String[] lines, GameWorld gameWorld) { super(sign, lines, gameWorld); } + /** + * @return the next floor + */ + public ResourceWorld getFloor() { + return floor; + } + + /** + * @param floor + * the floor to set + */ + public void setFloor(ResourceWorld floor) { + this.floor = floor; + } + @Override public boolean check() { return true; @@ -45,7 +61,7 @@ public class FloorSign extends DSign { @Override public void onInit() { if (!lines[1].isEmpty()) { - floor = lines[1]; + floor = plugin.getWorlds().getResourceByName(lines[1]); } if (!getTriggers().isEmpty()) { @@ -64,7 +80,7 @@ public class FloorSign extends DSign { if (floor == null) { getSign().setLine(2, ChatColor.DARK_GREEN + "NEXT FLOOR"); } else { - getSign().setLine(2, ChatColor.DARK_GREEN + floor.replaceAll("_", " ")); + getSign().setLine(2, ChatColor.DARK_GREEN + floor.getName().replaceAll("_", " ")); } getSign().setLine(3, ChatColor.DARK_BLUE + "############"); getSign().update(); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java index 41f552a3..a4064b22 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java @@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.dungeonsxl.world.ResourceWorld; import java.util.HashSet; import java.util.Set; @@ -28,7 +29,7 @@ public class ProgressTrigger extends Trigger { private TriggerType type = TriggerTypeDefault.PROGRESS; - private String floor; + private ResourceWorld floor; private int floorCount; private int waveCount; @@ -37,7 +38,7 @@ public class ProgressTrigger extends Trigger { this.waveCount = waveCount; } - public ProgressTrigger(String floor) { + public ProgressTrigger(ResourceWorld floor) { this.floor = floor; } @@ -45,7 +46,7 @@ public class ProgressTrigger extends Trigger { /** * @return the specific floor that must be finished */ - public String getFloor() { + public ResourceWorld getFloor() { return floor; } @@ -53,7 +54,7 @@ public class ProgressTrigger extends Trigger { * @param floor * the specific floor to set */ - public void setFloor(String floor) { + public void setFloor(ResourceWorld floor) { this.floor = floor; } @@ -114,7 +115,14 @@ public class ProgressTrigger extends Trigger { } public static ProgressTrigger getOrCreate(String floor, GameWorld gameWorld) { - return new ProgressTrigger(floor); + ResourceWorld resource = plugin.getWorlds().getResourceByName(floor); + + if (resource != null) { + return new ProgressTrigger(resource); + + } else { + return null; + } } public static Set getByGameWorld(GameWorld gameWorld) {