77import java .util .Map ;
88import java .util .Objects ;
99import java .util .Set ;
10+ import java .util .regex .Pattern ;
11+ import java .util .regex .PatternSyntaxException ;
1012import java .util .stream .Collectors ;
1113
14+ import fr .xyness .SCS .SimpleClaimSystem ;
15+ import net .md_5 .bungee .api .ChatColor ;
1216import org .bukkit .Location ;
1317import org .bukkit .Material ;
1418import org .bukkit .entity .EntityType ;
2024 */
2125public 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}
0 commit comments