Ensure all command aliases are removed in onDisable, and only if they were not replaced.
This commit is contained in:
@@ -1,16 +1,5 @@
|
|||||||
package com.redstoner.modules.blockplacemods;
|
package com.redstoner.modules.blockplacemods;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
import com.nemez.cmdmgr.Command;
|
import com.nemez.cmdmgr.Command;
|
||||||
import com.redstoner.annotations.AutoRegisterListener;
|
import com.redstoner.annotations.AutoRegisterListener;
|
||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
@@ -22,9 +11,15 @@ import com.redstoner.modules.blockplacemods.mods.ModAbstract;
|
|||||||
import com.redstoner.modules.blockplacemods.mods.ModToggledAbstract;
|
import com.redstoner.modules.blockplacemods.mods.ModToggledAbstract;
|
||||||
import com.redstoner.utils.CommandException;
|
import com.redstoner.utils.CommandException;
|
||||||
import com.redstoner.utils.CommandMap;
|
import com.redstoner.utils.CommandMap;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@Version(major = 3, minor = 2, revision = 6, compatible = 3)
|
@Version(major = 3, minor = 2, revision = 7, compatible = 3)
|
||||||
public final class BlockPlaceMods implements Module, Listener
|
public final class BlockPlaceMods implements Module, Listener
|
||||||
{
|
{
|
||||||
public static String PREFIX = ChatColor.GRAY + "[" + ChatColor.DARK_GREEN + "BPM" + ChatColor.GRAY + "]"
|
public static String PREFIX = ChatColor.GRAY + "[" + ChatColor.DARK_GREEN + "BPM" + ChatColor.GRAY + "]"
|
||||||
@@ -41,30 +36,15 @@ public final class BlockPlaceMods implements Module, Listener
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Map<String, org.bukkit.command.Command> commandMap = CommandMap.getCommandMap();
|
Map<String, org.bukkit.command.Command> commandMap = CommandMap.getCommandMap();
|
||||||
// @noformat
|
org.bukkit.command.Command command = new BlockPlaceModsCommand();
|
||||||
String pluginName = Main.plugin.getName().toLowerCase();
|
for (String alias : getCommandAliases())
|
||||||
String[] aliases = {"mod", pluginName + ":mod",
|
|
||||||
"set", pluginName + ":mod",
|
|
||||||
"toggle", pluginName + ":toggle"
|
|
||||||
};
|
|
||||||
// @format
|
|
||||||
org.bukkit.command.Command command = new org.bukkit.command.Command("mod")
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean execute(CommandSender sender, String label, String[] args)
|
|
||||||
{
|
|
||||||
onModCommand(sender, String.join(" ", args));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
for (String alias : aliases)
|
|
||||||
{
|
{
|
||||||
commandMap.put(alias, command);
|
commandMap.put(alias, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ReflectiveOperationException ex)
|
catch (ReflectiveOperationException ex)
|
||||||
{
|
{
|
||||||
throw new Error(ex);
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -76,16 +56,33 @@ public final class BlockPlaceMods implements Module, Listener
|
|||||||
{
|
{
|
||||||
mod.unregisterListeners();
|
mod.unregisterListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Map<String, org.bukkit.command.Command> commandMap = CommandMap.getCommandMap();
|
Map<String, org.bukkit.command.Command> commandMap = CommandMap.getCommandMap();
|
||||||
commandMap.remove("mod");
|
for (String alias : getCommandAliases())
|
||||||
commandMap.remove(Main.plugin.getName().toLowerCase() + ":mod");
|
{
|
||||||
|
if (commandMap.get(alias).getClass() == BlockPlaceModsCommand.class)
|
||||||
|
{
|
||||||
|
commandMap.remove(alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ignored)
|
catch (Exception ignored)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String[] getCommandAliases()
|
||||||
|
{
|
||||||
|
String pluginName = Main.plugin.getName().toLowerCase();
|
||||||
|
// @noformat
|
||||||
|
return new String[]{"mod", pluginName + ":mod",
|
||||||
|
"set", pluginName + ":mod",
|
||||||
|
"toggle", pluginName + ":toggle"
|
||||||
|
};
|
||||||
|
// @format
|
||||||
|
}
|
||||||
|
|
||||||
@Command(hook = "mod_empty")
|
@Command(hook = "mod_empty")
|
||||||
public void onModEmptyCommand(CommandSender sender)
|
public void onModEmptyCommand(CommandSender sender)
|
||||||
{
|
{
|
||||||
@@ -177,4 +174,22 @@ public final class BlockPlaceMods implements Module, Listener
|
|||||||
}
|
}
|
||||||
return modName;
|
return modName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class BlockPlaceModsCommand extends org.bukkit.command.Command
|
||||||
|
{
|
||||||
|
public BlockPlaceModsCommand()
|
||||||
|
{
|
||||||
|
super("mod");
|
||||||
|
String[] aliases = getCommandAliases();
|
||||||
|
setAliases(Arrays.asList(Arrays.copyOfRange(aliases, 1, aliases.length)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, String label, String[] args)
|
||||||
|
{
|
||||||
|
onModCommand(sender, String.join(" ", args));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user