Add the option to disable disabled-sign name protection. (#699)

This allows EssentialsX users to use other plugins that provide signs such as [Kit] and not have EssentialsX interfere with the final sign name.
This commit is contained in:
Ali Moghnieh 2016-07-01 16:23:54 +01:00 committed by Ali Moghnieh
parent 19f6510840
commit c9f1b0fdc5
No known key found for this signature in database
GPG Key ID: F09D3A1BAF2E6D70
4 changed files with 45 additions and 1 deletions

View File

@ -263,4 +263,6 @@ public interface ISettings extends IConf {
boolean isNpcsInBalanceRanking();
NumberFormat getCurrencyFormat();
List<EssentialsSign> getUnprotectedSignNames();
}

View File

@ -549,6 +549,7 @@ public class Settings implements net.ess3.api.ISettings {
commandCooldowns = _getCommandCooldowns();
npcsInBalanceRanking = _isNpcsInBalanceRanking();
currencyFormat = _getCurrencyFormat();
unprotectedSigns = _getUnprotectedSign();
}
private List<Integer> itemSpawnBl = new ArrayList<Integer>();
@ -1328,4 +1329,29 @@ public class Settings implements net.ess3.api.ISettings {
public NumberFormat getCurrencyFormat() {
return this.currencyFormat;
}
private List<EssentialsSign> unprotectedSigns = Collections.emptyList();
@Override
public List<EssentialsSign> getUnprotectedSignNames() {
return this.unprotectedSigns;
}
private List<EssentialsSign> _getUnprotectedSign() {
List<EssentialsSign> newSigns = new ArrayList<>();
for (String signName : config.getStringList("unprotected-sign-names")) {
signName = signName.trim().toUpperCase(Locale.ENGLISH);
if (signName.isEmpty()) {
continue;
}
try {
newSigns.add(Signs.valueOf(signName).getSign());
} catch (Exception ex) {
logger.log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names"));
continue;
}
}
return newSigns;
}
}

View File

@ -91,11 +91,18 @@ public class SignBlockListener implements Listener {
//We loop through all sign types here to prevent clashes with preexisting signs later
for (Signs signs : Signs.values()) {
final EssentialsSign sign = signs.getSign();
// If the top line contains any of the success name (excluding colors), just remove all colours from the first line.
// If the top sign line contains any of the success name (excluding colors), just remove all colours from the first line.
// This is to ensure we are only modifying possible Essentials Sign and not just removing colors from the first line of all signs.
// Top line and sign#getSuccessName() are both lowercased since contains is case-sensitive.
String lSuccessName = ChatColor.stripColor(sign.getSuccessName().toLowerCase());
if (lColorlessTopLine.contains(lSuccessName)) {
// If this sign is not enabled and it has been requested to not protect it's name (when disabled), then do not protect the name.
// By lower-casing it and stripping colours.
if (!ess.getSettings().enabledSigns().contains(sign)
&& ess.getSettings().getUnprotectedSignNames().contains(sign)) {
continue;
}
event.setLine(0, lColorlessTopLine);
}
}

View File

@ -325,6 +325,15 @@ enabledSigns:
# Lower numbers will reduce the possibility of lag, but may annoy players.
sign-use-per-second: 4
# List of sign names Essentials should not protect. This feature is especially useful when
# another plugin provides a sign that EssentialsX provides, but Essentials overrides.
# For example, if a plugin provides a [kit] sign, and you wish to use theirs instead of
# Essentials's, then simply add kit below and Essentials will not protect it.
#
# See https://github.com/drtshock/Essentials/pull/699 for more information.
unprotected-sign-names:
#- kit
# Backup runs a batch/bash command while saving is disabled.
backup:
# Interval in minutes.