From 14ddb769e617d972223f4ec0c9ca0f7e971305de Mon Sep 17 00:00:00 2001 From: sekwah Date: Tue, 23 Jan 2018 17:59:41 +0000 Subject: [PATCH] Added more subcommands --- Resources/lang/en_GB.lang | 7 ++++ .../core/AdvancedPortalsCore.java | 14 ++++++-- .../advancedportals/core/CoreListeners.java | 5 ++- .../subcommands/portal/ReloadSubCommand.java | 34 ++++++++++++++++++ .../portal/TransUpdateSubCommand.java | 36 +++++++++++++++++++ .../subcommands/portal/VersionSubCommand.java | 4 +-- .../container/CommandSenderContainer.java | 4 +++ 7 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java create mode 100644 src/com/sekwah/advancedportals/core/commands/subcommands/portal/TransUpdateSubCommand.java diff --git a/Resources/lang/en_GB.lang b/Resources/lang/en_GB.lang index fd1b5d0..a28e1b2 100644 --- a/Resources/lang/en_GB.lang +++ b/Resources/lang/en_GB.lang @@ -13,6 +13,8 @@ # translatedata.lastchange=1.0.0 translatedata.translationsoutdated= Some of the translations from the current translation file \u00A7e%1$s\u00A7c are out of date. +translatedata.replacecommand= Use \u00A7e/portal transupdate\u00A7c to copy out a new default \u00A7een_GB\u00A7c file. +translatedata.replaced= A new \u00A7een_GB\u00A7c file has been copied to the data folder. messageprefix.positive=\u00A7a[\u00A7eAdvancedPortals\u00A7a] messageprefix.negative=\u00A7c[\u00A77AdvancedPortals\u00A7c] @@ -27,4 +29,9 @@ command.subcommand.invalid= Sorry but that is not a valid sub command. command.help.header=\u00A7e--------- \u00A7a%1$s Help - Page %2$s of %3$s\u00A7e --------------- command.help.invalidnum= Sorry but \u00A7e%1$s\u00A7c is not a valid page number. +command.reload.help=Reloads portal data +command.reload.detailedhelp=Reloads all portal data from files in the data folder + +command.version.help=Returns the current version of the plugin + command.subcommand.nopermission= Sorry but you don't have permission for that, please use \u00A7e/%1$s help \u00A7cif you would like a list of possible sub commands. diff --git a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index d272112..09ffe28 100644 --- a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -2,6 +2,8 @@ package com.sekwah.advancedportals.core; import com.sekwah.advancedportals.core.api.commands.SubCommand; import com.sekwah.advancedportals.core.commands.CommandWithSubCommands; +import com.sekwah.advancedportals.core.commands.subcommands.portal.ReloadSubCommand; +import com.sekwah.advancedportals.core.commands.subcommands.portal.TransUpdateSubCommand; import com.sekwah.advancedportals.core.commands.subcommands.portal.VersionSubCommand; import com.sekwah.advancedportals.core.util.Config; import com.sekwah.advancedportals.core.util.DataStorage; @@ -35,6 +37,10 @@ public class AdvancedPortalsCore { this.onEnable(); } + public static String getTranslationName() { + return instance.config.getTranslation(); + } + private void onEnable() { this.dataStorage.copyDefaultFile("lang/en_GB.lang", false); @@ -44,13 +50,15 @@ public class AdvancedPortalsCore { this.registerPortalCommand(); this.registerDestinationCommand(); - infoLogger.log(Lang.translate("logger.pluginenable")); + this.infoLogger.log(Lang.translate("logger.pluginenable")); } private void registerPortalCommand() { this.portalCommand = new CommandWithSubCommands(); this.portalCommand.registerSubCommand("version", new VersionSubCommand()); + this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand()); + this.portalCommand.registerSubCommand("reload", new ReloadSubCommand()); this.commandRegister.registerCommand("portal", this.portalCommand); } @@ -78,7 +86,7 @@ public class AdvancedPortalsCore { } public void onDisable() { - infoLogger.log(Lang.translate("logger.plugindisable")); + this.infoLogger.log(Lang.translate("logger.plugindisable")); } private static AdvancedPortalsCore getInstance() { @@ -94,6 +102,6 @@ public class AdvancedPortalsCore { } public CoreListeners getCoreListeners() { - return coreListeners; + return this.coreListeners; } } diff --git a/src/com/sekwah/advancedportals/core/CoreListeners.java b/src/com/sekwah/advancedportals/core/CoreListeners.java index d958440..615b15a 100644 --- a/src/com/sekwah/advancedportals/core/CoreListeners.java +++ b/src/com/sekwah/advancedportals/core/CoreListeners.java @@ -8,7 +8,10 @@ public class CoreListeners { public void playerJoin(PlayerContainer player) { if(player.isOp()) { if(!Lang.translate("translatedata.lastchange").equals(AdvancedPortalsCore.lastTranslationUpdate)) { - player.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("translatedata.translationsoutdated")); + player.sendMessage(Lang.translateColor("messageprefix.negative" + + Lang.translateInsertVariablesColor("translatedata.translationsoutdated", AdvancedPortalsCore.getTranslationName()))); + player.sendMessage(Lang.translateColor("messageprefix.negative" + + Lang.translateColor("translatedata.replacecommand"))); } } } diff --git a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java new file mode 100644 index 0000000..9e61d5f --- /dev/null +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java @@ -0,0 +1,34 @@ +package com.sekwah.advancedportals.core.commands.subcommands.portal; + +import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.api.commands.SubCommand; +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; + +import java.util.List; + +public class ReloadSubCommand implements SubCommand { + @Override + public void onCommand(CommandSenderContainer sender, String[] args) { + } + + @Override + public boolean hasPermission(CommandSenderContainer sender) { + return sender.isOp(); + } + + @Override + public List onTabComplete(CommandSenderContainer sender, String[] args) { + return null; + } + + @Override + public String getBasicHelpText() { + return Lang.translate("command.reload.help"); + } + + @Override + public String getDetailedHelpText() { + return Lang.translate("command.reload.detailedhelp"); + } +} diff --git a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/TransUpdateSubCommand.java b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/TransUpdateSubCommand.java new file mode 100644 index 0000000..ba056db --- /dev/null +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/TransUpdateSubCommand.java @@ -0,0 +1,36 @@ +package com.sekwah.advancedportals.core.commands.subcommands.portal; + +import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.api.commands.SubCommand; +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; + +import java.util.List; + +public class TransUpdateSubCommand implements SubCommand { + @Override + public void onCommand(CommandSenderContainer sender, String[] args) { + AdvancedPortalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", true); + sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("translatedata.replaced")); + } + + @Override + public boolean hasPermission(CommandSenderContainer sender) { + return sender.isOp(); + } + + @Override + public List onTabComplete(CommandSenderContainer sender, String[] args) { + return null; + } + + @Override + public String getBasicHelpText() { + return "This is basic help text"; + } + + @Override + public String getDetailedHelpText() { + return "This help text is a lot more detailed than the basic one"; + } +} diff --git a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java index 6121462..5e766fc 100644 --- a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java @@ -25,11 +25,11 @@ public class VersionSubCommand implements SubCommand { @Override public String getBasicHelpText() { - return "This is basic help text"; + return Lang.translate("command.version.help"); } @Override public String getDetailedHelpText() { - return "This help text is a lot more detailed than the basic one"; + return Lang.translate("command.version.help"); } } diff --git a/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java b/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java index afe6cfd..32b6250 100644 --- a/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java +++ b/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java @@ -5,4 +5,8 @@ import com.sekwah.advancedportals.core.util.Lang; public class CommandSenderContainer { public void sendMessage(String message) { } + + public boolean isOp() { + return false; + } }