diff --git a/src/main/java/net/knarcraft/stargate/LanguageLoader.java b/src/main/java/net/knarcraft/stargate/LanguageLoader.java index 1cf4951..edae036 100644 --- a/src/main/java/net/knarcraft/stargate/LanguageLoader.java +++ b/src/main/java/net/knarcraft/stargate/LanguageLoader.java @@ -229,12 +229,16 @@ public class LanguageLoader { public void debug() { Set keys = loadedStringTranslations.keySet(); for (String key : keys) { - Stargate.debug("LanguageLoader::Debug::loadedStringTranslations", key + " => " + loadedStringTranslations.get(key)); + Stargate.debug("LanguageLoader::Debug::loadedStringTranslations", key + " => " + + loadedStringTranslations.get(key)); + } + if (loadedBackupStrings == null) { + return; } - if (loadedBackupStrings == null) return; keys = loadedBackupStrings.keySet(); for (String key : keys) { - Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", key + " => " + loadedBackupStrings.get(key)); + Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", key + " => " + + loadedBackupStrings.get(key)); } } diff --git a/src/main/java/net/knarcraft/stargate/Stargate.java b/src/main/java/net/knarcraft/stargate/Stargate.java index 975c97c..741b1f0 100644 --- a/src/main/java/net/knarcraft/stargate/Stargate.java +++ b/src/main/java/net/knarcraft/stargate/Stargate.java @@ -322,6 +322,9 @@ public class Stargate extends JavaPlugin { // It is important to load languages here, as they are used during reloadGates() languageLoader = new LanguageLoader(languageFolder, Stargate.languageName); + if (debuggingEnabled) { + languageLoader.debug(); + } this.createMissingFolders(); this.loadGates(); diff --git a/src/main/java/net/knarcraft/stargate/container/BlockChangeRequest.java b/src/main/java/net/knarcraft/stargate/container/BlockChangeRequest.java index 57008c4..55e5269 100644 --- a/src/main/java/net/knarcraft/stargate/container/BlockChangeRequest.java +++ b/src/main/java/net/knarcraft/stargate/container/BlockChangeRequest.java @@ -8,9 +8,9 @@ import org.bukkit.Material; */ public class BlockChangeRequest { - private BlockLocation blockLocation; - private Material newMaterial; - private Axis newAxis; + private final BlockLocation blockLocation; + private final Material newMaterial; + private final Axis newAxis; /** * Instantiates a new block change request @@ -34,15 +34,6 @@ public class BlockChangeRequest { return blockLocation; } - /** - * Sets the location of the block - * - * @param blockLocation

The new location of the block

- */ - public void setBlockLocation(BlockLocation blockLocation) { - this.blockLocation = blockLocation; - } - /** * Gets the material to change the block into * @@ -52,15 +43,6 @@ public class BlockChangeRequest { return newMaterial; } - /** - * Sets the material to change the block into - * - * @param material

The new material

- */ - public void setMaterial(Material material) { - newMaterial = material; - } - /** * Gets the axis to orient the block along * @@ -70,13 +52,4 @@ public class BlockChangeRequest { return newAxis; } - /** - * Sets the axis to orient the block along - * - * @param axis

The new axis to orient the block along

- */ - public void setAxis(Axis axis) { - newAxis = axis; - } - } diff --git a/src/main/java/net/knarcraft/stargate/container/BlockLocation.java b/src/main/java/net/knarcraft/stargate/container/BlockLocation.java index 7fec741..36f3386 100644 --- a/src/main/java/net/knarcraft/stargate/container/BlockLocation.java +++ b/src/main/java/net/knarcraft/stargate/container/BlockLocation.java @@ -62,73 +62,53 @@ public class BlockLocation extends Location { * @param z

The z position relative to this block's position

* @return

A new block location

*/ - public BlockLocation makeRelative(int x, int y, int z) { + public BlockLocation makeRelativeBlockLocation(int x, int y, int z) { return (BlockLocation) this.clone().add(x, y, z); } /** * Makes a location relative to the block location * - * @param x

The x position relative to this block's position

- * @param y

The y position relative to this block's position

- * @param z

The z position relative to this block's position

- * @param yaw

The yaw of the location

- * @param rotY

The y rotation of the location

+ * @param x

The x position relative to this block's position

+ * @param y

The y position relative to this block's position

+ * @param z

The z position relative to this block's position

+ * @param yaw

The yaw of the location

* @return

A new location

*/ - public Location makeRelativeLoc(double x, double y, double z, float yaw, float rotY) { + public Location makeRelativeLocation(double x, double y, double z, float yaw) { Location newLocation = this.clone(); newLocation.setYaw(yaw); - newLocation.setPitch(rotY); + newLocation.setPitch(0); return newLocation.add(x, y, z); } /** * Gets a location relative to this block location * - * @param vector

The relative block vector describing the relative location

- * @param yaw

The yaw pointing in the distance direction

+ * @param relativeVector

The relative block vector describing the relative location

+ * @param yaw

The yaw pointing in the distance direction

* @return

A location relative to this location

*/ - public BlockLocation getRelativeLocation(RelativeBlockVector vector, double yaw) { - Vector combined = DirectionHelper.getCoordinateVectorFromRelativeVector(vector.getRight(), vector.getDepth(), - vector.getDistance(), yaw); - return makeRelative(combined.getBlockX(), combined.getBlockY(), combined.getBlockZ()); - } - - /** - * Makes a block location relative to the current origin according to given parameters - * - *

See {@link RelativeBlockVector} to understand better. modX or modZ should always be 0 while the other is 1 - * or -1.

- * - * @param right

The amount of right steps from the top-left origin

- * @param depth

The amount of downward steps from the top-left origin

- * @param distance

The distance outward from the top-left origin

- * @param modX

X modifier. If modX = -1, X will increase as right increases

- * @param modY

Y modifier. modY = 1 for Y decreasing as depth increases

- * @param modZ

Z modifier. If modZ = 1, X will increase as distance increases

- * @return A new location relative to this block location - */ - public BlockLocation modRelative(int right, int depth, int distance, int modX, int modY, int modZ) { - return makeRelative(-right * modX + distance * modZ, -depth * modY, -right * modZ + -distance * modX); + public BlockLocation getRelativeLocation(RelativeBlockVector relativeVector, double yaw) { + Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(relativeVector.getRight(), + relativeVector.getDepth(), relativeVector.getDistance(), yaw); + return makeRelativeBlockLocation(realVector.getBlockX(), realVector.getBlockY(), realVector.getBlockZ()); } /** * Makes a location relative to the current location according to given parameters * - * @param right

- * @param depth

The y position relative to the current position

- * @param distance

The distance away from the previous location to the new location

- * @param yaw

The yaw of the location

- * @param rotY

Unused

- * @param modX

x modifier. Defines movement along the x-axis. 0 for no movement

- * @param modY

Unused

- * @param modZ

z modifier. Defines movement along the z-axis. 0 for no movement

+ * @param right

The amount of blocks to go right when looking the opposite direction from the yaw

+ * @param depth

The amount of blocks to go downwards when looking the opposite direction from the yaw

+ * @param distance

The amount of blocks to go outwards when looking the opposite direction from the yaw

+ * @param portalYaw

The yaw when looking out from the portal

+ * @param yaw

The yaw of the travelling entity

* @return A new location relative to this block location */ - public Location modRelativeLoc(double right, double depth, double distance, float yaw, float rotY, int modX, int modY, int modZ) { - return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, yaw, 0); + public Location getRelativeLocation(double right, double depth, double distance, float portalYaw, float yaw) { + Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(right, depth, distance, portalYaw); + return makeRelativeLocation(0.5 + realVector.getBlockX(), realVector.getBlockY(), + 0.5 + realVector.getBlockZ(), yaw); } /** @@ -193,7 +173,7 @@ public class BlockLocation extends Location { } else { return; } - parent = this.makeRelative(offsetX, offsetY, offsetZ); + parent = this.makeRelativeBlockLocation(offsetX, offsetY, offsetZ); } @Override diff --git a/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java b/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java index 6c1a8bf..8e02bb3 100644 --- a/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java +++ b/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java @@ -14,6 +14,8 @@ public class RelativeBlockVector { private final int depth; private final int distance; + public enum Property {RIGHT, DEPTH, DISTANCE} + /** * Instantiates a new relative block vector * @@ -27,6 +29,35 @@ public class RelativeBlockVector { this.distance = distance; } + /** + * Adds a value to one of the properties of this relative block vector + * + * @param propertyToAddTo

The property to change

+ * @param valueToAdd

The value to add to the property

+ * @return

A new relative block vector with the property altered

+ */ + public RelativeBlockVector addToVector(Property propertyToAddTo, int valueToAdd) { + switch (propertyToAddTo) { + case RIGHT: + return new RelativeBlockVector(this.right + valueToAdd, this.depth, this.distance); + case DEPTH: + return new RelativeBlockVector(this.right, this.depth + valueToAdd, this.distance); + case DISTANCE: + return new RelativeBlockVector(this.right, this.depth, this.distance + valueToAdd); + default: + throw new IllegalArgumentException("Invalid relative block vector property given"); + } + } + + /** + * Gets a relative block vector which is this inverted (pointing in the opposite direction) + * + * @return

This vector, but inverted

+ */ + public RelativeBlockVector invert() { + return new RelativeBlockVector(-this.right, -this.depth, -this.distance); + } + /** * Gets the distance to the right relative to the origin * diff --git a/src/main/java/net/knarcraft/stargate/event/StargateOpenEvent.java b/src/main/java/net/knarcraft/stargate/event/StargateOpenEvent.java index 04bf752..1c7e649 100644 --- a/src/main/java/net/knarcraft/stargate/event/StargateOpenEvent.java +++ b/src/main/java/net/knarcraft/stargate/event/StargateOpenEvent.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull; /** * This event should be called whenever a player opens a stargate */ +@SuppressWarnings({"unused"}) public class StargateOpenEvent extends StargatePlayerEvent { private static final HandlerList handlers = new HandlerList(); diff --git a/src/main/java/net/knarcraft/stargate/event/StargatePlayerEvent.java b/src/main/java/net/knarcraft/stargate/event/StargatePlayerEvent.java index bc7074d..a68db69 100644 --- a/src/main/java/net/knarcraft/stargate/event/StargatePlayerEvent.java +++ b/src/main/java/net/knarcraft/stargate/event/StargatePlayerEvent.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; /** * An abstract event describing any stargate event where a player is involved */ +@SuppressWarnings("unused") public abstract class StargatePlayerEvent extends StargateEvent { private final Player player; diff --git a/src/main/java/net/knarcraft/stargate/event/StargatePortalEvent.java b/src/main/java/net/knarcraft/stargate/event/StargatePortalEvent.java index ed13e26..0f30913 100644 --- a/src/main/java/net/knarcraft/stargate/event/StargatePortalEvent.java +++ b/src/main/java/net/knarcraft/stargate/event/StargatePortalEvent.java @@ -41,9 +41,9 @@ public class StargatePortalEvent extends StargatePlayerEvent { } /** - * Return the destination gate + * Return the destination portal * - * @return destination gate + * @return

The destination portal

*/ public Portal getDestination() { return destination; @@ -52,14 +52,14 @@ public class StargatePortalEvent extends StargatePlayerEvent { /** * Return the location of the players exit point * - * @return org.bukkit.Location Location of the exit point + * @return

Location of the exit point

*/ public Location getExit() { return exit; } /** - * Set the location of the players exit point + * Set the location of the player's exit point */ public void setExit(Location loc) { this.exit = loc; diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 885b0f7..2e3d31d 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -244,7 +244,7 @@ public class PlayerEventListener implements Listener { } /** - * This method handles right clicking of a sign or button belonging to a stargate + * This method handles right-clicking of a sign or button belonging to a stargate * * @param event

The event triggering the right-click

* @param player

The player doing the right-click

diff --git a/src/main/java/net/knarcraft/stargate/listener/WorldEventListener.java b/src/main/java/net/knarcraft/stargate/listener/WorldEventListener.java index f729fda..5f53cc6 100644 --- a/src/main/java/net/knarcraft/stargate/listener/WorldEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/WorldEventListener.java @@ -15,7 +15,7 @@ import org.bukkit.event.world.WorldUnloadEvent; public class WorldEventListener implements Listener { /** - * This listener listens for the loading of a world and loads all all gates from the world if not already loaded + * This listener listens for the loading of a world and loads all gates from the world if not already loaded * * @param event

The triggered world load event

*/ diff --git a/src/main/java/net/knarcraft/stargate/portal/Gate.java b/src/main/java/net/knarcraft/stargate/portal/Gate.java index 51ae9d2..8fd74bd 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Gate.java +++ b/src/main/java/net/knarcraft/stargate/portal/Gate.java @@ -26,8 +26,8 @@ public class Gate { private final Map types; //Gate materials - private Material portalOpenBlock; - private Material portalClosedBlock; + private final Material portalOpenBlock; + private final Material portalClosedBlock; private final Material portalButton; // Economy information @@ -74,15 +74,6 @@ public class Gate { return layout; } - /** - * Gets the material types each layout character represents - * - * @return

The material types each layout character represents

- */ - public Map getTypes() { - return types; - } - /** * Gets the material type used for this gate's control blocks * @@ -110,15 +101,6 @@ public class Gate { return portalOpenBlock; } - /** - * Sets the block to use for the opening when a portal using this gate is open - * - * @param type

The block type to use for the opening when open

- */ - public void setPortalOpenBlock(Material type) { - portalOpenBlock = type; - } - /** * Gets the block type to use for the opening when a portal using this gate is closed * @@ -128,15 +110,6 @@ public class Gate { return portalClosedBlock; } - /** - * Sets the block type to use for the opening when a portal using this gate is closed - * - * @param type

The block type to use for the opening when closed

- */ - public void setPortalClosedBlock(Material type) { - portalClosedBlock = type; - } - /** * Gets the material to use for a portal's button if using this gate type * @@ -186,36 +159,33 @@ public class Gate { * Checks whether a portal's gate matches this gate type * * @param topLeft

The top-left block of the portal's gate

- * @param modX

The x modifier used

- * @param modZ

The z modifier used

+ * @param yaw

The yaw when looking directly outwards

* @return

True if this gate matches the portal

*/ - public boolean matches(BlockLocation topLeft, int modX, int modZ) { - return matches(topLeft, modX, modZ, false); + public boolean matches(BlockLocation topLeft, double yaw) { + return matches(topLeft, yaw, false); } /** * Checks whether a portal's gate matches this gate type * * @param topLeft

The top-left block of the portal's gate

- * @param modX

The x modifier used

- * @param modZ

The z modifier used

+ * @param yaw

The yaw when looking directly outwards

* @param onCreate

Whether this is used in the context of creating a new gate

* @return

True if this gate matches the portal

*/ - public boolean matches(BlockLocation topLeft, int modX, int modZ, boolean onCreate) { - return verifyGateEntrancesMatch(topLeft, modX, modZ, onCreate) && verifyGateBorderMatches(topLeft, modX, modZ); + public boolean matches(BlockLocation topLeft, double yaw, boolean onCreate) { + return verifyGateEntrancesMatch(topLeft, yaw, onCreate) && verifyGateBorderMatches(topLeft, yaw); } /** * Verifies that all border blocks of a portal gate matches this gate type * * @param topLeft

The top-left block of the portal

- * @param modX

The x modifier used

- * @param modZ

The z modifier used

+ * @param yaw

The yaw when looking directly outwards

* @return

True if all border blocks of the gate match the layout

*/ - private boolean verifyGateBorderMatches(BlockLocation topLeft, int modX, int modZ) { + private boolean verifyGateBorderMatches(BlockLocation topLeft, double yaw) { Map portalTypes = new HashMap<>(types); for (RelativeBlockVector borderVector : layout.getBorder()) { int rowIndex = borderVector.getRight(); @@ -223,7 +193,7 @@ public class Gate { Character key = layout.getLayout()[lineIndex][rowIndex]; Material materialInLayout = portalTypes.get(key); - Material materialAtLocation = getBlockAt(topLeft, borderVector, modX, modZ).getType(); + Material materialAtLocation = getBlockAt(topLeft, borderVector, yaw).getType(); if (materialInLayout == null) { portalTypes.put(key, materialAtLocation); } else if (materialAtLocation != materialInLayout) { @@ -239,19 +209,20 @@ public class Gate { * Verifies that all entrances of a portal gate matches this gate type * * @param topLeft

The top-left block of this portal

- * @param modX

The x modifier used

- * @param modZ

The z modifier used

+ * @param yaw

The yaw when looking directly outwards

* @param onCreate

Whether this is used in the context of creating a new gate

* @return

Whether this is used in the context of creating a new gate

*/ - private boolean verifyGateEntrancesMatch(BlockLocation topLeft, int modX, int modZ, boolean onCreate) { + private boolean verifyGateEntrancesMatch(BlockLocation topLeft, double yaw, boolean onCreate) { if (Stargate.ignoreEntrance) { return true; } + Stargate.debug("verifyGateEntrancesMatch", String.valueOf(topLeft)); for (RelativeBlockVector entranceVector : layout.getEntrances()) { - Material type = getBlockAt(topLeft, entranceVector, modX, modZ).getType(); + Stargate.debug("verifyGateEntrancesMatch", String.valueOf(entranceVector)); + Material type = getBlockAt(topLeft, entranceVector, yaw).getType(); - // Ignore entrance if it's air and we're creating a new gate + //Ignore entrance if it's air, and we're creating a new gate if (onCreate && type == Material.AIR) { continue; } @@ -270,8 +241,8 @@ public class Gate { * @param vector

The relative block vector

* @return

The block at the given relative position

*/ - private BlockLocation getBlockAt(BlockLocation topLeft, RelativeBlockVector vector, int modX, int modZ) { - return DirectionHelper.getBlockAt(topLeft, vector, modX, modZ); + private BlockLocation getBlockAt(BlockLocation topLeft, RelativeBlockVector vector, double yaw) { + return DirectionHelper.getBlockAt(topLeft, vector, yaw); } /** @@ -371,6 +342,7 @@ public class Gate { * @param value

The value of the config key

* @throws IOException

If unable to write to the buffered writer

*/ + @SuppressWarnings("SameParameterValue") private void writeConfig(BufferedWriter bufferedWriter, String key, boolean value) throws IOException { writeConfig(bufferedWriter, "%s=%b", key, value); } diff --git a/src/main/java/net/knarcraft/stargate/portal/GateHandler.java b/src/main/java/net/knarcraft/stargate/portal/GateHandler.java index 3b5d700..b85f77c 100644 --- a/src/main/java/net/knarcraft/stargate/portal/GateHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/GateHandler.java @@ -378,7 +378,7 @@ public class GateHandler { } if (files == null || files.length == 0) { - //The gates folder was not found. Assume this is the first run + //The gates-folder was not found. Assume this is the first run if (directory.mkdir()) { populateDefaults(gateFolder); } diff --git a/src/main/java/net/knarcraft/stargate/portal/Portal.java b/src/main/java/net/knarcraft/stargate/portal/Portal.java index 0a635ae..8dc9afd 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Portal.java +++ b/src/main/java/net/knarcraft/stargate/portal/Portal.java @@ -78,30 +78,24 @@ public class Portal { * @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) { + Portal(PortalLocation portalLocation, BlockLocation button, String destination, String name, String network, + Gate gate, UUID ownerUUID, String ownerName, Map options) { this.location = portalLocation; this.destination = destination; this.button = button; - this.verified = verified; + this.verified = false; this.network = network; this.name = name; this.gate = gate; this.ownerUUID = ownerUUID; this.ownerName = ownerName; this.options = new PortalOptions(options, destination.length() > 0); - - if (verified) { - this.drawSign(); - } } /** @@ -145,6 +139,7 @@ public class Portal { * * @param network

The new network for this gate

*/ + @SuppressWarnings("unused") public void setNetwork(String network) { this.network = network; } @@ -172,6 +167,7 @@ public class Portal { * * @param name

The new name of this portal

*/ + @SuppressWarnings("unused") public void setName(String name) { this.name = filterName(name); drawSign(); @@ -275,6 +271,7 @@ public class Portal { * * @param owner

The new UUID of this portal's owner

*/ + @SuppressWarnings("unused") public void setOwner(UUID owner) { this.ownerUUID = owner; } @@ -348,24 +345,22 @@ public class Portal { * Open this portal * * @param force

Whether to force this portal open, even if it's already open for some player

- * @return

True if the portal was opened

*/ - public boolean open(boolean force) { - return open(null, force); + public void open(boolean force) { + open(null, force); } /** * Open this portal * * @param force

Whether to force this portal open, even if it's already open for some player

- * @return

True if the portal was opened

*/ - public boolean open(Player openFor, boolean force) { + public void open(Player openFor, boolean force) { //Call the StargateOpenEvent StargateOpenEvent event = new StargateOpenEvent(openFor, this, force); Stargate.server.getPluginManager().callEvent(event); if (event.isCancelled() || (isOpen() && !event.getForce())) { - return false; + return; } //Change the opening blocks to the correct type @@ -376,7 +371,6 @@ public class Portal { } updatePortalOpenState(openFor); - return true; } /** @@ -401,7 +395,9 @@ public class Portal { destination.getDestinationName().equalsIgnoreCase(getName())) && !destination.isOpen()) { destination.open(openFor, false); destination.setDestination(this); - if (destination.isVerified()) destination.drawSign(); + if (destination.isVerified()) { + destination.drawSign(); + } } } } @@ -636,9 +632,11 @@ public class Portal { RelativeBlockVector relativeExit = gate.getLayout().getExit(); if (relativeExit != null) { BlockLocation exit = getBlockAt(relativeExit); - int back = (options.isBackwards()) ? -1 : 1; - exitLocation = exit.modRelativeLoc(0D, 0D, 1, traveller.getYaw(), - traveller.getPitch(), getModX() * back, 1, getModZ() * back); + float yaw = traveller.getYaw(); + if (options.isBackwards()) { + yaw += 180; + } + exitLocation = exit.getRelativeLocation(0D, 0D, 1, this.getYaw(), yaw); if (entity != null) { double entitySize = EntityHelper.getEntityMaxSize(entity); @@ -791,24 +789,6 @@ public class Portal { return this.location.getSignLocation(); } - /** - * Gets the x modifier used by this portal - * - * @return

The x modifier used by this portal

- */ - public int getModX() { - return this.location.getModX(); - } - - /** - * Gets the z modifier used by this portal - * - * @return

The z modifier used by this portal

- */ - public int getModZ() { - return this.location.getModZ(); - } - /** * Gets the rotation of this portal * @@ -864,7 +844,7 @@ public class Portal { if (!Stargate.verifyPortals) { return true; } - return gate.matches(getTopLeft(), getModX(), getModZ()); + return gate.matches(getTopLeft(), getYaw()); } /** @@ -1014,7 +994,7 @@ public class Portal { * @return

The block at the given relative position

*/ public BlockLocation getBlockAt(RelativeBlockVector vector) { - return DirectionHelper.getBlockAt(getTopLeft(), vector, getModX(), getModZ()); + return DirectionHelper.getBlockAt(getTopLeft(), vector, getYaw()); } /** diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalDirection.java b/src/main/java/net/knarcraft/stargate/portal/PortalDirection.java deleted file mode 100644 index d6bbb4a..0000000 --- a/src/main/java/net/knarcraft/stargate/portal/PortalDirection.java +++ /dev/null @@ -1,6 +0,0 @@ -package net.knarcraft.stargate.portal; - -public class PortalDirection { - - -} diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java index 6336838..c11f5e1 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java @@ -20,7 +20,6 @@ import org.bukkit.block.data.Directional; import org.bukkit.block.data.type.WallSign; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.util.Vector; import java.io.BufferedWriter; import java.io.File; @@ -245,6 +244,7 @@ public class PortalHandler { //Return early if the sign is not placed on a block, or the block is not a control block if (idParent == null || GateHandler.getGatesByControlBlock(idParent).length == 0) { + Stargate.debug("createPortal", "Control block not registered"); return null; } @@ -269,14 +269,10 @@ public class PortalHandler { //Get the direction the button should be facing BlockFace buttonFacing = DirectionHelper.getBlockFaceFromYaw(yaw); - //Get the x and z modifiers - Vector direction = DirectionHelper.getDirectionVectorFromYaw(yaw); - //TODO: Figure out how modX and modZ really works and simplify it - int modX = -direction.getBlockZ(); - int modZ = direction.getBlockX(); - PortalLocation portalLocation = new PortalLocation(); - portalLocation.setButtonFacing(buttonFacing).setYaw(yaw).setModX(modX).setModZ(modZ).setSignLocation(signLocation); + portalLocation.setButtonFacing(buttonFacing).setYaw(yaw).setSignLocation(signLocation); + + Stargate.debug("createPortal", "Finished getting all portal info"); //Try and find a gate matching the new portal Gate gate = findMatchingGate(portalLocation, player); @@ -287,6 +283,7 @@ public class PortalHandler { //If the portal is a bungee portal and invalid, abort here if (!isValidBungeePortal(portalOptions, player, destinationName, network)) { + Stargate.debug("createPortal", "Portal is an invalid bungee portal"); return null; } @@ -344,7 +341,7 @@ public class PortalHandler { } //Check if a conflict exists - if (conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), modX, modZ, player)) { + if (conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), yaw, player)) { return null; } @@ -392,8 +389,7 @@ public class PortalHandler { //Get all gates with the used type of control blocks Gate[] possibleGates = GateHandler.getGatesByControlBlock(signParent); - int modX = portalLocation.getModX(); - int modZ = portalLocation.getModZ(); + double yaw = portalLocation.getYaw(); Gate gate = null; for (Gate possibleGate : possibleGates) { @@ -403,9 +399,8 @@ public class PortalHandler { portalLocation.setButtonVector(null); for (RelativeBlockVector controlVector : vectors) { //Assuming the top-left location is pointing to the gate's top-left location, check if it's a match - BlockLocation possibleTopLocation = parent.modRelative(-controlVector.getRight(), - -controlVector.getDepth(), -controlVector.getDistance(), modX, 1, modZ); - if (possibleGate.matches(possibleTopLocation, modX, modZ, true)) { + BlockLocation possibleTopLocation = parent.getRelativeLocation(controlVector.invert(), yaw); + if (possibleGate.matches(possibleTopLocation, portalLocation.getYaw(), true)) { gate = possibleGate; portalLocation.setTopLeft(possibleTopLocation); } else { @@ -422,19 +417,16 @@ public class PortalHandler { * * @param gate

The gate type of the new portal

* @param topLeft

The top-left block of the new portal

- * @param modX

The x-modifier for the new portal

- * @param modZ

The new z-modifier for the new portal

+ * @param yaw

The yaw when looking directly outwards from the portal

* @param player

The player creating the new portal

* @return

True if a conflict was found. False otherwise

*/ - private static boolean conflictsWithExistingPortal(Gate gate, BlockLocation topLeft, int modX, int modZ, - Player player) { + private static boolean conflictsWithExistingPortal(Gate gate, BlockLocation topLeft, double yaw, Player player) { //TODO: Make a quicker check. Could just check for control block conflicts if all code is changed to account for // getting several hits at a single location when checking for the existence of a portal. May make // everything slower overall? Would make for cooler gates though. for (RelativeBlockVector borderVector : gate.getLayout().getBorder()) { - BlockLocation borderBlockLocation = topLeft.modRelative(borderVector.getRight(), borderVector.getDepth(), - borderVector.getDistance(), modX, 1, modZ); + BlockLocation borderBlockLocation = topLeft.getRelativeLocation(borderVector, yaw); if (getByBlock(borderBlockLocation.getBlock()) != null) { Stargate.debug("createPortal", "Gate conflicts with existing gate"); Stargate.sendErrorMessage(player, Stargate.getString("createConflict")); @@ -463,7 +455,7 @@ public class PortalHandler { Map portalOptions, String denyMessage, String[] lines, boolean deny) { Portal portal = new Portal(portalLocation, null, destinationName, portalName, - false, network, gate, player.getUniqueId(), player.getName(), portalOptions); + network, gate, player.getUniqueId(), player.getName(), portalOptions); int createCost = EconomyHandler.getCreateCost(player, gate); @@ -569,8 +561,10 @@ public class PortalHandler { */ private static void generatePortalButton(Portal portal, BlockLocation topLeft, RelativeBlockVector buttonVector, BlockFace buttonFacing) { - BlockLocation button = topLeft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), - buttonVector.getDistance() + 1, portal.getModX(), 1, portal.getModZ()); + //Go one block outwards to find the button's location rather than the control block's location + BlockLocation button = topLeft.getRelativeLocation(buttonVector.addToVector( + RelativeBlockVector.Property.DISTANCE, 1), portal.getYaw()); + Directional buttonData = (Directional) Bukkit.createBlockData(portal.getGate().getPortalButton()); buttonData.setFacing(buttonFacing); button.getBlock().setBlockData(buttonData); @@ -724,15 +718,15 @@ public class PortalHandler { adjacentPositions.add(centerLocation); for (int index = 1; index <= range; index++) { - adjacentPositions.add(centerLocation.makeRelative(index, 0, 0)); - adjacentPositions.add(centerLocation.makeRelative(-index, 0, 0)); - adjacentPositions.add(centerLocation.makeRelative(0, 0, index)); - adjacentPositions.add(centerLocation.makeRelative(0, 0, -index)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, 0)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, 0)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, index)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, -index)); if (index < range) { - adjacentPositions.add(centerLocation.makeRelative(index, 0, index)); - adjacentPositions.add(centerLocation.makeRelative(-index, 0, -index)); - adjacentPositions.add(centerLocation.makeRelative(index, 0, -index)); - adjacentPositions.add(centerLocation.makeRelative(-index, 0, index)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, index)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, -index)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, -index)); + adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, index)); } } @@ -796,8 +790,8 @@ public class PortalHandler { builder.append(portal.getName()).append(':'); builder.append(portal.getSignLocation().toString()).append(':'); builder.append((button != null) ? button.toString() : "").append(':'); - builder.append(portal.getModX()).append(':'); - builder.append(portal.getModZ()).append(':'); + builder.append(0).append(':'); + builder.append(0).append(':'); builder.append(portal.getYaw()).append(':'); builder.append(portal.getTopLeft().toString()).append(':'); builder.append(portal.getGate().getFilename()).append(':'); @@ -958,8 +952,6 @@ public class PortalHandler { PortalLocation portalLocation = new PortalLocation(); portalLocation.setSignLocation(new BlockLocation(world, portalData[1])); BlockLocation button = (portalData[2].length() > 0) ? new BlockLocation(world, portalData[2]) : null; - portalLocation.setModX(Integer.parseInt(portalData[3])); - portalLocation.setModZ(Integer.parseInt(portalData[4])); portalLocation.setYaw(Float.parseFloat(portalData[5])); portalLocation.setTopLeft(new BlockLocation(world, portalData[6])); Gate gate = GateHandler.getGateByName(portalData[7]); @@ -995,7 +987,7 @@ public class PortalHandler { } //Creates the new portal - Portal portal = new Portal(portalLocation, button, destination, name, false, + Portal portal = new Portal(portalLocation, button, destination, name, network, gate, ownerUUID, ownerName, getPortalOptions(portalData)); registerPortal(portal); diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java b/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java index 8c0da51..32d5e51 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalLocation.java @@ -9,11 +9,10 @@ import org.bukkit.block.BlockFace; /** * Keeps track of location related data for a portal */ +@SuppressWarnings("UnusedReturnValue") public class PortalLocation { private BlockLocation topLeft; - private int modX; - private int modZ; private float yaw; private BlockLocation signLocation; private RelativeBlockVector buttonVector; @@ -28,24 +27,6 @@ public class PortalLocation { return topLeft; } - /** - * Gets the x-modifier for the portal - * - * @return

The x-modifier for the portal

- */ - public int getModX() { - return modX; - } - - /** - * Gets the z-modifier for the portal - * - * @return

The z-modifier for the portal

- */ - public int getModZ() { - return modZ; - } - /** * Gets the yaw for looking outwards from the portal * @@ -115,28 +96,6 @@ public class PortalLocation { return this; } - /** - * Sets the portal's x-modifier - * - * @param modX

The portal's new x-modifier

- * @return

The portal location Object

- */ - public PortalLocation setModX(int modX) { - this.modX = modX; - return this; - } - - /** - * Sets the portal's z-modifier - * - * @param modZ

The portal's new z-modifier

- * @return

The portal location Object

- */ - public PortalLocation setModZ(int modZ) { - this.modZ = modZ; - return this; - } - /** * Sets the portal's yaw * diff --git a/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java b/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java index a894503..1137b08 100644 --- a/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java @@ -125,7 +125,7 @@ public final class BungeeHelper { Stargate.bungeeQueue.put(playerName.toLowerCase(), destination); } else { Portal destinationPortal = PortalHandler.getBungeePortal(destination); - // Specified an invalid gate. For now we'll just let them connect at their current location + // Specified an invalid gate. For now, we'll just let them connect at their current location if (destinationPortal == null) { Stargate.logger.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist"); return; diff --git a/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java b/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java index aec2874..c0f3132 100644 --- a/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java @@ -7,7 +7,7 @@ import org.bukkit.block.BlockFace; import org.bukkit.util.Vector; /** - * This class helps with direction-dependent (modX, modZ) calculations + * This class helps with direction-dependent calculations */ public final class DirectionHelper { @@ -81,7 +81,7 @@ public final class DirectionHelper { } else if (yaw == 270) { return new Vector(1, 0, 0); } else { - throw new IllegalArgumentException("Invalid yaw given"); + throw new IllegalArgumentException(String.format("Invalid yaw %f given", yaw)); } } @@ -97,16 +97,6 @@ public final class DirectionHelper { return topLeft.getRelativeLocation(vector, yaw); } - /** - * Gets the block at a relative block vector location - * - * @param vector

The relative block vector

- * @return

The block at the given relative position

- */ - public static BlockLocation getBlockAt(BlockLocation topLeft, RelativeBlockVector vector, int modX, int modZ) { - return topLeft.modRelative(vector.getRight(), vector.getDepth(), vector.getDistance(), modX, 1, modZ); - } - /** * Moves a location relatively * diff --git a/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java b/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java index 31519ef..2b0d34b 100644 --- a/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java @@ -39,7 +39,7 @@ public final class EconomyHelper { return false; } - //Send the deduct message to the player + //Send the deduct-message to the player sendDeductMessage(entrancePortal.getName(), player, cost); if (entrancePortal.getGate().getToOwner()) { diff --git a/src/test/java/net/knarcraft/stargate/BlockLocationTest.java b/src/test/java/net/knarcraft/stargate/BlockLocationTest.java index 8dd6426..0935057 100644 --- a/src/test/java/net/knarcraft/stargate/BlockLocationTest.java +++ b/src/test/java/net/knarcraft/stargate/BlockLocationTest.java @@ -62,7 +62,7 @@ public class BlockLocationTest { @Test public void makeRelativeTest() { BlockLocation location = new BlockLocation(mockWorld, 3, 7, 19); - BlockLocation newLocation = location.makeRelative(34, 65, 75); + BlockLocation newLocation = location.makeRelativeBlockLocation(34, 65, 75); assertEquals(37, newLocation.getBlockX()); assertEquals(72, newLocation.getBlockY()); assertEquals(94, newLocation.getBlockZ()); @@ -82,13 +82,4 @@ public class BlockLocationTest { assertEquals("56,87,34", location.toString()); } - @Test - public void modRelativeTest() { - BlockLocation location = new BlockLocation(mockWorld, 5, 5, 5); - BlockLocation relativeLocation = location.modRelative(4, 2, 1, -1, 1, 0); - assertEquals(9, relativeLocation.getBlockX()); - assertEquals(3, relativeLocation.getBlockY()); - assertEquals(6, relativeLocation.getBlockZ()); - } - }