feat: add portal and desti commands

This commit is contained in:
Sekwah 2023-04-07 02:05:03 +01:00
parent d7e6df2556
commit 154919f780
20 changed files with 1027 additions and 11 deletions

View File

@ -1,5 +1,11 @@
package com.sekwah.advancedportals.core;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
import com.sekwah.advancedportals.core.commands.subcommands.desti.CreateDestiSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
import com.sekwah.advancedportals.core.data.DataStorage;
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
@ -11,35 +17,88 @@ import java.io.File;
public class AdvancedPortalsCore {
public static final String version = "1.0.0";
private final InfoLogger infoLogger;
private final DataStorage dataStorage;
private final AdvancedPortalsModule module;
private final ConfigRepository configRepository;
@Inject
private CommandRegister commandRegister;
private CommandWithSubCommands portalCommand;
private CommandWithSubCommands destiCommand;
@Inject
private ConfigRepository configRepository;
public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger) {
this.dataStorage = new DataStorage(dataStorageLoc);
this.infoLogger = infoLogger;
this.module = new AdvancedPortalsModule(this);
this.configRepository = module.getInjector().getInstance(ConfigRepository.class);
// Provide any items that need to be provided.
//this.module.addInstanceBinding(DataCollector.class, this.infoLogger);
// Force values to get injected, either because the initial ones were created too early or to ensure they are not null.
module.getInjector().injectMembers(Lang.instance);
// Don't do much crazy setup here, keep it to onEnable as that will be once the implementation is set up.
}
/**
* For some platforms we could do this on construction but this just allows for a bit more control
*/
public void onEnable() {
// Force values to get injected, either because the initial ones were created too early or to ensure they are not null.
// Do it here to give implementations a chance to interact with the module.
Injector injector = module.getInjector();
injector.injectMembers(this);
injector.injectMembers(Lang.instance);
//AdvancedPortalsModule module = new AdvancedPortalsModule(this);
this.dataStorage.copyDefaultFile("lang/en_GB.lang", false);
this.loadPortalConfig();
Lang.loadLanguage(configRepository.getTranslation());
this.registerCommands();
this.infoLogger.log(Lang.translate("logger.pluginenable"));
}
/**
*
*/
public void registerCommands() {
this.registerPortalCommand(commandRegister);
this.registerDestinationCommand(commandRegister);
// TODO run annotation grabbing shit
}
private void registerPortalCommand(CommandRegister commandRegister) {
this.portalCommand = new CommandWithSubCommands();
// TODO remove once annotations are done
this.portalCommand.registerSubCommand("version", new VersionSubCommand());
this.portalCommand.registerSubCommand("langupdate", new LangUpdateSubCommand());
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand());
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand");
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand());
this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand());
this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand());
this.portalCommand.registerSubCommand("create", new CreatePortalSubCommand());
this.portalCommand.registerSubCommand("remove", new RemoveSubCommand());
commandRegister.registerCommand("portal", this.portalCommand);
}
private void registerDestinationCommand(CommandRegister commandRegister) {
this.destiCommand = new CommandWithSubCommands();
// TODO remove once annotations are done
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
commandRegister.registerCommand("destination", this.destiCommand);
}
/**
* 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)
@ -60,4 +119,8 @@ public class AdvancedPortalsCore {
public DataStorage getDataStorage() {
return this.dataStorage;
}
public AdvancedPortalsModule getModule() {
return this.module;
}
}

View File

@ -0,0 +1,156 @@
package com.sekwah.advancedportals.core.commands;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.registry.SubCommandRegistry;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CommandWithSubCommands implements CommandTemplate {
private final SubCommandRegistry subCommandRegistry;
private final int subCommandsPerPage = 7;
public CommandWithSubCommands() {
this.subCommandRegistry = new SubCommandRegistry();
}
public boolean registerSubCommand(String arg, SubCommand subCommand, String... aliasArgs) {
boolean hasRegistered = false;
for(String additionalArg : aliasArgs) {
hasRegistered = hasRegistered || this.subCommandRegistry.registerSubCommand(additionalArg,subCommand);
}
return hasRegistered || 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 > pages) {
helpPage = pages;
}
if(helpPage <= 0) {
helpPage = 1;
}
}
catch(NumberFormatException e) {
String subCommand = args[1].toLowerCase();
if(this.subCommandRegistry.isArgRegistered(subCommand)) {
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.subcommandheader",
commandExecuted.substring(0,1).toUpperCase() + commandExecuted.substring(1).toLowerCase(), subCommand));
sender.sendMessage("\u00A77" + this.getSubCommand(subCommand).getDetailedHelpText());
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.help.invalidhelp", args[1]));
}
return;
}
}
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.header",
commandExecuted.substring(0,1).toUpperCase() + commandExecuted.substring(1).toLowerCase(), helpPage, pages));
sender.sendMessage("\u00A7a█\u00A77 = Permission \u00A7c█\u00A77 = No Permission");
int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage;
int displayEnd = subCommandOffset + this.subCommandsPerPage;
if(displayEnd > subCommands.length) {
displayEnd = subCommands.length;
}
for(; subCommandOffset < displayEnd; subCommandOffset++) {
SubCommand subCommand = this.getSubCommand(subCommands[subCommandOffset]);
String colorCode = "\u00A7" + (subCommand.hasPermission(sender) ? "a" : "c");
sender.sendMessage("\u00A7e/" + commandExecuted + " " + subCommands[subCommandOffset]
+ colorCode + " - " + subCommand.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;
}
}
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.subcommand.invalid"));
}
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.noargs", commandExecuted));
}
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
if(args[0].equalsIgnoreCase("help")) {
List<String> allowedCommands = new ArrayList<>(this.subCommandRegistry.getSubCommands());
Collections.sort(allowedCommands);
return this.filterTabResults(allowedCommands, args[args.length - 1]);
}
else {
for (String subCommandName : this.subCommandRegistry.getSubCommands()) {
if (subCommandName.equalsIgnoreCase(args[0])) {
SubCommand subCommand = this.getSubCommand(subCommandName);
if (subCommand.hasPermission(sender)) {
return this.filterTabResults(this.getSubCommand(subCommandName).onTabComplete(sender, args),
args[args.length - 1]);
} else {
return null;
}
}
}
}
}
else {
List<String> allowedCommands = new ArrayList<>();
for (String subCommandName : this.subCommandRegistry.getSubCommands()) {
SubCommand subCommand = this.getSubCommand(subCommandName);
if(subCommand.hasPermission(sender)) {
allowedCommands.add(subCommandName);
}
}
allowedCommands.add("help");
Collections.sort(allowedCommands);
return this.filterTabResults(allowedCommands, args[0]);
}
return null;
}
public List<String> filterTabResults(List<String> tabList, String lastArg) {
if(tabList == null) {
return null;
}
for(String arg : tabList.toArray(new String[0])) {
if(!arg.startsWith(lastArg.toLowerCase())) {
tabList.remove(arg);
}
}
return tabList;
}
}

View File

@ -0,0 +1,69 @@
package com.sekwah.advancedportals.core.commands.subcommands.desti;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
import java.util.ArrayList;
import java.util.List;
public class CreateDestiSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.createdesti.console"));
return;
}
ArrayList<DataTag> destiTags = TagReader.getTagsFromArgs(args);
// TODO sort desti service
/*Destination desti = AdvancedPortalsCore.getDestinationServices().createDesti(args[1], player, player.getLoc(), destiTags);
if(desti != null) {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.createdesti.complete"));
sender.sendMessage(Lang.translateColor("command.create.tags"));
ArrayList<DataTag> destiArgs = desti.getArgs();
if(destiArgs.size() == 0) {
sender.sendMessage(Lang.translateColor("desti.info.noargs"));
}
else {
for (DataTag tag : destiArgs) {
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
}
}
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.createdesti.error"));
}*/
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.error.noname"));
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.createdesti.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.createdesti.detailedhelp");
}
}

View File

@ -0,0 +1,64 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CreatePortalSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
return;
}
ArrayList<DataTag> portalTags = TagReader.getTagsFromArgs(args);
// TODO sort portal services
/*AdvancedPortal portal = AdvancedPortalsCore.getPortalServices().createPortal(args[1], player, portalTags);
if(portal != null) {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.create.complete"));
sender.sendMessage(Lang.translateColor("command.create.tags"));
sender.sendMessage("\u00A7a" + "triggerBlock\u00A77:\u00A7e" + Arrays.toString(portal.getTriggerBlocks()));
for (DataTag tag: portal.getArgs()) {
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
}
}*/
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error"));
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.error.noname"));
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.create.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.create.detailedhelp");
}
}

View File

@ -0,0 +1,51 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
public class EndGatewayBlockSubCommand implements SubCommand {
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveWool("BLACK", "\u00A78Gateway Block Placer"
, "\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.gatewayblock"));
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.selector.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.selector.detailedhelp");
}
}

View File

@ -0,0 +1,51 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
public class EndPortalBlockSubCommand implements SubCommand {
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveWool("BLACK", "\u00A78End Portal Block Placer"
, "\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.endportalblock"));
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.selector.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.selector.detailedhelp");
}
}

View File

@ -0,0 +1,44 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
public class LangUpdateSubCommand implements SubCommand {
@Inject
private AdvancedPortalsCore portalsCore;
public LangUpdateSubCommand() {
}
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
this.portalsCore.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() || sender.hasPermission("advancedportals.transupdate");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.trans.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.trans.help");
}
}

View File

@ -0,0 +1,53 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
public class PortalBlockSubCommand implements SubCommand {
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveWool("PURPLE", "\u00A75Portal Block Placer"
, "\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block",
"\u00A7rLeft Click: Rotate portal block");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.portalblock"));
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.selector.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.selector.detailedhelp");
}
}

View File

@ -0,0 +1,44 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
public class ReloadSubCommand implements SubCommand {
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
portalsCore.loadPortalConfig();
// TODO re-add or figure out a replacement.
//portalsCore.getPortalServices().loadPortals();
//portalsCore.getDestinationServices().loadDestinations();
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.reload");
}
@Override
public List<String> 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");
}
}

View File

@ -0,0 +1,72 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class RemoveSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
// TODO sort portal services
/*if(AdvancedPortalsCore.getPortalServices().removePortal(args[1], sender.getPlayerContainer())) {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.remove.complete"));
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative")
+ Lang.translateColor("command.remove.error"));
}*/
}
else {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translate("command.remove.noname"));
}
else {
// TODO sort portal services
/*if(AdvancedPortalsCore.getPortalServices().removePlayerSelection(player)) {
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative")
+ Lang.translateColor("command.remove.error"));
}*/
}
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
List<String> portalNames = new ArrayList<>();
// TODO sort portal services
/*for(Map.Entry<String, AdvancedPortal> portal : AdvancedPortalsCore.getPortalServices().getPortals()) {
portalNames.add(portal.getKey());
}
Collections.sort(portalNames);*/
return portalNames;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.create.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.create.detailedhelp");
}
}

View File

@ -0,0 +1,54 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
public class SelectorSubCommand implements SubCommand {
@Inject
private ConfigRepository configRepo;
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveItem(configRepo.getSelectorMaterial(), "\u00A7ePortal Region Selector"
, "\u00A7rThis wand with has the power to help", "\u00A7r create portals bistowed upon it!");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.selector"));
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.selector.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.selector.detailedhelp");
}
}

View File

@ -0,0 +1,36 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
public class VersionSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + " Advanced Portals v" + AdvancedPortalsCore.version);
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return true;
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.version.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.version.help");
}
}

View File

@ -10,6 +10,8 @@ import com.sekwah.advancedportals.core.repository.ConfigRepositoryImpl;
import com.sekwah.advancedportals.core.util.InfoLogger;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
public class AdvancedPortalsModule extends AbstractModule {
@ -17,11 +19,15 @@ public class AdvancedPortalsModule extends AbstractModule {
private Injector injector;
private AdvancedPortalsCore advancedPortalsCore;
private List<DelayedBinding> delayedBindings = new ArrayList<>();
public AdvancedPortalsModule(AdvancedPortalsCore advancedPortalsCore) {
this.advancedPortalsCore = advancedPortalsCore;
createInjector();
}
/**
* https://github.com/google/guice/wiki/Bindings
*/
@Override
protected void configure() {
// Instances
@ -32,17 +38,34 @@ public class AdvancedPortalsModule extends AbstractModule {
// Providers
bind(Config.class).toProvider(ConfigProvider.class);
// Delayed Bindings
for(DelayedBinding delayedBinding : delayedBindings) {
bind(delayedBinding.clazz).toInstance(delayedBinding.instance);
}
}
public Injector createInjector() {
// TODO change it so that it'll set these up during the injector.
public <T> void addInstanceBinding(Class<T> clazz, T instance) {
delayedBindings.add(new DelayedBinding<>(clazz, instance));
}
class DelayedBinding<T> {
private final T instance;
private final Class<T> clazz;
public DelayedBinding(Class<T> clazz, T instance) {
this.clazz = clazz;
this.instance = instance;
}
}
// Call this later than the calls to addInstanceBinding
@Nonnull
public Injector getInjector() {
if(injector == null) {
injector = Guice.createInjector(this);
}
return injector;
}
@Nonnull
public Injector getInjector() {
return injector;
}
}

View File

@ -18,6 +18,7 @@ dependencies {
// For spigot api
implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT"
implementation "net.md-5:bungeecord-api:1.16-R0.4"
implementation group: 'com.google.inject', name: 'guice', version:'5.0.1'
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
}

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.spigot;
import com.google.inject.Injector;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.util.DataStorage;
import com.sekwah.advancedportals.coreconnector.ConnectorDataCollector;

View File

@ -0,0 +1,30 @@
package com.sekwah.advancedportals.spigot.connector.command;
import com.sekwah.advancedportals.core.commands.CommandTemplate;
import com.sekwah.advancedportals.spigot.connector.container.SpigotCommandSenderContainer;
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 SpigotCommandHandler implements CommandExecutor, TabCompleter {
private final CommandTemplate commandExecutor;
public SpigotCommandHandler(CommandTemplate commandExecutor) {
this.commandExecutor = commandExecutor;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
this.commandExecutor.onCommand(new SpigotCommandSenderContainer(commandSender), command.getName(), args);
return true;
}
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
return this.commandExecutor.onTabComplete(new SpigotCommandSenderContainer(commandSender), args);
}
}

View File

@ -0,0 +1,26 @@
package com.sekwah.advancedportals.spigot.connector.command;
import com.sekwah.advancedportals.core.commands.CommandTemplate;
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
/**
* Register the CommandTemplate files to the appropriate system
*/
public class SpigotCommandRegister implements CommandRegister {
private final AdvancedPortalsPlugin plugin;
public SpigotCommandRegister(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 SpigotCommandHandler(commandExecutor));
}
}

View File

@ -0,0 +1,36 @@
package com.sekwah.advancedportals.spigot.connector.container;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SpigotCommandSenderContainer implements CommandSenderContainer {
private final CommandSender sender;
public SpigotCommandSenderContainer(CommandSender commandSender) {
this.sender = commandSender;
}
public void sendMessage(String message) {
sender.sendMessage(message);
}
public boolean isOp() {
return sender.isOp();
}
/**
* @return null if there isnt a player e.g. the console
*/
public SpigotPlayerContainer getPlayerContainer() {
if (sender instanceof Player) {
return new SpigotPlayerContainer((Player) sender);
}
return null;
}
public boolean hasPermission(String permission) {
return sender.hasPermission(permission);
}
}

View File

@ -0,0 +1,103 @@
package com.sekwah.advancedportals.spigot.connector.container;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
import com.sekwah.advancedportals.core.data.BlockLocation;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool;
import java.util.Arrays;
import java.util.UUID;
/**
* Just a temporary container for whenever advanced portals needs to get data from a player
*/
public class SpigotPlayerContainer implements PlayerContainer {
@Inject
private AdvancedPortalsCore portalsCore;
private final Player player;
public SpigotPlayerContainer(Player player) {
this.player = player;
}
public UUID getUUID() {
return player.getUniqueId();
}
public void sendMessage(String message) {
player.sendMessage(message);
}
public boolean isOp() {
return this.player.isOp();
}
public PlayerLocation getLoc() {
Location loc = this.player.getLocation();
return new PlayerLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ());
}
public double getEyeHeight() {
return 0;
}
public void teleport(PlayerLocation location) {
this.player.teleport(new Location(Bukkit.getWorld(location.getWorldName()), location.getPosX(), location.getPosY(), location.getPosZ()));
}
public boolean hasPermission(String permission) {
return this.player.hasPermission(permission);
}
public WorldContainer getWorld() {
return new SpigotWorldContainer(this.player.getWorld());
}
/**
* @param blockPos
* @param material
*/
public void sendFakeBlock(BlockLocation blockPos, String material) {
}
/**
* Only 1.12 and below supported
* @param blockPos
* @param material
* @param data
*/
public void sendFakeBlockWithData(BlockLocation blockPos, String material, byte data) {
}
public void giveWool(String dyeColor, String itemName, String... itemDescription) {
ItemStack regionselector = new Wool(DyeColor.valueOf(dyeColor)).toItemStack(1);
ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName(itemName);
selectorname.setLore(Arrays.asList(itemDescription));
regionselector.setItemMeta(selectorname);
this.player.getInventory().addItem(regionselector);
}
public void giveItem(String material, String itemName, String... itemDescription) {
ItemStack regionselector = new ItemStack(Material.getMaterial(material));
ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName(itemName);
selectorname.setLore(Arrays.asList(itemDescription));
regionselector.setItemMeta(selectorname);
this.player.getInventory().addItem(regionselector);
}
}

View File

@ -0,0 +1,39 @@
package com.sekwah.advancedportals.spigot.connector.container;
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
import com.sekwah.advancedportals.core.data.BlockLocation;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.material.Directional;
import org.bukkit.material.MaterialData;
public class SpigotWorldContainer implements WorldContainer {
private final World world;
public SpigotWorldContainer(World world) {
this.world = world;
}
public void setBlock(BlockLocation location, String material) {
this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(Material.getMaterial(material));
}
public void setBlockData(BlockLocation location, byte data) {
MaterialData matData = world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData();
if(matData instanceof Directional) {
Directional dir = (Directional) world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData();
dir.setFacingDirection(BlockFace.NORTH);
}
}
public String getBlock(BlockLocation location) {
return this.world.getBlockAt(location.posX, location.posY, location.posZ).getType().toString();
}
public byte getBlockData(BlockLocation location) {
return 0;
}
}