From 06c85f1848f3967df5645f5052b4efbc2ecc3b32 Mon Sep 17 00:00:00 2001 From: sekwah Date: Mon, 22 Jan 2018 21:36:53 +0000 Subject: [PATCH] Starting to add spigot loading --- Resources/plugin.yml | 54 +++++++++++++++++++ .../coreconnector/command/CommandHandler.java | 30 +++++++++++ .../command/CommandRegister.java | 9 +++- .../container/CommandSenderContainer.java | 9 ++++ .../spigot/AdvancedPortalsPlugin.java | 4 +- 5 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 Resources/plugin.yml create mode 100644 src/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java diff --git a/Resources/plugin.yml b/Resources/plugin.yml new file mode 100644 index 0000000..383a4fb --- /dev/null +++ b/Resources/plugin.yml @@ -0,0 +1,54 @@ +main: com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin +name: AdvancedPortals +version: 1.0.0 +author: sekwah41 +description: An advanced portals plugin for bukkit. +commands: + advancedportals: + description: The main command for the advanced portals + aliases: [portals, aportals, portal, ap] + usage: / + destination: + description: Can be used to access portal destinations. + aliases: [desti] + usage: / +permissions: + advancedportals.*: + description: Gives access to all commands + default: op + children: + advancedportals.createportal: true + advancedportals.portal: true + advancedportals.build: true + advancedportals.desti: true + advancedportals.createportal: + description: Allows you to create portals + default: op + advancedportals.createportal.commandlevel.*: + description: Gives access to all level raisers + default: false + children: + advancedportals.createportal.commandlevel.op: true + advancedportals.createportal.commandlevel.perms: true + advancedportals.createportal.commandlevel.console: true + advancedportals.createportal.commandlevel.op: + description: Allows you to increase the users level temporaily to op + default: false + advancedportals.createportal.commandlevel.perms: + description: Allows you to increase the users level temporaily to have all perms + default: false + advancedportals.createportal.commandlevel.console: + description: Executes command in the console + default: false + advancedportals.portal: + description: Allows use of portal commands + default: op + advancedportals.build: + description: Allows you to build in the portal regions + default: op + advancedportals.desti: + description: Gives access to all desti commands + default: op + advancedportals.warp.*: + description: Access to all warps (not really used tbh) + default: true diff --git a/src/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java b/src/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java new file mode 100644 index 0000000..6b70aff --- /dev/null +++ b/src/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java @@ -0,0 +1,30 @@ +package com.sekwah.advancedportals.coreconnector.command; + +import com.sekwah.advancedportals.core.commands.CommandTemplate; +import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import java.util.List; + +public class CommandHandler implements CommandExecutor, TabCompleter { + + private final CommandTemplate commandExecutor; + + public CommandHandler(CommandTemplate commandExecutor) { + this.commandExecutor = commandExecutor; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + this.commandExecutor.onCommand(new CommandSenderContainer(commandSender), command.getName(), args); + return true; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] args) { + return this.commandExecutor.onTabComplete(new CommandSenderContainer(commandSender), args); + } +} diff --git a/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java b/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java index feeaf6f..e304f16 100644 --- a/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java +++ b/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java @@ -1,18 +1,25 @@ package com.sekwah.advancedportals.coreconnector.command; import com.sekwah.advancedportals.core.commands.CommandTemplate; +import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; /** * Register the CommandTemplate files to the appropriate system */ public class CommandRegister { + private final AdvancedPortalsPlugin plugin; + + public CommandRegister(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; + } + /** * Registers the command to the appropriate system * @param commandName * @param commandExecutor */ public void registerCommand(String commandName, CommandTemplate commandExecutor) { - + this.plugin.getCommand(commandName).setExecutor(new CommandHandler(commandExecutor)); } } diff --git a/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java b/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java index afe6cfd..bcc7d6a 100644 --- a/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java +++ b/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java @@ -1,8 +1,17 @@ package com.sekwah.advancedportals.coreconnector.container; import com.sekwah.advancedportals.core.util.Lang; +import org.bukkit.command.CommandSender; public class CommandSenderContainer { + + private final CommandSender sender; + + public CommandSenderContainer(CommandSender commandSender) { + this.sender = commandSender; + } + public void sendMessage(String message) { + sender.sendMessage(message); } } diff --git a/src/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java index b040bee..fba5b66 100644 --- a/src/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java @@ -2,6 +2,7 @@ package com.sekwah.advancedportals.spigot; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.util.DataStorage; +import com.sekwah.advancedportals.coreconnector.command.CommandRegister; import org.bukkit.plugin.java.JavaPlugin; public class AdvancedPortalsPlugin extends JavaPlugin { @@ -9,7 +10,8 @@ public class AdvancedPortalsPlugin extends JavaPlugin { private AdvancedPortalsCore portalsCore; public void onEnable() { - this.portalsCore = new AdvancedPortalsCore(new DataStorage(this.getDataFolder()), new SpigotInfoLogger(this)); + this.portalsCore = new AdvancedPortalsCore(new DataStorage(this.getDataFolder()), + new SpigotInfoLogger(this), new CommandRegister(this)); } public void onDisable() {