Changes some sign coloring and adds some missing info to the readme

Makes the Disconnected message red
Makes the highlighting characters (><) white when cycling stargate destinations
Moves markPortalWithInvalidGate to PortalSignDrawer
Adds missing translation strings for reloaded and signInvalidGate to the readme
Moves some extra spacing around the >< characters
This commit is contained in:
2021-10-29 16:05:23 +02:00
parent f52ba79ae9
commit 5d84e1d78a
3 changed files with 37 additions and 25 deletions

View File

@ -13,6 +13,9 @@ import org.bukkit.block.Sign;
public class PortalSignDrawer {
private final Portal portal;
private final static ChatColor highlightColor = ChatColor.WHITE;
private final static ChatColor errorColor = ChatColor.DARK_RED;
private final static ChatColor freeColor = ChatColor.DARK_GREEN;
/**
* Instantiates a new portal sign drawer
@ -49,8 +52,8 @@ public class PortalSignDrawer {
for (int index = 0; index <= 3; index++) {
sign.setLine(index, "");
}
setLine(sign, 0, ChatColor.WHITE + "-" + Stargate.getGateConfig().getSignColor() +
portal.getName() + ChatColor.WHITE + "-");
setLine(sign, 0, highlightColor + "-" + Stargate.getGateConfig().getSignColor() +
portal.getName() + highlightColor + "-");
if (!portal.getPortalActivator().isActive()) {
//Default sign text
@ -115,11 +118,11 @@ public class PortalSignDrawer {
if (freeGatesGreen) {
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
setLine(sign, signLineIndex, (green ? ChatColor.DARK_GREEN : "") + ">" +
portal.getDestinationName() + (green ? ChatColor.DARK_GREEN : "") + "<");
setLine(sign, signLineIndex, (green ? freeColor : "") + ">" +
portal.getDestinationName() + (green ? freeColor : "") + "<");
} else {
setLine(sign, signLineIndex, Stargate.getGateConfig().getSignColor() + " >" +
portal.getDestinationName() + Stargate.getGateConfig().getSignColor() + "< ");
setLine(sign, signLineIndex, highlightColor + ">" + Stargate.getGateConfig().getSignColor() +
portal.getDestinationName() + highlightColor + "<");
}
}
@ -148,7 +151,7 @@ public class PortalSignDrawer {
Portal destination = PortalHandler.getByName(destinations.getDestinations().get(destinationIndex),
portal.getNetwork());
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
setLine(sign, signLineIndex, (green ? ChatColor.DARK_GREEN : "") +
setLine(sign, signLineIndex, (green ? freeColor : "") +
destinations.getDestinations().get(destinationIndex));
} else {
setLine(sign, signLineIndex, destinations.getDestinations().get(destinationIndex));
@ -199,10 +202,25 @@ public class PortalSignDrawer {
}
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
if (destination == null && !portal.getOptions().isRandom()) {
setLine(sign, 3, Stargate.getString("signDisconnected"));
setLine(sign, 3, errorColor + Stargate.getString("signDisconnected"));
} else {
setLine(sign, 3, "");
}
}
/**
* Marks a portal with an invalid gate by changing its sign and writing to the console
*
* @param portalLocation <p>The location of the portal with an invalid gate</p>
* @param gateName <p>The name of the invalid gate type</p>
* @param lineIndex <p>The index of the line the invalid portal was found at</p>
*/
public static void markPortalWithInvalidGate(PortalLocation portalLocation, String gateName, int lineIndex) {
Sign sign = (Sign) portalLocation.getSignLocation().getBlock().getState();
sign.setLine(3, errorColor + Stargate.getString("signInvalidGate"));
sign.update();
Stargate.logInfo(String.format("Gate layout on line %d does not exist [%s]", lineIndex, gateName));
}
}

View File

@ -10,9 +10,7 @@ import net.knarcraft.stargate.portal.PortalLocation;
import net.knarcraft.stargate.portal.PortalOptions;
import net.knarcraft.stargate.portal.PortalOwner;
import net.knarcraft.stargate.portal.PortalRegistry;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.block.Sign;
import java.io.BufferedWriter;
import java.io.File;
@ -20,6 +18,8 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import static net.knarcraft.stargate.portal.PortalSignDrawer.markPortalWithInvalidGate;
/**
* Helper class for saving and loading portal save files
*/
@ -257,19 +257,4 @@ public final class PortalFileHelper {
portal.getPortalOpener().closePortal(true);
}
/**
* Marks a portal with an invalid gate by changing its sign and writing to the console
*
* @param portalLocation <p>The location of the portal with an invalid gate</p>
* @param gateName <p>The name of the invalid gate type</p>
* @param lineIndex <p>The index of the line the invalid portal was found at</p>
*/
private static void markPortalWithInvalidGate(PortalLocation portalLocation, String gateName, int lineIndex) {
Sign sign = (Sign) portalLocation.getSignLocation().getBlock().getState();
sign.setLine(3, ChatColor.DARK_RED + Stargate.getString("signInvalidGate"));
sign.update();
Stargate.logInfo(String.format("Gate layout on line %d does not exist [%s]", lineIndex, gateName));
}
}