From d51b6dbcdb23effe0720f5b5b42a475169ef5c0e Mon Sep 17 00:00:00 2001 From: Sekwah Date: Tue, 12 Dec 2023 03:53:37 +0000 Subject: [PATCH] feat: add show desti command --- .../core/AdvancedPortalsCore.java | 56 ++++++++-- .../CreateTaggedSubCommand.java | 10 +- .../desti/CreateDestiSubCommand.java | 2 +- .../desti/ListDestiSubCommand.java | 4 +- .../desti/ReloadDestiSubCommand.java | 48 ++++++++ .../desti/RemoveDestiSubCommand.java | 8 +- .../desti/ShowDestiSubCommand.java | 100 +++++++++++++++++ .../portal/CreatePortalSubCommand.java | 5 +- ...mmand.java => ReloadPortalSubCommand.java} | 2 +- .../portal/ShowPortalSubCommand.java | 105 +++++++++++------- .../connector/containers/ServerContainer.java | 8 ++ .../core/destination/Destination.java | 8 ++ .../core/module/AdvancedPortalsModule.java | 2 + .../core/repository/ConfigRepository.java | 2 + .../repository/IDestinationRepository.java | 2 +- .../core/repository/IJsonRepository.java | 7 +- .../repository/impl/ConfigRepositoryImpl.java | 4 + .../impl/DestinationRepositoryImpl.java | 21 ++-- .../repository/impl/PortalRepositoryImpl.java | 7 +- .../core/serializeddata/BlockLocation.java | 11 ++ .../core/serializeddata/DataStorage.java | 16 ++- .../core/serializeddata/PlayerTempData.java | 26 +++++ .../core/serializeddata/WorldLocation.java | 15 +++ .../core/serializeddata/config/Config.java | 2 + .../core/services/DestinationServices.java | 70 ++++++------ .../core/services/Response.java | 10 -- .../core/tags/activation/DestiTag.java | 2 +- .../advancedportals/core/util/Response.java | 13 +++ lang/src/main/resources/lang/en_GB.lang | 13 +++ .../spigot/AdvancedPortalsPlugin.java | 13 ++- .../container/SpigotServerContainer.java | 54 +++++++++ 31 files changed, 503 insertions(+), 143 deletions(-) rename core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/{reusable => common}/CreateTaggedSubCommand.java (90%) create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ReloadDestiSubCommand.java create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java rename core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/{ReloadSubCommand.java => ReloadPortalSubCommand.java} (96%) delete mode 100644 core/src/main/java/com/sekwah/advancedportals/core/services/Response.java create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/util/Response.java create mode 100644 spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java diff --git a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index a612fbc..e1e52be 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -3,15 +3,15 @@ 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.desti.ListDestiSubCommand; -import com.sekwah.advancedportals.core.commands.subcommands.desti.RemoveDestiSubCommand; +import com.sekwah.advancedportals.core.commands.subcommands.desti.*; import com.sekwah.advancedportals.core.commands.subcommands.portal.*; import com.sekwah.advancedportals.core.connector.commands.CommandRegister; +import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.module.AdvancedPortalsModule; import com.sekwah.advancedportals.core.repository.ConfigRepository; +import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.tags.activation.DestiTag; import com.sekwah.advancedportals.core.tags.activation.NameTag; import com.sekwah.advancedportals.core.util.GameScheduler; @@ -19,19 +19,26 @@ import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; import java.io.File; +import java.util.Arrays; public class AdvancedPortalsCore { public static final String version = "1.0.0"; - public static final String lastTranslationUpdate = "1.0.0"; - private final InfoLogger infoLogger; private final DataStorage dataStorage; private final AdvancedPortalsModule module; + /** + * Use this to enable or alter certain features for different versions. + * If there is an issue parsing it for any reason it will be set to 0.0.0 + */ + private final int[] mcVersion; + + private final ServerContainer serverContainer; + @Inject private CommandRegister commandRegister; @@ -44,18 +51,32 @@ public class AdvancedPortalsCore { @Inject private TagRegistry tagRegistry; + @Inject + private DestinationServices destinationServices; + @Inject private GameScheduler gameScheduler; - public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger) { + public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, InfoLogger infoLogger, ServerContainer serverContainer) { + this.serverContainer = serverContainer; this.dataStorage = new DataStorage(dataStorageLoc); this.infoLogger = infoLogger; + + int[] mcVersionTemp; + infoLogger.log("Loading Advanced Portals Core v" + version + " for MC: " + mcVersion); + try { + mcVersionTemp = Arrays.stream(mcVersion.split("\\.")).mapToInt(Integer::parseInt).toArray(); + } catch (NumberFormatException e) { + infoLogger.log("Failed to parse MC version: " + mcVersion); + e.printStackTrace(); + mcVersionTemp = new int[]{0, 0, 0}; + } + if(mcVersionTemp.length == 2) { + mcVersionTemp = new int[]{mcVersionTemp[0], mcVersionTemp[1], 0}; + } + this.mcVersion = mcVersionTemp; + this.module = new AdvancedPortalsModule(this); - - // Provide any items that need to be provided. - //this.module.addInstanceBinding(DataCollector.class, this.infoLogger); - - // Don't do much crazy setup here, keep it to onEnable as that will be once the implementation is set up. } /** @@ -76,6 +97,7 @@ public class AdvancedPortalsCore { this.registerCommands(); this.registerTags(); + this.destinationServices.loadDestinations(); this.infoLogger.log(Lang.translate("logger.pluginenable")); } @@ -97,7 +119,7 @@ public class AdvancedPortalsCore { this.portalCommand.registerSubCommand("version", new VersionSubCommand()); this.portalCommand.registerSubCommand("langupdate", new LangUpdateSubCommand()); - this.portalCommand.registerSubCommand("reload", new ReloadSubCommand()); + this.portalCommand.registerSubCommand("reload", new ReloadPortalSubCommand()); this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand"); this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand()); this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand()); @@ -115,6 +137,8 @@ public class AdvancedPortalsCore { this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand()); this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand()); this.destiCommand.registerSubCommand("list", new ListDestiSubCommand()); + this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand()); + this.destiCommand.registerSubCommand("reload", new ReloadDestiSubCommand()); commandRegister.registerCommand("destination", this.destiCommand); } @@ -151,4 +175,12 @@ public class AdvancedPortalsCore { public GameScheduler getGameScheduler() { return gameScheduler; } + + public int[] getMcVersion() { + return mcVersion; + } + + public ServerContainer getServerContainer() { + return serverContainer; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/reusable/CreateTaggedSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java similarity index 90% rename from core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/reusable/CreateTaggedSubCommand.java rename to core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java index 559e259..010845e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/reusable/CreateTaggedSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java @@ -1,16 +1,8 @@ -package com.sekwah.advancedportals.core.commands.subcommands.reusable; +package com.sekwah.advancedportals.core.commands.subcommands.common; -import com.google.inject.Inject; 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.permissions.PortalPermissions; -import com.sekwah.advancedportals.core.portal.AdvancedPortal; -import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.serializeddata.DataTag; -import com.sekwah.advancedportals.core.services.PortalServices; -import com.sekwah.advancedportals.core.util.InfoLogger; -import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java index 8379832..c812b59 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java @@ -1,7 +1,7 @@ package com.sekwah.advancedportals.core.commands.subcommands.desti; import com.google.inject.Inject; -import com.sekwah.advancedportals.core.commands.subcommands.reusable.CreateTaggedSubCommand; +import com.sekwah.advancedportals.core.commands.subcommands.common.CreateTaggedSubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.destination.Destination; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java index e1de420..350b16b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java @@ -4,11 +4,9 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.services.DestinationServices; -import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; public class ListDestiSubCommand implements SubCommand { @@ -19,7 +17,7 @@ public class ListDestiSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.list") - + " " + portalServices.getDestinations().stream().sorted().collect(Collectors.joining(", "))); + + " " + portalServices.getDestinationNames().stream().sorted().collect(Collectors.joining(", "))); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ReloadDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ReloadDestiSubCommand.java new file mode 100644 index 0000000..3f93620 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ReloadDestiSubCommand.java @@ -0,0 +1,48 @@ +package com.sekwah.advancedportals.core.commands.subcommands.desti; + +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.connector.containers.ServerContainer; +import com.sekwah.advancedportals.core.services.DestinationServices; +import com.sekwah.advancedportals.core.services.PortalTempDataServices; +import com.sekwah.advancedportals.core.util.GameScheduler; +import com.sekwah.advancedportals.core.util.Lang; + +import java.util.List; + +/** + * This will be different from the old show command and I believe it is 1.16+ till the latest version as of writing this. + */ +public class ReloadDestiSubCommand implements SubCommand { + + @Inject + DestinationServices destinationServices; + + @Override + public void onCommand(CommandSenderContainer sender, String[] args) { + sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.reload")); + } + + @Override + public boolean hasPermission(CommandSenderContainer sender) { + return true; + } + + @Override + public List onTabComplete(CommandSenderContainer sender, String[] args) { + return null; + } + + @Override + public String getBasicHelpText() { + return Lang.translate("command.destination.reload.help"); + } + + @Override + public String getDetailedHelpText() { + return Lang.translate("command.destination.reload.detailedhelp"); + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java index 905fcec..a7e03b6 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java @@ -3,16 +3,12 @@ package com.sekwah.advancedportals.core.commands.subcommands.desti; import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; -import com.sekwah.advancedportals.core.destination.Destination; import com.sekwah.advancedportals.core.permissions.PortalPermissions; -import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.services.DestinationServices; 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 RemoveDestiSubCommand implements SubCommand { @@ -23,7 +19,7 @@ public class RemoveDestiSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { if(args.length > 1) { - if(destinationServices.removeDesti(args[1], sender.getPlayerContainer())) { + if(destinationServices.removeDestination(args[1], sender.getPlayerContainer())) { sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.portal.remove.complete")); } else { @@ -46,7 +42,7 @@ public class RemoveDestiSubCommand implements SubCommand { if(args.length > 2) { return Collections.emptyList(); } - List destiNames = destinationServices.getDestinations(); + List destiNames = destinationServices.getDestinationNames(); Collections.sort(destiNames); return destiNames; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java new file mode 100644 index 0000000..f5bc361 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java @@ -0,0 +1,100 @@ +package com.sekwah.advancedportals.core.commands.subcommands.desti; + +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.connector.containers.ServerContainer; +import com.sekwah.advancedportals.core.destination.Destination; +import com.sekwah.advancedportals.core.repository.ConfigRepository; +import com.sekwah.advancedportals.core.services.DestinationServices; +import com.sekwah.advancedportals.core.services.PortalTempDataServices; +import com.sekwah.advancedportals.core.tags.activation.NameTag; +import com.sekwah.advancedportals.core.util.Debug; +import com.sekwah.advancedportals.core.util.GameScheduler; +import com.sekwah.advancedportals.core.util.Lang; + +import java.awt.*; +import java.util.List; + +/** + * This will be different from the old show command and I believe it is 1.16+ till the latest version as of writing this. + */ +public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnInit { + + @Inject + PortalTempDataServices tempDataServices; + + @Inject + GameScheduler gameScheduler; + + @Inject + AdvancedPortalsCore core; + + @Inject + DestinationServices destinationServices; + + @Inject + ServerContainer serverContainer; + + @Inject + ConfigRepository config; + + @Override + public void onCommand(CommandSenderContainer sender, String[] args) { + if(core.getMcVersion()[1] < 16) { + sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.portal.show.unsupported")); + return; + } + + var tempData = tempDataServices.getPlayerTempData(sender.getPlayerContainer()); + if(tempData.isDestiVisible()) { + sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.destination.show.disabled")); + } else { + sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.show.enabled")); + } + tempData.setDestiVisible(!tempData.isDestiVisible()); + } + + @Override + public boolean hasPermission(CommandSenderContainer sender) { + return true; + } + + @Override + public List onTabComplete(CommandSenderContainer sender, String[] args) { + return null; + } + + @Override + public String getBasicHelpText() { + return Lang.translate("command.destination.show.help"); + } + + @Override + public String getDetailedHelpText() { + return Lang.translate("command.destination.show.detailedhelp"); + } + + @Override + public void registered() { + gameScheduler.intervalTickEvent("show_portal", () -> { + for(PlayerContainer player : serverContainer.getPlayers()) { + var tempData = tempDataServices.getPlayerTempData(player); + if(!tempData.isDestiVisible()) { + return; + } + + for (Destination destination : destinationServices.getDestinations()) { + var pos = destination.getLoc(); + if(pos.distanceTo(player.getLoc()) < config.getVisibleRange()) { + Debug.addMarker(player, pos.toBlockPos(), destination.getArgValues("name")[0], new Color(100, 100, 100, 100), 1000); + } + } + //Debug.addMarker(player, pos, "", new Color(255, 0, 0, 100), 1000 * 10); + + } + }, 1, 20); + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java index d40ed38..5422125 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java @@ -1,17 +1,14 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal; import com.google.inject.Inject; -import com.sekwah.advancedportals.core.commands.SubCommand; -import com.sekwah.advancedportals.core.commands.subcommands.reusable.CreateTaggedSubCommand; +import com.sekwah.advancedportals.core.commands.subcommands.common.CreateTaggedSubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.destination.Destination; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.services.PortalServices; -import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java similarity index 96% rename from core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java rename to core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java index 99b4aee..4034400 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java @@ -12,7 +12,7 @@ import com.sekwah.advancedportals.core.util.Lang; import java.util.List; -public class ReloadSubCommand implements SubCommand { +public class ReloadPortalSubCommand implements SubCommand { @Inject private AdvancedPortalsCore portalsCore; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java index f4da15b..ba5d192 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java @@ -1,17 +1,15 @@ 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.serializeddata.BlockLocation; -import com.sekwah.advancedportals.core.serializeddata.PlayerTempData; +import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.services.PortalTempDataServices; -import com.sekwah.advancedportals.core.util.Debug; import com.sekwah.advancedportals.core.util.GameScheduler; import com.sekwah.advancedportals.core.util.Lang; -import java.awt.*; import java.util.List; /** @@ -25,45 +23,26 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn @Inject GameScheduler gameScheduler; + @Inject + AdvancedPortalsCore core; + + @Inject + ServerContainer serverContainer; + @Override public void onCommand(CommandSenderContainer sender, String[] args) { - sender.sendMessage("Debug"); - if(sender.getPlayerContainer() != null) { - PlayerContainer playerContainer = sender.getPlayerContainer(); - PlayerTempData tempData = tempDataServices.getPlayerTempData(playerContainer); - if(tempData.getPos1() != null) { - Debug.addMarker(sender.getPlayerContainer(), tempData.getPos1(), "Pos1", new Color(0, 255, 0), 1000 * 10); - } - if(tempData.getPos2() != null) { - Debug.addMarker(sender.getPlayerContainer(), tempData.getPos2(), "Pos2", new Color(255, 0, 0), 1000 * 10); - } - - if (tempData.getPos1() != null && tempData.getPos2() != null) { - int minX = Math.min(tempData.getPos1().posX, tempData.getPos2().posX); - int minY = Math.min(tempData.getPos1().posY, tempData.getPos2().posY); - int minZ = Math.min(tempData.getPos1().posZ, tempData.getPos2().posZ); - - int maxX = Math.max(tempData.getPos1().posX, tempData.getPos2().posX); - int maxY = Math.max(tempData.getPos1().posY, tempData.getPos2().posY); - int maxZ = Math.max(tempData.getPos1().posZ, tempData.getPos2().posZ); - - for (int x = minX; x <= maxX; x++) { - for (int y = minY; y <= maxY; y++) { - for (int z = minZ; z <= maxZ; z++) { - if ((x == minX || x == maxX) && (y == minY || y == maxY || z == minZ || z == maxZ) || - (y == minY || y == maxY) && (x == minX || x == maxX || z == minZ || z == maxZ) || - (z == minZ || z == maxZ) && (x == minX || x == maxX || y == minY || y == maxY)) { - - var pos = new BlockLocation(tempData.getPos1().worldName, x, y, z); - if (pos.equals(tempData.getPos1()) || pos.equals(tempData.getPos2())) - continue; - Debug.addMarker(sender.getPlayerContainer(), pos, "", new Color(255, 0, 0, 100), 1000 * 10); - } - } - } - } - } + if(core.getMcVersion()[1] < 16) { + sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.portal.show.unsupported")); + return; } + + var tempData = tempDataServices.getPlayerTempData(sender.getPlayerContainer()); + if(tempData.isPortalVisible()) { + sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.portal.show.disabled")); + } else { + sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.portal.show.enabled")); + } + tempData.setPortalVisible(!tempData.isPortalVisible()); } @Override @@ -89,7 +68,51 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn @Override public void registered() { gameScheduler.intervalTickEvent("show_portal", () -> { - System.out.println("check visibility"); + for(PlayerContainer player : serverContainer.getPlayers()) { + var tempData = tempDataServices.getPlayerTempData(player); + if(!tempData.isDestiVisible()) { + return; + } + + + } + /*sender.sendMessage("Debug"); + if(sender.getPlayerContainer() != null) { + PlayerContainer playerContainer = sender.getPlayerContainer(); + PlayerTempData tempData = tempDataServices.getPlayerTempData(playerContainer); + if(tempData.getPos1() != null) { + Debug.addMarker(sender.getPlayerContainer(), tempData.getPos1(), "Pos1", new Color(0, 255, 0), 1000 * 10); + } + if(tempData.getPos2() != null) { + Debug.addMarker(sender.getPlayerContainer(), tempData.getPos2(), "Pos2", new Color(255, 0, 0), 1000 * 10); + } + + if (tempData.getPos1() != null && tempData.getPos2() != null) { + int minX = Math.min(tempData.getPos1().posX, tempData.getPos2().posX); + int minY = Math.min(tempData.getPos1().posY, tempData.getPos2().posY); + int minZ = Math.min(tempData.getPos1().posZ, tempData.getPos2().posZ); + + int maxX = Math.max(tempData.getPos1().posX, tempData.getPos2().posX); + int maxY = Math.max(tempData.getPos1().posY, tempData.getPos2().posY); + int maxZ = Math.max(tempData.getPos1().posZ, tempData.getPos2().posZ); + + for (int x = minX; x <= maxX; x++) { + for (int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + if ((x == minX || x == maxX) && (y == minY || y == maxY || z == minZ || z == maxZ) || + (y == minY || y == maxY) && (x == minX || x == maxX || z == minZ || z == maxZ) || + (z == minZ || z == maxZ) && (x == minX || x == maxX || y == minY || y == maxY)) { + + var pos = new BlockLocation(tempData.getPos1().worldName, x, y, z); + if (pos.equals(tempData.getPos1()) || pos.equals(tempData.getPos2())) + continue; + Debug.addMarker(sender.getPlayerContainer(), pos, "", new Color(255, 0, 0, 100), 1000 * 10); + } + } + } + } + } + }*/ }, 1, 20); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java index 793a3bb..6184e76 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java @@ -1,7 +1,15 @@ package com.sekwah.advancedportals.core.connector.containers; +import java.util.UUID; + public interface ServerContainer { WorldContainer getWorld(String name); + PlayerContainer getPlayer(String name); + + PlayerContainer getPlayer(UUID name); + + PlayerContainer[] getPlayers(); + } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/destination/Destination.java b/core/src/main/java/com/sekwah/advancedportals/core/destination/Destination.java index cd84d8b..cb1a338 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/destination/Destination.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/destination/Destination.java @@ -113,4 +113,12 @@ public class Destination implements TagTarget { } return tagList; } + + public PlayerLocation getLoc() { + return loc; + } + + public void setLoc(PlayerLocation loc) { + this.loc = loc; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java b/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java index 67bc676..9cc7ae6 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java @@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core.module; import com.google.inject.*; import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.serializeddata.config.Config; import com.sekwah.advancedportals.core.serializeddata.config.ConfigProvider; @@ -45,6 +46,7 @@ public class AdvancedPortalsModule extends AbstractModule { bind(AdvancedPortalsCore.class).toInstance(advancedPortalsCore); bind(InfoLogger.class).toInstance(advancedPortalsCore.getInfoLogger()); bind(DataStorage.class).toInstance(advancedPortalsCore.getDataStorage()); + bind(ServerContainer.class).toInstance(advancedPortalsCore.getServerContainer()); // Providers bind(Config.class).toProvider(ConfigProvider.class); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java index 6f4e00a..2a5afd1 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java @@ -13,4 +13,6 @@ public interface ConfigRepository { String getSelectorMaterial(); void loadConfig(DataStorage dataStorage); + + int getVisibleRange(); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/IDestinationRepository.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/IDestinationRepository.java index 2342a56..3d1161c 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/IDestinationRepository.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/IDestinationRepository.java @@ -5,5 +5,5 @@ import com.sekwah.advancedportals.core.destination.Destination; import java.io.IOException; public interface IDestinationRepository extends IJsonRepository { - void addDestination(String name, Destination desti) throws IOException; + } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/IJsonRepository.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/IJsonRepository.java index 812ce22..d0afa2d 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/IJsonRepository.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/IJsonRepository.java @@ -1,8 +1,5 @@ package com.sekwah.advancedportals.core.repository; -import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; - import java.util.List; public interface IJsonRepository { @@ -17,5 +14,7 @@ public interface IJsonRepository { T get(String name); - List listAll(); + List getAllNames(); + + List getAll(); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java index 8e3933a..f31ea55 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java @@ -43,6 +43,10 @@ public class ConfigRepositoryImpl implements ConfigRepository { return this.config.selectorMaterial; } + public int getVisibleRange() { + return this.config.visibleRange; + } + @Override public void loadConfig(DataStorage dataStorage) { this.config = dataStorage.loadJson(Config.class, "config.json"); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java index c6d8325..3dee4f0 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java @@ -11,6 +11,7 @@ import javax.inject.Singleton; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; @Singleton @@ -23,14 +24,9 @@ public class DestinationRepositoryImpl implements IDestinationRepository { @Inject InfoLogger infoLogger; - public void addDestination(String name, Destination destination) { - infoLogger.log("Adding destination: " + fileLocation + name + ".json"); - dataStorage.storeJson(destination, fileLocation + name + ".json"); - } - @Override public boolean save(String name, Destination destination) { - return false; + return dataStorage.storeJson(destination, fileLocation + name + ".json"); } public boolean containsKey(String name) { @@ -52,7 +48,18 @@ public class DestinationRepositoryImpl implements IDestinationRepository { } @Override - public List listAll() { + public List getAllNames() { return dataStorage.listAllFiles(fileLocation, true); } + + @Override + public List getAll() { + List destinations = new ArrayList<>(); + List allFiles = dataStorage.listAllFiles(fileLocation, false); + for (String fileName : allFiles) { + Destination destination = dataStorage.loadJson(Destination.class, fileLocation + fileName); + destinations.add(destination); + } + return destinations; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java index 1e5b7f9..aaaf03f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java @@ -49,7 +49,12 @@ public class PortalRepositoryImpl implements IPortalRepository { } @Override - public List listAll() { + public List getAllNames() { + return null; + } + + @Override + public List getAll() { return null; } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java index 680eff8..e40ff35 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java @@ -35,4 +35,15 @@ public class BlockLocation { public boolean equals(BlockLocation location) { return location.posX == this.posX && location.posY == this.posY && location.posZ == this.posZ && location.worldName.equals(this.worldName); } + + public double distanceTo(BlockLocation pos) { + return Math.sqrt(this.distanceToSq(pos)); + } + + public double distanceToSq(BlockLocation pos) { + double dx = this.posX - pos.posX; + double dy = this.posY - pos.posY; + double dz = this.posZ - pos.posZ; + return dx * dx + dy * dy + dz * dz; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java index 271ded4..e9f1b30 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java @@ -66,7 +66,13 @@ public class DataStorage { return null; } BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource)); - return gson.fromJson(bufReader, dataHolder); + T data = gson.fromJson(bufReader, dataHolder); + try { + bufReader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + return data; } public boolean storeJson(Object dataHolder, String location) { @@ -222,6 +228,12 @@ public class DataStorage { } public boolean deleteFile(String fileLocation) { - return new File(dataFolder, fileLocation).delete(); + try { + Files.delete(Paths.get(dataFolder.getAbsolutePath(), fileLocation)); + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java index 5694777..f5b7103 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java @@ -19,6 +19,16 @@ public class PlayerTempData { */ private BlockLocation pos2; + /** + * If to show portals near the player + */ + private boolean portalVisible; + + /** + * If to show destination blocks near the player + */ + private boolean destiVisible; + /** * Used for things like join cooldowns * TODO either store a hashmap of cool-downs on a portal, or a hashmap of cool-downs for portals on a player @@ -59,4 +69,20 @@ public class PlayerTempData { public void setSelectedPortal(String selectedPortal) { this.selectedPortal = selectedPortal; } + + public boolean isPortalVisible() { + return portalVisible; + } + + public void setPortalVisible(boolean showPortals) { + this.portalVisible = showPortals; + } + + public boolean isDestiVisible() { + return destiVisible; + } + + public void setDestiVisible(boolean destiVisible) { + this.destiVisible = destiVisible; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/WorldLocation.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/WorldLocation.java index 82f5fd4..7d08290 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/WorldLocation.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/WorldLocation.java @@ -22,4 +22,19 @@ public class WorldLocation { this.posY = posY; this.posZ = posZ; } + + public double distanceTo(WorldLocation pos) { + return Math.sqrt(this.distanceToSq(pos)); + } + + public double distanceToSq(WorldLocation pos) { + double dx = this.posX - pos.posX; + double dy = this.posY - pos.posY; + double dz = this.posZ - pos.posZ; + return dx * dx + dy * dy + dz * dz; + } + + public BlockLocation toBlockPos() { + return new BlockLocation(this.worldName, (int) Math.floor(this.posX), (int) Math.floor(this.posY), (int) Math.floor(this.posZ)); + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java index 5eb8c0f..9bdf4eb 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java @@ -27,4 +27,6 @@ public class Config { public String translationFile = "en_GB"; + public int visibleRange = 50; + } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java index bccb435..4d0a96c 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java @@ -1,37 +1,29 @@ package com.sekwah.advancedportals.core.services; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.gson.reflect.TypeToken; import com.google.inject.Inject; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.portal.AdvancedPortal; -import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.destination.Destination; import com.sekwah.advancedportals.core.repository.IDestinationRepository; import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.core.util.Response; import javax.inject.Singleton; -import java.io.IOException; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; -/** - * Handles logic for all destination, this is a transient layer so it should - * not store any information. - */ @Singleton public class DestinationServices { @Inject private IDestinationRepository destinationRepository; + private final Map destinationCache = new HashMap<>(); + public Response.Creation create(String name, Destination destination) { if (!destinationRepository.containsKey(name)) { destinationRepository.save(name, destination); @@ -47,8 +39,20 @@ public class DestinationServices { return false; } - public List getDestinations() { - return destinationRepository.listAll(); + public List getDestinationNames() { + return destinationRepository.getAllNames(); + } + + public List getDestinations() { + return new ArrayList<>(destinationCache.values()); + } + + public void loadDestinations() { + List destinationNames = destinationRepository.getAllNames(); + for (String name : destinationNames) { + Destination destination = destinationRepository.get(name); + destinationCache.put(name, destination); + } } public Destination createDesti(PlayerContainer player, PlayerLocation playerLocation, ArrayList tags) { @@ -58,25 +62,24 @@ public class DestinationServices { String name = nameTag == null ? null : nameTag.VALUES[0]; // If the name is null, send an error saying that the name is required. - if(nameTag == null) { + if (nameTag == null) { player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.noname")); return null; } - if(name == null || name.equals("")) { + if (name == null || name.equals("")) { player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname")); return null; - } - else if(this.destinationRepository.containsKey(name)) { + } else if (this.destinationRepository.containsKey(name)) { player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.error.nametaken", name)); return null; } Destination desti = new Destination(playerLocation); - for(DataTag portalTag : tags) { + for (DataTag portalTag : tags) { desti.setArgValues(portalTag); } - for(DataTag destiTag : tags) { + for (DataTag destiTag : tags) { // TODO sort tag handle registry /*TagHandler.Creation creation = AdvancedPortalsCore.getDestinationTagRegistry().getCreationHandler(destiTag.NAME); if(creation != null) { @@ -84,32 +87,21 @@ public class DestinationServices { }*/ } try { - this.destinationRepository.addDestination(name, desti); + if(this.destinationRepository.save(name, desti)) { + this.destinationCache.put(name, desti); + } else { + player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save")); + return null; + } } catch (Exception e) { e.printStackTrace(); player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save")); } - this.saveDestinations(); return desti; } - //TODO Change to repository - - public void loadDestinations() { - Type type = new TypeToken>() { - }.getType(); - //this.destiHashMap = this.portalsCore.getDataStorage().loadJson(type, "destinations.json"); - this.saveDestinations(); - } - - public void saveDestinations() { - /*if (this.destiHashMap == null) { - this.destiHashMap = new HashMap<>(); - } - this.portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json");*/ - } - - public boolean removeDesti(String name, PlayerContainer playerContainer) { + public boolean removeDestination(String name, PlayerContainer playerContainer) { + this.destinationCache.remove(name); if(this.destinationRepository.containsKey(name)) { this.destinationRepository.delete(name); return true; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/Response.java b/core/src/main/java/com/sekwah/advancedportals/core/services/Response.java deleted file mode 100644 index a817a6f..0000000 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/Response.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.sekwah.advancedportals.core.services; - -public class Response { - - public enum Creation { - SUCCESS, - NAME_IN_USE, - } - -} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/DestiTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/DestiTag.java index 270e668..f5a40e2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/DestiTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/DestiTag.java @@ -53,6 +53,6 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete { @Override public List autoComplete(String argData) { - return destinationServices.getDestinations(); + return destinationServices.getDestinationNames(); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/Response.java b/core/src/main/java/com/sekwah/advancedportals/core/util/Response.java new file mode 100644 index 0000000..4997272 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/Response.java @@ -0,0 +1,13 @@ +package com.sekwah.advancedportals.core.util; + +/** + * Need to make more of the plugin use this rather than just returning true or false. + */ +public class Response { + + public enum Creation { + SUCCESS, + NAME_IN_USE, + } + +} diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index 231162e..e687b2c 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -81,9 +81,22 @@ command.portal.remove.complete= The portal has been successfully removed. command.portal.show.help=Shows nearby portals command.portal.show.detailedhelp=Shows nearby portals. Relies on debug markers so may not work on certain versions of minecraft (1.16+ atm only). +command.portal.show.enabled= Portal markers are now enabled. +command.portal.show.disabled= Portal markers are now disabled. +command.portal.show.unsupported= Portal markers are not supported on this version of minecraft. (1.16+ atm only) command.destination.remove.error= There was a problem removing the destination. +command.destination.show.help=Shows nearby destinations +command.destination.show.detailedhelp=Shows nearby destinations. Relies on debug markers so may not work on certain versions of minecraft (1.16+ atm only). +command.destination.show.enabled= Destination markers are now enabled. +command.destination.show.disabled= Destination markers are now disabled. +command.destination.show.unsupported= Destination markers are not supported on this version of minecraft. (1.16+ atm only) + +command.destination.reload.help=Reloads the destination data from the repository. +command.destination.reload.detailedhelp=This command will reload all destination data from the repository, updating the cache with the latest data. +command.destination.reload= Destinations reloaded. + command.portal.list.help=Lists portals command.portal.list=&7 Portals&a: diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java index 78f2df9..93064c8 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java @@ -6,9 +6,15 @@ import com.sekwah.advancedportals.core.connector.commands.CommandRegister; import com.sekwah.advancedportals.core.module.AdvancedPortalsModule; import com.sekwah.advancedportals.core.util.GameScheduler; import com.sekwah.advancedportals.spigot.connector.command.SpigotCommandRegister; +import com.sekwah.advancedportals.spigot.connector.container.SpigotServerContainer; import com.sekwah.advancedportals.spigot.metrics.Metrics; import org.bukkit.plugin.java.JavaPlugin; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static java.awt.SystemColor.text; + public class AdvancedPortalsPlugin extends JavaPlugin { private AdvancedPortalsCore portalsCore; @@ -26,7 +32,12 @@ public class AdvancedPortalsPlugin extends JavaPlugin { @Override public void onEnable() { - this.portalsCore = new AdvancedPortalsCore(this.getDataFolder(), new SpigotInfoLogger(this)); + String mcVersion = this.getServer().getVersion(); + Pattern pattern = Pattern.compile("\\(MC: ([\\d.]+)\\)"); + Matcher matcher = pattern.matcher(mcVersion); + this.portalsCore = new AdvancedPortalsCore(matcher.find() ? matcher.group(1) : "0.0.0", this.getDataFolder(), + new SpigotInfoLogger(this), + new SpigotServerContainer(this.getServer())); AdvancedPortalsModule module = this.portalsCore.getModule(); module.addInstanceBinding(CommandRegister.class, new SpigotCommandRegister(this)); diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java new file mode 100644 index 0000000..32fac1c --- /dev/null +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java @@ -0,0 +1,54 @@ +package com.sekwah.advancedportals.spigot.connector.container; + +import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; +import com.sekwah.advancedportals.core.connector.containers.ServerContainer; +import com.sekwah.advancedportals.core.connector.containers.WorldContainer; +import org.bukkit.Server; + +import java.util.UUID; + +public class SpigotServerContainer implements ServerContainer { + + private final Server server; + + public SpigotServerContainer(Server server) { + this.server = server; + } + + @Override + public WorldContainer getWorld(String name) { + var world = server.getWorld(name); + if(world != null) { + return new SpigotWorldContainer(world); + } else { + return null; + } + } + + @Override + public PlayerContainer getPlayer(String name) { + var player = server.getPlayer(name); + if(player != null) { + return new SpigotPlayerContainer(player); + } else { + return null; + } + } + + @Override + public PlayerContainer getPlayer(UUID name) { + var player = server.getPlayer(name); + if(player != null) { + return new SpigotPlayerContainer(player); + } else { + return null; + } + } + + @Override + public PlayerContainer[] getPlayers() { + return server.getOnlinePlayers().stream() + .map(SpigotPlayerContainer::new) + .toArray(PlayerContainer[]::new); + } +}