diff --git a/src/main/java/net/knarcraft/stargate/config/Permission.java b/src/main/java/net/knarcraft/stargate/config/Permission.java index 2d3f6c2..fc4e7a2 100644 --- a/src/main/java/net/knarcraft/stargate/config/Permission.java +++ b/src/main/java/net/knarcraft/stargate/config/Permission.java @@ -15,7 +15,7 @@ public enum Permission { SEE_HIDDEN("admin.hidden"), USE_PRIVATE("admin.private"), - + FREE_USAGE("free.use"), FREE_DESTRUCTION("free.destroy"), FREE_CREATION("free.create"), diff --git a/src/main/java/net/knarcraft/stargate/config/formatting/Message.java b/src/main/java/net/knarcraft/stargate/config/formatting/Message.java index aed78c4..28deae4 100644 --- a/src/main/java/net/knarcraft/stargate/config/formatting/Message.java +++ b/src/main/java/net/knarcraft/stargate/config/formatting/Message.java @@ -202,6 +202,11 @@ public enum Message { * The author that created the loaded translation */ AUTHOR("author"), + + /** + * The error message to display when a teleportation fails for whatever reason + */ + TELEPORTATION_FAILED("teleportationFailed"), ; private final String key; diff --git a/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java b/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java index 9b9f02e..498f3ff 100644 --- a/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java +++ b/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java @@ -1,6 +1,5 @@ package net.knarcraft.stargate.container; -import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,28 +21,6 @@ import org.jetbrains.annotations.Nullable; */ public record RelativeBlockVector(int right, int down, int out) { - /** - * Adds the given value to this relative block vector's "right" property - * - * @param valueToAdd
The value to add
- * @returnThe new resulting vector
- */ - @NotNull - public RelativeBlockVector addRight(int valueToAdd) { - return new RelativeBlockVector(this.right + valueToAdd, this.down, this.out); - } - - /** - * Adds the given value to this relative block vector's "down" property - * - * @param valueToAddThe value to add
- * @returnThe new resulting vector
- */ - @NotNull - public RelativeBlockVector addDown(int valueToAdd) { - return new RelativeBlockVector(this.right, this.down + valueToAdd, this.out); - } - /** * Adds the given value to this relative block vector's "out" property * @@ -55,15 +32,6 @@ public record RelativeBlockVector(int right, int down, int out) { return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd); } - /** - * Gets a relative vector in the real space representing this relative block vector - * - * @returnA vector representing this relative block vector
- */ - public Vector toVector() { - return new Vector(this.right, -this.down, this.out); - } - /** * Gets a relative block vector which is this inverted (pointing in the opposite direction) * diff --git a/src/main/java/net/knarcraft/stargate/listener/StargateTeleportListener.java b/src/main/java/net/knarcraft/stargate/listener/StargateTeleportListener.java index d58a3b8..499be26 100644 --- a/src/main/java/net/knarcraft/stargate/listener/StargateTeleportListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/StargateTeleportListener.java @@ -388,6 +388,7 @@ public class StargateTeleportListener implements Listener { */ private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal, @NotNull Portal destination, @NotNull PlayerMoveEvent event) { + boolean success = true; if (playerVehicle instanceof LivingEntity) { //Make sure any horses are properly tamed if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) { @@ -399,10 +400,12 @@ public class StargateTeleportListener implements Listener { new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal); } else { //Just teleport the player like normal - new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event); + success = new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event); } - if (!entrancePortal.getOptions().isQuiet()) { + if (success && !entrancePortal.getOptions().isQuiet()) { new SGFormatBuilder(Message.TELEPORTED).success(player); + } else if (!success) { + new SGFormatBuilder(Message.TELEPORTATION_FAILED); } entrancePortal.getPortalOpener().closePortal(false); } diff --git a/src/main/java/net/knarcraft/stargate/portal/Portal.java b/src/main/java/net/knarcraft/stargate/portal/Portal.java index 3a8e2ba..666da46 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Portal.java +++ b/src/main/java/net/knarcraft/stargate/portal/Portal.java @@ -9,8 +9,6 @@ import net.knarcraft.stargate.portal.property.PortalOwner; import net.knarcraft.stargate.portal.property.PortalStrings; import net.knarcraft.stargate.portal.property.PortalStructure; import net.knarcraft.stargate.portal.property.gate.Gate; -import net.knarcraft.stargate.transformation.SimpleVectorOperation; -import net.knarcraft.stargate.utility.DirectionHelper; import net.md_5.bungee.api.ChatColor; import org.bukkit.World; import org.bukkit.entity.Player; @@ -28,7 +26,6 @@ public class Portal { private final String cleanName; private final String network; private final String cleanNetwork; - private final SimpleVectorOperation vectorOperation; private final PortalOwner portalOwner; private boolean isRegistered; @@ -64,7 +61,6 @@ public class Portal { this.portalActivator = portalOpener.getPortalActivator(); this.cleanName = cleanString(name); this.cleanNetwork = cleanString(network); - this.vectorOperation = new SimpleVectorOperation(DirectionHelper.getBlockFaceFromYaw(portalLocation.getYaw())); } /** @@ -317,7 +313,7 @@ public class Portal { */ @NotNull public BlockLocation getBlockAt(@NotNull RelativeBlockVector vector) { - return (BlockLocation) getTopLeft().clone().add(vectorOperation.performToRealSpaceOperation(vector.toVector())); + return getTopLeft().getRelativeLocation(vector, this.getYaw()); } /** diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java index e5bebf9..80a480e 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java @@ -71,15 +71,18 @@ public class PortalHandler { ListThe portal the player teleports from
* @param eventThe player move event triggering the event
*/ - public void teleportPlayer(@NotNull Portal origin, @Nullable PlayerMoveEvent event) { + public boolean teleportPlayer(@NotNull Portal origin, @Nullable PlayerMoveEvent event) { + boolean success = true; double velocity = player.getVelocity().length(); ListThe sign face of a gate's sign
- */ - public SimpleVectorOperation(@NotNull BlockFace signFace) { - if (normalAxes.isEmpty()) { - initializeIrisNormalAxes(); - initializeOperations(); - } - - this.facing = signFace; - this.normalAxis = normalAxes.get(signFace); - } - - /** - * Gets the block face of a sign given upon instantiation - * - * @returnThe block face of a sign given upon instantiation
- */ - @NotNull - public BlockFace getFacing() { - return facing; - } - - /** - * Gets the normal axis orthogonal to the opening plane - * - *Said another way, get the axis going directly towards or away from a stargate's entrance.
- * - * @returnThe normal axis orthogonal to the opening plane
- */ - @NotNull - public Axis getNormalAxis() { - return normalAxis; - } - - /** - * Sets whether to flip the Z- axis - * - * @param flipZAxisWhether to flip the z-axis
- */ - public void setFlipZAxis(boolean flipZAxis) { - this.flipZAxis = flipZAxis; - } - - /** - * Performs an operation from the real space to the vector space - * - * @param vectorThe vector to perform the operation on
- * @return vectorA new vector with the operation applied
- */ - @NotNull - public Vector performToAbstractSpaceOperation(@NotNull Vector vector) { - Vector clone = vector.clone(); - clone.rotateAroundAxis(rotationAxes.get(facing), rotationAngles.get(facing)); - if (flipZAxis) { - clone.setZ(-clone.getZ()); - } - return clone; - } - - /** - * Performs an operation from the vector space to the real space - * - * @param vectorThe vector to perform the inverse operation on
- * @return vectorA new vector with the operation applied
- */ - @NotNull - public Vector performToRealSpaceOperation(@NotNull Vector vector) { - Vector clone = vector.clone(); - if (flipZAxis) { - clone.setZ(-clone.getZ()); - } - return clone.rotateAroundAxis(rotationAxes.get(facing), -rotationAngles.get(facing)); - } - - /** - * Performs an operation from the vector space to the real space - * - * @param vectorThe vector to perform the inverse operation on
- * @return vectorA new vector with the operation applied
- */ - @NotNull - public BlockVector performToRealSpaceOperation(@NotNull BlockVector vector) { - return performToRealSpaceOperation((Vector) vector).toBlockVector(); - } - - /** - * Initializes the operations used for rotating to each block-face - */ - private static void initializeOperations() { - MapA random number between -500 and 500
- */ - private int getRandomNumber() { - return (int) ((Math.random() - 0.5) * 1000); - } - -}