Skip to content

Commit

Permalink
feat: message tags & priority sorting (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 authored Oct 17, 2024
1 parent b014570 commit fdec0d6
Show file tree
Hide file tree
Showing 39 changed files with 353 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface PlayerContainer extends EntityContainer {

void sendMessage(String message);

void sendActionBar(String message);

boolean isOp();

boolean hasPermission(String permission);
Expand Down
Loading

0 comments on commit fdec0d6

Please sign in to comment.