Remove commands and hopefully permissions from registered information if not used, mainly applies to api version and disabled commands.
This commit is contained in:
		| @@ -27,9 +27,7 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | ||||
| import me.libraryaddict.disguise.utilities.reflection.asm.WatcherSanitizer; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.command.CommandExecutor; | ||||
| import org.bukkit.command.PluginCommand; | ||||
| import org.bukkit.command.TabCompleter; | ||||
| import org.bukkit.command.*; | ||||
| import org.bukkit.configuration.file.YamlConfiguration; | ||||
| import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; | ||||
| import org.bukkit.entity.Player; | ||||
| @@ -39,6 +37,8 @@ import org.bukkit.util.FileUtil; | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.util.Arrays; | ||||
| import java.util.Iterator; | ||||
| import java.util.Map; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| public class LibsDisguises extends JavaPlugin { | ||||
| @@ -161,9 +161,40 @@ public class LibsDisguises extends JavaPlugin { | ||||
|             getLogger().info("Commands has been disabled, as per config"); | ||||
|         } | ||||
|  | ||||
|         unregisterCommands(); | ||||
|  | ||||
|         new MetricsInitalizer(); | ||||
|     } | ||||
|  | ||||
|     private void unregisterCommands() { | ||||
|         CommandMap map = ReflectionManager.getCommandMap(); | ||||
|         Map<String, Command> commands = ReflectionManager.getCommands(map); | ||||
|  | ||||
|         for (String command : getDescription().getCommands().keySet()) { | ||||
|             PluginCommand cmd = getCommand("libsdisguises:" + command); | ||||
|  | ||||
|             if (cmd.getExecutor() != this) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             if (cmd.getPermission() != null && cmd.getPermission().startsWith("libsdisguises.seecmd")) { | ||||
|                 Bukkit.getPluginManager().removePermission(cmd.getPermission()); | ||||
|             } | ||||
|  | ||||
|             Iterator<Map.Entry<String, Command>> itel = commands.entrySet().iterator(); | ||||
|  | ||||
|             while (itel.hasNext()) { | ||||
|                 Map.Entry<String, Command> entry = itel.next(); | ||||
|  | ||||
|                 if (entry.getValue() != cmd) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 itel.remove(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public File getFile() { | ||||
|         return super.getFile(); | ||||
| @@ -195,7 +226,7 @@ public class LibsDisguises extends JavaPlugin { | ||||
|     } | ||||
|  | ||||
|     private void registerCommand(String commandName, CommandExecutor executioner) { | ||||
|         PluginCommand command = getCommand(commandName); | ||||
|         PluginCommand command = getCommand("libsdisguises:" + commandName); | ||||
|  | ||||
|         command.setExecutor(executioner); | ||||
|  | ||||
|   | ||||
| @@ -65,7 +65,7 @@ public class LibsPremium { | ||||
|      * @return true if userID does not contain __USER__ | ||||
|      */ | ||||
|     private static Boolean isPremium(String resourceID, String userID) { | ||||
|         return !userID.contains("__USER__") && !resourceID.equals("81"); | ||||
|         return !userID.contains("__USER__") && resourceID.equals("32453"); | ||||
|     } | ||||
|  | ||||
|     public static Boolean isAPIPlugin() { | ||||
|   | ||||
| @@ -16,12 +16,16 @@ import me.libraryaddict.disguise.utilities.LibsPremium; | ||||
| import org.apache.commons.lang.ArrayUtils; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.bukkit.*; | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandMap; | ||||
| import org.bukkit.command.SimpleCommandMap; | ||||
| import org.bukkit.configuration.InvalidConfigurationException; | ||||
| import org.bukkit.configuration.file.YamlConfiguration; | ||||
| import org.bukkit.entity.*; | ||||
| import org.bukkit.inventory.EquipmentSlot; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| import org.bukkit.inventory.meta.ItemMeta; | ||||
| import org.bukkit.plugin.SimplePluginManager; | ||||
| import org.bukkit.potion.PotionEffect; | ||||
| import org.bukkit.util.Vector; | ||||
|  | ||||
| @@ -1853,6 +1857,34 @@ public class ReflectionManager { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static Map<String, Command> getCommands(CommandMap map) { | ||||
|         try { | ||||
|             Field field = SimpleCommandMap.class.getDeclaredField("knownCommands"); | ||||
|             field.setAccessible(true); | ||||
|  | ||||
|             return (Map<String, Command>) field.get(map); | ||||
|         } | ||||
|         catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     public static SimpleCommandMap getCommandMap() { | ||||
|         try { | ||||
|             Field commandMap = SimplePluginManager.class.getDeclaredField("commandMap"); | ||||
|             commandMap.setAccessible(true); | ||||
|  | ||||
|             return (SimpleCommandMap) commandMap.get(Bukkit.getPluginManager()); | ||||
|         } | ||||
|         catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     private static String[] splitReadable(String string) { | ||||
|         String[] split = string.split("_"); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user