Compare commits

...

9 Commits

Author SHA1 Message Date
24ef1cde02 Bumps version for release
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-24 17:23:23 +01:00
9b28107db8 Adds changes to README
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-24 17:22:50 +01:00
99c3b611dc Stops measuring distances across worlds
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-23 13:33:18 +01:00
07463f77d9 Blocks 1-block END_GATEWAY teleportation events which prevented sneaking from triggering a teleportation
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-23 13:18:02 +01:00
bbb5c5184e Stops cancelling END_GATEWAY teleportation events, as those prevented teleportation from end gateways
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-23 12:51:16 +01:00
69e334c195 Actually outputs the teleportation failure error message
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-23 02:24:59 +01:00
3e0b38c3d0 Removes SimpleVectorOperation and adds a different message for a failed teleportation
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-23 02:23:12 +01:00
2bf9f13379 Fixes a bug when checking whether a player has the required permission to access a world
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
2026-01-23 02:21:18 +01:00
89a68b40b1 Moves config loaded toggle to avoid unnecessary debug output 2026-01-23 02:20:41 +01:00
14 changed files with 70 additions and 294 deletions

View File

@@ -31,7 +31,7 @@ Highly capable, simple to use, with robust network capabilities and extensive cu
- LockedCraft and LittleBigBug also forked that version to add underwater and tag support, as well as a few bug fixes. - LockedCraft and LittleBigBug also forked that version to add underwater and tag support, as well as a few bug fixes.
- This version is a combination of all the forks above, maintained by EpicKnarvik97. - This version is a combination of all the forks above, maintained by EpicKnarvik97.
- A rewrite was underway, but because of a mix of real life obligations, and a general lack of motivation, progress - A rewrite was underway, but because of a mix of real life obligations, and a general lack of motivation, progress
stopped. stopped. Some features/improvements have found its way from the rewrite to this version over time.
## License ## License
@@ -489,6 +489,7 @@ Please note that %variableName% should be kept, as it will be replaced with a re
|-----------------------|--------------------------------------------------------------------| |-----------------------|--------------------------------------------------------------------|
| prefix | \[Stargate] | | prefix | \[Stargate] |
| teleportMsg | Teleported | | teleportMsg | Teleported |
| teleportationFailed | Teleportation was cancelled or denied |
| destroyMsg | Gate Destroyed | | destroyMsg | Gate Destroyed |
| invalidMsg | Invalid Destination | | invalidMsg | Invalid Destination |
| blockMsg | Destination Blocked | | blockMsg | Destination Blocked |
@@ -535,6 +536,25 @@ Please note that %variableName% should be kept, as it will be replaced with a re
# Changes # Changes
#### \[Version 0.11.5.12] Unified Legacy Fork
- Fixes gate verification incorrectly treating valid Stargates as invalid
- Improves the default permissions of players to allow personal creation of standard nether stargates, and general
Stargate use.
- Adds three new permission groups for easier permission setup: stargate.group.admin, stargate.group.builder,
stargate.group.player. The builder group allows creation and destruction of all Stargates, and usage of all
options/flags except bungee portals.
- Fixes end gateways not teleporting players unless sneaking into the portal on newer Minecraft versions.
- Adds an error message in case Stargate detects some other plugin cancelled or interfered with its teleportation.
- Stops some debug output during startup when debug is disabled
- Renames the silent option to quiet internally to better match the Q character used to enable the option.
- Replaces code for message formatting
- Improves some error messages
- Replaces some code with KnarLib implementations
- Updates some dependencies
- Restructures all event code, and improves Stargate protection
- Removes static permission strings, and removes redundancy in permission checking code
#### \[Version 0.11.5.11] Unified Legacy Fork #### \[Version 0.11.5.11] Unified Legacy Fork
- Removes legacy sign drawing code, as the check for whether a server supported the sign sides kept failing for some - Removes legacy sign drawing code, as the check for whether a server supported the sign sides kept failing for some
@@ -571,7 +591,7 @@ Please note that %variableName% should be kept, as it will be replaced with a re
- Fixed a potential stack trace experienced when disabling Dynmap - Fixed a potential stack trace experienced when disabling Dynmap
- Fixed some problems related to negative economy transactions. - Fixed some problems related to negative economy transactions.
- Fixed an exception occuring when negative yaw values are encountered. - Fixed an exception occurring when negative yaw values are encountered.
- Updated the about command and added a debug command. - Updated the about command and added a debug command.
#### \[Version 0.11.5.5] Unified Legacy Fork #### \[Version 0.11.5.5] Unified Legacy Fork

View File

@@ -4,7 +4,7 @@
<groupId>net.knarcraft</groupId> <groupId>net.knarcraft</groupId>
<artifactId>Stargate</artifactId> <artifactId>Stargate</artifactId>
<version>0.11.5.12-SNAPSHOT</version> <version>0.11.5.12</version>
<licenses> <licenses>
<license> <license>

View File

@@ -92,6 +92,7 @@ public final class StargateConfig {
*/ */
public void finishSetup() { public void finishSetup() {
this.loadConfig(); this.loadConfig();
this.isLoaded = true;
//Enable the required channels for Bungee support //Enable the required channels for Bungee support
if (stargateGateConfig.enableBungee()) { if (stargateGateConfig.enableBungee()) {
@@ -133,8 +134,6 @@ public final class StargateConfig {
"integration is disabled."); "integration is disabled.");
DynmapManager.disable(); DynmapManager.disable();
} }
this.isLoaded = true;
} }
/** /**

View File

@@ -202,6 +202,11 @@ public enum Message {
* The author that created the loaded translation * The author that created the loaded translation
*/ */
AUTHOR("author"), AUTHOR("author"),
/**
* The error message to display when a teleportation fails for whatever reason
*/
TELEPORTATION_FAILED("teleportationFailed"),
; ;
private final String key; private final String key;

View File

@@ -1,6 +1,5 @@
package net.knarcraft.stargate.container; package net.knarcraft.stargate.container;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -22,28 +21,6 @@ import org.jetbrains.annotations.Nullable;
*/ */
public record RelativeBlockVector(int right, int down, int out) { public record RelativeBlockVector(int right, int down, int out) {
/**
* Adds the given value to this relative block vector's "right" property
*
* @param valueToAdd <p>The value to add</p>
* @return <p>The new resulting vector</p>
*/
@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 valueToAdd <p>The value to add</p>
* @return <p>The new resulting vector</p>
*/
@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 * 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); return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd);
} }
/**
* Gets a relative vector in the real space representing this relative block vector
*
* @return <p>A vector representing this relative block vector</p>
*/
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) * Gets a relative block vector which is this inverted (pointing in the opposite direction)
* *

View File

@@ -63,15 +63,24 @@ public class StargateTeleportListener implements Listener {
* *
* @param event <p>The event to check and possibly cancel</p> * @param event <p>The event to check and possibly cancel</p>
*/ */
@EventHandler @EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) { public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
PlayerTeleportEvent.TeleportCause cause = event.getCause(); PlayerTeleportEvent.TeleportCause cause = event.getCause();
//Block normal portal teleportation if teleporting from a stargate //Block normal portal teleportation if teleporting from a stargate
if (!event.isCancelled() && (cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL || if ((cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY ||
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL) cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) { && PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
Stargate.debug("StargateTeleportListener::onPlayerTeleport",
"Cancelled vanilla portal event to " + event.getTo());
event.setCancelled(true);
}
// Cancel end gateway teleportation to the same destination
if (event.getTo() != null && cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY &&
PortalHandler.getByAdjacentEntrance(event.getFrom()) != null &&
event.getFrom().getWorld() != null && event.getFrom().getWorld().equals(event.getTo().getWorld()) &&
event.getFrom().distance(event.getTo()) <= 1) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@@ -388,6 +397,7 @@ public class StargateTeleportListener implements Listener {
*/ */
private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal, private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal,
@NotNull Portal destination, @NotNull PlayerMoveEvent event) { @NotNull Portal destination, @NotNull PlayerMoveEvent event) {
boolean success = true;
if (playerVehicle instanceof LivingEntity) { if (playerVehicle instanceof LivingEntity) {
//Make sure any horses are properly tamed //Make sure any horses are properly tamed
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) { if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
@@ -399,10 +409,12 @@ public class StargateTeleportListener implements Listener {
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal); new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal);
} else { } else {
//Just teleport the player like normal //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); new SGFormatBuilder(Message.TELEPORTED).success(player);
} else if (!success) {
new SGFormatBuilder(Message.TELEPORTATION_FAILED).error(player);
} }
entrancePortal.getPortalOpener().closePortal(false); entrancePortal.getPortalOpener().closePortal(false);
} }
@@ -462,8 +474,10 @@ public class StargateTeleportListener implements Listener {
*/ */
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) { private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
Portal entrancePortal = PortalHandler.getByEntrance(toLocation); Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
// Return if in an entrance // Return if in an entrance
if (entrancePortal != null) { if (entrancePortal != null) {
Stargate.debug("StargateTeleportListener::getEnteredPortal", "Player entered portal " + entrancePortal);
return entrancePortal; return entrancePortal;
} }
@@ -473,6 +487,8 @@ public class StargateTeleportListener implements Listener {
return null; return null;
} }
Stargate.debug("StargateTeleportListener::getEnteredPortal", "Player entered adjacent portal " + entrancePortal);
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks // If END_GATEWAY and END_PORTAL cannot appear, skip further checks
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials()); Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) { if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {

View File

@@ -9,8 +9,6 @@ import net.knarcraft.stargate.portal.property.PortalOwner;
import net.knarcraft.stargate.portal.property.PortalStrings; import net.knarcraft.stargate.portal.property.PortalStrings;
import net.knarcraft.stargate.portal.property.PortalStructure; import net.knarcraft.stargate.portal.property.PortalStructure;
import net.knarcraft.stargate.portal.property.gate.Gate; 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 net.md_5.bungee.api.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -28,7 +26,6 @@ public class Portal {
private final String cleanName; private final String cleanName;
private final String network; private final String network;
private final String cleanNetwork; private final String cleanNetwork;
private final SimpleVectorOperation vectorOperation;
private final PortalOwner portalOwner; private final PortalOwner portalOwner;
private boolean isRegistered; private boolean isRegistered;
@@ -64,7 +61,6 @@ public class Portal {
this.portalActivator = portalOpener.getPortalActivator(); this.portalActivator = portalOpener.getPortalActivator();
this.cleanName = cleanString(name); this.cleanName = cleanString(name);
this.cleanNetwork = cleanString(network); this.cleanNetwork = cleanString(network);
this.vectorOperation = new SimpleVectorOperation(DirectionHelper.getBlockFaceFromYaw(portalLocation.getYaw()));
} }
/** /**
@@ -317,7 +313,7 @@ public class Portal {
*/ */
@NotNull @NotNull
public BlockLocation getBlockAt(@NotNull RelativeBlockVector vector) { public BlockLocation getBlockAt(@NotNull RelativeBlockVector vector) {
return (BlockLocation) getTopLeft().clone().add(vectorOperation.performToRealSpaceOperation(vector.toVector())); return getTopLeft().getRelativeLocation(vector, this.getYaw());
} }
/** /**

View File

@@ -71,15 +71,18 @@ public class PortalHandler {
List<String> destinations = new ArrayList<>(); List<String> destinations = new ArrayList<>();
List<String> portalsInNetwork = PortalRegistry.getNetwork(network); List<String> portalsInNetwork = PortalRegistry.getNetwork(network);
if (portalsInNetwork == null) { if (portalsInNetwork == null) {
Stargate.debug("PortalHandler::getDestinations", "Portal network " + network + " is null");
return List.of(); return List.of();
} }
for (String destination : portalsInNetwork) { for (String destination : portalsInNetwork) {
Portal portal = getByName(destination, network); Portal portal = getByName(destination, network);
if (portal == null) { if (portal == null) {
Stargate.debug("PortalHandler::getDestinations", "Invalid portal with name " + destination);
continue; continue;
} }
if (isDestinationAvailable(entrancePortal, portal, player)) { if (isDestinationAvailable(entrancePortal, portal, player)) {
Stargate.debug("PortalHandler::getDestinations", "Found available destination " + portal.getName());
destinations.add(portal.getName()); destinations.add(portal.getName());
} }
} }
@@ -120,6 +123,7 @@ public class PortalHandler {
//Check if this player can access the destination world //Check if this player can access the destination world
if (destinationPortal.getWorld() != null && PermissionHelper.cannotAccessWorld(player, if (destinationPortal.getWorld() != null && PermissionHelper.cannotAccessWorld(player,
destinationPortal.getWorld().getName())) { destinationPortal.getWorld().getName())) {
Stargate.debug("PortalHandler::isDestinationAvailable", "Missing permission for destination world");
return false; return false;
} }
//The portal is visible to the player //The portal is visible to the player
@@ -473,7 +477,8 @@ public class PortalHandler {
if (!MaterialHelper.specifiersToMaterials(portal.getGate().getControlBlockMaterials()).contains( if (!MaterialHelper.specifiersToMaterials(portal.getGate().getControlBlockMaterials()).contains(
block.getType())) { block.getType())) {
Stargate.debug("PortalHandler::unregisterInvalidPortal", "Control Block Type == " + Stargate.debug("PortalHandler::unregisterInvalidPortal", "Control Block Type == " +
block.getType().name()); block.getType().name() + " at " + control + " real: " + block + " facing " +
portal.getLocation().getYaw());
} }
} }
PortalRegistry.unregisterPortal(portal, false); PortalRegistry.unregisterPortal(portal, false);

View File

@@ -39,7 +39,8 @@ public class PlayerTeleporter extends Teleporter {
* @param origin <p>The portal the player teleports from</p> * @param origin <p>The portal the player teleports from</p>
* @param event <p>The player move event triggering the event</p> * @param event <p>The player move event triggering the event</p>
*/ */
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(); double velocity = player.getVelocity().length();
List<Entity> passengers = player.getPassengers(); List<Entity> passengers = player.getPassengers();
@@ -47,7 +48,7 @@ public class PlayerTeleporter extends Teleporter {
if (!origin.equals(portal)) { if (!origin.equals(portal)) {
exit = triggerPortalEvent(origin, new StargatePlayerPortalEvent(player, origin, portal, exit)); exit = triggerPortalEvent(origin, new StargatePlayerPortalEvent(player, origin, portal, exit));
if (exit == null) { if (exit == null) {
return; return false;
} }
} }
@@ -67,14 +68,18 @@ public class PlayerTeleporter extends Teleporter {
//If no event is passed in, assume it's a teleport, and act as such //If no event is passed in, assume it's a teleport, and act as such
if (event == null) { if (event == null) {
player.teleport(exit); success &= player.teleport(exit);
Stargate.debug("PlayerTeleporter::teleportPlayer", "Teleported player to " + exit);
} else { } else {
//Set the exit location of the event //Set the exit location of the event
success &= !event.isCancelled();
event.setTo(exit); event.setTo(exit);
Stargate.debug("PlayerTeleporter::teleportPlayer", "Overwrote movement event to " + exit);
} }
//Set the velocity of the teleported player after the teleportation is finished //Set the velocity of the teleported player after the teleportation is finished
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () -> player.setVelocity(newVelocity), 1); Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () -> player.setVelocity(newVelocity), 1);
return success;
} }
} }

View File

@@ -1,185 +0,0 @@
package net.knarcraft.stargate.transformation;
import org.bukkit.Axis;
import org.bukkit.block.BlockFace;
import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
/**
* A class for performing rotational operations on vectors
*
* @author Kristian Knarvik
*/
@SuppressWarnings("unused")
public class SimpleVectorOperation {
private static final Map<BlockFace, Double> rotationAngles = new HashMap<>();
private static final Map<BlockFace, Vector> rotationAxes = new HashMap<>();
private static final Map<BlockFace, Axis> normalAxes = new HashMap<>();
private static final BlockFace defaultDirection = BlockFace.SOUTH;
private static final Axis defaultVerticalAxis = Axis.Y;
private final Axis normalAxis;
private boolean flipZAxis = false;
private final BlockFace facing;
/**
* Instantiates a vector operation to rotate vectors in the direction of a sign face
*
* @param signFace <p>The sign face of a gate's sign</p>
*/
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
*
* @return <p>The block face of a sign given upon instantiation</p>
*/
@NotNull
public BlockFace getFacing() {
return facing;
}
/**
* Gets the normal axis orthogonal to the opening plane
*
* <p>Said another way, get the axis going directly towards or away from a stargate's entrance.</p>
*
* @return <p>The normal axis orthogonal to the opening plane</p>
*/
@NotNull
public Axis getNormalAxis() {
return normalAxis;
}
/**
* Sets whether to flip the Z- axis
*
* @param flipZAxis <p>Whether to flip the z-axis</p>
*/
public void setFlipZAxis(boolean flipZAxis) {
this.flipZAxis = flipZAxis;
}
/**
* Performs an operation from the real space to the vector space
*
* @param vector <p>The vector to perform the operation on</p>
* @return vector <p>A new vector with the operation applied</p>
*/
@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 vector <p>The vector to perform the inverse operation on</p>
* @return vector <p>A new vector with the operation applied</p>
*/
@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 vector <p>The vector to perform the inverse operation on</p>
* @return vector <p>A new vector with the operation applied</p>
*/
@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() {
Map<Axis, Vector> axisVectors = new HashMap<>();
axisVectors.put(Axis.Y, new Vector(0, 1, 0));
axisVectors.put(Axis.X, new Vector(1, 0, 0));
axisVectors.put(Axis.Z, new Vector(0, 0, 1));
//Use the cross product to find the correct axis
for (BlockFace face : normalAxes.keySet()) {
Vector crossProduct = face.getDirection().crossProduct(defaultDirection.getDirection());
if (face == defaultDirection || face == defaultDirection.getOppositeFace()) {
rotationAxes.put(face, axisVectors.get(defaultVerticalAxis));
} else if (Math.abs(crossProduct.getZ()) > 0) {
rotationAxes.put(face, axisVectors.get(Axis.Z));
} else if (Math.abs(crossProduct.getY()) > 0) {
rotationAxes.put(face, axisVectors.get(Axis.Y));
} else {
rotationAxes.put(face, axisVectors.get(Axis.X));
}
}
calculateRotations();
}
/**
* Calculates the required rotations based on the default rotation
*/
private static void calculateRotations() {
double halfRotation = Math.PI;
double quarterRotation = halfRotation / 2;
Vector defaultDirectionVector = defaultDirection.getDirection();
boolean defaultDirectionPositive = defaultDirectionVector.getX() + defaultDirectionVector.getY() +
defaultDirectionVector.getZ() > 0;
for (BlockFace blockFace : normalAxes.keySet()) {
if (defaultDirection == blockFace) {
//The default direction requires no rotation
rotationAngles.put(blockFace, 0d);
} else if (defaultDirection.getOppositeFace() == blockFace) {
//The opposite direction requires a half rotation
rotationAngles.put(blockFace, halfRotation);
} else {
//All the other used directions require a quarter rotation
Vector faceDirectionVector = blockFace.getDirection();
boolean faceDirectionPositive = faceDirectionVector.getX() + faceDirectionVector.getY() +
faceDirectionVector.getZ() > 0;
double rotation = defaultDirectionPositive && faceDirectionPositive ? quarterRotation : -quarterRotation;
rotationAngles.put(blockFace, rotation);
}
}
}
/**
* Initializes the iris normal axes corresponding to each block face
*/
private static void initializeIrisNormalAxes() {
normalAxes.put(BlockFace.EAST, Axis.Z);
normalAxes.put(BlockFace.WEST, Axis.Z);
normalAxes.put(BlockFace.NORTH, Axis.X);
normalAxes.put(BlockFace.SOUTH, Axis.X);
normalAxes.put(BlockFace.UP, Axis.Y);
normalAxes.put(BlockFace.DOWN, Axis.Y);
}
}

View File

@@ -219,7 +219,7 @@ public final class PermissionHelper {
* @return <p>False if the player should be allowed to access the world</p> * @return <p>False if the player should be allowed to access the world</p>
*/ */
public static boolean cannotAccessWorld(@NotNull Player player, @NotNull String world) { public static boolean cannotAccessWorld(@NotNull Player player, @NotNull String world) {
return hasPermission(player, Permission.ACCESS_WORLD, world); return !hasPermission(player, Permission.ACCESS_WORLD, world);
} }
/** /**

View File

@@ -39,3 +39,4 @@ signToUse=to use gate
teleportMsg=Teleported teleportMsg=Teleported
vaultLoadError=Economy is enabled but Vault could not be loaded. Economy disabled vaultLoadError=Economy is enabled but Vault could not be loaded. Economy disabled
vaultLoaded=Vault v%version% found vaultLoaded=Vault v%version% found
teleportationFailed=Teleportation was cancelled or denied

View File

@@ -1,54 +0,0 @@
package net.knarcraft.stargate.container;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RelativeBlockVectorTest {
@Test
public void addToVectorTest() {
int right = 5;
int down = 5;
int out = 3;
RelativeBlockVector relativeBlockVector = new RelativeBlockVector(right, down, out);
for (int i = 0; i < 1000; i++) {
int randomValue = getRandomNumber();
RelativeBlockVector newVector = relativeBlockVector.addRight(randomValue);
assertEquals(new RelativeBlockVector(right + randomValue, down, out), newVector);
newVector = relativeBlockVector.addOut(randomValue);
assertEquals(new RelativeBlockVector(right, down, out + randomValue), newVector);
newVector = relativeBlockVector.addDown(randomValue);
assertEquals(new RelativeBlockVector(right, down + randomValue, out), newVector);
}
}
@Test
public void invertTest() {
for (int i = 0; i < 1000; i++) {
int randomNumber1 = getRandomNumber();
int randomNumber2 = getRandomNumber();
int randomNumber3 = getRandomNumber();
RelativeBlockVector relativeBlockVector = new RelativeBlockVector(randomNumber1, randomNumber2,
randomNumber3);
RelativeBlockVector invertedBlockVector = new RelativeBlockVector(-randomNumber1, -randomNumber2,
-randomNumber3);
assertEquals(invertedBlockVector, relativeBlockVector.invert());
}
}
/**
* Gets a random number between -500 and 500
*
* @return <p>A random number between -500 and 500</p>
*/
private int getRandomNumber() {
return (int) ((Math.random() - 0.5) * 1000);
}
}