Adds nullability annotations among other things
Adds nullability annotations for all methods Fixes some nullability problems and inconsistencies Gets rid of RelativeBlockVector's inner class Changes RelativeBlockVector to a record Simplifies FromTheEndTeleportation's storage, and makes it into a minimal record Removes the putStringInList method Gets rid of some primitive list usage Fixes some incorrect method accessibility Removes some redundancy in PortalOption
This commit is contained in:
@@ -2,6 +2,8 @@ package net.knarcraft.stargate.container;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a request for changing a block into another material
|
||||
@@ -19,7 +21,7 @@ public class BlockChangeRequest {
|
||||
* @param material <p>The new material to change the block to</p>
|
||||
* @param axis <p>The new axis to orient the block along</p>
|
||||
*/
|
||||
public BlockChangeRequest(BlockLocation blockLocation, Material material, Axis axis) {
|
||||
public BlockChangeRequest(@NotNull BlockLocation blockLocation, @NotNull Material material, @Nullable Axis axis) {
|
||||
this.blockLocation = blockLocation;
|
||||
newMaterial = material;
|
||||
newAxis = axis;
|
||||
@@ -30,6 +32,7 @@ public class BlockChangeRequest {
|
||||
*
|
||||
* @return <p>The location of the block</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation getBlockLocation() {
|
||||
return blockLocation;
|
||||
}
|
||||
@@ -39,6 +42,7 @@ public class BlockChangeRequest {
|
||||
*
|
||||
* @return <p>The material to change the block into</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Material getMaterial() {
|
||||
return newMaterial;
|
||||
}
|
||||
@@ -48,6 +52,7 @@ public class BlockChangeRequest {
|
||||
*
|
||||
* @return <p>The axis to orient the block along</p>
|
||||
*/
|
||||
@Nullable
|
||||
public Axis getAxis() {
|
||||
return newAxis;
|
||||
}
|
||||
|
@@ -10,6 +10,8 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This class represents a block location
|
||||
@@ -30,7 +32,7 @@ public class BlockLocation extends Location {
|
||||
* @param y <p>The y coordinate of the block</p>
|
||||
* @param z <p>The z coordinate of the block</p>
|
||||
*/
|
||||
public BlockLocation(World world, int x, int y, int z) {
|
||||
public BlockLocation(@NotNull World world, int x, int y, int z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
@@ -39,7 +41,7 @@ public class BlockLocation extends Location {
|
||||
*
|
||||
* @param block <p>The block to get the location of</p>
|
||||
*/
|
||||
public BlockLocation(Block block) {
|
||||
public BlockLocation(@NotNull Block block) {
|
||||
super(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
@@ -49,7 +51,7 @@ public class BlockLocation extends Location {
|
||||
* @param world <p>The world the block exists in</p>
|
||||
* @param string <p>A comma separated list of x, y and z coordinates as integers</p>
|
||||
*/
|
||||
public BlockLocation(World world, String string) {
|
||||
public BlockLocation(@NotNull World world, @NotNull String string) {
|
||||
super(world, Integer.parseInt(string.split(",")[0]), Integer.parseInt(string.split(",")[1]),
|
||||
Integer.parseInt(string.split(",")[2]));
|
||||
}
|
||||
@@ -62,6 +64,7 @@ public class BlockLocation extends Location {
|
||||
* @param z <p>The number of blocks to move in the z-direction</p>
|
||||
* @return <p>A new block location</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation makeRelativeBlockLocation(int x, int y, int z) {
|
||||
return (BlockLocation) this.clone().add(x, y, z);
|
||||
}
|
||||
@@ -75,6 +78,7 @@ public class BlockLocation extends Location {
|
||||
* @param yaw <p>The number of blocks to move in the z-direction</p>
|
||||
* @return <p>A new location</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Location makeRelativeLocation(double x, double y, double z, float yaw) {
|
||||
Location newLocation = this.clone();
|
||||
newLocation.setYaw(yaw);
|
||||
@@ -89,9 +93,10 @@ public class BlockLocation extends Location {
|
||||
* @param yaw <p>The yaw pointing outwards from a portal (in the relative vector's out direction)</p>
|
||||
* @return <p>A location relative to this location</p>
|
||||
*/
|
||||
public BlockLocation getRelativeLocation(RelativeBlockVector relativeVector, double yaw) {
|
||||
Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(relativeVector.getRight(),
|
||||
relativeVector.getDown(), relativeVector.getOut(), yaw);
|
||||
@NotNull
|
||||
public BlockLocation getRelativeLocation(@NotNull RelativeBlockVector relativeVector, double yaw) {
|
||||
Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(relativeVector.right(),
|
||||
relativeVector.down(), relativeVector.out(), yaw);
|
||||
return makeRelativeBlockLocation(realVector.getBlockX(), realVector.getBlockY(), realVector.getBlockZ());
|
||||
}
|
||||
|
||||
@@ -107,6 +112,7 @@ public class BlockLocation extends Location {
|
||||
* @param portalYaw <p>The yaw when looking out from the portal</p>
|
||||
* @return A new location relative to this block location
|
||||
*/
|
||||
@NotNull
|
||||
public Location getRelativeLocation(double right, double down, double out, float portalYaw) {
|
||||
Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(right, down, out, portalYaw);
|
||||
return makeRelativeLocation(0.5 + realVector.getBlockX(), realVector.getBlockY(),
|
||||
@@ -118,6 +124,7 @@ public class BlockLocation extends Location {
|
||||
*
|
||||
* @return <p>The block's material type</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Material getType() {
|
||||
return this.getBlock().getType();
|
||||
}
|
||||
@@ -127,7 +134,7 @@ public class BlockLocation extends Location {
|
||||
*
|
||||
* @param type <p>The block's new material type</p>
|
||||
*/
|
||||
public void setType(Material type) {
|
||||
public void setType(@NotNull Material type) {
|
||||
this.getBlock().setType(type);
|
||||
}
|
||||
|
||||
@@ -136,6 +143,7 @@ public class BlockLocation extends Location {
|
||||
*
|
||||
* @return <p>The location representing this block location</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return this.clone();
|
||||
}
|
||||
@@ -148,6 +156,7 @@ public class BlockLocation extends Location {
|
||||
*
|
||||
* @return <p>This block location's parent block</p>
|
||||
*/
|
||||
@Nullable
|
||||
public Block getParent() {
|
||||
if (parent == null) {
|
||||
findParent();
|
||||
@@ -184,6 +193,7 @@ public class BlockLocation extends Location {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
return String.valueOf(this.getBlockX()) + ',' + this.getBlockY() + ',' + this.getBlockZ();
|
||||
}
|
||||
@@ -203,7 +213,7 @@ public class BlockLocation extends Location {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
public boolean equals(@Nullable Object object) {
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ public class ChunkUnloadRequest implements Comparable<ChunkUnloadRequest> {
|
||||
* @param chunkToUnload <p>The chunk to request the unloading of</p>
|
||||
* @param timeUntilUnload <p>The time in milliseconds to wait before unloading the chunk</p>
|
||||
*/
|
||||
public ChunkUnloadRequest(Chunk chunkToUnload, Long timeUntilUnload) {
|
||||
public ChunkUnloadRequest(@NotNull Chunk chunkToUnload, @NotNull Long timeUntilUnload) {
|
||||
this.chunkToUnload = chunkToUnload;
|
||||
long systemNanoTime = System.nanoTime();
|
||||
this.unloadNanoTime = systemNanoTime + (timeUntilUnload * 1000000);
|
||||
@@ -28,6 +28,7 @@ public class ChunkUnloadRequest implements Comparable<ChunkUnloadRequest> {
|
||||
*
|
||||
* @return <p>The chunk to unload</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Chunk getChunkToUnload() {
|
||||
return this.chunkToUnload;
|
||||
}
|
||||
@@ -37,11 +38,13 @@ public class ChunkUnloadRequest implements Comparable<ChunkUnloadRequest> {
|
||||
*
|
||||
* @return <p>The system nano time denoting when the chunk is to be unloaded</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Long getUnloadNanoTime() {
|
||||
return this.unloadNanoTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
return "{" + chunkToUnload + ", " + unloadNanoTime + "}";
|
||||
}
|
||||
|
@@ -1,60 +1,16 @@
|
||||
package net.knarcraft.stargate.container;
|
||||
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This class represents a player teleporting from the end to the over-world using an artificial end portal
|
||||
* This class represents a teleportation from the end to the over-world using an artificial end portal
|
||||
*
|
||||
* <p>This is necessary because a player entering an end portal in the end is a special case. Instead of being
|
||||
* teleported, the player is respawned. Because of this, the teleportation needs to be saved and later used to hijack
|
||||
* the position of where the player is to respawn.</p>
|
||||
*
|
||||
* @param exitPortal <p>The portal the player should exit from when arriving in the over-world</p>
|
||||
*/
|
||||
public class FromTheEndTeleportation {
|
||||
|
||||
private final Player teleportingPlayer;
|
||||
private final Portal exitPortal;
|
||||
|
||||
/**
|
||||
* Instantiates a new teleportation from the end
|
||||
*
|
||||
* @param teleportingPlayer <p>The teleporting player</p>
|
||||
* @param exitPortal <p>The portal to exit from</p>
|
||||
*/
|
||||
public FromTheEndTeleportation(Player teleportingPlayer, Portal exitPortal) {
|
||||
this.teleportingPlayer = teleportingPlayer;
|
||||
this.exitPortal = exitPortal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the teleporting player
|
||||
*
|
||||
* @return <p>The teleporting player</p>
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return this.teleportingPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the portal to exit from
|
||||
*
|
||||
* @return <p>The portal to exit from</p>
|
||||
*/
|
||||
public Portal getExit() {
|
||||
return this.exitPortal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return teleportingPlayer.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof FromTheEndTeleportation otherTeleportation)) {
|
||||
return false;
|
||||
}
|
||||
return teleportingPlayer.equals(otherTeleportation.teleportingPlayer);
|
||||
}
|
||||
|
||||
public record FromTheEndTeleportation(@NotNull Portal exitPortal) {
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package net.knarcraft.stargate.container;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This stores a block location as a vector relative to a position
|
||||
*
|
||||
@@ -7,62 +10,48 @@ package net.knarcraft.stargate.container;
|
||||
* top-left block of a gate (top-left when looking at the side with the sign). The right is therefore the distance
|
||||
* from the top-left corner towards the top-right corner. Down is the distance from the top-left corner towards the
|
||||
* bottom-left corner. Out is the distance outward from the gate.</p>
|
||||
*
|
||||
* <p>Relative block vectors start from a top-left corner. A yaw is used to orient a relative block vector in the
|
||||
* "real world". In terms of a gate layout, the origin is 0,0. Right is towards the end of the line. Down is to the
|
||||
* next line. Out is towards the observer.</p>
|
||||
*
|
||||
* @param right <p>The distance rightward relative to the origin</p>
|
||||
* @param down <p>The distance downward relative to the origin</p>
|
||||
* @param out <p>The distance outward relative to the origin</p>
|
||||
*/
|
||||
public class RelativeBlockVector {
|
||||
|
||||
private final int right;
|
||||
private final int down;
|
||||
private final int out;
|
||||
public record RelativeBlockVector(int right, int down, int out) {
|
||||
|
||||
/**
|
||||
* A specifier for one of the relative block vector's three properties
|
||||
* 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>
|
||||
*/
|
||||
public enum Property {
|
||||
/**
|
||||
* Specifies the relative block vector's right property
|
||||
*/
|
||||
RIGHT,
|
||||
/**
|
||||
* Specifies the relative block vector's down property
|
||||
*/
|
||||
DOWN,
|
||||
/**
|
||||
* Specifies the relative block vector's out property
|
||||
*/
|
||||
OUT
|
||||
@NotNull
|
||||
public RelativeBlockVector addRight(int valueToAdd) {
|
||||
return new RelativeBlockVector(this.right + valueToAdd, this.down, this.out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new relative block vector
|
||||
* Adds the given value to this relative block vector's "down" property
|
||||
*
|
||||
* <p>Relative block vectors start from a top-left corner. A yaw is used to orient a relative block vector in the
|
||||
* "real world".
|
||||
* In terms of a gate layout, the origin is 0,0. Right is towards the end of the line. Down is to the
|
||||
* next line. Out is towards the observer.</p>
|
||||
*
|
||||
* @param right <p>The distance rightward relative to the origin</p>
|
||||
* @param down <p>The distance downward relative to the origin</p>
|
||||
* @param out <p>The distance outward relative to the origin</p>
|
||||
* @param valueToAdd <p>The value to add</p>
|
||||
* @return <p>The new resulting vector</p>
|
||||
*/
|
||||
public RelativeBlockVector(int right, int down, int out) {
|
||||
this.right = right;
|
||||
this.down = down;
|
||||
this.out = out;
|
||||
@NotNull
|
||||
public RelativeBlockVector addDown(int valueToAdd) {
|
||||
return new RelativeBlockVector(this.right, this.down + valueToAdd, this.out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a value to one of the properties of this relative block vector
|
||||
* Adds the given value to this relative block vector's "out" property
|
||||
*
|
||||
* @param propertyToAddTo <p>The property to add to</p>
|
||||
* @param valueToAdd <p>The value to add to the property (negative to move in the opposite direction)</p>
|
||||
* @return <p>A new relative block vector with the property altered</p>
|
||||
* @param valueToAdd <p>The value to add</p>
|
||||
* @return <p>The new resulting vector</p>
|
||||
*/
|
||||
public RelativeBlockVector addToVector(Property propertyToAddTo, int valueToAdd) {
|
||||
return switch (propertyToAddTo) {
|
||||
case RIGHT -> new RelativeBlockVector(this.right + valueToAdd, this.down, this.out);
|
||||
case DOWN -> new RelativeBlockVector(this.right, this.down + valueToAdd, this.out);
|
||||
case OUT -> new RelativeBlockVector(this.right, this.down, this.out + valueToAdd);
|
||||
};
|
||||
@NotNull
|
||||
public RelativeBlockVector addOut(int valueToAdd) {
|
||||
return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,6 +59,7 @@ public class RelativeBlockVector {
|
||||
*
|
||||
* @return <p>This vector, but inverted</p>
|
||||
*/
|
||||
@NotNull
|
||||
public RelativeBlockVector invert() {
|
||||
return new RelativeBlockVector(-this.right, -this.down, -this.out);
|
||||
}
|
||||
@@ -79,7 +69,8 @@ public class RelativeBlockVector {
|
||||
*
|
||||
* @return <p>The distance to the right relative to the origin</p>
|
||||
*/
|
||||
public int getRight() {
|
||||
@Override
|
||||
public int right() {
|
||||
return right;
|
||||
}
|
||||
|
||||
@@ -88,7 +79,8 @@ public class RelativeBlockVector {
|
||||
*
|
||||
* @return <p>The distance downward relative to the origin</p>
|
||||
*/
|
||||
public int getDown() {
|
||||
@Override
|
||||
public int down() {
|
||||
return down;
|
||||
}
|
||||
|
||||
@@ -97,17 +89,19 @@ public class RelativeBlockVector {
|
||||
*
|
||||
* @return <p>The distance outward relative to the origin</p>
|
||||
*/
|
||||
public int getOut() {
|
||||
@Override
|
||||
public int out() {
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
return String.format("(right = %d, down = %d, out = %d)", right, down, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import net.knarcraft.stargate.utility.SignHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A class that keeps track of the sign colors for a given sign
|
||||
@@ -23,7 +24,7 @@ public class SignData {
|
||||
* @param mainSignColor <p>The main color to use for the sign</p>
|
||||
* @param highlightSignColor <p>The highlighting color to use for the sign</p>
|
||||
*/
|
||||
public SignData(Sign sign, ChatColor mainSignColor, ChatColor highlightSignColor) {
|
||||
public SignData(@NotNull Sign sign, @NotNull ChatColor mainSignColor, @NotNull ChatColor highlightSignColor) {
|
||||
this.sign = sign;
|
||||
this.mainSignColor = mainSignColor;
|
||||
this.highlightSignColor = highlightSignColor;
|
||||
@@ -35,6 +36,7 @@ public class SignData {
|
||||
*
|
||||
* @return <p>The sign of this sign colors object</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Sign getSign() {
|
||||
return sign;
|
||||
}
|
||||
@@ -44,6 +46,7 @@ public class SignData {
|
||||
*
|
||||
* @return <p>The main color of the sign</p>
|
||||
*/
|
||||
@NotNull
|
||||
public ChatColor getMainSignColor() {
|
||||
if (dyedColor != DyeColor.BLACK) {
|
||||
return ColorHelper.fromColor(dyedColor.getColor());
|
||||
@@ -57,6 +60,7 @@ public class SignData {
|
||||
*
|
||||
* @return <p>The highlighting color of the sign</p>
|
||||
*/
|
||||
@NotNull
|
||||
public ChatColor getHighlightSignColor() {
|
||||
if (dyedColor != DyeColor.BLACK) {
|
||||
return ColorHelper.fromColor(ColorHelper.invert(dyedColor.getColor()));
|
||||
|
Reference in New Issue
Block a user