From 79c935a9314f64976750653b1368a776a442225c Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sun, 16 Jun 2024 04:50:56 +0100 Subject: [PATCH] chore: switch to using clang format --- .clang-format | 11 + .github/workflows/pre-commit-check.yaml | 6 - .pre-commit-config.yaml | 12 +- .../core/AdvancedPortalsCore.java | 91 +++-- .../advancedportals/core/CoreListeners.java | 106 ++--- .../core/commands/CommandTemplate.java | 8 +- .../core/commands/CommandWithSubCommands.java | 177 +++++---- .../core/commands/SubCommand.java | 6 +- .../common/CreateTaggedSubCommand.java | 152 +++++--- .../desti/CreateDestiSubCommand.java | 53 ++- .../desti/ListDestiSubCommand.java | 15 +- .../desti/RemoveDestiSubCommand.java | 16 +- .../desti/ShowDestiSubCommand.java | 67 ++-- .../desti/TeleportDestiSubCommand.java | 20 +- .../portal/CreatePortalSubCommand.java | 76 ++-- .../portal/EndGatewayBlockSubCommand.java | 25 +- .../portal/EndPortalBlockSubCommand.java | 25 +- .../portal/LangUpdateSubCommand.java | 65 ++-- .../portal/ListPortalsSubCommand.java | 15 +- .../portal/PortalBlockSubCommand.java | 33 +- .../portal/ReloadPortalSubCommand.java | 10 +- .../portal/RemovePortalSubCommand.java | 19 +- .../portal/SelectorSubCommand.java | 40 +- .../portal/ShowPortalSubCommand.java | 310 +++++++-------- .../subcommands/portal/VersionSubCommand.java | 12 +- .../connector/commands/CommandHandler.java | 1 - .../connector/commands/CommandRegister.java | 1 - .../containers/CommandSenderContainer.java | 1 - .../connector/containers/EntityContainer.java | 1 - .../connector/containers/PlayerContainer.java | 10 +- .../connector/containers/ServerContainer.java | 1 - .../connector/containers/WorldContainer.java | 1 - .../advancedportals/core/data/BlockAxis.java | 6 +- .../core/destination/Destination.java | 34 +- .../core/effect/WarpEffect.java | 3 - .../core/module/AdvancedPortalsModule.java | 29 +- .../core/permissions/PortalPermissions.java | 24 +- .../core/portal/AdvancedPortal.java | 63 +-- .../core/registry/CommandErrorCode.java | 3 +- .../core/registry/CommandHandler.java | 16 +- .../core/registry/RegisterBuilder.java | 9 +- .../core/registry/SubCommandRegistry.java | 22 +- .../core/registry/TagRegistry.java | 25 +- .../core/registry/TagTarget.java | 5 +- .../core/registry/WarpEffectRegistry.java | 54 ++- .../core/repository/ConfigRepository.java | 1 - .../core/repository/IJsonRepository.java | 1 - .../repository/impl/ConfigRepositoryImpl.java | 4 - .../impl/DestinationRepositoryImpl.java | 11 +- .../impl/PlayerDataRepositoryImpl.java | 5 +- .../repository/impl/PortalRepositoryImpl.java | 25 +- .../core/serializeddata/BlockLocation.java | 14 +- .../core/serializeddata/DataStorage.java | 89 +++-- .../core/serializeddata/DataTag.java | 1 - .../core/serializeddata/PlayerData.java | 44 ++- .../core/serializeddata/PlayerLocation.java | 8 +- .../serializeddata/ReflectiveConstructor.java | 94 +++-- .../serializeddata/ReflectiveRepresenter.java | 1 - .../core/serializeddata/WorldLocation.java | 12 +- .../core/serializeddata/config/Config.java | 5 +- .../core/services/Creation.java | 6 +- .../core/services/DestinationServices.java | 49 +-- .../core/services/PlayerDataServices.java | 41 +- .../core/services/PortalServices.java | 73 ++-- .../core/tags/activation/CooldownTag.java | 65 ++-- .../core/tags/activation/DestiTag.java | 25 +- .../core/tags/activation/NameTag.java | 25 +- .../core/tags/activation/PermissionTag.java | 21 +- .../core/tags/activation/TriggerBlockTag.java | 3 - .../advancedportals/core/util/Debug.java | 19 +- .../core/util/FriendlyDataOutput.java | 25 +- .../core/util/GameScheduler.java | 35 +- .../advancedportals/core/util/InfoLogger.java | 1 - .../advancedportals/core/util/Lang.java | 54 +-- .../core/util/PlayerUtils.java | 8 +- .../advancedportals/core/util/TagReader.java | 2 - .../core/warphandler/ActivationData.java | 23 +- .../advancedportals/core/warphandler/Tag.java | 139 ++++--- .../spigot/AdvancedPortalsPlugin.java | 2 +- .../advancedportals/spigot/Listeners.java | 51 ++- .../spigot/SpigotInfoLogger.java | 2 - .../portal/UpdatePortalSubCommand.java | 114 +++--- .../portal/update/ConfigAccessor.java | 18 +- .../command/SpigotCommandHandler.java | 19 +- .../command/SpigotCommandRegister.java | 11 +- .../SpigotCommandSenderContainer.java | 2 - .../container/SpigotEntityContainer.java | 34 +- .../container/SpigotPlayerContainer.java | 43 ++- .../container/SpigotServerContainer.java | 26 +- .../container/SpigotWorldContainer.java | 23 +- .../spigot/metrics/Metrics.java | 363 ++++++++++-------- .../reflection/MinecraftCustomPayload.java | 28 +- .../spigot/utils/ContainerHelpers.java | 16 +- .../spigot/warpeffects/EnderWarpEffect.java | 20 +- .../spigot/warpeffects/SpigotWarpEffects.java | 2 - 95 files changed, 1742 insertions(+), 1640 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..5ed80b3f --- /dev/null +++ b/.clang-format @@ -0,0 +1,11 @@ +BasedOnStyle: Google +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +AllowShortFunctionsOnASingleLine: None +BreakBeforeBraces: Attach +ConstructorInitializerAllOnOneLineOrOnePerLine: true +BreakConstructorInitializers: BeforeComma +AlignAfterOpenBracket: Align +PenaltyBreakBeforeFirstCallParameter: 1 +ColumnLimit: 80 diff --git a/.github/workflows/pre-commit-check.yaml b/.github/workflows/pre-commit-check.yaml index 66d72b31..6406bc5b 100644 --- a/.github/workflows/pre-commit-check.yaml +++ b/.github/workflows/pre-commit-check.yaml @@ -17,12 +17,6 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '11' - uses: dorny/paths-filter@v2 id: filter diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d08303e0..cef04543 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ # See https://pre-commit.com for more information repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -11,7 +11,7 @@ repos: - id: check-case-conflict - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.1.10 + rev: v1.5.5 hooks: - id: remove-crlf - id: remove-tabs @@ -19,9 +19,13 @@ repos: - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks rev: v2.13.0 hooks: - - id: pretty-format-java - args: [--autofix, --aosp, --google-java-formatter-version=1.16.0] - id: pretty-format-yaml args: [--autofix] - id: pretty-format-toml args: [--autofix] + +- repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + hooks: + - id: clang-format + args: [-i, --style=file] 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 53f59a83..c02bd713 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -20,12 +20,10 @@ import com.sekwah.advancedportals.core.tags.activation.*; import com.sekwah.advancedportals.core.util.GameScheduler; 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"; private final InfoLogger infoLogger; @@ -34,8 +32,8 @@ public class AdvancedPortalsCore { 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 + * 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; @@ -63,21 +61,21 @@ public class AdvancedPortalsCore { // TEMP REMOVE THIS THIS IS JUST FOR DEV @Inject private IPlayerDataRepository tempDataRepository; - public AdvancedPortalsCore( - String mcVersion, - File dataStorageLoc, - InfoLogger infoLogger, - ServerContainer serverContainer) { + public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, + InfoLogger infoLogger, + ServerContainer serverContainer) { instance = this; this.serverContainer = serverContainer; this.dataStorage = new DataStorage(dataStorageLoc); this.infoLogger = infoLogger; int[] mcVersionTemp; - infoLogger.info("Loading Advanced Portals Core v" + version + " for MC: " + mcVersion); + infoLogger.info("Loading Advanced Portals Core v" + version + + " for MC: " + mcVersion); try { - mcVersionTemp = - Arrays.stream(mcVersion.split("\\.")).mapToInt(Integer::parseInt).toArray(); + mcVersionTemp = Arrays.stream(mcVersion.split("\\.")) + .mapToInt(Integer::parseInt) + .toArray(); } catch (NumberFormatException e) { infoLogger.info("Failed to parse MC version: " + mcVersion); e.printStackTrace(); @@ -92,13 +90,13 @@ public class AdvancedPortalsCore { } /** - * For some platforms we could do this on construction but this just allows for a bit more - * control + * 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. + // 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); @@ -124,7 +122,8 @@ public class AdvancedPortalsCore { this.tagRegistry.registerTag(new PermissionTag()); } - /** */ + /** + */ public void registerCommands() { this.registerPortalCommand(commandRegister); this.registerDestinationCommand(commandRegister); @@ -133,43 +132,61 @@ public class AdvancedPortalsCore { private void registerPortalCommand(CommandRegister commandRegister) { this.portalCommand = new CommandWithSubCommands(this); - this.portalCommand.registerSubCommand("version", new VersionSubCommand()); - this.portalCommand.registerSubCommand("langupdate", new LangUpdateSubCommand()); - 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()); - this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand()); - this.portalCommand.registerSubCommand("create", new CreatePortalSubCommand()); - this.portalCommand.registerSubCommand("remove", new RemovePortalSubCommand()); - this.portalCommand.registerSubCommand("list", new ListPortalsSubCommand()); - this.portalCommand.registerSubCommand("show", new ShowPortalSubCommand()); + this.portalCommand.registerSubCommand("version", + new VersionSubCommand()); + this.portalCommand.registerSubCommand("langupdate", + new LangUpdateSubCommand()); + 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()); + this.portalCommand.registerSubCommand("endgatewayblock", + new EndGatewayBlockSubCommand()); + this.portalCommand.registerSubCommand("create", + new CreatePortalSubCommand()); + this.portalCommand.registerSubCommand("remove", + new RemovePortalSubCommand()); + this.portalCommand.registerSubCommand("list", + new ListPortalsSubCommand()); + this.portalCommand.registerSubCommand("show", + new ShowPortalSubCommand()); commandRegister.registerCommand("portal", this.portalCommand); } private void registerDestinationCommand(CommandRegister commandRegister) { this.destiCommand = new CommandWithSubCommands(this); - this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand()); - this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand()); - this.destiCommand.registerSubCommand("teleport", new TeleportDestiSubCommand(), "tp"); + this.destiCommand.registerSubCommand("create", + new CreateDestiSubCommand()); + this.destiCommand.registerSubCommand("remove", + new RemoveDestiSubCommand()); + this.destiCommand.registerSubCommand( + "teleport", new TeleportDestiSubCommand(), "tp"); this.destiCommand.registerSubCommand("list", new ListDestiSubCommand()); this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand()); commandRegister.registerCommand("destination", this.destiCommand); } - public boolean registerPortalCommand(String arg, SubCommand subCommand, String... aliasArgs) { - return this.portalCommand.registerSubCommand(arg, subCommand, aliasArgs); + public boolean registerPortalCommand(String arg, SubCommand subCommand, + String... aliasArgs) { + return this.portalCommand.registerSubCommand(arg, subCommand, + aliasArgs); } - public boolean registerDestiCommand(String arg, SubCommand subCommand, String... aliasArgs) { + public boolean registerDestiCommand(String arg, SubCommand subCommand, + String... aliasArgs) { return this.destiCommand.registerSubCommand(arg, subCommand, aliasArgs); } /** - * 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) + * 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) */ public void loadPortalConfig() { this.configRepository.loadConfig(this.dataStorage); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index e625a293..d2820f81 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -6,30 +6,24 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.connector.containers.WorldContainer; import com.sekwah.advancedportals.core.data.BlockAxis; import com.sekwah.advancedportals.core.data.Direction; -import com.sekwah.advancedportals.core.serializeddata.BlockLocation; -import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; -import com.sekwah.advancedportals.core.services.PortalServices; +import com.sekwah.advancedportals.core.serializeddata.BlockLocation; +import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.services.PlayerDataServices; +import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.GameScheduler; import com.sekwah.advancedportals.core.util.Lang; - import java.util.Objects; public class CoreListeners { + @Inject private PlayerDataServices playerDataServices; - @Inject - private PlayerDataServices playerDataServices; + @Inject private PortalServices portalServices; - @Inject - private PortalServices portalServices; + @Inject private ConfigRepository configRepository; - @Inject - private ConfigRepository configRepository; - - @Inject - private GameScheduler gameScheduler; + @Inject private GameScheduler gameScheduler; public void playerJoin(PlayerContainer player) { this.playerDataServices.setJoinCooldown(player); @@ -56,19 +50,24 @@ public class CoreListeners { } /** - * If the block is indirectly broken it will also take null for the player e.g. with tnt + * If the block is indirectly broken it will also take null for the player + * e.g. with tnt * * @player player causing the event (or null if not a player) * @param blockPos * @param blockMaterial * @return if the block is allowed to break */ - public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, String blockMaterial, String itemInHandMaterial, String itemInHandName) { - if(player == null) { + public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, + String blockMaterial, String itemInHandMaterial, + String itemInHandName) { + if (player == null) { return !portalServices.inPortalRegionProtected(blockPos); } - if(!(PortalPermissions.BUILD.hasPermission(player) || !portalServices.inPortalRegionProtected(blockPos))) { - player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("portal.nobuild")); + if (!(PortalPermissions.BUILD.hasPermission(player) + || !portalServices.inPortalRegionProtected(blockPos))) { + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("portal.nobuild")); return false; } return true; @@ -80,33 +79,36 @@ public class CoreListeners { * @param blockMaterial * @return if the block is allowed to be placed */ - public boolean blockPlace(PlayerContainer player, BlockLocation blockPos, String blockMaterial, String itemInHandMaterial, String itemInHandName) { - if(player != null && PortalPermissions.BUILD.hasPermission(player)) { + public boolean blockPlace(PlayerContainer player, BlockLocation blockPos, + String blockMaterial, String itemInHandMaterial, + String itemInHandName) { + if (player != null && PortalPermissions.BUILD.hasPermission(player)) { WorldContainer world = player.getWorld(); - if(itemInHandName.equals("\u00A75Portal Block Placer")) { + if (itemInHandName.equals("\u00A75Portal Block Placer")) { world.setBlock(blockPos, "NETHER_PORTAL"); for (Direction direction : Direction.values()) { var checkLoc = new BlockLocation(blockPos, direction); if (world.getBlock(checkLoc).equals("NETHER_PORTAL")) { - world.setBlockAxis(blockPos, world.getBlockAxis(checkLoc)); + world.setBlockAxis(blockPos, + world.getBlockAxis(checkLoc)); break; } } return true; - } - else if(itemInHandName.equals("\u00A78End Portal Block Placer")) { + } else if (itemInHandName.equals( + "\u00A78End Portal Block Placer")) { world.setBlock(blockPos, "END_PORTAL"); return true; - } - else if(itemInHandName.equals("\u00A78Gateway Block Placer")) { + } else if (itemInHandName.equals("\u00A78Gateway Block Placer")) { world.setBlock(blockPos, "END_GATEWAY"); return true; } return true; } - if(portalServices.inPortalRegionProtected(blockPos)) { - if(player != null) { - player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("portal.nobuild")); + if (portalServices.inPortalRegionProtected(blockPos)) { + if (player != null) { + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("portal.nobuild")); } return false; } @@ -119,7 +121,8 @@ public class CoreListeners { * @param blockPos * @return */ - public boolean blockInteract(PlayerContainer player, BlockLocation blockPos) { + public boolean blockInteract(PlayerContainer player, + BlockLocation blockPos) { return true; } @@ -129,25 +132,33 @@ public class CoreListeners { * @param leftClick true = left click, false = right click * @return if player is allowed to interact with block */ - public boolean playerInteractWithBlock(PlayerContainer player, String blockMaterialname, String itemMaterialName, String itemName, - BlockLocation blockLoc, boolean leftClick) { - if(itemName != null && (player.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(player)) && - itemMaterialName.equalsIgnoreCase(this.configRepository.getSelectorMaterial()) - && (!this.configRepository.getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) { - this.playerDataServices.playerSelectorActivate(player, blockLoc, leftClick); + public boolean playerInteractWithBlock(PlayerContainer player, + String blockMaterialname, + String itemMaterialName, + String itemName, + BlockLocation blockLoc, + boolean leftClick) { + if (itemName != null + && (player.isOp() + || PortalPermissions.CREATE_PORTAL.hasPermission(player)) + && itemMaterialName.equalsIgnoreCase( + this.configRepository.getSelectorMaterial()) + && (!this.configRepository.getUseOnlySpecialAxe() + || itemName.equals("\u00A7ePortal Region Selector"))) { + this.playerDataServices.playerSelectorActivate(player, blockLoc, + leftClick); return false; - } - else if(itemName != null && leftClick && - Objects.equals(itemMaterialName, "PURPLE_WOOL") && - itemName.equals("\u00A75Portal Block Placer") && PortalPermissions.BUILD.hasPermission(player)) { - if(!Objects.equals(blockMaterialname, "NETHER_PORTAL")) { + } else if (itemName != null && leftClick + && Objects.equals(itemMaterialName, "PURPLE_WOOL") + && itemName.equals("\u00A75Portal Block Placer") + && PortalPermissions.BUILD.hasPermission(player)) { + if (!Objects.equals(blockMaterialname, "NETHER_PORTAL")) { return false; } WorldContainer world = player.getWorld(); - if(world.getBlockAxis(blockLoc) == BlockAxis.X) { + if (world.getBlockAxis(blockLoc) == BlockAxis.X) { world.setBlockAxis(blockLoc, BlockAxis.Z); - } - else { + } else { world.setBlockAxis(blockLoc, BlockAxis.X); } return false; @@ -166,14 +177,15 @@ public class CoreListeners { public boolean entityPortalEvent(EntityContainer entity) { var pos = entity.getBlockLoc(); - if(entity instanceof PlayerContainer player) { + if (entity instanceof PlayerContainer player) { var playerData = playerDataServices.getPlayerData(player); - if(playerData.isNetherPortalCooldown()) { + if (playerData.isNetherPortalCooldown()) { return false; } } var feetInPortal = portalServices.inPortalRegion(pos, 1); - var headInPortal = portalServices.inPortalRegion(pos.addY((int) entity.getHeight()), 1); + var headInPortal = portalServices.inPortalRegion( + pos.addY((int) entity.getHeight()), 1); return !(feetInPortal || headInPortal); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java index 18146259..3ef2ba8b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java @@ -1,7 +1,6 @@ package com.sekwah.advancedportals.core.commands; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; - import java.util.List; /** @@ -11,13 +10,14 @@ import java.util.List; * https://docs.spongepowered.org/stable/en/plugin/commands/arguments.html#custom-command-elements */ public interface CommandTemplate { - - void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args); + void onCommand(CommandSenderContainer sender, String commandExecuted, + String[] args); /** * Fired when someone asks for a tab complete action. * - * @param sender whoever triggered the command e.g. command block, server or player + * @param sender whoever triggered the command e.g. command block, server or + * player * @param args arguments for the command * @return a lot of strings that are possible completions */ diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java index 5eff4db3..d77afa90 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java @@ -4,14 +4,12 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore; 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; import java.util.stream.Collectors; public class CommandWithSubCommands implements CommandTemplate { - private final SubCommandRegistry subCommandRegistry; private final int subCommandsPerPage = 7; @@ -22,128 +20,163 @@ public class CommandWithSubCommands implements CommandTemplate { this.pluginCore = advancedPortalsCore; } - public boolean registerSubCommand(String arg, SubCommand subCommand, String... aliasArgs) { + public boolean registerSubCommand(String arg, SubCommand subCommand, + String... aliasArgs) { pluginCore.getModule().getInjector().injectMembers(subCommand); boolean hasRegistered = false; - for(String additionalArg : aliasArgs) { - hasRegistered = this.subCommandRegistry.registerSubCommand(additionalArg,subCommand) || hasRegistered; + for (String additionalArg : aliasArgs) { + hasRegistered = this.subCommandRegistry.registerSubCommand( + additionalArg, subCommand) + || hasRegistered; } - boolean result = this.subCommandRegistry.registerSubCommand(arg,subCommand) || hasRegistered; - if(subCommand instanceof SubCommand.SubCommandOnInit init) { + boolean result = + this.subCommandRegistry.registerSubCommand(arg, subCommand) + || hasRegistered; + if (subCommand instanceof SubCommand.SubCommandOnInit init) { init.registered(); } return result; } - public ArrayList getSubCommands(){ + public ArrayList getSubCommands() { return this.subCommandRegistry.getSubCommands(); } - public boolean isArgRegistered(String arg){ + public boolean isArgRegistered(String arg) { return this.subCommandRegistry.isArgRegistered(arg); } - public SubCommand getSubCommand(String 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")) { + 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); - String command = commandExecuted.substring(0, 1).toUpperCase() + commandExecuted.substring(1).toLowerCase(); - if(args.length > 1) { + String[] subCommands = + this.subCommandRegistry.getSubCommands().toArray( + new String[0]); + int pages = (int) Math.ceil(subCommands.length + / (float) this.subCommandsPerPage); + String command = commandExecuted.substring(0, 1).toUpperCase() + + commandExecuted.substring(1).toLowerCase(); + if (args.length > 1) { try { helpPage = Integer.parseInt(args[1]); - if(helpPage > pages) { + if (helpPage > pages) { helpPage = pages; } - if(helpPage <= 0) { + if (helpPage <= 0) { helpPage = 1; } - } - catch(NumberFormatException e) { + } catch (NumberFormatException e) { String subCommand = args[1].toLowerCase(); - if(this.subCommandRegistry.isArgRegistered(subCommand)) { + if (this.subCommandRegistry.isArgRegistered( + subCommand)) { sender.sendMessage(""); - var helpTitle = Lang.centeredTitle(Lang.translateInsertVariables("command.help.subcommandheader", - command, subCommand)); + var helpTitle = Lang.centeredTitle( + Lang.translateInsertVariables( + "command.help.subcommandheader", command, + subCommand)); sender.sendMessage(helpTitle); - sender.sendMessage("\u00A77" + this.getSubCommand(subCommand).getDetailedHelpText()); - } - else { - sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.help.invalidhelp", args[1])); + sender.sendMessage("\u00A77" + + this.getSubCommand(subCommand) + .getDetailedHelpText()); + } else { + sender.sendMessage( + Lang.translate("messageprefix.negative") + + Lang.translateInsertVariables( + "command.help.invalidhelp", args[1])); } return; } } sender.sendMessage(""); - var helpTitle = Lang.centeredTitle(Lang.translateInsertVariables("command.help.header", - command, helpPage, pages)); + var helpTitle = + Lang.centeredTitle(Lang.translateInsertVariables( + "command.help.header", command, helpPage, pages)); sender.sendMessage(helpTitle); - sender.sendMessage("\u00A7a█\u00A77 = Permission \u00A7c█\u00A77 = No Permission"); + sender.sendMessage( + "\u00A7a█\u00A77 = Permission \u00A7c█\u00A77 " + + "= No Permission"); int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage; int displayEnd = subCommandOffset + this.subCommandsPerPage; - if(displayEnd > subCommands.length) { + 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()); + 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)) { + } 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.translate("messageprefix.negative") + Lang.translateInsertVariables("command.subcommand.nopermission", + } else { + sender.sendMessage( + Lang.translate("messageprefix.negative") + + Lang.translateInsertVariables( + "command.subcommand.nopermission", commandExecuted)); } return; } } - sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.subcommand.invalid")); + sender.sendMessage( + Lang.translate("messageprefix.negative") + + Lang.translate("command.subcommand.invalid")); } - } - else { - sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.noargs", commandExecuted)); + } else { + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translateInsertVariables( + "command.noargs", commandExecuted)); } } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { - if(args.length > 1) { - if(args[0].equalsIgnoreCase("help")) { - List allowedCommands = new ArrayList<>(this.subCommandRegistry.getSubCommands()); - int pages = (int) Math.ceil(allowedCommands.size() / (float) this.subCommandsPerPage); + public List onTabComplete(CommandSenderContainer sender, + String[] args) { + if (args.length > 1) { + if (args[0].equalsIgnoreCase("help")) { + List allowedCommands = + new ArrayList<>(this.subCommandRegistry.getSubCommands()); + int pages = (int) Math.ceil(allowedCommands.size() + / (float) this.subCommandsPerPage); for (int i = 1; i <= pages; i++) { allowedCommands.add(String.valueOf(i)); } Collections.sort(allowedCommands); - return this.filterTabResults(allowedCommands, args[args.length - 1]); - } - else { - for (String subCommandName : this.subCommandRegistry.getSubCommands()) { + 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); + SubCommand subCommand = + this.getSubCommand(subCommandName); if (subCommand.hasPermission(sender)) { - List tabComplete = this.filterTabResults(this.getSubCommand(subCommandName).onTabComplete(sender, args), - args[args.length - 1]); - if(tabComplete != null) { + List tabComplete = this.filterTabResults( + this.getSubCommand(subCommandName) + .onTabComplete(sender, args), + args[args.length - 1]); + if (tabComplete != null) { return tabComplete; - } - else { + } else { return Collections.emptyList(); } } else { @@ -152,12 +185,12 @@ public class CommandWithSubCommands implements CommandTemplate { } } } - } - else { + } else { List allowedCommands = new ArrayList<>(); - for (String subCommandName : this.subCommandRegistry.getSubCommands()) { + for (String subCommandName : + this.subCommandRegistry.getSubCommands()) { SubCommand subCommand = this.getSubCommand(subCommandName); - if(subCommand.hasPermission(sender)) { + if (subCommand.hasPermission(sender)) { allowedCommands.add(subCommandName); } } @@ -169,11 +202,11 @@ public class CommandWithSubCommands implements CommandTemplate { } public List filterTabResults(List tabList, String lastArg) { - if(tabList == null) { + if (tabList == null) { return null; } return tabList.stream() - .filter(arg -> arg.startsWith(lastArg)) - .collect(Collectors.toList()); + .filter(arg -> arg.startsWith(lastArg)) + .collect(Collectors.toList()); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java index 69a77881..233bb26f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java @@ -1,16 +1,14 @@ package com.sekwah.advancedportals.core.commands; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; - import java.util.List; public interface SubCommand { - /** * @param sender * @param args arguments including the subcommand that has been specified. - * @return if the command has worked (if false it will just display a message from the command - * suggesting to check help) + * @return if the command has worked (if false it will just display a + * message from the command suggesting to check help) */ void onCommand(CommandSenderContainer sender, String[] args); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java index b286125f..566285c4 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java @@ -5,7 +5,6 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -13,34 +12,36 @@ import java.util.Set; import java.util.stream.Collectors; public abstract class CreateTaggedSubCommand implements SubCommand { - protected abstract List getRelatedTags(); @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { - - if(TagReader.isClosedString(args)) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { + if (TagReader.isClosedString(args)) { return List.of(); } List allTags = this.getRelatedTags(); List suggestions = new ArrayList<>(); - if(args.length > 0) { + if (args.length > 0) { var lastArg = args[args.length - 1]; - // Check if the split results in exactly 2 or if its 1 and ends with : + // Check if the split results in exactly 2 or if its 1 and ends + // with : var split = lastArg.split(":"); - if(split.length == 2 || (split.length == 1 && lastArg.endsWith(":"))) { - // Loop over tags in allTags and check if the first half of split is equal to the tag name or alias - for(Tag tag : allTags) { + if (split.length == 2 + || (split.length == 1 && lastArg.endsWith(":"))) { + // Loop over tags in allTags and check if the first half of + // split is equal to the tag name or alias + for (Tag tag : allTags) { // Check if the last tag starts with the tag name or alias var startsWith = false; - if(lastArg.startsWith(tag.getName())) { + if (lastArg.startsWith(tag.getName())) { startsWith = true; } else { var aliases = tag.getAliases(); - if(aliases != null) { + if (aliases != null) { for (String alias : aliases) { - if(lastArg.startsWith(alias)) { + if (lastArg.startsWith(alias)) { startsWith = true; break; } @@ -48,33 +49,52 @@ public abstract class CreateTaggedSubCommand implements SubCommand { } } - if(tag instanceof Tag.AutoComplete autoComplete && startsWith) { + if (tag instanceof Tag.AutoComplete autoComplete + && startsWith) { var argData = split.length == 2 ? split[1] : ""; var tagSuggestions = autoComplete.autoComplete(argData); - if(tagSuggestions != null) { - if(tag instanceof Tag.Split splitTag) { + if (tagSuggestions != null) { + if (tag instanceof Tag.Split splitTag) { var multiTagSplit = splitTag.splitString(); - boolean endsWithSplit = argData.endsWith(multiTagSplit); + boolean endsWithSplit = + argData.endsWith(multiTagSplit); String[] items = argData.split(multiTagSplit); - Set existingItems = Arrays.stream(items, 0, endsWithSplit ? items.length : items.length - 1) + Set existingItems = + Arrays + .stream(items, 0, + endsWithSplit + ? items.length + : items.length - 1) .map(String::trim) .collect(Collectors.toSet()); - String partialInput = endsWithSplit ? "" : items[items.length - 1].trim(); - String baseString = endsWithSplit ? argData : argData.substring(0, argData.lastIndexOf(multiTagSplit) + 1); + String partialInput = endsWithSplit + ? "" + : items[items.length - 1].trim(); + String baseString = endsWithSplit + ? argData + : argData.substring( + 0, + argData.lastIndexOf(multiTagSplit) + + 1); - tagSuggestions = tagSuggestions.stream() + tagSuggestions = + tagSuggestions + .stream() // Remove already listed items .filter(s -> !existingItems.contains(s)) - // Remove items that don't match the currently typed input + // Remove items that don't match the + // currently typed input .filter(s -> s.startsWith(partialInput)) - // Remap so the auto completes actually show + // Remap so the auto completes actually + // show .map(s -> baseString + s) .toList(); } - // Loop over suggestions and add split[0] + ":" to the start + // Loop over suggestions and add split[0] + ":" to + // the start for (String tagSuggestion : tagSuggestions) { suggestions.add(split[0] + ":" + tagSuggestion); } @@ -88,28 +108,30 @@ public abstract class CreateTaggedSubCommand implements SubCommand { ArrayList tagsFromArgs = TagReader.getTagsFromArgs(args); - allTags.stream().filter(tag -> { - for (DataTag argTag : tagsFromArgs) { - if(argTag.NAME.equals(tag.getName())) { - return false; - } - var aliases = tag.getAliases(); - if(aliases != null) { - for (String alias : aliases) { - if(argTag.NAME.equals(alias)) { - return false; + allTags.stream() + .filter(tag -> { + for (DataTag argTag : tagsFromArgs) { + if (argTag.NAME.equals(tag.getName())) { + return false; + } + var aliases = tag.getAliases(); + if (aliases != null) { + for (String alias : aliases) { + if (argTag.NAME.equals(alias)) { + return false; + } } } } - } - return true; - }).forEach(tag -> { - suggestions.add(tag.getName()); - var aliases = tag.getAliases(); - if(aliases != null) { - suggestions.addAll(Arrays.stream(aliases).toList()); - } - }); + return true; + }) + .forEach(tag -> { + suggestions.add(tag.getName()); + var aliases = tag.getAliases(); + if (aliases != null) { + suggestions.addAll(Arrays.stream(aliases).toList()); + } + }); // Loop over all suggestions and add : to the end for (int i = 0; i < suggestions.size(); i++) { @@ -125,24 +147,34 @@ public abstract class CreateTaggedSubCommand implements SubCommand { for (var dataTag : dataTags) { for (Tag tag : relatedTags) { - if(tag instanceof Tag.Split splitTag) { + if (tag instanceof Tag.Split splitTag) { var splitString = splitTag.splitString(); - if(splitString != null) { + if (splitString != null) { List newValues = new ArrayList<>(); - for(String split : dataTag.VALUES) { - newValues.addAll(Arrays.stream(split.split(splitString)).map(String::trim).toList()); + for (String split : dataTag.VALUES) { + newValues.addAll( + Arrays.stream(split.split(splitString)) + .map(String::trim) + .toList()); } - dataTag = new DataTag(dataTag.NAME, newValues.toArray(new String[0])); + dataTag = new DataTag(dataTag.NAME, + newValues.toArray(new String[0])); } } if (dataTag.NAME.equals(tag.getName())) { // DataTag name matches the tag's main name, add as is processedTags.add(dataTag); break; - } else if (tag.getAliases() != null && Arrays.asList(tag.getAliases()).contains(dataTag.NAME)) { - // There is currently an edge case where if someone uses multiple aliases or names for tags at the same time, it'll only use the last one applied to the mapping. - // DataTag name matches an alias, create a new DataTag with the main name - processedTags.add(new DataTag(tag.getName(), dataTag.VALUES)); + } else if (tag.getAliases() != null + && Arrays.asList(tag.getAliases()) + .contains(dataTag.NAME)) { + // There is currently an edge case where if someone uses + // multiple aliases or names for tags at the same time, + // it'll only use the last one applied to the mapping. + // DataTag name matches an alias, create a new DataTag with + // the main name + processedTags.add( + new DataTag(tag.getName(), dataTag.VALUES)); break; } } @@ -153,24 +185,26 @@ public abstract class CreateTaggedSubCommand implements SubCommand { dataTags.addAll(processedTags); // Sort the tags by name however make sure name is first dataTags.sort((o1, o2) -> { - if(o1.NAME.equals("name")) { + if (o1.NAME.equals("name")) { return -1; } - if(o2.NAME.equals("name")) { + if (o2.NAME.equals("name")) { return 1; } return o1.NAME.compareTo(o2.NAME); }); } - - protected void printTags(CommandSenderContainer sender, List dataTags) { + protected void printTags(CommandSenderContainer sender, + List dataTags) { for (DataTag tag : dataTags) { - if(tag.VALUES.length == 1) { - sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]); + if (tag.VALUES.length == 1) { + sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e" + + tag.VALUES[0]); } else { for (int i = 0; i < tag.VALUES.length; i++) { - sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77[" + i + "]:\u00A7e" + tag.VALUES[i]); + sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77[" + i + + "]:\u00A7e" + tag.VALUES[i]); } } } 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 d9fb6f85..0c1c9100 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 @@ -12,13 +12,11 @@ import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CreateDestiSubCommand extends CreateTaggedSubCommand { - @Inject TagRegistry tagRegistry; @Inject DestinationServices destinationServices; @@ -29,34 +27,34 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.create.destination.console")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.create.destination.console")); return; } - ArrayList destinationTags = TagReader.getTagsFromArgs(args); + ArrayList destinationTags = + TagReader.getTagsFromArgs(args); // Find the tag with the "name" NAME - DataTag nameTag = - destinationTags.stream() - .filter(tag -> tag.NAME.equals("name")) - .findFirst() - .orElse(null); + DataTag nameTag = destinationTags.stream() + .filter(tag -> tag.NAME.equals("name")) + .findFirst() + .orElse(null); - // If the tag is null, check if arg[1] has a : to check it's not a tag. + // If the tag is null, check if arg[1] has a : to check it's not a + // tag. if (nameTag == null && !args[1].contains(":")) { nameTag = new DataTag("name", args[1]); destinationTags.add(nameTag); } if (nameTag == null) { - sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.error.noname")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.error.noname")); return; } - sender.sendMessage( - Lang.centeredTitle(Lang.translate("command.create.destination.prep"))); + sender.sendMessage(Lang.centeredTitle( + Lang.translate("command.create.destination.prep"))); sender.sendMessage(""); sender.sendMessage(Lang.translate("command.create.tags")); @@ -65,22 +63,21 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand { this.printTags(sender, destinationTags); } sender.sendMessage(""); - Destination destination = - destinationServices.createDesti(player, player.getLoc(), destinationTags); + Destination destination = destinationServices.createDesti( + player, player.getLoc(), destinationTags); if (destination != null) { sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.create.destination.complete")); + Lang.translate("messageprefix.positive") + + Lang.translate("command.create.destination.complete")); } else { sender.sendMessage(""); sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.create.destination.error")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.create.destination.error")); } } else { - sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.error.noname")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.error.noname")); } } @@ -94,8 +91,10 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand { var tags = tagRegistry.getTags(); // Filter tags that support Destination return tags.stream() - .filter(tag -> Arrays.asList(tag.getTagTypes()).contains(Tag.TagType.DESTINATION)) - .toList(); + .filter(tag + -> Arrays.asList(tag.getTagTypes()) + .contains(Tag.TagType.DESTINATION)) + .toList(); } @Override 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 92f52b4d..be01d981 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 @@ -5,23 +5,19 @@ 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.util.Lang; - import java.util.List; import java.util.stream.Collectors; public class ListDestiSubCommand implements SubCommand { - @Inject DestinationServices portalServices; @Override public void onCommand(CommandSenderContainer sender, String[] args) { sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.destination.list") - + " " - + portalServices.getDestinationNames().stream() - .sorted() - .collect(Collectors.joining(", "))); + Lang.translate("messageprefix.positive") + + Lang.translate("command.destination.list") + " " + + portalServices.getDestinationNames().stream().sorted().collect( + Collectors.joining(", "))); } @Override @@ -30,7 +26,8 @@ public class ListDestiSubCommand implements SubCommand { } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } 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 a5b14c4d..b1c73093 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 @@ -6,25 +6,24 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; - import java.util.Collections; import java.util.List; public class RemoveDestiSubCommand implements SubCommand { - @Inject DestinationServices destinationServices; @Override public void onCommand(CommandSenderContainer sender, String[] args) { if (args.length > 1) { - if (destinationServices.removeDestination(args[1], sender.getPlayerContainer())) { + if (destinationServices.removeDestination( + args[1], sender.getPlayerContainer())) { sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.destination.remove.complete")); + Lang.translate("messageprefix.positive") + + Lang.translate("command.destination.remove.complete")); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.destination.remove.error")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.destination.remove.error")); } } else { sender.sendMessage(Lang.translate("command.destination.noname")); @@ -37,7 +36,8 @@ public class RemoveDestiSubCommand implements SubCommand { } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { if (args.length > 2) { return Collections.emptyList(); } 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 index 818529b7..6fe0abe9 100644 --- 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 @@ -13,17 +13,16 @@ import com.sekwah.advancedportals.core.services.PlayerDataServices; 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; import java.util.Objects; /** - * This will be different from the old show command and I believe it is 1.16+ till the latest - * version as of writing this. + * 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 { - +public class ShowDestiSubCommand + implements SubCommand, SubCommand.SubCommandOnInit { @Inject PlayerDataServices tempDataServices; @Inject GameScheduler gameScheduler; @@ -40,20 +39,21 @@ public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnI public void onCommand(CommandSenderContainer sender, String[] args) { if (core.getMcVersion()[1] < 16) { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.portal.show.unsupported")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.portal.show.unsupported")); return; } - var tempData = tempDataServices.getPlayerData(sender.getPlayerContainer()); + var tempData = + tempDataServices.getPlayerData(sender.getPlayerContainer()); if (tempData.isDestiVisible()) { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.destination.show.disabled")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.destination.show.disabled")); } else { sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.destination.show.enabled")); + Lang.translate("messageprefix.positive") + + Lang.translate("command.destination.show.enabled")); } tempData.setDestiVisible(!tempData.isDestiVisible()); } @@ -64,7 +64,8 @@ public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnI } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } @@ -80,30 +81,26 @@ public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnI @Override public void registered() { - gameScheduler.intervalTickEvent( - "show_portal", - () -> { - for (PlayerContainer player : serverContainer.getPlayers()) { - var tempData = tempDataServices.getPlayerData(player); - if (!tempData.isDestiVisible()) { - continue; - } + gameScheduler.intervalTickEvent("show_portal", () -> { + for (PlayerContainer player : serverContainer.getPlayers()) { + var tempData = tempDataServices.getPlayerData(player); + if (!tempData.isDestiVisible()) { + continue; + } - for (Destination destination : destinationServices.getDestinations()) { - var pos = destination.getLoc(); - if (Objects.equals(pos.getWorldName(), player.getWorldName()) - && pos.distanceTo(player.getLoc()) < config.getVisibleRange()) { - Debug.addMarker( - player, - pos.toBlockPos(), + for (Destination destination : + destinationServices.getDestinations()) { + var pos = destination.getLoc(); + if (Objects.equals(pos.getWorldName(), + player.getWorldName()) + && pos.distanceTo(player.getLoc()) + < config.getVisibleRange()) { + Debug.addMarker(player, pos.toBlockPos(), destination.getArgValues("name")[0], - new Color(100, 100, 100, 100), - 1300); - } - } + new Color(100, 100, 100, 100), 1300); } - }, - 1, - 20); + } + } + }, 1, 20); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java index 72d7d1bb..4b03feaa 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java @@ -6,27 +6,26 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; - import java.util.Collections; import java.util.List; public class TeleportDestiSubCommand implements SubCommand { - @Inject DestinationServices destinationServices; @Override public void onCommand(CommandSenderContainer sender, String[] args) { if (args.length > 1) { - if (destinationServices.teleportToDestination(args[1], sender.getPlayerContainer())) { + if (destinationServices.teleportToDestination( + args[1], sender.getPlayerContainer())) { sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.destination.teleport.success") - .replaceAll("@destiname", args[1])); + Lang.translate("messageprefix.positive") + + Lang.translate("command.destination.teleport.success") + .replaceAll("@destiname", args[1])); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.destination.teleport.error") - .replaceAll("@destiname", args[1])); + Lang.translate("messageprefix.negative") + + Lang.translate("command.destination.teleport.error") + .replaceAll("@destiname", args[1])); } } else { sender.sendMessage(Lang.translate("command.destination.noname")); @@ -39,7 +38,8 @@ public class TeleportDestiSubCommand implements SubCommand { } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { if (args.length > 2) { return Collections.emptyList(); } 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 b7700ab0..d44ad663 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 @@ -16,13 +16,11 @@ 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; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CreatePortalSubCommand extends CreateTaggedSubCommand { - @Inject PortalServices portalServices; @Inject TagRegistry tagRegistry; @@ -36,9 +34,8 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand { if (args.length > 1) { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { - sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.create.console")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.create.console")); return; } @@ -46,31 +43,31 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand { // Find the tag with the "name" NAME DataTag nameTag = - portalTags.stream() - .filter( - tag -> { - this.infoLogger.info("Tag: " + tag.NAME); - this.infoLogger.info( - "Equals: " + tag.NAME.equals(NameTag.TAG_NAME)); - return tag.NAME.equals(NameTag.TAG_NAME); - }) - .findFirst() - .orElse(null); + portalTags.stream() + .filter(tag -> { + this.infoLogger.info("Tag: " + tag.NAME); + this.infoLogger.info( + "Equals: " + tag.NAME.equals(NameTag.TAG_NAME)); + return tag.NAME.equals(NameTag.TAG_NAME); + }) + .findFirst() + .orElse(null); - // If the tag is null, check if arg[1] has a : to check it's not a tag. + // If the tag is null, check if arg[1] has a : to check it's not a + // tag. if (nameTag == null && !args[1].contains(":")) { nameTag = new DataTag("name", args[1]); portalTags.add(nameTag); } if (nameTag == null) { - sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.error.noname")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.error.noname")); return; } - sender.sendMessage(Lang.centeredTitle(Lang.translate("command.create.portal.prep"))); + sender.sendMessage(Lang.centeredTitle( + Lang.translate("command.create.portal.prep"))); sender.sendMessage(""); sender.sendMessage(Lang.translate("command.create.tags")); @@ -81,38 +78,37 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand { sender.sendMessage(""); var triggerBlockTag = - portalTags.stream() - .filter(tag -> tag.NAME.equals(TriggerBlockTag.TAG_NAME)) - .findFirst() - .orElse(null); + portalTags.stream() + .filter(tag -> tag.NAME.equals(TriggerBlockTag.TAG_NAME)) + .findFirst() + .orElse(null); if (triggerBlockTag == null) { - portalTags.add( - new DataTag(TriggerBlockTag.TAG_NAME, config.getDefaultTriggerBlock())); + portalTags.add(new DataTag(TriggerBlockTag.TAG_NAME, + config.getDefaultTriggerBlock())); } - AdvancedPortal portal = portalServices.createPortal(player, portalTags); + AdvancedPortal portal = + portalServices.createPortal(player, portalTags); if (portal != null) { - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.create.complete")); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.create.complete")); sender.sendMessage(Lang.translate("command.create.tags")); this.printTags(sender, portal.getArgs()); } else { - sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.create.error")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.create.error")); } } else { - sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.error.notags")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.error.notags")); } } @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() + || PortalPermissions.CREATE_PORTAL.hasPermission(sender); } @Override @@ -120,8 +116,10 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand { var tags = tagRegistry.getTags(); // Filter tags that support Destination return tags.stream() - .filter(tag -> Arrays.asList(tag.getTagTypes()).contains(Tag.TagType.PORTAL)) - .toList(); + .filter(tag + -> Arrays.asList(tag.getTagTypes()) + .contains(Tag.TagType.PORTAL)) + .toList(); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java index c8f5db97..8aea9f98 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java @@ -7,39 +7,36 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.permissions.PortalPermissions; 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.translate("messageprefix.negative") - + Lang.translate("command.playeronly")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.playeronly")); } else { player.giveItem( - "BLACK_WOOL", - "\u00A78Gateway Block Placer", - "\u00A7r\u00A77This wool is made of a magical substance", - "\u00A7r\u00A7eRight Click\u00A77: Place portal block"); - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.gatewayblock")); + "BLACK_WOOL", "\u00A78Gateway Block Placer", + "\u00A7r\u00A77This wool is made of a magical substance", + "\u00A7r\u00A7eRight Click\u00A77: Place portal block"); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.gatewayblock")); } } @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() + || PortalPermissions.CREATE_PORTAL.hasPermission(sender); } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java index 6907460e..417d6ab6 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java @@ -7,39 +7,36 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.permissions.PortalPermissions; 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.translate("messageprefix.negative") - + Lang.translate("command.playeronly")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.playeronly")); } else { player.giveItem( - "BLACK_WOOL", - "\u00A78End Portal Block Placer", - "\u00A7r\u00A77This wool is made of a magical substance", - "\u00A7r\u00A7eRight Click\u00A77: Place portal block"); - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.endportalblock")); + "BLACK_WOOL", "\u00A78End Portal Block Placer", + "\u00A7r\u00A77This wool is made of a magical substance", + "\u00A7r\u00A7eRight Click\u00A77: Place portal block"); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.endportalblock")); } } @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() + || PortalPermissions.CREATE_PORTAL.hasPermission(sender); } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java index 819b1f81..b4552a69 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java @@ -7,7 +7,6 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.util.Lang; - import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -18,76 +17,76 @@ import java.util.Map; import java.util.stream.Collectors; public class LangUpdateSubCommand implements SubCommand { - @Inject private AdvancedPortalsCore portalsCore; @Inject private ConfigRepository configRepository; - public LangUpdateSubCommand() {} + public LangUpdateSubCommand() { + } @Override public void onCommand(CommandSenderContainer sender, String[] args) { if (args.length > 1 && args[1].equalsIgnoreCase("overwrite")) { - this.portalsCore - .getDataStorage() - .copyDefaultFile("lang/" + configRepository.getTranslation() + ".lang", true); - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("translatedata.replaced")); + this.portalsCore.getDataStorage().copyDefaultFile( + "lang/" + configRepository.getTranslation() + ".lang", true); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("translatedata.replaced")); Lang.loadLanguage(configRepository.getTranslation()); } else { - // TODO check what keys are missing and append them to the end of the file, check the - // translation first then GB + // TODO check what keys are missing and append them to the end of + // the file, check the translation first then GB Lang lang = Lang.instance; Map internalTranslation = - lang.getInternalLanguageMap(Lang.DEFAULT_LANG); + lang.getInternalLanguageMap(Lang.DEFAULT_LANG); internalTranslation.putAll( - lang.getInternalLanguageMap(configRepository.getTranslation())); + lang.getInternalLanguageMap(configRepository.getTranslation())); Map currentTranslation = - lang.getLanguageMap(configRepository.getTranslation()); + lang.getLanguageMap(configRepository.getTranslation()); // Remove everything to leave just the missing keys - for (Map.Entry entry : currentTranslation.entrySet()) { + for (Map.Entry entry : + currentTranslation.entrySet()) { internalTranslation.remove(entry.getKey()); } List newTranslations = new ArrayList<>(); - for (Map.Entry entry : internalTranslation.entrySet()) { + for (Map.Entry entry : + internalTranslation.entrySet()) { newTranslations.add(entry.getKey() + "=" + entry.getValue()); } String appendText = String.join("\n", newTranslations); InputStream translationFile = - this.portalsCore - .getDataStorage() - .loadResource("lang/" + configRepository.getTranslation() + ".lang"); + this.portalsCore.getDataStorage().loadResource( + "lang/" + configRepository.getTranslation() + ".lang"); String result = - new BufferedReader(new InputStreamReader(translationFile)) - .lines() - .collect(Collectors.joining("\n")); - InputStream withExtras = - new ByteArrayInputStream(result.concat("\n").concat(appendText).getBytes()); - this.portalsCore - .getDataStorage() - .writeResource( - withExtras, "lang/" + configRepository.getTranslation() + ".lang"); + new BufferedReader(new InputStreamReader(translationFile)) + .lines() + .collect(Collectors.joining("\n")); + InputStream withExtras = new ByteArrayInputStream( + result.concat("\n").concat(appendText).getBytes()); + this.portalsCore.getDataStorage().writeResource( + withExtras, + "lang/" + configRepository.getTranslation() + ".lang"); Lang.loadLanguage(configRepository.getTranslation()); sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translateInsertVariables( - "translatedata.updated", newTranslations.size())); + Lang.translate("messageprefix.positive") + + Lang.translateInsertVariables("translatedata.updated", + newTranslations.size())); } } @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.LANG_UPDATE.hasPermission(sender); + return sender.isOp() + || PortalPermissions.LANG_UPDATE.hasPermission(sender); } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java index 67499468..bd5a7b48 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java @@ -5,23 +5,19 @@ import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; - import java.util.List; import java.util.stream.Collectors; public class ListPortalsSubCommand implements SubCommand { - @Inject PortalServices portalServices; @Override public void onCommand(CommandSenderContainer sender, String[] args) { sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.portal.list") - + " " - + portalServices.getPortalNames().stream() - .sorted() - .collect(Collectors.joining(", "))); + Lang.translate("messageprefix.positive") + + Lang.translate("command.portal.list") + " " + + portalServices.getPortalNames().stream().sorted().collect( + Collectors.joining(", "))); } @Override @@ -30,7 +26,8 @@ public class ListPortalsSubCommand implements SubCommand { } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java index 6bbe30ca..2706cebd 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java @@ -7,44 +7,39 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.permissions.PortalPermissions; 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.translate("messageprefix.negative") - + Lang.translate("command.playeronly")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.playeronly")); } else { player.giveItem( - "PURPLE_WOOL", - "\u00A75Portal Block Placer", - "\u00A7r\u00A77This wool is made of a magical substance", - "\u00A7r\u00A7e" - + Lang.translate("items.interact.left") - + "\u00A77: Rotate portal block", - "\u00A7r\u00A7e" - + Lang.translate("items.interact.right") - + "\u00A77: Place portal block"); - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.portalblock")); + "PURPLE_WOOL", "\u00A75Portal Block Placer", + "\u00A7r\u00A77This wool is made of a magical substance", + "\u00A7r\u00A7e" + Lang.translate("items.interact.left") + + "\u00A77: Rotate portal block", + "\u00A7r\u00A7e" + Lang.translate("items.interact.right") + + "\u00A77: Place portal block"); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.portalblock")); } } @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() + || PortalPermissions.CREATE_PORTAL.hasPermission(sender); } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java index 725ec0fb..4cabb53a 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java @@ -9,11 +9,9 @@ import com.sekwah.advancedportals.core.repository.ConfigRepository; 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; public class ReloadPortalSubCommand implements SubCommand { - @Inject private AdvancedPortalsCore portalsCore; @Inject PortalServices portalServices; @@ -28,9 +26,8 @@ public class ReloadPortalSubCommand implements SubCommand { portalServices.loadPortals(); destinationServices.loadDestinations(); Lang.loadLanguage(configRepository.getTranslation()); - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.reload.reloaded")); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.reload.reloaded")); } @Override @@ -39,7 +36,8 @@ public class ReloadPortalSubCommand implements SubCommand { } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java index 0f399402..4fd0fa83 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java @@ -6,24 +6,23 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; - import java.util.List; public class RemovePortalSubCommand implements SubCommand { - @Inject PortalServices portalServices; @Override public void onCommand(CommandSenderContainer sender, String[] args) { if (args.length > 1) { - if (portalServices.removePortal(args[1], sender.getPlayerContainer())) { + if (portalServices.removePortal(args[1], + sender.getPlayerContainer())) { sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.portal.remove.complete")); + Lang.translate("messageprefix.positive") + + Lang.translate("command.portal.remove.complete")); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.portal.remove.error")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.portal.remove.error")); } } else { sender.sendMessage(Lang.translate("command.portal.remove.noname")); @@ -32,11 +31,13 @@ public class RemovePortalSubCommand implements SubCommand { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() + || PortalPermissions.CREATE_PORTAL.hasPermission(sender); } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return portalServices.getPortalNames(); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java index b0b532c8..d115d6f2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java @@ -8,11 +8,9 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.permissions.PortalPermissions; 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; @@ -21,36 +19,34 @@ public class SelectorSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { - sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.playeronly")); + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.playeronly")); } else { player.giveItem( - configRepo.getSelectorMaterial(), - "\u00A7e" + Lang.translate("items.selector.name"), - "\u00A7r\u00A77This wand with has the power to help", - "\u00A7r\u00A77 create portals bistowed upon it!", - "", - "\u00A7r\u00A7e" - + Lang.translate("items.interact.left") - + "\u00A77: " - + Lang.translateInsertVariables("items.selector.pos", "1"), - "\u00A7r\u00A7e" - + Lang.translate("items.interact.right") - + "\u00A77: " - + Lang.translateInsertVariables("items.selector.pos", "2")); - sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.translate("command.selector")); + configRepo.getSelectorMaterial(), + "\u00A7e" + Lang.translate("items.selector.name"), + "\u00A7r\u00A77This wand with has the power to help", + "\u00A7r\u00A77 create portals bistowed upon it!", "", + "\u00A7r\u00A7e" + Lang.translate("items.interact.left") + + "\u00A77: " + + Lang.translateInsertVariables("items.selector.pos", "1"), + "\u00A7r\u00A7e" + Lang.translate("items.interact.right") + + "\u00A77: " + + Lang.translateInsertVariables("items.selector.pos", "2")); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.selector")); } } @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() + || PortalPermissions.CREATE_PORTAL.hasPermission(sender); } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } 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 1bad51ca..afd41b73 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 @@ -15,17 +15,16 @@ 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; import java.util.Objects; /** - * This will be different from the old show command and I believe it is 1.16+ till the latest - * version as of writing this. + * 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 ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOnInit { - +public class ShowPortalSubCommand + implements SubCommand, SubCommand.SubCommandOnInit { static final int SHOW_TICKS = 1010; boolean alternate_show_trigger = true; @@ -57,20 +56,20 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn public void onCommand(CommandSenderContainer sender, String[] args) { if (core.getMcVersion()[1] < 16) { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.portal.show.unsupported")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.portal.show.unsupported")); return; } - var tempData = playerDataServices.getPlayerData(sender.getPlayerContainer()); + var tempData = + playerDataServices.getPlayerData(sender.getPlayerContainer()); if (tempData.isPortalVisible()) { sender.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.portal.show.disabled")); + Lang.translate("messageprefix.negative") + + Lang.translate("command.portal.show.disabled")); } else { - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translate("command.portal.show.enabled")); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.portal.show.enabled")); } tempData.setPortalVisible(!tempData.isPortalVisible()); } @@ -81,7 +80,8 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } @@ -97,110 +97,88 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn @Override public void registered() { - gameScheduler.intervalTickEvent( - "show_portal", - () -> { - alternate_show_trigger = !alternate_show_trigger; - for (PlayerContainer player : serverContainer.getPlayers()) { - var tempData = playerDataServices.getPlayerData(player); - if (!tempData.isPortalVisible()) { - continue; - } + gameScheduler.intervalTickEvent("show_portal", () -> { + alternate_show_trigger = !alternate_show_trigger; + for (PlayerContainer player : serverContainer.getPlayers()) { + var tempData = playerDataServices.getPlayerData(player); + if (!tempData.isPortalVisible()) { + continue; + } - if (tempData.getPos1() != null - && tempData.getPos2() != null - && tempData.getPos1().getWorldName().equals(player.getWorldName()) - && tempData.getPos2() - .getWorldName() - .equals(player.getWorldName())) { - debugVisuals( - player, - tempData.getPos1(), - tempData.getPos2(), - SELECTION_COLOR, - SHOW_TICKS); - } + if (tempData.getPos1() != null && tempData.getPos2() != null + && tempData.getPos1().getWorldName().equals( + player.getWorldName()) + && tempData.getPos2().getWorldName().equals( + player.getWorldName())) { + debugVisuals(player, tempData.getPos1(), tempData.getPos2(), + SELECTION_COLOR, SHOW_TICKS); + } - if (tempData.getPos1() != null - && tempData.getPos1() - .getWorldName() - .equals(player.getWorldName())) { - Debug.addMarker( - player, tempData.getPos1(), "Pos1", POS1_COLOR, SHOW_TICKS); - } - if (tempData.getPos2() != null - && tempData.getPos2() - .getWorldName() - .equals(player.getWorldName())) { - Debug.addMarker( - player, tempData.getPos2(), "Pos2", POS2_COLOR, SHOW_TICKS); - } + if (tempData.getPos1() != null + && tempData.getPos1().getWorldName().equals( + player.getWorldName())) { + Debug.addMarker(player, tempData.getPos1(), "Pos1", + POS1_COLOR, SHOW_TICKS); + } + if (tempData.getPos2() != null + && tempData.getPos2().getWorldName().equals( + player.getWorldName())) { + Debug.addMarker(player, tempData.getPos2(), "Pos2", + POS2_COLOR, SHOW_TICKS); + } - var world = player.getWorld(); - for (var portal : portalServices.getPortals()) { - if (Objects.equals( - portal.getMinLoc().getWorldName(), - player.getWorldName()) - && portal.isLocationInPortal( - player.getLoc(), config.getVisibleRange())) { - BlockLocation minLoc = portal.getMinLoc(); - BlockLocation maxLoc = portal.getMaxLoc(); - int midX = (minLoc.getPosX() + maxLoc.getPosX()) / 2; - int midZ = (minLoc.getPosZ() + maxLoc.getPosZ()) / 2; - BlockLocation midPoint = - new BlockLocation( - minLoc.getWorldName(), - midX, - maxLoc.getPosY(), - midZ); - Color color; - if (portal.isTriggerBlock(world.getBlock(midPoint))) { - color = TRIGGER_OUTLINE_COLOR; - } else { - if (midPoint.getPosX() == minLoc.getPosX() - || midPoint.getPosX() == maxLoc.getPosX() - || midPoint.getPosZ() == minLoc.getPosZ() - || midPoint.getPosZ() == maxLoc.getPosZ()) - color = OUTLINE_COLOR; - else color = new Color(0, 0, 0, 0); - } - debugVisuals( - player, portal, OUTLINE_COLOR, SHOW_TICKS, TRIGGER_COLOR); - var name = portal.getArgValues(NameTag.TAG_NAME); - if (name != null && name.length > 0) { - Debug.addMarker(player, midPoint, name[0], color, SHOW_TICKS); - } - } + var world = player.getWorld(); + for (var portal : portalServices.getPortals()) { + if (Objects.equals(portal.getMinLoc().getWorldName(), + player.getWorldName()) + && portal.isLocationInPortal( + player.getLoc(), config.getVisibleRange())) { + BlockLocation minLoc = portal.getMinLoc(); + BlockLocation maxLoc = portal.getMaxLoc(); + int midX = (minLoc.getPosX() + maxLoc.getPosX()) / 2; + int midZ = (minLoc.getPosZ() + maxLoc.getPosZ()) / 2; + BlockLocation midPoint = + new BlockLocation(minLoc.getWorldName(), midX, + maxLoc.getPosY(), midZ); + Color color; + if (portal.isTriggerBlock(world.getBlock(midPoint))) { + color = TRIGGER_OUTLINE_COLOR; + } else { + if (midPoint.getPosX() == minLoc.getPosX() + || midPoint.getPosX() == maxLoc.getPosX() + || midPoint.getPosZ() == minLoc.getPosZ() + || midPoint.getPosZ() == maxLoc.getPosZ()) + color = OUTLINE_COLOR; + else + color = new Color(0, 0, 0, 0); + } + debugVisuals(player, portal, OUTLINE_COLOR, SHOW_TICKS, + TRIGGER_COLOR); + var name = portal.getArgValues(NameTag.TAG_NAME); + if (name != null && name.length > 0) { + Debug.addMarker(player, midPoint, name[0], color, + SHOW_TICKS); } } - }, - 1, - 20); + } + } + }, 1, 20); } - private void debugVisuals( - PlayerContainer player, BlockLocation pos1, BlockLocation pos2, Color color, int time) { + private void debugVisuals(PlayerContainer player, BlockLocation pos1, + BlockLocation pos2, Color color, int time) { debugVisuals(player, pos1, pos2, color, time, null, null); } - private void debugVisuals( - PlayerContainer player, - AdvancedPortal portal, - Color color, - int time, - Color triggerColor) { - debugVisuals( - player, portal.getMinLoc(), portal.getMaxLoc(), color, time, triggerColor, portal); + private void debugVisuals(PlayerContainer player, AdvancedPortal portal, + Color color, int time, Color triggerColor) { + debugVisuals(player, portal.getMinLoc(), portal.getMaxLoc(), color, + time, triggerColor, portal); } - private void debugVisuals( - PlayerContainer player, - BlockLocation pos1, - BlockLocation pos2, - Color color, - int time, - Color triggerColor, - AdvancedPortal portal) { + private void debugVisuals(PlayerContainer player, BlockLocation pos1, + BlockLocation pos2, Color color, int time, + Color triggerColor, AdvancedPortal portal) { int minX = Math.min(pos1.getPosX(), pos2.getPosX()); int minY = Math.min(pos1.getPosY(), pos2.getPosY()); int minZ = Math.min(pos1.getPosZ(), pos2.getPosZ()); @@ -221,105 +199,83 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { for (int z = minZ; z <= maxZ; z++) { - var pos = new BlockLocation(pos1.getWorldName(), x, y, z); - boolean isTrigger = - portal != null && portal.isTriggerBlock(world.getBlock(pos)); - boolean isOutline = - (y == minY || y == maxY) - && (x == minX || x == maxX || z == minZ - || z == maxZ) - || (z == minZ || z == maxZ) && (x == minX || x == maxX); + var pos = + new BlockLocation(pos1.getWorldName(), x, y, z); + boolean isTrigger = portal != null + && portal.isTriggerBlock(world.getBlock(pos)); + boolean isOutline = (y == minY || y == maxY) + && (x == minX || x == maxX || z == minZ + || z == maxZ) + || (z == minZ || z == maxZ) + && (x == minX || x == maxX); if (isTrigger && isOutline && alternate_show_trigger) { - Debug.addMarker(player, pos, "", TRIGGER_OUTLINE_COLOR, time); + Debug.addMarker(player, pos, "", + TRIGGER_OUTLINE_COLOR, time); } else if (isOutline) { Debug.addMarker(player, pos, "", color, time); } else if (isTrigger) { if (alternate_show_trigger) - Debug.addMarker(player, pos, "", triggerColor, time); + Debug.addMarker(player, pos, "", triggerColor, + time); } } } } } else { - for (int x = minX; x <= maxX; x++) { Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), x, minY, minZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), x, minY, minZ), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), x, minY, maxZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), x, minY, maxZ), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), x, maxY, minZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), x, maxY, minZ), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), x, maxY, maxZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), x, maxY, maxZ), "", + color, time); } for (int z = minZ + 1; z < maxZ; z++) { Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), minX, minY, z), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), minX, minY, z), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), maxX, minY, z), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), maxX, minY, z), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), minX, maxY, z), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), minX, maxY, z), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), maxX, maxY, z), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), maxX, maxY, z), "", + color, time); } for (int y = minY + 1; y < maxY; y++) { Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), minX, y, minZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), minX, y, minZ), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), maxX, y, minZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), maxX, y, minZ), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), minX, y, maxZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), minX, y, maxZ), "", + color, time); Debug.addMarker( - player, - new BlockLocation(pos1.getWorldName(), maxX, y, maxZ), - "", - color, - time); + player, + new BlockLocation(pos1.getWorldName(), maxX, y, maxZ), "", + color, time); } } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java index 678a44ae..048d194f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java @@ -4,17 +4,14 @@ 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.translate("messageprefix.positive") - + " Advanced Portals v" - + AdvancedPortalsCore.version); + sender.sendMessage(Lang.translate("messageprefix.positive") + + " Advanced Portals v" + + AdvancedPortalsCore.version); } @Override @@ -23,7 +20,8 @@ public class VersionSubCommand implements SubCommand { } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandHandler.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandHandler.java index af59e140..9d60d1ee 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandHandler.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandHandler.java @@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.connector.commands; import com.sekwah.advancedportals.core.commands.CommandTemplate; public abstract class CommandHandler { - private final CommandTemplate commandExecutor; public CommandHandler(CommandTemplate commandExecutor) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandRegister.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandRegister.java index a4abeb5c..a2c2345d 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandRegister.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/commands/CommandRegister.java @@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.connector.commands; import com.sekwah.advancedportals.core.commands.CommandTemplate; public interface CommandRegister { - /** * Registers the command to the appropriate system * diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java index f0b077d5..937dc644 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java @@ -1,7 +1,6 @@ package com.sekwah.advancedportals.core.connector.containers; public interface CommandSenderContainer { - void sendMessage(String message); boolean isOp(); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/EntityContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/EntityContainer.java index 867ed5b3..c1f89625 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/EntityContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/EntityContainer.java @@ -5,7 +5,6 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.serializeddata.Vector; public interface EntityContainer { - PlayerLocation getLoc(); double getHeight(); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java index 185796e5..f51fb6b8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java @@ -1,12 +1,13 @@ package com.sekwah.advancedportals.core.connector.containers; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; - import java.util.UUID; -/** Just a temporary container for whenever advanced portals needs to get data from a player */ +/** + * Just a temporary container for whenever advanced portals needs to get data + * from a player + */ public interface PlayerContainer extends EntityContainer { - UUID getUUID(); void sendMessage(String message); @@ -28,7 +29,8 @@ public interface PlayerContainer extends EntityContainer { * @param material * @param data */ - void sendFakeBlockWithData(BlockLocation blockPos, String material, byte data); + void sendFakeBlockWithData(BlockLocation blockPos, String material, + byte data); void giveItem(String material, String itemName, String... itemDescription); 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 050019b2..c074612d 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 @@ -4,7 +4,6 @@ import java.util.List; import java.util.UUID; public interface ServerContainer { - WorldContainer getWorld(String name); PlayerContainer getPlayer(String name); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java index d1caf238..186142a5 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java @@ -4,7 +4,6 @@ import com.sekwah.advancedportals.core.data.BlockAxis; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; public interface WorldContainer { - void setBlock(BlockLocation location, String material); String getBlock(BlockLocation location); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/data/BlockAxis.java b/core/src/main/java/com/sekwah/advancedportals/core/data/BlockAxis.java index a0f28bb8..489f19ba 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/data/BlockAxis.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/data/BlockAxis.java @@ -1,7 +1,3 @@ package com.sekwah.advancedportals.core.data; -public enum BlockAxis { - X, - Y, - Z -} +public enum BlockAxis { X, Y, Z } 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 13d6480b..8db517f1 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 @@ -8,24 +8,23 @@ import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Set; /** - * Possibly look at adding the ability to add some tags to destinations such as permissions. Would - * make it easier to add permissions to block access to certain areas and such. Could be a different - * permission system or just it takes the tags on the destination and automatically applies them - * when a portal wants to warp to there. (Of course it would not work cross server unless the data - * was communicated and checked first however that could affect performance and would definitely - * affect speed) + * Possibly look at adding the ability to add some tags to destinations such as + * permissions. Would make it easier to add permissions to block access to + * certain areas and such. Could be a different permission system or just it + * takes the tags on the destination and automatically applies them when a + * portal wants to warp to there. (Of course it would not work cross server + * unless the data was communicated and checked first however that could affect + * performance and would definitely affect speed) * * @author sekwah41 */ public class Destination implements TagTarget { - @Inject transient TagRegistry tagRegistry; private PlayerLocation loc; @@ -53,7 +52,8 @@ public class Destination implements TagTarget { } @Override - public void addArg(String argName, String argValues) {} + public void addArg(String argName, String argValues) { + } public void setArgValues(DataTag portalTag) { this.setArgValues(portalTag.NAME, portalTag.VALUES); @@ -77,16 +77,19 @@ public class Destination implements TagTarget { destiTags[i++] = new DataTag(entry.getKey(), entry.getValue()); } for (DataTag destiTag : destiTags) { - Tag.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME); + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(destiTag.NAME); if (activationHandler != null) { activationHandler.preActivated( - this, player, data, this.getArgValues(destiTag.NAME)); + this, player, data, this.getArgValues(destiTag.NAME)); } } for (DataTag destiTag : destiTags) { - Tag.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME); + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(destiTag.NAME); if (activationHandler != null) { - activationHandler.activated(this, player, data, this.getArgValues(destiTag.NAME)); + activationHandler.activated(this, player, data, + this.getArgValues(destiTag.NAME)); } } return true; @@ -99,10 +102,11 @@ public class Destination implements TagTarget { destiTags[i++] = new DataTag(entry.getKey(), entry.getValue()); } for (DataTag destiTag : destiTags) { - Tag.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME); + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(destiTag.NAME); if (activationHandler != null) { activationHandler.postActivated( - this, player, data, this.getArgValues(destiTag.NAME)); + this, player, data, this.getArgValues(destiTag.NAME)); } } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/effect/WarpEffect.java b/core/src/main/java/com/sekwah/advancedportals/core/effect/WarpEffect.java index 8ffa2bb6..8c147d3f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/effect/WarpEffect.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/effect/WarpEffect.java @@ -3,19 +3,16 @@ package com.sekwah.advancedportals.core.effect; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; public interface WarpEffect { - enum Action { ENTER, EXIT; } interface Sound extends WarpEffect { - void onWarpSound(PlayerContainer player, Action action); } interface Visual extends WarpEffect { - void onWarpVisual(PlayerContainer player, Action action); } } 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 36a55ff5..b9b2f7f9 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 @@ -17,14 +17,11 @@ import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.serializeddata.config.Config; import com.sekwah.advancedportals.core.serializeddata.config.ConfigProvider; import com.sekwah.advancedportals.core.util.InfoLogger; - import java.util.ArrayList; import java.util.List; - import javax.annotation.Nonnull; public class AdvancedPortalsModule extends AbstractModule { - private Injector injector; private AdvancedPortalsCore advancedPortalsCore; private DataStorage dataStorage; @@ -35,19 +32,31 @@ public class AdvancedPortalsModule extends AbstractModule { this.advancedPortalsCore = advancedPortalsCore; } - /** https://github.com/google/guice/wiki/Bindings */ + /** + * https://github.com/google/guice/wiki/Bindings + */ @Override protected void configure() { - bind(IPortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON); - bind(IDestinationRepository.class).to(DestinationRepositoryImpl.class).in(Scopes.SINGLETON); - bind(IPlayerDataRepository.class).to(PlayerDataRepositoryImpl.class).in(Scopes.SINGLETON); - bind(ConfigRepository.class).to(ConfigRepositoryImpl.class).in(Scopes.SINGLETON); + bind(IPortalRepository.class) + .to(PortalRepositoryImpl.class) + .in(Scopes.SINGLETON); + bind(IDestinationRepository.class) + .to(DestinationRepositoryImpl.class) + .in(Scopes.SINGLETON); + bind(IPlayerDataRepository.class) + .to(PlayerDataRepositoryImpl.class) + .in(Scopes.SINGLETON); + bind(ConfigRepository.class) + .to(ConfigRepositoryImpl.class) + .in(Scopes.SINGLETON); // Instances bind(AdvancedPortalsCore.class).toInstance(advancedPortalsCore); bind(InfoLogger.class).toInstance(advancedPortalsCore.getInfoLogger()); - bind(DataStorage.class).toInstance(advancedPortalsCore.getDataStorage()); - bind(ServerContainer.class).toInstance(advancedPortalsCore.getServerContainer()); + 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/permissions/PortalPermissions.java b/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java index 3125ac7d..9f885263 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java @@ -2,22 +2,26 @@ package com.sekwah.advancedportals.core.permissions; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; - import java.util.List; public class PortalPermissions { + private static final PermissionBuilder PERMISSIONS = + new PermissionBuilder("advancedportals"); - private static final PermissionBuilder PERMISSIONS = new PermissionBuilder("advancedportals"); - - public static final PermissionBuilder BUILD = PERMISSIONS.createChild("build"); - public static final PermissionBuilder DESTI = PERMISSIONS.createChild("desti"); - public static final PermissionBuilder CREATE_PORTAL = PERMISSIONS.createChild("createportal"); - public static final PermissionBuilder LANG_UPDATE = PERMISSIONS.createChild("langupdate"); - public static final PermissionBuilder RELOAD = PERMISSIONS.createChild("reload"); + public static final PermissionBuilder BUILD = + PERMISSIONS.createChild("build"); + public static final PermissionBuilder DESTI = + PERMISSIONS.createChild("desti"); + public static final PermissionBuilder CREATE_PORTAL = + PERMISSIONS.createChild("createportal"); + public static final PermissionBuilder LANG_UPDATE = + PERMISSIONS.createChild("langupdate"); + public static final PermissionBuilder RELOAD = + PERMISSIONS.createChild("reload"); /** - * this will not currently build the permissions for the files, but maybe at some point. It'll - * just make it easier though. + * this will not currently build the permissions for the files, but maybe at + * some point. It'll just make it easier though. */ public static class PermissionBuilder { private final String permissionTag; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java b/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java index f6e51dd4..67e713bd 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java @@ -13,14 +13,12 @@ import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.*; /** * @author sekwah41 */ public class AdvancedPortal implements TagTarget { - @Inject private transient TagRegistry tagRegistry; private BlockLocation maxLoc; @@ -38,11 +36,9 @@ public class AdvancedPortal implements TagTarget { this.maxLoc = new BlockLocation(); } - public AdvancedPortal( - BlockLocation minLoc, - BlockLocation maxLoc, - TagRegistry tagRegistry, - PlayerDataServices playerDataServices) { + public AdvancedPortal(BlockLocation minLoc, BlockLocation maxLoc, + TagRegistry tagRegistry, + PlayerDataServices playerDataServices) { this.tagRegistry = tagRegistry; this.playerDataServices = playerDataServices; this.updateBounds(minLoc, maxLoc); @@ -105,24 +101,28 @@ public class AdvancedPortal implements TagTarget { }*/ /** - * @param player The player on the server attempting to use an advanced portal - * @param moveActivated if the portal was activated by a move event (won't trigger knockback) + * @param player The player on the server attempting to use an advanced + * portal + * @param moveActivated if the portal was activated by a move event (won't + * trigger knockback) * @return */ public boolean activate(PlayerContainer player, boolean moveActivated) { var playerData = playerDataServices.getPlayerData(player); - if (playerData.isInPortal()) return false; + if (playerData.isInPortal()) + return false; playerData.setInPortal(true); if (playerData.hasJoinCooldown()) { - var cooldown = (int) Math.ceil(playerData.getJoinCooldownLeft() / 1000D); - player.sendMessage( - Lang.translateInsertVariables( - "portal.cooldown.join", - cooldown, - Lang.translate(cooldown == 1 ? "time.second" : "time.seconds"))); + var cooldown = + (int) Math.ceil(playerData.getJoinCooldownLeft() / 1000D); + player.sendMessage(Lang.translateInsertVariables( + "portal.cooldown.join", cooldown, + Lang.translate(cooldown == 1 ? "time.second" + : "time.seconds"))); if (configRepository.playFailSound()) { var rand = new Random(); - player.playSound("block.portal.travel", 0.05f, rand.nextFloat() * 0.4F + 0.8F); + player.playSound("block.portal.travel", 0.05f, + rand.nextFloat() * 0.4F + 0.8F); } return false; } @@ -135,28 +135,33 @@ public class AdvancedPortal implements TagTarget { } for (DataTag portalTag : portalTags) { - Tag.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(portalTag.NAME); if (activationHandler != null) { if (!activationHandler.preActivated( - this, player, data, this.getArgValues(portalTag.NAME))) { + this, player, data, + this.getArgValues(portalTag.NAME))) { return false; } } } for (DataTag portalTag : portalTags) { - Tag.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(portalTag.NAME); if (activationHandler != null) { if (!activationHandler.activated( - this, player, data, this.getArgValues(portalTag.NAME))) { + this, player, data, + this.getArgValues(portalTag.NAME))) { return false; } } } for (DataTag portalTag : portalTags) { - Tag.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(portalTag.NAME); if (activationHandler != null) { activationHandler.postActivated( - this, player, data, this.getArgValues(portalTag.NAME)); + this, player, data, this.getArgValues(portalTag.NAME)); } } if (data.hasActivated()) { @@ -184,12 +189,12 @@ public class AdvancedPortal implements TagTarget { double playerZ = loc.getPosZ(); return Objects.equals(loc.getWorldName(), this.minLoc.getWorldName()) - && playerX >= this.minLoc.getPosX() - additionalArea - && playerX < this.maxLoc.getPosX() + 1 + additionalArea - && playerY >= this.minLoc.getPosY() - additionalArea - && playerY < this.maxLoc.getPosY() + 1 + additionalArea - && playerZ >= this.minLoc.getPosZ() - additionalArea - && playerZ < this.maxLoc.getPosZ() + 1 + additionalArea; + && playerX >= this.minLoc.getPosX() - additionalArea + && playerX < this.maxLoc.getPosX() + 1 + additionalArea + && playerY >= this.minLoc.getPosY() - additionalArea + && playerY < this.maxLoc.getPosY() + 1 + additionalArea + && playerZ >= this.minLoc.getPosZ() - additionalArea + && playerZ < this.maxLoc.getPosZ() + 1 + additionalArea; } public void setArgValues(DataTag portalTag) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandErrorCode.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandErrorCode.java index 6377b81e..dd03911d 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandErrorCode.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandErrorCode.java @@ -4,5 +4,6 @@ public enum CommandErrorCode { INSUFFICIENT_ARGUMENTS(""), NO_PERMISSION(""); - CommandErrorCode(String message) {} + CommandErrorCode(String message) { + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandHandler.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandHandler.java index c2a4c6b4..ee794449 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandHandler.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/CommandHandler.java @@ -4,17 +4,13 @@ import com.google.common.collect.ImmutableList; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; public interface CommandHandler { - void onExecute( - String commandName, - String parentCommand, - CommandSenderContainer sender, - ImmutableList args); + void onExecute(String commandName, String parentCommand, + CommandSenderContainer sender, ImmutableList args); - default void onCommandFailure( - String[] command, - CommandSenderContainer sender, - CommandException exception, - ImmutableList args) { + default void onCommandFailure(String[] command, + CommandSenderContainer sender, + CommandException exception, + ImmutableList args) { sender.sendMessage(exception.getMessage()); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/RegisterBuilder.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/RegisterBuilder.java index d71cb32c..b7142309 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/RegisterBuilder.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/RegisterBuilder.java @@ -1,6 +1,5 @@ package com.sekwah.advancedportals.core.registry; - import java.lang.reflect.ParameterizedType; public class RegisterBuilder { @@ -8,14 +7,14 @@ public class RegisterBuilder { return new RegisterBuilder(); } - private RegisterBuilder() {} + private RegisterBuilder() { + } private boolean allowPermissionInheritance; private String scanDirectory; private final Class genericType = - (Class) - ((ParameterizedType) getClass().getGenericSuperclass()) - .getActualTypeArguments()[0]; + (Class) ((ParameterizedType) getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; public RegisterBuilder inheritPermissions(boolean allowInheritance) { allowPermissionInheritance = allowInheritance; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java index dac8ed07..578c419c 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java @@ -3,24 +3,26 @@ package com.sekwah.advancedportals.core.registry; import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.util.InfoLogger; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; /** - * Do not register to here. Register to the sprcific subcommand registry classes. + * Do not register to here. Register to the sprcific subcommand registry + * classes. * - *

Designed to let addons add new command sections to access, edit or add new functonality. + *

Designed to let addons add new command sections to access, edit or add + * new functonality. * * @author sekwah41 */ public class SubCommandRegistry { - protected Map subCommandMap = new HashMap<>(); - /** List of subcommand names which should be in order alphabetically */ + /** + * List of subcommand names which should be in order alphabetically + */ protected ArrayList subCommands = new ArrayList<>(); @Inject private InfoLogger infoLogger; @@ -31,14 +33,15 @@ public class SubCommandRegistry { * @return if the subcommand is registered or not */ public boolean registerSubCommand(String arg, SubCommand subCommand) { - if (subCommand == null) { - this.infoLogger.warning("The subcommand '" + arg + "' cannot be null."); + this.infoLogger.warning("The subcommand '" + arg + + "' cannot be null."); return false; } if (this.subCommandMap.containsKey(arg)) { - this.infoLogger.warning("The subcommand '" + arg + "' already exists."); + this.infoLogger.warning("The subcommand '" + arg + + "' already exists."); return false; } @@ -59,7 +62,8 @@ public class SubCommandRegistry { } /** - * I may be wrong but for larger lists containsKey is faster with a hashmap than arraylist. + * I may be wrong but for larger lists containsKey is faster with a hashmap + * than arraylist. * *

Though im not sure at what size it becomes more efficient. * diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java index 5f87ed73..49e9124a 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java @@ -3,19 +3,16 @@ package com.sekwah.advancedportals.core.registry; import com.google.inject.Inject; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.*; /** - * Allows a portal to register a tag and add a handler. If a plugin wants to add functionality - * to someone elses tag then they should use the events. + * Allows a portal to register a tag and add a handler. If a plugin wants to + * add functionality to someone elses tag then they should use the events. * * @author sekwah41 */ public class TagRegistry { - - @Inject - AdvancedPortalsCore portalsCore; + @Inject AdvancedPortalsCore portalsCore; private final ArrayList literalTags = new ArrayList<>(); @@ -25,8 +22,7 @@ public class TagRegistry { private final Map creationTags = new HashMap<>(); private final Map statusTags = new HashMap<>(); - @Inject - private AdvancedPortalsCore pluginCore; + @Inject private AdvancedPortalsCore pluginCore; /** * Portals to trigger when a portal is activated @@ -68,17 +64,19 @@ public class TagRegistry { this.tags.add(tag); // Check literal tags for clashes - if(this.literalTags.contains(tagName)) { - this.portalsCore.getInfoLogger().warning("A tag with the name " + tagName + " already exists."); + if (this.literalTags.contains(tagName)) { + this.portalsCore.getInfoLogger().warning( + "A tag with the name " + tagName + " already exists."); return false; } var aliases = tag.getAliases(); this.literalTags.add(tagName); - if(aliases != null) { + if (aliases != null) { for (String alias : aliases) { - if(this.literalTags.contains(alias)) { - this.portalsCore.getInfoLogger().warning("A tag with the alias " + alias + " already exists."); + if (this.literalTags.contains(alias)) { + this.portalsCore.getInfoLogger().warning( + "A tag with the alias " + alias + " already exists."); return false; } } @@ -103,7 +101,6 @@ public class TagRegistry { return true; } - public List getTags() { // TODO Make a copy of the list to prevent issues with modification diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/TagTarget.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/TagTarget.java index 1b67305c..9fac6d39 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/TagTarget.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/TagTarget.java @@ -1,8 +1,9 @@ package com.sekwah.advancedportals.core.registry; -/** Something that a tag can be executed on. */ +/** + * Something that a tag can be executed on. + */ public interface TagTarget { - /** * Get the values for the arg * diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java index 7e3e584d..534c5fe0 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java @@ -4,7 +4,6 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.effect.WarpEffect; import com.sekwah.advancedportals.core.util.InfoLogger; - import java.util.HashMap; import java.util.Map; @@ -12,15 +11,11 @@ import java.util.Map; * @author sekwah41 */ public class WarpEffectRegistry { - - private Map warpEffects = new HashMap(); - @Inject - private AdvancedPortalsCore portalsCore; + @Inject private AdvancedPortalsCore portalsCore; - @Inject - private InfoLogger infoLogger; + @Inject private InfoLogger infoLogger; /** * Register a new warp effect. @@ -30,50 +25,49 @@ public class WarpEffectRegistry { * @return if the effect was registered */ public void registerEffect(String name, WarpEffect effect) { - - if(name == null){ + if (name == null) { this.infoLogger.warning("Effect name cannot be null"); return; } - if(this.warpEffects.containsKey(name)){ - this.infoLogger.warning("Effect with the name: " + name + " already exists"); + if (this.warpEffects.containsKey(name)) { + this.infoLogger.warning("Effect with the name: " + name + + " already exists"); return; } this.warpEffects.put(name, effect); } - public WarpEffect.Visual getVisualEffect(String name){ - if(this.warpEffects.containsKey(name)) { + public WarpEffect.Visual getVisualEffect(String name) { + if (this.warpEffects.containsKey(name)) { var effect = this.warpEffects.get(name); - if(effect instanceof WarpEffect.Visual visual){ + if (effect instanceof WarpEffect.Visual visual) { return visual; - } - else{ - this.infoLogger.warning("Effect called " + name + " is not a visual effect"); + } else { + this.infoLogger.warning("Effect called " + name + + " is not a visual effect"); return null; } - } - else{ - this.infoLogger.warning("No effect called " + name + " was registered"); + } else { + this.infoLogger.warning("No effect called " + name + + " was registered"); return null; } } - public WarpEffect.Sound getSoundEffect(String name){ - if(this.warpEffects.containsKey(name)) { + public WarpEffect.Sound getSoundEffect(String name) { + if (this.warpEffects.containsKey(name)) { var effect = this.warpEffects.get(name); - if(effect instanceof WarpEffect.Sound sound){ + if (effect instanceof WarpEffect.Sound sound) { return sound; - } - else{ - this.infoLogger.warning("Effect called " + name + " is not a sound effect"); + } else { + this.infoLogger.warning("Effect called " + name + + " is not a sound effect"); return null; } - } - else{ - this.infoLogger.warning("No effect called " + name + " was registered"); + } else { + this.infoLogger.warning("No effect called " + name + + " was registered"); return null; } } - } 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 c164bc85..8cf4efb3 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 @@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.repository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; public interface ConfigRepository { - boolean getUseOnlySpecialAxe(); String getTranslation(); 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 869d1af3..7175b7b3 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 @@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.repository; import java.util.List; public interface IJsonRepository { - boolean save(String name, T t); boolean containsKey(String name); 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 7dfd00a6..35ab286e 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 @@ -4,12 +4,10 @@ import com.google.inject.Singleton; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.serializeddata.config.Config; - import java.util.HashMap; @Singleton public class ConfigRepositoryImpl implements ConfigRepository { - private HashMap configs; private Config config; private DataStorage dataStorage; @@ -19,11 +17,9 @@ public class ConfigRepositoryImpl implements ConfigRepository { } public T getValue(String output) { - try { return (T) configs.get(output); } catch (ClassCastException ignored) { - } return null; } 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 e5135b2f..5c4be467 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 @@ -5,10 +5,8 @@ import com.sekwah.advancedportals.core.destination.Destination; import com.sekwah.advancedportals.core.repository.IDestinationRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.tags.activation.NameTag; - import java.util.ArrayList; import java.util.List; - import javax.inject.Singleton; @Singleton @@ -19,7 +17,8 @@ public class DestinationRepositoryImpl implements IDestinationRepository { @Override public boolean save(String name, Destination destination) { - return dataStorage.storeFile(destination, fileLocation + name + ".yaml"); + return dataStorage.storeFile(destination, + fileLocation + name + ".yaml"); } public boolean containsKey(String name) { @@ -32,7 +31,8 @@ public class DestinationRepositoryImpl implements IDestinationRepository { } public Destination get(String name) { - return dataStorage.loadFile(Destination.class, fileLocation + name + ".yaml"); + return dataStorage.loadFile(Destination.class, + fileLocation + name + ".yaml"); } @Override @@ -49,7 +49,8 @@ public class DestinationRepositoryImpl implements IDestinationRepository { // Forces the name tag to be up-to-date on load String[] name = destination.getArgValues(NameTag.TAG_NAME); if (name != null && name.length > 0) { - destination.setArgValues(NameTag.TAG_NAME, new String[] {fileName}); + destination.setArgValues(NameTag.TAG_NAME, + new String[] {fileName}); } destinations.add(destination); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java index b3229d34..a2790d45 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java @@ -4,11 +4,9 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.repository.IPlayerDataRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.serializeddata.PlayerData; - import java.util.List; public class PlayerDataRepositoryImpl implements IPlayerDataRepository { - private final String fileLocation = "playerData/"; @Inject DataStorage dataStorage; @@ -30,7 +28,8 @@ public class PlayerDataRepositoryImpl implements IPlayerDataRepository { @Override public PlayerData get(String name) { - return dataStorage.loadFile(PlayerData.class, fileLocation + name + ".yaml"); + return dataStorage.loadFile(PlayerData.class, + fileLocation + name + ".yaml"); } @Override 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 ea7d8202..187a8a56 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 @@ -7,21 +7,20 @@ import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.repository.IPortalRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.tags.activation.NameTag; - import java.util.*; @Singleton public class PortalRepositoryImpl implements IPortalRepository { - private final String fileLocation = "portals/"; @Inject DataStorage dataStorage; /** - * In memory copy of the portal files as they will be accessed every movement tick. + * In memory copy of the portal files as they will be accessed every + * movement tick. * - *

If we need to get it by name we can just load it from the file, but this is good for - * looping fast for the player move events. + *

If we need to get it by name we can just load it from the file, but + * this is good for looping fast for the player move events. */ private List portals = new ArrayList<>(); @@ -42,9 +41,13 @@ public class PortalRepositoryImpl implements IPortalRepository { @Override public AdvancedPortal get(String name) { - var portal = dataStorage.loadFile(AdvancedPortal.class, fileLocation + name + ".yaml"); + var portal = dataStorage.loadFile(AdvancedPortal.class, + fileLocation + name + ".yaml"); if (portal != null) { - AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(portal); + AdvancedPortalsCore.getInstance() + .getModule() + .getInjector() + .injectMembers(portal); } return portal; } @@ -59,12 +62,14 @@ public class PortalRepositoryImpl implements IPortalRepository { List portals = new ArrayList<>(); List allFiles = dataStorage.listAllFiles(fileLocation, false); for (String fileName : allFiles) { - AdvancedPortal portal = - dataStorage.loadFile(AdvancedPortal.class, fileLocation + fileName); + AdvancedPortal portal = dataStorage.loadFile( + AdvancedPortal.class, fileLocation + fileName); // Forces the name tag to be up-to-date on load String[] name = portal.getArgValues(NameTag.TAG_NAME); if (name != null && name.length > 0) { - portal.setArgValues(NameTag.TAG_NAME, new String[] {fileName.replace(".yaml", "")}); + portal.setArgValues( + NameTag.TAG_NAME, + new String[] {fileName.replace(".yaml", "")}); } portals.add(portal); } 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 a5cfc596..c49f5fe2 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 @@ -3,8 +3,8 @@ package com.sekwah.advancedportals.core.serializeddata; import com.sekwah.advancedportals.core.data.Direction; public class BlockLocation { - - // These should be treated as final, they only are not for serialization purposes + // These should be treated as final, they only are not for serialization + // purposes private final int posX; private final int posY; @@ -51,10 +51,9 @@ 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); + return location.posX == this.posX && location.posY == this.posY + && location.posZ == this.posZ + && location.worldName.equals(this.worldName); } public double distanceTo(BlockLocation pos) { @@ -73,6 +72,7 @@ public class BlockLocation { } public BlockLocation addY(int offsetY) { - return new BlockLocation(this.worldName, this.posX, (this.posY + offsetY), this.posZ); + return new BlockLocation(this.worldName, this.posX, + (this.posY + offsetY), this.posZ); } } 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 b938b509..43a32796 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 @@ -3,22 +3,19 @@ package com.sekwah.advancedportals.core.serializeddata; import com.google.inject.Inject; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.util.InfoLogger; - -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.LoaderOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.inspector.TagInspector; -import org.yaml.snakeyaml.nodes.Tag; - import java.io.*; import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.inspector.TagInspector; +import org.yaml.snakeyaml.nodes.Tag; public class DataStorage { - private final File dataFolder; @Inject private AdvancedPortalsCore portalsCore; @@ -30,10 +27,10 @@ public class DataStorage { } private Yaml getYaml(Class clazz) { - LoaderOptions loaderOptions = new LoaderOptions(); - TagInspector tagInspector = tag -> tag.getClassName().equals(clazz.getName()); + TagInspector tagInspector = + tag -> tag.getClassName().equals(clazz.getName()); loaderOptions.setTagInspector(tagInspector); @@ -44,7 +41,10 @@ public class DataStorage { representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); var constructor = new ReflectiveConstructor(clazz, loaderOptions); - AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(constructor); + AdvancedPortalsCore.getInstance() + .getModule() + .getInjector() + .injectMembers(constructor); return new Yaml(constructor, representer); } @@ -64,16 +64,15 @@ public class DataStorage { if (yamlResource == null) { try { return dataHolder.getDeclaredConstructor().newInstance(); - } catch (InstantiationException - | IllegalAccessException - | NoSuchMethodException - | InvocationTargetException e) { + } catch (InstantiationException | IllegalAccessException + | NoSuchMethodException | InvocationTargetException e) { e.printStackTrace(); } return null; } Yaml yaml = getYaml(dataHolder); - try (BufferedReader bufReader = new BufferedReader(new InputStreamReader(yamlResource))) { + try (BufferedReader bufReader = + new BufferedReader(new InputStreamReader(yamlResource))) { return yaml.loadAs(bufReader, dataHolder); } catch (Exception e) { infoLogger.warning("Failed to load file: " + location); @@ -85,7 +84,8 @@ public class DataStorage { public boolean storeFile(Object dataHolder, String location) { Yaml yaml = getYaml(dataHolder.getClass()); File outFile = new File(this.dataFolder, location); - if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { + if (!outFile.getParentFile().exists() + && !outFile.getParentFile().mkdirs()) { infoLogger.warning("Failed to create folder for file: " + location); } @@ -103,8 +103,8 @@ public class DataStorage { * Copies the specified file out of the plugin and into the plugins folder. * * @param fileLoc - * @return if the file is copied, will be false if override is false and the file already - * existed. + * @return if the file is copied, will be false if override is false and the + * file already existed. */ public boolean copyDefaultFile(String fileLoc, boolean overwrite) { return this.copyDefaultFile(fileLoc, fileLoc, overwrite); @@ -115,10 +115,11 @@ public class DataStorage { * * @param sourceLoc - location of the file in the jar * @param fileLoc - location to save the file - * @return if the file is copied, will be false if override is false and the file already - * existed. + * @return if the file is copied, will be false if override is false and the + * file already existed. */ - public boolean copyDefaultFile(String sourceLoc, String fileLoc, boolean overwrite) { + public boolean copyDefaultFile(String sourceLoc, String fileLoc, + boolean overwrite) { File outFile = new File(this.dataFolder, fileLoc); if (!outFile.exists()) { outFile.getParentFile().mkdirs(); @@ -126,7 +127,8 @@ public class DataStorage { if (!outFile.exists() || overwrite) { try { InputStream inputStream = - this.getClass().getClassLoader().getResourceAsStream(sourceLoc); + this.getClass().getClassLoader().getResourceAsStream( + sourceLoc); if (inputStream == null) { return false; } @@ -134,11 +136,10 @@ public class DataStorage { writeToFile(inputStream, outFile); } catch (NullPointerException e) { e.printStackTrace(); - this.infoLogger.warning( - "Could not load " - + sourceLoc - + ". The file does" - + "not exist or there has been an error reading the file."); + this.infoLogger.warning("Could not load " + sourceLoc + + ". The file does" + + ("not exist or there has been an " + + "error reading the file.")); return false; } catch (FileNotFoundException e) { e.printStackTrace(); @@ -152,8 +153,8 @@ public class DataStorage { } /** - * A method to try to grab the files from the plugin and if its in the plugin folder load from - * there instead. + * A method to try to grab the files from the plugin and if its in the + * plugin folder load from there instead. * *

* @@ -172,14 +173,14 @@ public class DataStorage { } else { try { copyDefaultFile(location, false); - return this.getClass().getClassLoader().getResourceAsStream(location); + return this.getClass().getClassLoader().getResourceAsStream( + location); } catch (NullPointerException e) { e.printStackTrace(); - this.infoLogger.warning( - "Could not load " - + location - + ". The file does" - + "not exist or there has been an error reading the file."); + this.infoLogger.warning("Could not load " + location + + ". The file does" + + ("not exist or there has been an " + + "error reading the file.")); return null; } } @@ -194,7 +195,8 @@ public class DataStorage { } } - private void writeToFile(InputStream inputStream, File outFile) throws IOException { + private void writeToFile(InputStream inputStream, File outFile) + throws IOException { try (FileOutputStream outStream = new FileOutputStream(outFile)) { byte[] buf = new byte[1024]; int len; @@ -209,7 +211,8 @@ public class DataStorage { return new File(this.dataFolder, name).exists(); } - public List listAllFiles(String fileLocation, boolean trimExtension) { + public List listAllFiles(String fileLocation, + boolean trimExtension) { return listAllFiles(fileLocation, trimExtension, null); } @@ -219,7 +222,8 @@ public class DataStorage { * @param extension - if null will not filter by extension * @return */ - public List listAllFiles(String fileLocation, boolean trimExtension, String extension) { + public List listAllFiles(String fileLocation, boolean trimExtension, + String extension) { File directory = new File(dataFolder, fileLocation); List list = new ArrayList<>(); @@ -230,7 +234,8 @@ public class DataStorage { if (file.isFile()) { String fileName = file.getName(); boolean extensionMatches = - (extension == null || fileName.endsWith("." + extension)); + (extension == null + || fileName.endsWith("." + extension)); if (extensionMatches) { if (trimExtension) { @@ -245,7 +250,9 @@ public class DataStorage { } } } else { - infoLogger.warning("Directory does not exist or is not a directory: " + fileLocation); + infoLogger.warning( + "Directory does not exist or is not a directory: " + + fileLocation); } return list; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataTag.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataTag.java index 0e113a60..a5b849f3 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataTag.java @@ -1,7 +1,6 @@ package com.sekwah.advancedportals.core.serializeddata; public class DataTag { - public final String NAME; public final String[] VALUES; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerData.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerData.java index 86a0a69d..4f83a1f8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerData.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerData.java @@ -3,32 +3,44 @@ package com.sekwah.advancedportals.core.serializeddata; import java.util.HashMap; /** - * Possibly one of the only files in this package not designed to be serialised. + * Possibly one of the only files in this package not designed to be + * serialised. * - *

Any temporary data about players will be stored here and cleaned up when the player leaves the - * server. + *

Any temporary data about players will be stored here and cleaned up when + * the player leaves the server. * - *

This is not a place to store long term data e.g. if you want to make a player unable to use a - * portal over hours/days. + *

This is not a place to store long term data e.g. if you want to make a + * player unable to use a portal over hours/days. */ public class PlayerData { - - /** Portal selection position 1 */ + /** + * Portal selection position 1 + */ private BlockLocation pos1; - /** Portal selection position 2 */ + /** + * Portal selection position 2 + */ private BlockLocation pos2; - /** If to show portals near the player */ + /** + * If to show portals near the player + */ private boolean portalVisible = false; - /** If to show destination blocks near the player */ + /** + * If to show destination blocks near the player + */ private boolean destiVisible; - /** If the player is in a portal. Stops re-triggering. */ + /** + * If the player is in a portal. Stops re-triggering. + */ private transient boolean isInPortal = false; - /** The next time System.currentTimeMillis() a player can use a portal. */ + /** + * The next time System.currentTimeMillis() a player can use a portal. + */ private transient long joinCooldown; private transient long netherPortalCooldown; @@ -94,7 +106,8 @@ public class PlayerData { } public void setNetherPortalCooldown(long netherPortalCooldown) { - this.netherPortalCooldown = System.currentTimeMillis() + netherPortalCooldown; + this.netherPortalCooldown = + System.currentTimeMillis() + netherPortalCooldown; } public boolean hasJoinCooldown() { @@ -106,12 +119,13 @@ public class PlayerData { } public void setPortalCooldown(String portalName, long cooldown) { - perPortalCooldowns.put(portalName, System.currentTimeMillis() + cooldown); + perPortalCooldowns.put(portalName, + System.currentTimeMillis() + cooldown); } public boolean hasPortalCooldown(String portalName) { return perPortalCooldowns.containsKey(portalName) - && System.currentTimeMillis() < perPortalCooldowns.get(portalName); + && System.currentTimeMillis() < perPortalCooldowns.get(portalName); } public double getPortalCooldownLeft(String portalName) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerLocation.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerLocation.java index 82a690c8..197c8baf 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerLocation.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerLocation.java @@ -1,7 +1,6 @@ package com.sekwah.advancedportals.core.serializeddata; public class PlayerLocation extends WorldLocation { - private final float yaw; private final float pitch; @@ -12,14 +11,15 @@ public class PlayerLocation extends WorldLocation { this.pitch = 0; } - public PlayerLocation(String worldName, double posX, double posY, double posZ) { + public PlayerLocation(String worldName, double posX, double posY, + double posZ) { super(worldName, posX, posY, posZ); this.yaw = 0; this.pitch = 0; } - public PlayerLocation( - String worldName, double posX, double posY, double posZ, float yaw, float pitch) { + public PlayerLocation(String worldName, double posX, double posY, + double posZ, float yaw, float pitch) { super(worldName, posX, posY, posZ); this.yaw = yaw; this.pitch = pitch; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java index 041da2ba..a9678feb 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java @@ -1,23 +1,21 @@ package com.sekwah.advancedportals.core.serializeddata; import com.sekwah.advancedportals.core.util.InfoLogger; +import java.lang.reflect.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.inject.Inject; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.nodes.*; import sun.misc.Unsafe; -import javax.inject.Inject; -import java.lang.reflect.*; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class ReflectiveConstructor extends Constructor { private static final Unsafe unsafe = getUnsafe(); private final Class clazz; - @Inject - private InfoLogger infoLogger; + @Inject private InfoLogger infoLogger; public ReflectiveConstructor(Class clazz, LoaderOptions loadingConfig) { super(clazz, loadingConfig); @@ -34,10 +32,11 @@ public class ReflectiveConstructor extends Constructor { return constructFromMappingNode(currentClass, (MappingNode) node); } else if (node instanceof ScalarNode scalarNode) { return constructFromScalarNode(scalarNode); - } else if(node instanceof SequenceNode sequenceNode) { + } else if (node instanceof SequenceNode sequenceNode) { return constructFromSequenceNode(sequenceNode); } else { - infoLogger.warning("Unexpected node type encountered: " + node.getClass().getSimpleName()); + infoLogger.warning("Unexpected node type encountered: " + + node.getClass().getSimpleName()); return null; } } @@ -58,9 +57,10 @@ public class ReflectiveConstructor extends Constructor { return array; } - private Object constructFromMappingNode(Class currentClass, MappingNode mappingNode) { - - // if the class is a hashmap, loop over the values and construct the objects + private Object constructFromMappingNode(Class currentClass, + MappingNode mappingNode) { + // if the class is a hashmap, loop over the values and construct the + // objects if (currentClass.equals(HashMap.class)) { Map values = new HashMap<>(); for (NodeTuple tuple : mappingNode.getValue()) { @@ -71,18 +71,23 @@ public class ReflectiveConstructor extends Constructor { if (node instanceof ScalarNode scalarNode) { var constructedItem = constructFromScalarNode(scalarNode); values.put(key, constructedItem); - } else if(node instanceof SequenceNode sequenceNode) { - var constructedItem = constructFromSequenceNode(sequenceNode); + } else if (node instanceof SequenceNode sequenceNode) { + var constructedItem = + constructFromSequenceNode(sequenceNode); values.put(key, constructedItem); } else if (node instanceof MappingNode mappingNodeChild) { try { - Object value = constructFromMappingNode(Object.class, mappingNodeChild); + Object value = constructFromMappingNode( + Object.class, mappingNodeChild); values.put(key, value); } catch (Exception e) { - infoLogger.warning("Failed to construct object from mapping node: " + e.getMessage()); + infoLogger.warning( + "Failed to construct object from mapping node: " + + e.getMessage()); } } else { - infoLogger.warning("Unexpected node type encountered: " + node.getClass().getSimpleName()); + infoLogger.warning("Unexpected node type encountered: " + + node.getClass().getSimpleName()); } } return values; @@ -93,11 +98,14 @@ public class ReflectiveConstructor extends Constructor { try { instance = currentClass.getDeclaredConstructor().newInstance(); } catch (NoSuchMethodException e) { - infoLogger.info("No default constructor found for " + currentClass.getName() + ", using unsafe allocation."); + infoLogger.info("No default constructor found for " + + currentClass.getName() + + ", using unsafe allocation."); instance = unsafe.allocateInstance(currentClass); } - Map mappedValues = mapMappingNode(currentClass, mappingNode); + Map mappedValues = + mapMappingNode(currentClass, mappingNode); Field[] fields = getAllFields(currentClass); for (Field field : fields) { @@ -111,19 +119,28 @@ public class ReflectiveConstructor extends Constructor { setField(instance, field, value); } else { - infoLogger.warning("Field " + field.getName() + " not found in mapping node " + instance.getClass().getName() + " will use default value."); + infoLogger.warning("Field " + field.getName() + + " not found in mapping node " + + instance.getClass().getName() + + " will use default value."); } - } - catch (Exception e) { - infoLogger.warning("Failed to set field " + field.getName() + " in " + currentClass.getName() + ": " + e.getMessage()); + } catch (Exception e) { + infoLogger.warning("Failed to set field " + field.getName() + + " in " + currentClass.getName() + + ": " + e.getMessage()); infoLogger.error(e); - throw new RuntimeException("Failed to set field " + field.getName() + " in " + currentClass.getName(), e); + throw new RuntimeException("Failed to set field " + + field.getName() + " in " + + currentClass.getName(), + e); } } return instance; } catch (Exception e) { - infoLogger.warning("Failed to instantiate " + currentClass.getName() + ": " + e.getMessage()); - throw new RuntimeException("Failed to instantiate " + currentClass.getName(), e); + infoLogger.warning("Failed to instantiate " + currentClass.getName() + + ": " + e.getMessage()); + throw new RuntimeException( + "Failed to instantiate " + currentClass.getName(), e); } } @@ -142,7 +159,8 @@ public class ReflectiveConstructor extends Constructor { return super.constructObject(scalarNode); } - private Map mapMappingNode(Class currentClass, MappingNode mappingNode) { + private Map mapMappingNode(Class currentClass, + MappingNode mappingNode) { Map values = new HashMap<>(); for (NodeTuple tuple : mappingNode.getValue()) { var key = (String) super.constructObject(tuple.getKeyNode()); @@ -154,13 +172,16 @@ public class ReflectiveConstructor extends Constructor { } else if (node instanceof MappingNode mappingNodeChild) { try { var field = currentClass.getDeclaredField(key); - Object value = constructFromMappingNode(field.getType(), mappingNodeChild); + Object value = constructFromMappingNode(field.getType(), + mappingNodeChild); values.put(key, value); } catch (NoSuchFieldException e) { - infoLogger.warning("Field " + key + " not found on " + currentClass.getName()); + infoLogger.warning("Field " + key + " not found on " + + currentClass.getName()); } } else { - infoLogger.warning("Expected mapping node: " + node.getClass().getSimpleName()); + infoLogger.warning("Expected mapping node: " + + node.getClass().getSimpleName()); } } return values; @@ -169,14 +190,14 @@ public class ReflectiveConstructor extends Constructor { /** * Check and convert value types e.g. double to float */ - private void setField(Object instance, Field field, Object value) throws IllegalAccessException { - + private void setField(Object instance, Field field, Object value) + throws IllegalAccessException { // Check for numeric type compatibility and cast if necessary - if (field.getType() == float.class && value instanceof Double) { + if (field.getType() == float.class &&value instanceof Double) { value = ((Double) value).floatValue(); - } else if (field.getType() == int.class && value instanceof Long) { + } else if (field.getType() == int.class &&value instanceof Long) { value = ((Long) value).intValue(); - } else if (field.getType() == short.class && value instanceof Integer) { + } else if (field.getType() == short.class &&value instanceof Integer) { value = ((Integer) value).shortValue(); } else if (field.getType() == byte.class && value instanceof Integer) { value = ((Integer) value).byteValue(); @@ -186,7 +207,6 @@ public class ReflectiveConstructor extends Constructor { field.set(instance, value); } - private static Unsafe getUnsafe() { try { Field f = Unsafe.class.getDeclaredField("theUnsafe"); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveRepresenter.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveRepresenter.java index 6117aa16..291bc8db 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveRepresenter.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveRepresenter.java @@ -5,7 +5,6 @@ import org.yaml.snakeyaml.introspector.BeanAccess; import org.yaml.snakeyaml.representer.Representer; public class ReflectiveRepresenter extends Representer { - public ReflectiveRepresenter(DumperOptions options) { super(options); this.getPropertyUtils().setBeanAccess(BeanAccess.FIELD); 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 168732aa..0ca8f503 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 @@ -1,19 +1,17 @@ package com.sekwah.advancedportals.core.serializeddata; public class WorldLocation extends Vector { - public final String worldName; - public WorldLocation(String worldName, double posX, double posY, double posZ) { + public WorldLocation(String worldName, double posX, double posY, + double posZ) { super(posX, posY, posZ); this.worldName = worldName; } public BlockLocation toBlockPos() { - return new BlockLocation( - this.worldName, - (int) Math.floor(this.x), - (int) Math.floor(this.y), - (int) Math.floor(this.z)); + return new BlockLocation(this.worldName, (int) Math.floor(this.x), + (int) Math.floor(this.y), + (int) Math.floor(this.z)); } } 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 81801ff0..d1216ab6 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 @@ -1,8 +1,9 @@ package com.sekwah.advancedportals.core.serializeddata.config; -/** To store the data for config */ +/** + * To store the data for config + */ public class Config { - public boolean useOnlySpecialAxe = true; public String selectorMaterial = "IRON_AXE"; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/Creation.java b/core/src/main/java/com/sekwah/advancedportals/core/services/Creation.java index 754c0041..5b6f1ea9 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/Creation.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/Creation.java @@ -1,7 +1,3 @@ package com.sekwah.advancedportals.core.services; -public enum Creation { - SUCCESS, - NAME_IN_USE, - TAG_REJECTED -} +public enum Creation { SUCCESS, NAME_IN_USE, TAG_REJECTED } 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 cb2218ce..668a8e2f 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 @@ -9,17 +9,14 @@ import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.inject.Singleton; @Singleton public class DestinationServices { - @Inject private IDestinationRepository destinationRepository; @Inject TagRegistry tagRegistry; @@ -43,38 +40,40 @@ public class DestinationServices { } } - public Destination createDesti(PlayerLocation playerLocation, List tags) { + public Destination createDesti(PlayerLocation playerLocation, + List tags) { return createDesti(null, playerLocation, tags); } - public Destination createDesti( - PlayerContainer player, PlayerLocation playerLocation, List tags) { + public Destination createDesti(PlayerContainer player, + PlayerLocation playerLocation, + List tags) { // Find the tag with the "name" NAME - DataTag nameTag = - tags.stream().filter(tag -> tag.NAME.equals("name")).findFirst().orElse(null); + DataTag nameTag = tags.stream() + .filter(tag -> tag.NAME.equals("name")) + .findFirst() + .orElse(null); 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 (player != null) - player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("desti.error.noname")); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("desti.error.noname")); return null; } if (name == null || name.equals("")) { if (player != null) - player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.error.noname")); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.error.noname")); return null; } else if (this.destinationRepository.containsKey(name)) { if (player != null) - player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translateInsertVariables("command.error.nametaken", name)); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translateInsertVariables( + "command.error.nametaken", name)); return null; } @@ -83,7 +82,8 @@ public class DestinationServices { desti.setArgValues(portalTag); } for (DataTag destiTag : tags) { - Tag.Creation creation = tagRegistry.getCreationHandler(destiTag.NAME); + Tag.Creation creation = + tagRegistry.getCreationHandler(destiTag.NAME); if (creation != null) { if (!creation.created(desti, player, destiTag.VALUES)) { return null; @@ -98,13 +98,14 @@ public class DestinationServices { } } catch (Exception e) { e.printStackTrace(); - player.sendMessage( - Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save")); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("desti.error.save")); } return desti; } - public boolean removeDestination(String name, PlayerContainer playerContainer) { + public boolean removeDestination(String name, + PlayerContainer playerContainer) { this.destinationCache.remove(name); if (this.destinationRepository.containsKey(name)) { this.destinationRepository.delete(name); @@ -117,9 +118,11 @@ public class DestinationServices { return destinationCache.get(name); } - public boolean teleportToDestination(String name, PlayerContainer playerContainer) { + public boolean teleportToDestination(String name, + PlayerContainer playerContainer) { if (this.destinationRepository.containsKey(name)) { - playerContainer.teleport(this.destinationRepository.get(name).getLoc()); + playerContainer.teleport( + this.destinationRepository.get(name).getLoc()); return true; } return false; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java index 37ef2ff8..e275d97a 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java @@ -7,17 +7,16 @@ import com.sekwah.advancedportals.core.repository.IPlayerDataRepository; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.PlayerData; import com.sekwah.advancedportals.core.util.Lang; - import java.util.HashMap; import java.util.Map; import java.util.UUID; - import javax.inject.Singleton; @Singleton public final class PlayerDataServices { - - /** Possibly change to the cache map Aztec was talking about */ + /** + * Possibly change to the cache map Aztec was talking about + */ private Map tempDataMap = new HashMap<>(); @Inject private IPlayerDataRepository tempDataRepository; @@ -25,16 +24,14 @@ public final class PlayerDataServices { @Inject private ConfigRepository configRepository; public PlayerData getPlayerData(PlayerContainer player) { - return tempDataMap.computeIfAbsent( - player.getUUID(), - uuid -> { - var tempData = tempDataRepository.get(player.getUUID().toString()); + return tempDataMap.computeIfAbsent(player.getUUID(), uuid -> { + var tempData = tempDataRepository.get(player.getUUID().toString()); - if (tempData == null) { - tempData = new PlayerData(); - } - return tempData; - }); + if (tempData == null) { + tempData = new PlayerData(); + } + return tempData; + }); } public void setJoinCooldown(PlayerContainer player) { @@ -43,24 +40,22 @@ public final class PlayerDataServices { } public void playerLeave(PlayerContainer player) { - tempDataRepository.save(player.getUUID().toString(), getPlayerData(player)); + tempDataRepository.save(player.getUUID().toString(), + getPlayerData(player)); tempDataMap.remove(player.getUUID()); } - public void playerSelectorActivate( - PlayerContainer player, BlockLocation blockLoc, boolean leftClick) { + public void playerSelectorActivate(PlayerContainer player, + BlockLocation blockLoc, + boolean leftClick) { var tempData = getPlayerData(player); if (leftClick) { tempData.setPos1(blockLoc); } else { tempData.setPos2(blockLoc); } - player.sendMessage( - Lang.translateInsertVariables( - "portal.selector.poschange", - leftClick ? "1" : "2", - blockLoc.getPosX(), - blockLoc.getPosY(), - blockLoc.getPosZ())); + player.sendMessage(Lang.translateInsertVariables( + "portal.selector.poschange", leftClick ? "1" : "2", + blockLoc.getPosX(), blockLoc.getPosY(), blockLoc.getPosZ())); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java index 31d660de..324e2568 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java @@ -14,14 +14,11 @@ import com.sekwah.advancedportals.core.tags.activation.NameTag; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.PlayerUtils; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.*; - import javax.inject.Singleton; @Singleton public class PortalServices { - @Inject private IPortalRepository portalRepository; @Inject private transient PlayerDataServices playerDataServices; @@ -47,7 +44,8 @@ public class PortalServices { public boolean inPortalRegionProtected(BlockLocation loc) { for (AdvancedPortal portal : portalCache.values()) { - if (portal.isLocationInPortal(loc, configRepository.getProtectionRadius())) { + if (portal.isLocationInPortal( + loc, configRepository.getProtectionRadius())) { return true; } } @@ -56,7 +54,8 @@ public class PortalServices { public boolean inPortalRegionProtected(PlayerLocation loc) { for (AdvancedPortal portal : portalCache.values()) { - if (portal.isLocationInPortal(loc, configRepository.getProtectionRadius())) { + if (portal.isLocationInPortal( + loc, configRepository.getProtectionRadius())) { return true; } } @@ -73,7 +72,6 @@ public class PortalServices { } public void playerMove(PlayerContainer player, PlayerLocation toLoc) { - var blockLoc = toLoc.toBlockPos(); var blockEntityTopLoc = blockLoc.addY(player.getHeight()); var world = player.getWorld(); @@ -82,9 +80,10 @@ public class PortalServices { var notInPortal = true; for (AdvancedPortal portal : portalCache.values()) { - if ((portal.isLocationInPortal(toLoc) && portal.isTriggerBlock(blockMaterial)) - || (portal.isLocationInPortal(blockEntityTopLoc) - && portal.isTriggerBlock(blockEntityTopMaterial))) { + if ((portal.isLocationInPortal(toLoc) + && portal.isTriggerBlock(blockMaterial)) + || (portal.isLocationInPortal(blockEntityTopLoc) + && portal.isTriggerBlock(blockEntityTopMaterial))) { notInPortal = false; if (portal.activate(player, true)) { return; @@ -118,62 +117,67 @@ public class PortalServices { return false; } - public AdvancedPortal createPortal(BlockLocation pos1, BlockLocation pos2, List tags) { + public AdvancedPortal createPortal(BlockLocation pos1, BlockLocation pos2, + List tags) { return createPortal(null, pos1, pos2, tags); } - public AdvancedPortal createPortal(PlayerContainer player, ArrayList tags) { + public AdvancedPortal createPortal(PlayerContainer player, + ArrayList tags) { PlayerData tempData = playerDataServices.getPlayerData(player); if (tempData.getPos1() == null || tempData.getPos2() == null) { player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("portal.error.selection.missing")); + Lang.translate("messageprefix.negative") + + Lang.translate("portal.error.selection.missing")); return null; } - if (!tempData.getPos1().getWorldName().equals(tempData.getPos2().getWorldName())) { + if (!tempData.getPos1().getWorldName().equals( + tempData.getPos2().getWorldName())) { player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("portal.error.selection.differentworlds")); + Lang.translate("messageprefix.negative") + + Lang.translate("portal.error.selection.differentworlds")); return null; } - return createPortal(player, tempData.getPos1(), tempData.getPos2(), tags); + return createPortal(player, tempData.getPos1(), tempData.getPos2(), + tags); } - public AdvancedPortal createPortal( - PlayerContainer player, BlockLocation pos1, BlockLocation pos2, List tags) { + public AdvancedPortal createPortal(PlayerContainer player, + BlockLocation pos1, BlockLocation pos2, + List tags) { // Find the tag with the "name" NAME - DataTag nameTag = - tags.stream() - .filter(tag -> tag.NAME.equals(NameTag.TAG_NAME)) - .findFirst() - .orElse(null); + DataTag nameTag = tags.stream() + .filter(tag -> tag.NAME.equals(NameTag.TAG_NAME)) + .findFirst() + .orElse(null); String name = nameTag == null ? null : nameTag.VALUES[0]; if (nameTag == null || name == null || name.isEmpty()) { if (player != null) - player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("command.error.noname")); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.error.noname")); return null; } else if (this.portalRepository.containsKey(name)) { if (player != null) - player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translateInsertVariables("command.error.nametaken", name)); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translateInsertVariables( + "command.error.nametaken", name)); return null; } - AdvancedPortal portal = new AdvancedPortal(pos1, pos2, tagRegistry, playerDataServices); + AdvancedPortal portal = + new AdvancedPortal(pos1, pos2, tagRegistry, playerDataServices); for (DataTag portalTag : tags) { portal.setArgValues(portalTag); } for (DataTag portalTag : tags) { - Tag.Creation creation = tagRegistry.getCreationHandler(portalTag.NAME); + Tag.Creation creation = + tagRegistry.getCreationHandler(portalTag.NAME); if (creation != null) { if (!creation.created(portal, player, portalTag.VALUES)) { return null; @@ -190,9 +194,8 @@ public class PortalServices { } catch (Exception e) { e.printStackTrace(); if (player != null) - player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("portal.error.save")); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("portal.error.save")); } return portal; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/CooldownTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/CooldownTag.java index 3683d635..574ddb09 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/CooldownTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/CooldownTag.java @@ -13,26 +13,20 @@ import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.PlayerUtils; import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; - -import javax.annotation.Nullable; import java.util.List; import java.util.Random; +import javax.annotation.Nullable; public class CooldownTag implements Tag.Activation, Tag.Creation { + @Inject transient PlayerDataServices playerDataServices; - @Inject - transient PlayerDataServices playerDataServices; + @Inject transient ConfigRepository configRepository; - @Inject - transient ConfigRepository configRepository; - - - @Inject - private InfoLogger infoLogger; + @Inject private InfoLogger infoLogger; public static String TAG_NAME = "cooldown"; - private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL }; + private final TagType[] tagTypes = new TagType[] {TagType.PORTAL}; @Override public TagType[] getTagTypes() { @@ -56,16 +50,22 @@ public class CooldownTag implements Tag.Activation, Tag.Creation { } @Override - public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + public boolean preActivated(TagTarget target, PlayerContainer player, + ActivationData activationData, + String[] argData) { var playerData = playerDataServices.getPlayerData(player); - if(target instanceof AdvancedPortal portal) { + if (target instanceof AdvancedPortal portal) { var portalName = portal.getName(); - if(playerData.hasPortalCooldown(portalName)) { - var cooldown = (int) Math.ceil(playerData.getPortalCooldownLeft(portalName) / 1000D); - player.sendMessage(Lang.translateInsertVariables("portal.cooldown.individual", cooldown, - Lang.translate(cooldown == 1 ? "time.second" : "time.seconds"))); - if(configRepository.playFailSound()) { - player.playSound("block.portal.travel", 0.05f, new Random().nextFloat() * 0.4F + 0.8F); + if (playerData.hasPortalCooldown(portalName)) { + var cooldown = (int) Math.ceil( + playerData.getPortalCooldownLeft(portalName) / 1000D); + player.sendMessage(Lang.translateInsertVariables( + "portal.cooldown.individual", cooldown, + Lang.translate(cooldown == 1 ? "time.second" + : "time.seconds"))); + if (configRepository.playFailSound()) { + player.playSound("block.portal.travel", 0.05f, + new Random().nextFloat() * 0.4F + 0.8F); } return false; } @@ -75,37 +75,44 @@ public class CooldownTag implements Tag.Activation, Tag.Creation { } @Override - public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { - if(activationData.hasActivated()) { - if(target instanceof AdvancedPortal portal) { + public void postActivated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData) { + if (activationData.hasActivated()) { + if (target instanceof AdvancedPortal portal) { var playerData = playerDataServices.getPlayerData(player); try { - playerData.setPortalCooldown(portal.getName(), Integer.parseInt(argData[0]) * 1000); + playerData.setPortalCooldown( + portal.getName(), Integer.parseInt(argData[0]) * 1000); } catch (NumberFormatException e) { - infoLogger.warning("Cooldown tag failed to set cooldown for portal: " + portal.getName() + " with value: " + argData[0]); + infoLogger.warning( + "Cooldown tag failed to set cooldown for portal: " + + portal.getName() + " with value: " + argData[0]); } } } } @Override - public boolean activated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + public boolean activated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData) { return true; } @Override - public boolean created(TagTarget target, PlayerContainer player, String[] argData) { + public boolean created(TagTarget target, PlayerContainer player, + String[] argData) { try { Integer.parseInt(argData[0]); } catch (NumberFormatException e) { - player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("tag.cooldown.fail")); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("tag.cooldown.fail")); return false; } return true; } @Override - public void destroyed(TagTarget target, PlayerContainer player, String[] argData) { - + public void destroyed(TagTarget target, PlayerContainer player, + String[] argData) { } } 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 ec8da425..130abec5 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 @@ -10,13 +10,10 @@ import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.List; - import javax.annotation.Nullable; public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split { - public static String TAG_NAME = "destination"; @Inject DestinationServices destinationServices; @@ -45,8 +42,8 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split { } @Override - public boolean preActivated( - TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + public boolean preActivated(TagTarget target, PlayerContainer player, + ActivationData activeData, String[] argData) { // Check that the destination exists. for (String destiName : destinationServices.getDestinationNames()) { if (destiName.equalsIgnoreCase(argData[0])) { @@ -57,19 +54,15 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split { } @Override - public void postActivated( - TagTarget target, - PlayerContainer player, - ActivationData activationData, - String[] argData) {} + public void postActivated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData) { + } @Override - public boolean activated( - TagTarget target, - PlayerContainer player, - ActivationData activationData, - String[] argData) { - Destination destination = destinationServices.getDestination(argData[0]); + public boolean activated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData) { + Destination destination = + destinationServices.getDestination(argData[0]); if (destination != null) { var warpEffectVisual = warpEffectRegistry.getVisualEffect("ender"); if (warpEffectVisual != null) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/NameTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/NameTag.java index 201f2841..0b995a0d 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/NameTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/NameTag.java @@ -4,24 +4,23 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.registry.TagTarget; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.List; - import javax.annotation.Nullable; /** * The name of the destination or portal. * - *

Most of the implementation of this tag is external, this is just to allow for the tag to be - * used. + *

Most of the implementation of this tag is external, this is just to allow + * for the tag to be used. * - *

Most tags shouldn't be like this unless they are to be paired with another tag. + *

Most tags shouldn't be like this unless they are to be paired with + * another tag. */ public class NameTag implements Tag.AutoComplete, Tag.Creation { - public static String TAG_NAME = "name"; - private final TagType[] tagTypes = new TagType[] {TagType.PORTAL, TagType.DESTINATION}; + private final TagType[] tagTypes = + new TagType[] {TagType.PORTAL, TagType.DESTINATION}; @Override public TagType[] getTagTypes() { @@ -55,13 +54,13 @@ public class NameTag implements Tag.AutoComplete, Tag.Creation { } @Override - public boolean created(TagTarget target, PlayerContainer player, String[] argData) { + public boolean created(TagTarget target, PlayerContainer player, + String[] argData) { if (argData.length > 0) { String name = argData[0]; if (name.contains(" ")) { - player.sendMessage( - Lang.translate("messageprefix.negative") - + Lang.translate("tag.name.error.nospaces")); + player.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("tag.name.error.nospaces")); return false; } } @@ -69,5 +68,7 @@ public class NameTag implements Tag.AutoComplete, Tag.Creation { } @Override - public void destroyed(TagTarget target, PlayerContainer player, String[] argData) {} + public void destroyed(TagTarget target, PlayerContainer player, + String[] argData) { + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/PermissionTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/PermissionTag.java index 1533144f..e41bd58d 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/PermissionTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/PermissionTag.java @@ -8,12 +8,10 @@ import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; - import javax.annotation.Nullable; import javax.inject.Inject; public class PermissionTag implements Tag.Activation { - @Inject transient PlayerDataServices playerDataServices; @Inject transient ConfigRepository configRepository; @@ -48,8 +46,8 @@ public class PermissionTag implements Tag.Activation { } @Override - public boolean preActivated( - TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + public boolean preActivated(TagTarget target, PlayerContainer player, + ActivationData activeData, String[] argData) { if (!player.hasPermission(argData[1])) { player.sendMessage(Lang.translate("portal.error.nopermission")); return false; @@ -58,18 +56,13 @@ public class PermissionTag implements Tag.Activation { } @Override - public void postActivated( - TagTarget target, - PlayerContainer player, - ActivationData activationData, - String[] argData) {} + public void postActivated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData) { + } @Override - public boolean activated( - TagTarget target, - PlayerContainer player, - ActivationData activationData, - String[] argData) { + public boolean activated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData) { return true; } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java index ab940ccd..72efee3e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java @@ -4,13 +4,10 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.Tag; - import java.util.List; - import javax.annotation.Nullable; public class TriggerBlockTag implements Tag.AutoComplete, Tag.Split { - @Inject private ServerContainer serverContainer; public static String TAG_NAME = "triggerblock"; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java b/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java index 1440c421..63bb426f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java @@ -2,31 +2,30 @@ package com.sekwah.advancedportals.core.util; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; - import java.awt.*; public class Debug { - public static boolean addMarker( - PlayerContainer player, - BlockLocation blockPos, - String name, - Color color, - int milliseconds) { + public static boolean addMarker(PlayerContainer player, + BlockLocation blockPos, String name, + Color color, int milliseconds) { FriendlyDataOutput out = new FriendlyDataOutput(); out.writeBlock(blockPos); out.writeInt(color(color)); out.writeUtf(name); out.writeInt(milliseconds); - return player.sendPacket("minecraft:debug/game_test_add_marker", out.toByteArray()); + return player.sendPacket("minecraft:debug/game_test_add_marker", + out.toByteArray()); } public static boolean clear(PlayerContainer player) { FriendlyDataOutput out = new FriendlyDataOutput(); - return player.sendPacket("minecraft:debug/game_test_clear", out.toByteArray()); + return player.sendPacket("minecraft:debug/game_test_clear", + out.toByteArray()); } public static int color(Color color) { - return color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + return color(color.getRed(), color.getGreen(), color.getBlue(), + color.getAlpha()); } public static int color(int r, int g, int b) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java b/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java index 51d1c6c4..aeafe78f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java @@ -1,16 +1,15 @@ package com.sekwah.advancedportals.core.util; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; - import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.EncoderException; - import java.nio.charset.StandardCharsets; -/** Meant to be similar to FriendlyByteBuf if you have used that before. */ +/** + * Meant to be similar to FriendlyByteBuf if you have used that before. + */ public class FriendlyDataOutput { - private final ByteBuf dataOutput; public FriendlyDataOutput() { @@ -51,14 +50,16 @@ public class FriendlyDataOutput { public void writeUtf(String text, int maxLength) { if (text.length() > maxLength) { - throw new EncoderException( - "String too big (was " + text.length() + " characters, max " + maxLength + ")"); + throw new EncoderException("String too big (was " + text.length() + + " characters, max " + maxLength + + ")"); } else { byte[] abyte = text.getBytes(StandardCharsets.UTF_8); int i = getMaxEncodedUtfLength(maxLength); if (abyte.length > i) { - throw new EncoderException( - "String too big (was " + abyte.length + " bytes encoded, max " + i + ")"); + throw new EncoderException("String too big (was " + abyte.length + + " bytes encoded, max " + i + + ")"); } else { this.writeVarInt(abyte.length); this.writeBytes(abyte); @@ -99,10 +100,11 @@ public class FriendlyDataOutput { // Only for block serialising and such private static final int PACKED_X_LENGTH = - 26; // 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000)) (im not gonna add all - // the mojang math stuff to calculate this. + 26; // 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000)) (im + // not gonna add all the mojang math stuff to calculate this. private static final int PACKED_Z_LENGTH = PACKED_X_LENGTH; - public static final int PACKED_Y_LENGTH = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH; + public static final int PACKED_Y_LENGTH = + 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH; private static final long PACKED_X_MASK = (1L << PACKED_X_LENGTH) - 1L; private static final long PACKED_Y_MASK = (1L << PACKED_Y_LENGTH) - 1L; private static final long PACKED_Z_MASK = (1L << PACKED_Z_LENGTH) - 1L; @@ -114,7 +116,6 @@ public class FriendlyDataOutput { } private long blockAsLong(BlockLocation blockLoc) { - long i = 0L; i |= ((long) blockLoc.getPosX() & PACKED_X_MASK) << X_OFFSET; i |= ((long) blockLoc.getPosY() & PACKED_Y_MASK) << 0; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java b/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java index 4021d6ee..56ebd7de 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java @@ -2,36 +2,44 @@ package com.sekwah.advancedportals.core.util; import java.util.ArrayList; import java.util.Iterator; - import javax.inject.Singleton; -/** For all delayed and repeating tasks. */ +/** + * For all delayed and repeating tasks. + */ @Singleton public final class GameScheduler { - - private final ArrayList newTickEvents = new ArrayList<>(); - private final ArrayList delayedTickEvents = new ArrayList<>(); + private final ArrayList newTickEvents = + new ArrayList<>(); + private final ArrayList delayedTickEvents = + new ArrayList<>(); public void tick() { this.delayedTickEvents.addAll(this.newTickEvents); this.newTickEvents.clear(); - Iterator tickEventIterator = this.delayedTickEvents.iterator(); + Iterator tickEventIterator = + this.delayedTickEvents.iterator(); while (tickEventIterator.hasNext()) { DelayedGameTickEvent event = tickEventIterator.next(); event.tick(); if (event.shouldRun()) { event.run(); - if (!(event instanceof DelayedGameIntervalEvent)) tickEventIterator.remove(); + if (!(event instanceof DelayedGameIntervalEvent)) + tickEventIterator.remove(); } } } - public void delayedTickEvent(String name, Runnable consumer, int tickDelay) { - this.newTickEvents.add(new DelayedGameTickEvent(name, consumer, tickDelay)); + public void delayedTickEvent(String name, Runnable consumer, + int tickDelay) { + this.newTickEvents.add( + new DelayedGameTickEvent(name, consumer, tickDelay)); } - public void intervalTickEvent(String name, Runnable consumer, int tickDelay, int interval) { - this.newTickEvents.add(new DelayedGameIntervalEvent(name, consumer, tickDelay, interval)); + public void intervalTickEvent(String name, Runnable consumer, int tickDelay, + int interval) { + this.newTickEvents.add( + new DelayedGameIntervalEvent(name, consumer, tickDelay, interval)); } public void clearAllEvents() { @@ -40,7 +48,6 @@ public final class GameScheduler { } public static class DelayedGameTickEvent { - // So we can find it later and remove it if needed public final String name; public final Runnable consumer; @@ -66,10 +73,10 @@ public final class GameScheduler { } public static class DelayedGameIntervalEvent extends DelayedGameTickEvent { - public int interval; - public DelayedGameIntervalEvent(String name, Runnable consumer, int ticks, int interval) { + public DelayedGameIntervalEvent(String name, Runnable consumer, + int ticks, int interval) { super(name, consumer, ticks); this.interval = interval; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/InfoLogger.java b/core/src/main/java/com/sekwah/advancedportals/core/util/InfoLogger.java index bc4a5005..e6ad52ee 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/InfoLogger.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/InfoLogger.java @@ -1,7 +1,6 @@ package com.sekwah.advancedportals.core.util; public abstract class InfoLogger { - /** * Problematic messages * diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java b/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java index cf667562..bc7869cc 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java @@ -2,7 +2,6 @@ package com.sekwah.advancedportals.core.util; import com.google.inject.Inject; import com.sekwah.advancedportals.core.serializeddata.DataStorage; - import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -13,13 +12,12 @@ import java.util.Scanner; /** * @author sekwah41 - *

The language translation file for the game. Will always load english first so that if the - * translations are missing any then they are still readable and can then be translated. (It's - * better than a raw translate string) - *

+ *

The language translation file for the game. Will always load english + * first so that if the translations are missing any then they are still + * readable and can then be translated. (It's better than a raw translate + * string)

*/ public class Lang { - public static final Lang instance = new Lang(); private final HashMap languageMap = new HashMap<>(); @@ -39,8 +37,10 @@ public class Lang { public static String translate(String s) { if (instance.languageMap.containsKey(s)) { String translation = instance.languageMap.get(s); - // noinspection ALL (not sure what the specific warning is for escaped unicode) - translation = translation.replaceAll("&([0-9a-frk-ox])", "\u00A7$1"); + // noinspection ALL (not sure what the specific warning is for + // escaped unicode) + translation = + translation.replaceAll("&([0-9a-frk-ox])", "\u00A7$1"); return translation; } else { return s; @@ -50,13 +50,15 @@ public class Lang { public static String translateInsertVariables(String s, Object... args) { String translation = translate(s); for (int i = 1; i <= args.length; i++) { - translation = translation.replaceAll("%" + i + "\\$s", args[i - 1].toString()); + translation = translation.replaceAll("%" + i + "\\$s", + args[i - 1].toString()); } return translation; } public Map getLanguageMap(String fileName) { - InputStream stream = this.dataStorage.loadResource("lang/" + fileName + ".lang"); + InputStream stream = + this.dataStorage.loadResource("lang/" + fileName + ".lang"); if (stream != null) { return Lang.parseLang(stream); } @@ -65,7 +67,8 @@ public class Lang { public Map getInternalLanguageMap(String fileName) { InputStream stream = - this.getClass().getClassLoader().getResourceAsStream("lang/" + fileName + ".lang"); + this.getClass().getClassLoader().getResourceAsStream( + "lang/" + fileName + ".lang"); if (stream != null) { return Lang.parseLang(stream); } @@ -92,8 +95,8 @@ public class Lang { } /** - * The default font is not monospaced, so this will likely be a little thinner to be on the safe - * side + * The default font is not monospaced, so this will likely be a little + * thinner to be on the safe side * * @param title * @return @@ -103,29 +106,28 @@ public class Lang { int eachSide = titleLength / 2; - return "\u00A7e" + "=".repeat(eachSide) + " " + title + " \u00A7e" + "=".repeat(eachSide); + return "\u00A7e" + + "=".repeat(eachSide) + " " + title + " \u00A7e" + + "=".repeat(eachSide); } private void injectTranslations(String fileName) { try { - URL url = - Lang.instance - .getClass() - .getClassLoader() - .getResource("lang/" + fileName + ".lang"); + URL url = Lang.instance.getClass().getClassLoader().getResource( + "lang/" + fileName + ".lang"); if (url != null) { - Map initialMap = Lang.parseLang(url.openStream()); + Map initialMap = + Lang.parseLang(url.openStream()); Lang.instance.languageMap.putAll(initialMap); } else { - this.infoLogger.warning( - "Could not load " - + fileName - + ".lang from within Advanced Portals as it doesn't exist."); + this.infoLogger.warning("Could not load " + fileName + + (".lang from within Advanced Portals " + + "as it doesn't exist.")); } } catch (IOException e) { e.printStackTrace(); - this.infoLogger.warning( - "Could not load " + fileName + ".lang from within Advanced Portals."); + this.infoLogger.warning("Could not load " + fileName + + ".lang from within Advanced Portals."); } Map newLangMap = this.getLanguageMap(fileName); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/PlayerUtils.java b/core/src/main/java/com/sekwah/advancedportals/core/util/PlayerUtils.java index a4304475..afd11ec8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/PlayerUtils.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/PlayerUtils.java @@ -3,9 +3,11 @@ package com.sekwah.advancedportals.core.util; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; public class PlayerUtils { - - public static void throwPlayerBack(PlayerContainer player, double strength) { + public static void throwPlayerBack(PlayerContainer player, + double strength) { var playerLoc = player.getLoc().getDirection(); - player.setVelocity(playerLoc.setY(0).normalize().multiply(-1).setY(0.5).multiply(strength)); + player.setVelocity( + playerLoc.setY(0).normalize().multiply(-1).setY(0.5).multiply( + strength)); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java b/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java index c1456724..da7d340c 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java @@ -1,12 +1,10 @@ package com.sekwah.advancedportals.core.util; import com.sekwah.advancedportals.core.serializeddata.DataTag; - import java.util.ArrayList; import java.util.HashMap; public class TagReader { - public static boolean isClosedString(String[] args) { StringBuilder currentValue = new StringBuilder(); boolean inQuotes = false; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/ActivationData.java b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/ActivationData.java index ea8c9de1..f1c1b7b3 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/ActivationData.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/ActivationData.java @@ -8,7 +8,6 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; * @author sekwah41 */ public class ActivationData { - private boolean warpAllowed = true; public final boolean moveActivated; @@ -28,15 +27,16 @@ public class ActivationData { public void setWarpStatus(WarpedStatus warped) { if (this.warpStatus == WarpedStatus.WARPED) { return; - } else if (this.warpStatus == WarpedStatus.ACTIVATED && warped != WarpedStatus.WARPED) { + } else if (this.warpStatus == WarpedStatus.ACTIVATED + && warped != WarpedStatus.WARPED) { return; } this.warpStatus = warped; } /** - * In case you need to set the status back down a step for whatever reason. However it is not - * recommended. + * In case you need to set the status back down a step for whatever reason. + * However it is not recommended. * * @param warped */ @@ -57,11 +57,20 @@ public class ActivationData { } public enum WarpedStatus { - /** Player has moved or something major has happened. (only one of these should activate) */ + /** + * Player has moved or something major has happened. (only one of these + * should activate) + */ WARPED, - /** Shows that the portal has been activated even if a major function is not performed. */ + /** + * Shows that the portal has been activated even if a major function is + * not performed. + */ ACTIVATED, - /** Nothing has activated on the portal (may need to come up with a new name) */ + /** + * Nothing has activated on the portal (may need to come up with a new + * name) + */ NOTACTIVATED; } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java index c26aaed3..94d3a87c 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java @@ -2,34 +2,32 @@ package com.sekwah.advancedportals.core.warphandler; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.registry.TagTarget; - import java.util.List; - import javax.annotation.Nullable; /** - * If a tag can be used for any of them then either make it cast the target or if it doesn't need a - * target then the exact same tag can be registered into both and ignore the portal info. + * If a tag can be used for any of them then either make it cast the target or + * if it doesn't need a target then the exact same tag can be registered into + * both and ignore the portal info. * - *

Will probably make better documentation on how to do so or some tutorial videos though take a - * look at the source code on GitHub for how the current tags are added. + *

Will probably make better documentation on how to do so or some tutorial + * videos though take a look at the source code on GitHub for how the current + * tags are added. * - *

Also, not sure if its good practice or not in java however these all extend TagHandler, so - * they can be accepted in 1 method nicer than if they didn't + *

Also, not sure if its good practice or not in java however these all + * extend TagHandler, so they can be accepted in 1 method nicer than if they + * didn't * * @author sekwah41 */ public interface Tag { - /** * By default, all tags should be able to use either. * - *

Though you may have use cases where you want to limit it to one or the other. + *

Though you may have use cases where you want to limit it to one or the + * other. */ - enum TagType { - PORTAL, - DESTINATION - } + enum TagType { PORTAL, DESTINATION } /** * Used to flag where the auto complete should show more or less info. @@ -40,41 +38,37 @@ public interface Tag { String getName(); - @Nullable - String[] getAliases(); + @Nullable String[] getAliases(); String description(); interface AutoComplete extends Tag { - /** - * This is used to get the auto complete for the tag. This is called when the player is - * typing the tag. + * This is used to get the auto complete for the tag. This is called + * when the player is typing the tag. * * @param argData * @return */ - @Nullable - List autoComplete(String argData); + @Nullable List autoComplete(String argData); - @Nullable - String splitString(); + @Nullable String splitString(); } interface Split extends Tag { - /** - * This is used to split the tag into the arguments if multiple are supported + * This is used to split the tag into the arguments if multiple are + * supported * * @return null if the tag does not support splitting */ - @Nullable - String splitString(); + @Nullable String splitString(); } - /** The events for portal creation and destroying */ + /** + * The events for portal creation and destroying + */ interface Creation extends Tag { - /** * Example if the player does not have access to use the tag. * @@ -82,45 +76,46 @@ public interface Tag { * @param argData * @return If the tag is valid or allowed creation */ - boolean created(TagTarget target, PlayerContainer player, String[] argData); + boolean created(TagTarget target, PlayerContainer player, + String[] argData); /** - * Example if the player does not have access to remove the portal or destination. + * Example if the player does not have access to remove the portal or + * destination. * * @param player if null then removed by the server or a plugin * @param argData */ - void destroyed(TagTarget target, PlayerContainer player, String[] argData); + void destroyed(TagTarget target, PlayerContainer player, + String[] argData); } /** - * Order of activation Portal and Desti: preActivated activated postActivated + * Order of activation Portal and Desti: preActivated activated + * postActivated * - *

Order of them combined: Portal.preActivated Portal.activated - when desti tag is hit (if - * listed) then next two actions are activated - Desti.preActivate - Desti.activate - * Portal.postActivate - when desti tag is hit (if listed) then the next action is activated - - * Desti.postActivate + *

Order of them combined: Portal.preActivated Portal.activated - when + * desti tag is hit (if listed) then next two actions are activated - + * Desti.preActivate - Desti.activate Portal.postActivate - when desti tag + * is hit (if listed) then the next action is activated - Desti.postActivate */ interface Activation extends Tag { - /** - * Activates before the main part of activation. This should be for prechecks e.g. if the - * player has enough money before then taking the money in postActivated. + * Activates before the main part of activation. This should be for + * prechecks e.g. if the player has enough money before then taking the + * money in postActivated. * * @param player * @param activeData * @param argData * @return If the tag has allowed the warp */ - boolean preActivated( - TagTarget target, - PlayerContainer player, - ActivationData activeData, - String[] argData); + boolean preActivated(TagTarget target, PlayerContainer player, + ActivationData activeData, String[] argData); /** - * Activates after activation, should be used for actions such as removing money for a - * teleport. + * Activates after activation, should be used for actions such as + * removing money for a teleport. * *

Any actions to do with player location should be done in activate * @@ -128,55 +123,57 @@ public interface Tag { * @param activationData * @param argData */ - void postActivated( - TagTarget target, - PlayerContainer player, - ActivationData activationData, - String[] argData); + void postActivated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData); /** - * Activates if the portal is allowed from preActivating. Should be used to set the intended - * warp location + * Activates if the portal is allowed from preActivating. Should be used + * to set the intended warp location * - *

You should do some second checks if it can be dependent on the preActivate, the - * destination tags will also be triggered here if a desti is listed. + *

You should do some second checks if it can be dependent on the + * preActivate, the destination tags will also be triggered here if a + * desti is listed. * * @param player * @param activationData * @param argData - * @return Action performed (only return false if the tag failed to do anything) + * @return Action performed (only return false if the tag failed to do + * anything) */ - boolean activated( - TagTarget target, - PlayerContainer player, - ActivationData activationData, - String[] argData); + boolean activated(TagTarget target, PlayerContainer player, + ActivationData activationData, String[] argData); } - /** Triggers when a tag is added or removed from a portal or destination */ + /** + * Triggers when a tag is added or removed from a portal or destination + */ interface TagStatus extends Tag { - /** - * If the user has access to add the tag (this does not include being added on creation) + * If the user has access to add the tag (this does not include being + * added on creation) * * @param target the target of the tag * @param player if null then removed by the server or a plugin * @param argData the data for the tag - * @param index the index of the tag in the list (if it is the only tag it will be 0) + * @param index the index of the tag in the list (if it is the only tag + * it will be 0) * @return if the tag will be added. */ - boolean tagAdded(TagTarget target, PlayerContainer player, int index, String argData); + boolean tagAdded(TagTarget target, PlayerContainer player, int index, + String argData); /** - * If the user has access to remove the tag (this does not include being added on - * destruction) + * If the user has access to remove the tag (this does not include being + * added on destruction) * * @param target the target of the tag * @param player if null then removed by the server or a plugin * @param argData the data of the tag to be removed - * @param index the index of the tag in the list (if it is the only tag it will be 0) + * @param index the index of the tag in the list (if it is the only tag + * it will be 0) * @return if the tag will be removed. */ - boolean tagRemoved(TagTarget target, PlayerContainer player, int index, String argData); + boolean tagRemoved(TagTarget target, PlayerContainer player, int index, + String argData); } } 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 b5478f6e..5d3c6522 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java @@ -11,9 +11,9 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.bukkit.plugin.java.JavaPlugin; public class AdvancedPortalsPlugin extends JavaPlugin { - private AdvancedPortalsCore portalsCore; /** diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java index 36124e06..1ca4b24f 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java @@ -17,11 +17,9 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.*; import org.bukkit.event.player.*; -import java.util.List; - /** - * Some of these will be passed to the core listener to handle the events, others it's easier to - * just check directly. + * Some of these will be passed to the core listener to handle the events, + * others it's easier to just check directly. */ public class Listeners implements Listener { @@ -60,9 +58,9 @@ public class Listeners implements Listener { @EventHandler public void onItemInteract(PlayerInteractEvent event) { if (!event.isCancelled() - && (event.getAction() == Action.LEFT_CLICK_BLOCK - || event.getAction() == Action.RIGHT_CLICK_BLOCK) - && event.getItem() != null) { + && (event.getAction() == Action.LEFT_CLICK_BLOCK + || event.getAction() == Action.RIGHT_CLICK_BLOCK) + && event.getItem() != null) { Location blockloc = event.getClickedBlock().getLocation(); boolean allowEvent = this.coreListeners.playerInteractWithBlock(new SpigotPlayerContainer(event.getPlayer()), event.getClickedBlock().getType().toString(), @@ -76,9 +74,10 @@ public class Listeners implements Listener { @EventHandler(ignoreCancelled = true) public void spawnMobEvent(CreatureSpawnEvent event) { - if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL - && portalServices.inPortalRegionProtected( - ContainerHelpers.toPlayerLocation(event.getLocation()))) { + if (event.getSpawnReason() + == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL + && portalServices.inPortalRegionProtected( + ContainerHelpers.toPlayerLocation(event.getLocation()))) { event.setCancelled(true); } } @@ -90,18 +89,16 @@ public class Listeners implements Listener { if (!configRepository.getStopWaterFlow()) { return; } - if (!coreListeners.blockPlace( - null, - ContainerHelpers.toBlockLocation(event.getBlock().getLocation()), - event.getBlock().getType().toString(), - null, - null) - || !coreListeners.blockPlace( - null, - ContainerHelpers.toBlockLocation(event.getToBlock().getLocation()), - event.getBlock().getType().toString(), - null, - null)) { + if (!coreListeners.blockPlace(null, + ContainerHelpers.toBlockLocation( + event.getBlock().getLocation()), + event.getBlock().getType().toString(), + null, null) + || !coreListeners.blockPlace(null, + ContainerHelpers.toBlockLocation( + event.getToBlock().getLocation()), + event.getBlock().getType().toString(), + null, null)) { event.setCancelled(true); } } @@ -111,19 +108,21 @@ public class Listeners implements Listener { var itemInHand = event.getPlayer().getItemInHand(); if (!coreListeners.blockBreak( new SpigotPlayerContainer(event.getPlayer()), - ContainerHelpers.toBlockLocation(event.getBlock().getLocation()), + ContainerHelpers.toBlockLocation( + event.getBlock().getLocation()), event.getBlock().getType().toString(), itemInHand == null ? null : itemInHand.getType().toString(), itemInHand == null || itemInHand.getItemMeta() == null - ? null - : itemInHand.getItemMeta().getDisplayName())) { + ? null + : itemInHand.getItemMeta().getDisplayName())) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGH) public void onExplosion(EntityExplodeEvent event) { - if (!configRepository.getPortalProtection()) return; + if (!configRepository.getPortalProtection()) + return; List blockList = event.blockList(); for (int i = 0; i < blockList.size(); i++) { diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java index ac179cd3..982b55f5 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java @@ -1,11 +1,9 @@ package com.sekwah.advancedportals.spigot; import com.sekwah.advancedportals.core.util.InfoLogger; - import java.util.logging.Level; public class SpigotInfoLogger extends InfoLogger { - private final AdvancedPortalsPlugin plugin; public SpigotInfoLogger(AdvancedPortalsPlugin plugin) { diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/UpdatePortalSubCommand.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/UpdatePortalSubCommand.java index 48d4e78b..da01a5a3 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/UpdatePortalSubCommand.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/UpdatePortalSubCommand.java @@ -11,15 +11,12 @@ import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; import com.sekwah.advancedportals.spigot.commands.subcommands.portal.update.ConfigAccessor; - -import org.bukkit.configuration.ConfigurationSection; - import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.bukkit.configuration.ConfigurationSection; public class UpdatePortalSubCommand implements SubCommand { - @Inject PortalServices portalServices; @Inject DestinationServices destinationServices; @@ -29,43 +26,41 @@ public class UpdatePortalSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { if (args.length > 1 && "confirm".equals(args[1])) { - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translateInsertVariables("command.portal.update.confirm")); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translateInsertVariables( + "command.portal.update.confirm")); int destinations = importDestinations(); int portals = importPortals(); sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translateInsertVariables( - "command.portal.update.complete", portals, destinations)); + Lang.translate("messageprefix.positive") + + Lang.translateInsertVariables( + "command.portal.update.complete", portals, destinations)); return; } - sender.sendMessage( - Lang.translate("messageprefix.positive") - + Lang.translateInsertVariables( - "command.portal.update", getPortalCount(), getDestinationCount())); + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translateInsertVariables( + "command.portal.update", getPortalCount(), + getDestinationCount())); } private int importPortals() { - ConfigAccessor portalConfig = - new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yaml"); + ConfigAccessor portalConfig = new ConfigAccessor( + AdvancedPortalsPlugin.getInstance(), "portals.yaml"); var config = portalConfig.getConfig(); Set portalSet = config.getKeys(false); int count = 0; for (String portalName : portalSet) { BlockLocation pos1 = - new BlockLocation( - config.getString(portalName + ".world"), - config.getInt(portalName + ".pos1.X"), - config.getInt(portalName + ".pos1.Y"), - config.getInt(portalName + ".pos1.Z")); + new BlockLocation(config.getString(portalName + ".world"), + config.getInt(portalName + ".pos1.X"), + config.getInt(portalName + ".pos1.Y"), + config.getInt(portalName + ".pos1.Z")); BlockLocation pos2 = - new BlockLocation( - config.getString(portalName + ".world"), - config.getInt(portalName + ".pos2.X"), - config.getInt(portalName + ".pos2.Y"), - config.getInt(portalName + ".pos2.Z")); + new BlockLocation(config.getString(portalName + ".world"), + config.getInt(portalName + ".pos2.X"), + config.getInt(portalName + ".pos2.Y"), + config.getInt(portalName + ".pos2.Z")); List args = new ArrayList<>(); args.add(new DataTag("name", portalName)); var triggerblock = config.getString(portalName + ".triggerblock"); @@ -73,24 +68,26 @@ public class UpdatePortalSubCommand implements SubCommand { args.add(new DataTag("triggerblock", triggerblock.split(","))); // It's called bungee as that's the implementation behind it var bungee = config.getString(portalName + ".bungee"); - if (bungee != null) args.add(new DataTag("bungee", bungee.split(","))); + if (bungee != null) + args.add(new DataTag("bungee", bungee.split(","))); var destination = config.getString(portalName + ".destination"); - if (destination != null) args.add(new DataTag("destination", destination.split(","))); + if (destination != null) + args.add(new DataTag("destination", destination.split(","))); - ConfigurationSection portalConfigSection = config.getConfigurationSection(portalName); + ConfigurationSection portalConfigSection = + config.getConfigurationSection(portalName); ConfigurationSection portalArgsConf = - portalConfigSection.getConfigurationSection("portalArgs"); + portalConfigSection.getConfigurationSection("portalArgs"); if (portalArgsConf != null) { Set argsSet = portalArgsConf.getKeys(true); for (Object argName : argsSet.toArray()) { // skip if it argName starts with command. if (portalArgsConf.isString(argName.toString())) { - args.add( - new DataTag( - argName.toString(), - portalArgsConf.getString(argName.toString()))); + args.add(new DataTag( + argName.toString(), + portalArgsConf.getString(argName.toString()))); } } } @@ -104,16 +101,18 @@ public class UpdatePortalSubCommand implements SubCommand { } } if (!commands.isEmpty()) { - args.add(new DataTag("commands", commands.toArray(new String[0]))); + args.add( + new DataTag("commands", commands.toArray(new String[0]))); } args.stream() - .filter(dataTag -> dataTag.NAME.startsWith("command.")) - .toList() - .forEach(args::remove); + .filter(dataTag -> dataTag.NAME.startsWith("command.")) + .toList() + .forEach(args::remove); var portal = portalService.createPortal(pos1, pos2, args); - if (portal != null) count++; + if (portal != null) + count++; } return count; @@ -129,32 +128,32 @@ public class UpdatePortalSubCommand implements SubCommand { } public int importDestinations() { - ConfigAccessor destiConfig = - new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yaml"); + ConfigAccessor destiConfig = new ConfigAccessor( + AdvancedPortalsPlugin.getInstance(), "destinations.yaml"); var config = destiConfig.getConfig(); Set destiSet = config.getKeys(false); int count = 0; for (String destiName : destiSet) { var destiPos = destiName + ".pos"; - var desti = - destinationServices.createDesti( - new PlayerLocation( - config.getString(destiName + ".world"), - config.getDouble(destiPos + ".X"), - config.getDouble(destiPos + ".Y"), - config.getDouble(destiPos + ".Z"), - (float) config.getDouble(destiPos + ".yaw"), - (float) config.getDouble(destiPos + ".pitch")), - List.of(new DataTag("name", destiName))); - if (desti != null) count++; + var desti = destinationServices.createDesti( + new PlayerLocation( + config.getString(destiName + ".world"), + config.getDouble(destiPos + ".X"), + config.getDouble(destiPos + ".Y"), + config.getDouble(destiPos + ".Z"), + (float) config.getDouble(destiPos + ".yaw"), + (float) config.getDouble(destiPos + ".pitch")), + List.of(new DataTag("name", destiName))); + if (desti != null) + count++; } return count; } public int getDestinationCount() { - ConfigAccessor destiConfig = - new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yaml"); + ConfigAccessor destiConfig = new ConfigAccessor( + AdvancedPortalsPlugin.getInstance(), "destinations.yaml"); var config = destiConfig.getConfig(); Set destiSet = config.getKeys(false); @@ -162,8 +161,8 @@ public class UpdatePortalSubCommand implements SubCommand { } public int getPortalCount() { - ConfigAccessor portalConfig = - new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yaml"); + ConfigAccessor portalConfig = new ConfigAccessor( + AdvancedPortalsPlugin.getInstance(), "portals.yaml"); var config = portalConfig.getConfig(); Set portalSet = config.getKeys(false); @@ -176,7 +175,8 @@ public class UpdatePortalSubCommand implements SubCommand { } @Override - public List onTabComplete(CommandSenderContainer sender, String[] args) { + public List onTabComplete(CommandSenderContainer sender, + String[] args) { return null; } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/update/ConfigAccessor.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/update/ConfigAccessor.java index e5afba69..e52c9409 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/update/ConfigAccessor.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/update/ConfigAccessor.java @@ -1,15 +1,13 @@ package com.sekwah.advancedportals.spigot.commands.subcommands.portal.update; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - import java.io.File; import java.io.IOException; import java.util.logging.Level; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; public class ConfigAccessor { - private final String fileName; private final JavaPlugin plugin; @@ -25,7 +23,8 @@ public class ConfigAccessor { public void reloadConfig() { if (configFile == null) { File dataFolder = plugin.getDataFolder(); - if (dataFolder == null) throw new IllegalStateException(); + if (dataFolder == null) + throw new IllegalStateException(); configFile = new File(dataFolder, fileName); } fileConfiguration = YamlConfiguration.loadConfiguration(configFile); @@ -46,7 +45,8 @@ public class ConfigAccessor { try { getConfig().save(configFile); } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex); + plugin.getLogger().log( + Level.SEVERE, "Could not save config to " + configFile, ex); } } } @@ -58,8 +58,8 @@ public class ConfigAccessor { * this.plugin.saveResource(fileName, false); } } */ - // New save default config saving code, it checks if the needed config is in the jar file before - // overriding it. + // New save default config saving code, it checks if the needed config is in + // the jar file before overriding it. public void saveDefaultConfig() { if (configFile == null) { configFile = new File(plugin.getDataFolder(), fileName); diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java index 824b84f6..c91cce07 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java @@ -2,16 +2,13 @@ package com.sekwah.advancedportals.spigot.connector.command; import com.sekwah.advancedportals.core.commands.CommandTemplate; import com.sekwah.advancedportals.spigot.connector.container.SpigotCommandSenderContainer; - +import java.util.List; 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) { @@ -19,17 +16,19 @@ public class SpigotCommandHandler implements CommandExecutor, TabCompleter { } @Override - public boolean onCommand( - CommandSender commandSender, Command command, String s, String[] args) { + public boolean onCommand(CommandSender commandSender, Command command, + String s, String[] args) { this.commandExecutor.onCommand( - new SpigotCommandSenderContainer(commandSender), command.getName(), args); + new SpigotCommandSenderContainer(commandSender), command.getName(), + args); return true; } @Override - public List onTabComplete( - CommandSender commandSender, Command command, String s, String[] args) { + public List onTabComplete(CommandSender commandSender, + Command command, String s, + String[] args) { return this.commandExecutor.onTabComplete( - new SpigotCommandSenderContainer(commandSender), args); + new SpigotCommandSenderContainer(commandSender), args); } } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandRegister.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandRegister.java index ccb50590..b6cc4b36 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandRegister.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandRegister.java @@ -4,9 +4,10 @@ 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 */ +/** + * Register the CommandTemplate files to the appropriate system + */ public class SpigotCommandRegister implements CommandRegister { - private final AdvancedPortalsPlugin plugin; public SpigotCommandRegister(AdvancedPortalsPlugin plugin) { @@ -19,7 +20,9 @@ public class SpigotCommandRegister implements CommandRegister { * @param commandName * @param commandExecutor */ - public void registerCommand(String commandName, CommandTemplate commandExecutor) { - this.plugin.getCommand(commandName).setExecutor(new SpigotCommandHandler(commandExecutor)); + public void registerCommand(String commandName, + CommandTemplate commandExecutor) { + this.plugin.getCommand(commandName) + .setExecutor(new SpigotCommandHandler(commandExecutor)); } } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotCommandSenderContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotCommandSenderContainer.java index bd61a9ff..8e9abaf9 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotCommandSenderContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotCommandSenderContainer.java @@ -1,12 +1,10 @@ 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) { diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotEntityContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotEntityContainer.java index 894f4f46..cf8522cc 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotEntityContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotEntityContainer.java @@ -7,14 +7,15 @@ import com.sekwah.advancedportals.core.connector.containers.WorldContainer; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.serializeddata.Vector; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; -/** Just a temporary container for whenever advanced portals needs to get data from a player */ +/** + * Just a temporary container for whenever advanced portals needs to get data + * from a player + */ public class SpigotEntityContainer implements EntityContainer { - @Inject private AdvancedPortalsCore portalsCore; private final Entity entity; @@ -26,20 +27,16 @@ public class SpigotEntityContainer implements EntityContainer { @Override public PlayerLocation getLoc() { Location loc = this.entity.getLocation(); - return new PlayerLocation( - loc.getWorld().getName(), - loc.getX(), - loc.getY(), - loc.getZ(), - loc.getYaw(), - loc.getPitch()); + return new PlayerLocation(loc.getWorld().getName(), loc.getX(), + loc.getY(), loc.getZ(), loc.getYaw(), + loc.getPitch()); } @Override public BlockLocation getBlockLoc() { Location loc = this.entity.getLocation(); - return new BlockLocation( - loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + return new BlockLocation(loc.getWorld().getName(), loc.getBlockX(), + loc.getBlockY(), loc.getBlockZ()); } @Override @@ -49,12 +46,9 @@ public class SpigotEntityContainer implements EntityContainer { @Override public boolean teleport(PlayerLocation location) { - return this.entity.teleport( - new Location( - Bukkit.getWorld(location.getWorldName()), - location.getPosX(), - location.getPosY(), - location.getPosZ())); + return this.entity.teleport(new Location( + Bukkit.getWorld(location.getWorldName()), location.getPosX(), + location.getPosY(), location.getPosZ())); } @Override @@ -74,7 +68,7 @@ public class SpigotEntityContainer implements EntityContainer { @Override public void setVelocity(Vector vector) { - this.entity.setVelocity( - new org.bukkit.util.Vector(vector.getX(), vector.getY(), vector.getZ())); + this.entity.setVelocity(new org.bukkit.util.Vector( + vector.getX(), vector.getY(), vector.getZ())); } } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java index c2368809..208f5909 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java @@ -7,7 +7,8 @@ import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; import com.sekwah.advancedportals.spigot.reflection.MinecraftCustomPayload; - +import java.util.Arrays; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -15,12 +16,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -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 extends SpigotEntityContainer implements PlayerContainer { - +/** + * Just a temporary container for whenever advanced portals needs to get data + * from a player + */ +public class SpigotPlayerContainer + extends SpigotEntityContainer implements PlayerContainer { @Inject private AdvancedPortalsCore portalsCore; private final Player player; @@ -47,12 +48,9 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play @Override public boolean teleport(PlayerLocation location) { - return this.player.teleport( - new Location( - Bukkit.getWorld(location.getWorldName()), - location.getPosX(), - location.getPosY(), - location.getPosZ())); + return this.player.teleport(new Location( + Bukkit.getWorld(location.getWorldName()), location.getPosX(), + location.getPosY(), location.getPosZ())); } @Override @@ -65,7 +63,8 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play * @param material */ @Override - public void sendFakeBlock(BlockLocation blockPos, String material) {} + public void sendFakeBlock(BlockLocation blockPos, String material) { + } /** * Only 1.12 and below supported @@ -75,11 +74,15 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play * @param data */ @Override - public void sendFakeBlockWithData(BlockLocation blockPos, String material, byte data) {} + public void sendFakeBlockWithData(BlockLocation blockPos, String material, + byte data) { + } @Override - public void giveItem(String material, String itemName, String... itemDescription) { - ItemStack regionselector = new ItemStack(Material.getMaterial(material)); + 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)); @@ -90,9 +93,11 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play @Override public boolean sendPacket(String channel, byte[] bytes) { if (channel.startsWith("minecraft:")) { - return MinecraftCustomPayload.sendCustomPayload(player, channel, bytes); + return MinecraftCustomPayload.sendCustomPayload(player, channel, + bytes); } else { - player.sendPluginMessage(AdvancedPortalsPlugin.getInstance(), channel, bytes); + player.sendPluginMessage(AdvancedPortalsPlugin.getInstance(), + channel, bytes); } return true; } 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 index d71a3f8d..6b1f9161 100644 --- 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 @@ -3,18 +3,19 @@ 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 java.util.Arrays; +import java.util.List; +import java.util.UUID; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.block.Block; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - public class SpigotServerContainer implements ServerContainer { - private final Server server; - private final List triggerBlockList = Arrays.stream(Material.values()).filter(this::isAdvancedPortalBlock).map(Enum::name) + private final List triggerBlockList = + Arrays.stream(Material.values()) + .filter(this::isAdvancedPortalBlock) + .map(Enum::name) .toList(); public SpigotServerContainer(Server server) { @@ -24,7 +25,7 @@ public class SpigotServerContainer implements ServerContainer { @Override public WorldContainer getWorld(String name) { var world = server.getWorld(name); - if(world != null) { + if (world != null) { return new SpigotWorldContainer(world); } else { return null; @@ -34,7 +35,7 @@ public class SpigotServerContainer implements ServerContainer { @Override public PlayerContainer getPlayer(String name) { var player = server.getPlayer(name); - if(player != null) { + if (player != null) { return new SpigotPlayerContainer(player); } else { return null; @@ -44,7 +45,7 @@ public class SpigotServerContainer implements ServerContainer { @Override public PlayerContainer getPlayer(UUID name) { var player = server.getPlayer(name); - if(player != null) { + if (player != null) { return new SpigotPlayerContainer(player); } else { return null; @@ -58,9 +59,10 @@ public class SpigotServerContainer implements ServerContainer { @Override public PlayerContainer[] getPlayers() { - return server.getOnlinePlayers().stream() - .map(SpigotPlayerContainer::new) - .toArray(PlayerContainer[]::new); + return server.getOnlinePlayers() + .stream() + .map(SpigotPlayerContainer::new) + .toArray(PlayerContainer[] ::new); } // Check if it's a material compatible with making portals diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java index 820b623e..6b5cd855 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java @@ -9,7 +9,6 @@ import org.bukkit.World; import org.bukkit.block.data.Orientable; public class SpigotWorldContainer implements WorldContainer { - private final World world; public SpigotWorldContainer(World world) { @@ -18,18 +17,27 @@ public class SpigotWorldContainer implements WorldContainer { public void setBlock(BlockLocation location, String material) { Material mat = Material.getMaterial(material, false); - if(mat != null) this.world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ()).setType(mat); + if (mat != null) + this.world + .getBlockAt(location.getPosX(), location.getPosY(), + location.getPosZ()) + .setType(mat); } public String getBlock(BlockLocation location) { - return this.world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ()).getType().toString(); + return this.world + .getBlockAt(location.getPosX(), location.getPosY(), + location.getPosZ()) + .getType() + .toString(); } @Override public BlockAxis getBlockAxis(BlockLocation location) { - var block = world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ()); + var block = world.getBlockAt(location.getPosX(), location.getPosY(), + location.getPosZ()); var matData = block.getState().getBlockData(); - if(matData instanceof Orientable rotatable) { + if (matData instanceof Orientable rotatable) { try { return BlockAxis.valueOf(rotatable.getAxis().toString()); } catch (IllegalArgumentException e) { @@ -41,9 +49,10 @@ public class SpigotWorldContainer implements WorldContainer { @Override public void setBlockAxis(BlockLocation location, BlockAxis axis) { - var block = world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ()); + var block = world.getBlockAt(location.getPosX(), location.getPosY(), + location.getPosZ()); var matData = block.getState().getBlockData(); - if(matData instanceof Orientable rotatable) { + if (matData instanceof Orientable rotatable) { rotatable.setAxis(Axis.valueOf(axis.toString())); block.setBlockData(rotatable); } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java index 10c834a5..3d37cd2d 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java @@ -3,14 +3,6 @@ package com.sekwah.advancedportals.spigot.metrics; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.ServicePriority; - import java.io.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -20,8 +12,13 @@ import java.util.*; import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; - import javax.net.ssl.HttpsURLConnection; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.ServicePriority; /** * bStats collects some data for plugin authors. @@ -30,30 +27,25 @@ import javax.net.ssl.HttpsURLConnection; */ @SuppressWarnings({"WeakerAccess", "unused"}) public class Metrics { - static { - // You can use the property to disable the check in your test environment + // You can use the property to disable the check in your test + // environment if (System.getProperty("bstats.relocatecheck") == null - || !System.getProperty("bstats.relocatecheck").equals("false")) { - // Maven's Relocate is clever and changes strings, too. So we have to use this little - // "trick" ... :D - final String defaultPackage = - new String( - new byte[] { - 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', - 'k', 'k', 'i', 't' - }); - final String examplePackage = - new String( - new byte[] { - 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' - }); - // We want to make sure nobody just copy & pastes the example and use the wrong package - // names + || !System.getProperty("bstats.relocatecheck").equals("false")) { + // Maven's Relocate is clever and changes strings, too. So we have + // to use this little "trick" ... :D + final String defaultPackage = new String( + new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', + '.', 'b', 'u', 'k', 'k', 'i', 't'}); + final String examplePackage = new String(new byte[] { + 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); + // We want to make sure nobody just copy & pastes the example and + // use the wrong package names if (Metrics.class.getPackage().getName().equals(defaultPackage) - || Metrics.class.getPackage().getName().equals(examplePackage)) { + || Metrics.class.getPackage().getName().equals( + examplePackage)) { throw new IllegalStateException( - "bStats Metrics class has not been relocated correctly!"); + "bStats Metrics class has not been relocated correctly!"); } } } @@ -97,13 +89,14 @@ public class Metrics { this.plugin = plugin; // Get the config file - File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + File bStatsFolder = + new File(plugin.getDataFolder().getParentFile(), "bStats"); File configFile = new File(bStatsFolder, "config.yaml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + YamlConfiguration config = + YamlConfiguration.loadConfiguration(configFile); // Check if the config file exists if (!config.isSet("serverUuid")) { - // Add default values config.addDefault("enabled", true); // Every server gets it's unique random id. @@ -117,13 +110,14 @@ public class Metrics { // Inform the server owners about bStats config.options() - .header( - "bStats collects some data for plugin authors like how many servers are" - + " using their plugins.\n" - + "To honor their work, you should not disable it.\n" - + "This has nearly no effect on the server performance!\n" - + "Check out https://bStats.org/ to learn more :)") - .copyDefaults(true); + .header( + "bStats collects some data for plugin authors like how " + + "many servers are" + + " using their plugins.\n" + + "To honor their work, you should not disable it.\n" + + "This has nearly no effect on the server performance!\n" + + "Check out https://bStats.org/ to learn more :)") + .copyDefaults(true); try { config.save(configFile); } catch (IOException ignored) { @@ -135,12 +129,15 @@ public class Metrics { serverUUID = config.getString("serverUuid"); logFailedRequests = config.getBoolean("logFailedRequests", false); logSentData = config.getBoolean("logSentData", false); - logResponseStatusText = config.getBoolean("logResponseStatusText", false); + logResponseStatusText = + config.getBoolean("logResponseStatusText", false); if (enabled) { boolean found = false; - // Search for all other bStats Metrics classes to see if we are the first one - for (Class service : Bukkit.getServicesManager().getKnownServices()) { + // Search for all other bStats Metrics classes to see if we are the + // first one + for (Class service : + Bukkit.getServicesManager().getKnownServices()) { try { service.getField("B_STATS_VERSION"); // Our identifier :) found = true; // We aren't the first @@ -149,8 +146,8 @@ public class Metrics { } } // Register our service - Bukkit.getServicesManager() - .register(Metrics.class, this, plugin, ServicePriority.Normal); + Bukkit.getServicesManager().register(Metrics.class, this, plugin, + ServicePriority.Normal); if (!found) { // We are the first! startSubmitting(); @@ -179,33 +176,31 @@ public class Metrics { charts.add(chart); } - /** Starts the Scheduler which submits our data every 30 minutes. */ + /** + * Starts the Scheduler which submits our data every 30 minutes. + */ private void startSubmitting() { final Timer timer = - new Timer( - true); // We use a timer cause the Bukkit scheduler is affected by server - // lags - timer.scheduleAtFixedRate( - new TimerTask() { - @Override - public void run() { - if (!plugin.isEnabled()) { // Plugin was disabled - timer.cancel(); - return; - } - // Nevertheless we want our code to run in the Bukkit main thread, so we - // have to use the Bukkit scheduler - // Don't be afraid! The connection to the bStats server is still async, only - // the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, () -> submitData()); - } - }, - 1000 * 60 * 5, - 1000 * 60 * 30); - // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough - // time to start - // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! - // WARNING: Just don't do it! + new Timer(true); // We use a timer cause the Bukkit + // scheduler is affected by server lags + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if (!plugin.isEnabled()) { // Plugin was disabled + timer.cancel(); + return; + } + // Nevertheless we want our code to run in the Bukkit main + // thread, so we have to use the Bukkit scheduler Don't be + // afraid! The connection to the bStats server is still async, + // only the stats collection is sync ;) + Bukkit.getScheduler().runTask(plugin, () -> submitData()); + } + }, 1000 * 60 * 5, 1000 * 60 * 30); + // Submit the data every 30 minutes, first time after 5 minutes to give + // other plugins enough time to start WARNING: Changing the frequency + // has no effect but your plugin WILL be blocked/deleted! WARNING: Just + // don't do it! } /** @@ -219,8 +214,10 @@ public class Metrics { String pluginName = plugin.getDescription().getName(); String pluginVersion = plugin.getDescription().getVersion(); - data.addProperty("pluginName", pluginName); // Append the name of the plugin - data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin + data.addProperty("pluginName", + pluginName); // Append the name of the plugin + data.addProperty("pluginVersion", + pluginVersion); // Append the version of the plugin JsonArray customCharts = new JsonArray(); for (CustomChart customChart : charts) { // Add the data of the custom charts @@ -244,20 +241,22 @@ public class Metrics { // Minecraft specific data int playerAmount; try { - // Around MC 1.8 the return type was changed to a collection from an array, - // This fixes java.lang.NoSuchMethodError: + // Around MC 1.8 the return type was changed to a collection from an + // array, This fixes java.lang.NoSuchMethodError: // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = - Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + Method onlinePlayersMethod = Class.forName("org.bukkit.Server") + .getMethod("getOnlinePlayers"); playerAmount = - onlinePlayersMethod.getReturnType().equals(Collection.class) - ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())) - .size() - : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; + onlinePlayersMethod.getReturnType().equals(Collection.class) + ? ((Collection) onlinePlayersMethod.invoke( + Bukkit.getServer())) + .size() + : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())) + .length; } catch (Exception e) { playerAmount = - Bukkit.getOnlinePlayers() - .size(); // Just use the new method if the Reflection failed + Bukkit.getOnlinePlayers() + .size(); // Just use the new method if the Reflection failed } int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; String bukkitVersion = Bukkit.getVersion(); @@ -288,55 +287,59 @@ public class Metrics { return data; } - /** Collects the data and sends it afterwards. */ + /** + * Collects the data and sends it afterwards. + */ private void submitData() { final JsonObject data = getServerData(); JsonArray pluginData = new JsonArray(); // Search for all other bStats Metrics classes to get their plugin data - for (Class service : Bukkit.getServicesManager().getKnownServices()) { + for (Class service : + Bukkit.getServicesManager().getKnownServices()) { try { service.getField("B_STATS_VERSION"); // Our identifier :) for (RegisteredServiceProvider provider : - Bukkit.getServicesManager().getRegistrations(service)) { + Bukkit.getServicesManager().getRegistrations(service)) { try { - Object plugin = - provider.getService() - .getMethod("getPluginData") - .invoke(provider.getProvider()); + Object plugin = provider.getService() + .getMethod("getPluginData") + .invoke(provider.getProvider()); if (plugin instanceof JsonObject) { pluginData.add((JsonObject) plugin); } else { // old bstats version compatibility try { Class jsonObjectJsonSimple = - Class.forName("org.json.simple.JSONObject"); - if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) { + Class.forName("org.json.simple.JSONObject"); + if (plugin.getClass().isAssignableFrom( + jsonObjectJsonSimple)) { Method jsonStringGetter = - jsonObjectJsonSimple.getDeclaredMethod("toJSONString"); + jsonObjectJsonSimple.getDeclaredMethod( + "toJSONString"); jsonStringGetter.setAccessible(true); - String jsonString = (String) jsonStringGetter.invoke(plugin); - JsonObject object = - new JsonParser().parse(jsonString).getAsJsonObject(); + String jsonString = + (String) jsonStringGetter.invoke( + plugin); + JsonObject object = new JsonParser() + .parse(jsonString) + .getAsJsonObject(); pluginData.add(object); } } catch (ClassNotFoundException e) { // minecraft version 1.14+ if (logFailedRequests) { - this.plugin - .getLogger() - .log( - Level.SEVERE, - "Encountered unexpected exception", - e); + this.plugin.getLogger().log( + Level.SEVERE, + "Encountered unexpected exception", e); } - continue; // continue looping since we cannot do any other thing. + continue; // continue looping since we cannot do + // any other thing. } } - } catch (NullPointerException - | NoSuchMethodException - | IllegalAccessException - | InvocationTargetException ignored) { + } catch (NullPointerException | NoSuchMethodException + | IllegalAccessException + | InvocationTargetException ignored) { } } } catch (NoSuchFieldException ignored) { @@ -346,27 +349,24 @@ public class Metrics { data.add("plugins", pluginData); // Create a new thread for the connection to the bStats server - new Thread( - new Runnable() { - @Override - public void run() { - try { - // Send the data - sendData(plugin, data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger() - .log( - Level.WARNING, - "Could not submit plugin stats of " - + plugin.getName(), - e); - } - } - } - }) - .start(); + new Thread(new Runnable() { + @Override + public void run() { + try { + // Send the data + sendData(plugin, data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log( + Level.WARNING, + "Could not submit plugin stats of " + + plugin.getName(), + e); + } + } + } + }).start(); } /** @@ -376,18 +376,21 @@ public class Metrics { * @param data The data to send. * @throws Exception If the request failed. */ - private static void sendData(Plugin plugin, JsonObject data) throws Exception { + private static void sendData(Plugin plugin, JsonObject data) + throws Exception { if (data == null) { throw new IllegalArgumentException("Data cannot be null!"); } if (Bukkit.isPrimaryThread()) { throw new IllegalAccessException( - "This method must not be called from the main thread!"); + "This method must not be called from the main thread!"); } if (logSentData) { - plugin.getLogger().info("Sending data to bStats: " + data.toString()); + plugin.getLogger().info("Sending data to bStats: " + + data.toString()); } - HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); + HttpsURLConnection connection = + (HttpsURLConnection) new URL(URL).openConnection(); // Compress the data to save bandwidth byte[] compressedData = compress(data.toString()); @@ -396,21 +399,27 @@ public class Metrics { connection.setRequestMethod("POST"); connection.addRequestProperty("Accept", "application/json"); connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.addRequestProperty("Content-Encoding", + "gzip"); // We gzip our request + connection.addRequestProperty("Content-Length", + String.valueOf(compressedData.length)); connection.setRequestProperty( - "Content-Type", "application/json"); // We send our data in JSON format - connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); + "Content-Type", + "application/json"); // We send our data in JSON format + connection.setRequestProperty("User-Agent", + "MC-Server/" + B_STATS_VERSION); // Send data connection.setDoOutput(true); - DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); + DataOutputStream outputStream = + new DataOutputStream(connection.getOutputStream()); outputStream.write(compressedData); outputStream.flush(); outputStream.close(); InputStream inputStream = connection.getInputStream(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(inputStream)); StringBuilder builder = new StringBuilder(); String line; @@ -419,8 +428,9 @@ public class Metrics { } bufferedReader.close(); if (logResponseStatusText) { - plugin.getLogger() - .info("Sent data to bStats and received response: " + builder.toString()); + plugin.getLogger().info( + "Sent data to bStats and received response: " + + builder.toString()); } } @@ -442,9 +452,10 @@ public class Metrics { return outputStream.toByteArray(); } - /** Represents a custom chart. */ + /** + * Represents a custom chart. + */ public abstract static class CustomChart { - // The id of the chart final String chartId; @@ -455,7 +466,8 @@ public class Metrics { */ CustomChart(String chartId) { if (chartId == null || chartId.isEmpty()) { - throw new IllegalArgumentException("ChartId cannot be null or empty!"); + throw new IllegalArgumentException( + "ChartId cannot be null or empty!"); } this.chartId = chartId; } @@ -472,11 +484,11 @@ public class Metrics { chart.add("data", data); } catch (Throwable t) { if (logFailedRequests) { - Bukkit.getLogger() - .log( - Level.WARNING, - "Failed to get data for custom chart with id " + chartId, - t); + Bukkit.getLogger().log( + Level.WARNING, + "Failed to get data for custom chart with id " + + chartId, + t); } return null; } @@ -486,9 +498,10 @@ public class Metrics { protected abstract JsonObject getChartData() throws Exception; } - /** Represents a custom simple pie. */ + /** + * Represents a custom simple pie. + */ public static class SimplePie extends CustomChart { - private final Callable callable; /** @@ -515,9 +528,10 @@ public class Metrics { } } - /** Represents a custom advanced pie. */ + /** + * Represents a custom advanced pie. + */ public static class AdvancedPie extends CustomChart { - private final Callable> callable; /** @@ -526,7 +540,8 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public AdvancedPie(String chartId, Callable> callable) { + public AdvancedPie(String chartId, + Callable> callable) { super(chartId); this.callable = callable; } @@ -557,9 +572,10 @@ public class Metrics { } } - /** Represents a custom drilldown pie. */ + /** + * Represents a custom drilldown pie. + */ public static class DrilldownPie extends CustomChart { - private final Callable>> callable; /** @@ -568,7 +584,9 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public DrilldownPie(String chartId, Callable>> callable) { + public DrilldownPie( + String chartId, + Callable>> callable) { super(chartId); this.callable = callable; } @@ -583,12 +601,14 @@ public class Metrics { return null; } boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { + for (Map.Entry> entryValues : + map.entrySet()) { JsonObject value = new JsonObject(); boolean allSkipped = true; for (Map.Entry valueEntry : - map.get(entryValues.getKey()).entrySet()) { - value.addProperty(valueEntry.getKey(), valueEntry.getValue()); + map.get(entryValues.getKey()).entrySet()) { + value.addProperty(valueEntry.getKey(), + valueEntry.getValue()); allSkipped = false; } if (!allSkipped) { @@ -605,9 +625,10 @@ public class Metrics { } } - /** Represents a custom single line chart. */ + /** + * Represents a custom single line chart. + */ public static class SingleLineChart extends CustomChart { - private final Callable callable; /** @@ -634,9 +655,10 @@ public class Metrics { } } - /** Represents a custom multi line chart. */ + /** + * Represents a custom multi line chart. + */ public static class MultiLineChart extends CustomChart { - private final Callable> callable; /** @@ -645,7 +667,8 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public MultiLineChart(String chartId, Callable> callable) { + public MultiLineChart(String chartId, + Callable> callable) { super(chartId); this.callable = callable; } @@ -676,9 +699,10 @@ public class Metrics { } } - /** Represents a custom simple bar chart. */ + /** + * Represents a custom simple bar chart. + */ public static class SimpleBarChart extends CustomChart { - private final Callable> callable; /** @@ -687,7 +711,8 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public SimpleBarChart(String chartId, Callable> callable) { + public SimpleBarChart(String chartId, + Callable> callable) { super(chartId); this.callable = callable; } @@ -711,9 +736,10 @@ public class Metrics { } } - /** Represents a custom advanced bar chart. */ + /** + * Represents a custom advanced bar chart. + */ public static class AdvancedBarChart extends CustomChart { - private final Callable> callable; /** @@ -722,7 +748,8 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public AdvancedBarChart(String chartId, Callable> callable) { + public AdvancedBarChart(String chartId, + Callable> callable) { super(chartId); this.callable = callable; } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java index 025438b6..87f627fc 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java @@ -1,37 +1,39 @@ package com.sekwah.advancedportals.spigot.reflection; -import org.bukkit.entity.Player; - import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import org.bukkit.entity.Player; /** - * Just a util class to force spigot to allow us to have fun with the minecraft: channel category + * Just a util class to force spigot to allow us to have fun with the + * minecraft: channel category * - *

Atm at least this is just designed to be able to access debug/ for showing visuals of the - * portals and such + *

Atm at least this is just designed to be able to access debug/ for + * showing visuals of the portals and such */ public class MinecraftCustomPayload { - - public static boolean sendCustomPayload(Player player, String channel, byte[] data) { + public static boolean sendCustomPayload(Player player, String channel, + byte[] data) { try { // Access the MinecraftKey class using reflection - Class minecraftKeyClass = Class.forName("net.minecraft.resources.MinecraftKey"); - Constructor minecraftKeyConstructor = minecraftKeyClass.getConstructor(String.class); + Class minecraftKeyClass = + Class.forName("net.minecraft.resources.MinecraftKey"); + Constructor minecraftKeyConstructor = + minecraftKeyClass.getConstructor(String.class); // Create an instance of MinecraftKey with the channel name Object minecraftKey = minecraftKeyConstructor.newInstance(channel); // Access the sendCustomPayload method in the CraftPlayer class Method sendCustomPayloadMethod = - player.getClass() - .getDeclaredMethod( - "sendCustomPayload", minecraftKeyClass, byte[].class); + player.getClass().getDeclaredMethod( + "sendCustomPayload", minecraftKeyClass, byte[].class); // Make the private method accessible sendCustomPayloadMethod.setAccessible(true); - // Invoke the sendCustomPayload method with the MinecraftKey and data + // Invoke the sendCustomPayload method with the MinecraftKey and + // data sendCustomPayloadMethod.invoke(player, minecraftKey, data); return true; // Successfully sent the custom payload diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/utils/ContainerHelpers.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/utils/ContainerHelpers.java index aa75c6ff..55fdf05d 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/utils/ContainerHelpers.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/utils/ContainerHelpers.java @@ -2,23 +2,17 @@ package com.sekwah.advancedportals.spigot.utils; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; - import org.bukkit.Location; public class ContainerHelpers { - public static PlayerLocation toPlayerLocation(Location loc) { - return new PlayerLocation( - loc.getWorld().getName(), - loc.getX(), - loc.getY(), - loc.getZ(), - loc.getYaw(), - loc.getPitch()); + return new PlayerLocation(loc.getWorld().getName(), loc.getX(), + loc.getY(), loc.getZ(), loc.getYaw(), + loc.getPitch()); } public static BlockLocation toBlockLocation(Location loc) { - return new BlockLocation( - loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + return new BlockLocation(loc.getWorld().getName(), loc.getBlockX(), + loc.getBlockY(), loc.getBlockZ()); } } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java index 00c6b246..a9b9a7b7 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java @@ -8,27 +8,31 @@ import com.sekwah.advancedportals.spigot.connector.container.SpigotPlayerContain import org.bukkit.Effect; public class EnderWarpEffect implements WarpEffect.Visual, WarpEffect.Sound { - @Override - public void onWarpSound(PlayerContainer playerContainer, WarpEffect.Action action) { - if(playerContainer instanceof SpigotPlayerContainer spigotPlayerContainer) { + public void onWarpSound(PlayerContainer playerContainer, + WarpEffect.Action action) { + if (playerContainer + instanceof SpigotPlayerContainer spigotPlayerContainer) { var player = spigotPlayerContainer.getPlayer(); - player.getWorld().playSound(player.getLocation(), "entity.enderman.teleport", 1, 1); + player.getWorld().playSound(player.getLocation(), + "entity.enderman.teleport", 1, 1); } } @Override - public void onWarpVisual(PlayerContainer playerContainer, WarpEffect.Action action) { - if(playerContainer instanceof SpigotPlayerContainer spigotPlayerContainer) { + public void onWarpVisual(PlayerContainer playerContainer, + WarpEffect.Action action) { + if (playerContainer + instanceof SpigotPlayerContainer spigotPlayerContainer) { var player = spigotPlayerContainer.getPlayer(); var world = player.getWorld(); var loc = player.getLocation().clone(); - for(int i = 0; i < 10; i++){ + for (int i = 0; i < 10; i++) { world.playEffect(loc, Effect.ENDER_SIGNAL, 0); } loc.add(0D, 1D, 0D); - for(int i = 0; i < 10; i++){ + for (int i = 0; i < 10; i++) { world.playEffect(loc, Effect.ENDER_SIGNAL, 0); } } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java index 1324baa7..39b519dc 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java @@ -1,11 +1,9 @@ package com.sekwah.advancedportals.spigot.warpeffects; import com.sekwah.advancedportals.core.registry.WarpEffectRegistry; - import javax.inject.Inject; public class SpigotWarpEffects { - @Inject private WarpEffectRegistry warpEffectRegistry; public void registerEffects() {