diff --git a/Resources/lang/en_GB.lang b/Resources/lang/en_GB.lang index 2a0188b2..476ba64f 100644 --- a/Resources/lang/en_GB.lang +++ b/Resources/lang/en_GB.lang @@ -15,6 +15,8 @@ messageprefix.positive=\u00Aa[\u00AeAdvancedPortals\u00Aa] messageprefix.negative=\u00Ac[\u00A7AdvancedPortals\u00Ac] -logger.pluginenable=\u00A7aAdvanced portals have been successfully enabled! -logger.plugindisable=\u00A7cAdvanced portals are being disabled! -logger.plugincrafterr=This version of craftbukkit is not yet supported or something went wrong, please post this message with the version number and the above stacktrace in an issue on GitHub v:%1$s +logger.pluginenable=Advanced portals have been successfully enabled! +logger.plugindisable=Advanced portals are being disabled! +logger.plugincrafterror=This version of craftbukkit is not yet supported or something went wrong, please post this message with the version number and the above stacktrace in an issue on GitHub v:%1$s + +command.noargs=%1$s Sorry but you need to specify a sub command, please use \u00Ae/%2$s help \u00Acif 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 2be90475..5947c596 100644 --- a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -1,10 +1,10 @@ package com.sekwah.advancedportals.core; -import com.sekwah.advancedportals.core.commands.DestiCommand; -import com.sekwah.advancedportals.core.commands.PortalCommand; +import com.sekwah.advancedportals.core.commands.CommandWithSubCommands; import com.sekwah.advancedportals.core.util.Config; import com.sekwah.advancedportals.core.util.DataStorage; import com.sekwah.advancedportals.core.util.InfoLogger; +import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.coreconnector.command.CommandRegister; public class AdvancedPortalsCore { @@ -13,8 +13,12 @@ public class AdvancedPortalsCore { private final CommandRegister commandRegister; private final DataStorage dataStorage; private final InfoLogger infoLogger; + private Config config; + private CommandWithSubCommands portalCommand; + private CommandWithSubCommands destiCommand; + public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger, CommandRegister commandRegister) { this.dataStorage = dataStorage; this.infoLogger = infoLogger; @@ -24,23 +28,28 @@ public class AdvancedPortalsCore { } private void onEnable() { - this.loadPortalData(); - infoLogger.log("Advanced portals have been successfully enabled!"); + Lang.loadLanguage("en_GB"); + this.loadPortalConfig(); - this.commandRegister.registerCommand("portal", new PortalCommand()); - this.commandRegister.registerCommand("destination", new DestiCommand()); + this.portalCommand = new CommandWithSubCommands(); + this.destiCommand = new CommandWithSubCommands(); + this.commandRegister.registerCommand("portal", this.portalCommand); + this.commandRegister.registerCommand("destination", this.destiCommand); + + infoLogger.log(Lang.translate("logger.pluginenable")); } /** - * Can be used for in /portal reload as well. + * Loads the portal config into the memory and saves from the memory to check in case certain things have changed + * (basically if values are missing or whatever) */ - private void loadPortalData() { - this.config = this.dataStorage.loadJson(Config.class, "config.json"); + private void loadPortalConfig() { + this.config = this.dataStorage.loadJson(Config.class, "config.json", true); this.dataStorage.storeJson(this.config, "config.json"); } public void onDisable() { - infoLogger.log("Advanced portals are being disabled!"); + infoLogger.log(Lang.translate("logger.plugindisable")); } private static AdvancedPortalsCore getInstance() { diff --git a/src/com/sekwah/advancedportals/core/api/commands/SubCommand.java b/src/com/sekwah/advancedportals/core/api/commands/SubCommand.java index 385b5897..00956ddb 100644 --- a/src/com/sekwah/advancedportals/core/api/commands/SubCommand.java +++ b/src/com/sekwah/advancedportals/core/api/commands/SubCommand.java @@ -28,8 +28,13 @@ public interface SubCommand { List onTabComplete(CommandSenderContainer sender, String[] args); /** - * @return the string to show on the above help menu. (describing the subcommand) + * @return the string to show next to the tag on the help menu. */ - String getHelpText(); + String getBasicHelpText(); + + /** + * @return the string to show if help then the tag is listed. + */ + String getDetailedHelpText(); } diff --git a/src/com/sekwah/advancedportals/core/api/registry/DestinationSubCommandRegistry.java b/src/com/sekwah/advancedportals/core/api/registry/DestinationSubCommandRegistry.java deleted file mode 100644 index 8546a2f1..00000000 --- a/src/com/sekwah/advancedportals/core/api/registry/DestinationSubCommandRegistry.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.sekwah.advancedportals.core.api.registry; - -/** - * Designed to let addons add new command sections to access, edit or add new functonality. - * - * @author sekwah41 - */ -public class DestinationSubCommandRegistry extends SubCommandRegistry { -} diff --git a/src/com/sekwah/advancedportals/core/api/registry/PortalSubCommandRegistry.java b/src/com/sekwah/advancedportals/core/api/registry/PortalSubCommandRegistry.java deleted file mode 100644 index f379f7a6..00000000 --- a/src/com/sekwah/advancedportals/core/api/registry/PortalSubCommandRegistry.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.sekwah.advancedportals.core.api.registry; - -/** - * Designed to let addons add new command sections to access, edit or add new functonality. - * - * @author sekwah41 - */ -public class PortalSubCommandRegistry extends SubCommandRegistry { - - -} diff --git a/src/com/sekwah/advancedportals/core/api/registry/SubCommandRegistry.java b/src/com/sekwah/advancedportals/core/api/registry/SubCommandRegistry.java index b0205aee..e54d1f7d 100644 --- a/src/com/sekwah/advancedportals/core/api/registry/SubCommandRegistry.java +++ b/src/com/sekwah/advancedportals/core/api/registry/SubCommandRegistry.java @@ -17,37 +17,35 @@ import java.util.Map; */ public class SubCommandRegistry { - private Map subCommandMap = new HashMap<>(); - - private static final SubCommandRegistry instance = new SubCommandRegistry(); + protected Map subCommandMap = new HashMap<>(); /** * List of subcommand names which should be in order alphabetically */ - private ArrayList subCommands = new ArrayList<>(); + protected ArrayList subCommands = new ArrayList<>(); /** * @param arg argument needed to activate * @param subCommand * @return if the subcommand is registered or not */ - public static boolean registerSubCommand(String arg, SubCommand subCommand) { + public boolean registerSubCommand(String arg, SubCommand subCommand) { if (subCommand == null) { AdvancedPortalsCore.getInfoLogger().logWarning("The subcommand '" + arg + "' cannot be null."); return false; } - if(!instance.subCommandMap.containsKey(arg)){ + if(!this.subCommandMap.containsKey(arg)){ AdvancedPortalsCore.getInfoLogger().logWarning("The subcommand '" + arg + "' already exists."); return false; } - instance.subCommandMap.put(arg.toLowerCase(), subCommand); + this.subCommandMap.put(arg.toLowerCase(), subCommand); - instance.subCommands.add(arg.toLowerCase()); + this.subCommands.add(arg.toLowerCase()); - Collections.sort(instance.subCommands); + Collections.sort(this.subCommands); return true; } @@ -55,8 +53,8 @@ public class SubCommandRegistry { /** * @return a list of arguments of registered subcommands */ - public static ArrayList getSubCommands(){ - return instance.subCommands; + public ArrayList getSubCommands(){ + return this.subCommands; } /** @@ -66,8 +64,8 @@ public class SubCommandRegistry { * @param arg * @return if the argument is registered */ - public static boolean isArgRegistered(String arg){ - return instance.subCommandMap.containsKey(arg.toLowerCase()); + public boolean isArgRegistered(String arg){ + return this.subCommandMap.containsKey(arg.toLowerCase()); } /** @@ -75,9 +73,9 @@ public class SubCommandRegistry { * @param arg * @return the subcommand linked to the arg */ - public static SubCommand getSubCommand(String arg){ - if(instance.subCommandMap.containsKey(arg.toLowerCase())){ - return instance.subCommandMap.get(arg.toLowerCase()); + public SubCommand getSubCommand(String arg){ + if(this.subCommandMap.containsKey(arg.toLowerCase())){ + return this.subCommandMap.get(arg.toLowerCase()); } return null; } diff --git a/src/com/sekwah/advancedportals/core/commands/CommandTemplate.java b/src/com/sekwah/advancedportals/core/commands/CommandTemplate.java index 1d5c2bdd..7ccf62ad 100644 --- a/src/com/sekwah/advancedportals/core/commands/CommandTemplate.java +++ b/src/com/sekwah/advancedportals/core/commands/CommandTemplate.java @@ -1,6 +1,6 @@ package com.sekwah.advancedportals.core.commands; -import com.sun.corba.se.impl.activation.CommandHandler; +import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; import java.util.List; @@ -11,7 +11,7 @@ import java.util.List; */ public interface CommandTemplate { - void onCommand(CommandHandler sender, String[] args); + void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args); /** * Fired when someone asks for a tab complete action. @@ -19,6 +19,6 @@ public interface CommandTemplate { * @param args * @return */ - List onTabComplete(CommandHandler sender, String[] args); + List onTabComplete(CommandSenderContainer sender, String[] args); } diff --git a/src/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java b/src/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java new file mode 100644 index 00000000..0a556e15 --- /dev/null +++ b/src/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java @@ -0,0 +1,55 @@ +package com.sekwah.advancedportals.core.commands; + +import com.sekwah.advancedportals.core.api.commands.SubCommand; +import com.sekwah.advancedportals.core.api.registry.SubCommandRegistry; +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; + +import java.util.ArrayList; +import java.util.List; + +public class CommandWithSubCommands implements CommandTemplate { + + private final SubCommandRegistry subCommandRegistry; + + public CommandWithSubCommands() { + this.subCommandRegistry = new SubCommandRegistry(); + } + + public boolean registerSubCommand(String arg, SubCommand subCommand) { + return this.subCommandRegistry.registerSubCommand(arg,subCommand); + } + + public ArrayList getSubCommands(){ + return this.subCommandRegistry.getSubCommands(); + } + + public boolean isArgRegistered(String arg){ + return this.subCommandRegistry.isArgRegistered(arg); + } + + public SubCommand getSubCommand(String arg){ + return this.subCommandRegistry.getSubCommand(arg); + } + + + @Override + public void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args) { + if(args.length > 0) { + if(args[0].equalsIgnoreCase("help")) { + // TODO do help menu here sorted alphabetically + } + else { + + } + } + else { + sender.sendMessage(Lang.translateInsertVariablesColor(Lang.translate("command.noargs"), Lang.translate("messageprefix.negative"), commandExecuted)); + } + } + + @Override + public List onTabComplete(CommandSenderContainer sender, String[] args) { + return null; + } +} diff --git a/src/com/sekwah/advancedportals/core/commands/DestiCommand.java b/src/com/sekwah/advancedportals/core/commands/DestiCommand.java deleted file mode 100644 index e0197a1a..00000000 --- a/src/com/sekwah/advancedportals/core/commands/DestiCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.sekwah.advancedportals.core.commands; - -import com.sun.corba.se.impl.activation.CommandHandler; - -import java.util.List; - -public class DestiCommand implements CommandTemplate { - - @Override - public void onCommand(CommandHandler sender, String[] args) { - - } - - @Override - public List onTabComplete(CommandHandler sender, String[] args) { - return null; - } -} diff --git a/src/com/sekwah/advancedportals/core/commands/PortalCommand.java b/src/com/sekwah/advancedportals/core/commands/PortalCommand.java deleted file mode 100644 index d02c2058..00000000 --- a/src/com/sekwah/advancedportals/core/commands/PortalCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.sekwah.advancedportals.core.commands; - -import com.sun.corba.se.impl.activation.CommandHandler; - -import java.util.List; - -public class PortalCommand implements CommandTemplate { - - @Override - public void onCommand(CommandHandler sender, String[] args) { - - } - - @Override - public List onTabComplete(CommandHandler sender, String[] args) { - return null; - } -} diff --git a/src/com/sekwah/advancedportals/core/util/Config.java b/src/com/sekwah/advancedportals/core/util/Config.java index 76ad5b59..75930969 100644 --- a/src/com/sekwah/advancedportals/core/util/Config.java +++ b/src/com/sekwah/advancedportals/core/util/Config.java @@ -19,6 +19,8 @@ public class Config { private String selectionBlock = "STAINED_GLASS"; + private String translationFile = "en_GB"; + private int blockSubID = 14; public boolean getUseOnlySpecialAxe() { diff --git a/src/com/sekwah/advancedportals/core/util/DataStorage.java b/src/com/sekwah/advancedportals/core/util/DataStorage.java index 822b351e..1e5e19df 100644 --- a/src/com/sekwah/advancedportals/core/util/DataStorage.java +++ b/src/com/sekwah/advancedportals/core/util/DataStorage.java @@ -33,7 +33,10 @@ public class DataStorage { } public T loadJson(Class dataHolder, String location) { - // TODO get json + return this.loadJson(dataHolder, location, false); + } + public T loadJson(Class dataHolder, String location, boolean loadDefaultIfMissing) { + // TODO get json and if file doesnt exist create default class if true return gson.fromJson("", dataHolder); } diff --git a/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java b/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java index b31dde26..feeaf6f5 100644 --- a/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java +++ b/src/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java @@ -1,7 +1,6 @@ package com.sekwah.advancedportals.coreconnector.command; import com.sekwah.advancedportals.core.commands.CommandTemplate; -import com.sekwah.advancedportals.core.commands.PortalCommand; /** * Register the CommandTemplate files to the appropriate system diff --git a/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java b/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java index b4b037a9..afe6cfd8 100644 --- a/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java +++ b/src/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java @@ -1,4 +1,8 @@ package com.sekwah.advancedportals.coreconnector.container; +import com.sekwah.advancedportals.core.util.Lang; + public class CommandSenderContainer { + public void sendMessage(String message) { + } }