Close menus when the plugin is disabled

This commit is contained in:
filoghost 2016-06-13 13:56:49 +02:00
parent f3aab47bad
commit fa382186c8
2 changed files with 29 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.gmail.filoghost.chestcommands.SimpleUpdater.ResponseHandler;
@ -24,6 +25,7 @@ import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
import com.gmail.filoghost.chestcommands.internal.BoundItem;
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
import com.gmail.filoghost.chestcommands.internal.MenuData;
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
import com.gmail.filoghost.chestcommands.listener.CommandListener;
import com.gmail.filoghost.chestcommands.listener.InventoryListener;
import com.gmail.filoghost.chestcommands.listener.JoinListener;
@ -36,6 +38,7 @@ import com.gmail.filoghost.chestcommands.task.RefreshMenusTask;
import com.gmail.filoghost.chestcommands.util.CaseInsensitiveMap;
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
import com.gmail.filoghost.chestcommands.util.Utils;
import com.gmail.filoghost.chestcommands.util.VersionUtils;
public class ChestCommands extends JavaPlugin {
@ -128,6 +131,15 @@ public class ChestCommands extends JavaPlugin {
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshMenusTask(), 2L, 2L);
}
@Override
public void onDisable() {
closeAllMenus();
}
public void load(ErrorLogger errorLogger) {
fileNameToMenuMap.clear();
commandsToMenuMap.clear();
@ -234,6 +246,8 @@ public class ChestCommands extends JavaPlugin {
}
}
/**
* Loads all the configuration files recursively into a list.
*/
@ -251,6 +265,20 @@ public class ChestCommands extends JavaPlugin {
return list;
}
public static void closeAllMenus() {
for (Player player : VersionUtils.getOnlinePlayers()) {
if (player.getOpenInventory() != null) {
if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) {
player.closeInventory();
}
}
}
}
public static ChestCommands getInstance() {
return instance;
}

View File

@ -9,10 +9,8 @@ import org.bukkit.entity.Player;
import com.gmail.filoghost.chestcommands.ChestCommands;
import com.gmail.filoghost.chestcommands.Permissions;
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
import com.gmail.filoghost.chestcommands.task.ErrorLoggerTask;
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
import com.gmail.filoghost.chestcommands.util.VersionUtils;
public class CommandHandler extends CommandFramework {
@ -47,13 +45,7 @@ public class CommandHandler extends CommandFramework {
if (args[0].equalsIgnoreCase("reload")) {
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "reload"), "You don't have permission.");
for (Player player : VersionUtils.getOnlinePlayers()) {
if (player.getOpenInventory() != null) {
if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) {
player.closeInventory();
}
}
}
ChestCommands.closeAllMenus();
ErrorLogger errorLogger = new ErrorLogger();
ChestCommands.getInstance().load(errorLogger);