From e7fc1daafe4e163053f06f1a485128c47d4e51de Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 8 Oct 2021 01:26:12 +0200 Subject: [PATCH] Moves functionality to the PortalOptions and PortalLocation classes --- .../listener/PlayerEventListener.java | 4 +- .../listener/VehicleEventListener.java | 4 +- .../net/knarcraft/stargate/portal/Portal.java | 234 +++++------------- .../stargate/portal/PortalHandler.java | 65 ++--- .../stargate/portal/PortalLocation.java | 27 ++ .../stargate/thread/StarGateThread.java | 2 +- .../stargate/utility/EconomyHandler.java | 4 +- .../stargate/utility/PermissionHelper.java | 18 +- .../stargate/utility/SignHelper.java | 10 +- 9 files changed, 142 insertions(+), 226 deletions(-) diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 8416b9f..9dcb908 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -155,7 +155,7 @@ public class PlayerEventListener implements Listener { } //Decide if the user should be teleported to another bungee server - if (entrancePortal.isBungee()) { + if (entrancePortal.getOptions().isBungee()) { if (bungeeTeleport(player, entrancePortal, event)) { Stargate.sendSuccessMessage(player, Stargate.getString("teleportMsg")); } @@ -368,7 +368,7 @@ public class PlayerEventListener implements Listener { } //No destination - if (!entrancePortal.isBungee() && destination == null) { + if (!entrancePortal.getOptions().isBungee() && destination == null) { return false; } diff --git a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java index ec87539..4a69c13 100644 --- a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java @@ -44,7 +44,7 @@ public class VehicleEventListener implements Listener { } //Return if the portal cannot be teleported through - if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.isBungee()) { + if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.getOptions().isBungee()) { return; } @@ -69,7 +69,7 @@ public class VehicleEventListener implements Listener { Stargate.logger.warning(Stargate.getString("prefox") + "Unable to find portal destination"); return; } - Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " + destinationPortal.getId()); + Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " + destinationPortal.getSignLocation()); destinationPortal.teleport(vehicle, entrancePortal); } } diff --git a/src/main/java/net/knarcraft/stargate/portal/Portal.java b/src/main/java/net/knarcraft/stargate/portal/Portal.java index fe26130..bb47e36 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Portal.java +++ b/src/main/java/net/knarcraft/stargate/portal/Portal.java @@ -46,17 +46,10 @@ import java.util.logging.Level; public class Portal { // Gate location block info - private final BlockLocation topLeft; - private final int modX; - private final int modZ; - private final float yaw; - //The rotation axis is the axis along which the gate is placed. It's the cross axis of the button's axis - private final Axis rotationAxis; + private final PortalLocation location; // Block references - private final BlockLocation id; private final Gate gate; - private final World world; private BlockLocation button; private BlockLocation[] frame; private BlockLocation[] entrances; @@ -69,8 +62,7 @@ public class Portal { private final String ownerName; private UUID ownerUUID; private boolean verified; - private boolean fixed; - private final Map options; + private final PortalOptions options; // In-use information private Player player; @@ -83,25 +75,20 @@ public class Portal { * Instantiates a new portal * * @param portalLocation

Object containing locations of all relevant blocks

- * @param button

The location of the portal's open button

- * @param destination

The destination defined on the sign's destination line

- * @param name

The name of the portal defined on the sign's first line

- * @param verified

Whether the portal's gate has been verified to match its template

- * @param network

The network the portal belongs to, defined on the sign's network line

- * @param gate

The gate template this portal uses

- * @param ownerUUID

The UUID of the gate's owner

- * @param ownerName

The name of the gate's owner

- * @param options

A map containing all possible portal options

+ * @param button

The location of the portal's open button

+ * @param destination

The destination defined on the sign's destination line

+ * @param name

The name of the portal defined on the sign's first line

+ * @param verified

Whether the portal's gate has been verified to match its template

+ * @param network

The network the portal belongs to, defined on the sign's network line

+ * @param gate

The gate template this portal uses

+ * @param ownerUUID

The UUID of the gate's owner

+ * @param ownerName

The name of the gate's owner

+ * @param options

A map containing all possible portal options

*/ Portal(PortalLocation portalLocation, BlockLocation button, String destination, String name, boolean verified, String network, Gate gate, UUID ownerUUID, String ownerName, Map options) { - this.topLeft = portalLocation.getTopLeft(); - this.modX = portalLocation.getModX(); - this.modZ = portalLocation.getModZ(); - this.yaw = portalLocation.getYaw(); - this.rotationAxis = yaw == 0.0F || yaw == 180.0F ? Axis.X : Axis.Z; - this.id = portalLocation.getSignLocation(); + this.location = portalLocation; this.destination = destination; this.button = button; this.verified = verified; @@ -110,124 +97,29 @@ public class Portal { this.gate = gate; this.ownerUUID = ownerUUID; this.ownerName = ownerName; - this.options = options; - this.world = topLeft.getWorld(); - this.fixed = destination.length() > 0 || this.isRandom() || this.isBungee(); - - if (this.isAlwaysOn() && !this.isFixed()) { - this.options.put(PortalOption.ALWAYS_ON, false); - Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false"); - } - - if (this.isRandom() && !this.isAlwaysOn()) { - this.options.put(PortalOption.ALWAYS_ON, true); - Stargate.debug("Portal", "Gate marked as random, set to always-on"); - } + this.options = new PortalOptions(options, destination.length() > 0); if (verified) { this.drawSign(); } } + /** + * Gets the portal options for this portal + * + * @return

This portal's portal options

+ */ + public PortalOptions getOptions() { + return this.options; + } + /** * Gets whether this portal is currently open * * @return

Whether this portal is open

*/ public boolean isOpen() { - return isOpen || isAlwaysOn(); - } - - /** - * Gets whether this portal is always on - * - * @return

Whether this portal is always on

- */ - public boolean isAlwaysOn() { - return this.options.get(PortalOption.ALWAYS_ON); - } - - /** - * Gets whether this portal is hidden - * - * @return

Whether this portal is hidden

- */ - public boolean isHidden() { - return this.options.get(PortalOption.HIDDEN); - } - - /** - * Gets whether this portal is private - * - * @return

Whether this portal is private

- */ - public boolean isPrivate() { - return this.options.get(PortalOption.PRIVATE); - } - - /** - * Gets whether this portal is free - * - * @return

Whether this portal is free

- */ - public boolean isFree() { - return this.options.get(PortalOption.FREE); - } - - /** - * Gets whether this portal is backwards - * - *

A backwards portal is one where players exit through the back.

- * - * @return

Whether this portal is backwards

- */ - public boolean isBackwards() { - return this.options.get(PortalOption.BACKWARDS); - } - - /** - * Gets whether this portal is shown on the network even if it's always on - * - * @return

Whether portal gate is shown

- */ - public boolean isShown() { - return this.options.get(PortalOption.SHOW); - } - - /** - * Gets whether this portal shows no network - * - * @return

Whether this portal shows no network/p> - */ - public boolean isNoNetwork() { - return this.options.get(PortalOption.NO_NETWORK); - } - - /** - * Gets whether this portal goes to a random location on the network - * - * @return

Whether this portal goes to a random location

- */ - public boolean isRandom() { - return this.options.get(PortalOption.RANDOM); - } - - /** - * Gets whether this portal is a bungee portal - * - * @return

Whether this portal is a bungee portal

- */ - public boolean isBungee() { - return this.options.get(PortalOption.BUNGEE); - } - - /** - * Gets the rotation of the portal in degrees - * - * @return

The rotation of the portal

- */ - public float getRotation() { - return yaw; + return isOpen || options.isAlwaysOn(); } /** @@ -301,7 +193,7 @@ public class Portal { * @return

The destination portal the player should teleport to

*/ public Portal getDestination(Player player) { - if (isRandom()) { + if (options.isRandom()) { destinations = PortalHandler.getDestinations(this, player, getNetwork()); if (destinations.size() == 0) { return null; @@ -426,22 +318,13 @@ public class Portal { return frame; } - /** - * Gets the location of this portal's sign - * - * @return

The location of this portal's sign

- */ - public BlockLocation getSign() { - return id; - } - /** * Gets the world this portal belongs to * * @return

The world this portal belongs to

*/ public World getWorld() { - return world; + return location.getWorld(); } /** @@ -488,7 +371,7 @@ public class Portal { //Change the opening blocks to the correct type Material openType = gate.getPortalOpenBlock(); - Axis axis = (openType.createBlockData() instanceof Orientable) ? rotationAxis : null; + Axis axis = (openType.createBlockData() instanceof Orientable) ? location.getRotationAxis() : null; for (BlockLocation inside : getEntrances()) { Stargate.blockChangeRequestQueue.add(new BlockChangeRequest(inside, openType, axis)); } @@ -510,12 +393,12 @@ public class Portal { Stargate.activePortalsQueue.remove(this); //Open remote portal - if (!isAlwaysOn()) { + if (!options.isAlwaysOn()) { player = openFor; Portal destination = getDestination(); // Only open destination if it's not-fixed or points at this portal - if (!isRandom() && destination != null && (!destination.isFixed() || + if (!options.isRandom() && destination != null && (!destination.isFixed() || destination.getDestinationName().equalsIgnoreCase(getName())) && !destination.isOpen()) { destination.open(openFor, false); destination.setDestination(this); @@ -537,7 +420,7 @@ public class Portal { if (event.isCancelled()) return; force = event.getForce(); - if (isAlwaysOn() && !force) return; // Only close always-open if forced + if (options.isAlwaysOn() && !force) return; // Only close always-open if forced // Close this gate, then the dest gate. Material closedType = gate.getPortalClosedBlock(); @@ -560,7 +443,7 @@ public class Portal { Stargate.activePortalsQueue.remove(this); //Close remote portal - if (!isAlwaysOn()) { + if (!options.isAlwaysOn()) { Portal end = getDestination(); if (end != null && end.isOpen()) { @@ -581,7 +464,7 @@ public class Portal { if (!isOpen) { return false; } - if (isAlwaysOn() || this.player == null) { + if (options.isAlwaysOn() || this.player == null) { return true; } return player != null && player.getName().equalsIgnoreCase(this.player.getName()); @@ -595,7 +478,7 @@ public class Portal { * @return

True if this portal points to a fixed exit portal

*/ public boolean isFixed() { - return fixed; + return options.isFixed(); } /** @@ -606,7 +489,7 @@ public class Portal { * @param fixed

True if this portal points to a fixed exit portal

*/ public void setFixed(boolean fixed) { - this.fixed = fixed; + options.setFixed(fixed); } /** @@ -655,10 +538,10 @@ public class Portal { */ private void adjustRotation(Location exit, Portal origin) { int adjust = 0; - if (isBackwards() != origin.isBackwards()) { + if (options.isBackwards() != origin.options.isBackwards()) { adjust = 180; } - float newYaw = (this.getRotation() + adjust) % 360; + float newYaw = (this.getYaw() + adjust) % 360; Stargate.debug("Portal::adjustRotation", "Setting exit yaw to " + newYaw); exit.setYaw(newYaw); } @@ -679,7 +562,7 @@ public class Portal { vehicle.setVelocity(new Vector()); //Get new velocity - Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(this.getRotation()); + Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(this.getYaw()); Vector newVelocity = newVelocityDirection.multiply(velocity); adjustRotation(exit, origin); @@ -769,9 +652,9 @@ public class Portal { RelativeBlockVector relativeExit = gate.getLayout().getExit(); if (relativeExit != null) { BlockLocation exit = getBlockAt(relativeExit); - int back = (isBackwards()) ? -1 : 1; + int back = (options.isBackwards()) ? -1 : 1; exitLocation = exit.modRelativeLoc(0D, 0D, 1, traveller.getYaw(), - traveller.getPitch(), modX * back, 1, modZ * back); + traveller.getPitch(), getModX() * back, 1, getModZ() * back); if (entity != null) { double entitySize = EntityHelper.getEntityMaxSize(entity); @@ -810,20 +693,22 @@ public class Portal { if (openingWidth > 1) { newOffset -= 0.5; } - exitLocation = DirectionHelper.adjustLocation(exitLocation, newOffset, 0, 0, modX, modZ); + exitLocation = DirectionHelper.adjustLocation(exitLocation, newOffset, 0, 0, getModX(), getModZ()); //Move large entities further from the portal, especially if this portal will teleport them at once double entitySize = EntityHelper.getEntityMaxSize(entity); int entityBoxSize = EntityHelper.getEntityMaxSizeInt(entity); if (entitySize > 1) { - if (isAlwaysOn()) { - exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, (entityBoxSize / 2D), modX, modZ); + if (options.isAlwaysOn()) { + exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, (entityBoxSize / 2D), + getModX(), getModZ()); } else { - exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, (entitySize / 2D) - 1, modX, modZ); + exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, + (entitySize / 2D) - 1, getModX(), getModZ()); } } if (entity instanceof AbstractHorse) { - exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, 1, modX, modZ); + exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, 1, getModX(), getModZ()); } return exitLocation; @@ -886,8 +771,9 @@ public class Portal { //Get the chunk in front of the gate corner Location cornerLocation = getBlockAt(vector).getLocation(); - int blockOffset = this.isBackwards() ? -5 : 5; - Location fiveBlocksForward = DirectionHelper.adjustLocation(cornerLocation, 0, 0, blockOffset, modX, modZ); + int blockOffset = options.isBackwards() ? -5 : 5; + Location fiveBlocksForward = DirectionHelper.adjustLocation(cornerLocation, 0, 0, blockOffset, + getModX(), getModZ()); Chunk forwardChunk = fiveBlocksForward.getChunk(); //Load the chunks @@ -914,8 +800,8 @@ public class Portal { * * @return

The identity location of the portal

*/ - public BlockLocation getId() { - return this.id; + public BlockLocation getSignLocation() { + return this.location.getSignLocation(); } /** @@ -924,7 +810,7 @@ public class Portal { * @return

The x modifier used by this portal

*/ public int getModX() { - return this.modX; + return this.location.getModX(); } /** @@ -933,7 +819,7 @@ public class Portal { * @return

The z modifier used by this portal

*/ public int getModZ() { - return this.modZ; + return this.location.getModZ(); } /** @@ -942,7 +828,7 @@ public class Portal { * @return

The rotation of this portal

*/ public float getYaw() { - return this.yaw; + return this.location.getYaw(); } /** @@ -951,7 +837,7 @@ public class Portal { * @return

The location of the top-left portal block

*/ public BlockLocation getTopLeft() { - return this.topLeft; + return this.location.getTopLeft(); } /** @@ -991,7 +877,7 @@ public class Portal { if (!Stargate.verifyPortals) { return true; } - return gate.matches(topLeft, modX, modZ); + return gate.matches(getTopLeft(), getModX(), getModZ()); } /** @@ -1122,10 +1008,11 @@ public class Portal { * Draws the sign on this portal */ public final void drawSign() { - BlockState state = id.getBlock().getState(); + BlockState state = getSignLocation().getBlock().getState(); if (!(state instanceof Sign)) { Stargate.logger.warning(Stargate.getString("prefix") + "Sign block is not a Sign object"); - Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation()); + Stargate.debug("Portal::drawSign", "Block: " + getSignLocation().getBlock().getType() + " @ " + + getSignLocation().getBlock().getLocation()); return; } @@ -1140,7 +1027,7 @@ public class Portal { * @return

The block at the given relative position

*/ public BlockLocation getBlockAt(RelativeBlockVector vector) { - return DirectionHelper.getBlockAt(topLeft, vector, modX, modZ); + return DirectionHelper.getBlockAt(getTopLeft(), vector, getModX(), getModZ()); } /** @@ -1174,7 +1061,8 @@ public class Portal { @Override public String toString() { - return String.format("Portal [id=%s, network=%s name=%s, type=%s]", id, network, name, gate.getFilename()); + return String.format("Portal [id=%s, network=%s name=%s, type=%s]", getSignLocation(), network, name, + gate.getFilename()); } @Override diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java index 2efc3c8..067f12b 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java @@ -73,11 +73,11 @@ public class PortalHandler { continue; } //Check if destination is a random portal - if (portal.isRandom()) { + if (portal.getOptions().isRandom()) { continue; } //Check if destination is always open (Don't show if so) - if (portal.isAlwaysOn() && !portal.isShown()) { + if (portal.getOptions().isAlwaysOn() && !portal.getOptions().isShown()) { continue; } //Check if destination is this portal @@ -125,8 +125,8 @@ public class PortalHandler { } //Remove registered info about the lookup controls and blocks - lookupBlocks.remove(portal.getId()); - lookupControls.remove(portal.getId()); + lookupBlocks.remove(portal.getSignLocation()); + lookupControls.remove(portal.getSignLocation()); if (portal.getButton() != null) { lookupBlocks.remove(portal.getButton()); lookupControls.remove(portal.getButton()); @@ -142,7 +142,7 @@ public class PortalHandler { allPortals.remove(portal); } - if (portal.isBungee()) { + if (portal.getOptions().isBungee()) { //Remove the bungee listing bungeePortals.remove(portalName); } else { @@ -161,15 +161,15 @@ public class PortalHandler { origin.drawSign(); } //Close portal without destination - if (origin.isAlwaysOn()) { + if (origin.getOptions().isAlwaysOn()) { origin.close(true); } } } //Clear sign data - if (portal.getId().getBlock().getBlockData() instanceof WallSign) { - Sign sign = (Sign) portal.getId().getBlock().getState(); + if (portal.getSignLocation().getBlock().getBlockData() instanceof WallSign) { + Sign sign = (Sign) portal.getSignLocation().getBlock().getState(); sign.setLine(0, portal.getName()); sign.setLine(1, ""); sign.setLine(2, ""); @@ -186,13 +186,13 @@ public class PortalHandler { * @param portal

The portal to register

*/ private static void registerPortal(Portal portal) { - portal.setFixed(portal.getDestinationName().length() > 0 || portal.isRandom() || portal.isBungee()); + portal.setFixed(portal.getDestinationName().length() > 0 || portal.getOptions().isRandom() || portal.getOptions().isBungee()); String portalName = portal.getName().toLowerCase(); String networkName = portal.getNetwork().toLowerCase(); //Bungee portals are stored in their own list - if (portal.isBungee()) { + if (portal.getOptions().isBungee()) { bungeePortals.put(portalName, portal); } else { //Check if network exists in the lookup list. If not, register the new network @@ -216,8 +216,8 @@ public class PortalHandler { lookupBlocks.put(block, portal); } //Register the sign and button to the lookup lists - lookupBlocks.put(portal.getId(), portal); - lookupControls.put(portal.getId(), portal); + lookupBlocks.put(portal.getSignLocation(), portal); + lookupControls.put(portal.getSignLocation(), portal); if (portal.getButton() != null) { lookupBlocks.put(portal.getButton(), portal); lookupControls.put(portal.getButton(), portal); @@ -353,10 +353,11 @@ public class PortalHandler { /** * Checks if the new portal is a valid bungee portal - * @param portalOptions

The enabled portal options

- * @param player

The player trying to create the new portal

+ * + * @param portalOptions

The enabled portal options

+ * @param player

The player trying to create the new portal

* @param destinationName

The name of the portal's destination

- * @param network

The name of the portal's network

+ * @param network

The name of the portal's network

* @return

False if the portal is an invalid bungee portal. True otherwise

*/ private static boolean isValidBungeePortal(Map portalOptions, Player player, @@ -497,7 +498,7 @@ public class PortalHandler { updateNewPortal(portal, destinationName); //Update portals pointing at this one if it's not a bungee portal - if (!portal.isBungee()) { + if (!portal.getOptions().isBungee()) { updatePortalsPointingAtNewPortal(portal); } @@ -524,7 +525,7 @@ public class PortalHandler { } //Don't do network checks for bungee portals - if (portal.isBungee()) { + if (portal.getOptions().isBungee()) { if (bungeePortals.get(portal.getName().toLowerCase()) != null) { Stargate.debug("createPortal::Bungee", "Gate name duplicate"); Stargate.sendErrorMessage(player, Stargate.getString("createExists")); @@ -584,9 +585,9 @@ public class PortalHandler { private static void updateNewPortal(Portal portal, String destinationName) { portal.drawSign(); //Open an always on portal - if (portal.isRandom() || portal.isBungee()) { + if (portal.getOptions().isRandom() || portal.getOptions().isBungee()) { portal.open(true); - } else if (portal.isAlwaysOn()) { + } else if (portal.getOptions().isAlwaysOn()) { Portal destinationPortal = getByName(destinationName, portal.getNetwork()); if (destinationPortal != null) { portal.open(true); @@ -618,7 +619,7 @@ public class PortalHandler { origin.drawSign(); } //Open any always on portal pointing at this portal - if (origin.isAlwaysOn()) { + if (origin.getOptions().isAlwaysOn()) { origin.open(true); } } @@ -792,7 +793,7 @@ public class PortalHandler { BlockLocation button = portal.getButton(); builder.append(portal.getName()).append(':'); - builder.append(portal.getId().toString()).append(':'); + builder.append(portal.getSignLocation().toString()).append(':'); builder.append((button != null) ? button.toString() : "").append(':'); builder.append(portal.getModX()).append(':'); builder.append(portal.getModZ()).append(':'); @@ -808,16 +809,16 @@ public class PortalHandler { builder.append(portal.getOwnerName()); } builder.append(':'); - builder.append(portal.isHidden()).append(':'); - builder.append(portal.isAlwaysOn()).append(':'); - builder.append(portal.isPrivate()).append(':'); + builder.append(portal.getOptions().isHidden()).append(':'); + builder.append(portal.getOptions().isAlwaysOn()).append(':'); + builder.append(portal.getOptions().isPrivate()).append(':'); builder.append(portal.getWorld().getName()).append(':'); - builder.append(portal.isFree()).append(':'); - builder.append(portal.isBackwards()).append(':'); - builder.append(portal.isShown()).append(':'); - builder.append(portal.isNoNetwork()).append(':'); - builder.append(portal.isRandom()).append(':'); - builder.append(portal.isBungee()); + builder.append(portal.getOptions().isFree()).append(':'); + builder.append(portal.getOptions().isBackwards()).append(':'); + builder.append(portal.getOptions().isShown()).append(':'); + builder.append(portal.getOptions().isNoNetwork()).append(':'); + builder.append(portal.getOptions().isRandom()).append(':'); + builder.append(portal.getOptions().isBungee()); bw.append(builder.toString()); bw.newLine(); @@ -1038,8 +1039,8 @@ public class PortalHandler { portalCount++; //Open the gate if it's set as always open or if it's a bungee gate - if (portal.isFixed() && (Stargate.enableBungee && portal.isBungee() || portal.getDestination() != null && - portal.isAlwaysOn())) { + if (portal.isFixed() && (Stargate.enableBungee && portal.getOptions().isBungee() || + portal.getDestination() != null && portal.getOptions().isAlwaysOn())) { portal.open(true); openCount++; } diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java b/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java index 7f0eb0b..8c0da51 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java @@ -2,6 +2,8 @@ package net.knarcraft.stargate.portal; import net.knarcraft.stargate.container.BlockLocation; import net.knarcraft.stargate.container.RelativeBlockVector; +import org.bukkit.Axis; +import org.bukkit.World; import org.bukkit.block.BlockFace; /** @@ -55,6 +57,7 @@ public class PortalLocation { /** * Gets the location of the portal's sign + * * @return

The location of the portal's sign

*/ public BlockLocation getSignLocation() { @@ -63,6 +66,7 @@ public class PortalLocation { /** * The relative block vector pointing to the portal's button + * * @return

The relative location of the portal's button

*/ public RelativeBlockVector getButtonVector() { @@ -71,12 +75,32 @@ public class PortalLocation { /** * Gets the block face determining the button's direction + * * @return

The button's block face

*/ public BlockFace getButtonFacing() { return buttonFacing; } + /** + * Gets the rotation axis, which is the axis along which the gate is placed + *

The portal's rotation axis is the cross axis of the button's axis

+ * + * @return

The portal's rotation axis

+ */ + public Axis getRotationAxis() { + return getYaw() == 0.0F || getYaw() == 180.0F ? Axis.X : Axis.Z; + } + + /** + * Gets the world this portal resides in + * + * @return

The world this portal resides in

+ */ + public World getWorld() { + return topLeft.getWorld(); + } + /** * Sets the portal's top-left location * @@ -128,6 +152,7 @@ public class PortalLocation { /** * Sets the location of the portal's sign + * * @param signLocation

The new sign location

* @return

The portal location Object

*/ @@ -138,6 +163,7 @@ public class PortalLocation { /** * Sets the relative location of the portal's button + * * @param buttonVector

The new relative button location

* @return

The portal location Object

*/ @@ -148,6 +174,7 @@ public class PortalLocation { /** * Sets the block face for the direction the portal button is facing + * * @param buttonFacing

The new block face of the portal's button

* @return

The portal location Object

*/ diff --git a/src/main/java/net/knarcraft/stargate/thread/StarGateThread.java b/src/main/java/net/knarcraft/stargate/thread/StarGateThread.java index 4b202df..521b388 100644 --- a/src/main/java/net/knarcraft/stargate/thread/StarGateThread.java +++ b/src/main/java/net/knarcraft/stargate/thread/StarGateThread.java @@ -17,7 +17,7 @@ public class StarGateThread implements Runnable { for (Iterator iterator = Stargate.openPortalsQueue.iterator(); iterator.hasNext(); ) { Portal portal = iterator.next(); // Skip always open and non-open gates - if (portal.isAlwaysOn() || !portal.isOpen()) { + if (portal.getOptions().isAlwaysOn() || !portal.isOpen()) { continue; } if (time > portal.getOpenTime() + Stargate.getOpenTime()) { diff --git a/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java b/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java index 616e347..33c4b1e 100644 --- a/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java +++ b/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java @@ -190,11 +190,11 @@ public final class EconomyHandler { */ public static int getUseCost(Player player, Portal source, Portal destination) { //No payment required - if (!EconomyHandler.useEconomy() || source.isFree()) { + if (!EconomyHandler.useEconomy() || source.getOptions().isFree()) { return 0; } //Not charging for free destinations - if (destination != null && !EconomyHandler.chargeFreeDestination && destination.isFree()) { + if (destination != null && !EconomyHandler.chargeFreeDestination && destination.getOptions().isFree()) { return 0; } //Cost is 0 if the player owns this gate and funds go to the owner diff --git a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java index 9c6eacb..bfe8444 100644 --- a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java @@ -25,12 +25,12 @@ public final class PermissionHelper { Portal destination = portal.getDestination(); //Always-open gate -- Do nothing - if (portal.isAlwaysOn()) { + if (portal.getOptions().isAlwaysOn()) { return; } //Random gate -- Do nothing - if (portal.isRandom()) { + if (portal.getOptions().isRandom()) { return; } @@ -56,13 +56,13 @@ public final class PermissionHelper { } //Check if the player can use the private gate - if (portal.isPrivate() && !PermissionHelper.canPrivate(player, portal)) { + if (portal.getOptions().isPrivate() && !PermissionHelper.canPrivate(player, portal)) { Stargate.sendErrorMessage(player, Stargate.getString("denyMsg")); return; } //Destination blocked - if ((destination.isOpen()) && (!destination.isAlwaysOn())) { + if ((destination.isOpen()) && (!destination.getOptions().isAlwaysOn())) { Stargate.sendErrorMessage(player, Stargate.getString("blockMsg")); return; } @@ -98,13 +98,13 @@ public final class PermissionHelper { public static boolean cannotAccessPortal(Player player, Portal entrancePortal, Portal destination) { boolean deny = false; // Check if player has access to this server for Bungee gates - if (entrancePortal.isBungee() && !PermissionHelper.canAccessServer(player, entrancePortal.getNetwork())) { + if (entrancePortal.getOptions().isBungee() && !PermissionHelper.canAccessServer(player, entrancePortal.getNetwork())) { Stargate.debug("cannotAccessPortal", "Cannot access server"); deny = true; } else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getNetwork())) { Stargate.debug("cannotAccessPortal", "Cannot access network"); deny = true; - } else if (!entrancePortal.isBungee() && PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) { + } else if (!entrancePortal.getOptions().isBungee() && PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) { Stargate.debug("cannotAccessPortal", "Cannot access world"); deny = true; } @@ -219,7 +219,7 @@ public final class PermissionHelper { */ public static boolean isFree(Player player, Portal src, Portal dest) { // This gate is free - if (src.isFree()) { + if (src.getOptions().isFree()) { return true; } // Player gets free use @@ -227,7 +227,7 @@ public final class PermissionHelper { return true; } // Don't charge for free destination gates - return dest != null && !EconomyHandler.chargeFreeDestination && dest.isFree(); + return dest != null && !EconomyHandler.chargeFreeDestination && dest.getOptions().isFree(); } /** @@ -241,7 +241,7 @@ public final class PermissionHelper { */ public static boolean canSeePortal(Player player, Portal portal) { // The gate is not hidden - if (!portal.isHidden()) { + if (!portal.getOptions().isHidden()) { return true; } // The player is an admin with the ability to see hidden gates diff --git a/src/main/java/net/knarcraft/stargate/utility/SignHelper.java b/src/main/java/net/knarcraft/stargate/utility/SignHelper.java index 891c209..d84fa21 100644 --- a/src/main/java/net/knarcraft/stargate/utility/SignHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/SignHelper.java @@ -25,7 +25,7 @@ public final class SignHelper { //Default sign text drawInactiveSign(sign, portal); } else { - if (portal.isBungee()) { + if (portal.getOptions().isBungee()) { //Bungee sign drawBungeeSign(sign, portal); } else if (portal.isFixed()) { @@ -126,7 +126,7 @@ public final class SignHelper { private static void drawInactiveSign(Sign sign, Portal portal) { Stargate.setLine(sign, 1, Stargate.getString("signRightClick")); Stargate.setLine(sign, 2, Stargate.getString("signToUse")); - if (!portal.isNoNetwork()) { + if (!portal.getOptions().isNoNetwork()) { Stargate.setLine(sign, 3, "(" + portal.getNetwork() + ")"); } else { Stargate.setLine(sign, 3, ""); @@ -139,18 +139,18 @@ public final class SignHelper { * @param sign

The sign to draw on

*/ private static void drawFixedSign(Sign sign, Portal portal) { - if (portal.isRandom()) { + if (portal.getOptions().isRandom()) { Stargate.setLine(sign, 1, "> " + Stargate.getString("signRandom") + " <"); } else { Stargate.setLine(sign, 1, ">" + portal.getDestinationName() + "<"); } - if (portal.isNoNetwork()) { + if (portal.getOptions().isNoNetwork()) { Stargate.setLine(sign, 2, ""); } else { Stargate.setLine(sign, 2, "(" + portal.getNetwork() + ")"); } Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork()); - if (destination == null && !portal.isRandom()) { + if (destination == null && !portal.getOptions().isRandom()) { Stargate.setLine(sign, 3, Stargate.getString("signDisconnected")); } else { Stargate.setLine(sign, 3, "");