Fixed missing prefix on status messages for accelerator, mining laser & laser tree farm

This commit is contained in:
LemADEC 2017-05-06 16:04:11 +02:00
parent 7eed9dcce5
commit 4e292c214b
5 changed files with 36 additions and 20 deletions

View file

@ -42,12 +42,17 @@ public class Commons {
.replaceAll("\u00A0", " "); // u00A0 is 'NO-BREAK SPACE'
}
public static String removeFormatting(final String message) {
return updateEscapeCodes(message)
.replaceAll("(" + CHAR_FORMATTING + ".)", "");
}
public static void addChatMessage(final ICommandSender sender, final String message) {
if (sender == null) {
WarpDrive.logger.error("Unable to send message to NULL sender: " + message);
return;
}
String[] lines = updateEscapeCodes(message).split("\n");
final String[] lines = updateEscapeCodes(message).split("\n");
for (String line : lines) {
sender.addChatMessage(new ChatComponentText(line));
}
@ -60,7 +65,7 @@ public class Commons {
public static void addTooltip(List<String> list, String tooltip) {
tooltip = updateEscapeCodes(tooltip);
String[] split = tooltip.split("\n");
final String[] split = tooltip.split("\n");
for (String line : split) {
String lineRemaining = line;
String formatNextLine = "";
@ -69,7 +74,7 @@ public class Commons {
int displayLength = 0;
int length = lineRemaining.length();
while (indexToCut < length && displayLength <= 38) {
if (lineRemaining.charAt(indexToCut) == (char)167 && indexToCut + 1 < length) {
if (lineRemaining.charAt(indexToCut) == (char) 167 && indexToCut + 1 < length) {
indexToCut++;
} else {
displayLength++;
@ -87,9 +92,9 @@ public class Commons {
// compute remaining format
int index = formatNextLine.length();
while (index <= indexToCut) {
if (lineRemaining.charAt(index) == (char)167 && index + 1 < indexToCut) {
if (lineRemaining.charAt(index) == (char) 167 && index + 1 < indexToCut) {
index++;
formatNextLine += ("" + (char)167) + lineRemaining.charAt(index);
formatNextLine += CHAR_FORMATTING + lineRemaining.charAt(index);
}
index++;
}

View file

@ -54,7 +54,7 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
@Override
public void markDirty() {
super.markDirty();
if (worldObj != null) {
if (hasWorldObj()) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@ -223,7 +223,7 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
}
}
public String getStatus() {
protected String getStatusPrefix() {
if (worldObj == null) {
return "";
} else {
@ -232,6 +232,19 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
}
}
public String getStatusHeader() {
return "";
}
public String getStatus() {
return getStatusPrefix()
+ getStatusHeader();
}
public String getStatusHeaderInPureText() {
return Commons.removeFormatting( getStatusHeader() );
}
// upgrade system
private final HashMap<Object, Integer> installedUpgrades = new HashMap<>(10);
private final HashMap<Object, Integer> maxUpgrades = new HashMap<>(10);

View file

@ -174,7 +174,7 @@ public class TileEntityAcceleratorControlPoint extends TileEntityAbstractInterfa
}
private Object[] state() { // isConnected, isPowered, shape
String status = getStatus();
final String status = getStatusHeaderInPureText();
return new Object[] { status, isEnabled, controlChannel };
}

View file

@ -624,9 +624,9 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
}
private Object[] state() {
int energy = getEnergyStored();
String status = getStatus();
Integer retValuables, retValuablesIndex;
final int energy = getEnergyStored();
final String status = getStatusHeaderInPureText();
final Integer retValuables, retValuablesIndex;
if (isFarming() && valuables != null) {
retValuables = valuables.size();
retValuablesIndex = valuableIndex;
@ -724,9 +724,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
}
@Override
public String getStatus() {
// @TODO merge with base
int energy = getEnergyStored();
public String getStatusHeader() {
final int energy = getEnergyStored();
String state = "IDLE (not farming)";
if (currentState == STATE_IDLE) {
state = "IDLE (not farming)";

View file

@ -430,9 +430,9 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
}
private Object[] state() {
int energy = getEnergyStored();
String status = getStatus();
Integer retValuablesInLayer, retValuablesMined;
final int energy = getEnergyStored();
final String status = getStatusHeaderInPureText();
final Integer retValuablesInLayer, retValuablesMined;
if (isActive()) {
retValuablesInLayer = valuablesInLayer.size();
retValuablesMined = valuableIndex;
@ -518,9 +518,8 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
}
@Override
public String getStatus() {
// @TODO merge with base
int energy = getEnergyStored();
public String getStatusHeader() {
final int energy = getEnergyStored();
String state = "IDLE (not mining)";
if (currentState == STATE_IDLE) {
state = "IDLE (not mining)";