Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "fr.xyness"
version = "1.11.6.1"
version = "1.11.7.0"

java {
toolchain {
Expand Down
2 changes: 1 addition & 1 deletion langs/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ world-list-changeda-via-command: "§fWorld §e%name%§f removed from §edisabled
cant-add-member-anymore: "§cYou have reached the maximum number of members per claim."
you-cannot-use-this-name: "§cYou cannot use 'claim-' in your new claim name."
incorrect-characters-name: "§cYou must use a name with only letters and numbers."
incorrect-characters-description: "§cYou must use a description with only letters and numbers."
incorrect-characters-description: "§cThe provided description contains illegal characters."
claim-not-an-admin-claim: "§cThis claim is not a protected area."
not-using-database: "§cThe database is disabled in config.yml."
member-limit-must-be-positive: "§cThe member limit must be positive."
Expand Down
2 changes: 1 addition & 1 deletion langs/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ world-list-changeda-via-command: "§fMonde §e%name%§f retiré des §emondes d
cant-add-member-anymore: "§cVous avez atteint le nombre maximum de membres par claim."
you-cannot-use-this-name: "§cVous ne pouvez pas utiliser 'claim-' dans votre nouveau nom de claim."
incorrect-characters-name: "§cVous devez utiliser un nom avec seulement des lettres et des chiffres."
incorrect-characters-description: "§cVous devez utiliser une description avec seulement des lettres et des chiffres."
incorrect-characters-description: "§cLa description fournie contient des caractères illégaux."
claim-not-an-admin-claim: "§cCe claim n'est pas une zone protégée."
not-using-database: "§cLa base de données est désactivée dans config.yml."
member-limit-must-be-positive: "§cLa limite de membres doit être positive."
Expand Down
2 changes: 1 addition & 1 deletion langs/pt_BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ world-list-changeda-via-command: "§fMundo §e%name%§f removido dos §emundos d
cant-add-member-anymore: "§cVocê atingiu o número máximo de membros por claim."
you-cannot-use-this-name: "§cVocê não pode usar 'claim-' no seu novo nome de claim."
incorrect-characters-name: "§cVocê deve usar um nome com apenas letras e números."
incorrect-characters-description: "§cVocê deve usar uma descrição com apenas letras e números."
incorrect-characters-description: "§cA descrição fornecida contém caracteres ilegais."
claim-not-an-admin-claim: "§cEste claim não é uma área protegida."
not-using-database: "§cO banco de dados está desativado no config.yml."
member-limit-must-be-positive: "§cO limite de membros deve ser positivo."
Expand Down
3 changes: 1 addition & 2 deletions langs/vi_VN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ cant-add-member-anymore: §cBạn đã đạt được số lượng thành viê
you-cannot-use-this-name: §cBạn không thể chiếm đóng mới trong khi khu vực đang chiếm
đóng.
incorrect-characters-name: §cBạn phải sử dụng tên chỉ với các chữ cái và số.
incorrect-characters-description: §cBạn phải sử dụng một mô tả chỉ với các chữ cái
và số.
incorrect-characters-description: §cMô tả được cung cấp có chứa ký tự không hợp lệ.
claim-not-an-admin-claim: §cKhu vực này không phải là một khu vực được bảo vệ.
not-using-database: §cCơ sở dữ liệu bị vô hiệu hóa config.yml.
member-limit-must-be-positive: §cGiới hạn thành viên phải tích cực.
Expand Down
2 changes: 1 addition & 1 deletion langs/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ world-list-changeda-via-command: "§f世界 §e%name%§f 已从§e 禁用世界
cant-add-member-anymore: "§c您已达到每个领地的最大成员数量。"
you-cannot-use-this-name: "§c您不能在新的领地名称中使用 'claim-'。"
incorrect-characters-name: "§c您必须使用仅包含字母和数字的名称。"
incorrect-characters-description: "§c您必须使用仅包含字母和数字的描述。"
incorrect-characters-description: "§c提供的描述包含非法字符。"
claim-not-an-admin-claim: "§c此领地不是受保护区域。"
not-using-database: "§c在 config.yml 中禁用了数据库。"
member-limit-must-be-positive: "§c成员限制必须为正数。"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/xyness/SCS/Commands/ClaimCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void handleDesc(Player player, String playerName, String[] args) {
player.sendMessage(instance.getLanguage().getMessage("claim-description-too-long"));
return;
}
if (!description.matches("^[a-zA-Z0-9\\s]+$")) {
if (!instance.getSettings().getDescriptionPatternClaims().matcher(description).find()) {
player.sendMessage(instance.getLanguage().getMessage("incorrect-characters-description"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ private void handleDesc(Player player, String[] args) {
player.sendMessage(instance.getLanguage().getMessage("claim-description-too-long"));
return;
}
if (!description.matches("^[a-zA-Z0-9]+$")) {
player.sendMessage(instance.getLanguage().getMessage("incorrect-characters-description"));
return;
if (!instance.getSettings().getDescriptionPatternProtected().matcher(description).find()) {
player.sendMessage(instance.getLanguage().getMessage("incorrect-characters-description"));
return;
}
Claim claim = instance.getMain().getProtectedAreaByName(args[1]);
instance.getMain().setClaimDescription(claim, description)
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/fr/xyness/SCS/Config/ClaimSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;

import fr.xyness.SCS.SimpleClaimSystem;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
Expand All @@ -20,6 +24,10 @@
*/
public class ClaimSettings {

private final SimpleClaimSystem instance;
public ClaimSettings(SimpleClaimSystem instance) {
this.instance = instance;
}

// ***************
// * Variables *
Expand Down Expand Up @@ -83,6 +91,15 @@ public class ClaimSettings {
/** Location of the expulsion */
private Location expulsionLocation;

/** Regex for the description of player claims. */
private Pattern descriptionRegexClaims;

/** Same, but for the protected areas. */
private Pattern descriptionRegexProtected;

/** Default description pattern. Used if the user regex is not valid. */
private static final Pattern DEFAULT_DESCRIPTION_PATTERN = Pattern.compile("^[a-zA-Z0-9\\s]+$");


// ********************
// * Others Methods *
Expand All @@ -106,6 +123,8 @@ public void clearAll() {
groupsSettings.clear();
worlds.clear();
aliases.clear();
descriptionRegexClaims = null;
descriptionRegexProtected = null;
worldsAliases.clear();
}

Expand Down Expand Up @@ -569,4 +588,36 @@ public void setPlaceBlocksIgnore(List<String> mat) {
public Map<String, Boolean> getStatusSettings() {
return enabledSettings;
}

/**
* Get the pattern for the description of claims.
* @return a non-null instance of a pattern. If the provided one is not valid, will use a default, safe one.
*/
public Pattern getDescriptionPatternClaims() {
if(descriptionRegexClaims == null) {
descriptionRegexClaims = computeOrDefault("description-regex.claims");
}
return descriptionRegexClaims;
}

/**
* Get the pattern for the description of protected-areas.
* @return a non-null instance of a pattern. If the provided one is not valid, will use a default, safe one.
*/
public Pattern getDescriptionPatternProtected() {
if(descriptionRegexProtected == null) {
descriptionRegexProtected = computeOrDefault("description-regex.protected-areas");
}
return descriptionRegexProtected;
}

private Pattern computeOrDefault(String key) {
String regex = getSetting(key);
try {
return Pattern.compile(regex);
} catch(PatternSyntaxException e) {
instance.info(ChatColor.RED + "[ERROR] The property "+key+" (\""+regex+"\") is not valid: " + e.getMessage());
return DEFAULT_DESCRIPTION_PATTERN;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private List<String> prepareLore(List<String> template, Claim claim, Player play
* @return The created ItemStack.
*/
private ItemStack createClaimItem(Claim claim, Player player, List<String> lore) {
String displayName = "§6"+claim.getName()+" §7("+claim.getDescription()+")";
String displayName = "§6"+claim.getName()+" §7("+ChatColor.translateAlternateColorCodes('&', claim.getDescription())+"§7)";
return createPlayerHeadItem(claim, displayName, lore);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fr/xyness/SCS/Guis/ClaimListGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.CompletableFuture;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -274,7 +275,7 @@ public List<String> processLore(List<String> lore, Claim claim) {

for (String s : lore) {
s = s.replace("%owner%", owner)
.replace("%description%", description)
.replace("%description%", ChatColor.translateAlternateColorCodes('&', description))
.replace("%name%", name)
.replace("%coords%", coords);

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/fr/xyness/SCS/Guis/ClaimMainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.CompletableFuture;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -109,15 +110,15 @@ public CompletableFuture<Boolean> loadItems(Claim claim) {
String title = slot.getTitle();
String lore_string = slot.getLore();
if(key.equals("Info")) {
title = title.replace("%description%", claim.getDescription())
title = title.replace("%description%", ChatColor.translateAlternateColorCodes('&', claim.getDescription()))
.replace("%claim-name%", claim.getName())
.replace("%sale-status%", claim.getSale() ? (instance.getLanguage().getMessage("claim-info-lore-sale-status-true")
.replace("%price%", instance.getMain().getNumberSeparate(String.valueOf(claim.getPrice())))
.replace("%money-symbol%", instance.getLanguage().getMessage("money-symbol"))) : instance.getLanguage().getMessage("claim-info-lore-sale-status-false"))
.replace("%chunks-count%", instance.getMain().getNumberSeparate(String.valueOf(claim.getChunks().size())))
.replace("%members-count%", instance.getMain().getNumberSeparate(String.valueOf(claim.getMembers().size())))
.replace("%bans-count%", instance.getMain().getNumberSeparate(String.valueOf(claim.getBans().size())));
lore_string = lore_string.replace("%description%", claim.getDescription())
lore_string = lore_string.replace("%description%", ChatColor.translateAlternateColorCodes('&', claim.getDescription()))
.replace("%claim-name%", claim.getName())
.replace("%sale-status%", claim.getSale() ? (instance.getLanguage().getMessage("claim-info-lore-sale-status-true")
.replace("%price%", instance.getMain().getNumberSeparate(String.valueOf(claim.getPrice())))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/xyness/SCS/Guis/ClaimsOwnerGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private Set<Claim> getClaims(String filter, String owner) {
private List<String> prepareLore(List<String> template, Claim claim, Player player) {
List<String> lore = new ArrayList<>();
for (String line : template) {
line = line.replace("%description%", claim.getDescription())
line = line.replace("%description%", ChatColor.translateAlternateColorCodes('&', claim.getDescription()))
.replace("%name%", claim.getName())
.replace("%coords%", instance.getMain().getClaimCoords(claim));
if (line.contains("%members%")) {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/fr/xyness/SCS/SimpleClaimSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public boolean loadConfig(boolean reload, CommandSender sender) {
} else {
claimInstance = new ClaimMain(this);
claimGuisInstance = new ClaimGuis(this);
claimSettingsInstance = new ClaimSettings();
claimSettingsInstance = new ClaimSettings(this);
cPlayerMainInstance = new CPlayerMain(this);
claimLanguageInstance = new ClaimLanguage(this);
claimBossBarInstance = new ClaimBossBar(this);
Expand Down Expand Up @@ -719,6 +719,10 @@ public boolean loadConfig(boolean reload, CommandSender sender) {

// Check if claims where Visitors is false are displayed in the /claims GUI
claimSettingsInstance.addSetting("claims-visitors-off-visible", getConfig().getString("claims-visitors-off-visible"));

// Description regex
claimSettingsInstance.addSetting("description-regex.claims", getConfig().getString("description-regex.claims"));
claimSettingsInstance.addSetting("description-regex.protected-areas", getConfig().getString("description-regex.protected-areas"));

// Check claim fly disabled or not for Folia
if(isFolia) {
Expand Down Expand Up @@ -1668,8 +1672,8 @@ public void executeAsyncLater(Runnable gTask, long delayMillis) {
if (isFolia) {
Bukkit.getAsyncScheduler().runDelayed(this, task -> gTask.run(), delayMillis, TimeUnit.MILLISECONDS);
} else {
long delayTicks = Math.max(1, (delayMillis * 20) / 1000);
Bukkit.getScheduler().runTaskLaterAsynchronously(this, gTask, delayTicks);
long delayTicks = Math.max(1, (delayMillis * 20) / 1000);
Bukkit.getScheduler().runTaskLaterAsynchronously(this, gTask, delayTicks);
}
}

Expand All @@ -1680,7 +1684,7 @@ public void executeAsyncLater(Runnable gTask, long delayMillis) {
* @param delayMillis The delay.
*/
public void executeSyncLater(Runnable gTask, long delayMillis) {
long delayTicks = Math.max(1, (delayMillis * 20) / 1000);
long delayTicks = Math.max(1, (delayMillis * 20) / 1000);
if (isFolia) {
Bukkit.getGlobalRegionScheduler().runDelayed(this, task -> gTask.run(), delayTicks);
} else {
Expand Down Expand Up @@ -1759,7 +1763,7 @@ public void checkPaper() {

/**
* Reloads the language file.
*
*
* @param plugin The plugin instance
* @param sender The command sender
* @param lang The language file to reload
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ bossbar-settings:
color: YELLOW
style: SOLID

# A regular expression to control the allowed description of a claim.
# The default value for the player-claims is '^[a-zA-Z0-9\s]+$' and only allows for alphanumerical strings, with spaces.
# The default value for the protected areas is the same, but will also include the color symbols.
description-regex:
claims: '^[a-zA-Z0-9\s]+$'
protected-areas: '^[a-zA-Z0-9&#\s]+$'

# If delay > 0, can the player move
# true = can move, false = cannot move
teleportation-delay-moving: false
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/langs/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ world-list-changeda-via-command: "§fWorld §e%name%§f removed from §edisabled
cant-add-member-anymore: "§cYou have reached the maximum number of members per claim."
you-cannot-use-this-name: "§cYou cannot use 'claim-' in your new claim name."
incorrect-characters-name: "§cYou must use a name with only letters and numbers."
incorrect-characters-description: "§cYou must use a description with only letters and numbers."
incorrect-characters-description: "§cThe provided description contains illegal characters."
claim-not-an-admin-claim: "§cThis claim is not a protected area."
not-using-database: "§cThe database is disabled in config.yml."
member-limit-must-be-positive: "§cThe member limit must be positive."
Expand Down