From e056a6836d1cfb175c8bb333a09d8eb27eab168a Mon Sep 17 00:00:00 2001 From: Sekwah Date: Thu, 17 Oct 2024 02:21:35 +0100 Subject: [PATCH] feat: message tags & priority sorting (#447) --- .../core/AdvancedPortalsCore.java | 2 + .../advancedportals/core/CoreListeners.java | 4 +- .../core/commands/CommandWithSubCommands.java | 8 +- .../desti/CreateDestiSubCommand.java | 10 +- .../desti/ListDestiSubCommand.java | 2 +- .../desti/RemoveDestiSubCommand.java | 4 +- .../desti/ShowDestiSubCommand.java | 6 +- .../desti/TeleportDestiSubCommand.java | 4 +- .../portal/CreatePortalSubCommand.java | 10 +- .../portal/EndGatewayBlockSubCommand.java | 4 +- .../portal/EndPortalBlockSubCommand.java | 4 +- .../portal/InfoPortalSubCommand.java | 7 +- .../portal/LangUpdateSubCommand.java | 4 +- .../portal/ListPortalsSubCommand.java | 2 +- .../portal/PortalBlockSubCommand.java | 4 +- .../portal/ReloadPortalSubCommand.java | 2 +- .../portal/RemovePortalSubCommand.java | 4 +- .../portal/SelectorSubCommand.java | 4 +- .../portal/ShowPortalSubCommand.java | 6 +- .../subcommands/portal/VersionSubCommand.java | 2 +- .../connector/containers/PlayerContainer.java | 2 + .../core/destination/Destination.java | 56 ++++++++--- .../core/portal/AdvancedPortal.java | 11 ++- .../core/registry/TagRegistry.java | 18 ++-- .../core/repository/ConfigRepository.java | 4 + .../repository/impl/ConfigRepositoryImpl.java | 10 ++ .../core/serializeddata/config/Config.java | 4 + .../core/services/DestinationServices.java | 8 +- .../core/services/PortalServices.java | 10 +- .../advancedportals/core/tags/CommandTag.java | 22 ++--- .../core/tags/CooldownTag.java | 2 +- .../advancedportals/core/tags/DestiTag.java | 70 ++++++++++++-- .../advancedportals/core/tags/MessageTag.java | 92 +++++++++++++++++++ .../advancedportals/core/tags/NameTag.java | 2 +- .../advancedportals/core/util/Lang.java | 22 ++++- .../core/warphandler/ActivationData.java | 13 +++ lang/src/main/resources/lang/en_GB.lang | 5 + .../portal/ImportPortalSubCommand.java | 6 +- .../container/SpigotPlayerContainer.java | 8 ++ 39 files changed, 353 insertions(+), 105 deletions(-) create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java diff --git a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index aae88278..dc62cf27 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -2,6 +2,7 @@ import com.google.inject.Inject; import com.google.inject.Injector; +import com.google.inject.spi.Message; import com.sekwah.advancedportals.core.commands.CommandWithSubCommands; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.commands.subcommands.desti.*; @@ -130,6 +131,7 @@ private void registerTags() { this.tagRegistry.registerTag(new PermissionTag()); this.tagRegistry.registerTag(new CommandTag()); this.tagRegistry.registerTag(new PortalEventTag()); + this.tagRegistry.registerTag(new MessageTag()); } /** 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 25f0d306..5bcfa3a6 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -87,7 +87,7 @@ public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, } if (!(PortalPermissions.BUILD.hasPermission(player) || !portalServices.inPortalRegionProtected(blockPos))) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("portal.nobuild")); return false; } @@ -128,7 +128,7 @@ public boolean blockPlace(PlayerContainer player, BlockLocation blockPos, } if (portalServices.inPortalRegionProtected(blockPos)) { if (player != null) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("portal.nobuild")); } return false; 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 d77afa90..a26cdd42 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 @@ -87,7 +87,7 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, .getDetailedHelpText()); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translateInsertVariables( "command.help.invalidhelp", args[1])); } @@ -129,7 +129,7 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, subCommand.onCommand(sender, args); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translateInsertVariables( "command.subcommand.nopermission", commandExecuted)); @@ -138,11 +138,11 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, } } sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.subcommand.invalid")); } } else { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables( "command.noargs", commandExecuted)); } 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 39a4c48c..979e1c94 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 @@ -29,7 +29,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.create.destination.console")); return; } @@ -51,7 +51,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { } if (nameTag == null) { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.error.noname")); return; } @@ -69,16 +69,16 @@ public void onCommand(CommandSenderContainer sender, String[] args) { player, player.getLoc(), destinationTags); if (destination != null) { sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translate("command.create.destination.complete")); } else { sender.sendMessage(""); sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.create.destination.error")); } } else { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.error.noname")); } } 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 64900ec5..e1e90cd2 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 @@ -15,7 +15,7 @@ public class ListDestiSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translate("command.destination.list") + " " + portalServices.getDestinationNames().stream().sorted().collect( Collectors.joining(", "))); 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 ea5eac68..f2dbf7ee 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 @@ -19,11 +19,11 @@ public void onCommand(CommandSenderContainer sender, String[] args) { if (destinationServices.removeDestination( args[1], sender.getPlayerContainer())) { sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translate("command.destination.remove.complete")); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.destination.remove.error")); } } else { 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 c82ef922..8de82335 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 @@ -45,7 +45,7 @@ public class ShowDestiSubCommand public void onCommand(CommandSenderContainer sender, String[] args) { if (core.getMcVersion()[1] < 16) { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.portal.show.unsupported")); return; } @@ -54,11 +54,11 @@ public void onCommand(CommandSenderContainer sender, String[] args) { tempDataServices.getPlayerData(sender.getPlayerContainer()); if (tempData.isDestiVisible()) { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.destination.show.disabled")); } else { sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translate("command.destination.show.enabled")); } tempData.setDestiVisible(!tempData.isDestiVisible()); 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 26865bc4..6ae1e3b7 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 @@ -19,12 +19,12 @@ public void onCommand(CommandSenderContainer sender, String[] args) { if (destinationServices.teleportToDestination( args[1], sender.getPlayerContainer())) { sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translate("command.destination.teleport.success") .replaceAll("@destiname", args[1])); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.destination.teleport.error") .replaceAll("@destiname", args[1])); } 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 3804119c..9ecd7a41 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 @@ -38,7 +38,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { if (args.length > 1) { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.create.console")); return; } @@ -60,7 +60,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { } if (nameTag == null) { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.error.noname")); return; } @@ -90,16 +90,16 @@ public void onCommand(CommandSenderContainer sender, String[] args) { AdvancedPortal portal = portalServices.createPortal(player, portalTags); if (portal != null) { - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("command.create.complete")); sender.sendMessage(Lang.translate("command.create.tags")); TagReader.printArgs(sender, portal.getArgs()); } else { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.create.error")); } } else { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.error.notags")); } } 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 35bcde95..7e54c788 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 @@ -17,14 +17,14 @@ public class EndGatewayBlockSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + 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") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("command.gatewayblock")); } } 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 bc5f570a..873f6a00 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 @@ -17,14 +17,14 @@ public class EndPortalBlockSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + 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") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("command.endportalblock")); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java index f1e566e5..b01aef32 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java @@ -19,15 +19,16 @@ public void onCommand(CommandSenderContainer sender, String[] args) { var portalName = args[1]; var portal = portalServices.getPortal(portalName); if(portal == null) { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("command.portal.info.notfound", portalName)); return; } - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translateInsertVariables("command.portal.info.complete", portalName)); TagReader.printArgs(sender, portal.getArgs()); } else { - sender.sendMessage(Lang.translate("command.portal.info.noname")); + sender.sendMessage(Lang.getNegativePrefix() + + Lang.translate("command.portal.info.noname")); } } 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 da54da87..22a0bf8e 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 @@ -30,7 +30,7 @@ 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") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("translatedata.replaced")); Lang.loadLanguage(configRepository.getTranslation()); } else { @@ -74,7 +74,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { Lang.loadLanguage(configRepository.getTranslation()); sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translateInsertVariables("translatedata.updated", newTranslations.size())); } 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 5cf42175..15957417 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 @@ -15,7 +15,7 @@ public class ListPortalsSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translate("command.portal.list") + " " + portalServices.getPortalNames().stream().sorted().collect( Collectors.joining(", "))); 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 6a6910c2..4ca97d2b 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 @@ -17,7 +17,7 @@ public class PortalBlockSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { PlayerContainer player = sender.getPlayerContainer(); if (player == null) { - sender.sendMessage(Lang.translate("messageprefix.negative") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.playeronly")); } else { player.giveItem( @@ -27,7 +27,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { + "\u00A77: Rotate portal block", "\u00A7r\u00A7e" + Lang.translate("items.interact.right") + "\u00A77: Place portal block"); - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("command.portalblock")); } } 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 1af83111..2dbf5d28 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 @@ -30,7 +30,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { portalServices.loadPortals(); destinationServices.loadDestinations(); Lang.loadLanguage(configRepository.getTranslation()); - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("command.reload.reloaded")); } 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 8e5fc1af..38ca8aaf 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 @@ -18,11 +18,11 @@ public void onCommand(CommandSenderContainer sender, String[] args) { if (portalServices.removePortal(args[1], sender.getPlayerContainer())) { sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translate("command.portal.remove.complete")); } else { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.portal.remove.error")); } } else { 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 e4e6bc5f..a21caf3a 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 @@ -21,7 +21,7 @@ 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") + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.playeronly")); } else { player.giveItem( @@ -35,7 +35,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { "\u00A7r\u00A7e" + Lang.translate("items.interact.right") + "\u00A77: " + Lang.translateInsertVariables("items.selector.pos", "2")); - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("command.selector")); } } 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 b2cf23a2..e37e8b60 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 @@ -62,7 +62,7 @@ public class ShowPortalSubCommand public void onCommand(CommandSenderContainer sender, String[] args) { if (core.getMcVersion()[1] < 16) { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.portal.show.unsupported")); return; } @@ -71,10 +71,10 @@ public void onCommand(CommandSenderContainer sender, String[] args) { playerDataServices.getPlayerData(sender.getPlayerContainer()); if (tempData.isPortalVisible()) { sender.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("command.portal.show.disabled")); } else { - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translate("command.portal.show.enabled")); } tempData.setPortalVisible(!tempData.isPortalVisible()); 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 048d194f..d3a12a5d 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 @@ -9,7 +9,7 @@ public class VersionSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + " Advanced Portals v" + AdvancedPortalsCore.version); } 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 f35d4e84..2d5c67bc 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 @@ -13,6 +13,8 @@ public interface PlayerContainer extends EntityContainer { void sendMessage(String message); + void sendActionBar(String message); + boolean isOp(); boolean hasPermission(String permission); 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 4f0481d1..b9f625e1 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 @@ -10,10 +10,7 @@ import com.sekwah.advancedportals.core.warphandler.Tag; import com.sekwah.advancedportals.core.warphandler.TriggerType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Possibly look at adding the ability to add some tags to destinations such as @@ -33,8 +30,9 @@ public class Destination implements TagTarget { private PlayerLocation loc; private HashMap args = new HashMap<>(); + private transient List destiTags = new ArrayList<>(); - private transient Set argsCol; + private transient boolean isSorted = false; public Destination() { this.loc = new PlayerLocation(); @@ -51,29 +49,55 @@ public String[] getArgValues(String argName) { @Override public void setArgValues(String argName, String[] argValue) { + this.isSorted = false; this.args.put(argName, argValue); } @Override public void addArg(String argName, String argValues) { + this.isSorted = false; } public void setArgValues(DataTag portalTag) { + this.isSorted = false; this.setArgValues(portalTag.NAME, portalTag.VALUES); } public void removeArg(String arg) { + this.isSorted = false; this.args.remove(arg); } + private void updateDestiTagList() { + destiTags.clear(); + for (Map.Entry entry : args.entrySet()) { + this.destiTags.add(new DataTag(entry.getKey(), entry.getValue())); + } + + this.destiTags.sort(Comparator.comparingInt(o -> { + var tag = tagRegistry.getTag(o.NAME); + if (tag instanceof Tag.OrderPriority tagPriority) { + return tagPriority.getPriority().ordinal(); + } else { + return Tag.Priority.NORMAL.ordinal(); + } + })); + isSorted = true; + } + public boolean activate(PlayerContainer player) { ActivationData data = new ActivationData(TriggerType.MANUAL); - this.portalActivate(player, data); - this.postActivate(player, data); - return true; + if(this.portalActivate(player, data)) { + this.postActivate(player, data); + return true; + } + return false; } public boolean portalActivate(PlayerContainer player, ActivationData data) { + if(!isSorted) { + updateDestiTagList(); + } DataTag[] destiTags = new DataTag[args.size()]; int i = 0; for (Map.Entry entry : args.entrySet()) { @@ -81,15 +105,15 @@ public boolean portalActivate(PlayerContainer player, ActivationData data) { } for (DataTag destiTag : destiTags) { Tag.Activation activationHandler = - tagRegistry.getActivationHandler(destiTag.NAME); - if (activationHandler != null) { - activationHandler.preActivated( - this, player, data, this.getArgValues(destiTag.NAME)); + tagRegistry.getActivationHandler(destiTag.NAME, Tag.TagType.DESTINATION); + if (activationHandler != null && !activationHandler.preActivated( + this, player, data, this.getArgValues(destiTag.NAME))) { + return false; } } for (DataTag destiTag : destiTags) { Tag.Activation activationHandler = - tagRegistry.getActivationHandler(destiTag.NAME); + tagRegistry.getActivationHandler(destiTag.NAME, Tag.TagType.DESTINATION); if (activationHandler != null) { activationHandler.activated(this, player, data, this.getArgValues(destiTag.NAME)); @@ -106,7 +130,7 @@ public void postActivate(PlayerContainer player, ActivationData data) { } for (DataTag destiTag : destiTags) { Tag.Activation activationHandler = - tagRegistry.getActivationHandler(destiTag.NAME); + tagRegistry.getActivationHandler(destiTag.NAME, Tag.TagType.DESTINATION); if (activationHandler != null) { activationHandler.postActivated( this, player, data, this.getArgValues(destiTag.NAME)); @@ -122,6 +146,10 @@ public ArrayList getArgs() { return tagList; } + public String getName() { + return this.getArgValues("name")[0]; + } + public PlayerLocation getLoc() { return loc; } 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 abf8b51e..035dbaba 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 @@ -77,12 +77,13 @@ public void addArg(String argName, String argValues) { // TODO need to add the ability to add args after creation } - private void updatePortalTagList() { + public void updatePortalTagList() { portalTags.clear(); int i = 0; for (Map.Entry entry : args.entrySet()) { this.portalTags.add(new DataTag(entry.getKey(), entry.getValue())); } + // sort the tags by priority this.portalTags.sort(Comparator.comparingInt(o -> { var tag = tagRegistry.getTag(o.NAME); @@ -92,6 +93,7 @@ private void updatePortalTagList() { return Tag.Priority.NORMAL.ordinal(); } })); + isSorted = true; } @Override @@ -138,7 +140,6 @@ public void updateBounds(BlockLocation loc1, BlockLocation loc2) { public ActivationResult activate(PlayerContainer player, TriggerType triggerType) { if(!isSorted) { updatePortalTagList(); - isSorted = true; } var playerData = playerDataServices.getPlayerData(player); @@ -162,7 +163,7 @@ public ActivationResult activate(PlayerContainer player, TriggerType triggerType for (DataTag portalTag : this.portalTags) { Tag.Activation activationHandler = - tagRegistry.getActivationHandler(portalTag.NAME); + tagRegistry.getActivationHandler(portalTag.NAME, Tag.TagType.PORTAL); if (activationHandler != null) { var preActivated = activationHandler.preActivated( this, player, data, this.getArgValues(portalTag.NAME)); @@ -177,7 +178,7 @@ public ActivationResult activate(PlayerContainer player, TriggerType triggerType } for (DataTag portalTag : this.portalTags) { Tag.Activation activationHandler = - tagRegistry.getActivationHandler(portalTag.NAME); + tagRegistry.getActivationHandler(portalTag.NAME, Tag.TagType.PORTAL); if (activationHandler != null && !activationHandler.activated( this, player, data, this.getArgValues(portalTag.NAME))) { @@ -186,7 +187,7 @@ public ActivationResult activate(PlayerContainer player, TriggerType triggerType } for (DataTag portalTag : this.portalTags) { Tag.Activation activationHandler = - tagRegistry.getActivationHandler(portalTag.NAME); + tagRegistry.getActivationHandler(portalTag.NAME, Tag.TagType.PORTAL); if (activationHandler != null) { activationHandler.postActivated( this, player, data, this.getArgValues(portalTag.NAME)); 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 9bcdf976..ca7eca72 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 @@ -19,6 +19,7 @@ public class TagRegistry { private final ArrayList tags = new ArrayList<>(); + private final Map tagMap = new HashMap<>(); private final Map activationTags = new HashMap<>(); private final Map creationTags = new HashMap<>(); private final Map statusTags = new HashMap<>(); @@ -32,8 +33,12 @@ public class TagRegistry { * @param arg * @return */ - public Tag.Activation getActivationHandler(String arg) { - return this.activationTags.get(arg); + public Tag.Activation getActivationHandler(String arg, Tag.TagType targetType) { + var tag = this.activationTags.get(arg); + if (tag != null && Arrays.asList(tag.getTagTypes()).contains(targetType)) { + return tag; + } + return null; } /** @@ -91,6 +96,8 @@ public boolean registerTag(Tag tag) { return false; } + this.tagMap.put(tagName, tag); + if (tag instanceof Tag.Activation tagActivation) { this.activationTags.put(tagName, tagActivation); } @@ -104,12 +111,7 @@ public boolean registerTag(Tag tag) { } public Tag getTag(String tagName) { - for (Tag tag : this.tags) { - if (tag.getName().equals(tagName)) { - return tag; - } - } - return null; + return this.tagMap.get(tagName); } public List getTags() { 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 6899c169..be8a1e45 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 @@ -40,5 +40,9 @@ public interface ConfigRepository { String getWarpSound(); + boolean warpMessageOnActionBar(); + + boolean warpMessageInChat(); + String getWarpParticles(); } 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 fd39e35d..425b82b2 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 @@ -116,6 +116,16 @@ public CommandPortalConfig getCommandPortals() { return this.config.commandPortals; } + @Override + public boolean warpMessageOnActionBar() { + return this.config.warpMessageOnActionBar; + } + + @Override + public boolean warpMessageInChat() { + return this.config.warpMessageInChat; + } + @Override public void storeConfig() { this.dataStorage.storeFile(this.config, "config.yaml"); 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 77fc0806..3a150227 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 @@ -34,5 +34,9 @@ public class Config { public boolean playFailSound = true; + public boolean warpMessageOnActionBar = true; + + public boolean warpMessageInChat = false; + public CommandPortalConfig commandPortals = new CommandPortalConfig(); } 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 759a2668..4d0addb2 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 @@ -61,19 +61,19 @@ public Destination createDesti(PlayerContainer player, // 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") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("desti.error.noname")); return null; } if (name == null || name.equals("")) { if (player != null) - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.error.noname")); return null; } else if (this.destinationRepository.containsKey(name)) { if (player != null) - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables( "command.error.nametaken", name)); return null; @@ -100,7 +100,7 @@ public Destination createDesti(PlayerContainer player, } } catch (Exception e) { e.printStackTrace(); - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("desti.error.save")); } return desti; 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 3e87b81a..2ece276a 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 @@ -164,7 +164,7 @@ public AdvancedPortal createPortal(PlayerContainer player, if (tempData.getPos1() == null || tempData.getPos2() == null) { player.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("portal.error.selection.missing")); return null; } @@ -172,7 +172,7 @@ public AdvancedPortal createPortal(PlayerContainer player, if (!tempData.getPos1().getWorldName().equals( tempData.getPos2().getWorldName())) { player.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("portal.error.selection.differentworlds")); return null; } @@ -193,12 +193,12 @@ public AdvancedPortal createPortal(PlayerContainer player, String name = nameTag == null ? null : nameTag.VALUES[0]; if (nameTag == null || name == null || name.isEmpty()) { if (player != null) - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.error.noname")); return null; } else if (this.portalRepository.containsKey(name)) { if (player != null) - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables( "command.error.nametaken", name)); return null; @@ -230,7 +230,7 @@ public AdvancedPortal createPortal(PlayerContainer player, } catch (Exception e) { e.printStackTrace(); if (player != null) - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("portal.error.save")); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java index 8f85be06..458ba03e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java @@ -51,7 +51,7 @@ public boolean preActivated(TagTarget target, PlayerContainer player, var commandPortals = configRepository.getCommandPortals(); if (!commandPortals.enabled) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.command.disabled")); return false; } @@ -62,7 +62,7 @@ public boolean preActivated(TagTarget target, PlayerContainer player, case '!': if (!commandPortals.op) { player.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("tag.command.op.disabled")); return false; } @@ -70,7 +70,7 @@ public boolean preActivated(TagTarget target, PlayerContainer player, case '#': if (!commandPortals.console) { player.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate("tag.command.console.disabled")); return false; } @@ -78,7 +78,7 @@ public boolean preActivated(TagTarget target, PlayerContainer player, case '^': if (!commandPortals.permsWildcard) { player.sendMessage( - Lang.translate("messageprefix.negative") + Lang.getNegativePrefix() + Lang.translate( "tag.command.permswildcard.disabled")); return false; @@ -140,7 +140,7 @@ public boolean created(TagTarget target, PlayerContainer player, if (argData != null) { var commandPortals = configRepository.getCommandPortals(); if (!commandPortals.enabled) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.command.disabled")); return false; } @@ -149,12 +149,12 @@ public boolean created(TagTarget target, PlayerContainer player, return switch (executionCommand) { case '!' -> { if (!commandPortals.op) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.command.op.disabled")); yield false; } if (!player.hasPermission("advancedportals.createportal.commandlevel.op")) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("tag.command.nopermission", "OP")); yield false; } @@ -162,12 +162,12 @@ public boolean created(TagTarget target, PlayerContainer player, } case '#' -> { if (!commandPortals.console) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.command.console.disabled")); yield false; } if (!player.hasPermission("advancedportals.createportal.commandlevel.console")) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("tag.command.nopermission","Console")); yield false; } @@ -175,12 +175,12 @@ public boolean created(TagTarget target, PlayerContainer player, } case '^' -> { if (!commandPortals.permsWildcard) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.command.permswildcard.disabled")); yield false; } if (!player.hasPermission("advancedportals.createportal.commandlevel.permswild")) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("tag.command.nopermission", "*")); yield false; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/CooldownTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/CooldownTag.java index ff27590d..89ca45cc 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/CooldownTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/CooldownTag.java @@ -104,7 +104,7 @@ public boolean created(TagTarget target, PlayerContainer player, try { Integer.parseInt(argData[0]); } catch (NumberFormatException e) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.cooldown.fail")); return false; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java index 1e28c425..774f0895 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java @@ -4,24 +4,35 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.destination.Destination; import com.sekwah.advancedportals.core.effect.WarpEffect; +import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.registry.TagTarget; import com.sekwah.advancedportals.core.registry.WarpEffectRegistry; +import com.sekwah.advancedportals.core.repository.ConfigRepository; 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 javax.annotation.Nullable; +import java.util.Arrays; import java.util.List; +import java.util.Random; public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split { public static String TAG_NAME = "destination"; + + @Inject + ConfigRepository configRepository; + @Inject DestinationServices destinationServices; @Inject WarpEffectRegistry warpEffectRegistry; + @Inject + private transient TagRegistry tagRegistry; + private final TagType[] tagTypes = new TagType[] {TagType.PORTAL}; @Override @@ -34,6 +45,8 @@ public String getName() { return TAG_NAME; } + private final Random random = new Random(); + @Override public String[] getAliases() { return new String[] {"desti"}; @@ -47,25 +60,61 @@ public String description() { @Override 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])) { - return true; + if (argData.length == 0) { + return false; + } + String selectedArg = argData[random.nextInt(argData.length)]; + + activeData.setMetadata(TAG_NAME, selectedArg); + + if(destinationServices.getDestination(selectedArg) == null) { + player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("desti.error.notfound", selectedArg)); + return false; + } + + // Check and trigger all tags on the destination + Destination destination = destinationServices.getDestination(selectedArg); + if (destination != null) { + + for (var destiTag : destination.getArgs()) { + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(destiTag.NAME, Tag.TagType.DESTINATION); + if (activationHandler != null + && !activationHandler.preActivated(target, player, activeData, argData)) { + return false; + } } } - return false; + + return true; } @Override public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + var selectedArg = activationData.getMetadata(TAG_NAME); + Destination destination = destinationServices.getDestination(selectedArg); + if (destination != null) { + for (var destiTag : destination.getArgs()) { + Tag.Activation activationHandler = + tagRegistry.getActivationHandler(destiTag.NAME, Tag.TagType.DESTINATION); + if (activationHandler != null) { + activationHandler.postActivated(target, player, activationData, argData); + } + } + var message = activationData.getMetadata(MessageTag.TAG_NAME); + if(message == null) { + sendMessage(player, Lang.translateInsertVariables("desti.warpdesti.warp", destination.getName().replaceAll("_", " "))); + } + } } @Override public boolean activated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + var selectedArg = activationData.getMetadata(TAG_NAME); Destination destination = - destinationServices.getDestination(argData[0]); + destinationServices.getDestination(selectedArg); if (destination != null) { var warpEffectVisual = warpEffectRegistry.getVisualEffect("ender"); if (warpEffectVisual != null) { @@ -87,6 +136,15 @@ public boolean activated(TagTarget target, PlayerContainer player, return true; } + public void sendMessage(PlayerContainer player, String message) { + if(this.configRepository.warpMessageOnActionBar()) { + player.sendActionBar(Lang.convertColors(message)); + } + else if(this.configRepository.warpMessageInChat()) { + player.sendMessage(Lang.getPositivePrefix() + " " + Lang.convertColors(message)); + } + } + @Override public List autoComplete(String argData) { return destinationServices.getDestinationNames(); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java new file mode 100644 index 00000000..69114d03 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java @@ -0,0 +1,92 @@ +package com.sekwah.advancedportals.core.tags; + +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; +import com.sekwah.advancedportals.core.registry.TagTarget; +import com.sekwah.advancedportals.core.repository.ConfigRepository; +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 java.util.List; +import java.util.Random; + +/** + * 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 tags shouldn't be like this unless they are to be paired with + * another tag. + */ +public class MessageTag implements Tag.Activation { + + @Inject + ConfigRepository configRepository; + + public static String TAG_NAME = "message"; + + private final TagType[] tagTypes = + new TagType[] {TagType.PORTAL, TagType.DESTINATION}; + + private final Random random = new Random(); + + @Override + public TagType[] getTagTypes() { + return tagTypes; + } + + @Override + public String getName() { + return TAG_NAME; + } + + @Override + public String[] getAliases() { + return null; + } + + @Override + public String description() { + return Lang.translate("tag.message.description"); + } + + @Override + public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + + String selectedArg = argData[random.nextInt(argData.length)]; + activeData.setMetadata(TAG_NAME, selectedArg); + activeData.setWarpStatus(ActivationData.WarpedStatus.ACTIVATED); + return true; + } + + @Override + public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + + var destination = activationData.getMetadata(DestiTag.TAG_NAME); + var message = activationData.getMetadata(TAG_NAME); + if(destination == null) { + destination = ""; + } else { + destination = destination.replaceAll("_", " "); + } + + sendMessage(player, message.replaceAll("@desti", destination).replaceAll("@player", player.getName())); + } + + @Override + public boolean activated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + return true; + } + + public void sendMessage(PlayerContainer player, String message) { + if(this.configRepository.warpMessageOnActionBar()) { + player.sendActionBar(Lang.convertColors(message)); + } + else if(this.configRepository.warpMessageInChat()) { + player.sendMessage(Lang.getPositivePrefix() + " " + Lang.convertColors(message)); + } + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java index 0236dc50..718795ac 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java @@ -60,7 +60,7 @@ public boolean created(TagTarget target, PlayerContainer player, if (argData.length > 0) { String name = argData[0]; if (name.contains(" ")) { - player.sendMessage(Lang.translate("messageprefix.negative") + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.name.error.nospaces")); return false; } 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 5b184b3f..e115e443 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 @@ -21,6 +21,10 @@ public class Lang { public static final Lang instance = new Lang(); private final HashMap languageMap = new HashMap<>(); + private String negativePrefix; + + private String positivePrefix; + @Inject private DataStorage dataStorage; @@ -34,6 +38,17 @@ public static void loadLanguage(String fileName) { instance.injectTranslations(DEFAULT_LANG); } instance.injectTranslations(fileName); + + instance.negativePrefix = translate("messageprefix.negative"); + instance.positivePrefix = translate("messageprefix.positive"); + } + + public static String getNegativePrefix() { + return instance.negativePrefix; + } + + public static String getPositivePrefix() { + return instance.positivePrefix; } public static String translate(String s) { @@ -41,14 +56,17 @@ public static String translate(String 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"); + translation = convertColors(translation); return translation; } else { return s; } } + public static String convertColors(String s) { + return s.replaceAll("&([0-9a-frk-ox])", "\u00A7$1"); + } + public static String translateInsertVariables(String s, Object... args) { String translation = translate(s); for (int i = 1; i <= args.length; i++) { 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 2e6a7b93..34dc9ff5 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 @@ -2,6 +2,9 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; +import java.util.HashMap; +import java.util.Map; + /** * Created by on 30/07/2016. * @@ -16,6 +19,8 @@ public class ActivationData { private TriggerType triggerType; + private Map metadata = new HashMap<>(); + public WarpedStatus getWarped() { return this.warpStatus; } @@ -37,6 +42,14 @@ public TriggerType getTriggerType() { return this.triggerType; } + public String getMetadata(String key) { + return this.metadata.get(key); + } + + public void setMetadata(String key, String value) { + this.metadata.put(key, value); + } + /** * In case you need to set the status back down a step for whatever reason. * However it is not recommended. diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index fbc4f314..4f14b30e 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -74,6 +74,7 @@ created. command.portal.info.complete= Portal information for &e%1$s&a: command.portal.info.notfound= No portal by the name &e%1$s &cwas found. +command.portal.info.noname= You must specify a name. command.create.tags=&aTags&7: @@ -152,6 +153,9 @@ command.error.nametaken= The name &e%1$s &cis already taken. desti.error.save= There was a problem saving the destination. desti.error.noname= You must specify a name. (name:someNameHere) +desti.error.notfound= No destination by the name &e%1$s &cwas found. + +desti.warpdesti.warp=&aYou have warped to &e%1$s&a. error.notplayer=Only players can do that. @@ -179,6 +183,7 @@ tag.name.error.nospaces= The name cannot contain spaces. tag.triggerblock.description=Sets the trigger block/s of the portal. Comma separated or multi tag. tag.command.description=Sets a command on the post activation of the portal. Comma separated or multi tag. tag.portalEvent.description=Triggers the portal from portal events rather than the player entering the portal. (survival nether portal) +tag.message.description=Sets the message to be displayed when the portal is activated tag.cooldown.fail= The cooldown must be a number. tag.command.nopermission= You do not have permission to create a command at %1$s command level diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java index 851cc58e..66e8c484 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java @@ -27,18 +27,18 @@ public class ImportPortalSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { if (args.length > 1 && "confirm".equals(args[1])) { - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translateInsertVariables( "command.portal.import.confirm")); int destinations = importDestinations(); int portals = importPortals(); sender.sendMessage( - Lang.translate("messageprefix.positive") + Lang.getPositivePrefix() + Lang.translateInsertVariables( "command.portal.import.complete", portals, destinations)); return; } - sender.sendMessage(Lang.translate("messageprefix.positive") + sender.sendMessage(Lang.getPositivePrefix() + Lang.translateInsertVariables( "command.portal.import", getPortalCount(), getDestinationCount())); 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 e273d83d..9d4edda9 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 @@ -11,6 +11,9 @@ import com.sekwah.advancedportals.spigot.reflection.MinecraftCustomPayload; import java.util.Arrays; import java.util.UUID; + +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -44,6 +47,11 @@ public void sendMessage(String message) { player.sendMessage(message); } + @Override + public void sendActionBar(String message) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); + } + @Override public boolean isOp() { return this.player.isOp();