commit 079dc9da0dcc403ecd27d32be7ff8985863eaa83 Author: 502647092 Date: Thu Mar 31 20:34:25 2016 +0800 init: 初始化项目 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3a92321 --- /dev/null +++ b/.classpath @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7876f5f --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Eclipse stuff +/.settings + +# netbeans +/nbproject + +# we use maven! +/build.xml + +# maven +/target +/repo + +# vim +.*.sw[a-p] + +# various other potential build files +/build +/bin +/dist +/manifest.mf + +/world + +# Mac filesystem dust +*.DS_Store + +# intellij +*.iml +*.ipr +*.iws +.idea/ + +# Project Stuff +/src/main/resources/Soulbound + +# Atlassian Stuff +/atlassian-ide-plugin.xml \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..8e90838 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + BukkitInjectedTools + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3d0f72c --- /dev/null +++ b/pom.xml @@ -0,0 +1,92 @@ + + 4.0.0 + pw.yumc + BukkitInjectedTools + 1.0 + BukkitInjectedTools + + ${project.name} + + + src/main/resources + true + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + false + true + + + cn.citycraft:PluginHelper + + + + + cn.citycraft.PluginHelper + ${project.groupId}.${project.artifactId} + + + + + + package + + shade + + + + + + + + Jenkins + http://ci.yumc.pw/job/${project.artifactId}/ + + + + + DEBUG + UTF-8 + + + + yumc-repo + http://repo.yumc.pw/content/groups/public/ + + + + + jtb + YUMC + http://repo.yumc.pw/content/repositories/yumcenter/ + + + + + org.spigotmc + spigot-api + jar + 1.9-R0.1-SNAPSHOT + + + cn.citycraft + PluginHelper + jar + 1.0 + + + \ No newline at end of file diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/BukkitInjectedTools.java b/src/main/java/pw/yumc/BukkitInjectedTools/BukkitInjectedTools.java new file mode 100644 index 0000000..71d8e42 --- /dev/null +++ b/src/main/java/pw/yumc/BukkitInjectedTools/BukkitInjectedTools.java @@ -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); + } +} diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java new file mode 100644 index 0000000..8629529 --- /dev/null +++ b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java @@ -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(); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..4ae38b2 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -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你没有 的权限来执行此命令! +permissions: + ${project.artifactId}.use: + description: ${project.artifactId} 使用! + default: true + ${project.artifactId}.reload: + description: 重新载入插件! + default: op \ No newline at end of file