diff --git a/src/main/java/org/mctourney/autoreferee/AutoRefMatch.java b/src/main/java/org/mctourney/autoreferee/AutoRefMatch.java index de806c73..d5d62de3 100644 --- a/src/main/java/org/mctourney/autoreferee/AutoRefMatch.java +++ b/src/main/java/org/mctourney/autoreferee/AutoRefMatch.java @@ -2019,27 +2019,39 @@ public void destroy(MatchUnloadEvent.Reason reason) MatchUnloadEvent event = new MatchUnloadEvent(this, reason); AutoReferee.callEvent(event); if (event.isCancelled()) return; - // for cleanup purposes, BEFORE we eject all of the players this.messageReferees("world", getWorld().getName(), "destroy"); + + // we have to make our own teleport function because ejectPlayer() runs a task + // not the best solution but it works + + // if there is a lobby to teleport the players to, do so (copied from ejectPlayer()) + World target = AutoReferee.getInstance().getLobbyWorld(); + if (target == null) for (World w : Bukkit.getWorlds()) + if (!AutoRefMatch.isCompatible(w)) { target = w; break; } // first, handle all the players - for (Player p : primaryWorld.getPlayers()) this.ejectPlayer(p); - + for (Player p : primaryWorld.getPlayers()){ + if (target != null) + { + PlayerUtil.setGameMode(p, GameMode.SURVIVAL); + p.teleport(target.getSpawnLocation()); // so that there are no players in the world by the next line of code + } + //this.ejectPlayer(p); + } + // if everyone has been moved out of this world, clean it up if (primaryWorld.getPlayers().size() == 0) - { + { // if this is OUR world (we can delete it if we want) AutoReferee plugin = AutoReferee.getInstance(); - if (this.isTemporaryWorld()) - { - plugin.clearMatch(this); - this.countTask.cancel(); - - plugin.getServer().unloadWorld(primaryWorld, false); - if (!plugin.getConfig().getBoolean("save-worlds", false)) - new WorldFolderDeleter(primaryWorld).runTaskTimer(plugin, 0L, 10 * 20L); + plugin.clearMatch(this); + this.countTask.cancel(); + plugin.getServer().unloadWorld(primaryWorld, false); + if (!plugin.getConfig().getBoolean("save-worlds", false)){ + new WorldFolderDeleter(primaryWorld).runTaskTimer(plugin, 0L, 10 * 20L); } + } } diff --git a/src/main/java/org/mctourney/autoreferee/commands/AdminCommands.java b/src/main/java/org/mctourney/autoreferee/commands/AdminCommands.java index d3f6af01..67d2285a 100644 --- a/src/main/java/org/mctourney/autoreferee/commands/AdminCommands.java +++ b/src/main/java/org/mctourney/autoreferee/commands/AdminCommands.java @@ -128,12 +128,21 @@ public boolean loadMapFromURL(CommandSender sender, AutoRefMatch match, String[] @AutoRefCommand(name={"autoref", "unload"}, argmin=0, argmax=0, description="Unloads the current map. Connected players are either moved to the lobby or kicked.") - @AutoRefPermission(console=true, nodes={"autoreferee.admin"}) + @AutoRefPermission(console=true) public boolean unloadMap(CommandSender sender, AutoRefMatch match, String[] args, CommandLine options) { - if (match != null) match.destroy(MatchUnloadEvent.Reason.COMMAND); - else sender.sendMessage(ChatColor.GRAY + "No world to unload."); + if (match == null) + { + sender.sendMessage(ChatColor.GRAY + "No world to unload."); + return false; + } + + if ((!match.isPracticeMode() || match.getCurrentState().isBeforeMatch()) + && !sender.hasPermission("autoreferee.admin")) return false; + + if (match != null) + match.destroy(MatchUnloadEvent.Reason.COMMAND); return true; }