2
0
Эх сурвалжийг харах

Fixing event error when no game world has been created yet

RedstoneFuture 3 жил өмнө
parent
commit
32c890f32a

+ 9 - 4
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Game.java

@@ -77,7 +77,7 @@ public class Game {
     private static int fights = 0;
     private final Map<UUID, MWPlayer> players = new HashMap<>();
     private final Map<String, Integer> votes = new HashMap<>(); // Votes for the maps.
-    @Getter private final Lobby lobby;
+    private final Lobby lobby;
     private final HashMap<UUID, BukkitTask> playerTasks = new HashMap<>();
     private Timer timer;
     private BukkitTask bt;
@@ -85,11 +85,11 @@ public class Game {
     private Team team1;
     private Team team2;
     @Setter private boolean draw = true;
-    @Getter private boolean ready = false;
+    private boolean ready = false;
     private boolean restart = false;
     private GameWorld gameWorld;
     private long timestart;
-    @Getter private Arena arena;
+    private Arena arena;
     private ScoreboardManager scoreboardManager;
     private GameBoundListener listener;
     private ItemStack customBow;
@@ -344,7 +344,12 @@ public class Game {
 
     public boolean isInGameWorld(Location location) {
         World world = location.getWorld();
-        return gameWorld.isWorld(world);
+        if (world == null) return false;
+
+        if (gameWorld != null) {
+            return gameWorld.isWorld(world);
+        }
+        return false;
     }
 
     public boolean isIn(Location location) {

+ 8 - 2
missilewars-plugin/src/main/java/de/butzlabben/missilewars/listener/PlayerListener.java

@@ -95,6 +95,7 @@ public class PlayerListener implements Listener {
 
         Game game = getGame(p.getLocation());
         if (game != null) {
+
             if (!game.isIn(game.getLobby().getAfterGameSpawn()))
                 p.teleport(game.getLobby().getAfterGameSpawn());
             else
@@ -107,8 +108,11 @@ public class PlayerListener implements Listener {
         Player p = event.getPlayer();
 
         Game game = getGame(p.getLocation());
-        if (checkJoinOrLeave(p, null, game)) {
-            p.teleport(Config.getFallbackSpawn());
+        if (game != null) {
+
+            if (checkJoinOrLeave(p, null, game)) {
+                p.teleport(Config.getFallbackSpawn());
+            }
         }
     }
 
@@ -125,12 +129,14 @@ public class PlayerListener implements Listener {
     public void onMove(PlayerMoveEvent event) {
         Game to = getGame(event.getTo());
         Game from = getGame(event.getFrom());
+
         if (checkJoinOrLeave(event.getPlayer(), from, to)) {
             event.setCancelled(true);
             Vector addTo = event.getFrom().toVector().subtract(event.getTo().toVector()).multiply(3);
             addTo.setY(0);
             event.getPlayer().teleport(event.getFrom().add(addTo));
         }
+
     }
 
     @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)