diff --git a/README-EN.md b/README-EN.md index c3ea6d9..0596080 100644 --- a/README-EN.md +++ b/README-EN.md @@ -9,10 +9,10 @@ README LANGUAGES [ [中文](README.md) | [**English**](README-EN.md) ] # MoeTeleport -[![CodeFactor](https://www.codefactor.io/repository/github/carm-outsource/MoeTeleport/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carm-outsource/MoeTeleport) -![CodeSize](https://img.shields.io/github/languages/code-size/carm-outsource/MoeTeleport) -[![Download](https://img.shields.io/github/downloads/carm-outsource/MoeTeleport/total)](https://github.com/carm-outsource/MoeTeleport/releases) -[![Java CI with Maven](https://github.com/carm-outsource/MoeTeleport/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/carm-outsource/MoeTeleport/actions/workflows/maven.yml) +[![CodeFactor](https://www.codefactor.io/repository/github/CarmJos/MoeTeleport/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/CarmJos/MoeTeleport) +![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/MoeTeleport) +[![Download](https://img.shields.io/github/downloads/CarmJos/MoeTeleport/total)](https://github.com/CarmJos/MoeTeleport/releases) +[![Java CI with Maven](https://github.com/CarmJos/MoeTeleport/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/MoeTeleport/actions/workflows/maven.yml) ![Support](https://img.shields.io/badge/Minecraft-Java%201.13--Latest-blue) ![](https://visitor-badge.glitch.me/badge?page_id=moeteleport.readme) diff --git a/README.md b/README.md index ecb90cc..81e56bd 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,10 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-EN.md) ] # MoeTeleport 喵喵传送 -[![CodeFactor](https://www.codefactor.io/repository/github/carm-outsource/MoeTeleport/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carm-outsource/MoeTeleport) -![CodeSize](https://img.shields.io/github/languages/code-size/carm-outsource/MoeTeleport) -[![Download](https://img.shields.io/github/downloads/carm-outsource/MoeTeleport/total)](https://github.com/carm-outsource/MoeTeleport/releases) -[![Java CI with Maven](https://github.com/carm-outsource/MoeTeleport/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/carm-outsource/MoeTeleport/actions/workflows/maven.yml) +[![CodeFactor](https://www.codefactor.io/repository/github/CarmJos/MoeTeleport/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/CarmJos/MoeTeleport) +![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/MoeTeleport) +[![Download](https://img.shields.io/github/downloads/CarmJos/MoeTeleport/total)](https://github.com/CarmJos/MoeTeleport/releases) +[![Java CI with Maven](https://github.com/CarmJos/MoeTeleport/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/MoeTeleport/actions/workflows/maven.yml) ![Support](https://img.shields.io/badge/Minecraft-Java%201.13--Latest-blue) ![](https://visitor-badge.glitch.me/badge?page_id=moeteleport.readme) diff --git a/pom.xml b/pom.xml index 40e0b56..9e3a29e 100644 --- a/pom.xml +++ b/pom.xml @@ -11,14 +11,14 @@ UTF-8 UTF-8 - 1.5.4 + 1.5.5 0.4.6 2.5.0 cc.carm.plugin moeteleport - 4.0.1 + 4.0.2 MoeTeleport 喵喵传送,简单的传送、设置家的插件。 @@ -44,13 +44,6 @@ - - - carm-repo - Carm's Repo - https://repo.carm.cc/repository/maven-public/ - - spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ @@ -87,10 +80,11 @@ - github - GitHub Packages - https://maven.pkg.github.com/CarmJos/${project.name} + carm-repo + Carm's Repo + https://repo.carm.cc/repository/maven-public/ + @@ -98,7 +92,7 @@ github GitHub Packages - https://maven.pkg.github.com/CarmJos/${project.name} + https://maven.pkg.github.com/CarmJos/MoeTeleport @@ -128,6 +122,14 @@ true + + cc.carm.lib + easyplugin-command-alias + ${deps.easyplugin.version} + compile + true + + cc.carm.lib easyplugin-githubchecker @@ -295,7 +297,7 @@ - ${project.name}-${project.version} + MoeTeleport-${project.version} ${project.basedir}/asset/ false diff --git a/src/main/java/cc/carm/plugin/moeteleport/Main.java b/src/main/java/cc/carm/plugin/moeteleport/Main.java index 735cfb7..8ba3ca5 100644 --- a/src/main/java/cc/carm/plugin/moeteleport/Main.java +++ b/src/main/java/cc/carm/plugin/moeteleport/Main.java @@ -2,6 +2,7 @@ import cc.carm.lib.configuration.core.source.ConfigurationProvider; import cc.carm.lib.easyplugin.EasyPlugin; +import cc.carm.lib.easyplugin.command.alias.AliasCommandManager; import cc.carm.lib.easyplugin.updatechecker.GHUpdateChecker; import cc.carm.lib.mineconfiguration.bukkit.MineConfiguration; import cc.carm.plugin.moeteleport.command.MainCommands; @@ -15,6 +16,7 @@ import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; import xyz.xenondevs.particle.utils.ReflectionUtils; public class Main extends EasyPlugin { @@ -28,7 +30,7 @@ public class Main extends EasyPlugin { protected UserManager userManager; protected RequestManager requestManager; protected TeleportManager teleportManager; - protected CommandManager commandManager; + protected AliasCommandManager commandManager; public Main() { instance = this; @@ -85,14 +87,15 @@ protected boolean initialize() { log("注册指令..."); registerCommand("MoeTeleport", new MainCommands(this)); - try { - this.commandManager = new CommandManager(this); - if (PluginConfig.COMMAND.ENABLE.getNotNull()) { + if (PluginConfig.COMMAND.ENABLE.getNotNull()) { + log("注册简化指令映射..."); + try { + this.commandManager = new AliasCommandManager(this); PluginConfig.COMMAND.ALIAS.getNotNull().forEach(commandManager::register); + } catch (Exception e) { + log("注册简化指令失败: " + e.getMessage()); + e.printStackTrace(); } - } catch (Exception e) { - log("注册简化指令失败: " + e.getMessage()); - e.printStackTrace(); } if (PluginConfig.METRICS.getNotNull()) { @@ -116,8 +119,8 @@ protected boolean initialize() { @Override protected void shutdown() { - log("清空简化指令..."); - if (this.commandManager != null) { + if (PluginConfig.COMMAND.ENABLE.getNotNull() && this.commandManager != null) { + log("清空简化指令..."); this.commandManager.unregisterAll(); } diff --git a/src/main/java/cc/carm/plugin/moeteleport/command/sub/BackCommand.java b/src/main/java/cc/carm/plugin/moeteleport/command/sub/BackCommand.java index 771a0ca..d8f046f 100644 --- a/src/main/java/cc/carm/plugin/moeteleport/command/sub/BackCommand.java +++ b/src/main/java/cc/carm/plugin/moeteleport/command/sub/BackCommand.java @@ -39,4 +39,9 @@ public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) { return null; } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission("MoeTeleport.back"); + } + } diff --git a/src/main/java/cc/carm/plugin/moeteleport/command/sub/HomeCommands.java b/src/main/java/cc/carm/plugin/moeteleport/command/sub/HomeCommands.java index 49a6760..5255026 100644 --- a/src/main/java/cc/carm/plugin/moeteleport/command/sub/HomeCommands.java +++ b/src/main/java/cc/carm/plugin/moeteleport/command/sub/HomeCommands.java @@ -48,4 +48,9 @@ public Void noPermission(CommandSender sender) { return main.noPermission(sender); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission("MoeTeleport.home"); + } + } diff --git a/src/main/java/cc/carm/plugin/moeteleport/command/sub/ReloadCommand.java b/src/main/java/cc/carm/plugin/moeteleport/command/sub/ReloadCommand.java index 6094573..51c3069 100644 --- a/src/main/java/cc/carm/plugin/moeteleport/command/sub/ReloadCommand.java +++ b/src/main/java/cc/carm/plugin/moeteleport/command/sub/ReloadCommand.java @@ -35,7 +35,7 @@ public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) { @Override public boolean hasPermission(CommandSender sender) { - return sender.hasPermission("moeteleport.reload"); + return sender.hasPermission("MoeTeleport.admin"); } } diff --git a/src/main/java/cc/carm/plugin/moeteleport/command/sub/TeleportCommands.java b/src/main/java/cc/carm/plugin/moeteleport/command/sub/TeleportCommands.java index 45bbbda..f471fd5 100644 --- a/src/main/java/cc/carm/plugin/moeteleport/command/sub/TeleportCommands.java +++ b/src/main/java/cc/carm/plugin/moeteleport/command/sub/TeleportCommands.java @@ -22,7 +22,7 @@ public TeleportCommands(@NotNull JavaPlugin plugin, @NotNull MainCommands main, registerSubCommand(new TeleportRequestCommand(this, TeleportRequest.Type.TPA_TO, "to")); registerSubCommand(new TeleportRequestCommand(this, TeleportRequest.Type.TPA_HERE, "here")); - registerSubCommand(new TeleportHandleCommand(this, true, "cancel")); + registerSubCommand(new TeleportHandleCommand(this, true, "accept", "agree")); registerSubCommand(new TeleportHandleCommand(this, false, "deny", "refuse")); registerSubCommand(new TeleportCancelCommand(this, "cancel")); } @@ -38,4 +38,9 @@ public Void noPermission(CommandSender sender) { return main.noPermission(sender); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission("MoeTeleport.teleport"); + } + } diff --git a/src/main/java/cc/carm/plugin/moeteleport/command/sub/WarpCommands.java b/src/main/java/cc/carm/plugin/moeteleport/command/sub/WarpCommands.java index 1e31806..25f82cb 100644 --- a/src/main/java/cc/carm/plugin/moeteleport/command/sub/WarpCommands.java +++ b/src/main/java/cc/carm/plugin/moeteleport/command/sub/WarpCommands.java @@ -49,4 +49,10 @@ public Void noPermission(CommandSender sender) { return main.noPermission(sender); } + + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission("MoeTeleport.warp"); + } + } diff --git a/src/main/java/cc/carm/plugin/moeteleport/manager/CommandManager.java b/src/main/java/cc/carm/plugin/moeteleport/manager/CommandManager.java deleted file mode 100644 index d5e15ab..0000000 --- a/src/main/java/cc/carm/plugin/moeteleport/manager/CommandManager.java +++ /dev/null @@ -1,122 +0,0 @@ -package cc.carm.plugin.moeteleport.manager; - -import cc.carm.plugin.moeteleport.Main; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.plugin.SimplePluginManager; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.*; - -public class CommandManager { - - protected final JavaPlugin plugin; - - protected final SimpleCommandMap commandMap; - protected final Field knownCommandsFiled; - - protected final Map registeredCommands = new HashMap<>(); - - public CommandManager(JavaPlugin plugin) throws Exception { - this.plugin = plugin; - - SimplePluginManager manager = (SimplePluginManager) Bukkit.getPluginManager(); - Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - this.commandMap = (SimpleCommandMap) commandMapField.get(manager); - - this.knownCommandsFiled = SimpleCommandMap.class.getDeclaredField("knownCommands"); - this.knownCommandsFiled.setAccessible(true); - - } - - @SuppressWarnings("unchecked") - protected Map getKnownCommands() { - try { - return (Map) knownCommandsFiled.get(commandMap); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return new HashMap<>(); - } - - public String getPrefix() { - return this.plugin.getName().toLowerCase() + " "; - } - - protected SimpleCommandMap getCommandMap() { - return commandMap; - } - - public void register(String alias, String target) { - AliasCommand current = this.registeredCommands.get(alias); - if (current != null) current.unregister(getCommandMap()); - - AliasCommand cmd = new AliasCommand(alias, this, getPrefix() + target); - this.registeredCommands.put(alias, cmd); - getCommandMap().register(Main.getInstance().getName(), cmd); - } - - public void unregister(String alias) { - AliasCommand current = this.registeredCommands.remove(alias); - if (current != null) { - getKnownCommands().remove(alias); - current.unregister(getCommandMap()); - } - } - - public void unregisterAll() { - registeredCommands.forEach((k, v) -> { - getKnownCommands().remove(k); - v.unregister(getCommandMap()); - }); - registeredCommands.clear(); - } - - public static class AliasCommand extends Command { - - protected final CommandManager commandManager; - protected final String targetCommand; - - public AliasCommand(String name, CommandManager commandManager, String targetCommand) { - super(name); - this.commandManager = commandManager; - this.targetCommand = targetCommand; - } - - protected SimpleCommandMap getCommandMap() { - return this.commandManager.getCommandMap(); - } - - protected String buildCommand(String[] args) { - return this.targetCommand + " " + String.join(" ", args); - } - - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) { - return getCommandMap().dispatch(sender, buildCommand(args)); - } - - @NotNull - @Override - public List tabComplete(@NotNull CommandSender sender, @NotNull String alias, - @NotNull String[] args, @Nullable Location location) throws IllegalArgumentException { - return Optional.ofNullable(getCommandMap().tabComplete(sender, buildCommand(args))).orElse(Collections.emptyList()); - } - - @NotNull - @Override - public List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { - return tabComplete(sender, alias, args, null); - } - - } - - -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fd42aa2..1a88afc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -13,18 +13,30 @@ softdepend: - CMI permissions: - "MoeTeleport": - description: "插件的主权限节点" - default: false "MoeTeleport.admin": description: "插件的管理员权限节点" default: op + "MoeTeleport.teleport": + description: "使用传送请求相关指令的权限。" + default: true + + "MoeTeleport.home": + description: "使用家相关指令的权限。" + default: true + + "MoeTeleport.warp": + description: "使用传送请求相关指令的权限。" + default: true + + "MoeTeleport.back": + description: "使用返回相关指令的权限。" + default: true + commands: "MoeTeleport": description: "插件的主命令,用于重载插件或查看插件信息。" - permission: "MoeTeleport.admin" - usage: "/MoeTeleport reload" + usage: "您可以输入 /MoeTeleport help 查看插件的相关帮助。" aliases: - mt \ No newline at end of file