Fix silent error when creating signs.

If the signFormatSuccess message is empty an error occurs silently that prevents the sign from being created from Essentials behalf. This commit tackles that issue by creating `getSuccessName(IEssentials)` and invoking it where possible to notify the console when this error occurs.
This commit is contained in:
Ali Moghnieh 2017-06-19 05:18:33 +01:00
parent ec3dc50e20
commit 2fe05b4ff4
No known key found for this signature in database
GPG key ID: F09D3A1BAF2E6D70
4 changed files with 28 additions and 7 deletions

View file

@ -54,7 +54,7 @@ public class EssentialsSign {
try {
final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
if (ret) {
sign.setLine(0, getSuccessName());
sign.setLine(0, getSuccessName(ess));
}
return ret;
} catch (ChargeException ex) {
@ -66,8 +66,22 @@ public class EssentialsSign {
return true;
}
public String getSuccessName(IEssentials ess) {
String successName = getSuccessName();
if (successName == null) {
ess.getLogger().severe("signFormatSuccess message must use the {0} argument.");
}
return successName;
}
public String getSuccessName() {
return tl("signFormatSuccess", this.signName);
String successName = tl("signFormatSuccess", this.signName);
if (successName.isEmpty() || !successName.contains(this.signName)) {
// Set to null to cause an error in place of no functionality. This makes an error obvious as opposed to leaving users baffled by lack of
// functionality.
successName = null;
}
return successName;
}
public String getTemplateName() {

View file

@ -1,5 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.I18n;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import net.ess3.api.IEssentials;
@ -57,7 +58,7 @@ public class SignBlockListener implements Listener {
final Sign csign = (Sign) block.getState();
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
if (csign.getLine(0).equalsIgnoreCase(sign.getSuccessName()) && !sign.onSignBreak(block, player, ess)) {
if (csign.getLine(0).equalsIgnoreCase(sign.getSuccessName(ess)) && !sign.onSignBreak(block, player, ess)) {
return true;
}
}
@ -94,7 +95,13 @@ public class SignBlockListener implements Listener {
// 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());
String successName = sign.getSuccessName(ess);
if (successName == null) {
event.getPlayer().sendMessage(I18n.tl("errorWithMessage",
"Please report this error to a staff member."));
return;
}
String lSuccessName = ChatColor.stripColor(successName.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.
@ -116,7 +123,7 @@ public class SignBlockListener implements Listener {
}
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
if (event.getLine(0).equalsIgnoreCase(sign.getSuccessName())) {
if (event.getLine(0).equalsIgnoreCase(sign.getSuccessName(ess))) {
event.setCancelled(true);
return;
}

View file

@ -56,7 +56,7 @@ public class SignPlayerListener implements Listener {
if (mat == Material.SIGN_POST || mat == Material.WALL_SIGN) {
final String csign = ((Sign) block.getState()).getLine(0);
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
if (csign.equalsIgnoreCase(sign.getSuccessName())) {
if (csign.equalsIgnoreCase(sign.getSuccessName(ess))) {
sign.onSignInteract(block, event.getPlayer(), ess);
event.setCancelled(true);
return;

View file

@ -105,7 +105,7 @@ public class SignProtection extends EssentialsSign {
private SignProtectionState checkProtectionSign(final Block block, final User user, final String username) {
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
final BlockSign sign = new BlockSign(block);
if (sign.getLine(0).equals(this.getSuccessName())) {
if (sign.getLine(0).equals(this.getSuccessName())) { // TODO call getSuccessName(IEssentials)
return checkProtectionSign(sign, user, username);
}
}