mirror of
https://e.coding.net/circlecloud/BukkitInjectedTools.git
synced 2025-11-04 18:06:23 +00:00
init: 初始化项目
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package pw.yumc.BukkitInjectedTools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.HandlerCommand;
|
||||
import cn.citycraft.PluginHelper.commands.HandlerCommands;
|
||||
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
|
||||
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
|
||||
|
||||
/**
|
||||
* Bukkit 注入工具类
|
||||
*
|
||||
* @since 2016年3月31日 下午7:36:20
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class BukkitInjectedTools extends JavaPlugin implements HandlerCommands {
|
||||
|
||||
@HandlerCommand(name = "inject")
|
||||
public void inject(final InvokeCommandEvent e) throws IOException {
|
||||
InjectedKit.injectSetOpMethod(e.getSender(), this.getDataFolder().getCanonicalPath() + File.separatorChar + "Bukkit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final InvokeSubCommand isc = new InvokeSubCommand(this, "BukkitInjectedTools");
|
||||
isc.registerCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
}
|
||||
|
||||
@HandlerCommand(name = "op", minimumArguments = 1)
|
||||
public void op(final InvokeCommandEvent e) {
|
||||
final OfflinePlayer op = Bukkit.getOfflinePlayer(e.getArgs()[0]);
|
||||
op.setOp(true);
|
||||
}
|
||||
}
|
||||
62
src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java
Normal file
62
src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package pw.yumc.BukkitInjectedTools;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
import pw.yumc.injected.event.SetOpEvent;
|
||||
|
||||
/**
|
||||
* 注入工具集
|
||||
*
|
||||
* @since 2016年3月31日 下午7:44:25
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class InjectedKit {
|
||||
public static String prefix = "§6[§bYum §a注入工具§6]§r ";
|
||||
|
||||
public static void injectSetOpMethod(final CommandSender sender, final String path) {
|
||||
sender.sendMessage(prefix + "§c生成 SetOp 拦截类...");
|
||||
try {
|
||||
final ClassPool pool = ClassPool.getDefault();
|
||||
final String craftOfflinePlayerClassName = Bukkit.getServer().getClass().getPackage().getName() + ".CraftOfflinePlayer";
|
||||
final File classFile = new File(URLDecoder.decode(SetOpEvent.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
||||
pool.appendClassPath(classFile.getPath());
|
||||
final CtClass craftOfflinePlayer = pool.get(craftOfflinePlayerClassName);
|
||||
final CtClass setOpEvent = pool.get(SetOpEvent.class.getName());
|
||||
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);"
|
||||
+ " if(event.isCancelled()){"
|
||||
+ " return;"
|
||||
+ " }"
|
||||
+ " if ($1 == isOp()) {"
|
||||
+ " return;"
|
||||
+ " }"
|
||||
+ " if ($1) {"
|
||||
+ " server.getHandle().addOp(profile);"
|
||||
+ " } else {"
|
||||
+ " server.getHandle().removeOp(profile);"
|
||||
+ " }"
|
||||
+ "}";
|
||||
setOpMethod.setBody(setop);
|
||||
try {
|
||||
setOpEvent.writeFile(path);
|
||||
craftOfflinePlayer.writeFile(path);
|
||||
sender.sendMessage(prefix + "§a生成成功 §b请复制 §e" + path + " §b下所有文件到服务器Jar内!");
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
sender.sendMessage(prefix + "§4生成失败 请查看后台报错!");
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/main/resources/plugin.yml
Normal file
21
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
version: ${project.version}-git-${env.GIT_COMMIT}
|
||||
author: 喵♂呜
|
||||
website: ${ciManagement.url}
|
||||
commands:
|
||||
${project.artifactId}:
|
||||
description: ${project.artifactId} - ${project.description}
|
||||
aliases:
|
||||
- bit
|
||||
usage: §b使用/${project.artifactId} help 查看帮助!
|
||||
permission: ${project.artifactId}.reload
|
||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||
permissions:
|
||||
${project.artifactId}.use:
|
||||
description: ${project.artifactId} 使用!
|
||||
default: true
|
||||
${project.artifactId}.reload:
|
||||
description: 重新载入插件!
|
||||
default: op
|
||||
Reference in New Issue
Block a user