Moves the drawing of unregistered signs to the portal sign drawer
This commit is contained in:
		@@ -4,8 +4,6 @@ import net.knarcraft.stargate.Stargate;
 | 
				
			|||||||
import net.knarcraft.stargate.container.BlockLocation;
 | 
					import net.knarcraft.stargate.container.BlockLocation;
 | 
				
			||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
 | 
					import net.knarcraft.stargate.utility.PortalFileHelper;
 | 
				
			||||||
import org.bukkit.World;
 | 
					import org.bukkit.World;
 | 
				
			||||||
import org.bukkit.block.Sign;
 | 
					 | 
				
			||||||
import org.bukkit.block.data.type.WallSign;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
@@ -220,15 +218,8 @@ public class PortalRegistry {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Clear sign data
 | 
					        //Mark the portal's sign as unregistered
 | 
				
			||||||
        if (portal.getSignLocation().getBlock().getBlockData() instanceof WallSign) {
 | 
					        new PortalSignDrawer(portal).drawUnregisteredSign();
 | 
				
			||||||
            Sign sign = (Sign) portal.getSignLocation().getBlock().getState();
 | 
					 | 
				
			||||||
            sign.setLine(0, portal.getName());
 | 
					 | 
				
			||||||
            sign.setLine(1, "");
 | 
					 | 
				
			||||||
            sign.setLine(2, "");
 | 
					 | 
				
			||||||
            sign.setLine(3, "");
 | 
					 | 
				
			||||||
            sign.update();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PortalFileHelper.saveAllPortals(portal.getWorld());
 | 
					        PortalFileHelper.saveAllPortals(portal.getWorld());
 | 
				
			||||||
        portal.setRegistered(false);
 | 
					        portal.setRegistered(false);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,16 +46,29 @@ public class PortalSignDrawer {
 | 
				
			|||||||
     * Draws the sign of the portal this sign drawer is responsible for
 | 
					     * Draws the sign of the portal this sign drawer is responsible for
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void drawSign() {
 | 
					    public void drawSign() {
 | 
				
			||||||
 | 
					        Sign sign = getSign();
 | 
				
			||||||
 | 
					        if (sign == null) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        drawSign(sign);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the sign for this sign drawer's portal
 | 
				
			||||||
 | 
					     * 
 | 
				
			||||||
 | 
					     * @return <p>The sign of this sign drawer's portal</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private Sign getSign() {
 | 
				
			||||||
        Block signBlock = portal.getSignLocation().getBlock();
 | 
					        Block signBlock = portal.getSignLocation().getBlock();
 | 
				
			||||||
        BlockState state = signBlock.getState();
 | 
					        BlockState state = signBlock.getState();
 | 
				
			||||||
        if (!(state instanceof Sign sign)) {
 | 
					        if (!(state instanceof Sign sign)) {
 | 
				
			||||||
            Stargate.logWarning("Sign block is not a Sign object");
 | 
					            Stargate.logWarning("Sign block is not a Sign object");
 | 
				
			||||||
            Stargate.debug("Portal::drawSign", String.format("Block: %s @ %s", signBlock.getType(),
 | 
					            Stargate.debug("Portal::drawSign", String.format("Block: %s @ %s", signBlock.getType(),
 | 
				
			||||||
                    signBlock.getLocation()));
 | 
					                    signBlock.getLocation()));
 | 
				
			||||||
            return;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        return sign;
 | 
				
			||||||
        drawSign(sign);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -65,9 +78,7 @@ public class PortalSignDrawer {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    private void drawSign(Sign sign) {
 | 
					    private void drawSign(Sign sign) {
 | 
				
			||||||
        //Clear sign
 | 
					        //Clear sign
 | 
				
			||||||
        for (int index = 0; index <= 3; index++) {
 | 
					        clearSign(sign);
 | 
				
			||||||
            sign.setLine(index, "");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        setLine(sign, 0, highlightColor + "-" + mainColor +
 | 
					        setLine(sign, 0, highlightColor + "-" + mainColor +
 | 
				
			||||||
                portal.getName() + highlightColor + "-");
 | 
					                portal.getName() + highlightColor + "-");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -90,6 +101,31 @@ public class PortalSignDrawer {
 | 
				
			|||||||
        sign.update();
 | 
					        sign.update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Clears all lines of a sign, but does not update the sign
 | 
				
			||||||
 | 
					     * 
 | 
				
			||||||
 | 
					     * @param sign <p>The sign to clear</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private void clearSign(Sign sign) {
 | 
				
			||||||
 | 
					        for (int index = 0; index <= 3; index++) {
 | 
				
			||||||
 | 
					            sign.setLine(index, "");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Marks this sign drawer's portal as unregistered
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public void drawUnregisteredSign() {
 | 
				
			||||||
 | 
					        Sign sign = getSign();
 | 
				
			||||||
 | 
					        if (sign == null) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        clearSign(sign);
 | 
				
			||||||
 | 
					        sign.setLine(0, portal.getName());
 | 
				
			||||||
 | 
					        sign.setLine(3, errorColor + Stargate.getString("signInvalidGate"));
 | 
				
			||||||
 | 
					        sign.update();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Draws a sign with choose-able network locations
 | 
					     * Draws a sign with choose-able network locations
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -175,7 +211,7 @@ public class PortalSignDrawer {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Draws a bungee sign
 | 
					     * Draws the sign of a BungeeCord portal
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param sign <p>The sign to re-draw</p>
 | 
					     * @param sign <p>The sign to re-draw</p>
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@@ -186,7 +222,9 @@ public class PortalSignDrawer {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Draws an inactive sign
 | 
					     * Draws the sign of an in-active portal
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * <p>The sign for an in-active portal should display the right-click prompt and the network.</p>
 | 
				
			||||||
     * 
 | 
					     * 
 | 
				
			||||||
     * @param sign <p>The sign to re-draw</p>
 | 
					     * @param sign <p>The sign to re-draw</p>
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user