mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-12-23 09:28:06 +01:00
feat: message tags & priority sorting (#447)
This commit is contained in:
parent
e7b0d5e4ca
commit
e056a6836d
@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core;
|
||||
|
||||
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 @@ public class AdvancedPortalsCore {
|
||||
this.tagRegistry.registerTag(new PermissionTag());
|
||||
this.tagRegistry.registerTag(new CommandTag());
|
||||
this.tagRegistry.registerTag(new PortalEventTag());
|
||||
this.tagRegistry.registerTag(new MessageTag());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ public class CoreListeners {
|
||||
}
|
||||
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 class CoreListeners {
|
||||
}
|
||||
if (portalServices.inPortalRegionProtected(blockPos)) {
|
||||
if (player != null) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("portal.nobuild"));
|
||||
}
|
||||
return false;
|
||||
|
@ -87,7 +87,7 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
.getDetailedHelpText());
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
Lang.getNegativePrefix()
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.help.invalidhelp", args[1]));
|
||||
}
|
||||
@ -129,7 +129,7 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
subCommand.onCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
Lang.getNegativePrefix()
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.subcommand.nopermission",
|
||||
commandExecuted));
|
||||
@ -138,11 +138,11 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
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 class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
}
|
||||
|
||||
if (nameTag == null) {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("command.error.noname"));
|
||||
return;
|
||||
}
|
||||
@ -69,16 +69,16 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
@ -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(", ")));
|
||||
|
@ -19,11 +19,11 @@ public class RemoveDestiSubCommand implements SubCommand {
|
||||
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 {
|
||||
|
@ -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 class ShowDestiSubCommand
|
||||
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());
|
||||
|
@ -19,12 +19,12 @@ public class TeleportDestiSubCommand implements SubCommand {
|
||||
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]));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
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 class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
}
|
||||
|
||||
if (nameTag == null) {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("command.error.noname"));
|
||||
return;
|
||||
}
|
||||
@ -90,16 +90,16 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,16 @@ public class InfoPortalSubCommand implements SubCommand {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class LangUpdateSubCommand implements SubCommand {
|
||||
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 class LangUpdateSubCommand implements SubCommand {
|
||||
Lang.loadLanguage(configRepository.getTranslation());
|
||||
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
Lang.getPositivePrefix()
|
||||
+ Lang.translateInsertVariables("translatedata.updated",
|
||||
newTranslations.size()));
|
||||
}
|
||||
|
@ -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(", ")));
|
||||
|
@ -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 class PortalBlockSubCommand implements SubCommand {
|
||||
+ "\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"));
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class ReloadPortalSubCommand implements SubCommand {
|
||||
portalServices.loadPortals();
|
||||
destinationServices.loadDestinations();
|
||||
Lang.loadLanguage(configRepository.getTranslation());
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.getPositivePrefix()
|
||||
+ Lang.translate("command.reload.reloaded"));
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,11 @@ public class RemovePortalSubCommand implements SubCommand {
|
||||
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 {
|
||||
|
@ -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 class SelectorSubCommand implements SubCommand {
|
||||
"\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"));
|
||||
}
|
||||
}
|
||||
|
@ -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 class ShowPortalSubCommand
|
||||
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());
|
||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||
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);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ public interface PlayerContainer extends EntityContainer {
|
||||
|
||||
void sendMessage(String message);
|
||||
|
||||
void sendActionBar(String message);
|
||||
|
||||
boolean isOp();
|
||||
|
||||
boolean hasPermission(String permission);
|
||||
|
@ -10,10 +10,7 @@ import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
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<String, String[]> args = new HashMap<>();
|
||||
private transient List<DataTag> destiTags = new ArrayList<>();
|
||||
|
||||
private transient Set<String> argsCol;
|
||||
private transient boolean isSorted = false;
|
||||
|
||||
public Destination() {
|
||||
this.loc = new PlayerLocation();
|
||||
@ -51,29 +49,55 @@ public class Destination implements TagTarget {
|
||||
|
||||
@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<String, String[]> 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<String, String[]> entry : args.entrySet()) {
|
||||
@ -81,15 +105,15 @@ public class Destination implements TagTarget {
|
||||
}
|
||||
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 class Destination implements TagTarget {
|
||||
}
|
||||
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 class Destination implements TagTarget {
|
||||
return tagList;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.getArgValues("name")[0];
|
||||
}
|
||||
|
||||
public PlayerLocation getLoc() {
|
||||
return loc;
|
||||
}
|
||||
|
@ -77,12 +77,13 @@ public class AdvancedPortal implements TagTarget {
|
||||
// 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<String, String[]> 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 @@ public class AdvancedPortal implements TagTarget {
|
||||
return Tag.Priority.NORMAL.ordinal();
|
||||
}
|
||||
}));
|
||||
isSorted = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,7 +140,6 @@ public class AdvancedPortal implements TagTarget {
|
||||
public ActivationResult activate(PlayerContainer player, TriggerType triggerType) {
|
||||
if(!isSorted) {
|
||||
updatePortalTagList();
|
||||
isSorted = true;
|
||||
}
|
||||
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
@ -162,7 +163,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
|
||||
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 class AdvancedPortal implements TagTarget {
|
||||
}
|
||||
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 class AdvancedPortal implements TagTarget {
|
||||
}
|
||||
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));
|
||||
|
@ -19,6 +19,7 @@ public class TagRegistry {
|
||||
|
||||
private final ArrayList<Tag> tags = new ArrayList<>();
|
||||
|
||||
private final Map<String, Tag> tagMap = new HashMap<>();
|
||||
private final Map<String, Tag.Activation> activationTags = new HashMap<>();
|
||||
private final Map<String, Tag.Creation> creationTags = new HashMap<>();
|
||||
private final Map<String, Tag.TagStatus> 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 class TagRegistry {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.tagMap.put(tagName, tag);
|
||||
|
||||
if (tag instanceof Tag.Activation tagActivation) {
|
||||
this.activationTags.put(tagName, tagActivation);
|
||||
}
|
||||
@ -104,12 +111,7 @@ public class TagRegistry {
|
||||
}
|
||||
|
||||
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<Tag> getTags() {
|
||||
|
@ -40,5 +40,9 @@ public interface ConfigRepository {
|
||||
|
||||
String getWarpSound();
|
||||
|
||||
boolean warpMessageOnActionBar();
|
||||
|
||||
boolean warpMessageInChat();
|
||||
|
||||
String getWarpParticles();
|
||||
}
|
||||
|
@ -116,6 +116,16 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
||||
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");
|
||||
|
@ -34,5 +34,9 @@ public class Config {
|
||||
|
||||
public boolean playFailSound = true;
|
||||
|
||||
public boolean warpMessageOnActionBar = true;
|
||||
|
||||
public boolean warpMessageInChat = false;
|
||||
|
||||
public CommandPortalConfig commandPortals = new CommandPortalConfig();
|
||||
}
|
||||
|
@ -61,19 +61,19 @@ public class DestinationServices {
|
||||
// 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 class DestinationServices {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("desti.error.save"));
|
||||
}
|
||||
return desti;
|
||||
|
@ -164,7 +164,7 @@ public class PortalServices {
|
||||
|
||||
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 class PortalServices {
|
||||
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 class PortalServices {
|
||||
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 class PortalServices {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (player != null)
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("portal.error.save"));
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
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 class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
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 class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
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 class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
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 class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
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 class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
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 class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
}
|
||||
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 class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class CooldownTag implements Tag.Activation, Tag.Creation {
|
||||
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;
|
||||
}
|
||||
|
@ -4,24 +4,35 @@ import com.google.inject.Inject;
|
||||
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 class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
return TAG_NAME;
|
||||
}
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[] {"desti"};
|
||||
@ -47,25 +60,61 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
@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 class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
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<String> autoComplete(String argData) {
|
||||
return destinationServices.getDestinationNames();
|
||||
|
@ -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.
|
||||
*
|
||||
* <p>Most of the implementation of this tag is external, this is just to allow
|
||||
* for the tag to be used.
|
||||
*
|
||||
* <p>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));
|
||||
}
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ public class NameTag implements Tag.AutoComplete, Tag.Creation {
|
||||
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;
|
||||
}
|
||||
|
@ -21,6 +21,10 @@ public class Lang {
|
||||
public static final Lang instance = new Lang();
|
||||
private final HashMap<String, String> languageMap = new HashMap<>();
|
||||
|
||||
private String negativePrefix;
|
||||
|
||||
private String positivePrefix;
|
||||
|
||||
@Inject
|
||||
private DataStorage dataStorage;
|
||||
|
||||
@ -34,6 +38,17 @@ public class Lang {
|
||||
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 class Lang {
|
||||
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++) {
|
||||
|
@ -2,6 +2,9 @@ package com.sekwah.advancedportals.core.warphandler;
|
||||
|
||||
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<String, String> metadata = new HashMap<>();
|
||||
|
||||
public WarpedStatus getWarped() {
|
||||
return this.warpStatus;
|
||||
}
|
||||
@ -37,6 +42,14 @@ public class ActivationData {
|
||||
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.
|
||||
|
@ -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
|
||||
|
@ -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()));
|
||||
|
@ -11,6 +11,9 @@ import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
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 class SpigotPlayerContainer
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user