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:
@@ -8,6 +8,7 @@ import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.charts.SingleLineChart;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -28,7 +29,7 @@ public final class BStatsHelper {
|
||||
*
|
||||
* @param plugin <p>The plugin to initialize BStats for</p>
|
||||
*/
|
||||
public static void initialize(JavaPlugin plugin) {
|
||||
public static void initialize(@NotNull JavaPlugin plugin) {
|
||||
if (hasBeenInitialized) {
|
||||
throw new IllegalArgumentException("BStats initialized twice");
|
||||
} else {
|
||||
|
@@ -7,6 +7,8 @@ import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -36,6 +38,7 @@ public final class BungeeHelper {
|
||||
*
|
||||
* @return <p>The bungee plugin channel</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String getBungeeChannel() {
|
||||
return bungeeChannel;
|
||||
}
|
||||
@@ -48,9 +51,10 @@ public final class BungeeHelper {
|
||||
* queue and teleported to the destination.</p>
|
||||
*
|
||||
* @param playerUUID <p>The UUID of the player to remove</p>
|
||||
* @return <p>The name of the destination portal the player should be teleported to</p>
|
||||
* @return <p>The name of the destination portal the player should be teleported to, or null if not queued</p>
|
||||
*/
|
||||
public static String removeFromQueue(UUID playerUUID) {
|
||||
@Nullable
|
||||
public static String removeFromQueue(@NotNull UUID playerUUID) {
|
||||
return bungeeQueue.remove(playerUUID);
|
||||
}
|
||||
|
||||
@@ -61,7 +65,7 @@ public final class BungeeHelper {
|
||||
* @param entrancePortal <p>The portal the player is teleporting from</p>
|
||||
* @return <p>True if the message was successfully sent</p>
|
||||
*/
|
||||
public static boolean sendTeleportationMessage(Player player, Portal entrancePortal) {
|
||||
public static boolean sendTeleportationMessage(@NotNull Player player, @NotNull Portal entrancePortal) {
|
||||
try {
|
||||
//Build the teleportation message, format is <player identifier>delimiter<destination>
|
||||
String message = player.getUniqueId() + teleportMessageDelimiter + entrancePortal.getDestinationName();
|
||||
@@ -81,8 +85,8 @@ public final class BungeeHelper {
|
||||
dataOutputStream.writeBytes(message);
|
||||
//Send the plugin message
|
||||
player.sendPluginMessage(Stargate.getInstance(), bungeeChannel, byteArrayOutputStream.toByteArray());
|
||||
} catch (IOException ex) {
|
||||
Stargate.logSevere("Error sending BungeeCord teleport packet! Message: " + ex.getMessage());
|
||||
} catch (IOException exception) {
|
||||
Stargate.logSevere("Error sending BungeeCord teleport packet! Message: " + exception.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -95,7 +99,7 @@ public final class BungeeHelper {
|
||||
* @param entrancePortal <p>The bungee portal the player is teleporting from</p>
|
||||
* @return <p>True if the plugin message was sent successfully</p>
|
||||
*/
|
||||
public static boolean changeServer(Player player, Portal entrancePortal) {
|
||||
public static boolean changeServer(@NotNull Player player, @NotNull Portal entrancePortal) {
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
|
||||
@@ -119,6 +123,7 @@ public final class BungeeHelper {
|
||||
* @param message <p>The byte array to read</p>
|
||||
* @return <p>The message contained in the byte array, or null on failure</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static String readPluginMessage(byte[] message) {
|
||||
byte[] data;
|
||||
try {
|
||||
@@ -147,7 +152,7 @@ public final class BungeeHelper {
|
||||
*
|
||||
* @param receivedMessage <p>The received teleport message</p>
|
||||
*/
|
||||
public static void handleTeleportMessage(String receivedMessage) {
|
||||
public static void handleTeleportMessage(@NotNull String receivedMessage) {
|
||||
//Get the player id and destination from the message
|
||||
String[] messageParts = receivedMessage.split(teleportMessageDelimiter);
|
||||
UUID playerUUID = UUID.fromString(messageParts[0]);
|
||||
@@ -176,7 +181,8 @@ public final class BungeeHelper {
|
||||
* @param event <p>The event causing the teleportation</p>
|
||||
* @return <p>True if the teleportation was successful</p>
|
||||
*/
|
||||
public static boolean bungeeTeleport(Player player, Portal entrancePortal, PlayerMoveEvent event) {
|
||||
public static boolean bungeeTeleport(@NotNull Player player, @NotNull Portal entrancePortal,
|
||||
@NotNull PlayerMoveEvent event) {
|
||||
//Check if bungee is actually enabled
|
||||
if (!Stargate.getGateConfig().enableBungee()) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
@@ -211,7 +217,8 @@ public final class BungeeHelper {
|
||||
* @param string <p>The string to strip color from</p>
|
||||
* @return <p>The string without color codes</p>
|
||||
*/
|
||||
private static String stripColor(String string) {
|
||||
@NotNull
|
||||
private static String stripColor(@NotNull String string) {
|
||||
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', string));
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package net.knarcraft.stargate.utility;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This class helps with direction-related calculations
|
||||
@@ -24,7 +25,7 @@ public final class DirectionHelper {
|
||||
* @param location2 <p>The second location, which the yaw will point towards</p>
|
||||
* @return <p>The yaw pointing from the first location to the second location</p>
|
||||
*/
|
||||
public static float getYawFromLocationDifference(Location location1, Location location2) {
|
||||
public static float getYawFromLocationDifference(@NotNull Location location1, @NotNull Location location2) {
|
||||
Location difference = location1.clone().subtract(location2.clone());
|
||||
if (difference.getX() > 0) {
|
||||
return 90;
|
||||
@@ -45,8 +46,10 @@ public final class DirectionHelper {
|
||||
*
|
||||
* @param yaw <p>The yaw value to convert</p>
|
||||
* @return <p>The block face the yaw corresponds to</p>
|
||||
* @throws IllegalArgumentException <p>If a yaw not divisible by 90 us given</p>
|
||||
*/
|
||||
public static BlockFace getBlockFaceFromYaw(double yaw) {
|
||||
@NotNull
|
||||
public static BlockFace getBlockFaceFromYaw(double yaw) throws IllegalArgumentException {
|
||||
//Make sure the yaw is between 0 and 360
|
||||
yaw = normalizeYaw(yaw);
|
||||
|
||||
@@ -68,8 +71,10 @@ public final class DirectionHelper {
|
||||
*
|
||||
* @param yaw <p>The yaw to convert to a direction vector</p>
|
||||
* @return <p>The direction vector pointing in the same direction as the yaw</p>
|
||||
* @throws IllegalArgumentException <p>If a yaw not divisible by 90 is given</p>
|
||||
*/
|
||||
public static Vector getDirectionVectorFromYaw(double yaw) {
|
||||
@NotNull
|
||||
public static Vector getDirectionVectorFromYaw(double yaw) throws IllegalArgumentException {
|
||||
//Make sure the yaw is between 0 and 360
|
||||
yaw = normalizeYaw(yaw);
|
||||
|
||||
@@ -99,7 +104,8 @@ public final class DirectionHelper {
|
||||
* @param yaw <p>The yaw when looking directly outwards from a portal</p>
|
||||
* @return <p>A location relative to the given location</p>
|
||||
*/
|
||||
public static Location moveLocation(Location location, double right, double down, double out, double yaw) {
|
||||
@NotNull
|
||||
public static Location moveLocation(@NotNull Location location, double right, double down, double out, double yaw) {
|
||||
return location.add(getCoordinateVectorFromRelativeVector(right, down, out, yaw));
|
||||
}
|
||||
|
||||
@@ -111,8 +117,11 @@ public final class DirectionHelper {
|
||||
* @param out <p>The distance outward from the top-left origin</p>
|
||||
* @param yaw <p>The yaw when looking directly outwards from a portal</p>
|
||||
* @return <p>A normal vector</p>
|
||||
* @throws IllegalArgumentException <p>If a yaw not divisible by 90 is given</p>
|
||||
*/
|
||||
public static Vector getCoordinateVectorFromRelativeVector(double right, double down, double out, double yaw) {
|
||||
@NotNull
|
||||
public static Vector getCoordinateVectorFromRelativeVector(double right, double down, double out,
|
||||
double yaw) throws IllegalArgumentException {
|
||||
//Make sure the yaw is between 0 and 360
|
||||
yaw = normalizeYaw(yaw);
|
||||
|
||||
|
@@ -9,6 +9,8 @@ import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -29,7 +31,7 @@ public final class EconomyHelper {
|
||||
* @param cost <p>The cost of teleportation</p>
|
||||
* @return <p>False if payment was successful. True if the payment was unsuccessful</p>
|
||||
*/
|
||||
public static boolean cannotPayTeleportFee(Portal entrancePortal, Player player, int cost) {
|
||||
public static boolean cannotPayTeleportFee(@NotNull Portal entrancePortal, @NotNull Player player, int cost) {
|
||||
boolean success;
|
||||
|
||||
//Try to charge the player. Paying the portal owner is only possible if a UUID is available
|
||||
@@ -78,7 +80,7 @@ public final class EconomyHelper {
|
||||
* @param portalOwner <p>The owner of the portal</p>
|
||||
* @param earnings <p>The amount the owner earned</p>
|
||||
*/
|
||||
public static void sendObtainMessage(String portalName, Player portalOwner, int earnings) {
|
||||
public static void sendObtainMessage(@NotNull String portalName, @NotNull Player portalOwner, int earnings) {
|
||||
String obtainedMsg = Stargate.getString("ecoObtain");
|
||||
obtainedMsg = replacePlaceholders(obtainedMsg, portalName, earnings);
|
||||
Stargate.getMessageSender().sendSuccessMessage(portalOwner, obtainedMsg);
|
||||
@@ -91,7 +93,7 @@ public final class EconomyHelper {
|
||||
* @param player <p>The interacting player</p>
|
||||
* @param cost <p>The cost of the interaction</p>
|
||||
*/
|
||||
public static void sendDeductMessage(String portalName, Player player, int cost) {
|
||||
public static void sendDeductMessage(@NotNull String portalName, @NotNull Player player, int cost) {
|
||||
String deductMsg = Stargate.getString("ecoDeduct");
|
||||
deductMsg = replacePlaceholders(deductMsg, portalName, cost);
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, deductMsg);
|
||||
@@ -104,7 +106,7 @@ public final class EconomyHelper {
|
||||
* @param player <p>The interacting player</p>
|
||||
* @param cost <p>The cost of the interaction</p>
|
||||
*/
|
||||
public static void sendInsufficientFundsMessage(String portalName, Player player, int cost) {
|
||||
public static void sendInsufficientFundsMessage(@NotNull String portalName, @NotNull Player player, int cost) {
|
||||
String inFundMsg = Stargate.getString("ecoInFunds");
|
||||
inFundMsg = replacePlaceholders(inFundMsg, portalName, cost);
|
||||
Stargate.getMessageSender().sendErrorMessage(player, inFundMsg);
|
||||
@@ -117,7 +119,7 @@ public final class EconomyHelper {
|
||||
* @param player <p>The player breaking the portal</p>
|
||||
* @param cost <p>The amount the user has to pay for destroying the portal. (expects a negative value)</p>
|
||||
*/
|
||||
public static void sendRefundMessage(String portalName, Player player, int cost) {
|
||||
public static void sendRefundMessage(@NotNull String portalName, @NotNull Player player, int cost) {
|
||||
String refundMsg = Stargate.getString("ecoRefund");
|
||||
refundMsg = replacePlaceholders(refundMsg, portalName, -cost);
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, refundMsg);
|
||||
@@ -131,7 +133,7 @@ public final class EconomyHelper {
|
||||
* @param destination <p>The destination portal</p>
|
||||
* @return <p>The cost of using the portal</p>
|
||||
*/
|
||||
public static int getUseCost(Player player, Portal source, Portal destination) {
|
||||
public static int getUseCost(@NotNull Player player, @NotNull Portal source, @Nullable Portal destination) {
|
||||
EconomyConfig config = Stargate.getEconomyConfig();
|
||||
//No payment required
|
||||
if (!config.useEconomy() || source.getOptions().isFree()) {
|
||||
@@ -161,7 +163,7 @@ public final class EconomyHelper {
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the player was charged successfully</p>
|
||||
*/
|
||||
public static boolean chargePlayerIfNecessary(Player player, UUID target, int cost) {
|
||||
public static boolean chargePlayerIfNecessary(@NotNull Player player, @NotNull UUID target, int cost) {
|
||||
if (skipPayment(cost)) {
|
||||
return true;
|
||||
}
|
||||
@@ -176,7 +178,7 @@ public final class EconomyHelper {
|
||||
* @param amount <p>The amount to charge</p>
|
||||
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
|
||||
*/
|
||||
private static boolean chargePlayer(Player player, double amount) {
|
||||
private static boolean chargePlayer(@NotNull Player player, double amount) {
|
||||
Economy economy = Stargate.getEconomyConfig().getEconomy();
|
||||
if (Stargate.getEconomyConfig().isEconomyEnabled() && economy != null) {
|
||||
if (!economy.has(player, amount)) {
|
||||
@@ -198,7 +200,7 @@ public final class EconomyHelper {
|
||||
* @param cost <p>The cost to transfer</p>
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private static void transferFees(Economy economy, int cost) {
|
||||
private static void transferFees(@NotNull Economy economy, int cost) {
|
||||
String accountName = Stargate.getEconomyConfig().getTaxAccount();
|
||||
if (accountName == null || accountName.isEmpty()) {
|
||||
return;
|
||||
@@ -220,7 +222,7 @@ public final class EconomyHelper {
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the player was charged successfully</p>
|
||||
*/
|
||||
public static boolean chargePlayerIfNecessary(Player player, int cost) {
|
||||
public static boolean chargePlayerIfNecessary(@NotNull Player player, int cost) {
|
||||
if (skipPayment(cost)) {
|
||||
return true;
|
||||
}
|
||||
@@ -228,8 +230,9 @@ public final class EconomyHelper {
|
||||
boolean charged = chargePlayer(player, cost);
|
||||
|
||||
// Transfer the charged amount to the tax account
|
||||
if (charged) {
|
||||
transferFees(Stargate.getEconomyConfig().getEconomy(), cost);
|
||||
Economy economy = Stargate.getEconomyConfig().getEconomy();
|
||||
if (charged && economy != null) {
|
||||
transferFees(economy, cost);
|
||||
}
|
||||
|
||||
return charged;
|
||||
@@ -253,9 +256,10 @@ public final class EconomyHelper {
|
||||
* @param amount <p>The amount to charge</p>
|
||||
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
|
||||
*/
|
||||
private static boolean chargePlayer(Player player, UUID target, double amount) {
|
||||
private static boolean chargePlayer(@NotNull Player player, @NotNull UUID target, double amount) {
|
||||
Economy economy = Stargate.getEconomyConfig().getEconomy();
|
||||
if (Stargate.getEconomyConfig().isEconomyEnabled() && player.getUniqueId().compareTo(target) != 0 && economy != null) {
|
||||
if (Stargate.getEconomyConfig().isEconomyEnabled() && player.getUniqueId().compareTo(target) != 0 &&
|
||||
economy != null) {
|
||||
if (!economy.has(player, amount)) {
|
||||
return false;
|
||||
}
|
||||
@@ -274,7 +278,8 @@ public final class EconomyHelper {
|
||||
* @param cost <p>The cost for a given interaction</p>
|
||||
* @return <p>The same string with cost and portal variables replaced</p>
|
||||
*/
|
||||
private static String replacePlaceholders(String message, String portalName, int cost) {
|
||||
@NotNull
|
||||
private static String replacePlaceholders(@NotNull String message, @NotNull String portalName, int cost) {
|
||||
return StringFormatter.replacePlaceholders(message, new String[]{"%cost%", "%portal%"},
|
||||
new String[]{Stargate.getEconomyConfig().format(cost), portalName});
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This helper class helps with entity properties not immediately available
|
||||
@@ -21,7 +22,7 @@ public final class EntityHelper {
|
||||
* @param entity <p>The entity to get max size for</p>
|
||||
* @return <p>The max size of the entity</p>
|
||||
*/
|
||||
public static int getEntityMaxSizeInt(Entity entity) {
|
||||
public static int getEntityMaxSizeInt(@NotNull Entity entity) {
|
||||
return (int) Math.ceil((float) getEntityMaxSize(entity));
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ public final class EntityHelper {
|
||||
* @param entity <p>The entity to get max size for</p>
|
||||
* @return <p>The max size of the entity</p>
|
||||
*/
|
||||
public static double getEntityMaxSize(Entity entity) {
|
||||
public static double getEntityMaxSize(@NotNull Entity entity) {
|
||||
return Math.max(entity.getBoundingBox().getWidthX(), entity.getBoundingBox().getWidthZ());
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,18 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class FileHelper {
|
||||
public final class FileHelper {
|
||||
|
||||
private FileHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the stream directly into a string, includes the newline character
|
||||
@@ -15,7 +21,8 @@ public class FileHelper {
|
||||
* @return <p> A String of the file read </p>
|
||||
* @throws IOException <p>If unable to read the stream</p>
|
||||
*/
|
||||
public static String readStreamToString(InputStream stream) throws IOException {
|
||||
@NotNull
|
||||
public static String readStreamToString(@NotNull InputStream stream) throws IOException {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
|
||||
BufferedReader reader = new BufferedReader(inputStreamReader);
|
||||
String line = reader.readLine();
|
||||
|
@@ -5,6 +5,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -31,12 +32,12 @@ public final class GateReader {
|
||||
* @param config <p>The map of config values to store to</p>
|
||||
* @return <p>The column count/width of the loaded gate</p>
|
||||
*/
|
||||
public static int readGateFile(Scanner scanner, Map<Character, Material> characterMaterialMap,
|
||||
Map<Character, Tag<Material>> materialTagMap, String fileName,
|
||||
List<List<Character>> design, Map<String, String> config) {
|
||||
public static int readGateFile(@NotNull Scanner scanner, @NotNull Map<Character, Material> characterMaterialMap,
|
||||
@NotNull Map<Character, Tag<Material>> materialTagMap, @NotNull String fileName,
|
||||
@NotNull List<List<Character>> design, Map<String, String> config) {
|
||||
boolean designing = false;
|
||||
int columns = 0;
|
||||
try {
|
||||
try (scanner) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
|
||||
@@ -59,10 +60,6 @@ public final class GateReader {
|
||||
} catch (Exception exception) {
|
||||
Stargate.logSevere(String.format("Could not load Gate %s - %s", fileName, exception.getMessage()));
|
||||
return -1;
|
||||
} finally {
|
||||
if (scanner != null) {
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
@@ -81,9 +78,10 @@ public final class GateReader {
|
||||
* @param design <p>The two-dimensional list to store the loaded design to</p>
|
||||
* @return <p>The new max columns value of the design</p>
|
||||
*/
|
||||
private static int readGateDesignLine(String line, int maxColumns, Map<Character, Material> characterMaterialMap,
|
||||
Map<Character, Tag<Material>> materialTagMap,
|
||||
String fileName, List<List<Character>> design) {
|
||||
private static int readGateDesignLine(@NotNull String line, int maxColumns,
|
||||
@NotNull Map<Character, Material> characterMaterialMap,
|
||||
@NotNull Map<Character, Tag<Material>> materialTagMap,
|
||||
@NotNull String fileName, @NotNull List<List<Character>> design) {
|
||||
List<Character> row = new ArrayList<>();
|
||||
|
||||
//Update the max columns number if this line has more columns
|
||||
@@ -116,9 +114,9 @@ public final class GateReader {
|
||||
* @param config <p>The config value map to store to</p>
|
||||
* @throws Exception <p>If an invalid material is encountered</p>
|
||||
*/
|
||||
private static void readGateConfigValue(String line, Map<Character, Material> characterMaterialMap,
|
||||
Map<Character, Tag<Material>> materialTagMap,
|
||||
Map<String, String> config) throws Exception {
|
||||
private static void readGateConfigValue(@NotNull String line, @NotNull Map<Character, Material> characterMaterialMap,
|
||||
@NotNull Map<Character, Tag<Material>> materialTagMap,
|
||||
@NotNull Map<String, String> config) throws Exception {
|
||||
String[] split = line.split("=");
|
||||
String key = split[0].trim();
|
||||
String value = split[1].trim();
|
||||
@@ -158,12 +156,13 @@ public final class GateReader {
|
||||
* @param key <p>The config key to read</p>
|
||||
* @return <p>The read value, or -1 if it could not be read</p>
|
||||
*/
|
||||
public static int readGateConfig(Map<String, String> config, String fileName, String key) {
|
||||
public static int readGateConfig(@NotNull Map<String, String> config, @NotNull String fileName,
|
||||
@NotNull String key) {
|
||||
if (config.containsKey(key)) {
|
||||
try {
|
||||
return Integer.parseInt(config.get(key));
|
||||
} catch (NumberFormatException ex) {
|
||||
Stargate.logWarning(String.format("%s reading %s: %s is not numeric", ex.getClass().getName(),
|
||||
} catch (NumberFormatException exception) {
|
||||
Stargate.logWarning(String.format("%s reading %s: %s is not numeric", exception.getClass().getName(),
|
||||
fileName, key));
|
||||
}
|
||||
}
|
||||
@@ -180,8 +179,9 @@ public final class GateReader {
|
||||
* @param defaultMaterial <p>The default material to use, in case the config is invalid</p>
|
||||
* @return <p>The material specified in the config, or the default material if it could not be read</p>
|
||||
*/
|
||||
public static Material readGateConfig(Map<String, String> config, String fileName, String key,
|
||||
Material defaultMaterial) {
|
||||
@NotNull
|
||||
public static Material readGateConfig(@NotNull Map<String, String> config, @NotNull String fileName,
|
||||
@NotNull String key, @NotNull Material defaultMaterial) {
|
||||
if (config.containsKey(key)) {
|
||||
Material material = Material.matchMaterial(config.get(key));
|
||||
if (material != null) {
|
||||
@@ -203,7 +203,8 @@ public final class GateReader {
|
||||
* @param columns <p>The largest amount of columns in the design</p>
|
||||
* @return <p>A matrix containing the gate's layout</p>
|
||||
*/
|
||||
public static Character[][] generateLayoutMatrix(List<List<Character>> design, int columns) {
|
||||
@NotNull
|
||||
public static Character[][] generateLayoutMatrix(@NotNull List<List<Character>> design, int columns) {
|
||||
Character[][] layout = new Character[design.size()][columns];
|
||||
for (int lineIndex = 0; lineIndex < design.size(); lineIndex++) {
|
||||
List<Character> row = design.get(lineIndex);
|
||||
|
@@ -2,6 +2,7 @@ package net.knarcraft.stargate.utility;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This class helps decide properties of materials not already present in the Spigot API
|
||||
@@ -18,7 +19,7 @@ public final class MaterialHelper {
|
||||
* @param material <p>The material to check</p>
|
||||
* @return <p>True if the material is a wall coral</p>
|
||||
*/
|
||||
public static boolean isWallCoral(Material material) {
|
||||
public static boolean isWallCoral(@NotNull Material material) {
|
||||
//Unfortunately, there is no tag for dead wall corals, so they need to be checked manually
|
||||
return Tag.WALL_CORALS.isTagged(material) ||
|
||||
material.equals(Material.DEAD_BRAIN_CORAL_WALL_FAN) ||
|
||||
@@ -34,7 +35,7 @@ public final class MaterialHelper {
|
||||
* @param material <p>The material to check</p>
|
||||
* @return <p>True if the material is a container</p>
|
||||
*/
|
||||
public static boolean isContainer(Material material) {
|
||||
public static boolean isContainer(@NotNull Material material) {
|
||||
return Tag.SHULKER_BOXES.isTagged(material) || material == Material.CHEST ||
|
||||
material == Material.TRAPPED_CHEST || material == Material.ENDER_CHEST;
|
||||
}
|
||||
@@ -45,7 +46,7 @@ public final class MaterialHelper {
|
||||
* @param material <p>The material to check</p>
|
||||
* @return <p>True if the material can be used as a button</p>
|
||||
*/
|
||||
public static boolean isButtonCompatible(Material material) {
|
||||
public static boolean isButtonCompatible(@NotNull Material material) {
|
||||
return Tag.BUTTONS.isTagged(material) || isWallCoral(material) || isContainer(material);
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,8 @@ import net.knarcraft.stargate.portal.property.PortalOption;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.knarcraft.stargate.Stargate.getMaxNameNetworkLength;
|
||||
|
||||
@@ -25,7 +27,7 @@ public final class PermissionHelper {
|
||||
* @param player <p>The player opening the portal</p>
|
||||
* @param portal <p>The portal to open</p>
|
||||
*/
|
||||
public static void openPortal(Player player, Portal portal) {
|
||||
public static void openPortal(@NotNull Player player, @NotNull Portal portal) {
|
||||
Portal destination = portal.getPortalActivator().getDestination();
|
||||
|
||||
//For an always open portal, no action is necessary
|
||||
@@ -89,7 +91,7 @@ public final class PermissionHelper {
|
||||
* @param deny <p>Whether the player's access has already been denied by a previous check</p>
|
||||
* @return <p>False if the player should be allowed through the portal</p>
|
||||
*/
|
||||
public static boolean portalAccessDenied(Player player, Portal portal, boolean deny) {
|
||||
public static boolean portalAccessDenied(@NotNull Player player, @NotNull Portal portal, boolean deny) {
|
||||
StargateAccessEvent event = new StargateAccessEvent(player, portal, deny);
|
||||
Stargate.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
return event.getDeny();
|
||||
@@ -103,7 +105,8 @@ public final class PermissionHelper {
|
||||
* @param destination <p>The portal the user wants to exit from</p>
|
||||
* @return <p>False if the user is allowed to access the portal</p>
|
||||
*/
|
||||
public static boolean cannotAccessPortal(Player player, Portal entrancePortal, Portal destination) {
|
||||
public static boolean cannotAccessPortal(@NotNull Player player, @NotNull Portal entrancePortal,
|
||||
@Nullable Portal destination) {
|
||||
boolean deny = false;
|
||||
|
||||
if (entrancePortal.getOptions().isBungee()) {
|
||||
@@ -116,10 +119,17 @@ public final class PermissionHelper {
|
||||
//If the player does not have access to the network, deny
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access network");
|
||||
deny = true;
|
||||
} else if (PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
||||
//If the player does not have access to the portal's world, deny
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access world");
|
||||
deny = true;
|
||||
} else {
|
||||
if (destination == null) {
|
||||
//If there is no destination, deny
|
||||
Stargate.debug("cannotAccessPortal", "Portal has no destination");
|
||||
deny = true;
|
||||
} else if (destination.getWorld() != null &&
|
||||
PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
||||
//If the player does not have access to the portal's world, deny
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access world");
|
||||
deny = true;
|
||||
}
|
||||
}
|
||||
//Allow other plugins to override whether the player can access the portal
|
||||
return portalAccessDenied(player, entrancePortal, deny);
|
||||
@@ -134,7 +144,7 @@ public final class PermissionHelper {
|
||||
* @param permission <p>The permission to check</p>
|
||||
* @return <p>True if the player has the permission</p>
|
||||
*/
|
||||
public static boolean hasPermission(Player player, String permission) {
|
||||
public static boolean hasPermission(@NotNull Player player, @NotNull String permission) {
|
||||
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
||||
Stargate.debug("hasPerm::Permission(" + player.getName() + ")", permission + " => " +
|
||||
player.hasPermission(permission));
|
||||
@@ -152,7 +162,7 @@ public final class PermissionHelper {
|
||||
* @param permission <p>The permission to check</p>
|
||||
* @return <p>True if the player has the permission implicitly or explicitly</p>
|
||||
*/
|
||||
public static boolean hasPermissionImplicit(Player player, String permission) {
|
||||
public static boolean hasPermissionImplicit(@NotNull Player player, @NotNull String permission) {
|
||||
if (!player.isPermissionSet(permission)) {
|
||||
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
||||
Stargate.debug("hasPermissionImplicit::Permission", permission + " => implicitly true");
|
||||
@@ -173,7 +183,7 @@ public final class PermissionHelper {
|
||||
* @param world <p>The world the player is trying to access</p>
|
||||
* @return <p>False if the player should be allowed to access the world</p>
|
||||
*/
|
||||
public static boolean cannotAccessWorld(Player player, String world) {
|
||||
public static boolean cannotAccessWorld(@NotNull Player player, @NotNull String world) {
|
||||
//The player can access all worlds
|
||||
if (hasPermission(player, "stargate.world")) {
|
||||
//Check if the world permission has been explicitly denied
|
||||
@@ -190,7 +200,7 @@ public final class PermissionHelper {
|
||||
* @param network <p>The network to check</p>
|
||||
* @return <p>True if the player is denied from accessing the network</p>
|
||||
*/
|
||||
public static boolean cannotAccessNetwork(Player player, String network) {
|
||||
public static boolean cannotAccessNetwork(@NotNull Player player, @NotNull String network) {
|
||||
//The player can access all networks
|
||||
if (hasPermission(player, "stargate.network")) {
|
||||
//Check if the world permission has been explicitly denied
|
||||
@@ -215,7 +225,7 @@ public final class PermissionHelper {
|
||||
* @param server <p>The server the player is trying to connect to</p>
|
||||
* @return <p>True if the player is allowed to access the given server</p>
|
||||
*/
|
||||
public static boolean canAccessServer(Player player, String server) {
|
||||
public static boolean canAccessServer(@NotNull Player player, @NotNull String server) {
|
||||
//The player can access all servers
|
||||
if (hasPermission(player, "stargate.server")) {
|
||||
//Check if the server permission has been explicitly denied
|
||||
@@ -233,7 +243,7 @@ public final class PermissionHelper {
|
||||
* @param dest <p>The portal the player wants to teleport to</p>
|
||||
* @return <p>True if the player can travel for free</p>
|
||||
*/
|
||||
public static boolean isFree(Player player, Portal src, Portal dest) {
|
||||
public static boolean isFree(@NotNull Player player, @NotNull Portal src, @Nullable Portal dest) {
|
||||
//This portal is free
|
||||
if (src.getOptions().isFree()) {
|
||||
return true;
|
||||
@@ -255,7 +265,7 @@ public final class PermissionHelper {
|
||||
* @param portal <p>The portal to check</p>
|
||||
* @return <p>True if the given player can see the given portal</p>
|
||||
*/
|
||||
public static boolean canSeePortal(Player player, Portal portal) {
|
||||
public static boolean canSeePortal(@NotNull Player player, @NotNull Portal portal) {
|
||||
//The portal is not hidden
|
||||
if (!portal.getOptions().isHidden()) {
|
||||
return true;
|
||||
@@ -275,7 +285,7 @@ public final class PermissionHelper {
|
||||
* @param portal <p>The private portal used</p>
|
||||
* @return <p>True if the player is allowed to use the portal</p>
|
||||
*/
|
||||
public static boolean canUsePrivatePortal(Player player, Portal portal) {
|
||||
public static boolean canUsePrivatePortal(@NotNull Player player, @NotNull Portal portal) {
|
||||
//Check if the player is the owner of the gate
|
||||
if (portal.isOwner(player)) {
|
||||
return true;
|
||||
@@ -291,7 +301,7 @@ public final class PermissionHelper {
|
||||
* @param option <p>The option the player is trying to use</p>
|
||||
* @return <p>True if the player is allowed to create a portal with the given option</p>
|
||||
*/
|
||||
public static boolean canUseOption(Player player, PortalOption option) {
|
||||
public static boolean canUseOption(@NotNull Player player, @NotNull PortalOption option) {
|
||||
return hasPermission(player, option.getPermissionString());
|
||||
}
|
||||
|
||||
@@ -302,7 +312,7 @@ public final class PermissionHelper {
|
||||
* @param network <p>The network the player is trying to create a gate on</p>
|
||||
* @return <p>True if the player is allowed to create the new gate</p>
|
||||
*/
|
||||
public static boolean canCreateNetworkGate(Player player, String network) {
|
||||
public static boolean canCreateNetworkGate(@NotNull Player player, @NotNull String network) {
|
||||
//Check if the player is allowed to create a portal on any network
|
||||
if (hasPermission(player, "stargate.create.network")) {
|
||||
//Check if the network has been explicitly denied
|
||||
@@ -318,7 +328,7 @@ public final class PermissionHelper {
|
||||
* @param player <p>The player trying to create the new gate</p>
|
||||
* @return <p>True if the player is allowed</p>
|
||||
*/
|
||||
public static boolean canCreatePersonalPortal(Player player) {
|
||||
public static boolean canCreatePersonalPortal(@NotNull Player player) {
|
||||
return hasPermission(player, "stargate.create.personal");
|
||||
}
|
||||
|
||||
@@ -329,7 +339,7 @@ public final class PermissionHelper {
|
||||
* @param gate <p>The gate type of the new portal</p>
|
||||
* @return <p>True if the player is allowed to create a portal with the given gate layout</p>
|
||||
*/
|
||||
public static boolean canCreatePortal(Player player, String gate) {
|
||||
public static boolean canCreatePortal(@NotNull Player player, @NotNull String gate) {
|
||||
//Check if the player is allowed to create all gates
|
||||
if (hasPermission(player, "stargate.create.gate")) {
|
||||
//Check if the gate type has been explicitly denied
|
||||
@@ -346,7 +356,7 @@ public final class PermissionHelper {
|
||||
* @param portal <p>The portal to destroy</p>
|
||||
* @return <p>True if the player is allowed to destroy the portal</p>
|
||||
*/
|
||||
public static boolean canDestroyPortal(Player player, Portal portal) {
|
||||
public static boolean canDestroyPortal(@NotNull Player player, @NotNull Portal portal) {
|
||||
String network = portal.getCleanNetwork();
|
||||
|
||||
//Use a special check for bungee portals
|
||||
@@ -376,7 +386,8 @@ public final class PermissionHelper {
|
||||
* @param event <p>The move event causing the teleportation</p>
|
||||
* @return <p>True if the player cannot teleport. False otherwise</p>
|
||||
*/
|
||||
public static boolean playerCannotTeleport(Portal entrancePortal, Portal destination, Player player, PlayerMoveEvent event) {
|
||||
public static boolean playerCannotTeleport(@Nullable Portal entrancePortal, @Nullable Portal destination,
|
||||
@NotNull Player player, @Nullable PlayerMoveEvent event) {
|
||||
//No portal or not open
|
||||
if (entrancePortal == null || !entrancePortal.isOpen()) {
|
||||
return true;
|
||||
@@ -392,12 +403,13 @@ public final class PermissionHelper {
|
||||
}
|
||||
|
||||
//No destination
|
||||
if (!entrancePortal.getOptions().isBungee() && destination == null) {
|
||||
boolean isBungee = entrancePortal.getOptions().isBungee();
|
||||
if (!isBungee && destination == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Player cannot access portal
|
||||
if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destination)) {
|
||||
if (!PermissionHelper.cannotAccessPortal(player, entrancePortal, destination)) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -43,7 +45,7 @@ public final class PortalFileHelper {
|
||||
*
|
||||
* @param world <p>The world to save portals for</p>
|
||||
*/
|
||||
public static void saveAllPortals(World world) {
|
||||
public static void saveAllPortals(@NotNull World world) {
|
||||
Stargate.getStargateConfig().addManagedWorld(world.getName());
|
||||
String saveFileLocation = Stargate.getPortalFolder() + "/" + world.getName() + ".db";
|
||||
|
||||
@@ -52,6 +54,11 @@ public final class PortalFileHelper {
|
||||
|
||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||
//Skip portals in other worlds
|
||||
if (portal.getWorld() == null) {
|
||||
Stargate.logSevere(String.format("Could not save portal %s because its world is null",
|
||||
portal.getName()));
|
||||
continue;
|
||||
}
|
||||
String worldName = portal.getWorld().getName();
|
||||
if (!worldName.equalsIgnoreCase(world.getName())) {
|
||||
continue;
|
||||
@@ -61,8 +68,8 @@ public final class PortalFileHelper {
|
||||
}
|
||||
|
||||
bufferedWriter.close();
|
||||
} catch (Exception e) {
|
||||
Stargate.logSevere(String.format("Exception while writing stargates to %s: %s", saveFileLocation, e));
|
||||
} catch (Exception exception) {
|
||||
Stargate.logSevere(String.format("Exception while writing stargates to %s: %s", saveFileLocation, exception));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,13 +80,13 @@ public final class PortalFileHelper {
|
||||
* @param portal <p>The portal to save</p>
|
||||
* @throws IOException <p>If unable to write to the buffered writer</p>
|
||||
*/
|
||||
private static void savePortal(BufferedWriter bufferedWriter, Portal portal) throws IOException {
|
||||
private static void savePortal(@NotNull BufferedWriter bufferedWriter, @NotNull Portal portal) throws IOException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
BlockLocation button = portal.getStructure().getButton();
|
||||
|
||||
//WARNING: Because of the primitive save format, any change in order will break everything!
|
||||
builder.append(portal.getName()).append(':');
|
||||
builder.append(portal.getSignLocation().toString()).append(':');
|
||||
builder.append(portal.getSignLocation()).append(':');
|
||||
builder.append((button != null) ? button.toString() : "").append(':');
|
||||
|
||||
//Add removes config values to keep indices consistent
|
||||
@@ -87,7 +94,7 @@ public final class PortalFileHelper {
|
||||
builder.append(0).append(':');
|
||||
|
||||
builder.append(portal.getYaw()).append(':');
|
||||
builder.append(portal.getTopLeft().toString()).append(':');
|
||||
builder.append(portal.getTopLeft()).append(':');
|
||||
builder.append(portal.getGate().getFilename()).append(':');
|
||||
|
||||
//Only save the destination name if the gate is fixed as it doesn't matter otherwise
|
||||
@@ -111,13 +118,17 @@ public final class PortalFileHelper {
|
||||
* @param portal <p>The portal to save</p>
|
||||
* @param builder <p>The string builder to append to</p>
|
||||
*/
|
||||
private static void savePortalOptions(Portal portal, StringBuilder builder) {
|
||||
private static void savePortalOptions(@NotNull Portal portal, @NotNull StringBuilder builder) {
|
||||
PortalOptions options = portal.getOptions();
|
||||
builder.append(':');
|
||||
builder.append(options.isHidden()).append(':');
|
||||
builder.append(options.isAlwaysOn()).append(':');
|
||||
builder.append(options.isPrivate()).append(':');
|
||||
builder.append(portal.getWorld().getName()).append(':');
|
||||
if (portal.getWorld() != null) {
|
||||
builder.append(portal.getWorld().getName()).append(':');
|
||||
} else {
|
||||
builder.append(':');
|
||||
}
|
||||
builder.append(options.isFree()).append(':');
|
||||
builder.append(options.isBackwards()).append(':');
|
||||
builder.append(options.isShown()).append(':');
|
||||
@@ -134,7 +145,7 @@ public final class PortalFileHelper {
|
||||
* @param world <p>The world to load portals for</p>
|
||||
* @return <p>True if portals could be loaded</p>
|
||||
*/
|
||||
public static boolean loadAllPortals(World world) {
|
||||
public static boolean loadAllPortals(@NotNull World world) {
|
||||
String location = Stargate.getPortalFolder();
|
||||
|
||||
File database = new File(location, world.getName() + ".db");
|
||||
@@ -154,7 +165,7 @@ public final class PortalFileHelper {
|
||||
* @param database <p>The database file containing the portals</p>
|
||||
* @return <p>True if the portals were loaded successfully</p>
|
||||
*/
|
||||
private static boolean loadPortals(World world, File database) {
|
||||
private static boolean loadPortals(@NotNull World world, @NotNull File database) {
|
||||
int lineIndex = 0;
|
||||
try {
|
||||
Scanner scanner = new Scanner(database);
|
||||
@@ -185,7 +196,7 @@ public final class PortalFileHelper {
|
||||
* @param world <p>The world for which portals are currently being read</p>
|
||||
* @return <p>True if the read portal has changed and the world's database needs to be saved</p>
|
||||
*/
|
||||
private static boolean readPortalLine(Scanner scanner, int lineIndex, World world) {
|
||||
private static boolean readPortalLine(@NotNull Scanner scanner, int lineIndex, @NotNull World world) {
|
||||
String line = scanner.nextLine().trim();
|
||||
|
||||
//Ignore empty and comment lines
|
||||
@@ -213,7 +224,7 @@ public final class PortalFileHelper {
|
||||
* @param world <p>The world portals have been loaded for</p>
|
||||
* @param needsToSaveDatabase <p>Whether the portal database's file needs to be updated</p>
|
||||
*/
|
||||
private static void doPostLoadTasks(World world, boolean needsToSaveDatabase) {
|
||||
private static void doPostLoadTasks(@NotNull World world, boolean needsToSaveDatabase) {
|
||||
//Open any always-on portals. Do this here as it should be more efficient than in the loop.
|
||||
PortalHandler.verifyAllPortals();
|
||||
int portalCount = PortalRegistry.getAllPortals().size();
|
||||
@@ -245,7 +256,7 @@ public final class PortalFileHelper {
|
||||
* @param lineIndex <p>The line index to report in case the user needs to fix an error</p>
|
||||
* @return <p>True if the portal's data has changed and its database needs to be updated</p>
|
||||
*/
|
||||
private static boolean loadPortal(String[] portalData, World world, int lineIndex) {
|
||||
private static boolean loadPortal(@NotNull String[] portalData, @NotNull World world, int lineIndex) {
|
||||
//Load min. required portal data
|
||||
String name = portalData[0];
|
||||
BlockLocation button = (portalData[2].length() > 0) ? new BlockLocation(world, portalData[2]) : null;
|
||||
@@ -289,17 +300,21 @@ public final class PortalFileHelper {
|
||||
*
|
||||
* @param portal <p>The portal update the button of</p>
|
||||
*/
|
||||
private static void updatePortalButton(Portal portal) {
|
||||
private static void updatePortalButton(@NotNull Portal portal) {
|
||||
BlockLocation buttonLocation = getButtonLocation(portal);
|
||||
if (buttonLocation == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (portal.getOptions().isAlwaysOn()) {
|
||||
//Clear button if not already air or water
|
||||
//Clear button if it exists
|
||||
if (MaterialHelper.isButtonCompatible(buttonLocation.getType())) {
|
||||
Material newMaterial = decideRemovalMaterial(buttonLocation, portal);
|
||||
Stargate.addBlockChangeRequest(new BlockChangeRequest(buttonLocation, newMaterial, null));
|
||||
}
|
||||
} else {
|
||||
//Replace button if the material does not match
|
||||
if (buttonLocation.getType() != portal.getGate().getPortalButton()) {
|
||||
//Replace button if the material is not a button
|
||||
if (!MaterialHelper.isButtonCompatible(buttonLocation.getType())) {
|
||||
generatePortalButton(portal, DirectionHelper.getBlockFaceFromYaw(portal.getYaw()));
|
||||
}
|
||||
}
|
||||
@@ -312,7 +327,8 @@ public final class PortalFileHelper {
|
||||
* @param portal <p>The portal the button/sign belongs to</p>
|
||||
* @return <p>The material to use for removing the button/sign</p>
|
||||
*/
|
||||
public static Material decideRemovalMaterial(BlockLocation location, Portal portal) {
|
||||
@NotNull
|
||||
public static Material decideRemovalMaterial(@NotNull BlockLocation location, @NotNull Portal portal) {
|
||||
//Get the blocks to each side of the location
|
||||
Location leftLocation = location.getRelativeLocation(-1, 0, 0, portal.getYaw());
|
||||
Location rightLocation = location.getRelativeLocation(1, 0, 0, portal.getYaw());
|
||||
@@ -333,7 +349,7 @@ public final class PortalFileHelper {
|
||||
* @param location <p>The location to check</p>
|
||||
* @return <p>True if the location is underwater</p>
|
||||
*/
|
||||
private static boolean isUnderwater(Location location) {
|
||||
private static boolean isUnderwater(@NotNull Location location) {
|
||||
BlockData blockData = location.getBlock().getBlockData();
|
||||
return blockData.getMaterial() == Material.WATER ||
|
||||
(blockData instanceof Waterlogged waterlogged && waterlogged.isWaterlogged());
|
||||
@@ -348,7 +364,7 @@ public final class PortalFileHelper {
|
||||
* @param portal <p>The portal to update the button vector for</p>
|
||||
* @return <p>True if the calculated button location is not the same as the one in the portal file</p>
|
||||
*/
|
||||
private static boolean updateButtonVector(Portal portal) {
|
||||
private static boolean updateButtonVector(@NotNull Portal portal) {
|
||||
for (RelativeBlockVector control : portal.getGate().getLayout().getControls()) {
|
||||
BlockLocation controlLocation = portal.getLocation().getTopLeft().getRelativeLocation(control,
|
||||
portal.getYaw());
|
||||
@@ -374,10 +390,15 @@ public final class PortalFileHelper {
|
||||
* @param portal <p>The portal to generate button for</p>
|
||||
* @param buttonFacing <p>The direction the button should be facing</p>
|
||||
*/
|
||||
public static void generatePortalButton(Portal portal, BlockFace buttonFacing) {
|
||||
public static void generatePortalButton(@NotNull Portal portal, @NotNull BlockFace buttonFacing) {
|
||||
//Go one block outwards to find the button's location rather than the control block's location
|
||||
BlockLocation button = getButtonLocation(portal);
|
||||
|
||||
// If the button location is null here, it is assumed that the button generation wasn't necessary
|
||||
if (button == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Directional buttonData = (Directional) Bukkit.createBlockData(portal.getGate().getPortalButton());
|
||||
buttonData.setFacing(buttonFacing);
|
||||
button.getBlock().setBlockData(buttonData);
|
||||
@@ -390,11 +411,16 @@ public final class PortalFileHelper {
|
||||
* @param portal <p>The portal to find the button for</p>
|
||||
* @return <p>The location of the portal's button</p>
|
||||
*/
|
||||
private static BlockLocation getButtonLocation(Portal portal) {
|
||||
@Nullable
|
||||
private static BlockLocation getButtonLocation(@NotNull Portal portal) {
|
||||
BlockLocation topLeft = portal.getTopLeft();
|
||||
RelativeBlockVector buttonVector = portal.getLocation().getButtonVector();
|
||||
return topLeft.getRelativeLocation(buttonVector.addToVector(RelativeBlockVector.Property.OUT, 1),
|
||||
portal.getYaw());
|
||||
|
||||
if (buttonVector == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return topLeft.getRelativeLocation(buttonVector.addOut(1), portal.getYaw());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package net.knarcraft.stargate.utility;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.sign.Side;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A helper class for dealing with signs
|
||||
@@ -21,7 +23,8 @@ public final class SignHelper {
|
||||
* @param sign <p>The sign to check</p>
|
||||
* @return <p>The dye currently applied to the sign</p>
|
||||
*/
|
||||
public static DyeColor getDye(Sign sign) {
|
||||
@Nullable
|
||||
public static DyeColor getDye(@NotNull Sign sign) {
|
||||
if (HAS_SIGN_SIDES) {
|
||||
return sign.getSide(Side.FRONT).getColor();
|
||||
} else {
|
||||
@@ -38,7 +41,7 @@ public final class SignHelper {
|
||||
* @param line <p>The line to set</p>
|
||||
* @param text <p>The text to set</p>
|
||||
*/
|
||||
public static void setSignLine(Sign sign, int line, String text) {
|
||||
public static void setSignLine(@NotNull Sign sign, int line, @NotNull String text) {
|
||||
if (HAS_SIGN_SIDES) {
|
||||
sign.getSide(Side.FRONT).setLine(line, text);
|
||||
} else {
|
||||
|
@@ -10,6 +10,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -31,7 +32,7 @@ public final class TeleportHelper {
|
||||
* @param player <p>The player trying to teleport</p>
|
||||
* @return <p>False if the player has leashed any creatures that cannot go through the portal</p>
|
||||
*/
|
||||
public static boolean noLeashedCreaturesPreventTeleportation(Player player) {
|
||||
public static boolean noLeashedCreaturesPreventTeleportation(@NotNull Player player) {
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Creature> nearbyCreatures = getLeashedCreatures(player);
|
||||
|
||||
@@ -56,7 +57,8 @@ public final class TeleportHelper {
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>A list of all creatures the player is holding in a leash (lead)</p>
|
||||
*/
|
||||
public static List<Creature> getLeashedCreatures(Player player) {
|
||||
@NotNull
|
||||
public static List<Creature> getLeashedCreatures(@NotNull Player player) {
|
||||
List<Creature> leashedCreatures = new ArrayList<>();
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
|
||||
@@ -80,8 +82,8 @@ public final class TeleportHelper {
|
||||
* @param exitDirection <p>The direction of any passengers exiting the stargate</p>
|
||||
* @param newVelocity <p>The new velocity of the teleported passenger</p>
|
||||
*/
|
||||
public static void teleportAndAddPassenger(Entity targetVehicle, Entity passenger, Vector exitDirection,
|
||||
Vector newVelocity) {
|
||||
public static void teleportAndAddPassenger(@NotNull Entity targetVehicle, @NotNull Entity passenger,
|
||||
@NotNull Vector exitDirection, @NotNull Vector newVelocity) {
|
||||
Location passengerExit = targetVehicle.getLocation().clone().setDirection(exitDirection);
|
||||
if (!passenger.teleport(passengerExit)) {
|
||||
Stargate.debug("TeleportHelper::handleVehiclePassengers", "Failed to teleport passenger" +
|
||||
@@ -112,8 +114,9 @@ public final class TeleportHelper {
|
||||
* @param exitRotation <p>The rotation of any passengers exiting the stargate</p>
|
||||
* @param newVelocity <p>The new velocity of the teleported passengers</p>
|
||||
*/
|
||||
public static void handleEntityPassengers(List<Entity> passengers, Entity entity, Portal origin, Portal target,
|
||||
Vector exitRotation, Vector newVelocity) {
|
||||
public static void handleEntityPassengers(@NotNull List<Entity> passengers, @NotNull Entity entity,
|
||||
@NotNull Portal origin, @NotNull Portal target,
|
||||
@NotNull Vector exitRotation, @NotNull Vector newVelocity) {
|
||||
for (Entity passenger : passengers) {
|
||||
List<Entity> passengerPassengers = passenger.getPassengers();
|
||||
if (!passengerPassengers.isEmpty()) {
|
||||
@@ -144,7 +147,7 @@ public final class TeleportHelper {
|
||||
* @param origin <p>The portal the player is teleporting from</p>
|
||||
* @param target <p>The portal the player is teleporting to</p>
|
||||
*/
|
||||
public static void teleportLeashedCreatures(Player player, Portal origin, Portal target) {
|
||||
public static void teleportLeashedCreatures(@NotNull Player player, @NotNull Portal origin, @NotNull Portal target) {
|
||||
//If this feature is disabled, just return
|
||||
if (!Stargate.getGateConfig().handleLeashedCreatures()) {
|
||||
return;
|
||||
@@ -171,7 +174,7 @@ public final class TeleportHelper {
|
||||
* @param entities <p>The list of entities to check</p>
|
||||
* @return <p>True if at least one entity is not a player</p>
|
||||
*/
|
||||
public static boolean containsNonPlayer(List<Entity> entities) {
|
||||
public static boolean containsNonPlayer(@NotNull List<Entity> entities) {
|
||||
for (Entity entity : entities) {
|
||||
if (!(entity instanceof Player) || containsNonPlayer(entity.getPassengers())) {
|
||||
return true;
|
||||
@@ -186,7 +189,7 @@ public final class TeleportHelper {
|
||||
* @param entities <p>The list of entities to check</p>
|
||||
* @return <p>True if at least one player is present among the passengers</p>
|
||||
*/
|
||||
public static boolean containsPlayer(List<Entity> entities) {
|
||||
public static boolean containsPlayer(@NotNull List<Entity> entities) {
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof Player || containsPlayer(entity.getPassengers())) {
|
||||
return true;
|
||||
@@ -201,7 +204,8 @@ public final class TeleportHelper {
|
||||
* @param entities <p>The entities to check for players</p>
|
||||
* @return <p>The found players</p>
|
||||
*/
|
||||
public static List<Player> getPlayers(List<Entity> entities) {
|
||||
@NotNull
|
||||
public static List<Player> getPlayers(@NotNull List<Entity> entities) {
|
||||
List<Player> players = new ArrayList<>(5);
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof Player) {
|
||||
@@ -220,7 +224,8 @@ public final class TeleportHelper {
|
||||
* @param destinationPortal <p>The portal the player is to exit from</p>
|
||||
* @return <p>True if the player is allowed to teleport and is able to pay necessary fees</p>
|
||||
*/
|
||||
public static boolean playerCanTeleport(Player player, Portal entrancePortal, Portal destinationPortal) {
|
||||
public static boolean playerCanTeleport(@NotNull Player player, @NotNull Portal entrancePortal,
|
||||
@NotNull Portal destinationPortal) {
|
||||
//Make sure the user can access the portal
|
||||
if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destinationPortal)) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
|
@@ -7,6 +7,7 @@ import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -35,7 +36,7 @@ public final class UUIDMigrationHelper {
|
||||
*
|
||||
* @param player <p>The player to migrate</p>
|
||||
*/
|
||||
public static void migrateUUID(OfflinePlayer player) {
|
||||
public static void migrateUUID(@NotNull OfflinePlayer player) {
|
||||
Map<String, List<Portal>> playersToMigrate = getPlayersToMigrate();
|
||||
String playerName = player.getName();
|
||||
|
||||
@@ -53,7 +54,7 @@ public final class UUIDMigrationHelper {
|
||||
|
||||
migratePortalsToUUID(portalsOwned, player.getUniqueId());
|
||||
|
||||
//Remove the player to prevent the migration to happen every time the player joins
|
||||
//Remove the player to prevent the migration from happening every time the player joins
|
||||
playersToMigrate.remove(playerName);
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ public final class UUIDMigrationHelper {
|
||||
* @param portals <p>The portals to migrate</p>
|
||||
* @param uniqueId <p>The unique ID of the portals' owner</p>
|
||||
*/
|
||||
private static void migratePortalsToUUID(List<Portal> portals, UUID uniqueId) {
|
||||
private static void migratePortalsToUUID(@NotNull List<Portal> portals, @NotNull UUID uniqueId) {
|
||||
Set<World> worldsToSave = new HashSet<>();
|
||||
|
||||
//Get the real portal from the copy and set UUID
|
||||
@@ -86,6 +87,7 @@ public final class UUIDMigrationHelper {
|
||||
*
|
||||
* @return <p>The player names to migrate</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static Map<String, List<Portal>> getPlayersToMigrate() {
|
||||
//Make sure to only go through portals once
|
||||
if (playerNamesToMigrate != null) {
|
||||
|
Reference in New Issue
Block a user