Skip to content

Commit 566a082

Browse files
authored
Merge pull request #52 from jamailun/main
Configurable regex for description
2 parents 8d88120 + cf4dad4 commit 566a082

16 files changed

Lines changed: 85 additions & 22 deletions

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "fr.xyness"
10-
version = "1.11.6.1"
10+
version = "1.11.7.0"
1111

1212
java {
1313
toolchain {

langs/en_US.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ world-list-changeda-via-command: "§fWorld §e%name%§f removed from §edisabled
140140
cant-add-member-anymore: "§cYou have reached the maximum number of members per claim."
141141
you-cannot-use-this-name: "§cYou cannot use 'claim-' in your new claim name."
142142
incorrect-characters-name: "§cYou must use a name with only letters and numbers."
143-
incorrect-characters-description: "§cYou must use a description with only letters and numbers."
143+
incorrect-characters-description: "§cThe provided description contains illegal characters."
144144
claim-not-an-admin-claim: "§cThis claim is not a protected area."
145145
not-using-database: "§cThe database is disabled in config.yml."
146146
member-limit-must-be-positive: "§cThe member limit must be positive."

langs/fr_FR.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ world-list-changeda-via-command: "§fMonde §e%name%§f retiré des §emondes d
119119
cant-add-member-anymore: "§cVous avez atteint le nombre maximum de membres par claim."
120120
you-cannot-use-this-name: "§cVous ne pouvez pas utiliser 'claim-' dans votre nouveau nom de claim."
121121
incorrect-characters-name: "§cVous devez utiliser un nom avec seulement des lettres et des chiffres."
122-
incorrect-characters-description: "§cVous devez utiliser une description avec seulement des lettres et des chiffres."
122+
incorrect-characters-description: "§cLa description fournie contient des caractères illégaux."
123123
claim-not-an-admin-claim: "§cCe claim n'est pas une zone protégée."
124124
not-using-database: "§cLa base de données est désactivée dans config.yml."
125125
member-limit-must-be-positive: "§cLa limite de membres doit être positive."

langs/pt_BR.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ world-list-changeda-via-command: "§fMundo §e%name%§f removido dos §emundos d
138138
cant-add-member-anymore: "§cVocê atingiu o número máximo de membros por claim."
139139
you-cannot-use-this-name: "§cVocê não pode usar 'claim-' no seu novo nome de claim."
140140
incorrect-characters-name: "§cVocê deve usar um nome com apenas letras e números."
141-
incorrect-characters-description: "§cVocê deve usar uma descrição com apenas letras e números."
141+
incorrect-characters-description: "§cA descrição fornecida contém caracteres ilegais."
142142
claim-not-an-admin-claim: "§cEste claim não é uma área protegida."
143143
not-using-database: "§cO banco de dados está desativado no config.yml."
144144
member-limit-must-be-positive: "§cO limite de membros deve ser positivo."

langs/vi_VN.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ cant-add-member-anymore: §cBạn đã đạt được số lượng thành viê
139139
you-cannot-use-this-name: §cBạn không thể chiếm đóng mới trong khi khu vực đang chiếm
140140
đóng.
141141
incorrect-characters-name: §cBạn phải sử dụng tên chỉ với các chữ cái và số.
142-
incorrect-characters-description: §cBạn phải sử dụng một mô tả chỉ với các chữ cái
143-
và số.
142+
incorrect-characters-description: §cMô tả được cung cấp có chứa ký tự không hợp lệ.
144143
claim-not-an-admin-claim: §cKhu vực này không phải là một khu vực được bảo vệ.
145144
not-using-database: §cCơ sở dữ liệu bị vô hiệu hóa config.yml.
146145
member-limit-must-be-positive: §cGiới hạn thành viên phải tích cực.

langs/zh_CN.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ world-list-changeda-via-command: "§f世界 §e%name%§f 已从§e 禁用世界
140140
cant-add-member-anymore: "§c您已达到每个领地的最大成员数量。"
141141
you-cannot-use-this-name: "§c您不能在新的领地名称中使用 'claim-'。"
142142
incorrect-characters-name: "§c您必须使用仅包含字母和数字的名称。"
143-
incorrect-characters-description: "§c您必须使用仅包含字母和数字的描述"
143+
incorrect-characters-description: "§c提供的描述包含非法字符"
144144
claim-not-an-admin-claim: "§c此领地不是受保护区域。"
145145
not-using-database: "§c在 config.yml 中禁用了数据库。"
146146
member-limit-must-be-positive: "§c成员限制必须为正数。"

src/main/java/fr/xyness/SCS/Commands/ClaimCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private void handleDesc(Player player, String playerName, String[] args) {
229229
player.sendMessage(instance.getLanguage().getMessage("claim-description-too-long"));
230230
return;
231231
}
232-
if (!description.matches("^[a-zA-Z0-9\\s]+$")) {
232+
if (!instance.getSettings().getDescriptionPatternClaims().matcher(description).find()) {
233233
player.sendMessage(instance.getLanguage().getMessage("incorrect-characters-description"));
234234
return;
235235
}

src/main/java/fr/xyness/SCS/Commands/ProtectedAreaCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ private void handleDesc(Player player, String[] args) {
168168
player.sendMessage(instance.getLanguage().getMessage("claim-description-too-long"));
169169
return;
170170
}
171-
if (!description.matches("^[a-zA-Z0-9]+$")) {
172-
player.sendMessage(instance.getLanguage().getMessage("incorrect-characters-description"));
173-
return;
171+
if (!instance.getSettings().getDescriptionPatternProtected().matcher(description).find()) {
172+
player.sendMessage(instance.getLanguage().getMessage("incorrect-characters-description"));
173+
return;
174174
}
175175
Claim claim = instance.getMain().getProtectedAreaByName(args[1]);
176176
instance.getMain().setClaimDescription(claim, description)

src/main/java/fr/xyness/SCS/Config/ClaimSettings.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import java.util.Map;
88
import java.util.Objects;
99
import java.util.Set;
10+
import java.util.regex.Pattern;
11+
import java.util.regex.PatternSyntaxException;
1012
import java.util.stream.Collectors;
1113

14+
import fr.xyness.SCS.SimpleClaimSystem;
15+
import net.md_5.bungee.api.ChatColor;
1216
import org.bukkit.Location;
1317
import org.bukkit.Material;
1418
import org.bukkit.entity.EntityType;
@@ -20,6 +24,10 @@
2024
*/
2125
public class ClaimSettings {
2226

27+
private final SimpleClaimSystem instance;
28+
public ClaimSettings(SimpleClaimSystem instance) {
29+
this.instance = instance;
30+
}
2331

2432
// ***************
2533
// * Variables *
@@ -83,6 +91,15 @@ public class ClaimSettings {
8391
/** Location of the expulsion */
8492
private Location expulsionLocation;
8593

94+
/** Regex for the description of player claims. */
95+
private Pattern descriptionRegexClaims;
96+
97+
/** Same, but for the protected areas. */
98+
private Pattern descriptionRegexProtected;
99+
100+
/** Default description pattern. Used if the user regex is not valid. */
101+
private static final Pattern DEFAULT_DESCRIPTION_PATTERN = Pattern.compile("^[a-zA-Z0-9\\s]+$");
102+
86103

87104
// ********************
88105
// * Others Methods *
@@ -106,6 +123,8 @@ public void clearAll() {
106123
groupsSettings.clear();
107124
worlds.clear();
108125
aliases.clear();
126+
descriptionRegexClaims = null;
127+
descriptionRegexProtected = null;
109128
worldsAliases.clear();
110129
}
111130

@@ -569,4 +588,36 @@ public void setPlaceBlocksIgnore(List<String> mat) {
569588
public Map<String, Boolean> getStatusSettings() {
570589
return enabledSettings;
571590
}
591+
592+
/**
593+
* Get the pattern for the description of claims.
594+
* @return a non-null instance of a pattern. If the provided one is not valid, will use a default, safe one.
595+
*/
596+
public Pattern getDescriptionPatternClaims() {
597+
if(descriptionRegexClaims == null) {
598+
descriptionRegexClaims = computeOrDefault("description-regex.claims");
599+
}
600+
return descriptionRegexClaims;
601+
}
602+
603+
/**
604+
* Get the pattern for the description of protected-areas.
605+
* @return a non-null instance of a pattern. If the provided one is not valid, will use a default, safe one.
606+
*/
607+
public Pattern getDescriptionPatternProtected() {
608+
if(descriptionRegexProtected == null) {
609+
descriptionRegexProtected = computeOrDefault("description-regex.protected-areas");
610+
}
611+
return descriptionRegexProtected;
612+
}
613+
614+
private Pattern computeOrDefault(String key) {
615+
String regex = getSetting(key);
616+
try {
617+
return Pattern.compile(regex);
618+
} catch(PatternSyntaxException e) {
619+
instance.info(ChatColor.RED + "[ERROR] The property "+key+" (\""+regex+"\") is not valid: " + e.getMessage());
620+
return DEFAULT_DESCRIPTION_PATTERN;
621+
}
622+
}
572623
}

src/main/java/fr/xyness/SCS/Guis/AdminGestion/AdminGestionClaimsProtectedAreasGui.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private List<String> prepareLore(List<String> template, Claim claim, Player play
229229
* @return The created ItemStack.
230230
*/
231231
private ItemStack createClaimItem(Claim claim, Player player, List<String> lore) {
232-
String displayName = "§6"+claim.getName()+" §7("+claim.getDescription()+")";
232+
String displayName = "§6"+claim.getName()+" §7("+ChatColor.translateAlternateColorCodes('&', claim.getDescription())+"§7)";
233233
return createPlayerHeadItem(claim, displayName, lore);
234234
}
235235

0 commit comments

Comments
 (0)