Moves the rest of the sign drawing code from Portal to SignHelper

This commit is contained in:
Kristian Knarvik 2021-10-18 19:12:30 +02:00
parent 82ed28bba0
commit 1d4b988ca4
4 changed files with 35 additions and 31 deletions

View File

@ -8,6 +8,7 @@ import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.EconomyHelper;
import net.knarcraft.stargate.utility.MaterialHelper;
import net.knarcraft.stargate.utility.PermissionHelper;
import net.knarcraft.stargate.utility.SignHelper;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.WallSign;
@ -81,7 +82,7 @@ public class BlockEventListener implements Listener {
Stargate.sendSuccessMessage(player, Stargate.getString("createMsg"));
Stargate.debug("onSignChange", "Initialized stargate: " + portal.getName());
Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, portal::drawSign, 1);
Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, () -> SignHelper.drawSign(portal), 1);
}
/**

View File

@ -8,12 +8,9 @@ import net.knarcraft.stargate.event.StargateActivateEvent;
import net.knarcraft.stargate.event.StargateCloseEvent;
import net.knarcraft.stargate.event.StargateDeactivateEvent;
import net.knarcraft.stargate.event.StargateOpenEvent;
import net.knarcraft.stargate.utility.SignHelper;
import org.bukkit.Axis;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.block.data.Orientable;
import org.bukkit.entity.Player;
@ -24,6 +21,8 @@ import java.util.Map;
import java.util.Random;
import java.util.UUID;
import static net.knarcraft.stargate.utility.SignHelper.drawSign;
/**
* This class represents a portal in space which points to one or several portals
*/
@ -154,7 +153,7 @@ public class Portal {
@SuppressWarnings("unused")
public void setName(String name) {
this.name = filterName(name);
drawSign();
drawSign(this);
}
/**
@ -374,13 +373,13 @@ public class Portal {
player = openFor;
Portal destination = getDestination();
// Only open destination if it's not-fixed or points at this portal
//Only open destination if it's not-fixed or points at this portal
if (!options.isRandom() && destination != null && (!destination.options.isFixed() ||
destination.getDestinationName().equalsIgnoreCase(getName())) && !destination.isOpen()) {
destination.open(openFor, false);
destination.setDestination(this);
if (destination.isVerified()) {
destination.drawSign();
drawSign(destination);
}
}
}
@ -551,7 +550,7 @@ public class Portal {
}
destination = event.getDestination();
destinations = event.getDestinations();
drawSign();
drawSign(this);
return true;
}
@ -572,7 +571,7 @@ public class Portal {
destinations.clear();
destination = "";
activePlayer = null;
drawSign();
drawSign(this);
}
/**
@ -624,7 +623,7 @@ public class Portal {
cycleDestination(direction);
}
openTime = System.currentTimeMillis() / 1000;
drawSign();
drawSign(this);
}
/**
@ -636,7 +635,7 @@ public class Portal {
int index = destinations.indexOf(destination);
index += direction;
//Wrap around
//Wrap around if the last destination has been reached
if (index >= destinations.size()) {
index = 0;
} else if (index < 0) {
@ -647,21 +646,6 @@ public class Portal {
lastDestination = destination;
}
/**
* Draws this portal's sign
*/
public final void drawSign() {
BlockState state = getSignLocation().getBlock().getState();
if (!(state instanceof Sign sign)) {
Stargate.logger.warning(Stargate.getString("prefix") + "Sign block is not a Sign object");
Stargate.debug("Portal::drawSign", "Block: " + getSignLocation().getBlock().getType() + " @ "
+ getSignLocation().getBlock().getLocation());
return;
}
SignHelper.drawSign(sign, this);
}
/**
* Gets the block at the given location relative to this portal's location
*

View File

@ -9,6 +9,7 @@ import net.knarcraft.stargate.utility.DirectionHelper;
import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.EconomyHelper;
import net.knarcraft.stargate.utility.PermissionHelper;
import net.knarcraft.stargate.utility.SignHelper;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@ -163,7 +164,7 @@ public class PortalHandler {
}
//Update the portal's sign
if (origin.getOptions().isFixed()) {
origin.drawSign();
SignHelper.drawSign(origin);
}
//Close portal without destination
if (origin.getOptions().isAlwaysOn()) {
@ -584,7 +585,7 @@ public class PortalHandler {
* @param destinationName <p>The name of the destination portal</p>
*/
private static void updateNewPortal(Portal portal, String destinationName) {
portal.drawSign();
SignHelper.drawSign(portal);
//Open an always on portal
if (portal.getOptions().isRandom() || portal.getOptions().isBungee()) {
portal.open(true);
@ -592,7 +593,7 @@ public class PortalHandler {
Portal destinationPortal = getByName(destinationName, portal.getNetwork());
if (destinationPortal != null) {
portal.open(true);
destinationPortal.drawSign();
SignHelper.drawSign(destinationPortal);
}
} else {
//Update the block type for the portal's opening to the closed block
@ -617,7 +618,7 @@ public class PortalHandler {
}
//Update sign of fixed gates pointing at this gate
if (origin.getOptions().isFixed()) {
origin.drawSign();
SignHelper.drawSign(origin);
}
//Open any always on portal pointing at this portal
if (origin.getOptions().isAlwaysOn()) {
@ -940,7 +941,7 @@ public class PortalHandler {
//Re-draw the signs in case a bug in the config prevented the portal from loading and has been fixed since
for (Portal portal : allPortals) {
portal.drawSign();
SignHelper.drawSign(portal);
}
return true;
} catch (Exception e) {

View File

@ -4,6 +4,8 @@ import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.portal.PortalHandler;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
/**
@ -11,6 +13,22 @@ import org.bukkit.block.Sign;
*/
public final class SignHelper {
/**
* Draws this portal's sign
*/
public static void drawSign(Portal portal) {
Block signBlock = portal.getSignLocation().getBlock();
BlockState state = signBlock.getState();
if (!(state instanceof Sign sign)) {
Stargate.logger.warning(Stargate.getString("prefix") + "Sign block is not a Sign object");
Stargate.debug("Portal::drawSign", "Block: " + signBlock.getType() + " @ " +
signBlock.getLocation());
return;
}
SignHelper.drawSign(sign, portal);
}
/**
* Draws the sign on this portal
*/