Skip to content

Fixed unloading not working properly #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/main/java/org/mctourney/autoreferee/AutoRefMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down