mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-11-16 15:25:11 +01:00
Improve language variable argument detection
This commit is contained in:
parent
38b658fccf
commit
5f20689ba3
@ -66,7 +66,6 @@ public class Message {
|
||||
return new Message().setMessage(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the message with all replacements done
|
||||
* @return Message as a list
|
||||
@ -197,7 +196,7 @@ public class Message {
|
||||
List<String> original = new ArrayList<>(message);
|
||||
|
||||
replaceArgumentVariables();
|
||||
replaceLanguageVariables(0);
|
||||
replaceLanguageVariables();
|
||||
|
||||
shouldReplace = !message.equals(original);
|
||||
round++;
|
||||
@ -229,10 +228,7 @@ public class Message {
|
||||
Pattern variables = Pattern.compile(Pattern.quote(VARIABLESTART)+number+Pattern.quote(VARIABLEEND));
|
||||
Matcher matches = variables.matcher(message.get(i));
|
||||
if(matches.find()) {
|
||||
// insert message
|
||||
FancyMessageFormat.insertMessage(message, ((Message)param).get(), i, matches.start(), matches.end());
|
||||
// Reset to start of the line, redo matching because the line changed and the inserted part might contain variables again
|
||||
i--;
|
||||
}
|
||||
number++;
|
||||
} else {
|
||||
@ -247,15 +243,18 @@ public class Message {
|
||||
/**
|
||||
* Replace all language variables in a message
|
||||
*/
|
||||
private void replaceLanguageVariables(int recursed) {
|
||||
private void replaceLanguageVariables() {
|
||||
if(message == null || message.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if(recursed > REPLACEMENTLIMIT) {
|
||||
AreaShop.getInstance().getLogger().warning("Reached replacement limit for message "+key+", probably has replacements loops, resulting message: "+message.toString());
|
||||
return;
|
||||
}
|
||||
Pattern variables = Pattern.compile(Pattern.quote(VARIABLESTART)+"lang:[^%\\s]+(\\|[^"+Pattern.quote(VARIABLEEND)+"]*)*"+Pattern.quote(VARIABLEEND)); // Variables cannot contain spaces and percent characters, and area enclosed by percent characters
|
||||
|
||||
Pattern variables = Pattern.compile(
|
||||
Pattern.quote(VARIABLESTART)+
|
||||
"lang:[a-zA-Z-]+"+ // Language key
|
||||
"(\\|(.*?\\|)+)?"+ // Optional message arguments
|
||||
Pattern.quote(VARIABLEEND)
|
||||
);
|
||||
|
||||
for(int i = 0; i < message.size(); i++) {
|
||||
Matcher matches = variables.matcher(message.get(i));
|
||||
if(matches.find()) {
|
||||
@ -273,11 +272,11 @@ public class Message {
|
||||
insert.replacements(arguments);
|
||||
}
|
||||
|
||||
// insert message
|
||||
//List<String> insert = AreaShop.getInstance().getLanguageManager().getRawMessage(variable.substring(6, variable.length()-1));
|
||||
// Insert message
|
||||
int startDiff = message.size()-i;
|
||||
FancyMessageFormat.insertMessage(message, insert.get(), i, matches.start(), matches.end());
|
||||
// Reset to start of the line, redo matching because the line changed and the inserted part might contain language tags again
|
||||
i--;
|
||||
// Skip to end of insert, language tags already replaced
|
||||
i = message.size()-startDiff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ helpCommand:
|
||||
- "[gold]%0% [gray]-[reset]"
|
||||
- " hover: [blue][bold]<use %0%>"
|
||||
- " command: %0%"
|
||||
region: "%lang:tRegion|%region%%"
|
||||
region: "%lang:tRegion|%region%|%"
|
||||
tRegion:
|
||||
- "[underline]%0%[/underline]"
|
||||
- " hover: Region %0%"
|
||||
- " hover: [blue][bold]<region information>"
|
||||
- " command: /areashop info region %0%"
|
||||
player: "%lang:tPlayer|%player%%"
|
||||
player: "%lang:tPlayer|%player%|%"
|
||||
tPlayer:
|
||||
- "[underline]%0%[/underline]"
|
||||
- " hover: Player %0%"
|
||||
@ -55,45 +55,45 @@ cmd-automaticRegionOnlyByPlayer: "Automatically determining the region is only p
|
||||
|
||||
help-header: "Help page, commands that you can execute."
|
||||
help-alias: "Command aliases: /areashop, /as."
|
||||
help-help: "%lang:helpCommand|/as help% Shows this help page."
|
||||
help-info: "%lang:helpCommand|/as info% Get info about current regions."
|
||||
help-rent: "%lang:helpCommand|/as rent% Rent a region or extend your current rent."
|
||||
help-buy: "%lang:helpCommand|/as buy% Buy a region."
|
||||
help-unrent: "%lang:helpCommand|/as unrent% Unrent a region."
|
||||
help-unrentOwn: "%lang:helpCommand|/as unrent% Unrent your own region."
|
||||
help-sell: "%lang:helpCommand|/as sell% Sell a region."
|
||||
help-sellOwn: "%lang:helpCommand|/as sell% Sell your own region."
|
||||
help-reload: "%lang:helpCommand|/as reload% Reload all files and update the regions."
|
||||
help-setrestore: "%lang:helpCommand|/as setrestore% Set restoring on/off and choose profile."
|
||||
help-setprice: "%lang:helpCommand|/as setprice% Change the price of a region."
|
||||
help-setduration: "%lang:helpCommand|/as setduration% Change the duration of a rent region."
|
||||
help-teleport: "%lang:helpCommand|/as tp% Teleport to your bought/rented regions."
|
||||
help-teleportAll: "%lang:helpCommand|/as tp% Teleport to a rent/buy region."
|
||||
help-setteleport: "%lang:helpCommand|/as settp% Set teleport position for bought/rented regions."
|
||||
help-setteleportAll: "%lang:helpCommand|/as settp% Set teleport position for a region."
|
||||
help-find: "%lang:helpCommand|/as find% Find an empty buy or rent."
|
||||
help-groupadd: "%lang:helpCommand|/as groupadd% Add a region to a group."
|
||||
help-groupdel: "%lang:helpCommand|/as groupdel% Delete a region from a group."
|
||||
help-grouplist: "%lang:helpCommand|/as grouplist% Display all groups currently registered."
|
||||
help-groupinfo: "%lang:helpCommand|/as groupinfo% Display information about a group."
|
||||
help-schemevent: "%lang:helpCommand|/as schemevent% Trigger a schematic event for a region."
|
||||
help-add: "%lang:helpCommand|/as add% Register a region as rent or buy."
|
||||
help-del: "%lang:helpCommand|/as del% Delete a registered region from AreaShop."
|
||||
help-addsign: "%lang:helpCommand|/as addsign% Add a sign to an existing region."
|
||||
help-delsign: "%lang:helpCommand|/as delsign% Delete the sign you are looking at."
|
||||
help-me: "%lang:helpCommand|/as me% Check which regions you have (+expiration)."
|
||||
help-setowner: "%lang:helpCommand|/as setowner% Set region owner or extend the rent."
|
||||
help-resell: "%lang:helpCommand|/as resell% Put one of your regions into resell mode."
|
||||
help-resellAll: "%lang:helpCommand|/as resell% Put a region into resell mode."
|
||||
help-stopResell: "%lang:helpCommand|/as stopresell% Put your region back into sold mode."
|
||||
help-stopResellAll: "%lang:helpCommand|/as stopresell% Put a region back into sold mode."
|
||||
help-addFriend: "%lang:helpCommand|/as addfriend% Add a friend to your region."
|
||||
help-addFriendAll: "%lang:helpCommand|/as addfriend% Add a friend to a region."
|
||||
help-delFriend: "%lang:helpCommand|/as delfriend% Delete a friend from your region."
|
||||
help-delFriendAll: "%lang:helpCommand|/as delfriend% Delete a friend from a region."
|
||||
help-linksigns: "%lang:helpCommand|/as linksigns% Use bulk sign linking mode."
|
||||
help-stack: "%lang:helpCommand|/as stack% Create multiple regions and add them."
|
||||
help-setlandlord: "%lang:helpCommand|/as setlandlord% Set the landlord of a region."
|
||||
help-help: "%lang:helpCommand|/as help|% Shows this help page."
|
||||
help-info: "%lang:helpCommand|/as info|% Get info about current regions."
|
||||
help-rent: "%lang:helpCommand|/as rent|% Rent a region or extend your current rent."
|
||||
help-buy: "%lang:helpCommand|/as buy|% Buy a region."
|
||||
help-unrent: "%lang:helpCommand|/as unrent|% Unrent a region."
|
||||
help-unrentOwn: "%lang:helpCommand|/as unrent|% Unrent your own region."
|
||||
help-sell: "%lang:helpCommand|/as sell|% Sell a region."
|
||||
help-sellOwn: "%lang:helpCommand|/as sell|% Sell your own region."
|
||||
help-reload: "%lang:helpCommand|/as reload|% Reload all files and update the regions."
|
||||
help-setrestore: "%lang:helpCommand|/as setrestore|% Set restoring on/off and choose profile."
|
||||
help-setprice: "%lang:helpCommand|/as setprice|% Change the price of a region."
|
||||
help-setduration: "%lang:helpCommand|/as setduration|% Change the duration of a rent region."
|
||||
help-teleport: "%lang:helpCommand|/as tp|% Teleport to your bought/rented regions."
|
||||
help-teleportAll: "%lang:helpCommand|/as tp|% Teleport to a rent/buy region."
|
||||
help-setteleport: "%lang:helpCommand|/as settp|% Set teleport position for bought/rented regions."
|
||||
help-setteleportAll: "%lang:helpCommand|/as settp|% Set teleport position for a region."
|
||||
help-find: "%lang:helpCommand|/as find|% Find an empty buy or rent."
|
||||
help-groupadd: "%lang:helpCommand|/as groupadd|% Add a region to a group."
|
||||
help-groupdel: "%lang:helpCommand|/as groupdel|% Delete a region from a group."
|
||||
help-grouplist: "%lang:helpCommand|/as grouplist|% Display all groups currently registered."
|
||||
help-groupinfo: "%lang:helpCommand|/as groupinfo|% Display information about a group."
|
||||
help-schemevent: "%lang:helpCommand|/as schemevent|% Trigger a schematic event for a region."
|
||||
help-add: "%lang:helpCommand|/as add|% Register a region as rent or buy."
|
||||
help-del: "%lang:helpCommand|/as del|% Delete a registered region from AreaShop."
|
||||
help-addsign: "%lang:helpCommand|/as addsign|% Add a sign to an existing region."
|
||||
help-delsign: "%lang:helpCommand|/as delsign|% Delete the sign you are looking at."
|
||||
help-me: "%lang:helpCommand|/as me|% Check which regions you have (+expiration)."
|
||||
help-setowner: "%lang:helpCommand|/as setowner|% Set region owner or extend the rent."
|
||||
help-resell: "%lang:helpCommand|/as resell|% Put one of your regions into resell mode."
|
||||
help-resellAll: "%lang:helpCommand|/as resell|% Put a region into resell mode."
|
||||
help-stopResell: "%lang:helpCommand|/as stopresell|% Put your region back into sold mode."
|
||||
help-stopResellAll: "%lang:helpCommand|/as stopresell|% Put a region back into sold mode."
|
||||
help-addFriend: "%lang:helpCommand|/as addfriend|% Add a friend to your region."
|
||||
help-addFriendAll: "%lang:helpCommand|/as addfriend|% Add a friend to a region."
|
||||
help-delFriend: "%lang:helpCommand|/as delfriend|% Delete a friend from your region."
|
||||
help-delFriendAll: "%lang:helpCommand|/as delfriend|% Delete a friend from a region."
|
||||
help-linksigns: "%lang:helpCommand|/as linksigns|% Use bulk sign linking mode."
|
||||
help-stack: "%lang:helpCommand|/as stack|% Create multiple regions and add them."
|
||||
help-setlandlord: "%lang:helpCommand|/as setlandlord|% Set the landlord of a region."
|
||||
|
||||
rent-help: "/as rent [region], the region you stand in will be used if not specified."
|
||||
rent-noPermission: "You don't have permission to rent a region."
|
||||
@ -123,7 +123,7 @@ buy-notBuyable: "Region %lang:region% is not available for buying."
|
||||
buy-maximum: "You can't buy more than %0% region(s) (you already have %1% in group '%2%')."
|
||||
buy-payError: "Something went wrong with paying, try again later."
|
||||
buy-succes: "You successfully bought %lang:region%."
|
||||
buy-successResale: "You successfully bought %lang:region% from %lang:tPlayer|%0%%."
|
||||
buy-successResale: "You successfully bought %lang:region% from %lang:tPlayer|%0%|%."
|
||||
buy-successSeller: "Your region %lang:region% has been sold to %lang:player% for %0%."
|
||||
buy-lowMoney: "You don't have enough money to buy this region (you have %0% and you need %price%)."
|
||||
buy-lowMoneyResell: "You don't have enough money to buy this region (you have %0% and you need %resellprice%)."
|
||||
@ -157,14 +157,14 @@ reload-updateCommandChanged: "'/as updaterents' and '/as updatebuys' have been r
|
||||
|
||||
info-help:
|
||||
- "/as info[break]"
|
||||
- " %lang:command|all|/as info all%[break]"
|
||||
- " %lang:command|rented|/as info rented% [group][break]"
|
||||
- " %lang:command|forrent|/as info forrent% [group][break]"
|
||||
- " %lang:command|sold|/as info sold% [group][break]"
|
||||
- " %lang:command|forsale|/as info forsale% [group][break]"
|
||||
- " %lang:command|player|/as info player% <player>[break]"
|
||||
- " %lang:command|region|/as info region% [region][break]"
|
||||
- " %lang:command|nogroup|/as info nogroup%"
|
||||
- " %lang:command|all|/as info all|%[break]"
|
||||
- " %lang:command|rented|/as info rented|% [group][break]"
|
||||
- " %lang:command|forrent|/as info forrent|% [group][break]"
|
||||
- " %lang:command|sold|/as info sold|% [group][break]"
|
||||
- " %lang:command|forsale|/as info forsale|% [group][break]"
|
||||
- " %lang:command|player|/as info player|% <player>[break]"
|
||||
- " %lang:command|region|/as info region|% [region][break]"
|
||||
- " %lang:command|nogroup|/as info nogroup|%"
|
||||
info-noPermission: "You don't have permission to get information about regions."
|
||||
info-all-rents: "Regions registered for renting: [gray]%0%."
|
||||
info-all-noRents: "There are no regions registered for renting."
|
||||
@ -182,10 +182,10 @@ info-forsale: "Regions for sale: [gray]%0%."
|
||||
info-noForsale: "All regions are sold."
|
||||
info-noFiltergroup: "Group '%0%' does not exist and therefore cannot be used to limit the results."
|
||||
info-playerHelp: "/as info player <name>."
|
||||
info-playerRents: "Regions rented by %lang:tPlayer|%0%%: [gray]%1%"
|
||||
info-playerNoRents: "%lang:tPlayer|%0%% has not rented a region."
|
||||
info-playerBuys: "Regions bought by %lang:tPlayer|%0%%: [gray]%1%."
|
||||
info-playerNoBuys: "%lang:tPlayer|%0%% has not bought a region."
|
||||
info-playerRents: "Regions rented by %lang:tPlayer|%0%|%: [gray]%1%"
|
||||
info-playerNoRents: "%lang:tPlayer|%0%|% has not rented a region."
|
||||
info-playerBuys: "Regions bought by %lang:tPlayer|%0%|%: [gray]%1%."
|
||||
info-playerNoBuys: "%lang:tPlayer|%0%|% has not bought a region."
|
||||
info-regionHelp: "/as info region [name], the region you stand in will be used if not specified."
|
||||
info-regionHeaderRent: "[darkgreen]Information about %region%:"
|
||||
info-regionHeaderBuy: "[darkgreen]Information about %region%:"
|
||||
@ -354,8 +354,8 @@ addsign-help: "/as addsign [region] [profile]."
|
||||
addsign-noSign: "You are not looking at a sign."
|
||||
addsign-noRegion: "Region '%0%' is not known in AreaShop, check if you added it to AreaShop already."
|
||||
addsign-noRegions: "No region found around the sign position."
|
||||
addsign-couldNotDetect: "Found multiple regions around the sign, specify region as extra argument (2 of the regions that were found: %lang:tRegion|%0%% and %lang:tRegion|%1%%)."
|
||||
addsign-couldNotDetectSign: "Found multiple regions around the sign, specify region on the second line (2 of the regions that were found: %lang:tRegion|%0%% and %lang:tRegion|%1%%)."
|
||||
addsign-couldNotDetect: "Found multiple regions around the sign, specify region as extra argument (2 of the regions that were found: %lang:tRegion|%0%|% and %lang:tRegion|%1%|%)."
|
||||
addsign-couldNotDetectSign: "Found multiple regions around the sign, specify region on the second line (2 of the regions that were found: %lang:tRegion|%0%|% and %lang:tRegion|%1%|%)."
|
||||
addsign-wrongProfile: "The specified profile does not exist, use one of the following (check config): [gray]%0%."
|
||||
addsign-profile:
|
||||
- "[underline]%0%[/underline]"
|
||||
@ -414,9 +414,9 @@ stopresell-noPermissionOther: "You don't have permission to set regions back to
|
||||
addfriend-help: "/as addfriend <player> [region], the region you stand in will be used if not specified."
|
||||
addfriend-noPermissionOther: "You don't have permission to add friends to regions that are not yours."
|
||||
addfriend-noPermission: "You don't have permission to add friends to your region."
|
||||
addfriend-successOther: "%lang:tPlayer|%0%% has been added as friend to region %lang:region%."
|
||||
addfriend-success: "%lang:tPlayer|%0%% has been added as friend to your region %lang:region%."
|
||||
addfriend-alreadyAdded: "%lang:tPlayer|%0%% is already added as friend for this region."
|
||||
addfriend-successOther: "%lang:tPlayer|%0%|% has been added as friend to region %lang:region%."
|
||||
addfriend-success: "%lang:tPlayer|%0%|% has been added as friend to your region %lang:region%."
|
||||
addfriend-alreadyAdded: "%lang:tPlayer|%0%|% is already added as friend for this region."
|
||||
addfriend-self: "Adding the owner of the region as friend would be pointless."
|
||||
addfriend-noOwner: "You cannot add friends to a region without owner."
|
||||
addfriend-notVisited: "You cannot add %0% because he did not visit the server yet."
|
||||
@ -424,9 +424,9 @@ addfriend-notVisited: "You cannot add %0% because he did not visit the server ye
|
||||
delfriend-help: "/as delfriend <player> [region], the region you stand in will be used if not specified."
|
||||
delfriend-noPermissionOther: "You don't have permission to delete friends from regions that are not yours."
|
||||
delfriend-noPermission: "You don't have permission to delete friends from your region."
|
||||
delfriend-successOther: "%lang:tPlayer|%0%% has been deleted as friend from region %lang:region%."
|
||||
delfriend-success: "%lang:tPlayer|%0%% has been deleted as friend from your region %lang:region%."
|
||||
delfriend-notAdded: "%lang:tPlayer|%0%% is not added as friend for this region."
|
||||
delfriend-successOther: "%lang:tPlayer|%0%|% has been deleted as friend from region %lang:region%."
|
||||
delfriend-success: "%lang:tPlayer|%0%|% has been deleted as friend from your region %lang:region%."
|
||||
delfriend-notAdded: "%lang:tPlayer|%0%|% is not added as friend for this region."
|
||||
delfriend-noOwner: "You cannot remove friends from a region without owner."
|
||||
|
||||
linksigns-multipleRegions: "Found multiple regions: [gray]%0%."
|
||||
@ -443,12 +443,12 @@ linksigns-stopped: "Exited sign linking mode."
|
||||
|
||||
stack-help:
|
||||
- "/as stack <amount> <gap> <name> <rent|buy> [group].[break]"
|
||||
- "[gray] <amount> Number of regions that will be created."
|
||||
- " <gap> Blocks distance between the regions."
|
||||
- " <name> Name of the regions (number will be behind it)."
|
||||
- " <rent|buy> Make then rent or buy regions."
|
||||
- " [group] A group to add the created regions to."
|
||||
- " The regions will be created in the direction you are facing."
|
||||
- " [gray]<amount> Number of regions that will be created.[break]"
|
||||
- " [gray]<gap> Blocks distance between the regions.[break]"
|
||||
- " [gray]<name> Name of the regions (number will be behind it).[break]"
|
||||
- " [gray]<rent|buy> Make then rent or buy regions.[break]"
|
||||
- " [gray][group] A group to add the created regions to.[break]"
|
||||
- " [gray]The regions will be created in the direction you are facing."
|
||||
stack-accepted: "Starting to create %0% %1% regions with %2% blocks in between, names start with %3% and have a number behind them.%4%"
|
||||
stack-addToGroup: " Created regions will be added to the group '%0%'."
|
||||
stack-noPermission: "You don't have permission to create and add regions to AreaShop in bulk."
|
||||
|
Loading…
Reference in New Issue
Block a user