Gets rid of the rest of the modX and modY usages, and removes some unused code

This commit is contained in:
Kristian Knarvik 2021-10-08 18:23:42 +02:00
parent a68dc4b464
commit fff4d8d78b
20 changed files with 150 additions and 279 deletions

View File

@ -229,12 +229,16 @@ public class LanguageLoader {
public void debug() { public void debug() {
Set<String> keys = loadedStringTranslations.keySet(); Set<String> keys = loadedStringTranslations.keySet();
for (String key : keys) { 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(); keys = loadedBackupStrings.keySet();
for (String key : keys) { for (String key : keys) {
Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", key + " => " + loadedBackupStrings.get(key)); Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", key + " => " +
loadedBackupStrings.get(key));
} }
} }

View File

@ -322,6 +322,9 @@ public class Stargate extends JavaPlugin {
// It is important to load languages here, as they are used during reloadGates() // It is important to load languages here, as they are used during reloadGates()
languageLoader = new LanguageLoader(languageFolder, Stargate.languageName); languageLoader = new LanguageLoader(languageFolder, Stargate.languageName);
if (debuggingEnabled) {
languageLoader.debug();
}
this.createMissingFolders(); this.createMissingFolders();
this.loadGates(); this.loadGates();

View File

@ -8,9 +8,9 @@ import org.bukkit.Material;
*/ */
public class BlockChangeRequest { public class BlockChangeRequest {
private BlockLocation blockLocation; private final BlockLocation blockLocation;
private Material newMaterial; private final Material newMaterial;
private Axis newAxis; private final Axis newAxis;
/** /**
* Instantiates a new block change request * Instantiates a new block change request
@ -34,15 +34,6 @@ public class BlockChangeRequest {
return blockLocation; return blockLocation;
} }
/**
* Sets the location of the block
*
* @param blockLocation <p>The new location of the block</p>
*/
public void setBlockLocation(BlockLocation blockLocation) {
this.blockLocation = blockLocation;
}
/** /**
* Gets the material to change the block into * Gets the material to change the block into
* *
@ -52,15 +43,6 @@ public class BlockChangeRequest {
return newMaterial; return newMaterial;
} }
/**
* Sets the material to change the block into
*
* @param material <p>The new material</p>
*/
public void setMaterial(Material material) {
newMaterial = material;
}
/** /**
* Gets the axis to orient the block along * Gets the axis to orient the block along
* *
@ -70,13 +52,4 @@ public class BlockChangeRequest {
return newAxis; return newAxis;
} }
/**
* Sets the axis to orient the block along
*
* @param axis <p>The new axis to orient the block along</p>
*/
public void setAxis(Axis axis) {
newAxis = axis;
}
} }

View File

@ -62,73 +62,53 @@ public class BlockLocation extends Location {
* @param z <p>The z position relative to this block's position</p> * @param z <p>The z position relative to this block's position</p>
* @return <p>A new block location</p> * @return <p>A new block location</p>
*/ */
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); return (BlockLocation) this.clone().add(x, y, z);
} }
/** /**
* Makes a location relative to the block location * Makes a location relative to the block location
* *
* @param x <p>The x position relative to this block's position</p> * @param x <p>The x position relative to this block's position</p>
* @param y <p>The y position relative to this block's position</p> * @param y <p>The y position relative to this block's position</p>
* @param z <p>The z position relative to this block's position</p> * @param z <p>The z position relative to this block's position</p>
* @param yaw <p>The yaw of the location</p> * @param yaw <p>The yaw of the location</p>
* @param rotY <p>The y rotation of the location</p>
* @return <p>A new location</p> * @return <p>A new location</p>
*/ */
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(); Location newLocation = this.clone();
newLocation.setYaw(yaw); newLocation.setYaw(yaw);
newLocation.setPitch(rotY); newLocation.setPitch(0);
return newLocation.add(x, y, z); return newLocation.add(x, y, z);
} }
/** /**
* Gets a location relative to this block location * Gets a location relative to this block location
* *
* @param vector <p>The relative block vector describing the relative location</p> * @param relativeVector <p>The relative block vector describing the relative location</p>
* @param yaw <p>The yaw pointing in the distance direction</p> * @param yaw <p>The yaw pointing in the distance direction</p>
* @return <p>A location relative to this location</p> * @return <p>A location relative to this location</p>
*/ */
public BlockLocation getRelativeLocation(RelativeBlockVector vector, double yaw) { public BlockLocation getRelativeLocation(RelativeBlockVector relativeVector, double yaw) {
Vector combined = DirectionHelper.getCoordinateVectorFromRelativeVector(vector.getRight(), vector.getDepth(), Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(relativeVector.getRight(),
vector.getDistance(), yaw); relativeVector.getDepth(), relativeVector.getDistance(), yaw);
return makeRelative(combined.getBlockX(), combined.getBlockY(), combined.getBlockZ()); return makeRelativeBlockLocation(realVector.getBlockX(), realVector.getBlockY(), realVector.getBlockZ());
}
/**
* Makes a block location relative to the current origin according to given parameters
*
* <p>See {@link RelativeBlockVector} to understand better. modX or modZ should always be 0 while the other is 1
* or -1.</p>
*
* @param right <p>The amount of right steps from the top-left origin</p>
* @param depth <p>The amount of downward steps from the top-left origin</p>
* @param distance <p>The distance outward from the top-left origin</p>
* @param modX <p>X modifier. If modX = -1, X will increase as right increases</p>
* @param modY <p>Y modifier. modY = 1 for Y decreasing as depth increases</p>
* @param modZ <p>Z modifier. If modZ = 1, X will increase as distance increases</p>
* @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);
} }
/** /**
* Makes a location relative to the current location according to given parameters * Makes a location relative to the current location according to given parameters
* *
* @param right <p></p> * @param right <p>The amount of blocks to go right when looking the opposite direction from the yaw</p>
* @param depth <p>The y position relative to the current position</p> * @param depth <p>The amount of blocks to go downwards when looking the opposite direction from the yaw</p>
* @param distance <p>The distance away from the previous location to the new location</p> * @param distance <p>The amount of blocks to go outwards when looking the opposite direction from the yaw</p>
* @param yaw <p>The yaw of the location</p> * @param portalYaw <p>The yaw when looking out from the portal</p>
* @param rotY <p>Unused</p> * @param yaw <p>The yaw of the travelling entity</p>
* @param modX <p>x modifier. Defines movement along the x-axis. 0 for no movement</p>
* @param modY <p>Unused</p>
* @param modZ <p>z modifier. Defines movement along the z-axis. 0 for no movement</p>
* @return A new location relative to this block location * @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) { public Location getRelativeLocation(double right, double depth, double distance, float portalYaw, float yaw) {
return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, yaw, 0); 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 { } else {
return; return;
} }
parent = this.makeRelative(offsetX, offsetY, offsetZ); parent = this.makeRelativeBlockLocation(offsetX, offsetY, offsetZ);
} }
@Override @Override

View File

@ -14,6 +14,8 @@ public class RelativeBlockVector {
private final int depth; private final int depth;
private final int distance; private final int distance;
public enum Property {RIGHT, DEPTH, DISTANCE}
/** /**
* Instantiates a new relative block vector * Instantiates a new relative block vector
* *
@ -27,6 +29,35 @@ public class RelativeBlockVector {
this.distance = distance; this.distance = distance;
} }
/**
* Adds a value to one of the properties of this relative block vector
*
* @param propertyToAddTo <p>The property to change</p>
* @param valueToAdd <p>The value to add to the property</p>
* @return <p>A new relative block vector with the property altered</p>
*/
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 <p>This vector, but inverted</p>
*/
public RelativeBlockVector invert() {
return new RelativeBlockVector(-this.right, -this.depth, -this.distance);
}
/** /**
* Gets the distance to the right relative to the origin * Gets the distance to the right relative to the origin
* *

View File

@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
/** /**
* This event should be called whenever a player opens a stargate * This event should be called whenever a player opens a stargate
*/ */
@SuppressWarnings({"unused"})
public class StargateOpenEvent extends StargatePlayerEvent { public class StargateOpenEvent extends StargatePlayerEvent {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
/** /**
* An abstract event describing any stargate event where a player is involved * An abstract event describing any stargate event where a player is involved
*/ */
@SuppressWarnings("unused")
public abstract class StargatePlayerEvent extends StargateEvent { public abstract class StargatePlayerEvent extends StargateEvent {
private final Player player; private final Player player;

View File

@ -41,9 +41,9 @@ public class StargatePortalEvent extends StargatePlayerEvent {
} }
/** /**
* Return the destination gate * Return the destination portal
* *
* @return destination gate * @return <p>The destination portal</p>
*/ */
public Portal getDestination() { public Portal getDestination() {
return destination; return destination;
@ -52,14 +52,14 @@ public class StargatePortalEvent extends StargatePlayerEvent {
/** /**
* Return the location of the players exit point * Return the location of the players exit point
* *
* @return org.bukkit.Location Location of the exit point * @return <p>Location of the exit point</p>
*/ */
public Location getExit() { public Location getExit() {
return exit; return exit;
} }
/** /**
* Set the location of the players exit point * Set the location of the player's exit point
*/ */
public void setExit(Location loc) { public void setExit(Location loc) {
this.exit = loc; this.exit = loc;

View File

@ -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 <p>The event triggering the right-click</p> * @param event <p>The event triggering the right-click</p>
* @param player <p>The player doing the right-click</p> * @param player <p>The player doing the right-click</p>

View File

@ -15,7 +15,7 @@ import org.bukkit.event.world.WorldUnloadEvent;
public class WorldEventListener implements Listener { 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 <p>The triggered world load event</p> * @param event <p>The triggered world load event</p>
*/ */

View File

@ -26,8 +26,8 @@ public class Gate {
private final Map<Character, Material> types; private final Map<Character, Material> types;
//Gate materials //Gate materials
private Material portalOpenBlock; private final Material portalOpenBlock;
private Material portalClosedBlock; private final Material portalClosedBlock;
private final Material portalButton; private final Material portalButton;
// Economy information // Economy information
@ -74,15 +74,6 @@ public class Gate {
return layout; return layout;
} }
/**
* Gets the material types each layout character represents
*
* @return <p>The material types each layout character represents</p>
*/
public Map<Character, Material> getTypes() {
return types;
}
/** /**
* Gets the material type used for this gate's control blocks * Gets the material type used for this gate's control blocks
* *
@ -110,15 +101,6 @@ public class Gate {
return portalOpenBlock; return portalOpenBlock;
} }
/**
* Sets the block to use for the opening when a portal using this gate is open
*
* @param type <p>The block type to use for the opening when open</p>
*/
public void setPortalOpenBlock(Material type) {
portalOpenBlock = type;
}
/** /**
* Gets the block type to use for the opening when a portal using this gate is closed * 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; return portalClosedBlock;
} }
/**
* Sets the block type to use for the opening when a portal using this gate is closed
*
* @param type <p>The block type to use for the opening when closed</p>
*/
public void setPortalClosedBlock(Material type) {
portalClosedBlock = type;
}
/** /**
* Gets the material to use for a portal's button if using this gate 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 * Checks whether a portal's gate matches this gate type
* *
* @param topLeft <p>The top-left block of the portal's gate</p> * @param topLeft <p>The top-left block of the portal's gate</p>
* @param modX <p>The x modifier used</p> * @param yaw <p>The yaw when looking directly outwards</p>
* @param modZ <p>The z modifier used</p>
* @return <p>True if this gate matches the portal</p> * @return <p>True if this gate matches the portal</p>
*/ */
public boolean matches(BlockLocation topLeft, int modX, int modZ) { public boolean matches(BlockLocation topLeft, double yaw) {
return matches(topLeft, modX, modZ, false); return matches(topLeft, yaw, false);
} }
/** /**
* Checks whether a portal's gate matches this gate type * Checks whether a portal's gate matches this gate type
* *
* @param topLeft <p>The top-left block of the portal's gate</p> * @param topLeft <p>The top-left block of the portal's gate</p>
* @param modX <p>The x modifier used</p> * @param yaw <p>The yaw when looking directly outwards</p>
* @param modZ <p>The z modifier used</p>
* @param onCreate <p>Whether this is used in the context of creating a new gate</p> * @param onCreate <p>Whether this is used in the context of creating a new gate</p>
* @return <p>True if this gate matches the portal</p> * @return <p>True if this gate matches the portal</p>
*/ */
public boolean matches(BlockLocation topLeft, int modX, int modZ, boolean onCreate) { public boolean matches(BlockLocation topLeft, double yaw, boolean onCreate) {
return verifyGateEntrancesMatch(topLeft, modX, modZ, onCreate) && verifyGateBorderMatches(topLeft, modX, modZ); return verifyGateEntrancesMatch(topLeft, yaw, onCreate) && verifyGateBorderMatches(topLeft, yaw);
} }
/** /**
* Verifies that all border blocks of a portal gate matches this gate type * Verifies that all border blocks of a portal gate matches this gate type
* *
* @param topLeft <p>The top-left block of the portal</p> * @param topLeft <p>The top-left block of the portal</p>
* @param modX <p>The x modifier used</p> * @param yaw <p>The yaw when looking directly outwards</p>
* @param modZ <p>The z modifier used</p>
* @return <p>True if all border blocks of the gate match the layout</p> * @return <p>True if all border blocks of the gate match the layout</p>
*/ */
private boolean verifyGateBorderMatches(BlockLocation topLeft, int modX, int modZ) { private boolean verifyGateBorderMatches(BlockLocation topLeft, double yaw) {
Map<Character, Material> portalTypes = new HashMap<>(types); Map<Character, Material> portalTypes = new HashMap<>(types);
for (RelativeBlockVector borderVector : layout.getBorder()) { for (RelativeBlockVector borderVector : layout.getBorder()) {
int rowIndex = borderVector.getRight(); int rowIndex = borderVector.getRight();
@ -223,7 +193,7 @@ public class Gate {
Character key = layout.getLayout()[lineIndex][rowIndex]; Character key = layout.getLayout()[lineIndex][rowIndex];
Material materialInLayout = portalTypes.get(key); Material materialInLayout = portalTypes.get(key);
Material materialAtLocation = getBlockAt(topLeft, borderVector, modX, modZ).getType(); Material materialAtLocation = getBlockAt(topLeft, borderVector, yaw).getType();
if (materialInLayout == null) { if (materialInLayout == null) {
portalTypes.put(key, materialAtLocation); portalTypes.put(key, materialAtLocation);
} else if (materialAtLocation != materialInLayout) { } else if (materialAtLocation != materialInLayout) {
@ -239,19 +209,20 @@ public class Gate {
* Verifies that all entrances of a portal gate matches this gate type * Verifies that all entrances of a portal gate matches this gate type
* *
* @param topLeft <p>The top-left block of this portal</p> * @param topLeft <p>The top-left block of this portal</p>
* @param modX <p>The x modifier used</p> * @param yaw <p>The yaw when looking directly outwards</p>
* @param modZ <p>The z modifier used</p>
* @param onCreate <p>Whether this is used in the context of creating a new gate</p> * @param onCreate <p>Whether this is used in the context of creating a new gate</p>
* @return <p>Whether this is used in the context of creating a new gate</p> * @return <p>Whether this is used in the context of creating a new gate</p>
*/ */
private boolean verifyGateEntrancesMatch(BlockLocation topLeft, int modX, int modZ, boolean onCreate) { private boolean verifyGateEntrancesMatch(BlockLocation topLeft, double yaw, boolean onCreate) {
if (Stargate.ignoreEntrance) { if (Stargate.ignoreEntrance) {
return true; return true;
} }
Stargate.debug("verifyGateEntrancesMatch", String.valueOf(topLeft));
for (RelativeBlockVector entranceVector : layout.getEntrances()) { 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) { if (onCreate && type == Material.AIR) {
continue; continue;
} }
@ -270,8 +241,8 @@ public class Gate {
* @param vector <p>The relative block vector</p> * @param vector <p>The relative block vector</p>
* @return <p>The block at the given relative position</p> * @return <p>The block at the given relative position</p>
*/ */
private BlockLocation getBlockAt(BlockLocation topLeft, RelativeBlockVector vector, int modX, int modZ) { private BlockLocation getBlockAt(BlockLocation topLeft, RelativeBlockVector vector, double yaw) {
return DirectionHelper.getBlockAt(topLeft, vector, modX, modZ); return DirectionHelper.getBlockAt(topLeft, vector, yaw);
} }
/** /**
@ -371,6 +342,7 @@ public class Gate {
* @param value <p>The value of the config key</p> * @param value <p>The value of the config key</p>
* @throws IOException <p>If unable to write to the buffered writer</p> * @throws IOException <p>If unable to write to the buffered writer</p>
*/ */
@SuppressWarnings("SameParameterValue")
private void writeConfig(BufferedWriter bufferedWriter, String key, boolean value) throws IOException { private void writeConfig(BufferedWriter bufferedWriter, String key, boolean value) throws IOException {
writeConfig(bufferedWriter, "%s=%b", key, value); writeConfig(bufferedWriter, "%s=%b", key, value);
} }

View File

@ -378,7 +378,7 @@ public class GateHandler {
} }
if (files == null || files.length == 0) { 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()) { if (directory.mkdir()) {
populateDefaults(gateFolder); populateDefaults(gateFolder);
} }

View File

@ -78,30 +78,24 @@ public class Portal {
* @param button <p>The location of the portal's open button</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 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 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 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 gate <p>The gate template this portal uses</p>
* @param ownerUUID <p>The UUID of the gate's owner</p> * @param ownerUUID <p>The UUID of the gate's owner</p>
* @param ownerName <p>The name 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 options <p>A map containing all possible portal options</p>
*/ */
Portal(PortalLocation portalLocation, BlockLocation button, Portal(PortalLocation portalLocation, BlockLocation button, String destination, String name, String network,
String destination, String name, boolean verified, String network, Gate gate, UUID ownerUUID, Gate gate, UUID ownerUUID, String ownerName, Map<PortalOption, Boolean> options) {
String ownerName, Map<PortalOption, Boolean> options) {
this.location = portalLocation; this.location = portalLocation;
this.destination = destination; this.destination = destination;
this.button = button; this.button = button;
this.verified = verified; this.verified = false;
this.network = network; this.network = network;
this.name = name; this.name = name;
this.gate = gate; this.gate = gate;
this.ownerUUID = ownerUUID; this.ownerUUID = ownerUUID;
this.ownerName = ownerName; this.ownerName = ownerName;
this.options = new PortalOptions(options, destination.length() > 0); this.options = new PortalOptions(options, destination.length() > 0);
if (verified) {
this.drawSign();
}
} }
/** /**
@ -145,6 +139,7 @@ public class Portal {
* *
* @param network <p>The new network for this gate</p> * @param network <p>The new network for this gate</p>
*/ */
@SuppressWarnings("unused")
public void setNetwork(String network) { public void setNetwork(String network) {
this.network = network; this.network = network;
} }
@ -172,6 +167,7 @@ public class Portal {
* *
* @param name <p>The new name of this portal</p> * @param name <p>The new name of this portal</p>
*/ */
@SuppressWarnings("unused")
public void setName(String name) { public void setName(String name) {
this.name = filterName(name); this.name = filterName(name);
drawSign(); drawSign();
@ -275,6 +271,7 @@ public class Portal {
* *
* @param owner <p>The new UUID of this portal's owner</p> * @param owner <p>The new UUID of this portal's owner</p>
*/ */
@SuppressWarnings("unused")
public void setOwner(UUID owner) { public void setOwner(UUID owner) {
this.ownerUUID = owner; this.ownerUUID = owner;
} }
@ -348,24 +345,22 @@ public class Portal {
* Open this portal * Open this portal
* *
* @param force <p>Whether to force this portal open, even if it's already open for some player</p> * @param force <p>Whether to force this portal open, even if it's already open for some player</p>
* @return <p>True if the portal was opened</p>
*/ */
public boolean open(boolean force) { public void open(boolean force) {
return open(null, force); open(null, force);
} }
/** /**
* Open this portal * Open this portal
* *
* @param force <p>Whether to force this portal open, even if it's already open for some player</p> * @param force <p>Whether to force this portal open, even if it's already open for some player</p>
* @return <p>True if the portal was opened</p>
*/ */
public boolean open(Player openFor, boolean force) { public void open(Player openFor, boolean force) {
//Call the StargateOpenEvent //Call the StargateOpenEvent
StargateOpenEvent event = new StargateOpenEvent(openFor, this, force); StargateOpenEvent event = new StargateOpenEvent(openFor, this, force);
Stargate.server.getPluginManager().callEvent(event); Stargate.server.getPluginManager().callEvent(event);
if (event.isCancelled() || (isOpen() && !event.getForce())) { if (event.isCancelled() || (isOpen() && !event.getForce())) {
return false; return;
} }
//Change the opening blocks to the correct type //Change the opening blocks to the correct type
@ -376,7 +371,6 @@ public class Portal {
} }
updatePortalOpenState(openFor); updatePortalOpenState(openFor);
return true;
} }
/** /**
@ -401,7 +395,9 @@ public class Portal {
destination.getDestinationName().equalsIgnoreCase(getName())) && !destination.isOpen()) { destination.getDestinationName().equalsIgnoreCase(getName())) && !destination.isOpen()) {
destination.open(openFor, false); destination.open(openFor, false);
destination.setDestination(this); 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(); RelativeBlockVector relativeExit = gate.getLayout().getExit();
if (relativeExit != null) { if (relativeExit != null) {
BlockLocation exit = getBlockAt(relativeExit); BlockLocation exit = getBlockAt(relativeExit);
int back = (options.isBackwards()) ? -1 : 1; float yaw = traveller.getYaw();
exitLocation = exit.modRelativeLoc(0D, 0D, 1, traveller.getYaw(), if (options.isBackwards()) {
traveller.getPitch(), getModX() * back, 1, getModZ() * back); yaw += 180;
}
exitLocation = exit.getRelativeLocation(0D, 0D, 1, this.getYaw(), yaw);
if (entity != null) { if (entity != null) {
double entitySize = EntityHelper.getEntityMaxSize(entity); double entitySize = EntityHelper.getEntityMaxSize(entity);
@ -791,24 +789,6 @@ public class Portal {
return this.location.getSignLocation(); return this.location.getSignLocation();
} }
/**
* Gets the x modifier used by this portal
*
* @return <p>The x modifier used by this portal</p>
*/
public int getModX() {
return this.location.getModX();
}
/**
* Gets the z modifier used by this portal
*
* @return <p>The z modifier used by this portal</p>
*/
public int getModZ() {
return this.location.getModZ();
}
/** /**
* Gets the rotation of this portal * Gets the rotation of this portal
* *
@ -864,7 +844,7 @@ public class Portal {
if (!Stargate.verifyPortals) { if (!Stargate.verifyPortals) {
return true; return true;
} }
return gate.matches(getTopLeft(), getModX(), getModZ()); return gate.matches(getTopLeft(), getYaw());
} }
/** /**
@ -1014,7 +994,7 @@ public class Portal {
* @return <p>The block at the given relative position</p> * @return <p>The block at the given relative position</p>
*/ */
public BlockLocation getBlockAt(RelativeBlockVector vector) { public BlockLocation getBlockAt(RelativeBlockVector vector) {
return DirectionHelper.getBlockAt(getTopLeft(), vector, getModX(), getModZ()); return DirectionHelper.getBlockAt(getTopLeft(), vector, getYaw());
} }
/** /**

View File

@ -1,6 +0,0 @@
package net.knarcraft.stargate.portal;
public class PortalDirection {
}

View File

@ -20,7 +20,6 @@ import org.bukkit.block.data.Directional;
import org.bukkit.block.data.type.WallSign; import org.bukkit.block.data.type.WallSign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.util.Vector;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; 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 //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) { if (idParent == null || GateHandler.getGatesByControlBlock(idParent).length == 0) {
Stargate.debug("createPortal", "Control block not registered");
return null; return null;
} }
@ -269,14 +269,10 @@ public class PortalHandler {
//Get the direction the button should be facing //Get the direction the button should be facing
BlockFace buttonFacing = DirectionHelper.getBlockFaceFromYaw(yaw); 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 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 //Try and find a gate matching the new portal
Gate gate = findMatchingGate(portalLocation, player); Gate gate = findMatchingGate(portalLocation, player);
@ -287,6 +283,7 @@ public class PortalHandler {
//If the portal is a bungee portal and invalid, abort here //If the portal is a bungee portal and invalid, abort here
if (!isValidBungeePortal(portalOptions, player, destinationName, network)) { if (!isValidBungeePortal(portalOptions, player, destinationName, network)) {
Stargate.debug("createPortal", "Portal is an invalid bungee portal");
return null; return null;
} }
@ -344,7 +341,7 @@ public class PortalHandler {
} }
//Check if a conflict exists //Check if a conflict exists
if (conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), modX, modZ, player)) { if (conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), yaw, player)) {
return null; return null;
} }
@ -392,8 +389,7 @@ public class PortalHandler {
//Get all gates with the used type of control blocks //Get all gates with the used type of control blocks
Gate[] possibleGates = GateHandler.getGatesByControlBlock(signParent); Gate[] possibleGates = GateHandler.getGatesByControlBlock(signParent);
int modX = portalLocation.getModX(); double yaw = portalLocation.getYaw();
int modZ = portalLocation.getModZ();
Gate gate = null; Gate gate = null;
for (Gate possibleGate : possibleGates) { for (Gate possibleGate : possibleGates) {
@ -403,9 +399,8 @@ public class PortalHandler {
portalLocation.setButtonVector(null); portalLocation.setButtonVector(null);
for (RelativeBlockVector controlVector : vectors) { for (RelativeBlockVector controlVector : vectors) {
//Assuming the top-left location is pointing to the gate's top-left location, check if it's a match //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(), BlockLocation possibleTopLocation = parent.getRelativeLocation(controlVector.invert(), yaw);
-controlVector.getDepth(), -controlVector.getDistance(), modX, 1, modZ); if (possibleGate.matches(possibleTopLocation, portalLocation.getYaw(), true)) {
if (possibleGate.matches(possibleTopLocation, modX, modZ, true)) {
gate = possibleGate; gate = possibleGate;
portalLocation.setTopLeft(possibleTopLocation); portalLocation.setTopLeft(possibleTopLocation);
} else { } else {
@ -422,19 +417,16 @@ public class PortalHandler {
* *
* @param gate <p>The gate type of the new portal</p> * @param gate <p>The gate type of the new portal</p>
* @param topLeft <p>The top-left block of the new portal</p> * @param topLeft <p>The top-left block of the new portal</p>
* @param modX <p>The x-modifier for the new portal</p> * @param yaw <p>The yaw when looking directly outwards from the portal</p>
* @param modZ <p>The new z-modifier for the new portal</p>
* @param player <p>The player creating the new portal</p> * @param player <p>The player creating the new portal</p>
* @return <p>True if a conflict was found. False otherwise</p> * @return <p>True if a conflict was found. False otherwise</p>
*/ */
private static boolean conflictsWithExistingPortal(Gate gate, BlockLocation topLeft, int modX, int modZ, private static boolean conflictsWithExistingPortal(Gate gate, BlockLocation topLeft, double yaw, Player player) {
Player player) {
//TODO: Make a quicker check. Could just check for control block conflicts if all code is changed to account for //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 // 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. // everything slower overall? Would make for cooler gates though.
for (RelativeBlockVector borderVector : gate.getLayout().getBorder()) { for (RelativeBlockVector borderVector : gate.getLayout().getBorder()) {
BlockLocation borderBlockLocation = topLeft.modRelative(borderVector.getRight(), borderVector.getDepth(), BlockLocation borderBlockLocation = topLeft.getRelativeLocation(borderVector, yaw);
borderVector.getDistance(), modX, 1, modZ);
if (getByBlock(borderBlockLocation.getBlock()) != null) { if (getByBlock(borderBlockLocation.getBlock()) != null) {
Stargate.debug("createPortal", "Gate conflicts with existing gate"); Stargate.debug("createPortal", "Gate conflicts with existing gate");
Stargate.sendErrorMessage(player, Stargate.getString("createConflict")); Stargate.sendErrorMessage(player, Stargate.getString("createConflict"));
@ -463,7 +455,7 @@ public class PortalHandler {
Map<PortalOption, Boolean> portalOptions, String denyMessage, Map<PortalOption, Boolean> portalOptions, String denyMessage,
String[] lines, boolean deny) { String[] lines, boolean deny) {
Portal portal = new Portal(portalLocation, null, destinationName, portalName, 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); int createCost = EconomyHandler.getCreateCost(player, gate);
@ -569,8 +561,10 @@ public class PortalHandler {
*/ */
private static void generatePortalButton(Portal portal, BlockLocation topLeft, RelativeBlockVector buttonVector, private static void generatePortalButton(Portal portal, BlockLocation topLeft, RelativeBlockVector buttonVector,
BlockFace buttonFacing) { BlockFace buttonFacing) {
BlockLocation button = topLeft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), //Go one block outwards to find the button's location rather than the control block's location
buttonVector.getDistance() + 1, portal.getModX(), 1, portal.getModZ()); BlockLocation button = topLeft.getRelativeLocation(buttonVector.addToVector(
RelativeBlockVector.Property.DISTANCE, 1), portal.getYaw());
Directional buttonData = (Directional) Bukkit.createBlockData(portal.getGate().getPortalButton()); Directional buttonData = (Directional) Bukkit.createBlockData(portal.getGate().getPortalButton());
buttonData.setFacing(buttonFacing); buttonData.setFacing(buttonFacing);
button.getBlock().setBlockData(buttonData); button.getBlock().setBlockData(buttonData);
@ -724,15 +718,15 @@ public class PortalHandler {
adjacentPositions.add(centerLocation); adjacentPositions.add(centerLocation);
for (int index = 1; index <= range; index++) { for (int index = 1; index <= range; index++) {
adjacentPositions.add(centerLocation.makeRelative(index, 0, 0)); adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, 0));
adjacentPositions.add(centerLocation.makeRelative(-index, 0, 0)); adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, 0));
adjacentPositions.add(centerLocation.makeRelative(0, 0, index)); adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, index));
adjacentPositions.add(centerLocation.makeRelative(0, 0, -index)); adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, -index));
if (index < range) { if (index < range) {
adjacentPositions.add(centerLocation.makeRelative(index, 0, index)); adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, index));
adjacentPositions.add(centerLocation.makeRelative(-index, 0, -index)); adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, -index));
adjacentPositions.add(centerLocation.makeRelative(index, 0, -index)); adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, -index));
adjacentPositions.add(centerLocation.makeRelative(-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.getName()).append(':');
builder.append(portal.getSignLocation().toString()).append(':'); builder.append(portal.getSignLocation().toString()).append(':');
builder.append((button != null) ? button.toString() : "").append(':'); builder.append((button != null) ? button.toString() : "").append(':');
builder.append(portal.getModX()).append(':'); builder.append(0).append(':');
builder.append(portal.getModZ()).append(':'); builder.append(0).append(':');
builder.append(portal.getYaw()).append(':'); builder.append(portal.getYaw()).append(':');
builder.append(portal.getTopLeft().toString()).append(':'); builder.append(portal.getTopLeft().toString()).append(':');
builder.append(portal.getGate().getFilename()).append(':'); builder.append(portal.getGate().getFilename()).append(':');
@ -958,8 +952,6 @@ public class PortalHandler {
PortalLocation portalLocation = new PortalLocation(); PortalLocation portalLocation = new PortalLocation();
portalLocation.setSignLocation(new BlockLocation(world, portalData[1])); portalLocation.setSignLocation(new BlockLocation(world, portalData[1]));
BlockLocation button = (portalData[2].length() > 0) ? new BlockLocation(world, portalData[2]) : null; 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.setYaw(Float.parseFloat(portalData[5]));
portalLocation.setTopLeft(new BlockLocation(world, portalData[6])); portalLocation.setTopLeft(new BlockLocation(world, portalData[6]));
Gate gate = GateHandler.getGateByName(portalData[7]); Gate gate = GateHandler.getGateByName(portalData[7]);
@ -995,7 +987,7 @@ public class PortalHandler {
} }
//Creates the new portal //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)); network, gate, ownerUUID, ownerName, getPortalOptions(portalData));
registerPortal(portal); registerPortal(portal);

View File

@ -9,11 +9,10 @@ import org.bukkit.block.BlockFace;
/** /**
* Keeps track of location related data for a portal * Keeps track of location related data for a portal
*/ */
@SuppressWarnings("UnusedReturnValue")
public class PortalLocation { public class PortalLocation {
private BlockLocation topLeft; private BlockLocation topLeft;
private int modX;
private int modZ;
private float yaw; private float yaw;
private BlockLocation signLocation; private BlockLocation signLocation;
private RelativeBlockVector buttonVector; private RelativeBlockVector buttonVector;
@ -28,24 +27,6 @@ public class PortalLocation {
return topLeft; return topLeft;
} }
/**
* Gets the x-modifier for the portal
*
* @return <p>The x-modifier for the portal</p>
*/
public int getModX() {
return modX;
}
/**
* Gets the z-modifier for the portal
*
* @return <p>The z-modifier for the portal</p>
*/
public int getModZ() {
return modZ;
}
/** /**
* Gets the yaw for looking outwards from the portal * Gets the yaw for looking outwards from the portal
* *
@ -115,28 +96,6 @@ public class PortalLocation {
return this; return this;
} }
/**
* Sets the portal's x-modifier
*
* @param modX <p>The portal's new x-modifier</p>
* @return <p>The portal location Object</p>
*/
public PortalLocation setModX(int modX) {
this.modX = modX;
return this;
}
/**
* Sets the portal's z-modifier
*
* @param modZ <p>The portal's new z-modifier</p>
* @return <p>The portal location Object</p>
*/
public PortalLocation setModZ(int modZ) {
this.modZ = modZ;
return this;
}
/** /**
* Sets the portal's yaw * Sets the portal's yaw
* *

View File

@ -125,7 +125,7 @@ public final class BungeeHelper {
Stargate.bungeeQueue.put(playerName.toLowerCase(), destination); Stargate.bungeeQueue.put(playerName.toLowerCase(), destination);
} else { } else {
Portal destinationPortal = PortalHandler.getBungeePortal(destination); 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) { if (destinationPortal == null) {
Stargate.logger.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist"); Stargate.logger.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist");
return; return;

View File

@ -7,7 +7,7 @@ import org.bukkit.block.BlockFace;
import org.bukkit.util.Vector; 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 { public final class DirectionHelper {
@ -81,7 +81,7 @@ public final class DirectionHelper {
} else if (yaw == 270) { } else if (yaw == 270) {
return new Vector(1, 0, 0); return new Vector(1, 0, 0);
} else { } 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); return topLeft.getRelativeLocation(vector, yaw);
} }
/**
* Gets the block at a relative block vector location
*
* @param vector <p>The relative block vector</p>
* @return <p>The block at the given relative position</p>
*/
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 * Moves a location relatively
* *

View File

@ -39,7 +39,7 @@ public final class EconomyHelper {
return false; return false;
} }
//Send the deduct message to the player //Send the deduct-message to the player
sendDeductMessage(entrancePortal.getName(), player, cost); sendDeductMessage(entrancePortal.getName(), player, cost);
if (entrancePortal.getGate().getToOwner()) { if (entrancePortal.getGate().getToOwner()) {

View File

@ -62,7 +62,7 @@ public class BlockLocationTest {
@Test @Test
public void makeRelativeTest() { public void makeRelativeTest() {
BlockLocation location = new BlockLocation(mockWorld, 3, 7, 19); 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(37, newLocation.getBlockX());
assertEquals(72, newLocation.getBlockY()); assertEquals(72, newLocation.getBlockY());
assertEquals(94, newLocation.getBlockZ()); assertEquals(94, newLocation.getBlockZ());
@ -82,13 +82,4 @@ public class BlockLocationTest {
assertEquals("56,87,34", location.toString()); 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());
}
} }