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 f362bfea..68b57359 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -24,6 +24,7 @@ import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.config.WorldConfig; 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.DGroup; import io.github.dre2n.dungeonsxl.player.DPermissions; @@ -164,6 +165,7 @@ public class PlayCommand extends BRCommand { return; } + new Game(dGroup, dGroup.getGameWorld()); if (dGroup.getGameWorld().getLobbyLocation() == null) { for (Player groupPlayer : dGroup.getPlayers()) { new DGamePlayer(groupPlayer, dGroup.getGameWorld()); 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 667c75a6..320c1778 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -58,10 +58,16 @@ public class Game { public Game(DGroup dGroup) { dGroups.add(dGroup); started = false; + fetchRules(); plugin.getGames().add(this); } + public Game(DGroup dGroup, GameWorld world) { + this(dGroup); + this.world = world; + } + public Game(DGroup dGroup, GameType type, GameWorld world) { this(new ArrayList<>(Arrays.asList(dGroup)), type, world); } @@ -71,6 +77,7 @@ public class Game { this.type = type; this.world = world; this.started = true; + fetchRules(); plugin.getGames().add(this); } @@ -196,13 +203,15 @@ public class Game { finalRules.apply(floorConfig); } - if (getDungeon() != null) { + if (dungeonConfig != null) { finalRules.apply(dungeonConfig.getDefaultValues()); } finalRules.apply(plugin.getMainConfig().getDefaultWorldConfig()); finalRules.apply(GameRules.DEFAULT_VALUES); + + rules = finalRules; } /** diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 9ca4cd4e..34611924 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -27,7 +27,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.GameMode; import org.bukkit.Material; @@ -363,10 +362,8 @@ public class GameRules { /** * @return the objects to get passed to another player of the group when this player leaves */ - public CopyOnWriteArrayList getSecureObjects() { - CopyOnWriteArrayList tmpSecureObjects = new CopyOnWriteArrayList<>(); - tmpSecureObjects.addAll(secureObjects); - return tmpSecureObjects; + public List getSecureObjects() { + return secureObjects; } /* Actions */ diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java b/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java index 1e1286ae..a668565c 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -191,14 +191,15 @@ public class DPortal extends GlobalProtection { } if (target == null) { - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.ERROR_DUNGEON_NOT_EXIST, DGroup.getByPlayer(player).getMapName())); + MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage(DGroup.getByPlayer(player).getMapName())); return; } - if (game != null) { - game.setWorld(target); + if (game == null) { + game = new Game(dGroup); } + game.setWorld(target); dGroup.setGameWorld(target); new DGamePlayer(player, target); 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 23387215..a8c21766 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -83,7 +83,12 @@ public class DGamePlayer extends DInstancePlayer { public DGamePlayer(Player player, World world) { super(player, world); - GameRules rules = Game.getByWorld(world).getRules(); + Game game = Game.getByWorld(world); + if (game == null) { + game = new Game(DGroup.getByPlayer(player)); + } + + GameRules rules = game.getRules(); player.setGameMode(GameMode.SURVIVAL); if (!rules.getKeepInventoryOnEnter()) { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java index fb14bc4b..2bdba9eb 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java @@ -42,6 +42,8 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.ObjectInputStream; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -76,7 +78,7 @@ public class GameWorld { private Location locStart; private boolean isPlaying = false; private int id; - private CopyOnWriteArrayList secureObjects = new CopyOnWriteArrayList<>(); + private List secureObjects = new ArrayList<>(); private CopyOnWriteArrayList loadedChunks = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList signClass = new CopyOnWriteArrayList<>(); @@ -244,7 +246,7 @@ public class GameWorld { /** * @return the secureObjects */ - public CopyOnWriteArrayList getSecureObjects() { + public List getSecureObjects() { return secureObjects; } @@ -252,7 +254,7 @@ public class GameWorld { * @param secureObjects * the secureObjects to set */ - public void setSecureObjects(CopyOnWriteArrayList secureObjects) { + public void setSecureObjects(List secureObjects) { this.secureObjects = secureObjects; }