mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-07 19:39:47 +01:00
Updating core
This commit is contained in:
commit
64971a7173
@ -15,6 +15,13 @@
|
||||
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=Sorry but you need to specify a sub command, please use \u00Ae/%1$s help \u00Acif you would like a list of possible sub commands.
|
||||
|
||||
command.help.header=\u00Ae--------- \u00Aa%1$s Help - Page %2$s of %3$s\u00Ae ---------------
|
||||
command.help.invalidnum=Sorry but \u00Ae%1$s\u00Ac is not a valid page number.
|
||||
|
||||
command.subcommand.nopermission=Sorry but you don't have permission for that, please use \u00Ae/%1$s help \u00Acif you would like a list of possible sub commands.
|
||||
|
2
TODO.md
2
TODO.md
@ -6,6 +6,8 @@ Tag registration system (Mostly done, just needs to be tested and implemented)
|
||||
|
||||
Portal loading system
|
||||
|
||||
Portal trigger system
|
||||
|
||||
Configs for language files to allow all messages to change
|
||||
|
||||
Destination Command
|
||||
|
@ -1,38 +1,55 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
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 {
|
||||
|
||||
private static AdvancedPortalsCore instance;
|
||||
private DataStorage dataStorage;
|
||||
private InfoLogger infoLogger;
|
||||
private final CommandRegister commandRegister;
|
||||
private final DataStorage dataStorage;
|
||||
private final InfoLogger infoLogger;
|
||||
|
||||
private Config config;
|
||||
|
||||
public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger) {
|
||||
private CommandWithSubCommands portalCommand;
|
||||
private CommandWithSubCommands destiCommand;
|
||||
|
||||
public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger, CommandRegister commandRegister) {
|
||||
this.dataStorage = dataStorage;
|
||||
this.infoLogger = infoLogger;
|
||||
this.instance = this;
|
||||
this.commandRegister = commandRegister;
|
||||
this.onEnable();
|
||||
}
|
||||
|
||||
private void onEnable() {
|
||||
this.loadPortalData();
|
||||
infoLogger.log("Advanced portals have been successfully enabled!");
|
||||
Lang.loadLanguage("en_GB");
|
||||
this.loadPortalConfig();
|
||||
|
||||
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() {
|
||||
|
@ -18,6 +18,8 @@ public interface SubCommand {
|
||||
*/
|
||||
boolean onCommand(CommandSenderContainer sender, String[] args);
|
||||
|
||||
boolean hasPermission(CommandSenderContainer sender);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@ -28,8 +30,13 @@ public interface SubCommand {
|
||||
List<String> 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();
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
|
||||
|
||||
}
|
@ -17,37 +17,35 @@ import java.util.Map;
|
||||
*/
|
||||
public class SubCommandRegistry {
|
||||
|
||||
private Map<String, SubCommand> subCommandMap = new HashMap<>();
|
||||
|
||||
private static final SubCommandRegistry instance = new SubCommandRegistry();
|
||||
protected Map<String, SubCommand> subCommandMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* List of subcommand names which should be in order alphabetically
|
||||
*/
|
||||
private ArrayList<String> subCommands = new ArrayList<>();
|
||||
protected ArrayList<String> 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<String> getSubCommands(){
|
||||
return instance.subCommands;
|
||||
public ArrayList<String> 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;
|
||||
}
|
||||
|
@ -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<String> onTabComplete(CommandHandler sender, String[] args);
|
||||
List<String> onTabComplete(CommandSenderContainer sender, String[] args);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,112 @@
|
||||
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;
|
||||
|
||||
private final int subCommandsPerPage = 5;
|
||||
|
||||
public CommandWithSubCommands() {
|
||||
this.subCommandRegistry = new SubCommandRegistry();
|
||||
}
|
||||
|
||||
public boolean registerSubCommand(String arg, SubCommand subCommand) {
|
||||
return this.subCommandRegistry.registerSubCommand(arg,subCommand);
|
||||
}
|
||||
|
||||
public ArrayList<String> 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")) {
|
||||
int helpPage = 1;
|
||||
String[] subCommands = this.subCommandRegistry.getSubCommands().toArray(new String[0]);
|
||||
int pages = (int) Math.ceil(subCommands.length / (float) this.subCommandsPerPage);
|
||||
if(args.length > 1) {
|
||||
try {
|
||||
helpPage = Integer.parseInt(args[1]);
|
||||
if(helpPage < 0) {
|
||||
helpPage = 1;
|
||||
}
|
||||
else if(helpPage > pages) {
|
||||
helpPage = pages;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.invalidnum", args[1]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.header", commandExecuted, helpPage, pages));
|
||||
int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage;
|
||||
int displayEnd = subCommandOffset + this.subCommandsPerPage;
|
||||
if(displayEnd > subCommands.length) {
|
||||
displayEnd = subCommands.length;
|
||||
}
|
||||
for(; subCommandOffset < displayEnd; subCommandOffset++) {
|
||||
sender.sendMessage("\u00A76/" + commandExecuted + " " + subCommands[subCommandOffset]
|
||||
+ "\u00A7a - " + this.getSubCommand(subCommands[subCommandOffset]).getBasicHelpText());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(String subCommandName : this.subCommandRegistry.getSubCommands()) {
|
||||
if(subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommandName);
|
||||
if(subCommand.hasPermission(sender)) {
|
||||
subCommand.onCommand(sender, args);
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.subcommand.nopermission",
|
||||
commandExecuted));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.noargs", commandExecuted));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 0) {
|
||||
for (String subCommandName : this.subCommandRegistry.getSubCommands()) {
|
||||
if (subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommandName);
|
||||
if(subCommand.hasPermission(sender)) {
|
||||
this.getSubCommand(subCommandName).onTabComplete(sender, args);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return this.subCommandRegistry.getSubCommands();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.sekwah.advancedportals.core.commands;
|
||||
|
||||
public class PortalCommand {
|
||||
}
|
@ -19,6 +19,8 @@ public class Config {
|
||||
|
||||
private String selectionBlock = "STAINED_GLASS";
|
||||
|
||||
private String translationFile = "en_GB";
|
||||
|
||||
private int blockSubID = 14;
|
||||
|
||||
public boolean getUseOnlySpecialAxe() {
|
||||
|
@ -33,7 +33,10 @@ public class DataStorage {
|
||||
}
|
||||
|
||||
public <T> T loadJson(Class<T> dataHolder, String location) {
|
||||
// TODO get json
|
||||
return this.loadJson(dataHolder, location, false);
|
||||
}
|
||||
public <T> T loadJson(Class<T> dataHolder, String location, boolean loadDefaultIfMissing) {
|
||||
// TODO get json and if file doesnt exist create default class if true
|
||||
return gson.fromJson("", dataHolder);
|
||||
}
|
||||
|
||||
|
@ -39,18 +39,18 @@ public class Lang {
|
||||
}
|
||||
}
|
||||
|
||||
public static String translateInsertVariables(String s, String... args) {
|
||||
public static String translateInsertVariables(String s, Object... args) {
|
||||
String translation = instance.translate(s);
|
||||
for (int i = 1; i <= args.length; i++) {
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i]);
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i].toString());
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
||||
public static String translateInsertVariablesColor(String s, String... args) {
|
||||
public static String translateInsertVariablesColor(String s, Object... args) {
|
||||
String translation = instance.translateColor(s);
|
||||
for (int i = 1; i <= args.length; i++) {
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i]);
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i].toString());
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.sekwah.advancedportals.coreconnector.command;
|
||||
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
|
||||
/**
|
||||
* Register the CommandTemplate files to the appropriate system
|
||||
*/
|
||||
public class CommandRegister {
|
||||
|
||||
/**
|
||||
* Registers the command to the appropriate system
|
||||
* @param commandName
|
||||
* @param commandExecutor
|
||||
*/
|
||||
public void registerCommand(String commandName, CommandTemplate commandExecutor) {
|
||||
|
||||
}
|
||||
}
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user