├── license ├── licenses.properties └── mit │ ├── header.txt │ └── license.txt ├── images ├── github_logo.png ├── jenkins_logo.png ├── yourkit_logo.png ├── intreppid_logo.png └── jetbrains_logo.png ├── .gitignore ├── src └── main │ ├── resources │ ├── PlugManDummy.jar │ ├── bungee.yml │ ├── config.yml │ ├── resourcemaps.yml │ ├── plugin.yml │ ├── messages_jp.yml │ ├── messages.yml │ ├── messages_es.yml │ └── messages_de.yml │ └── java │ ├── com │ └── rylinaux │ │ └── plugman │ │ ├── api │ │ ├── GentleUnload.java │ │ └── PlugManAPI.java │ │ ├── util │ │ ├── BukkitCommandWrap_Useless.java │ │ ├── CollectionUtil.java │ │ ├── StringUtil.java │ │ ├── ThreadUtil.java │ │ ├── FlagUtil.java │ │ ├── PluginUtil.java │ │ ├── UpdateUtil.java │ │ ├── SpiGetUtil.java │ │ ├── CurseForgeUtil.java │ │ └── BukkitCommandWrap.java │ │ ├── messaging │ │ ├── MessageFile.java │ │ └── MessageFormatter.java │ │ ├── command │ │ ├── HelpCommand.java │ │ ├── UsageCommand.java │ │ ├── LookupCommand.java │ │ ├── ListCommand.java │ │ ├── DumpCommand.java │ │ ├── UnloadCommand.java │ │ ├── LoadCommand.java │ │ ├── ReloadCommand.java │ │ ├── RestartCommand.java │ │ ├── DisableCommand.java │ │ ├── EnableCommand.java │ │ ├── InfoCommand.java │ │ ├── DownloadCommand.java │ │ ├── AbstractCommand.java │ │ └── CheckCommand.java │ │ ├── pojo │ │ └── UpdateResult.java │ │ ├── PlugManCommandHandler.java │ │ └── PlugManTabCompleter.java │ └── me │ └── entity303 │ └── plugmanbungee │ ├── util │ ├── PluginResult.java │ └── BungeePluginUtil.java │ ├── main │ └── PlugManBungee.java │ └── commands │ ├── PluginsCommand.java │ ├── cmd │ ├── UnloadCommand.java │ ├── ReloadCommand.java │ └── LoadCommand.java │ └── PlugManBungeeCommand.java ├── LICENSE.md ├── README.md └── pom.xml /license/licenses.properties: -------------------------------------------------------------------------------- 1 | mit=MIT License -------------------------------------------------------------------------------- /images/github_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firestarter/plugman/master/images/github_logo.png -------------------------------------------------------------------------------- /images/jenkins_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firestarter/plugman/master/images/jenkins_logo.png -------------------------------------------------------------------------------- /images/yourkit_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firestarter/plugman/master/images/yourkit_logo.png -------------------------------------------------------------------------------- /images/intreppid_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firestarter/plugman/master/images/intreppid_logo.png -------------------------------------------------------------------------------- /images/jetbrains_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firestarter/plugman/master/images/jetbrains_logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /out/ 3 | /.idea/ 4 | /*.iml 5 | dependency-reduced-pom.xml 6 | copy.bat 7 | delete.bat 8 | .attach* 9 | -------------------------------------------------------------------------------- /src/main/resources/PlugManDummy.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firestarter/plugman/master/src/main/resources/PlugManDummy.jar -------------------------------------------------------------------------------- /src/main/resources/bungee.yml: -------------------------------------------------------------------------------- 1 | name: PlugManBungee 2 | version: 2.3.7 3 | main: me.entity303.plugmanbungee.main.PlugManBungee 4 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/api/GentleUnload.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.api; 2 | 3 | public interface GentleUnload { 4 | 5 | boolean askingForGentleUnload(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/BukkitCommandWrap_Useless.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | import org.bukkit.command.Command; 4 | 5 | public class BukkitCommandWrap_Useless extends BukkitCommandWrap { 6 | 7 | public BukkitCommandWrap_Useless() { 8 | } 9 | 10 | @Override 11 | public void wrap(Command command, String alias) { 12 | } 13 | 14 | @Override 15 | public void unwrap(String command) { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/util/PluginResult.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.util; 2 | 3 | public class PluginResult { 4 | private final String message; 5 | private final boolean positive; 6 | 7 | public PluginResult(String message, boolean positive) { 8 | this.message = message; 9 | this.positive = positive; 10 | } 11 | 12 | public String getMessage() { 13 | return message; 14 | } 15 | 16 | public boolean isPositive() { 17 | return positive; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | ### 2 | # A list of plugins that we should ignore when doing enable, disable, restart, load, reload, and unload. 3 | # 4 | # This takes the form of a comma separated list enclosed within the brackets. 5 | ### 6 | ignored-plugins: [PlugMan,PlugManX,ViaVersion,ViaBackwards,ViaRewind,ProtocolSupport,ProtocolLib] 7 | notify-on-broken-command-removal: true 8 | disable-download-command: true 9 | auto-load: 10 | enabled: false 11 | check-every-seconds: 10 12 | auto-unload: 13 | enabled: false 14 | check-every-seconds: 10 15 | auto-reload: 16 | enabled: false 17 | check-every-seconds: 10 18 | # Do not change this value 19 | version: 1 -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | import java.util.function.Supplier; 6 | 7 | public class CollectionUtil { 8 | public static int maxCollectionsSize(Collection collection1, Collection collection2) { 9 | return Math.max(collection1.size(), collection2.size()); 10 | } 11 | 12 | public static T getElementOrDefault(List list, int index, Supplier defaults) { 13 | if (index < 0) throw new IllegalArgumentException("index < 0"); 14 | if (index >= list.size()) return defaults.get(); 15 | return list.get(index); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/main/PlugManBungee.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.main; 2 | 3 | import me.entity303.plugmanbungee.commands.PlugManBungeeCommand; 4 | import me.entity303.plugmanbungee.commands.PluginsCommand; 5 | import net.md_5.bungee.api.ProxyServer; 6 | import net.md_5.bungee.api.plugin.Listener; 7 | import net.md_5.bungee.api.plugin.Plugin; 8 | 9 | public final class PlugManBungee extends Plugin implements Listener { 10 | private static PlugManBungee instance; 11 | 12 | @Override 13 | public void onEnable() { 14 | instance = this; 15 | 16 | ProxyServer.getInstance().getPluginManager().registerCommand(this, new PluginsCommand()); 17 | ProxyServer.getInstance().getPluginManager().registerCommand(this, new PlugManBungeeCommand()); 18 | } 19 | 20 | @Override 21 | public void onDisable() { 22 | } 23 | 24 | public static PlugManBungee getInstance() { 25 | return instance; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 TheBlackEntity/ryan-clancy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /license/mit/header.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Ryan Clancy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /license/mit/license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Ryan Clancy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/commands/PluginsCommand.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.commands; 2 | 3 | import net.md_5.bungee.api.ChatColor; 4 | import net.md_5.bungee.api.CommandSender; 5 | import net.md_5.bungee.api.ProxyServer; 6 | import net.md_5.bungee.api.chat.TextComponent; 7 | import net.md_5.bungee.api.plugin.Command; 8 | import net.md_5.bungee.api.plugin.Plugin; 9 | 10 | import java.util.Collection; 11 | import java.util.stream.Collectors; 12 | 13 | public class PluginsCommand extends Command { 14 | 15 | public PluginsCommand() { 16 | super("bungeeplugins", "plugman.seeplugins", "bpl"); 17 | } 18 | 19 | @Override 20 | public void execute(CommandSender sender, String[] args) { 21 | Collection plugins = ProxyServer.getInstance().getPluginManager().getPlugins(); 22 | String message = plugins.stream().map(plugin -> ChatColor.RESET + "," + " " + (plugin.getDescription() == null ? ChatColor.RED : ChatColor.GREEN) + plugin.getDescription().getName()).collect(Collectors.joining("", "Plugins (" + plugins.size() + "):", "")); 23 | sender.sendMessage(new TextComponent(message.replace(":" + ChatColor.RESET + ",", ":"))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/resources/resourcemaps.yml: -------------------------------------------------------------------------------- 1 | Resources: 2 | BetterSleeping3: 3 | ID: 60837 4 | spigotmc: true 5 | AntiXRay: 6 | ID: 40729 7 | spigotmc: false 8 | DeadChest: 9 | ID: 322882 10 | spigotmc: false 11 | DeathCoordinates: 12 | ID: 43318 13 | spigotmc: true 14 | dynmap: 15 | ID: 274 16 | spigotmc: true 17 | Dynmap-Essentials: 18 | ID: 35085 19 | spigotmc: false 20 | Dynmap-GriefPrevention: 21 | ID: 37535 22 | spigotmc: false 23 | Essentials: 24 | ID: 9089 25 | spigotmc: true 26 | EssentialsChat: 27 | ID: 9089 28 | spigotmc: true 29 | EssentialsGeoIP: 30 | ID: 9089 31 | spigotmc: true 32 | EssentialsSpawn: 33 | ID: 9089 34 | spigotmc: true 35 | Jobs: 36 | ID: 4216 37 | spigotmc: true 38 | PetMaster: 39 | ID: 15904 40 | spigotmc: true 41 | ServerUtils: 42 | ID: 79599 43 | spigotmc: true 44 | ServerSystem: 45 | ID: 78974 46 | spigotmc: true 47 | TimeIsMoney: 48 | ID: 12409 49 | spigotmc: true 50 | TogglePvp: 51 | ID: 44918 52 | spigotmc: true 53 | TreeGravity: 54 | ID: 59283 55 | spigotmc: true 56 | Vault: 57 | ID: 34315 58 | spigotmc: true -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | /** 30 | * Utilities for String manipulation. 31 | * 32 | * @author rylinaux 33 | */ 34 | public class StringUtil { 35 | 36 | /** 37 | * Returns an array of Strings as a single String. 38 | * 39 | * @param args the array 40 | * @param start the index to start at 41 | * @return the array as a String 42 | */ 43 | public static String consolidateStrings(String[] args, int start) { 44 | String ret = args[start]; 45 | if (args.length > (start + 1)) { 46 | for (int i = (start + 1); i < args.length; i++) 47 | ret = ret + " " + args[i]; 48 | } 49 | return ret; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/ThreadUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2015 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.Bukkit; 31 | 32 | /** 33 | * Utility class for threading. 34 | * 35 | * @author rylinaux 36 | */ 37 | public class ThreadUtil { 38 | 39 | /** 40 | * Run a task in a separate thread. 41 | * 42 | * @param runnable the task. 43 | */ 44 | public static void async(Runnable runnable) { 45 | Bukkit.getScheduler().runTaskAsynchronously(PlugMan.getInstance(), runnable); 46 | } 47 | 48 | /** 49 | * Run a task in the main thread. 50 | * 51 | * @param runnable the task. 52 | */ 53 | public static void sync(Runnable runnable) { 54 | Bukkit.getScheduler().runTask(PlugMan.getInstance(), runnable); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/commands/cmd/UnloadCommand.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.commands.cmd; 2 | 3 | import me.entity303.plugmanbungee.util.BungeePluginUtil; 4 | import me.entity303.plugmanbungee.util.PluginResult; 5 | import net.md_5.bungee.api.CommandSender; 6 | import net.md_5.bungee.api.ProxyServer; 7 | import net.md_5.bungee.api.chat.TextComponent; 8 | import net.md_5.bungee.api.plugin.PluginManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | import java.util.Locale; 13 | import java.util.stream.Collectors; 14 | 15 | public class UnloadCommand { 16 | 17 | public void execute(CommandSender sender, String[] args) { 18 | if (args.length <= 0) { 19 | sendMessage(sender, "§cSyntax: §4/PlugManBungee unload "); 20 | return; 21 | } 22 | 23 | String pluginName = args[0]; 24 | 25 | PluginManager pluginManager = ProxyServer.getInstance().getPluginManager(); 26 | 27 | if (pluginManager.getPlugin(pluginName) == null) { 28 | sendMessage(sender, "§cThere is no plugin named §4" + pluginName + "§c!"); 29 | return; 30 | } 31 | 32 | PluginResult pluginResult = BungeePluginUtil.unloadPlugin(pluginManager.getPlugin(pluginName)); 33 | sendMessage(sender, pluginResult.getMessage()); 34 | } 35 | 36 | private void sendMessage(CommandSender sender, String message) { 37 | sender.sendMessage(new TextComponent("§8[§2PlugManBungee§8] §7" + message)); 38 | } 39 | 40 | public Iterable onTabComplete(CommandSender sender, String[] args) { 41 | if (args.length == 1) { 42 | List completions = ProxyServer.getInstance().getPluginManager().getPlugins().stream().map(plugin -> plugin.getDescription().getName()).collect(Collectors.toList()); 43 | 44 | List realCompletions = new ArrayList<>(); 45 | 46 | for (String com : completions) { 47 | if (com.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT))) { 48 | realCompletions.add(com); 49 | } 50 | } 51 | 52 | return realCompletions.size() > 0 ? realCompletions : completions; 53 | } 54 | return new ArrayList<>(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/FlagUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2015 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | 30 | import java.util.ArrayList; 31 | import java.util.Arrays; 32 | import java.util.Iterator; 33 | import java.util.List; 34 | 35 | /** 36 | * Utilities for dealing with flags passed to commands. 37 | * 38 | * @author rylinaux 39 | */ 40 | public class FlagUtil { 41 | 42 | /** 43 | * Check if a flag exists in the command arguments and remove it from the original array. 44 | * 45 | * @param args the array of arguments. 46 | * @param flag the flag to check for. 47 | * @return true if the flag exists. 48 | */ 49 | public static boolean hasFlag(String[] args, char flag) { 50 | 51 | List list = new ArrayList(Arrays.asList(args)); 52 | 53 | for (Iterator it = list.iterator(); it.hasNext();) { 54 | if (it.next().equalsIgnoreCase("-" + flag)) { 55 | it.remove(); 56 | args = list.toArray(args); 57 | return true; 58 | } 59 | } 60 | 61 | return false; 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/commands/cmd/ReloadCommand.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.commands.cmd; 2 | 3 | import me.entity303.plugmanbungee.util.BungeePluginUtil; 4 | import me.entity303.plugmanbungee.util.PluginResult; 5 | import net.md_5.bungee.api.CommandSender; 6 | import net.md_5.bungee.api.ProxyServer; 7 | import net.md_5.bungee.api.chat.TextComponent; 8 | import net.md_5.bungee.api.plugin.PluginManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | import java.util.Locale; 13 | import java.util.Map; 14 | import java.util.stream.Collectors; 15 | 16 | public class ReloadCommand { 17 | 18 | public void execute(CommandSender sender, String[] args) { 19 | if (args.length <= 0) { 20 | sendMessage(sender, "§cSyntax: §4/PlugManBungee reload "); 21 | return; 22 | } 23 | 24 | String pluginName = args[0]; 25 | 26 | PluginManager pluginManager = ProxyServer.getInstance().getPluginManager(); 27 | 28 | if (pluginManager.getPlugin(pluginName) == null) { 29 | sendMessage(sender, "§cThere is no plugin named §4" + pluginName + "§c!"); 30 | return; 31 | } 32 | 33 | Map.Entry pluginResults = BungeePluginUtil.reloadPlugin(pluginManager.getPlugin(pluginName)); 34 | sendMessage(sender, pluginResults.getKey().getMessage()); 35 | sendMessage(sender, pluginResults.getValue().getMessage()); 36 | } 37 | 38 | private void sendMessage(CommandSender sender, String message) { 39 | sender.sendMessage(new TextComponent("§8[§2PlugManBungee§8] §7" + message)); 40 | } 41 | 42 | public Iterable onTabComplete(CommandSender sender, String[] args) { 43 | if (args.length == 1) { 44 | List completions = ProxyServer.getInstance().getPluginManager().getPlugins().stream().map(plugin -> plugin.getDescription().getName()).collect(Collectors.toList()); 45 | 46 | List realCompletions = new ArrayList<>(); 47 | 48 | for (String com : completions) { 49 | if (com.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT))) { 50 | realCompletions.add(com); 51 | } 52 | } 53 | 54 | return realCompletions.size() > 0 ? realCompletions : completions; 55 | } 56 | return new ArrayList<>(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/api/PlugManAPI.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.api; 2 | 3 | import com.rylinaux.plugman.PlugMan; 4 | 5 | import java.util.HashMap; 6 | 7 | public class PlugManAPI { 8 | protected static final HashMap gentleUnloads = new HashMap<>(); 9 | private static Class pluginClass = null; 10 | 11 | /** 12 | * @return = Returns all plugins which should be unloaded gently 13 | */ 14 | public static HashMap getGentleUnloads() { 15 | return new HashMap<>(PlugManAPI.gentleUnloads); 16 | } 17 | 18 | /** 19 | * A gentle unload is when a plugin wants to unload itself, so PlugMan doesn't break stuff 20 | * 21 | * @param plugin = Plugin which wants a gentle unload 22 | * @param gentleUnload = The class which will handle the gentle unload 23 | * @return = If the plugin is allowed to be unloaded gently 24 | */ 25 | public static boolean pleaseAddMeToGentleUnload(Object plugin, GentleUnload gentleUnload) { 26 | if (plugin == null) 27 | return false; 28 | 29 | if (gentleUnload == null) 30 | return false; 31 | 32 | if (PlugManAPI.pluginClass == null) try { 33 | PlugManAPI.pluginClass = Class.forName("org.bukkit.plugin.Plugin"); 34 | } catch (ClassNotFoundException e) { 35 | try { 36 | PlugManAPI.pluginClass = Class.forName("net.md_5.bungee.api.plugin.Plugin"); 37 | } catch (ClassNotFoundException ex) { 38 | ex.addSuppressed(e); 39 | ex.printStackTrace(); 40 | return false; 41 | } 42 | } 43 | 44 | if (PlugManAPI.gentleUnloads.containsKey(plugin)) 45 | return false; 46 | 47 | if (!PlugManAPI.pluginClass.isInstance(plugin)) 48 | return false; 49 | 50 | PlugManAPI.gentleUnloads.put(plugin, gentleUnload); 51 | return true; 52 | } 53 | 54 | /** 55 | * If you don't want your plugin to be un-/reloaded, you can use this method to add it to the list of ignored plugins 56 | * 57 | * @param plugin = The plugin that should be ignored 58 | * @return = Whether the method was executed successfully 59 | */ 60 | public static boolean iDoNotWantToBeUnOrReloaded(String plugin) { 61 | if (PlugMan.getInstance() == null) 62 | return false; 63 | 64 | if (PlugMan.getInstance().getIgnoredPlugins() == null) 65 | return false; 66 | 67 | PlugMan.getInstance().getIgnoredPlugins().add(plugin); 68 | return true; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/messaging/MessageFile.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.messaging; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2015 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import org.bukkit.configuration.file.FileConfiguration; 30 | import org.bukkit.configuration.file.YamlConfiguration; 31 | 32 | import java.io.File; 33 | import java.io.InputStreamReader; 34 | 35 | /** 36 | * Class that allows reading from a YAML file embedded in the JAR. 37 | * 38 | * @author rylinaux 39 | */ 40 | public class MessageFile { 41 | 42 | /** 43 | * The configuration. 44 | */ 45 | private FileConfiguration config = null; 46 | 47 | /** 48 | * Construct the object. 49 | * 50 | * @param name the name of the file. 51 | */ 52 | public MessageFile(String name) { 53 | this.config = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(name))); 54 | } 55 | 56 | /** 57 | * Construct the object. 58 | * 59 | * @param file the file. 60 | */ 61 | public MessageFile(File file) { 62 | this.config = YamlConfiguration.loadConfiguration(file); 63 | } 64 | 65 | /** 66 | * Get the FileConfiguration. 67 | * 68 | * @return the FileConfiguration. 69 | */ 70 | public FileConfiguration getConfig() { 71 | return config; 72 | } 73 | 74 | /** 75 | * Get a key from the file. 76 | * 77 | * @param key the key. 78 | * @return the value. 79 | */ 80 | public String get(String key) { 81 | return config.getString(key); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: PlugManX 2 | main: com.rylinaux.plugman.PlugMan 3 | version: 2.3.7 4 | description: Plugin manager for Bukkit servers 5 | authors: [rylinaux, Entity303] 6 | api-version: 1.13 7 | folia-supported: true 8 | provides: [PlugMan] 9 | load: STARTUP 10 | softdepend: 11 | - PlugMan 12 | commands: 13 | plugman: 14 | description: Manage plugins. 15 | permission: plugman.help 16 | usage: /plugman (help|dump) 17 | /plugman list [-v] 18 | /plugman check [-f] 19 | /plugman lookup 20 | /plugman (enable|disable|restart) 21 | /plugman (info|usage|load|download|reload|unload) 22 | permissions: 23 | plugman.admin: 24 | description: Allows use of all PlugMan commands. 25 | default: op 26 | children: 27 | plugman.update: true 28 | plugman.help: true 29 | plugman.list: true 30 | plugman.dump: true 31 | plugman.info: true 32 | plugman.usage: true 33 | plugman.lookup: true 34 | plugman.enable: true 35 | plugman.enable.all: true 36 | plugman.disable: true 37 | plugman.disable.all: true 38 | plugman.restart: true 39 | plugman.restart.all: true 40 | plugman.load: true 41 | plugman.download: true 42 | plugman.reload: true 43 | plugman.unload: true 44 | plugman.check: true 45 | plugman.check.all: true 46 | plugman.update: 47 | description: Allows the player to see the update alerts. 48 | default: op 49 | plugman.help: 50 | description: Allows use of the help command. 51 | default: op 52 | plugman.list: 53 | description: Allows use of the list command. 54 | default: op 55 | plugman.dump: 56 | description: Allows use of the dump command. 57 | default: op 58 | plugman.info: 59 | description: Allows use of the info command. 60 | default: op 61 | plugman.usage: 62 | description: Allows use of the usage command. 63 | default: op 64 | plugman.lookup: 65 | description: Allows use of the lookup command. 66 | default: op 67 | plugman.enable: 68 | description: Allows use of the enable command. 69 | default: op 70 | plugman.enable.all: 71 | description: Allows use of the enable all command. 72 | default: op 73 | plugman.disable: 74 | description: Allows use of the disable command. 75 | default: op 76 | plugman.disable.all: 77 | description: Allows use of the disable all command. 78 | default: op 79 | plugman.restart: 80 | description: Allows use of the restart command. 81 | default: op 82 | plugman.restart.all: 83 | description: Allows use of the restart all command. 84 | default: op 85 | plugman.load: 86 | description: Allows use of the load command. 87 | default: op 88 | plugman.download: 89 | description: Allows use of the download command. 90 | default: op 91 | plugman.reload: 92 | description: Allows use of the reload command. 93 | default: op 94 | plugman.unload: 95 | description: Allows use of the unload command. 96 | default: op 97 | plugman.check: 98 | description: Allows use of the check command. 99 | default: op 100 | plugman.check.all: 101 | description: Allows use of the check all command. 102 | default: op 103 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/messaging/MessageFormatter.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.messaging; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import org.bukkit.ChatColor; 30 | 31 | import java.io.File; 32 | 33 | /** 34 | * Manages custom messages. 35 | * 36 | * @author rylinaux 37 | */ 38 | public class MessageFormatter { 39 | 40 | /** 41 | * The configuration file. 42 | */ 43 | private final MessageFile messageFile; 44 | 45 | /** 46 | * Construct our object. 47 | */ 48 | public MessageFormatter() { 49 | this.messageFile = new MessageFile(new File("plugins" + File.separator + "PlugManX", "messages.yml")); 50 | } 51 | 52 | /** 53 | * Returns the formatted version of the message. 54 | * 55 | * @param key the key 56 | * @param args the args to replace 57 | * @return the formatted String 58 | */ 59 | public String format(String key, Object... args) { 60 | return format(true, key, args); 61 | } 62 | 63 | /** 64 | * Returns the formatted version of the message. 65 | * 66 | * @param prefix whether to prepend with the plugin's prefix 67 | * @param key the key 68 | * @param args the args to replace 69 | * @return the formatted String 70 | */ 71 | public String format(boolean prefix, String key, Object... args) { 72 | String message = prefix ? messageFile.get("prefix") + messageFile.get(key) : messageFile.get(key); 73 | for (int i = 0; i < args.length; i++) 74 | message = message.replace("{" + i + "}", String.valueOf(args[i])); 75 | return ChatColor.translateAlternateColorCodes('&', message); 76 | } 77 | 78 | /** 79 | * Add the prefix to a message. 80 | * 81 | * @param msg the message. 82 | * @return the message with the prefix. 83 | */ 84 | public String prefix(String msg) { 85 | return ChatColor.translateAlternateColorCodes('&', messageFile.get("prefix") + msg); 86 | } 87 | 88 | /** 89 | * Returns the message configuration. 90 | * 91 | * @return the message configuration. 92 | */ 93 | public MessageFile getMessageFile() { 94 | return messageFile; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/HelpCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.configuration.ConfigurationSection; 33 | 34 | /** 35 | * Command that displays the help. 36 | * 37 | * @author rylinaux 38 | */ 39 | public class HelpCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Help"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "Displays help information."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.help"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman help"; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {""}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public HelpCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command. 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | ConfigurationSection help = PlugMan.getInstance().getMessageFormatter().getMessageFile().getConfig().getConfigurationSection("help"); 92 | 93 | for (String s : help.getKeys(false)) { 94 | if (sender.hasPermission("plugman." + s) || s.equalsIgnoreCase("header")) 95 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, help.getName() + "." + s)); 96 | } 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/commands/cmd/LoadCommand.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.commands.cmd; 2 | 3 | import me.entity303.plugmanbungee.util.BungeePluginUtil; 4 | import me.entity303.plugmanbungee.util.PluginResult; 5 | import net.md_5.bungee.api.CommandSender; 6 | import net.md_5.bungee.api.ProxyServer; 7 | import net.md_5.bungee.api.chat.TextComponent; 8 | import net.md_5.bungee.config.Configuration; 9 | import net.md_5.bungee.config.ConfigurationProvider; 10 | import net.md_5.bungee.config.YamlConfiguration; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.io.InputStreamReader; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.Locale; 19 | import java.util.jar.JarEntry; 20 | import java.util.jar.JarFile; 21 | 22 | public class LoadCommand { 23 | 24 | public void execute(CommandSender sender, String[] args) { 25 | if (args.length <= 0) { 26 | this.sendMessage(sender, "§cSyntax: §4/PlugManBungee unload "); 27 | return; 28 | } 29 | 30 | String filename = args[0].replaceAll("[/\\\\]", ""); 31 | 32 | File file = new File("plugins", filename + ".jar"); 33 | 34 | if (!file.exists()) { 35 | this.sendMessage(sender, "§cThere is no plugin file named §4" + filename + "§c!"); 36 | return; 37 | } 38 | 39 | PluginResult pluginResult = BungeePluginUtil.loadPlugin(file); 40 | 41 | this.sendMessage(sender, pluginResult.getMessage()); 42 | } 43 | 44 | private void sendMessage(CommandSender sender, String message) { 45 | sender.sendMessage(new TextComponent("§8[§2PlugManBungee§8] §7" + message)); 46 | } 47 | 48 | public Iterable onTabComplete(CommandSender sender, String[] args) { 49 | if (args.length == 1) { 50 | List completions = new ArrayList<>(); 51 | //Yaml yaml = new Yaml(); 52 | for (File file : new File("plugins").listFiles()) 53 | if (file.isFile()) if (file.getName().toLowerCase(Locale.ROOT).endsWith(".jar")) 54 | try (JarFile jar = new JarFile(file)) { 55 | JarEntry pdf = jar.getJarEntry("bungee.yml"); 56 | if (pdf == null) pdf = jar.getJarEntry("plugin.yml"); 57 | 58 | if (pdf == null) 59 | continue; 60 | 61 | try (InputStream in = jar.getInputStream(pdf)) { 62 | //PluginDescription desc = yaml.loadAs(in, PluginDescription.class); 63 | Configuration cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new InputStreamReader(in)); 64 | 65 | if (cfg.get("name", null) == null) 66 | continue; 67 | 68 | if (cfg.get("main", null) == null) 69 | continue; 70 | 71 | if (ProxyServer.getInstance().getPluginManager().getPlugin(cfg.getString("name", null)) != null) 72 | continue; 73 | 74 | completions.add(file.getName().substring(0, file.getName().length() - 4)); 75 | } 76 | } catch (IOException ignored) { 77 | } 78 | 79 | List realCompletions = new ArrayList<>(); 80 | 81 | for (String com : completions) 82 | if (com.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT))) realCompletions.add(com); 83 | 84 | return realCompletions.size() > 0 ? realCompletions : completions; 85 | } 86 | return new ArrayList<>(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/pojo/UpdateResult.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.pojo; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2015 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | /** 30 | * Represents a result from an update check from DBO. 31 | * 32 | * @author rylinaux 33 | */ 34 | public class UpdateResult { 35 | 36 | /** 37 | * The type of the result. 38 | */ 39 | private final ResultType type; 40 | 41 | /** 42 | * The current version of the plugin. 43 | */ 44 | private final String currentVersion; 45 | 46 | /** 47 | * The latest version of the plugin. 48 | */ 49 | private final String latestVersion; 50 | 51 | /** 52 | * Represents the type of the result. 53 | */ 54 | public enum ResultType { 55 | INVALID_PLUGIN, NOT_INSTALLED, OUT_OF_DATE, UP_TO_DATE 56 | } 57 | 58 | /** 59 | * Construct the object with no versions. 60 | * 61 | * @param type the type of the result. 62 | */ 63 | public UpdateResult(ResultType type) { 64 | this(type, null, null); 65 | } 66 | 67 | /** 68 | * Construct the object with only the current version. 69 | * 70 | * @param type the type of the result. 71 | * @param currentVersion the current version. 72 | */ 73 | public UpdateResult(ResultType type, String currentVersion) { 74 | this(type, currentVersion, null); 75 | } 76 | 77 | /** 78 | * Construct the object. 79 | * 80 | * @param type the type of the result. 81 | * @param currentVersion the current version of the plugin. 82 | * @param latestVersion the latest version of the plugin. 83 | */ 84 | public UpdateResult(ResultType type, String currentVersion, String latestVersion) { 85 | this.type = type; 86 | this.currentVersion = currentVersion; 87 | this.latestVersion = latestVersion; 88 | } 89 | 90 | /** 91 | * Get the type of the result. 92 | * 93 | * @return the type of the result. 94 | */ 95 | public ResultType getType() { 96 | return type; 97 | } 98 | 99 | /** 100 | * Get the current version of the plugin. 101 | * 102 | * @return the current version of the plugin. 103 | */ 104 | public String getCurrentVersion() { 105 | return currentVersion; 106 | } 107 | 108 | /** 109 | * Get the latest version of the plugin. 110 | * 111 | * @return the latest version of the plugin. 112 | */ 113 | public String getLatestVersion() { 114 | return latestVersion; 115 | } 116 | 117 | } -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/PlugManCommandHandler.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.command.*; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandExecutor; 32 | import org.bukkit.command.CommandSender; 33 | 34 | /** 35 | * Listen for commands and execute them. 36 | * 37 | * @author rylinaux 38 | */ 39 | public class PlugManCommandHandler implements CommandExecutor { 40 | 41 | @Override 42 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 43 | 44 | AbstractCommand cmd = new HelpCommand(sender); 45 | 46 | // No args, show help. 47 | if (args.length == 0) { 48 | cmd.execute(sender, command, label, args); 49 | return true; 50 | } 51 | 52 | switch (args[0].toLowerCase()) { 53 | case "help": 54 | cmd = new HelpCommand(sender); 55 | break; 56 | case "list": 57 | cmd = new ListCommand(sender); 58 | break; 59 | case "dump": 60 | cmd = new DumpCommand(sender); 61 | break; 62 | case "info": 63 | cmd = new InfoCommand(sender); 64 | break; 65 | case "lookup": 66 | cmd = new LookupCommand(sender); 67 | break; 68 | case "usage": 69 | cmd = new UsageCommand(sender); 70 | break; 71 | case "enable": 72 | cmd = new EnableCommand(sender); 73 | break; 74 | case "disable": 75 | cmd = new DisableCommand(sender); 76 | break; 77 | case "restart": 78 | cmd = new RestartCommand(sender); 79 | break; 80 | case "load": 81 | cmd = new LoadCommand(sender); 82 | break; 83 | case "download": 84 | cmd = new DownloadCommand(sender); 85 | break; 86 | case "reload": 87 | cmd = new ReloadCommand(sender); 88 | break; 89 | case "unload": 90 | cmd = new UnloadCommand(sender); 91 | break; 92 | case "check": 93 | cmd = new CheckCommand(sender); 94 | break; 95 | } 96 | 97 | cmd.execute(sender, command, label, args); 98 | return true; 99 | 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/main/resources/messages_jp.yml: -------------------------------------------------------------------------------- 1 | ### 2 | # カスタムメッセージファイル 3 | # 4 | # メッセージには、http://minecraft.gamepedia.com/Formatting_codes にある任意の書式設定コードを含めることができ、それらを示すには「&」文字を使用する必要があります。 5 | # カスタム メッセージは必ず一重引用符で囲んでください。 6 | # 新しい更新により、これは変更される可能性があり、以前のバージョンでは情報が正しく表示されない可能性があります。変更は変更ログに記録されます。 7 | ### 8 | 9 | prefix: '&7[&aPlugMan&7] ' 10 | check: 11 | header: '&9プラグインのバージョンを取得しています...' 12 | not-found: '&9プラグインはインストールされていません - 最新バージョンは "{0}" です。' 13 | not-found-spigot: '&cプラグインのデータを取得できませんでした - Spigotリソースとして存在するか確認してください。' 14 | out-of-date: '&c現在のバージョン(&4{0}&c)と最新バージョン(&2{1}&c)が一致しません。' 15 | out-of-date-player: '&c最新版にアップデートしてください(インストール済 -> 最新版): {0}' 16 | up-to-date: '&9プラグインはバージョン "{0}" を使用して最新の状態です。' 17 | up-to-date-player: '&a最新版を使用しています(インストール済): {0}' 18 | file-done: '&9ファイルのダンプが完了しました: {0}' 19 | unknown: '&cバージョン情報が不明です。' 20 | unknown-player: '&c不明(インストール済): {0}' 21 | not-available: '&c{0}のバージョン情報は利用できません。' 22 | disable: 23 | all: '&9すべてのプラグインが無効になりました(PlugManは除く)。' 24 | already-disabled: '&c{0}は既に無効です。' 25 | disabled: '&9{0}が無効になりました。' 26 | dump: 27 | dumped: '&9プラグインが {0} にダンプされました。' 28 | error: '&4ファイルにダンプできませんでした。' 29 | enable: 30 | all: '&9すべてのプラグインが有効になりました。' 31 | already-enabled: '&c{0}は既に有効です。' 32 | enabled: '&9{0}が有効になりました。' 33 | error: 34 | ignored: '&cそのプラグインは無視されています。' 35 | invalid-plugin: '&c有効なプラグインではありません。' 36 | no-permission: '&cこの操作を実行する権限がありません。' 37 | specify-plugin: '&cプラグインを指定する必要があります。' 38 | specify-command: '&cコマンドを指定する必要があります。' 39 | usage: 40 | command: '&7- &9コマンド: &7{0}' 41 | description: '&7- &9説明: &7{0}' 42 | usage: '&7- &9使用方法: &7{0}' 43 | help: 44 | header: '&7--------------------- [&a PlugMan &7] ---------------------' 45 | help: '&7- &a/plugman help &f- &7このメッセージを表示します。' 46 | list: '&7- &a/plugman list [-v] &f- &7すべてのプラグインをリストします(-v オプションを指定すると、バージョンも表示されます)。' 47 | dump: '&7- &a/plugman dump &f- &7プラグイン名とバージョンをファイルにダンプします。' 48 | info: '&7- &a/plugman info <プラグイン名> &f- &7プラグインに関する情報を表示します。' 49 | usage: '&7- &a/plugman usage <プラグイン名> &f- &7プラグインが登録したコマンドを表示します。' 50 | lookup: '&7- &a/plugman lookup <コマンド> &f- &7指定したコマンドを登録したプラグインを探します。' 51 | enable: '&7- &a/plugman enable <プラグイン名|all> &f- &7プラグインを有効化します。' 52 | disable: '&7- &a/plugman disable <プラグイン名|all> &f- &7プラグインを無効化します。' 53 | restart: '&7- &a/plugman restart <プラグイン名|all> &f- &7プラグインを再起動します。' 54 | load: '&7- &a/plugman load <プラグイン名> &f- &7プラグインを読み込みます。' 55 | download: '&7- &a/plugman download &f- &7プラグインをダウンロードしてロードします。' 56 | reload: '&7- &a/plugman reload &f- &7プラグインをリロードします。' 57 | unload: '&7- &a/plugman unload &f- &7プラグインをアンロードします。' 58 | check: '&7- &a/plugman check [-f] &f- &7プラグインが最新かどうかを確認します(-fはすべてのプラグインをファイルにダンプします)。' 59 | info: 60 | header: 'プラグイン情報:{0}' 61 | version: '&7- バージョン:&a{0}' 62 | authors: '&7- 作者:&a{0}' 63 | status: '&7- ステータス:{0}' 64 | depends: '&7- 依存関係:{0}' 65 | softdepends: '&7- ソフト依存関係:&a{0}' 66 | list: 67 | list: '&9プラグイン({0}):{1}' 68 | load: 69 | already-loaded: '&c{0} はすでにロードされています。' 70 | cannot-find: '&cファイルを見つけられず、説明文の検索に失敗しました。' 71 | invalid-description: '&cそのプラグインには無効な説明があります。' 72 | invalid-plugin: '&cそのファイルは有効なプラグインではありません。' 73 | loaded: '&9{0} がロードされ、有効になりました。' 74 | plugin-dir: '&cプラグインディレクトリが見つかりません。' 75 | download: 76 | invalid-id: '&cプラグインIDは数字でなければなりません。' 77 | invalid-type: '&cプラグインタイプは "direct" または "spigot" のいずれかである必要があります。' 78 | invalid-url: '&c有効なURLを指定する必要があります。URLは http:// または https:// で始まります。' 79 | malformed-url: '&c指定したURLが正しくありません。' 80 | download-failed: '&cダウンロードに失敗しました。詳細はコンソールを確認してください。' 81 | lookup: 82 | found: '&9/{0} は {1} に登録されています。' 83 | not-found: '&cコマンド "/{0}" はどの plugin.yml にも登録されていません。' 84 | reload: 85 | all: '&9すべてのプラグインがリロードされました。' 86 | reloaded: '&9{0} がリロードされました。' 87 | restart: 88 | all: '&9すべてのプラグインが再起動されました。' 89 | restarted: '&9{0} が再起動されました。' 90 | unload: 91 | failed: '&c{0}をアンロードできませんでした。' 92 | unloaded: '&9{0}がアンロードされました。' 93 | usage: 94 | usage: '&9コマンド: &7{0}' -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/UsageCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.plugin.Plugin; 33 | 34 | /** 35 | * Command that lists a plugin's commands. 36 | * 37 | * @author rylinaux 38 | */ 39 | public class UsageCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Usage"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "List commands a plugin has registered."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.usage"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman usage "; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {""}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public UsageCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command. 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | if (args.length < 2) { 92 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 93 | sendUsage(); 94 | return; 95 | } 96 | 97 | Plugin target = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 98 | 99 | if (target == null) { 100 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.invalid-plugin")); 101 | sendUsage(); 102 | return; 103 | } 104 | 105 | String usages = PlugMan.getInstance().getPluginUtil().getUsages(target); 106 | 107 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("usage.usage", usages)); 108 | 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/LookupCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.google.common.base.Joiner; 30 | import com.rylinaux.plugman.PlugMan; 31 | import org.bukkit.command.Command; 32 | import org.bukkit.command.CommandSender; 33 | 34 | import java.util.List; 35 | 36 | /** 37 | * Command that finds which plugin a command is registered to. 38 | * 39 | * @author rylinaux 40 | */ 41 | public class LookupCommand extends AbstractCommand { 42 | 43 | /** 44 | * The name of the command. 45 | */ 46 | public static final String NAME = "Lookup"; 47 | 48 | /** 49 | * The description of the command. 50 | */ 51 | public static final String DESCRIPTION = "Find which plugin a command is registered to."; 52 | 53 | /** 54 | * The main permission of the command. 55 | */ 56 | public static final String PERMISSION = "plugman.lookup"; 57 | 58 | /** 59 | * The proper usage of the command. 60 | */ 61 | public static final String USAGE = "/plugman lookup "; 62 | 63 | /** 64 | * The sub permissions of the command. 65 | */ 66 | public static final String[] SUB_PERMISSIONS = {""}; 67 | 68 | /** 69 | * Construct out object. 70 | * 71 | * @param sender the command sender 72 | */ 73 | public LookupCommand(CommandSender sender) { 74 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 75 | } 76 | 77 | /** 78 | * Execute the command. 79 | * 80 | * @param sender the sender of the command 81 | * @param command the command being done 82 | * @param label the name of the command 83 | * @param args the arguments supplied 84 | */ 85 | @Override 86 | public void execute(CommandSender sender, Command command, String label, String[] args) { 87 | 88 | if (!hasPermission()) { 89 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 90 | return; 91 | } 92 | 93 | if (args.length < 2) { 94 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-command")); 95 | sendUsage(); 96 | return; 97 | } 98 | 99 | String commandName = args[1]; 100 | 101 | List plugins = PlugMan.getInstance().getPluginUtil().findByCommand(commandName); 102 | 103 | if (plugins.isEmpty()) { 104 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("lookup.not-found", commandName)); 105 | return; 106 | } 107 | 108 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("lookup.found", commandName, Joiner.on(", ").join(plugins))); 109 | 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/ListCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.google.common.base.Joiner; 30 | import com.google.common.collect.Lists; 31 | import com.rylinaux.plugman.PlugMan; 32 | import com.rylinaux.plugman.util.FlagUtil; 33 | import org.bukkit.Bukkit; 34 | import org.bukkit.command.Command; 35 | import org.bukkit.command.CommandSender; 36 | import org.bukkit.plugin.Plugin; 37 | 38 | import java.util.Collections; 39 | import java.util.List; 40 | 41 | /** 42 | * Command that lists plugins. 43 | * 44 | * @author rylinaux 45 | */ 46 | public class ListCommand extends AbstractCommand { 47 | 48 | /** 49 | * The name of the command. 50 | */ 51 | public static final String NAME = "List"; 52 | 53 | /** 54 | * The description of the command. 55 | */ 56 | public static final String DESCRIPTION = "List all plugins."; 57 | 58 | /** 59 | * The main permission of the command. 60 | */ 61 | public static final String PERMISSION = "plugman.list"; 62 | 63 | /** 64 | * The proper usage of the command. 65 | */ 66 | public static final String USAGE = "/plugman list [-v]"; 67 | 68 | /** 69 | * The sub permissions of the command. 70 | */ 71 | public static final String[] SUB_PERMISSIONS = {""}; 72 | 73 | /** 74 | * Construct out object. 75 | * 76 | * @param sender the command sender 77 | */ 78 | public ListCommand(CommandSender sender) { 79 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 80 | } 81 | 82 | /** 83 | * Execute the command. 84 | * 85 | * @param sender the sender of the command 86 | * @param command the command being done 87 | * @param label the name of the command 88 | * @param args the arguments supplied 89 | */ 90 | @Override 91 | public void execute(CommandSender sender, Command command, String label, String[] args) { 92 | 93 | if (!hasPermission()) { 94 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 95 | return; 96 | } 97 | 98 | boolean includeVersions = FlagUtil.hasFlag(args, 'v'); 99 | 100 | List pluginList = Lists.newArrayList(); 101 | 102 | for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { 103 | pluginList.add(PlugMan.getInstance().getPluginUtil().getFormattedName(plugin, includeVersions)); 104 | } 105 | 106 | Collections.sort(pluginList, String.CASE_INSENSITIVE_ORDER); 107 | 108 | String plugins = Joiner.on(", ").join(pluginList); 109 | 110 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("list.list", pluginList.size(), plugins)); 111 | 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/DumpCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | 30 | import com.rylinaux.plugman.PlugMan; 31 | import org.bukkit.command.Command; 32 | import org.bukkit.command.CommandSender; 33 | 34 | import java.io.File; 35 | import java.io.IOException; 36 | import java.io.PrintWriter; 37 | import java.util.Collections; 38 | import java.util.List; 39 | 40 | /** 41 | * Command that dumps plugin names and versions to file. 42 | * 43 | * @author rylinaux 44 | */ 45 | public class DumpCommand extends AbstractCommand { 46 | 47 | /** 48 | * The name of the command. 49 | */ 50 | public static final String NAME = "Dump"; 51 | 52 | /** 53 | * The description of the command. 54 | */ 55 | public static final String DESCRIPTION = "Dump plugins and versions to file."; 56 | 57 | /** 58 | * The main permission of the command. 59 | */ 60 | public static final String PERMISSION = "plugman.dump"; 61 | 62 | /** 63 | * The proper usage of the command. 64 | */ 65 | public static final String USAGE = "/plugman dump"; 66 | 67 | /** 68 | * The sub permissions of the command. 69 | */ 70 | public static final String[] SUB_PERMISSIONS = {""}; 71 | 72 | /** 73 | * Construct out object. 74 | * 75 | * @param sender the command sender 76 | */ 77 | public DumpCommand(CommandSender sender) { 78 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 79 | } 80 | 81 | /** 82 | * Executes the command. 83 | * 84 | * @param sender the sender of the command 85 | * @param command the command being done 86 | * @param label the name of the command 87 | * @param args the arguments supplied 88 | */ 89 | @Override 90 | public void execute(CommandSender sender, Command command, String label, String[] args) { 91 | 92 | if (!hasPermission()) { 93 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 94 | return; 95 | } 96 | 97 | File dumpFile = new File(PlugMan.getInstance().getDataFolder(), "versions.txt"); 98 | 99 | PrintWriter writer = null; 100 | 101 | List plugins = PlugMan.getInstance().getPluginUtil().getPluginNames(true); 102 | Collections.sort(plugins, String.CASE_INSENSITIVE_ORDER); 103 | 104 | try { 105 | writer = new PrintWriter(dumpFile); 106 | for (String plugin : plugins) 107 | writer.println(plugin); 108 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("dump.dumped", dumpFile.getName())); 109 | } catch (IOException e) { 110 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("dump.error")); 111 | e.printStackTrace(); 112 | } finally { 113 | if (writer != null) 114 | writer.close(); 115 | } 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/UnloadCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.plugin.Plugin; 33 | 34 | /** 35 | * Command that unloads plugin(s). 36 | * 37 | * @author rylinaux 38 | */ 39 | public class UnloadCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Unload"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "Unload a plugin."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.unload"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman unload "; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {""}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public UnloadCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command. 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | if (args.length < 2) { 92 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 93 | sendUsage(); 94 | return; 95 | } 96 | 97 | Plugin target = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 98 | 99 | if (target == null) { 100 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.invalid-plugin")); 101 | sendUsage(); 102 | return; 103 | } 104 | 105 | if (PlugMan.getInstance().getPluginUtil().isIgnored(target)) { 106 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.ignored")); 107 | return; 108 | } 109 | 110 | if (PlugMan.getInstance().getPluginUtil().isPaperPlugin(target)) { 111 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.paper-plugin")); 112 | return; 113 | } 114 | 115 | sender.sendMessage(PlugMan.getInstance().getPluginUtil().unload(target)); 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/LoadCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import com.rylinaux.plugman.util.StringUtil; 31 | import org.bukkit.command.Command; 32 | import org.bukkit.command.CommandSender; 33 | import org.bukkit.plugin.Plugin; 34 | 35 | /** 36 | * Command that loads plugin(s). 37 | * 38 | * @author rylinaux 39 | */ 40 | public class LoadCommand extends AbstractCommand { 41 | 42 | /** 43 | * The name of the command. 44 | */ 45 | public static final String NAME = "Load"; 46 | 47 | /** 48 | * The description of the command. 49 | */ 50 | public static final String DESCRIPTION = "Load a plugin."; 51 | 52 | /** 53 | * The main permission of the command. 54 | */ 55 | public static final String PERMISSION = "plugman.load"; 56 | 57 | /** 58 | * The proper usage of the command. 59 | */ 60 | public static final String USAGE = "/plugman load "; 61 | 62 | /** 63 | * The sub permissions of the command. 64 | */ 65 | public static final String[] SUB_PERMISSIONS = {""}; 66 | 67 | /** 68 | * Construct out object. 69 | * 70 | * @param sender the command sender 71 | */ 72 | public LoadCommand(CommandSender sender) { 73 | super(sender, LoadCommand.NAME, LoadCommand.DESCRIPTION, LoadCommand.PERMISSION, LoadCommand.SUB_PERMISSIONS, LoadCommand.USAGE); 74 | } 75 | 76 | /** 77 | * Execute the command. 78 | * 79 | * @param sender the sender of the command 80 | * @param command the command being done 81 | * @param label the name of the command 82 | * @param args the arguments supplied 83 | */ 84 | @Override 85 | public void execute(CommandSender sender, Command command, String label, String[] args) { 86 | 87 | if (!this.hasPermission()) { 88 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 89 | return; 90 | } 91 | 92 | if (args.length < 2) { 93 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 94 | this.sendUsage(); 95 | return; 96 | } 97 | 98 | for (int i = 1; i < args.length; i++) { 99 | args[i] = args[i].replaceAll("[/\\\\]", ""); 100 | } 101 | 102 | Plugin potential = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 103 | 104 | if (potential != null) { 105 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("load.already-loaded", potential.getName())); 106 | return; 107 | } 108 | 109 | String name = StringUtil.consolidateStrings(args, 1); 110 | 111 | if (PlugMan.getInstance().getPluginUtil().isIgnored(name)) { 112 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.ignored")); 113 | return; 114 | } 115 | 116 | sender.sendMessage(PlugMan.getInstance().getPluginUtil().load(name)); 117 | 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

This is a PlugMan *Fork*

2 |

Original PlugMan: https://github.com/r-clancy/PlugMan

3 | 4 | # PlugMan 5 | 6 | PlugMan is a simple, easy to use plugin that lets server admins manage plugins from either in-game or console without the need to restart the server. 7 | 8 | ## Features 9 | * Enable, disable, restart, load, reload, and unload plugins from in-game or console. 10 | * List plugins alphabetically, with version if specified. 11 | * Get useful information on plugins such as commands, version, author(s), etc. 12 | * Easily manage plugins without having to constantly restart your server. 13 | * List commands a plugin has registered. 14 | * Find the plugin a command is registered to. 15 | * Tab completion for command names and plugin names. 16 | * Dump plugin list with versions to a file. 17 | * Check if a plugin is up-to-date with dev.bukkit.org 18 | * Permissions Support - All commands default to OP. 19 | 20 | ## Commands 21 | | Command | Description | 22 | | --------------- | ---------------- | 23 | | /plugman help | Show help information. | 24 | | /plugman list [-v] | List plugins in alphabetical order. Use "-v" to include versions. | 25 | | /plugman info [plugin] | Displays information about a plugin. | 26 | | /plugman dump | Dump plugin names and version to a file. | 27 | | /plugman usage [plugin] | List commands that a plugin has registered. | 28 | | /plugman lookup [command] | Find the plugin a command is registered to. | 29 | | /plugman enable [plugin|all] | Enable a plugin. | 30 | | /plugman disable [plugin|all] | Disable a plugin. | 31 | | /plugman restart [plugin|all] | Restart (disable/enable) a plugin. | 32 | | /plugman load [plugin] | Load a plugin. | 33 | | /plugman download [direct|spigot] [ID|URL] | Download and load a plugin. | 34 | | /plugman reload [plugin|all] | Reload (unload/load) a plugin. | 35 | | /plugman unload [plugin] | Unload a plugin. | 36 | | /plugman check [plugin|all] [-f] | Check if a plugin is up-to-date. | 37 | 38 | ## Permissions 39 | | Permission Node | Default | Description | 40 | | ------------------------- | ---------- | ---------------- | 41 | | plugman.admin | OP | Allows use of all PlugMan commands. | 42 | | plugman.update | OP | Allows user to see update messages. | 43 | | plugman.help | OP | Allow use of the help command. | 44 | | plugman.list | OP | Allow use of the list command. | 45 | | plugman.info | OP | Allow use of the info command. | 46 | | plugman.dump | OP | Allow use of the dump command. | 47 | | plugman.usage | OP | Allow use of the usage command. | 48 | | plugman.lookup | OP | Allow use of the lookup command. | 49 | | plugman.enable | OP | Allow use of the enable command. | 50 | | plugman.enable.all | OP | Allow use of the enable all command. | 51 | | plugman.disable | OP | Allow use of the disable command. | 52 | | plugman.disable.all | OP | Allow use of the disable all command. | 53 | | plugman.restart | OP | Allow use of the restart command. | 54 | | plugman.restart.all | OP | Allow use of the restart all command. | 55 | | plugman.load | OP | Allow use of the load command. | 56 | | plugman.download | OP | Allow use of the download command. | 57 | | plugman.reload | OP | Allow use of the reload command. | 58 | | plugman.reload.all | OP | Allow use of the reload all command. | 59 | | plugman.unload | OP | Allow use of the unload command. | 60 | | plugman.check | OP | Allow use of the check command. | 61 | | plugman.check.all | OP | Allow use of the check command. | 62 | 63 | ## Configuration 64 | | File | URL | 65 | | ----- | ------- | 66 | | config.yml | https://github.com/TheBlackEntity/PlugMan/blob/master/src/main/resources/config.yml | 67 | 68 | ## Developers 69 | How to include PlugMan with Maven: 70 | ```xml 71 | 72 | 73 | 74 | PlugMan 75 | https://raw.githubusercontent.com/TheBlackEntity/PlugMan/repository/ 76 | 77 | 78 | 79 | 80 | 81 | com.rylinaux 82 | PlugMan 83 | 2.3.3 84 | provided 85 | 86 | 87 | ``` 88 | How to include PlugMan with Gradle: 89 | ```groovy 90 | repositories { 91 | maven { 92 | name = 'PlugMan' 93 | url = 'https://raw.githubusercontent.com/TheBlackEntity/PlugMan/repository/' 94 | } 95 | } 96 | dependencies { 97 | compileOnly 'com.rylinaux:PlugMan:2.3.3' 98 | } 99 | ``` 100 | -------------------------------------------------------------------------------- /src/main/resources/messages.yml: -------------------------------------------------------------------------------- 1 | ### 2 | # Custom Messaging File. 3 | # 4 | # Messaging can include any of the formatting codes found on http://minecraft.gamepedia.com/Formatting_codes and must use the '&' character to denote them. 5 | # Make sure to include the single quotes around the custom messages. 6 | # With new updates, this is subject to change and previous versions might not display information properly. Changes will be noted in the changelog. 7 | ### 8 | 9 | prefix: '&7[&aPlugMan&7] ' 10 | check: 11 | header: '&9Retrieving plugin versions...' 12 | not-found: '&9Plugin not installed - latest available version is "{0}".' 13 | not-found-spigot: '&cCould not fetch plugin data - does the plugin exist as a Spigot Resource?' 14 | out-of-date: '&cCurrent version (&4{0}&c) does not match latest version (&2{1}&c).' 15 | out-of-date-player: '&cMight be Out-of-date (Installed -> Latest): {0}' 16 | up-to-date: '&9Plugin seems to be up-to-date using version "{0}".' 17 | up-to-date-player: '&aSeems to be Up-to-date (Installed): {0}' 18 | file-done: '&9File dump complete: {0}' 19 | unknown: '&cVersion information is unknown.' 20 | unknown-player: '&cUnknown (Installed): {0}' 21 | not-available: '&cVersion information for {0} is unavailable.' 22 | disable: 23 | all: '&9All plugins have been disabled (excluding PlugMan).' 24 | already-disabled: '&c{0} is already disabled.' 25 | disabled: '&9{0} has been disabled.' 26 | dump: 27 | dumped: '&9Plugins dumped to {0}.' 28 | error: '&4Could not dump to file.' 29 | enable: 30 | all: '&9All plugins have been enabled.' 31 | already-enabled: '&c{0} is already enabled.' 32 | enabled: '&9{0} has been enabled.' 33 | error: 34 | ignored: '&cPlugMan is configured to ignore that plugin.' 35 | invalid-plugin: '&cThat is not a valid plugin.' 36 | no-permission: '&cYou do not have permission to do this.' 37 | specify-plugin: '&cYou must specify a plugin.' 38 | specify-command: '&cYou must specify a command.' 39 | paper-plugin: "&cPaper plugins are currently not supported, I'm sorry." 40 | usage: 41 | command: '&7- &9Command: &7{0}' 42 | description: '&7- &9Description: &7{0}' 43 | usage: '&7- &9Usage: &7{0}' 44 | help: 45 | header: '&7--------------------- [&a PlugMan &7] ---------------------' 46 | help: '&7- &a/plugman help &f- &7Displays this.' 47 | list: '&7- &a/plugman list [-v] &f- &7List all plugins (-v shows versions).' 48 | dump: '&7- &a/plugman dump &f- &7Dump plugin names and versions to file.' 49 | info: '&7- &a/plugman info &f- &7Get info on a plugin.' 50 | usage: '&7- &a/plugman usage &f- &7List commands a plugin has registered.' 51 | lookup: '&7- &a/plugman lookup &f- &7Find the plugin a command is registered to.' 52 | enable: '&7- &a/plugman enable &f- &7Enable a plugin.' 53 | disable: '&7- &a/plugman disable &f- &7Disable a plugin.' 54 | restart: '&7- &a/plugman restart &f- &7Restart a plugin.' 55 | load: '&7- &a/plugman load &f- &7Load a plugin.' 56 | download: '&7- &a/plugman download &f- &7Download and load a plugin.' 57 | reload: '&7- &a/plugman reload &f- &7Reload a plugin.' 58 | unload: '&7- &a/plugman unload &f- &7Unload a plugin.' 59 | check: '&7- &a/plugman check [-f] &f- &7Check if a plugin is up-to-date (-f dumps to file for all).' 60 | info: 61 | header: 'Plugin Information: {0}' 62 | version: '&7- Version: &a{0}' 63 | authors: '&7- Author(s): &a{0}' 64 | status: '&7- Status: {0}' 65 | depends: '&7- Depends: {0}' 66 | softdepends: '&7- SoftDepends: &a{0}' 67 | list: 68 | list: '&9Plugins ({0}): {1}' 69 | load: 70 | already-loaded: '&c{0} is already loaded.' 71 | cannot-find: '&cCould not find file and failed to search descriptions.' 72 | invalid-description: '&cThat plugin has an invalid description.' 73 | invalid-plugin: '&cThat file is not a valid plugin.' 74 | loaded: '&9{0} has been loaded and enabled.' 75 | plugin-dir: '&cPlugin directory not found.' 76 | download: 77 | invalid-id: '&cPlugin ID must be a number.' 78 | invalid-type: '&cPlugin type must be either "direct" or "spigot".' 79 | invalid-url: '&cYou must specify a valid URL that starts with http:// or https://.' 80 | malformed-url: '&cSpecified URL is malformed.' 81 | download-failed: '&cDownload failed. Check console for more information' 82 | lookup: 83 | found: '&9/{0} is registered to {1}.' 84 | not-found: '&cCommand "/{0}" not registered in any plugin.yml' 85 | reload: 86 | all: '&9All plugins have been reloaded.' 87 | reloaded: '&9{0} has been reloaded.' 88 | restart: 89 | all: '&9All plugins have been restarted.' 90 | restarted: '&9{0} has been restarted.' 91 | unload: 92 | failed: '&cFailed to unload {0}.' 93 | unloaded: '&9{0} has been unloaded.' 94 | usage: 95 | usage: '&9Commands: &7{0}' 96 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/ReloadCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.plugin.Plugin; 33 | 34 | /** 35 | * Command that reloads plugin(s). 36 | * 37 | * @author rylinaux 38 | */ 39 | public class ReloadCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Reload"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "Reload a plugin."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.reload"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman reload "; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {"all"}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public ReloadCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command. 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | if (args.length < 2) { 92 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 93 | sendUsage(); 94 | return; 95 | } 96 | 97 | if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("*")) { 98 | if (hasPermission("all")) { 99 | PlugMan.getInstance().getPluginUtil().reloadAll(); 100 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("reload.all")); 101 | } else { 102 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 103 | } 104 | return; 105 | } 106 | 107 | Plugin target = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 108 | 109 | if (target == null) { 110 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.invalid-plugin")); 111 | sendUsage(); 112 | return; 113 | } 114 | 115 | if (PlugMan.getInstance().getPluginUtil().isIgnored(target)) { 116 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.ignored")); 117 | return; 118 | } 119 | 120 | if (PlugMan.getInstance().getPluginUtil().isPaperPlugin(target)) { 121 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.paper-plugin")); 122 | return; 123 | } 124 | 125 | PlugMan.getInstance().getPluginUtil().reload(target); 126 | 127 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("reload.reloaded", target.getName())); 128 | 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/PluginUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | import org.bukkit.command.Command; 4 | import org.bukkit.plugin.Plugin; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.net.URL; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | public interface PluginUtil { 13 | 14 | /** 15 | * Download a plugin from a URL. 16 | * 17 | * @param url the URL to download from 18 | * @return downloaded plugin 19 | * @throws IOException if an error occurs 20 | */ 21 | public File download(URL url) throws IOException; 22 | 23 | /** 24 | * Enable a plugin. 25 | * 26 | * @param plugin the plugin to enable 27 | */ 28 | public void enable(Plugin plugin); 29 | 30 | /** 31 | * Enable all plugins. 32 | */ 33 | public void enableAll(); 34 | 35 | /** 36 | * Disable a plugin. 37 | * 38 | * @param plugin the plugin to disable 39 | */ 40 | public void disable(Plugin plugin); 41 | 42 | /** 43 | * Disable all plugins. 44 | */ 45 | public void disableAll(); 46 | 47 | /** 48 | * Returns the formatted name of the plugin. 49 | * 50 | * @param plugin the plugin to format 51 | * @return the formatted name 52 | */ 53 | public String getFormattedName(Plugin plugin); 54 | 55 | /** 56 | * Returns the formatted name of the plugin. 57 | * 58 | * @param plugin the plugin to format 59 | * @param includeVersions whether to include the version 60 | * @return the formatted name 61 | */ 62 | public String getFormattedName(Plugin plugin, boolean includeVersions); 63 | 64 | /** 65 | * Returns a plugin from an array of Strings. 66 | * 67 | * @param args the array 68 | * @param start the index to start at 69 | * @return the plugin 70 | */ 71 | public Plugin getPluginByName(String[] args, int start); 72 | 73 | /** 74 | * Returns a plugin from a String. 75 | * 76 | * @param name the name of the plugin 77 | * @return the plugin 78 | */ 79 | public Plugin getPluginByName(String name); 80 | 81 | /** 82 | * Returns a List of plugin names. 83 | * 84 | * @return list of plugin names 85 | */ 86 | public List getPluginNames(boolean fullName); 87 | 88 | /** 89 | * Returns a List of disabled plugin names. 90 | * 91 | * @return list of disabled plugin names 92 | */ 93 | public List getDisabledPluginNames(boolean fullName); 94 | 95 | /** 96 | * Returns a List of enabled plugin names. 97 | * 98 | * @return list of enabled plugin names 99 | */ 100 | public List getEnabledPluginNames(boolean fullName); 101 | 102 | /** 103 | * Get the version of another plugin. 104 | * 105 | * @param name the name of the other plugin. 106 | * @return the version. 107 | */ 108 | public String getPluginVersion(String name); 109 | 110 | /** 111 | * Returns the commands a plugin has registered. 112 | * 113 | * @param plugin the plugin to deal with 114 | * @return the commands registered 115 | */ 116 | public String getUsages(Plugin plugin); 117 | 118 | /** 119 | * Find which plugin has a given command registered. 120 | * 121 | * @param command the command. 122 | * @return the plugin. 123 | */ 124 | public List findByCommand(String command); 125 | 126 | /** 127 | * Checks whether the plugin is ignored. 128 | * 129 | * @param plugin the plugin to check 130 | * @return whether the plugin is ignored 131 | */ 132 | public boolean isIgnored(Plugin plugin); 133 | 134 | /** 135 | * Checks whether the plugin is ignored. 136 | * 137 | * @param plugin the plugin to check 138 | * @return whether the plugin is ignored 139 | */ 140 | public boolean isIgnored(String plugin); 141 | 142 | /** 143 | * Loads and enables a plugin. 144 | * 145 | * @param name plugin's name 146 | * @return status message 147 | */ 148 | public String load(String name); 149 | 150 | public Map getKnownCommands(); 151 | 152 | 153 | /** 154 | * Reload a plugin. 155 | * 156 | * @param plugin the plugin to reload 157 | */ 158 | public void reload(Plugin plugin); 159 | 160 | /** 161 | * Reload all plugins. 162 | */ 163 | public void reloadAll(); 164 | 165 | /** 166 | * Unload a plugin. 167 | * 168 | * @param plugin the plugin to unload 169 | * @return the message to send to the user. 170 | */ 171 | public String unload(Plugin plugin); 172 | 173 | /** 174 | * Returns if the plugin is a Paper plugin. 175 | * @param plugin the plugin to check 176 | * @return if the plugin is a Paper plugin 177 | */ 178 | public boolean isPaperPlugin(Plugin plugin); 179 | } 180 | -------------------------------------------------------------------------------- /src/main/resources/messages_es.yml: -------------------------------------------------------------------------------- 1 | ### 2 | # Archivo de Mensajes Personalizado. 3 | # 4 | # Los mensajes pueden incluir cualquier código de formato encontrado en http://minecraft.gamepedia.com/Formatting_codes y deben usar el carácter '&' para denotarlos. 5 | # Asegúrate de incluir las comillas simples alrededor de los mensajes personalizados. 6 | # Con nuevas actualizaciones, esto está sujeto a cambios y las versiones anteriores podrían no mostrar la información correctamente. Los cambios se anotarán en el registro de cambios. 7 | ### 8 | 9 | prefix: '&7[&aPlugMan&7] ' 10 | check: 11 | header: '&9Recuperando versiones de plugin...' 12 | not-found: '&9Plugin no instalado - la versión más reciente es "{0}".' 13 | not-found-spigot: '&cNo se ha podido recuperar datos del plugin - existe como recurso de Spigot?' 14 | out-of-date: '&cVersión Actual (&4{0}&c) no coincide con la más reciente (&2{1}&c).' 15 | out-of-date-player: '&cPodría estar Desactualizado (Installed -> Latest): {0}' 16 | up-to-date: '&9El plugin parece estar Actualizado en la versión "{0}".' 17 | up-to-date-player: '&aParece estar Actualizado (Installed): {0}' 18 | file-done: '&9Volcado de archivo completo: {0}' 19 | unknown: '&cInformación de la versión desconocida.' 20 | unknown-player: '&cDesconocido (Installed): {0}' 21 | not-available: '&cInformación de la versión {0} no está disponible.' 22 | disable: 23 | all: '&9Todos los plugins han sido deshabilitados (excluyendo PlugMan).' 24 | already-disabled: '&c{0} ya está desactivado.' 25 | disabled: '&9{0} ha sido desactivado.' 26 | dump: 27 | dumped: '&9Plugins volcados a {0}.' 28 | error: '&4No se ha podido volcar a archivo.' 29 | enable: 30 | all: '&9Todos los plugins han sido habilitados.' 31 | already-enabled: '&c{0} ya está habilitado.' 32 | enabled: '&9{0} ha sido habilitado.' 33 | error: 34 | ignored: '&cPlugMan está configurado para ignorar ese plugin.' 35 | invalid-plugin: '&cEse no es un plugin válido.' 36 | no-permission: '&cNo tienes permitido hacer eso.' 37 | specify-plugin: '&cDebes especificar un plugin.' 38 | specify-command: '&cDebes especificar un comando.' 39 | paper-plugin: "&cActualmente, no se soportan plugins de Paper, Lo siento." 40 | usage: 41 | command: '&7- &9Comando: &7{0}' 42 | description: '&7- &9Descripción: &7{0}' 43 | usage: '&7- &9Uso: &7{0}' 44 | help: 45 | header: '&7--------------------- [&a PlugMan &7] ---------------------' 46 | help: '&7- &a/plugman help &f- &7Muestra esto.' 47 | list: '&7- &a/plugman list [-v] &f- &7Lista todo plugin (-v muestra versiones).' 48 | dump: '&7- &a/plugman dump &f- &7Volca los nombres y versiones de plugins a un archivo.' 49 | info: '&7- &a/plugman info &f- &7Muestra información de un plugin.' 50 | usage: '&7- &a/plugman usage &f- &7Lista los comandos registrados de un plugin.' 51 | lookup: '&7- &a/plugman lookup &f- &7Encuentra que plugin ha registrado un comando.' 52 | enable: '&7- &a/plugman enable &f- &7Habilita un plugin.' 53 | disable: '&7- &a/plugman disable &f- &7Deshabilita un plugin.' 54 | restart: '&7- &a/plugman restart &f- &7Reinicia un plugin.' 55 | load: '&7- &a/plugman load &f- &7Carga un plugin.' 56 | download: '&7- &a/plugman download &f- &7Descarga y carga un plugin.' 57 | reload: '&7- &a/plugman reload &f- &7Recarga un plugin.' 58 | unload: '&7- &a/plugman unload &f- &7Des-carga un plugin.' 59 | check: '&7- &a/plugman check [-f] &f- &7Revisa si un plugin está actualizado (-f volca un archivo para todos).' 60 | info: 61 | header: 'Información del plugin: {0}' 62 | version: '&7- Versión: &a{0}' 63 | authors: '&7- Autor(es): &a{0}' 64 | status: '&7- Status: {0}' 65 | depends: '&7- Dependencias: {0}' 66 | softdepends: '&7- SoftDepends: &a{0}' 67 | list: 68 | list: '&9Plugins ({0}): {1}' 69 | load: 70 | already-loaded: '&c{0} ya ha sido cargado.' 71 | cannot-find: '&cNo se ha encontrado el archivo y fallo al buscar descripciones.' 72 | invalid-description: '&cTal plugin tiene una descripción invalida.' 73 | invalid-plugin: '&cEse archivo no es un plugin válido.' 74 | loaded: '&9{0} ha sido cargado y activado.' 75 | plugin-dir: '&cCarpeta de plugins no encontrada.' 76 | download: 77 | invalid-id: '&cEl ID de plugin debe ser un número.' 78 | invalid-type: '&cEl tipo de plugin debe ser "direct" o "spigot".' 79 | invalid-url: '&cDebes especificar un URL válido que inicie con http:// o https://.' 80 | malformed-url: '&cLa URL especificada está malformada.' 81 | download-failed: '&cDescarga fallida. Revisa la consola para más información.' 82 | lookup: 83 | found: '&9/{0} está registrado a {1}.' 84 | not-found: '&cComando "/{0}" no está registrado en ningún plugin.yml' 85 | reload: 86 | all: '&9Todos los plugins han sido recargados.' 87 | reloaded: '&9{0} ha sido recargados.' 88 | restart: 89 | all: '&9Todos los plugins han sido reiniciados.' 90 | restarted: '&9{0} ha sido reiniciado.' 91 | unload: 92 | failed: '&cError al des-cargar {0}.' 93 | unloaded: '&9{0} ha sido des-cargado.' 94 | usage: 95 | usage: '&9Comandos: &7{0}' 96 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/RestartCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.plugin.Plugin; 33 | 34 | /** 35 | * Command that restarts plugin(s). 36 | * 37 | * @author rylinaux 38 | */ 39 | public class RestartCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Restart"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "Restart a plugin."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.restart"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman restart "; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {"all"}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public RestartCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command. 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | if (args.length < 2) { 92 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 93 | sendUsage(); 94 | return; 95 | } 96 | 97 | if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("*")) { 98 | if (hasPermission("all")) { 99 | PlugMan.getInstance().getPluginUtil().disableAll(); 100 | PlugMan.getInstance().getPluginUtil().enableAll(); 101 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("restart.all")); 102 | } else { 103 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 104 | } 105 | return; 106 | } 107 | 108 | Plugin target = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 109 | 110 | if (target == null) { 111 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.invalid-plugin")); 112 | sendUsage(); 113 | return; 114 | } 115 | 116 | if (PlugMan.getInstance().getPluginUtil().isIgnored(target)) { 117 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.ignored")); 118 | return; 119 | } 120 | 121 | if (PlugMan.getInstance().getPluginUtil().isPaperPlugin(target)) { 122 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.paper-plugin")); 123 | return; 124 | } 125 | 126 | PlugMan.getInstance().getPluginUtil().disable(target); 127 | PlugMan.getInstance().getPluginUtil().enable(target); 128 | 129 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("restart.restarted", target.getName())); 130 | 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/DisableCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.plugin.Plugin; 33 | 34 | /** 35 | * Command that disables plugin(s). 36 | * 37 | * @author rylinaux 38 | */ 39 | public class DisableCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Disable"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "Disable a plugin."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.disable"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman disable "; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {"all"}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public DisableCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!this.hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | if (args.length < 2) { 92 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 93 | this.sendUsage(); 94 | return; 95 | } 96 | 97 | if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("*")) { 98 | if (this.hasPermission("all")) { 99 | PlugMan.getInstance().getPluginUtil().disableAll(); 100 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("disable.all")); 101 | } else sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 102 | return; 103 | } 104 | 105 | Plugin target = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 106 | 107 | if (target == null) { 108 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.invalid-plugin")); 109 | this.sendUsage(); 110 | return; 111 | } 112 | 113 | if (PlugMan.getInstance().getPluginUtil().isIgnored(target)) { 114 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.ignored")); 115 | return; 116 | } 117 | 118 | if (PlugMan.getInstance().getPluginUtil().isPaperPlugin(target)) { 119 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.paper-plugin")); 120 | return; 121 | } 122 | 123 | if (!target.isEnabled()) { 124 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("disable.already-disabled", target.getName())); 125 | return; 126 | } 127 | 128 | PlugMan.getInstance().getPluginUtil().disable(target); 129 | 130 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("disable.disabled", target.getName())); 131 | 132 | } 133 | 134 | } -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/EnableCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.plugin.Plugin; 33 | 34 | /** 35 | * Command that enables plugin(s). 36 | * 37 | * @author rylinaux 38 | */ 39 | public class EnableCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Enable"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "Enable a plugin."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.enable"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman enable "; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {"all"}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public EnableCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | if (args.length < 2) { 92 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 93 | sendUsage(); 94 | return; 95 | } 96 | 97 | if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("*")) { 98 | if (hasPermission("all")) { 99 | PlugMan.getInstance().getPluginUtil().enableAll(); 100 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("enable.all")); 101 | } else { 102 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 103 | } 104 | return; 105 | } 106 | 107 | Plugin target = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 108 | 109 | if (target == null) { 110 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.invalid-plugin")); 111 | sendUsage(); 112 | return; 113 | } 114 | 115 | if (PlugMan.getInstance().getPluginUtil().isIgnored(target)) { 116 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.ignored")); 117 | return; 118 | } 119 | 120 | if (PlugMan.getInstance().getPluginUtil().isPaperPlugin(target)) { 121 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.paper-plugin")); 122 | return; 123 | } 124 | 125 | if (target.isEnabled()) { 126 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("enable.already-enabled", target.getName())); 127 | return; 128 | } 129 | 130 | PlugMan.getInstance().getPluginUtil().enable(target); 131 | 132 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("enable.enabled", target.getName())); 133 | 134 | } 135 | 136 | } -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/InfoCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.google.common.base.Joiner; 30 | import com.rylinaux.plugman.PlugMan; 31 | import org.bukkit.ChatColor; 32 | import org.bukkit.command.Command; 33 | import org.bukkit.command.CommandSender; 34 | import org.bukkit.plugin.Plugin; 35 | 36 | import java.util.List; 37 | 38 | /** 39 | * Command that displays information on a plugin. 40 | * 41 | * @author rylinaux 42 | */ 43 | public class InfoCommand extends AbstractCommand { 44 | 45 | /** 46 | * The name of the command. 47 | */ 48 | public static final String NAME = "Info"; 49 | 50 | /** 51 | * The description of the command. 52 | */ 53 | public static final String DESCRIPTION = "View information on a plugin."; 54 | 55 | /** 56 | * The main permission of the command. 57 | */ 58 | public static final String PERMISSION = "plugman.info"; 59 | 60 | /** 61 | * The proper usage of the command. 62 | */ 63 | public static final String USAGE = "/plugman info "; 64 | 65 | /** 66 | * The sub permissions of the command. 67 | */ 68 | public static final String[] SUB_PERMISSIONS = {""}; 69 | 70 | /** 71 | * Construct out object. 72 | * 73 | * @param sender the command sender 74 | */ 75 | public InfoCommand(CommandSender sender) { 76 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 77 | } 78 | 79 | /** 80 | * Execute the command. 81 | * 82 | * @param sender the sender of the command 83 | * @param command the command being done 84 | * @param label the name of the command 85 | * @param args the arguments supplied 86 | */ 87 | @Override 88 | public void execute(CommandSender sender, Command command, String label, String[] args) { 89 | 90 | if (!hasPermission()) { 91 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 92 | return; 93 | } 94 | 95 | if (args.length < 2) { 96 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 97 | sendUsage(); 98 | return; 99 | } 100 | 101 | Plugin target = PlugMan.getInstance().getPluginUtil().getPluginByName(args, 1); 102 | 103 | if (target == null) { 104 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.invalid-plugin")); 105 | sendUsage(); 106 | return; 107 | } 108 | 109 | String name = target.getName(); 110 | String version = target.getDescription().getVersion(); 111 | String authors = Joiner.on(", ").join(target.getDescription().getAuthors()); 112 | String status = target.isEnabled() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled"; 113 | List dependList = target.getDescription().getDepend(); 114 | List softdependList = target.getDescription().getSoftDepend(); 115 | 116 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("info.header", name)); 117 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "info.version", version)); 118 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "info.authors", authors)); 119 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "info.status", status)); 120 | if (!dependList.isEmpty()) sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "info.depends", Joiner.on(", ").join(dependList))); 121 | if (!softdependList.isEmpty()) sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "info.softdepends", Joiner.on(", ").join(softdependList))); 122 | 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/resources/messages_de.yml: -------------------------------------------------------------------------------- 1 | ### 2 | # Eigene Nachrichten-Datei. 3 | # 4 | # Nachrichten können Formatierungscodes enthalten, die auf http://minecraft.gamepedia.com/Formatting_codes gefunden werden können, und müssen das '&' Zeichen verwenden, um sie zu kennzeichnen. 5 | # Stelle sicher, dass du die einfachen Anführungszeichen um die Nachrichten setzt. 6 | # Bei neuen Updates kann sich dies ändern, und frühere Versionen zeigen die Informationen möglicherweise nicht richtig an. Änderungen werden im Changelog vermerkt. 7 | ### 8 | 9 | prefix: '&7[&aPlugMan&7] ' 10 | check: 11 | header: '&9Rufe Plugin-Versionen ab...' 12 | not-found: '&9Plugin nicht installiert - neueste verfügbare Version ist "{0}".' 13 | not-found-spigot: '&cKonnte Plugin-Daten nicht abrufen - existiert das Plugin als Spigot-Ressource?' 14 | out-of-date: '&cAktuelle Version (&4{0}&c) stimmt nicht mit neuester Version (&2{1}&c) überein.' 15 | out-of-date-player: '&cKönnte veraltet sein (Installiert -> Neueste): {0}' 16 | up-to-date: '&9Plugin scheint auf dem neuesten Stand zu sein mit Version "{0}".' 17 | up-to-date-player: '&aScheint auf dem neuesten Stand zu sein (Installiert): {0}' 18 | file-done: '&9Datei dump abgeschlossen: {0}' 19 | unknown: '&cVersionsinformationen sind unbekannt.' 20 | unknown-player: '&cUnbekannt (Installiert): {0}' 21 | not-available: '&cVersionsinformationen für {0} sind nicht verfügbar.' 22 | disable: 23 | all: '&9Alle Plugins wurden deaktiviert (außer PlugMan).' 24 | already-disabled: '&c{0} ist bereits deaktiviert.' 25 | disabled: '&9{0} wurde deaktiviert.' 26 | dump: 27 | dumped: '&9Plugins wurden in {0} abgelegt.' 28 | error: '&4Konnte nicht in Datei ablegen.' 29 | enable: 30 | all: '&9Alle Plugins wurden aktiviert.' 31 | already-enabled: '&c{0} ist bereits aktiviert.' 32 | enabled: '&9{0} wurde aktiviert.' 33 | error: 34 | ignored: '&cPlugMan ist darauf konfiguriert, dieses Plugin zu ignorieren.' 35 | invalid-plugin: '&cDies ist kein gültiges Plugin.' 36 | no-permission: '&cDu hast hierzu keine Berechtigung.' 37 | specify-plugin: '&cBitte gib ein Plugin an.' 38 | specify-command: '&cBitte gib einen Befehl an.' 39 | paper-plugin: '&cPaper-Plugins werden derzeit leider nicht unterstützt.' 40 | usage: 41 | command: '&7- &9Befehl: &7{0}' 42 | description: '&7- &9Beschreibung: &7{0}' 43 | usage: '&7- &9Verwendung: &7{0}' 44 | help: 45 | header: '&7--------------------- [&a PlugMan &7] ---------------------' 46 | help: '&7- &a/plugman help &f- &7Zeigt dies an.' 47 | list: '&7- &a/plugman list [-v] &f- &7Listet alle Plugins auf (-v zeigt Versionen).' 48 | dump: '&7- &a/plugman dump &f- &7Listet Plugin-Namen und Versionen in Datei auf.' 49 | info: '&7- &a/plugman info &f- &7Informationen zu einem Plugin abrufen.' 50 | usage: '&7- &a/plugman usage &f- &7Listet die von einem Plugin registrierten Befehle auf.' 51 | lookup: '&7- &a/plugman lookup &f- &7Ermittelt, zu welchem Plugin ein Befehl registriert ist.' 52 | enable: '&7- &a/plugman enable &f- &7Aktiviert ein Plugin.' 53 | disable: '&7- &a/plugman disable &f- &7Deaktiviert ein Plugin.' 54 | restart: '&7- &a/plugman restart &f- &7Startet ein Plugin neu.' 55 | load: '&7- &a/plugman load &f- &7Lädt ein Plugin.' 56 | download: '&7- &a/plugman download &f- &7Lädt ein Plugin herunter und lädt es.' 57 | reload: '&7- &a/plugman reload &f- &7Lädt ein Plugin neu.' 58 | unload: '&7- &a/plugman unload &f- &7Entlädt ein Plugin.' 59 | check: '&7- &a/plugman check [-f] &f- &7Überprüft, ob ein Plugin aktuell ist (-f legt alle in Datei ab).' 60 | info: 61 | header: 'Plugin-Informationen: {0}' 62 | version: '&7- Version: &a{0}' 63 | authors: '&7- Autor(en): &a{0}' 64 | status: '&7- Status: {0}' 65 | depends: '&7- Abhängigkeiten: {0}' 66 | softdepends: '&7- Soft-Abhängigkeiten: &a{0}' 67 | list: 68 | list: '&9Plugins ({0}): {1}' 69 | load: 70 | already-loaded: '&c{0} ist bereits geladen.' 71 | cannot-find: '&cKonnte Datei nicht finden und konnte Beschreibungen nicht durchsuchen.' 72 | invalid-description: '&cDas Plugin hat eine ungültige Beschreibung.' 73 | invalid-plugin: '&cDiese Datei ist kein gültiges Plugin.' 74 | loaded: '&9{0} wurde geladen und aktiviert.' 75 | plugin-dir: '&cPlugin-Verzeichnis nicht gefunden.' 76 | download: 77 | invalid-id: '&cPlugin-ID muss eine Nummer sein.' 78 | invalid-type: '&cPlugin-Typ muss entweder "direct" oder "spigot" sein.' 79 | invalid-url: '&cBitte gib eine gültige URL an, die mit http:// oder https:// beginnt.' 80 | malformed-url: '&cAngegebene URL ist fehlerhaft.' 81 | download-failed: '&cDownload fehlgeschlagen. Überprüfe die Konsole für weitere Informationen.' 82 | lookup: 83 | found: '&9/{0} ist bei {1} registriert.' 84 | not-found: '&cDer Befehl "/{0}" ist in keiner plugin.yml registriert.' 85 | reload: 86 | all: '&9Alle Plugins wurden neu geladen.' 87 | reloaded: '&9{0} wurde neu geladen.' 88 | restart: 89 | all: '&9Alle Plugins wurden neu gestartet.' 90 | restarted: '&9{0} wurde neu gestartet.' 91 | unload: 92 | failed: '&cKonnte {0} nicht entladen.' 93 | unloaded: '&9{0} wurde entladen.' 94 | usage: 95 | usage: '&9Befehle: &7{0}' 96 | -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/commands/PlugManBungeeCommand.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.commands; 2 | 3 | import me.entity303.plugmanbungee.commands.cmd.LoadCommand; 4 | import me.entity303.plugmanbungee.commands.cmd.ReloadCommand; 5 | import me.entity303.plugmanbungee.commands.cmd.UnloadCommand; 6 | import net.md_5.bungee.api.CommandSender; 7 | import net.md_5.bungee.api.chat.TextComponent; 8 | import net.md_5.bungee.api.plugin.Command; 9 | import net.md_5.bungee.api.plugin.TabExecutor; 10 | 11 | import java.util.*; 12 | 13 | public class PlugManBungeeCommand extends Command implements TabExecutor { 14 | private LoadCommand loadCommand; 15 | private UnloadCommand unloadCommand; 16 | private ReloadCommand reloadCommand; 17 | 18 | public PlugManBungeeCommand() { 19 | super("plugmanbungee", "plugman.use"); 20 | loadCommand = new LoadCommand(); 21 | unloadCommand = new UnloadCommand(); 22 | reloadCommand = new ReloadCommand(); 23 | } 24 | 25 | @Override 26 | public void execute(CommandSender sender, String[] args) { 27 | if (args.length <= 0) { 28 | sendMessage(sender, "Syntax: §2/plugman "); 29 | return; 30 | } 31 | 32 | if (args[0].equalsIgnoreCase("load")) { 33 | if (!sender.hasPermission("plugman.load")) { 34 | sendMessage(sender, "§cYou do not have enough permissions to execute this command!!"); 35 | return; 36 | } 37 | String[] newArgs = new String[args.length - 1]; 38 | for (int i = 0, i1 = 1; i1 < args.length; i1++) { 39 | newArgs[i] = args[i1]; 40 | } 41 | loadCommand.execute(sender, newArgs); 42 | return; 43 | } 44 | 45 | if (args[0].equalsIgnoreCase("unload")) { 46 | if (!sender.hasPermission("plugman.unload")) { 47 | sendMessage(sender, "§cYou do not have enough permissions to execute this command!!"); 48 | return; 49 | } 50 | String[] newArgs = new String[args.length - 1]; 51 | for (int i = 0, i1 = 1; i1 < args.length; i1++) { 52 | newArgs[i] = args[i1]; 53 | } 54 | unloadCommand.execute(sender, newArgs); 55 | return; 56 | } 57 | 58 | if (args[0].equalsIgnoreCase("reload")) { 59 | if (!sender.hasPermission("plugman.reload")) { 60 | sendMessage(sender, "§cYou do not have enough permissions to execute this command!!"); 61 | return; 62 | } 63 | String[] newArgs = new String[args.length - 1]; 64 | for (int i = 0, i1 = 1; i1 < args.length; i1++) { 65 | newArgs[i] = args[i1]; 66 | } 67 | reloadCommand.execute(sender, newArgs); 68 | return; 69 | } 70 | 71 | sendMessage(sender, "Syntax: §2/plugman "); 72 | } 73 | 74 | private void sendMessage(CommandSender sender, String message) { 75 | sender.sendMessage(new TextComponent("§8[§2PlugManBungee§8] §7" + message)); 76 | } 77 | 78 | @Override 79 | public Iterable onTabComplete(CommandSender sender, String[] args) { 80 | if (args.length == 1) { 81 | List completion = new ArrayList<>(Arrays.asList("load", "unload", "reload")); 82 | for (String com : completion) { 83 | if (com.startsWith(args[0].toLowerCase(Locale.ROOT))) { 84 | return Collections.singletonList(com); 85 | } 86 | } 87 | return completion; 88 | } 89 | 90 | if (args.length == 2) { 91 | if (args[0].equalsIgnoreCase("unload")) { 92 | if (!sender.hasPermission("plugman.unload")) { 93 | return new ArrayList<>(); 94 | } 95 | 96 | String[] newArgs = new String[args.length - 1]; 97 | for (int i = 0, i1 = 1; i1 < args.length; i1++) { 98 | newArgs[i] = args[i1]; 99 | } 100 | return unloadCommand.onTabComplete(sender, newArgs); 101 | } 102 | 103 | if (args[0].equalsIgnoreCase("load")) { 104 | if (!sender.hasPermission("plugman.load")) { 105 | return new ArrayList<>(); 106 | } 107 | 108 | String[] newArgs = new String[args.length - 1]; 109 | for (int i = 0, i1 = 1; i1 < args.length; i1++) { 110 | newArgs[i] = args[i1]; 111 | } 112 | return loadCommand.onTabComplete(sender, newArgs); 113 | } 114 | 115 | if (args[0].equalsIgnoreCase("reload")) { 116 | if (!sender.hasPermission("plugman.reload")) { 117 | return new ArrayList<>(); 118 | } 119 | 120 | String[] newArgs = new String[args.length - 1]; 121 | for (int i = 0, i1 = 1; i1 < args.length; i1++) { 122 | newArgs[i] = args[i1]; 123 | } 124 | return loadCommand.onTabComplete(sender, newArgs); 125 | } 126 | } 127 | 128 | return new ArrayList<>(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/DownloadCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | import com.rylinaux.plugman.PlugMan; 4 | import org.apache.commons.lang.math.NumberUtils; 5 | import org.bukkit.command.Command; 6 | import org.bukkit.command.CommandSender; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.net.MalformedURLException; 11 | import java.net.URL; 12 | 13 | /* 14 | * #%L 15 | * PlugMan 16 | * %% 17 | * Copyright (C) 2010 - 2014 PlugMan 18 | * %% 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy 20 | * of this software and associated documentation files (the "Software"), to deal 21 | * in the Software without restriction, including without limitation the rights 22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | * copies of the Software, and to permit persons to whom the Software is 24 | * furnished to do so, subject to the following conditions: 25 | * 26 | * The above copyright notice and this permission notice shall be included in 27 | * all copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | * THE SOFTWARE. 36 | * #L% 37 | */ 38 | 39 | public class DownloadCommand extends AbstractCommand { 40 | 41 | /** 42 | * The name of the command. 43 | */ 44 | public static final String NAME = "Download"; 45 | 46 | /** 47 | * The description of the command. 48 | */ 49 | public static final String DESCRIPTION = "Download a plugin."; 50 | 51 | /** 52 | * The main permission of the command. 53 | */ 54 | public static final String PERMISSION = "plugman.download"; 55 | 56 | /** 57 | * The proper usage of the command. 58 | */ 59 | public static final String USAGE = "/plugman download "; 60 | 61 | /** 62 | * The sub permissions of the command. 63 | */ 64 | public static final String[] SUB_PERMISSIONS = {}; 65 | 66 | /** 67 | * Construct out object. 68 | * 69 | * @param sender the command sender 70 | */ 71 | public DownloadCommand(CommandSender sender) { 72 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 73 | } 74 | 75 | /** 76 | * Execute the command 77 | * 78 | * @param sender the sender of the command 79 | * @param command the command being done 80 | * @param label the name of the command 81 | * @param args the arguments supplied 82 | */ 83 | @Override 84 | public void execute(CommandSender sender, Command command, String label, String[] args) { 85 | 86 | if (!hasPermission()) { 87 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 88 | return; 89 | } 90 | 91 | if (PlugMan.getInstance().isDisableDownloadCommand()) 92 | return; 93 | 94 | URL url; 95 | switch (args.length < 2 ? "" : args[1]) { 96 | case "spigot": 97 | if (args.length < 3 || !NumberUtils.isNumber(args[2])) { 98 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("download.invalid-id")); 99 | sendUsage(); 100 | return; 101 | } 102 | 103 | try { 104 | url = new URL("https://api.spiget.org/v2/resources/" + args[2] + "/download"); 105 | } catch (MalformedURLException e) { 106 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("download.invalid-id")); 107 | sendUsage(); 108 | return; 109 | } 110 | 111 | break; 112 | case "direct": 113 | if (args.length < 3 || !args[2].startsWith("http://") && !args[2].startsWith("https://")) { 114 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("download.invalid-url")); 115 | sendUsage(); 116 | return; 117 | } 118 | 119 | try { 120 | url = new URL(args[2]); 121 | } catch (MalformedURLException e) { 122 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("download.malformed-url")); 123 | sendUsage(); 124 | return; 125 | } 126 | 127 | break; 128 | default: 129 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("download.invalid-type")); 130 | sendUsage(); 131 | return; 132 | } 133 | 134 | File file; 135 | try { 136 | file = PlugMan.getInstance().getPluginUtil().download(url); 137 | } catch (IOException e) { 138 | e.printStackTrace(); 139 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("download.download-failed")); 140 | return; 141 | } 142 | 143 | String name = file.getName(); 144 | name = name.substring(0, name.length() - 4); 145 | sender.sendMessage(PlugMan.getInstance().getPluginUtil().load(name)); 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/UpdateUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | import com.rylinaux.plugman.PlugMan; 4 | import com.rylinaux.plugman.pojo.UpdateResult; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.plugin.Plugin; 7 | import org.json.simple.JSONArray; 8 | 9 | import java.util.*; 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | public class UpdateUtil { 14 | /** 15 | * Check which plugins are up-to-date or not. 16 | * 17 | * @return a map of the plugins and the results. 18 | */ 19 | public static Map checkUpToDate() { 20 | Map results = new TreeMap<>(); 21 | for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { 22 | results.put(plugin.getName(), checkUpToDate(plugin.getName())); 23 | } 24 | return results; 25 | } 26 | 27 | /** 28 | * Check if the installed plugin version is up-to-date with the Spigot version. 29 | * 30 | * @param pluginName the plugin name. 31 | * @return the reflective UpdateResult. 32 | */ 33 | public static UpdateResult checkUpToDate(String pluginName) { 34 | if (PlugMan.getInstance().getResourceMap().containsKey(pluginName.toLowerCase(Locale.ROOT))) { 35 | Map.Entry entry = PlugMan.getInstance().getResourceMap().get(pluginName.toLowerCase(Locale.ROOT)); 36 | 37 | if (entry.getValue()) { 38 | return SpiGetUtil.checkUpToDate(pluginName, entry.getKey()); 39 | } else { 40 | return CurseForgeUtil.checkUpToDate(pluginName, entry.getKey()); 41 | } 42 | } 43 | 44 | long id = SpiGetUtil.getPluginId(pluginName); 45 | if (id < 0) { 46 | id = CurseForgeUtil.getPluginId(pluginName); 47 | if (id < 0) { 48 | Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); 49 | if (plugin == null) { 50 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, pluginName); 51 | } 52 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, plugin.getDescription().getVersion()); 53 | } 54 | return CurseForgeUtil.checkUpToDate(pluginName); 55 | } 56 | return SpiGetUtil.checkUpToDate(pluginName); 57 | } 58 | 59 | /** 60 | * Get the id of the plugin. 61 | * 62 | * @param name the name of the plugin. 63 | * @return the id of the plugin. 64 | */ 65 | public static long getPluginId(String name) { 66 | if (PlugMan.getInstance().getResourceMap().containsKey(name.toLowerCase(Locale.ROOT))) { 67 | Map.Entry entry = PlugMan.getInstance().getResourceMap().get(name.toLowerCase(Locale.ROOT)); 68 | 69 | if (entry.getValue()) { 70 | return SpiGetUtil.getPluginId(name); 71 | } else { 72 | return CurseForgeUtil.getPluginId(name); 73 | } 74 | } 75 | 76 | long id = SpiGetUtil.getPluginId(name); 77 | if (id < 0) { 78 | id = CurseForgeUtil.getPluginId(name); 79 | } 80 | return id; 81 | 82 | } 83 | 84 | /** 85 | * Get the versions for a given plugin. 86 | * 87 | * @param id the plugin id. 88 | * @return the JSON encoded data. 89 | */ 90 | public static JSONArray getPluginVersions(long id) { 91 | for (Map.Entry entry : PlugMan.getInstance().getResourceMap().values()) { 92 | if (entry.getKey() == id) { 93 | if (entry.getValue()) { 94 | return SpiGetUtil.getPluginVersions(id); 95 | } else { 96 | return CurseForgeUtil.getPluginVersions(id); 97 | } 98 | } 99 | } 100 | 101 | JSONArray jsonArray = SpiGetUtil.getPluginVersions(id); 102 | if (jsonArray == null || jsonArray.size() <= 0) { 103 | return CurseForgeUtil.getPluginVersions(id); 104 | } 105 | return jsonArray; 106 | } 107 | 108 | private static final Pattern VERSION_FAMILY_NUMBERS_PATTERN = Pattern.compile("\\d+(\\.\\d+)*"); 109 | 110 | protected static Boolean isActualVersion(String current, String latest) { 111 | if (current.equalsIgnoreCase(latest)) return true; // Strings are fully equals 112 | 113 | List> currentNumbers; 114 | List> latestNumbers; 115 | 116 | try { 117 | currentNumbers = parseNumbers(VERSION_FAMILY_NUMBERS_PATTERN.matcher(current)); 118 | latestNumbers = parseNumbers(VERSION_FAMILY_NUMBERS_PATTERN.matcher(latest)); 119 | } catch (NumberFormatException ex) { 120 | return null; // Unable to parse numbers to int 121 | } 122 | 123 | for (int familyIndex = 0; familyIndex < CollectionUtil.maxCollectionsSize(currentNumbers, latestNumbers); familyIndex++) { 124 | List currentFamily = CollectionUtil.getElementOrDefault(currentNumbers, familyIndex, ArrayList::new); 125 | List latestFamily = CollectionUtil.getElementOrDefault(latestNumbers, familyIndex, ArrayList::new); 126 | 127 | for (int numberIndex = 0; numberIndex < CollectionUtil.maxCollectionsSize(currentFamily, latestFamily); numberIndex++) { 128 | int currentValue = CollectionUtil.getElementOrDefault(currentFamily, numberIndex, () -> 0); 129 | int latestValue = CollectionUtil.getElementOrDefault(latestFamily, numberIndex, () -> 0); 130 | 131 | if (latestValue > currentValue) { 132 | return false; 133 | } else if (latestValue < currentValue) { 134 | return true; 135 | } 136 | } 137 | } 138 | return true; // Numbers amount equals, numbers values too 139 | } 140 | 141 | private static List> parseNumbers(Matcher matcher) { 142 | List> result = new ArrayList<>(); 143 | while (matcher.find()) { 144 | String familyString = matcher.group(); 145 | List family = new ArrayList<>(); 146 | for (String number : familyString.split("\\.")) { 147 | family.add(Integer.parseInt(number)); 148 | } 149 | result.add(family); 150 | } 151 | return result; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/AbstractCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | 30 | import com.rylinaux.plugman.PlugMan; 31 | import org.bukkit.command.Command; 32 | import org.bukkit.command.CommandSender; 33 | import org.bukkit.command.ConsoleCommandSender; 34 | import org.bukkit.command.RemoteConsoleCommandSender; 35 | import org.bukkit.entity.Player; 36 | 37 | /** 38 | * Abstract command class that our commands extend. 39 | * 40 | * @author rylinaux 41 | */ 42 | public abstract class AbstractCommand { 43 | 44 | /** 45 | * The command's sender. 46 | */ 47 | private final CommandSender sender; 48 | 49 | /** 50 | * The command's name. 51 | */ 52 | private final String name; 53 | 54 | /** 55 | * The command's description. 56 | */ 57 | private final String description; 58 | 59 | /** 60 | * The command's description. 61 | */ 62 | private final String permission; 63 | 64 | /** 65 | * The command's usage. 66 | */ 67 | private final String usage; 68 | 69 | /** 70 | * The sub permissions. 71 | */ 72 | private final String[] subPermissions; 73 | 74 | /** 75 | * Construct the object. 76 | * 77 | * @param sender the sender of the command 78 | * @param description the description of the command 79 | * @param permission the permission to use the command 80 | * @param usage the proper usage of the command 81 | */ 82 | public AbstractCommand(CommandSender sender, String name, String description, String permission, String[] subPermissions, String usage) { 83 | this.sender = sender; 84 | this.name = name; 85 | this.description = description; 86 | this.permission = permission; 87 | this.subPermissions = subPermissions; 88 | this.usage = usage; 89 | } 90 | 91 | /** 92 | * Gets the sender of the command. 93 | * 94 | * @return the command's sender 95 | */ 96 | public CommandSender getSender() { 97 | return sender; 98 | } 99 | 100 | /** 101 | * Gets the name of the command. 102 | * 103 | * @return the command's name 104 | */ 105 | public String getName() { 106 | return name; 107 | } 108 | 109 | /** 110 | * Gets the description of the command. 111 | * 112 | * @return the command's description 113 | */ 114 | public String getDescription() { 115 | return description; 116 | } 117 | 118 | /** 119 | * Gets the permission associated with the command. 120 | * 121 | * @return the command's permission 122 | */ 123 | public String getPermission() { 124 | return permission; 125 | } 126 | 127 | /** 128 | * Gets the sub permissions associated with the command. 129 | * 130 | * @return the command's sub permissions 131 | */ 132 | public String[] getSubPermissions() { 133 | return subPermissions; 134 | } 135 | 136 | /** 137 | * Gets the proper usage for the command. 138 | * 139 | * @return the command's usage 140 | */ 141 | public String getUsage() { 142 | return usage; 143 | } 144 | 145 | /** 146 | * Checks whether the sender has permission to do the command. 147 | * 148 | * @return does the sender have permission 149 | */ 150 | public boolean hasPermission() { 151 | return sender.hasPermission(permission) || isSenderConsole() || isSenderRemoteConsole(); 152 | } 153 | 154 | /** 155 | * Checks whether the sender has permission to do the command. 156 | * 157 | * @param sub the sub permission to check 158 | * @return does the sender have permission 159 | */ 160 | public boolean hasPermission(String sub) { 161 | String permission = this.permission + "." + sub; 162 | return sender.hasPermission(permission) || isSenderConsole() || isSenderRemoteConsole(); 163 | } 164 | 165 | /** 166 | * Sends the usage message to the sender. 167 | */ 168 | public void sendUsage() { 169 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "error.usage.command", name)); 170 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "error.usage.description", description)); 171 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format(false, "error.usage.usage", usage)); 172 | } 173 | 174 | /** 175 | * Checks whether the sender is a . 176 | * 177 | * @return is the sender a player 178 | */ 179 | public boolean isSenderPlayer() { 180 | return (sender instanceof Player); 181 | } 182 | 183 | /** 184 | * Checks whether the sender is the console. 185 | * 186 | * @return is the sender console 187 | */ 188 | public boolean isSenderConsole() { 189 | return (sender instanceof ConsoleCommandSender); 190 | } 191 | 192 | /** 193 | * Checks whether the sender is rcon. 194 | * 195 | * @return is the sender rcon 196 | */ 197 | public boolean isSenderRemoteConsole() { 198 | return (sender instanceof RemoteConsoleCommandSender); 199 | } 200 | 201 | /** 202 | * Executes the command. 203 | * 204 | * @param sender the sender of the command 205 | * @param command the command being done 206 | * @param label the name of the command 207 | * @param args the arguments supplied 208 | */ 209 | public abstract void execute(CommandSender sender, Command command, String label, String[] args); 210 | 211 | } 212 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/PlugManTabCompleter.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2014 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import org.bukkit.Bukkit; 30 | import org.bukkit.command.Command; 31 | import org.bukkit.command.CommandSender; 32 | import org.bukkit.command.TabCompleter; 33 | import org.bukkit.plugin.InvalidDescriptionException; 34 | import org.bukkit.plugin.Plugin; 35 | import org.bukkit.plugin.PluginDescriptionFile; 36 | import org.bukkit.util.StringUtil; 37 | 38 | import java.io.File; 39 | import java.io.IOException; 40 | import java.io.InputStream; 41 | import java.util.ArrayList; 42 | import java.util.Arrays; 43 | import java.util.Collections; 44 | import java.util.List; 45 | import java.util.jar.JarFile; 46 | import java.util.stream.Collectors; 47 | 48 | /** 49 | * Completes partial matches in command and plugin names. 50 | * 51 | * @author rylinaux 52 | */ 53 | public class PlugManTabCompleter implements TabCompleter { 54 | 55 | /** 56 | * Valid command names. 57 | */ 58 | private static final String[] COMMANDS = {"check", "disable", "dump", "enable", "help", "info", "list", "load", "lookup", "reload", "restart", "unload", "usage"}; 59 | 60 | @Override 61 | public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { 62 | 63 | if (sender.isOp() || sender.hasPermission("plugman.admin") || sender.hasPermission("plugman." + args[0])) { 64 | 65 | List completions = new ArrayList<>(); 66 | 67 | if (args.length == 1) { 68 | String partialCommand = args[0]; 69 | List commands = new ArrayList<>(Arrays.asList(COMMANDS)); 70 | StringUtil.copyPartialMatches(partialCommand, commands, completions); 71 | } 72 | 73 | if (args.length == 2) if (args[0].equalsIgnoreCase("load")) { 74 | List files = new ArrayList<>(); 75 | String partialPlugin = args[1]; 76 | 77 | for (File pluginFile : new File("plugins").listFiles()) { 78 | try { 79 | if (pluginFile.isDirectory()) continue; 80 | 81 | if (!pluginFile.getName().toLowerCase().endsWith(".jar")) 82 | if (!new File("plugins", pluginFile.getName() + ".jar").exists()) continue; 83 | 84 | JarFile jarFile = null; 85 | try { 86 | jarFile = new JarFile(pluginFile); 87 | } catch (IOException e) { 88 | e.printStackTrace(); 89 | continue; 90 | } 91 | 92 | if (jarFile.getEntry("plugin.yml") == null) continue; 93 | 94 | InputStream stream; 95 | try { 96 | stream = jarFile.getInputStream(jarFile.getEntry("plugin.yml")); 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | continue; 100 | } 101 | 102 | if (stream == null) continue; 103 | 104 | PluginDescriptionFile descriptionFile = null; 105 | try { 106 | descriptionFile = new PluginDescriptionFile(stream); 107 | } catch (InvalidDescriptionException e) { 108 | e.printStackTrace(); 109 | continue; 110 | } 111 | 112 | files.add(pluginFile.getName().substring(0, pluginFile.getName().length() - ".jar".length())); 113 | 114 | for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) 115 | if (plugin.getName().equalsIgnoreCase(descriptionFile.getName())) 116 | files.remove(pluginFile.getName().substring(0, pluginFile.getName().length() - ".jar".length())); 117 | } catch (Exception ignored) { 118 | } 119 | } 120 | 121 | StringUtil.copyPartialMatches(partialPlugin, files, completions); 122 | } else if (args[0].equalsIgnoreCase("lookup")) { 123 | String partialCommand = args[1]; 124 | List commands = PlugMan.getInstance().getPluginUtil().getKnownCommands().keySet().stream().filter(s -> !s.toLowerCase().contains(":")).collect(Collectors.toList()); 125 | commands.remove("/"); 126 | StringUtil.copyPartialMatches(partialCommand, commands, completions); 127 | } else if (args[0].equalsIgnoreCase("enable")) { 128 | String partialPlugin = args[1]; 129 | List plugins = PlugMan.getInstance().getPluginUtil().getDisabledPluginNames(false); 130 | StringUtil.copyPartialMatches(partialPlugin, plugins, completions); 131 | } else if (args[0].equalsIgnoreCase("disable")) { 132 | String partialPlugin = args[1]; 133 | List plugins = PlugMan.getInstance().getPluginUtil().getEnabledPluginNames(false); 134 | StringUtil.copyPartialMatches(partialPlugin, plugins, completions); 135 | } else { 136 | String partialPlugin = args[1]; 137 | List plugins = PlugMan.getInstance().getPluginUtil().getPluginNames(false); 138 | StringUtil.copyPartialMatches(partialPlugin, plugins, completions); 139 | } 140 | 141 | Collections.sort(completions); 142 | 143 | return completions; 144 | 145 | } 146 | 147 | return null; 148 | 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/SpiGetUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2015 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import com.rylinaux.plugman.pojo.UpdateResult; 31 | import org.apache.commons.io.IOUtils; 32 | import org.apache.http.HttpResponse; 33 | import org.apache.http.client.HttpClient; 34 | import org.apache.http.client.methods.HttpGet; 35 | import org.apache.http.impl.client.HttpClients; 36 | import org.bukkit.Bukkit; 37 | import org.bukkit.plugin.Plugin; 38 | import org.json.simple.JSONArray; 39 | import org.json.simple.JSONObject; 40 | import org.json.simple.JSONValue; 41 | 42 | import java.io.IOException; 43 | import java.util.Map; 44 | import java.util.TreeMap; 45 | 46 | /** 47 | * Utilities for dealing with the SpiGet API. 48 | * 49 | * @author rylinaux 50 | */ 51 | public class SpiGetUtil { 52 | 53 | /** 54 | * The base URL for the SpiGet API. 55 | */ 56 | public static final String API_BASE_URL = "https://api.spiget.org/v2/"; 57 | 58 | /** 59 | * Check which plugins are up-to-date or not. 60 | * 61 | * @return a map of the plugins and the results. 62 | */ 63 | public static Map checkUpToDate() { 64 | Map results = new TreeMap<>(); 65 | for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { 66 | results.put(plugin.getName(), checkUpToDate(plugin.getName())); 67 | } 68 | return results; 69 | } 70 | 71 | /** 72 | * Check if the installed plugin version is up-to-date with the Spigot version. 73 | * 74 | * @param pluginName the plugin name. 75 | * @return the reflective UpdateResult. 76 | */ 77 | public static UpdateResult checkUpToDate(String pluginName) { 78 | return checkUpToDate(pluginName, null); 79 | } 80 | 81 | /** 82 | * Check if the installed plugin version is up-to-date with the Spigot version. 83 | * 84 | * @param pluginName the plugin name. 85 | * @return the reflective UpdateResult. 86 | */ 87 | public static UpdateResult checkUpToDate(String pluginName, Long pluginId) { 88 | boolean idSpecified = pluginId != null; 89 | 90 | if (!idSpecified) { 91 | pluginId = SpiGetUtil.getPluginId(pluginName); 92 | } 93 | 94 | if (pluginId < 0) { 95 | Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); 96 | if (plugin == null) { 97 | if (idSpecified) { 98 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, pluginName); 99 | } else { 100 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED); 101 | } 102 | } 103 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, plugin.getDescription().getVersion()); 104 | } 105 | 106 | JSONArray versions = SpiGetUtil.getPluginVersions(pluginId); 107 | 108 | if (versions == null || versions.size() == 0) { 109 | Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); 110 | if (plugin == null) { 111 | if (idSpecified) { 112 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, pluginName); 113 | } else { 114 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED); 115 | } 116 | } 117 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, plugin.getDescription().getVersion()); 118 | } 119 | 120 | JSONObject latest = (JSONObject) versions.get(0); 121 | 122 | String currentVersion = PlugMan.getInstance().getPluginUtil().getPluginVersion(pluginName); 123 | String latestVersion = (String) latest.get("name"); 124 | 125 | if (currentVersion == null) { 126 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED, currentVersion, latestVersion); 127 | } else if (latestVersion == null) { 128 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, currentVersion, latestVersion); 129 | } 130 | 131 | Boolean isActual = UpdateUtil.isActualVersion(currentVersion, latestVersion); 132 | if (isActual != null && isActual) { 133 | return new UpdateResult(UpdateResult.ResultType.UP_TO_DATE, currentVersion, latestVersion); 134 | } else { 135 | return new UpdateResult(UpdateResult.ResultType.OUT_OF_DATE, currentVersion, latestVersion); 136 | } 137 | 138 | } 139 | 140 | /** 141 | * Get the id of the plugin. 142 | * 143 | * @param name the name of the plugin. 144 | * @return the id of the plugin. 145 | */ 146 | public static long getPluginId(String name) { 147 | 148 | HttpClient client = HttpClients.createMinimal(); 149 | 150 | HttpGet get = new HttpGet(API_BASE_URL + "search/resources/" + name + "?field=name&fields=id%2Cname"); 151 | get.setHeader("User-Agent", "PlugMan"); 152 | 153 | try { 154 | 155 | HttpResponse response = client.execute(get); 156 | String body = IOUtils.toString(response.getEntity().getContent()); 157 | 158 | Object object = JSONValue.parse(body); 159 | 160 | if (object instanceof JSONArray) { 161 | 162 | JSONArray array = (JSONArray) JSONValue.parse(body); 163 | 164 | for (int i = 0; i < array.size(); i++) { 165 | JSONObject json = (JSONObject) array.get(i); 166 | String pluginName = (String) json.get("name"); 167 | if (name.equalsIgnoreCase(pluginName)) { 168 | return (long) json.get("id"); 169 | } 170 | } 171 | 172 | } 173 | 174 | } catch (IOException e) { 175 | e.printStackTrace(); 176 | } 177 | 178 | return -1; 179 | 180 | } 181 | 182 | /** 183 | * Get the versions for a given plugin. 184 | * 185 | * @param id the plugin id. 186 | * @return the JSON encoded data. 187 | */ 188 | public static JSONArray getPluginVersions(long id) { 189 | 190 | HttpClient client = HttpClients.createMinimal(); 191 | 192 | HttpGet get = new HttpGet(API_BASE_URL + "/resources/" + id + "/versions?sort=-releaseDate"); 193 | get.setHeader("User-Agent", "PlugMan"); 194 | 195 | try { 196 | 197 | HttpResponse response = client.execute(get); 198 | String body = IOUtils.toString(response.getEntity().getContent()); 199 | 200 | return (JSONArray) JSONValue.parse(body); 201 | 202 | } catch (IOException e) { 203 | e.printStackTrace(); 204 | } 205 | 206 | return null; 207 | 208 | } 209 | 210 | } 211 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 4.0.0 6 | 7 | com.rylinaux 8 | PlugMan 9 | 2.3.3 10 | jar 11 | 12 | PlugMan 13 | Plugin manager for Bukkit servers. 14 | http://dev.bukkit.org/bukkit-plugins/plugman/ 15 | 16 | 2010 17 | 18 | 19 | 20 | Ryan Clancy 21 | rylinaux@gmail.com 22 | rylinaux 23 | 24 | Lead Developer 25 | 26 | 27 | 28 | 29 | 30 | 31 | MIT 32 | http://opensource.org/licenses/MIT 33 | 34 | 35 | 36 | 37 | GitHub 38 | https://github.com/rylinaux/PlugMan/issues 39 | 40 | 41 | 42 | UTF-8 43 | 44 | 45 | 46 | 47 | spigot-repo 48 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 49 | 50 | 51 | papermc 52 | https://repo.papermc.io/repository/maven-public/ 53 | 54 | 55 | devmart-other 56 | https://nexuslite.gcnt.net/repos/other/ 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.spigotmc 64 | spigot-api 65 | 1.17-R0.1-SNAPSHOT 66 | provided 67 | 68 | 69 | 70 | io.papermc.paper 71 | paper-api 72 | 1.19.4-R0.1-SNAPSHOT 73 | provided 74 | 75 | 76 | 77 | com.tcoded 78 | FoliaLib 79 | 0.2.0 80 | compile 81 | 82 | 83 | 84 | org.bukkit 85 | bukkit 86 | 1.15.2-R0.1-SNAPSHOT 87 | provided 88 | 89 | 90 | 91 | 92 | com.googlecode.json-simple 93 | json-simple 94 | 1.1.1 95 | compile 96 | 97 | 98 | 99 | 100 | 101 | 102 | net.md-5 103 | bungeecord-api 104 | 1.16-R0.4 105 | provided 106 | 107 | 108 | 109 | commons-io 110 | commons-io 111 | 2.6 112 | 113 | 114 | commons-logging 115 | commons-logging 116 | 1.2 117 | 118 | 119 | org.apache.httpcomponents 120 | httpclient 121 | 4.5.13 122 | 123 | 124 | 125 | 126 | ${project.artifactId} 127 | 128 | 129 | org.codehaus.mojo 130 | license-maven-plugin 131 | 1.8 132 | 133 | mit 134 | ${project.baseUri}/license 135 | ${project.artifactId} 136 | 137 | 138 | 139 | first 140 | 141 | update-file-header 142 | 143 | process-sources 144 | 145 | 146 | src/main/java/com/rylinaux/* 147 | 148 | 149 | 150 | 151 | 152 | 153 | org.apache.maven.plugins 154 | maven-compiler-plugin 155 | 3.3 156 | 157 | 8 158 | 8 159 | 160 | 161 | 162 | org.apache.maven.plugins 163 | maven-shade-plugin 164 | 3.4.1 165 | 166 | 167 | package 168 | 169 | shade 170 | 171 | 172 | 173 | 174 | commons-io 175 | commons-logging 176 | org.apache.httpcomponents 177 | com.tcoded:FoliaLib 178 | 179 | 180 | 181 | 182 | com.tcoded 183 | com.rylinaux.lib 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | org.apache.maven.plugins 192 | maven-javadoc-plugin 193 | 3.4.1 194 | 195 | 196 | attach-javadocs 197 | 198 | jar 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/CurseForgeUtil.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | import com.google.common.hash.HashCode; 4 | import com.google.common.hash.Hashing; 5 | import com.google.common.io.Files; 6 | import com.rylinaux.plugman.PlugMan; 7 | import com.rylinaux.plugman.pojo.UpdateResult; 8 | import org.apache.commons.io.IOUtils; 9 | import org.apache.http.HttpResponse; 10 | import org.apache.http.client.HttpClient; 11 | import org.apache.http.client.methods.HttpGet; 12 | import org.apache.http.impl.client.HttpClients; 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.plugin.Plugin; 15 | import org.bukkit.plugin.java.JavaPlugin; 16 | import org.json.simple.JSONArray; 17 | import org.json.simple.JSONObject; 18 | import org.json.simple.JSONValue; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.lang.reflect.InvocationTargetException; 23 | import java.lang.reflect.Method; 24 | import java.util.Map; 25 | import java.util.TreeMap; 26 | 27 | public class CurseForgeUtil { 28 | /** 29 | * The base URL for the CurseForge API. 30 | */ 31 | public static final String API_BASE_URL = "https://servermods.forgesvc.net/servermods/"; 32 | 33 | /** 34 | * Check which plugins are up-to-date or not. 35 | * 36 | * @return a map of the plugins and the results. 37 | */ 38 | public static Map checkUpToDate() { 39 | Map results = new TreeMap<>(); 40 | for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { 41 | results.put(plugin.getName(), checkUpToDate(plugin.getName())); 42 | } 43 | return results; 44 | } 45 | 46 | /** 47 | * Check if the installed plugin version is up-to-date with the Spigot version. 48 | * 49 | * @param pluginName the plugin name. 50 | * @return the reflective UpdateResult. 51 | */ 52 | public static UpdateResult checkUpToDate(String pluginName) { 53 | return checkUpToDate(pluginName, null); 54 | } 55 | 56 | /** 57 | * Check if the installed plugin version is up-to-date with the Spigot version. 58 | * 59 | * @param pluginName the plugin name. 60 | * @return the reflective UpdateResult. 61 | */ 62 | public static UpdateResult checkUpToDate(String pluginName, Long pluginId) { 63 | boolean idSpecified = pluginId != null; 64 | 65 | if (!idSpecified) { 66 | pluginId = CurseForgeUtil.getPluginId(pluginName); 67 | } 68 | 69 | if (pluginId < 0) { 70 | Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); 71 | if (plugin == null) { 72 | if (idSpecified) { 73 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, pluginName); 74 | } else { 75 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED); 76 | } 77 | } 78 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, plugin.getDescription().getVersion()); 79 | } 80 | 81 | JSONArray versions = CurseForgeUtil.getPluginVersions(pluginId); 82 | 83 | if (versions == null || versions.size() == 0) { 84 | Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); 85 | if (plugin == null) { 86 | if (idSpecified) { 87 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, pluginName); 88 | } else { 89 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED); 90 | } 91 | } 92 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, plugin.getDescription().getVersion()); 93 | } 94 | 95 | JSONObject latest = (JSONObject) versions.get(versions.size() - 1); 96 | 97 | String currentVersion = PlugMan.getInstance().getPluginUtil().getPluginVersion(pluginName); 98 | if (!(Bukkit.getPluginManager().getPlugin(pluginName) instanceof JavaPlugin)) { 99 | if (idSpecified) { 100 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, currentVersion); 101 | } else { 102 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, currentVersion, "null"); 103 | } 104 | } 105 | JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(pluginName); 106 | if (plugin == null) { 107 | if (idSpecified) { 108 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED, currentVersion); 109 | } else { 110 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED, currentVersion, "null"); 111 | } 112 | } 113 | String latestVersion = (String) latest.get("md5"); 114 | HashCode currentPluginHashCode; 115 | 116 | try { 117 | Method getFileMethod = JavaPlugin.class.getDeclaredMethod("getFile"); 118 | getFileMethod.setAccessible(true); 119 | File file = (File) getFileMethod.invoke(plugin); 120 | currentPluginHashCode = Files.asByteSource(file).hash(Hashing.md5()); 121 | currentPluginHashCode.toString(); 122 | } catch (IOException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) { 123 | e.printStackTrace(); 124 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, currentVersion, latestVersion); 125 | } 126 | 127 | if (latestVersion == null) { 128 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, currentVersion, latestVersion); 129 | } 130 | 131 | latestVersion = (String) latest.get("name"); 132 | 133 | if (currentVersion == null) { 134 | return new UpdateResult(UpdateResult.ResultType.NOT_INSTALLED, currentVersion, latestVersion); 135 | } else if (latestVersion == null) { 136 | return new UpdateResult(UpdateResult.ResultType.INVALID_PLUGIN, currentVersion, latestVersion); 137 | } 138 | 139 | Boolean isActual = UpdateUtil.isActualVersion(currentVersion, latestVersion); 140 | if (isActual != null && isActual) { 141 | return new UpdateResult(UpdateResult.ResultType.UP_TO_DATE, currentVersion, latestVersion); 142 | } else { 143 | return new UpdateResult(UpdateResult.ResultType.OUT_OF_DATE, currentVersion, latestVersion); 144 | } 145 | 146 | } 147 | 148 | /** 149 | * Get the id of the plugin. 150 | * 151 | * @param name the name of the plugin. 152 | * @return the id of the plugin. 153 | */ 154 | public static long getPluginId(String name) { 155 | 156 | HttpClient client = HttpClients.createMinimal(); 157 | 158 | HttpGet get = new HttpGet(API_BASE_URL + "projects?search=" + name.toLowerCase()); 159 | get.setHeader("User-Agent", "PlugMan"); 160 | 161 | try { 162 | 163 | HttpResponse response = client.execute(get); 164 | String body = IOUtils.toString(response.getEntity().getContent()); 165 | 166 | Object object = JSONValue.parse(body); 167 | 168 | if (object instanceof JSONArray) { 169 | 170 | JSONArray array = (JSONArray) JSONValue.parse(body); 171 | 172 | for (int i = 0; i < array.size(); i++) { 173 | JSONObject json = (JSONObject) array.get(i); 174 | String pluginName = (String) json.get("slug"); 175 | if (name.equalsIgnoreCase(pluginName)) { 176 | return (long) json.get("id"); 177 | } 178 | } 179 | 180 | } 181 | 182 | } catch (IOException e) { 183 | e.printStackTrace(); 184 | } 185 | 186 | return -1; 187 | 188 | } 189 | 190 | /** 191 | * Get the versions for a given plugin. 192 | * 193 | * @param id the plugin id. 194 | * @return the JSON encoded data. 195 | */ 196 | public static JSONArray getPluginVersions(long id) { 197 | 198 | HttpClient client = HttpClients.createMinimal(); 199 | 200 | HttpGet get = new HttpGet(API_BASE_URL + "files?projectIds=" + id); 201 | get.setHeader("User-Agent", "PlugMan"); 202 | 203 | try { 204 | 205 | HttpResponse response = client.execute(get); 206 | String body = IOUtils.toString(response.getEntity().getContent()); 207 | 208 | return (JSONArray) JSONValue.parse(body); 209 | 210 | } catch (IOException e) { 211 | e.printStackTrace(); 212 | } 213 | 214 | return null; 215 | 216 | } 217 | 218 | } 219 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/command/CheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.command; 2 | 3 | /* 4 | * #%L 5 | * PlugMan 6 | * %% 7 | * Copyright (C) 2010 - 2015 PlugMan 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.rylinaux.plugman.PlugMan; 30 | import com.rylinaux.plugman.pojo.UpdateResult; 31 | import com.rylinaux.plugman.util.FlagUtil; 32 | import com.rylinaux.plugman.util.StringUtil; 33 | import com.rylinaux.plugman.util.ThreadUtil; 34 | import com.rylinaux.plugman.util.UpdateUtil; 35 | import org.bukkit.Bukkit; 36 | import org.bukkit.command.Command; 37 | import org.bukkit.command.CommandSender; 38 | 39 | import java.io.File; 40 | import java.io.IOException; 41 | import java.io.PrintWriter; 42 | import java.util.Map; 43 | 44 | /** 45 | * Command that checks if a plugin is up-to-date. 46 | * 47 | * @author rylinaux 48 | */ 49 | public class CheckCommand extends AbstractCommand { 50 | 51 | /** 52 | * The name of the command. 53 | */ 54 | public static final String NAME = "Check"; 55 | 56 | /** 57 | * The description of the command. 58 | */ 59 | public static final String DESCRIPTION = "Check if a plugin is up-to-date."; 60 | 61 | /** 62 | * The main permission of the command. 63 | */ 64 | public static final String PERMISSION = "plugman.check"; 65 | 66 | /** 67 | * The proper usage of the command. 68 | */ 69 | public static final String USAGE = "/plugman check "; 70 | 71 | /** 72 | * The sub permissions of the command. 73 | */ 74 | public static final String[] SUB_PERMISSIONS = {"all"}; 75 | 76 | /** 77 | * Construct out object. 78 | * 79 | * @param sender the command sender 80 | */ 81 | public CheckCommand(CommandSender sender) { 82 | super(sender, NAME, DESCRIPTION, PERMISSION, SUB_PERMISSIONS, USAGE); 83 | } 84 | 85 | /** 86 | * Execute the command 87 | * 88 | * @param sender the sender of the command 89 | * @param command the command being done 90 | * @param label the name of the command 91 | * @param args the arguments supplied 92 | */ 93 | @Override 94 | public void execute(final CommandSender sender, final Command command, final String label, final String[] args) { 95 | if (!hasPermission()) { 96 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 97 | return; 98 | } 99 | 100 | if (args.length < 2) { 101 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 102 | sendUsage(); 103 | return; 104 | } 105 | 106 | final boolean toFile = FlagUtil.hasFlag(args, 'f'); 107 | 108 | if (args[1] == null) { 109 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.specify-plugin")); 110 | sendUsage(); 111 | return; 112 | } 113 | 114 | if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("*")) { 115 | 116 | if (hasPermission("all")) { 117 | 118 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.header")); 119 | 120 | ThreadUtil.async(new Runnable() { 121 | 122 | @Override 123 | public void run() { 124 | 125 | Map results = UpdateUtil.checkUpToDate(); 126 | 127 | final StringBuilder upToDate = new StringBuilder(), outOfDate = new StringBuilder(), unknown = new StringBuilder(); 128 | 129 | for (Map.Entry entry : results.entrySet()) { 130 | 131 | UpdateResult.ResultType result = entry.getValue().getType(); 132 | 133 | String currentVersion = Bukkit.getPluginManager().getPlugin(entry.getKey()).getDescription().getVersion(); 134 | 135 | if (result == UpdateResult.ResultType.UP_TO_DATE) { 136 | upToDate.append(entry.getKey()).append("(").append(currentVersion).append(") "); 137 | } else if (result == UpdateResult.ResultType.INVALID_PLUGIN || result == UpdateResult.ResultType.NOT_INSTALLED) { 138 | unknown.append(entry.getKey()).append("(").append(currentVersion).append(") "); 139 | } else { 140 | outOfDate.append(entry.getKey()).append("(").append(currentVersion).append(" -> ").append(entry.getValue().getLatestVersion()).append(") "); 141 | } 142 | 143 | } 144 | 145 | if (toFile) { 146 | 147 | File outFile = new File(PlugMan.getInstance().getDataFolder(), "updates.txt"); 148 | 149 | PrintWriter writer = null; 150 | 151 | try { 152 | 153 | writer = new PrintWriter(outFile); 154 | 155 | writer.println("Up-to-date (Installed):"); 156 | writer.println(upToDate); 157 | 158 | writer.println("Out-of-date (Installed -> Latest):"); 159 | writer.println(outOfDate); 160 | 161 | writer.println("Unknown (Installed):"); 162 | writer.println(unknown); 163 | 164 | } catch (IOException ignored) { 165 | 166 | } finally { 167 | if (writer != null) { 168 | writer.close(); 169 | } 170 | } 171 | 172 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.file-done", outFile.getPath())); 173 | 174 | } else { 175 | 176 | ThreadUtil.sync(new Runnable() { 177 | @Override 178 | public void run() { 179 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.up-to-date-player", upToDate.toString())); 180 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.out-of-date-player", outOfDate.toString())); 181 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.unknown-player", unknown.toString())); 182 | } 183 | }); 184 | 185 | } 186 | 187 | } 188 | 189 | }); 190 | 191 | 192 | } else { 193 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("error.no-permission")); 194 | } 195 | 196 | return; 197 | 198 | } 199 | 200 | final String pluginName = StringUtil.consolidateStrings(args, 1).replaceAll(" ", "+").replace("-[a-zA-Z]", "").replace("+null", ""); 201 | 202 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.header")); 203 | 204 | ThreadUtil.async(new Runnable() { 205 | 206 | @Override 207 | public void run() { 208 | 209 | final UpdateResult result = UpdateUtil.checkUpToDate(pluginName); 210 | 211 | ThreadUtil.sync(new Runnable() { 212 | 213 | @Override 214 | public void run() { 215 | switch (result.getType()) { 216 | case NOT_INSTALLED: 217 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.not-found", result.getLatestVersion())); 218 | break; 219 | case OUT_OF_DATE: 220 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.out-of-date", result.getCurrentVersion(), result.getLatestVersion())); 221 | break; 222 | case UP_TO_DATE: 223 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.up-to-date", result.getCurrentVersion())); 224 | break; 225 | default: 226 | sender.sendMessage(PlugMan.getInstance().getMessageFormatter().format("check.not-found-spigot")); 227 | } 228 | } 229 | 230 | }); 231 | 232 | } 233 | 234 | }); 235 | 236 | } 237 | 238 | } -------------------------------------------------------------------------------- /src/main/java/me/entity303/plugmanbungee/util/BungeePluginUtil.java: -------------------------------------------------------------------------------- 1 | package me.entity303.plugmanbungee.util; 2 | 3 | import me.entity303.plugmanbungee.main.PlugManBungee; 4 | import net.md_5.bungee.api.ProxyServer; 5 | import net.md_5.bungee.api.plugin.Plugin; 6 | import net.md_5.bungee.api.plugin.PluginDescription; 7 | import net.md_5.bungee.api.plugin.PluginManager; 8 | import org.yaml.snakeyaml.Yaml; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.lang.reflect.Field; 14 | import java.net.URLClassLoader; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | import java.util.Set; 18 | import java.util.jar.JarEntry; 19 | import java.util.jar.JarFile; 20 | import java.util.logging.Handler; 21 | import java.util.logging.Level; 22 | 23 | public class BungeePluginUtil { 24 | 25 | public static Map.Entry reloadPlugin(Plugin plugin) { 26 | File file = plugin.getFile(); 27 | 28 | 29 | PluginResult result1 = unloadPlugin(plugin); 30 | 31 | PluginResult result2 = loadPlugin(file); 32 | 33 | return new Map.Entry() { 34 | @Override 35 | public PluginResult getKey() { 36 | return result1; 37 | } 38 | 39 | @Override 40 | public PluginResult getValue() { 41 | return result2; 42 | } 43 | 44 | @Override 45 | public PluginResult setValue(PluginResult value) { 46 | return result2; 47 | } 48 | }; 49 | } 50 | 51 | public static PluginResult unloadPlugin(Plugin plugin) { 52 | boolean exception = false; 53 | PluginManager pluginManager = ProxyServer.getInstance().getPluginManager(); 54 | try { 55 | plugin.onDisable(); 56 | for (Handler handler : plugin.getLogger().getHandlers()) { 57 | handler.close(); 58 | } 59 | } catch (Throwable t) { 60 | PlugManBungee.getInstance().getLogger().log(Level.SEVERE, "Exception disabling plugin '" + plugin.getDescription().getName() + "'", t); 61 | exception = true; 62 | } 63 | 64 | pluginManager.unregisterCommands(plugin); 65 | 66 | pluginManager.unregisterListeners(plugin); 67 | 68 | ProxyServer.getInstance().getScheduler().cancel(plugin); 69 | 70 | plugin.getExecutorService().shutdownNow(); 71 | 72 | Field pluginsField = null; 73 | try { 74 | pluginsField = PluginManager.class.getDeclaredField("plugins"); 75 | pluginsField.setAccessible(true); 76 | } catch (NoSuchFieldException e) { 77 | e.printStackTrace(); 78 | return new PluginResult("§cError while trying to unload plugin: §4Could not load field 'plugins'§c, see console for more info!", false); 79 | } 80 | 81 | Map plugins; 82 | 83 | try { 84 | plugins = (Map) pluginsField.get(pluginManager); 85 | } catch (IllegalAccessException e) { 86 | e.printStackTrace(); 87 | return new PluginResult("§cError while trying to unload plugin: §4Could not get field 'plugins'§c, see console for more info!", false); 88 | } 89 | 90 | plugins.remove(plugin.getDescription().getName()); 91 | 92 | ClassLoader cl = plugin.getClass().getClassLoader(); 93 | 94 | if (cl instanceof URLClassLoader) { 95 | 96 | try { 97 | 98 | Field pluginField = cl.getClass().getDeclaredField("plugin"); 99 | pluginField.setAccessible(true); 100 | pluginField.set(cl, null); 101 | 102 | Field pluginInitField = cl.getClass().getDeclaredField("desc"); 103 | pluginInitField.setAccessible(true); 104 | pluginInitField.set(cl, null); 105 | 106 | Field allLoadersField = cl.getClass().getDeclaredField("allLoaders"); 107 | allLoadersField.setAccessible(true); 108 | Set allLoaders = (Set) allLoadersField.get(cl); 109 | allLoaders.remove(cl); 110 | 111 | } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { 112 | PlugManBungee.getInstance().getLogger().log(Level.SEVERE, null, ex); 113 | 114 | return new PluginResult("§cError while trying to unload plugin: §4Could not unload ClassLoader§c, see console for more info!", false); 115 | } 116 | 117 | try { 118 | 119 | ((URLClassLoader) cl).close(); 120 | } catch (IOException ex) { 121 | PlugManBungee.getInstance().getLogger().log(Level.SEVERE, null, ex); 122 | return new PluginResult("§cError while trying to unload plugin: §4Could not close ClassLoader§c, see console for more info!", false); 123 | } 124 | 125 | } 126 | 127 | // Will not work on processes started with the -XX:+DisableExplicitGC flag, but lets try it anyway. 128 | // This tries to get around the issue where Windows refuses to unlock jar files that were previously loaded into the JVM. 129 | System.gc(); 130 | if (exception) { 131 | return new PluginResult("§cAn unknown error occured while unloading, see console for more info!", false); 132 | } else { 133 | return new PluginResult("§7Plugin was unloaded successfully!", true); 134 | } 135 | } 136 | 137 | public static PluginResult loadPlugin(File file) { 138 | PluginManager pluginManager = ProxyServer.getInstance().getPluginManager(); 139 | 140 | Field yamlField = null; 141 | try { 142 | yamlField = PluginManager.class.getDeclaredField("yaml"); 143 | yamlField.setAccessible(true); 144 | } catch (NoSuchFieldException e) { 145 | e.printStackTrace(); 146 | return new PluginResult("§cError while trying to load plugin: §4Could not load field 'yaml'§c, see console for more info!", false); 147 | } 148 | 149 | Yaml yaml = null; 150 | try { 151 | yaml = (Yaml) yamlField.get(pluginManager); 152 | } catch (IllegalAccessException e) { 153 | e.printStackTrace(); 154 | return new PluginResult("§cError while trying to load plugin: §4Could not get field 'yaml'§c, see console for more info!", false); 155 | } 156 | 157 | Field toLoadField = null; 158 | try { 159 | toLoadField = PluginManager.class.getDeclaredField("toLoad"); 160 | toLoadField.setAccessible(true); 161 | } catch (NoSuchFieldException e) { 162 | e.printStackTrace(); 163 | return new PluginResult("§cError while trying to load plugin: §4Could not load field 'toLoad'§c, see console for more info!", false); 164 | } 165 | 166 | HashMap toLoad = null; 167 | try { 168 | toLoad = (HashMap) toLoadField.get(pluginManager); 169 | } catch (IllegalAccessException e) { 170 | e.printStackTrace(); 171 | return new PluginResult("§cError while trying to load plugin: §4Could not get field 'toLoad'§c, see console for more info!", false); 172 | } 173 | 174 | if (toLoad == null) { 175 | toLoad = new HashMap<>(); 176 | } 177 | 178 | if (file.isFile()) { 179 | PluginDescription desc; 180 | 181 | try (JarFile jar = new JarFile(file)) { 182 | JarEntry pdf = jar.getJarEntry("bungee.yml"); 183 | if (pdf == null) { 184 | pdf = jar.getJarEntry("plugin.yml"); 185 | } 186 | 187 | if (pdf == null) { 188 | return new PluginResult("§cError while trying to load plugin: §4Plugin does not contain plugin.yml or bungee.yml!", false); 189 | } 190 | 191 | //Preconditions.checkNotNull(pdf, "Plugin must have a plugin.yml or bungee.yml"); 192 | 193 | try (InputStream in = jar.getInputStream(pdf)) { 194 | desc = yaml.loadAs(in, PluginDescription.class); 195 | 196 | if (desc.getName() == null) { 197 | return new PluginResult("§cError while trying to load plugin: §4Plugin does not contain a name in it's plugin.yml/bungee.yml!", false); 198 | } 199 | 200 | if (desc.getMain() == null) { 201 | return new PluginResult("§cError while trying to load plugin: §4Plugin does not contain a main class in it's plugin.yml/bungee.yml!", false); 202 | } 203 | 204 | if (pluginManager.getPlugin(desc.getName()) != null) { 205 | return new PluginResult("§cError while trying to load plugin: §4A plugin named '" + desc.getName() + "' is already loaded!", false); 206 | } 207 | 208 | desc.setFile(file); 209 | 210 | toLoad.put(desc.getName(), desc); 211 | } 212 | 213 | toLoadField.set(pluginManager, toLoad); 214 | 215 | pluginManager.loadPlugins(); 216 | 217 | Plugin plugin = pluginManager.getPlugin(desc.getName()); 218 | if (plugin == null) 219 | return new PluginResult("§cError while trying to load plugin: §4An unknown error occurred§c, see console for more info!", false); 220 | plugin.onEnable(); 221 | } catch (Exception ex) { 222 | ProxyServer.getInstance().getLogger().log(Level.WARNING, "Could not load plugin from file " + file, ex); 223 | return new PluginResult("§cError while trying to load plugin: §4An unknown error occurred§c, see console for more info!", false); 224 | } 225 | } 226 | return new PluginResult("§7Plugin was loaded successfully!", true); 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /src/main/java/com/rylinaux/plugman/util/BukkitCommandWrap.java: -------------------------------------------------------------------------------- 1 | package com.rylinaux.plugman.util; 2 | 3 | import com.mojang.brigadier.tree.CommandNode; 4 | import com.mojang.brigadier.tree.RootCommandNode; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.command.Command; 7 | import org.bukkit.entity.Player; 8 | 9 | import java.lang.reflect.Constructor; 10 | import java.lang.reflect.Field; 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.lang.reflect.Method; 13 | 14 | public class BukkitCommandWrap { 15 | private Field bField; 16 | private Method removeCommandMethod; 17 | private Class minecraftServerClass; 18 | private Method aMethod; 19 | private Method getServerMethod; 20 | private Field vanillaCommandDispatcherField; 21 | private Method getCommandDispatcherMethod; 22 | private Method registerMethod; 23 | private Method syncCommandsMethod; 24 | private Constructor bukkitcommandWrapperConstructor; 25 | 26 | public void wrap(Command command, String alias) { 27 | if (this.minecraftServerClass == null) try { 28 | this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer"); 29 | } catch (ClassNotFoundException e) { 30 | try { 31 | this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer"); 32 | } catch (ClassNotFoundException classNotFoundException) { 33 | classNotFoundException.addSuppressed(e); 34 | classNotFoundException.printStackTrace(); 35 | return; 36 | } 37 | } 38 | 39 | if (this.getServerMethod == null) try { 40 | this.getServerMethod = this.minecraftServerClass.getMethod("getServer"); 41 | this.getServerMethod.setAccessible(true); 42 | } catch (NoSuchMethodException e) { 43 | e.printStackTrace(); 44 | return; 45 | } 46 | 47 | Object minecraftServer; 48 | try { 49 | minecraftServer = this.getServerMethod.invoke(this.minecraftServerClass); 50 | } catch (IllegalAccessException | InvocationTargetException e) { 51 | e.printStackTrace(); 52 | return; 53 | } 54 | 55 | if (this.vanillaCommandDispatcherField == null) try { 56 | this.vanillaCommandDispatcherField = this.minecraftServerClass.getDeclaredField("vanillaCommandDispatcher"); 57 | this.vanillaCommandDispatcherField.setAccessible(true); 58 | } catch (NoSuchFieldException e) { 59 | e.printStackTrace(); 60 | return; 61 | } 62 | 63 | Object commandDispatcher = null; 64 | try { 65 | commandDispatcher = this.vanillaCommandDispatcherField.get(minecraftServer); 66 | } catch (IllegalAccessException e) { 67 | e.printStackTrace(); 68 | return; 69 | } 70 | 71 | if (this.bField == null) try { 72 | this.bField = Class.forName("net.minecraft.server.CommandDispatcher").getDeclaredField("b"); 73 | this.bField.setAccessible(true); 74 | } catch (NoSuchFieldException | ClassNotFoundException e) { 75 | if (this.bField == null) try { 76 | Class commandDispatcherClass = Class.forName("net.minecraft.commands.CommandDispatcher"); 77 | if (commandDispatcherClass.getDeclaredField("g").getType() == com.mojang.brigadier.CommandDispatcher.class) { 78 | this.bField = commandDispatcherClass.getDeclaredField("g"); 79 | } else { 80 | this.bField = commandDispatcherClass.getDeclaredField("h"); 81 | } 82 | this.bField.setAccessible(true); 83 | } catch (NoSuchFieldException | ClassNotFoundException ex) { 84 | ex.addSuppressed(e); 85 | e.printStackTrace(); 86 | return; 87 | } 88 | } 89 | 90 | com.mojang.brigadier.CommandDispatcher b; 91 | try { 92 | b = (com.mojang.brigadier.CommandDispatcher) this.bField.get(commandDispatcher); 93 | } catch (IllegalAccessException e) { 94 | e.printStackTrace(); 95 | return; 96 | } 97 | 98 | if (this.aMethod == null) try { 99 | this.aMethod = commandDispatcher.getClass().getDeclaredMethod("a"); 100 | this.aMethod.setAccessible(true); 101 | } catch (NoSuchMethodException e) { 102 | e.printStackTrace(); 103 | return; 104 | } 105 | 106 | if (this.bukkitcommandWrapperConstructor == null) try { 107 | this.bukkitcommandWrapperConstructor = Class.forName("org.bukkit.craftbukkit.command.BukkitCommandWrapper").getDeclaredConstructor(Class.forName("org.bukkit.craftbukkit.CraftServer"), Command.class); 108 | this.bukkitcommandWrapperConstructor.setAccessible(true); 109 | } catch (NoSuchMethodException | ClassNotFoundException e) { 110 | e.printStackTrace(); 111 | return; 112 | } 113 | 114 | Object commandWrapper; 115 | 116 | try { 117 | commandWrapper = this.bukkitcommandWrapperConstructor.newInstance(Bukkit.getServer(), command); 118 | } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { 119 | e.printStackTrace(); 120 | return; 121 | } 122 | 123 | Object a; 124 | 125 | try { 126 | a = this.aMethod.invoke(commandDispatcher); 127 | } catch (IllegalAccessException | InvocationTargetException e) { 128 | e.printStackTrace(); 129 | return; 130 | } 131 | 132 | if (this.registerMethod == null) try { 133 | this.registerMethod = Class.forName("org.bukkit.craftbukkit.command.BukkitCommandWrapper").getMethod("register", com.mojang.brigadier.CommandDispatcher.class, String.class); 134 | this.registerMethod.setAccessible(true); 135 | } catch (NoSuchMethodException | ClassNotFoundException e) { 136 | e.printStackTrace(); 137 | return; 138 | } 139 | 140 | try { 141 | this.registerMethod.invoke(commandWrapper, a, alias); 142 | } catch (IllegalAccessException | InvocationTargetException e) { 143 | e.printStackTrace(); 144 | } 145 | } 146 | 147 | public void sync() { 148 | if (this.syncCommandsMethod == null) try { 149 | this.syncCommandsMethod = Class.forName("org.bukkit.craftbukkit.CraftServer").getDeclaredMethod("syncCommands"); 150 | this.syncCommandsMethod.setAccessible(true); 151 | 152 | if (Bukkit.getOnlinePlayers().size() >= 1) 153 | for (Player player : Bukkit.getOnlinePlayers()) 154 | player.updateCommands(); 155 | } catch (NoSuchMethodException | ClassNotFoundException e) { 156 | e.printStackTrace(); 157 | return; 158 | } 159 | 160 | try { 161 | this.syncCommandsMethod.invoke(Bukkit.getServer()); 162 | } catch (IllegalAccessException | InvocationTargetException e) { 163 | e.printStackTrace(); 164 | } 165 | } 166 | 167 | public void unwrap(String command) { 168 | if (this.minecraftServerClass == null) try { 169 | this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer"); 170 | } catch (ClassNotFoundException e) { 171 | try { 172 | this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer"); 173 | } catch (ClassNotFoundException classNotFoundException) { 174 | classNotFoundException.printStackTrace(); 175 | classNotFoundException.addSuppressed(e); 176 | return; 177 | } 178 | } 179 | if (this.getServerMethod == null) try { 180 | this.getServerMethod = this.minecraftServerClass.getMethod("getServer"); 181 | this.getServerMethod.setAccessible(true); 182 | } catch (NoSuchMethodException e) { 183 | e.printStackTrace(); 184 | return; 185 | } 186 | 187 | Object server; 188 | 189 | try { 190 | server = this.getServerMethod.invoke(this.minecraftServerClass); 191 | } catch (IllegalAccessException | InvocationTargetException e) { 192 | e.printStackTrace(); 193 | return; 194 | } 195 | 196 | if (this.vanillaCommandDispatcherField == null) try { 197 | this.vanillaCommandDispatcherField = this.minecraftServerClass.getDeclaredField("vanillaCommandDispatcher"); 198 | this.vanillaCommandDispatcherField.setAccessible(true); 199 | } catch (NoSuchFieldException e) { 200 | e.printStackTrace(); 201 | return; 202 | } 203 | 204 | Object commandDispatcher = null; 205 | try { 206 | commandDispatcher = this.vanillaCommandDispatcherField.get(server); 207 | } catch (IllegalAccessException e) { 208 | e.printStackTrace(); 209 | return; 210 | } 211 | 212 | if (this.bField == null) try { 213 | this.bField = Class.forName("net.minecraft.server.CommandDispatcher").getDeclaredField("b"); 214 | this.bField.setAccessible(true); 215 | } catch (NoSuchFieldException | ClassNotFoundException e) { 216 | if (this.bField == null) try { 217 | Class commandDispatcherClass = Class.forName("net.minecraft.commands.CommandDispatcher"); 218 | if (commandDispatcherClass.getDeclaredField("g").getType() == com.mojang.brigadier.CommandDispatcher.class) { 219 | this.bField = commandDispatcherClass.getDeclaredField("g"); 220 | } else { 221 | this.bField = commandDispatcherClass.getDeclaredField("h"); 222 | } 223 | this.bField.setAccessible(true); 224 | } catch (NoSuchFieldException | ClassNotFoundException ex) { 225 | ex.addSuppressed(e); 226 | e.printStackTrace(); 227 | return; 228 | } 229 | } 230 | 231 | com.mojang.brigadier.CommandDispatcher b; 232 | try { 233 | b = (com.mojang.brigadier.CommandDispatcher) this.bField.get(commandDispatcher); 234 | } catch (IllegalAccessException e) { 235 | e.printStackTrace(); 236 | return; 237 | } 238 | 239 | if (this.removeCommandMethod == null) try { 240 | try { 241 | this.removeCommandMethod = RootCommandNode.class.getDeclaredMethod("removeCommand", String.class); 242 | } catch (NoSuchMethodException | NoSuchMethodError ex) { 243 | this.removeCommandMethod = CommandNode.class.getDeclaredMethod("removeCommand", String.class); 244 | } 245 | } catch (NoSuchMethodException e) { 246 | e.printStackTrace(); 247 | return; 248 | } 249 | 250 | try { 251 | this.removeCommandMethod.invoke(b.getRoot(), command); 252 | } catch (IllegalAccessException | InvocationTargetException e) { 253 | e.printStackTrace(); 254 | } 255 | } 256 | } 257 | --------------------------------------------------------------------------------