mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-12-01 02:04:45 +00:00
addons editor commands
This commit is contained in:
1 parent
bd45e4cb87
commit
621f3a6876
12 files changed
+205
-24
No files matched your search
@@ -33,6 +33,14 @@ public class AddonsCommand implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (args.length >= 2 && (args[1].equalsIgnoreCase("editor") || args[1].equalsIgnoreCase("editorsync"))) {
|
||||
Main plugin = Main.getInstance();
|
||||
if (!plugin.canEdit(sendi)) { sendi.sendMessage("§cYou need betterrtp.addon.editor permission."); return; }
|
||||
if (args[1].equalsIgnoreCase("editor") && args.length == 2) plugin.getEditorBridge().upload(sendi);
|
||||
else if (args[1].equalsIgnoreCase("editorsync") && args.length == 3) plugin.getEditorBridge().redeem(sendi, args[2]);
|
||||
else sendi.sendMessage("§eUsage: /" + label + " addons " + (args[1].equalsIgnoreCase("editor") ? "editor" : "editorsync <token>"));
|
||||
return;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
for (AddonCmds cmds : AddonCmds.values()) {
|
||||
if (cmds.name().equalsIgnoreCase(args[1])) {
|
||||
@@ -44,6 +52,7 @@ public class AddonsCommand implements RTPCommand, RTPCommandHelpable {
|
||||
} else {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(MessagesHelp.PREFIX.get());
|
||||
addEditorHelp(sendi, label, list);
|
||||
for (AddonsHandler.Addons addon : Main.getInstance().getAddonsHandler().addons) {
|
||||
RTPCommand cmd = addon.getCmd();
|
||||
if (cmd instanceof RTPCommandHelpable)
|
||||
@@ -57,6 +66,10 @@ public class AddonsCommand implements RTPCommand, RTPCommandHelpable {
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sendi, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (args.length == 2 && Main.getInstance().canEdit(sendi)) {
|
||||
for (String command : new String[] { "editor", "editorsync" })
|
||||
if (command.startsWith(args[1].toLowerCase(Locale.ROOT))) list.add(command);
|
||||
}
|
||||
if (args.length == 2)
|
||||
for (AddonCmds cmds : AddonCmds.values()) {
|
||||
if (cmds.name().toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
@@ -65,6 +78,13 @@ public class AddonsCommand implements RTPCommand, RTPCommandHelpable {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void addEditorHelp(CommandSender sender, String label, List<String> list) {
|
||||
if (Main.getInstance().canEdit(sender)) {
|
||||
list.add("§7- §e/" + label + " addons editor §7- Open the Addons web editor");
|
||||
list.add("§7- §e/" + label + " addons editorsync <token> §7- Apply a saved Addons config");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionNode permission() {
|
||||
return PermissionNode.USE;
|
||||
|
||||
@@ -30,7 +30,8 @@ public class AddonsHandler {
|
||||
//addonCount++;
|
||||
}
|
||||
//Main.getInstance().getLogger().log(Level.INFO, addonCount + "/" + Addons.values().length + " addons were enabled!");
|
||||
HelperRTP_Command.registerCommand(cmd, false);
|
||||
if (!BetterRTP.getInstance().getCmd().commands.contains(cmd))
|
||||
HelperRTP_Command.registerCommand(cmd, false);
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
|
||||
@@ -17,15 +17,26 @@ public class Main extends JavaPlugin {
|
||||
public final AddonMessages msgs = new AddonMessages();
|
||||
private final ReloadListener reloadListener = new ReloadListener();
|
||||
|
||||
@Getter
|
||||
private me.SuperRonanCraft.BetterRTP.references.web.editor.EditorBridge editorBridge;
|
||||
|
||||
public boolean canEdit(org.bukkit.command.CommandSender sender) {
|
||||
return !(sender instanceof org.bukkit.entity.Player) || sender.hasPermission("betterrtp.addon.editor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
Bukkit.getPluginManager().registerEvents(reloadListener, this);
|
||||
load();
|
||||
editorBridge = new me.SuperRonanCraft.BetterRTP.references.web.editor.EditorBridge(
|
||||
this, me.SuperRonanCraft.BetterRTP.versions.AsyncHandler::sync, sender -> load(),
|
||||
this::canEdit, () -> Files.FILETYPE.CONFIG.getConfig().saveToString(), "betterrtp-addons");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (editorBridge != null) editorBridge.close();
|
||||
addonsHandler.unload();
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -21,6 +21,7 @@ public class AddonsCommand_Help implements AddonsCommands, RTPCommandHelpable {
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(MessagesHelp.PREFIX.get());
|
||||
AddonsCommand.addEditorHelp(sendi, label, list);
|
||||
for (AddonsCommand.AddonCmds cmds : AddonsCommand.AddonCmds.values()) {
|
||||
if (cmds.cmd instanceof RTPCommandHelpable)
|
||||
list.add(((RTPCommandHelpable) cmds.cmd).getHelp().replace("%command%", label));
|
||||
|
||||
@@ -7,6 +7,9 @@ depend: [BetterRTP]
|
||||
softdepend: [ProtocolLib]
|
||||
|
||||
permissions:
|
||||
betterrtp.addon.editor:
|
||||
description: Open and sync the BetterRTP Addons web editor
|
||||
default: op
|
||||
betterrtp.addon.portals:
|
||||
description: Ability to use the portals addon commands
|
||||
|
||||
Reference in new issue
Block a user