Moves functionality to the PortalOptions and PortalLocation classes

This commit is contained in:
Kristian Knarvik 2021-10-08 01:26:12 +02:00
parent 60c543e52a
commit e7fc1daafe
9 changed files with 142 additions and 226 deletions

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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<PortalOption, Boolean> options;
private final PortalOptions options;
// In-use information
private Player player;
@ -83,25 +75,20 @@ public class Portal {
* Instantiates a new portal
*
* @param portalLocation <p>Object containing locations of all relevant blocks</p>
* @param button <p>The location of the portal's open button</p>
* @param destination <p>The destination defined on the sign's destination line</p>
* @param name <p>The name of the portal defined on the sign's first line</p>
* @param verified <p>Whether the portal's gate has been verified to match its template</p>
* @param network <p>The network the portal belongs to, defined on the sign's network line</p>
* @param gate <p>The gate template this portal uses</p>
* @param ownerUUID <p>The UUID of the gate's owner</p>
* @param ownerName <p>The name of the gate's owner</p>
* @param options <p>A map containing all possible portal options</p>
* @param button <p>The location of the portal's open button</p>
* @param destination <p>The destination defined on the sign's destination line</p>
* @param name <p>The name of the portal defined on the sign's first line</p>
* @param verified <p>Whether the portal's gate has been verified to match its template</p>
* @param network <p>The network the portal belongs to, defined on the sign's network line</p>
* @param gate <p>The gate template this portal uses</p>
* @param ownerUUID <p>The UUID of the gate's owner</p>
* @param ownerName <p>The name of the gate's owner</p>
* @param options <p>A map containing all possible portal options</p>
*/
Portal(PortalLocation portalLocation, BlockLocation button,
String destination, String name, boolean verified, String network, Gate gate, UUID ownerUUID,
String ownerName, Map<PortalOption, Boolean> 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 <p>This portal's portal options</p>
*/
public PortalOptions getOptions() {
return this.options;
}
/**
* Gets whether this portal is currently open
*
* @return <p>Whether this portal is open</p>
*/
public boolean isOpen() {
return isOpen || isAlwaysOn();
}
/**
* Gets whether this portal is always on
*
* @return <p>Whether this portal is always on</p>
*/
public boolean isAlwaysOn() {
return this.options.get(PortalOption.ALWAYS_ON);
}
/**
* Gets whether this portal is hidden
*
* @return <p>Whether this portal is hidden</p>
*/
public boolean isHidden() {
return this.options.get(PortalOption.HIDDEN);
}
/**
* Gets whether this portal is private
*
* @return <p>Whether this portal is private</p>
*/
public boolean isPrivate() {
return this.options.get(PortalOption.PRIVATE);
}
/**
* Gets whether this portal is free
*
* @return <p>Whether this portal is free</p>
*/
public boolean isFree() {
return this.options.get(PortalOption.FREE);
}
/**
* Gets whether this portal is backwards
*
* <p>A backwards portal is one where players exit through the back.</p>
*
* @return <p>Whether this portal is backwards</p>
*/
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 <p>Whether portal gate is shown</p>
*/
public boolean isShown() {
return this.options.get(PortalOption.SHOW);
}
/**
* Gets whether this portal shows no network
*
* @return <p>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 <p>Whether this portal goes to a random location</p>
*/
public boolean isRandom() {
return this.options.get(PortalOption.RANDOM);
}
/**
* Gets whether this portal is a bungee portal
*
* @return <p>Whether this portal is a bungee portal</p>
*/
public boolean isBungee() {
return this.options.get(PortalOption.BUNGEE);
}
/**
* Gets the rotation of the portal in degrees
*
* @return <p>The rotation of the portal</p>
*/
public float getRotation() {
return yaw;
return isOpen || options.isAlwaysOn();
}
/**
@ -301,7 +193,7 @@ public class Portal {
* @return <p>The destination portal the player should teleport to</p>
*/
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 <p>The location of this portal's sign</p>
*/
public BlockLocation getSign() {
return id;
}
/**
* Gets the world this portal belongs to
*
* @return <p>The world this portal belongs to</p>
*/
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 <p>True if this portal points to a fixed exit portal</p>
*/
public boolean isFixed() {
return fixed;
return options.isFixed();
}
/**
@ -606,7 +489,7 @@ public class Portal {
* @param fixed <p>True if this portal points to a fixed exit portal</p>
*/
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 <p>The identity location of the portal</p>
*/
public BlockLocation getId() {
return this.id;
public BlockLocation getSignLocation() {
return this.location.getSignLocation();
}
/**
@ -924,7 +810,7 @@ public class Portal {
* @return <p>The x modifier used by this portal</p>
*/
public int getModX() {
return this.modX;
return this.location.getModX();
}
/**
@ -933,7 +819,7 @@ public class Portal {
* @return <p>The z modifier used by this portal</p>
*/
public int getModZ() {
return this.modZ;
return this.location.getModZ();
}
/**
@ -942,7 +828,7 @@ public class Portal {
* @return <p>The rotation of this portal</p>
*/
public float getYaw() {
return this.yaw;
return this.location.getYaw();
}
/**
@ -951,7 +837,7 @@ public class Portal {
* @return <p>The location of the top-left portal block</p>
*/
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 <p>The block at the given relative position</p>
*/
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

View File

@ -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 <p>The portal to register</p>
*/
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 <p>The enabled portal options</p>
* @param player <p>The player trying to create the new portal</p>
*
* @param portalOptions <p>The enabled portal options</p>
* @param player <p>The player trying to create the new portal</p>
* @param destinationName <p>The name of the portal's destination</p>
* @param network <p>The name of the portal's network</p>
* @param network <p>The name of the portal's network</p>
* @return <p>False if the portal is an invalid bungee portal. True otherwise</p>
*/
private static boolean isValidBungeePortal(Map<PortalOption, Boolean> 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++;
}

View File

@ -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 <p>The location of the portal's sign</p>
*/
public BlockLocation getSignLocation() {
@ -63,6 +66,7 @@ public class PortalLocation {
/**
* The relative block vector pointing to the portal's button
*
* @return <p>The relative location of the portal's button</p>
*/
public RelativeBlockVector getButtonVector() {
@ -71,12 +75,32 @@ public class PortalLocation {
/**
* Gets the block face determining the button's direction
*
* @return <p>The button's block face</p>
*/
public BlockFace getButtonFacing() {
return buttonFacing;
}
/**
* Gets the rotation axis, which is the axis along which the gate is placed
* <p>The portal's rotation axis is the cross axis of the button's axis</p>
*
* @return <p>The portal's rotation axis</p>
*/
public Axis getRotationAxis() {
return getYaw() == 0.0F || getYaw() == 180.0F ? Axis.X : Axis.Z;
}
/**
* Gets the world this portal resides in
*
* @return <p>The world this portal resides in</p>
*/
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 <p>The new sign location</p>
* @return <p>The portal location Object</p>
*/
@ -138,6 +163,7 @@ public class PortalLocation {
/**
* Sets the relative location of the portal's button
*
* @param buttonVector <p>The new relative button location</p>
* @return <p>The portal location Object</p>
*/
@ -148,6 +174,7 @@ public class PortalLocation {
/**
* Sets the block face for the direction the portal button is facing
*
* @param buttonFacing <p>The new block face of the portal's button</p>
* @return <p>The portal location Object</p>
*/

View File

@ -17,7 +17,7 @@ public class StarGateThread implements Runnable {
for (Iterator<Portal> 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()) {

View File

@ -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

View File

@ -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

View File

@ -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 <p>The sign to draw on</p>
*/
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, "");