mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-10-03 23:34:15 +00:00
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:
parent
ec3dc50e20
commit
2fe05b4ff4
|
@ -54,7 +54,7 @@ public class EssentialsSign {
|
||||||
try {
|
try {
|
||||||
final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
|
final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
sign.setLine(0, getSuccessName());
|
sign.setLine(0, getSuccessName(ess));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
} catch (ChargeException ex) {
|
} catch (ChargeException ex) {
|
||||||
|
@ -66,8 +66,22 @@ public class EssentialsSign {
|
||||||
return true;
|
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() {
|
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() {
|
public String getTemplateName() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.earth2me.essentials.signs;
|
package com.earth2me.essentials.signs;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.I18n;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.utils.FormatUtil;
|
import com.earth2me.essentials.utils.FormatUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
|
@ -57,7 +58,7 @@ public class SignBlockListener implements Listener {
|
||||||
final Sign csign = (Sign) block.getState();
|
final Sign csign = (Sign) block.getState();
|
||||||
|
|
||||||
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
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;
|
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.
|
// 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.
|
// 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.
|
// 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 (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.
|
// 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()) {
|
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
||||||
if (event.getLine(0).equalsIgnoreCase(sign.getSuccessName())) {
|
if (event.getLine(0).equalsIgnoreCase(sign.getSuccessName(ess))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class SignPlayerListener implements Listener {
|
||||||
if (mat == Material.SIGN_POST || mat == Material.WALL_SIGN) {
|
if (mat == Material.SIGN_POST || mat == Material.WALL_SIGN) {
|
||||||
final String csign = ((Sign) block.getState()).getLine(0);
|
final String csign = ((Sign) block.getState()).getLine(0);
|
||||||
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
||||||
if (csign.equalsIgnoreCase(sign.getSuccessName())) {
|
if (csign.equalsIgnoreCase(sign.getSuccessName(ess))) {
|
||||||
sign.onSignInteract(block, event.getPlayer(), ess);
|
sign.onSignInteract(block, event.getPlayer(), ess);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class SignProtection extends EssentialsSign {
|
||||||
private SignProtectionState checkProtectionSign(final Block block, final User user, final String username) {
|
private SignProtectionState checkProtectionSign(final Block block, final User user, final String username) {
|
||||||
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
|
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
|
||||||
final BlockSign sign = new BlockSign(block);
|
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);
|
return checkProtectionSign(sign, user, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue