Moves the rest of the sign drawing code from Portal to SignHelper
This commit is contained in:
parent
82ed28bba0
commit
1d4b988ca4
@ -8,6 +8,7 @@ import net.knarcraft.stargate.utility.EconomyHandler;
|
|||||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
|
import net.knarcraft.stargate.utility.SignHelper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.type.WallSign;
|
import org.bukkit.block.data.type.WallSign;
|
||||||
@ -81,7 +82,7 @@ public class BlockEventListener implements Listener {
|
|||||||
|
|
||||||
Stargate.sendSuccessMessage(player, Stargate.getString("createMsg"));
|
Stargate.sendSuccessMessage(player, Stargate.getString("createMsg"));
|
||||||
Stargate.debug("onSignChange", "Initialized stargate: " + portal.getName());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,12 +8,9 @@ import net.knarcraft.stargate.event.StargateActivateEvent;
|
|||||||
import net.knarcraft.stargate.event.StargateCloseEvent;
|
import net.knarcraft.stargate.event.StargateCloseEvent;
|
||||||
import net.knarcraft.stargate.event.StargateDeactivateEvent;
|
import net.knarcraft.stargate.event.StargateDeactivateEvent;
|
||||||
import net.knarcraft.stargate.event.StargateOpenEvent;
|
import net.knarcraft.stargate.event.StargateOpenEvent;
|
||||||
import net.knarcraft.stargate.utility.SignHelper;
|
|
||||||
import org.bukkit.Axis;
|
import org.bukkit.Axis;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
import org.bukkit.block.data.Orientable;
|
import org.bukkit.block.data.Orientable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -24,6 +21,8 @@ import java.util.Map;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
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
|
* This class represents a portal in space which points to one or several portals
|
||||||
*/
|
*/
|
||||||
@ -154,7 +153,7 @@ public class Portal {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = filterName(name);
|
this.name = filterName(name);
|
||||||
drawSign();
|
drawSign(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -380,7 +379,7 @@ public class Portal {
|
|||||||
destination.open(openFor, false);
|
destination.open(openFor, false);
|
||||||
destination.setDestination(this);
|
destination.setDestination(this);
|
||||||
if (destination.isVerified()) {
|
if (destination.isVerified()) {
|
||||||
destination.drawSign();
|
drawSign(destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -551,7 +550,7 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
destination = event.getDestination();
|
destination = event.getDestination();
|
||||||
destinations = event.getDestinations();
|
destinations = event.getDestinations();
|
||||||
drawSign();
|
drawSign(this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +571,7 @@ public class Portal {
|
|||||||
destinations.clear();
|
destinations.clear();
|
||||||
destination = "";
|
destination = "";
|
||||||
activePlayer = null;
|
activePlayer = null;
|
||||||
drawSign();
|
drawSign(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -624,7 +623,7 @@ public class Portal {
|
|||||||
cycleDestination(direction);
|
cycleDestination(direction);
|
||||||
}
|
}
|
||||||
openTime = System.currentTimeMillis() / 1000;
|
openTime = System.currentTimeMillis() / 1000;
|
||||||
drawSign();
|
drawSign(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -636,7 +635,7 @@ public class Portal {
|
|||||||
int index = destinations.indexOf(destination);
|
int index = destinations.indexOf(destination);
|
||||||
index += direction;
|
index += direction;
|
||||||
|
|
||||||
//Wrap around
|
//Wrap around if the last destination has been reached
|
||||||
if (index >= destinations.size()) {
|
if (index >= destinations.size()) {
|
||||||
index = 0;
|
index = 0;
|
||||||
} else if (index < 0) {
|
} else if (index < 0) {
|
||||||
@ -647,21 +646,6 @@ public class Portal {
|
|||||||
lastDestination = destination;
|
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
|
* Gets the block at the given location relative to this portal's location
|
||||||
*
|
*
|
||||||
|
@ -9,6 +9,7 @@ import net.knarcraft.stargate.utility.DirectionHelper;
|
|||||||
import net.knarcraft.stargate.utility.EconomyHandler;
|
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
|
import net.knarcraft.stargate.utility.SignHelper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -163,7 +164,7 @@ public class PortalHandler {
|
|||||||
}
|
}
|
||||||
//Update the portal's sign
|
//Update the portal's sign
|
||||||
if (origin.getOptions().isFixed()) {
|
if (origin.getOptions().isFixed()) {
|
||||||
origin.drawSign();
|
SignHelper.drawSign(origin);
|
||||||
}
|
}
|
||||||
//Close portal without destination
|
//Close portal without destination
|
||||||
if (origin.getOptions().isAlwaysOn()) {
|
if (origin.getOptions().isAlwaysOn()) {
|
||||||
@ -584,7 +585,7 @@ public class PortalHandler {
|
|||||||
* @param destinationName <p>The name of the destination portal</p>
|
* @param destinationName <p>The name of the destination portal</p>
|
||||||
*/
|
*/
|
||||||
private static void updateNewPortal(Portal portal, String destinationName) {
|
private static void updateNewPortal(Portal portal, String destinationName) {
|
||||||
portal.drawSign();
|
SignHelper.drawSign(portal);
|
||||||
//Open an always on portal
|
//Open an always on portal
|
||||||
if (portal.getOptions().isRandom() || portal.getOptions().isBungee()) {
|
if (portal.getOptions().isRandom() || portal.getOptions().isBungee()) {
|
||||||
portal.open(true);
|
portal.open(true);
|
||||||
@ -592,7 +593,7 @@ public class PortalHandler {
|
|||||||
Portal destinationPortal = getByName(destinationName, portal.getNetwork());
|
Portal destinationPortal = getByName(destinationName, portal.getNetwork());
|
||||||
if (destinationPortal != null) {
|
if (destinationPortal != null) {
|
||||||
portal.open(true);
|
portal.open(true);
|
||||||
destinationPortal.drawSign();
|
SignHelper.drawSign(destinationPortal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Update the block type for the portal's opening to the closed block
|
//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
|
//Update sign of fixed gates pointing at this gate
|
||||||
if (origin.getOptions().isFixed()) {
|
if (origin.getOptions().isFixed()) {
|
||||||
origin.drawSign();
|
SignHelper.drawSign(origin);
|
||||||
}
|
}
|
||||||
//Open any always on portal pointing at this portal
|
//Open any always on portal pointing at this portal
|
||||||
if (origin.getOptions().isAlwaysOn()) {
|
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
|
//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) {
|
for (Portal portal : allPortals) {
|
||||||
portal.drawSign();
|
SignHelper.drawSign(portal);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -4,6 +4,8 @@ import net.knarcraft.stargate.Stargate;
|
|||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,6 +13,22 @@ import org.bukkit.block.Sign;
|
|||||||
*/
|
*/
|
||||||
public final class SignHelper {
|
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
|
* Draws the sign on this portal
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user