diff --git a/src/main/java/tech/sbdevelopment/v10lift/V10LiftPlugin.java b/src/main/java/tech/sbdevelopment/v10lift/V10LiftPlugin.java index c44563a..146ec0c 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/V10LiftPlugin.java +++ b/src/main/java/tech/sbdevelopment/v10lift/V10LiftPlugin.java @@ -1,5 +1,10 @@ package tech.sbdevelopment.v10lift; +import lombok.Getter; +import org.bstats.bukkit.Metrics; +import org.bstats.charts.SingleLineChart; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; import tech.sbdevelopment.v10lift.commands.V10LiftCommand; import tech.sbdevelopment.v10lift.commands.V10LiftTabCompleter; import tech.sbdevelopment.v10lift.listeners.BlockBreakListener; @@ -12,10 +17,6 @@ import tech.sbdevelopment.v10lift.managers.VaultManager; import tech.sbdevelopment.v10lift.sbutils.ConfigUpdater; import tech.sbdevelopment.v10lift.sbutils.UpdateManager; import tech.sbdevelopment.v10lift.sbutils.YamlFile; -import org.bstats.bukkit.Metrics; -import org.bstats.charts.SingleLineChart; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; import java.sql.SQLException; @@ -23,9 +24,11 @@ import java.util.Collections; public class V10LiftPlugin extends JavaPlugin { + @Getter private static V10LiftPlugin instance; private static YamlFile config; private static DBManager dbManager; + @Getter private static YamlFile messages; private static boolean vault = false; @@ -129,10 +132,6 @@ public class V10LiftPlugin extends JavaPlugin { instance = null; } - public static V10LiftPlugin getInstance() { - return instance; - } - public static YamlFile getSConfig() { return config; } @@ -141,10 +140,6 @@ public class V10LiftPlugin extends JavaPlugin { return dbManager; } - public static YamlFile getMessages() { - return messages; - } - public static boolean isVaultEnabled() { return vault; } diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/V10LiftAPI.java b/src/main/java/tech/sbdevelopment/v10lift/api/V10LiftAPI.java index 0abe984..4dfa6dd 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/V10LiftAPI.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/V10LiftAPI.java @@ -1,6 +1,14 @@ package tech.sbdevelopment.v10lift.api; import com.cryptomorin.xseries.XMaterial; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import tech.sbdevelopment.v10lift.V10LiftPlugin; import tech.sbdevelopment.v10lift.api.objects.*; import tech.sbdevelopment.v10lift.api.runnables.DoorCloser; @@ -11,24 +19,18 @@ import tech.sbdevelopment.v10lift.sbutils.LocationSerializer; import tech.sbdevelopment.v10lift.utils.ConfigUtil; import tech.sbdevelopment.v10lift.utils.DirectionUtil; import tech.sbdevelopment.v10lift.utils.DoorUtil; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import tech.sbdevelopment.v10lift.api.objects.*; import javax.annotation.Nonnull; import java.util.*; -/** The Main API class, for all the API methods */ +/** + * The Main API class, for all the API methods + */ public class V10LiftAPI { private static V10LiftAPI instance; - private V10LiftAPI() {} + private V10LiftAPI() { + } public static V10LiftAPI getInstance() { if (instance == null) instance = new V10LiftAPI(); @@ -64,7 +66,7 @@ public class V10LiftAPI { /** * Create a new Lift * - * @param p The player [owner] of the lift + * @param p The player [owner] of the lift * @param liftName The name of the lift * @return true if created, false if null or already exists */ @@ -137,7 +139,7 @@ public class V10LiftAPI { * Rename a lift * * @param liftName The name of the lift - * @param newName The new name of the lift + * @param newName The new name of the lift */ public void renameLift(String liftName, String newName) { if (liftName == null || newName == null || !DataManager.containsLift(liftName)) return; @@ -160,7 +162,7 @@ public class V10LiftAPI { * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * * @param liftName The name of the lift - * @param block The block + * @param block The block * @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added */ public int addBlockToLift(String liftName, Block block) { @@ -174,7 +176,7 @@ public class V10LiftAPI { * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * * @param blocks The blockset - * @param block The block + * @param block The block * @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added */ public int addBlockToLift(Set blocks, @Nonnull Block block) { @@ -214,7 +216,7 @@ public class V10LiftAPI { * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * * @param blocks The blockset - * @param block The LiftBlock + * @param block The LiftBlock * @return 0 if added, -2 if forbidden, -3 if already added */ public int addBlockToLift(@Nonnull Set blocks, @Nonnull LiftBlock block) { @@ -229,7 +231,7 @@ public class V10LiftAPI { * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * * @param liftName The name of the lift - * @param block The block + * @param block The block * @return 0 if removed, -1 if null or doesn't exists, -2 if not added */ public int removeBlockFromLift(String liftName, Block block) { @@ -273,11 +275,11 @@ public class V10LiftAPI { * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * * @param liftName The name of the lift - * @param block The block + * @param block The block * @return 0 if added, 1 if removed, -1 if null or doesn't exists, -2 if not added */ public int switchBlockAtLift(String liftName, Block block) { - if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1; + if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1; return switchBlockAtLift(DataManager.getLift(liftName).getBlocks(), block); } @@ -286,11 +288,11 @@ public class V10LiftAPI { * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * * @param blocks The blockset - * @param block The block + * @param block The block * @return 0 if added, 1 if removed, -1 if null or doesn't exists, -2 if not added */ public int switchBlockAtLift(TreeSet blocks, Block block) { - if (blocks == null || block == null) return -1; + if (blocks == null || block == null) return -1; Material type = block.getType(); if (ForbiddenBlockManager.isForbidden(type)) return -2; LiftBlock lb; @@ -394,9 +396,9 @@ public class V10LiftAPI { /** * Open the door * - * @param lift The lift + * @param lift The lift * @param liftName The name of the lift - * @param f The floor + * @param f The floor * @return true/false */ public boolean openDoor(Lift lift, String liftName, Floor f) { @@ -498,14 +500,16 @@ public class V10LiftAPI { /** * Adds a new floor to a lift * - * @param liftName The name of the lift + * @param liftName The name of the lift * @param floorName The name of the floor - * @param floor The floor object + * @param floor The floor object * @return 0 if added, -1 if null or doesn't exists, -2 if height is to high, -3 if floor already exists */ public int addFloor(String liftName, String floorName, Floor floor) { - if (liftName == null || floorName == null || floor == null || !DataManager.containsLift(liftName) || floor.getWorld() == null) return -1; - if (floor.getY() > Objects.requireNonNull(Bukkit.getServer().getWorld(floor.getWorld()), "World is null at addNewFloor!").getMaxHeight()) return -2; + if (liftName == null || floorName == null || floor == null || !DataManager.containsLift(liftName) || floor.getWorld() == null) + return -1; + if (floor.getY() > Objects.requireNonNull(Bukkit.getServer().getWorld(floor.getWorld()), "World is null at addNewFloor!").getMaxHeight()) + return -2; if (floorName.length() > 13) floorName = floorName.substring(0, 13).trim(); Lift lift = DataManager.getLift(liftName); if (lift.getFloors().containsKey(floorName) || lift.getFloors().containsValue(floor)) return -3; @@ -518,7 +522,7 @@ public class V10LiftAPI { /** * Removes a floor from a lift * - * @param liftName The name of the lift + * @param liftName The name of the lift * @param floorName The name of the floor * @return true if removed, false if null or doesn't exists */ @@ -536,8 +540,8 @@ public class V10LiftAPI { * Rename a floor from a lift * * @param liftName The name of the lift - * @param oldName The old name of the floor - * @param newName The new name of the floor + * @param oldName The old name of the floor + * @param newName The new name of the floor * @return 0 if renamed, -1 if null or doesn't exists, -2 if floor doesn't exists, -3 if floor already exists */ public int renameFloor(String liftName, String oldName, String newName) { @@ -580,7 +584,7 @@ public class V10LiftAPI { * Set a lift to (not) defective * * @param liftName The name of the lift - * @param state true/false + * @param state true/false * @return 0 if set, -1 if null or doesn't exists, -2 if same state, -3 if no signs, -4 if wrong sign */ public int setDefective(String liftName, boolean state) { @@ -650,7 +654,7 @@ public class V10LiftAPI { /** * Get the userWhitelist of a lift * - * @param liftName The name of the lift + * @param liftName The name of the lift * @param floorName The name of the floor * @return list with UUIDs of the players */ @@ -668,7 +672,7 @@ public class V10LiftAPI { /** * Get the groupWhitelist of a lift * - * @param liftName The name of the lift + * @param liftName The name of the lift * @param floorName The name of the floor * @return list with groupnames */ @@ -698,7 +702,7 @@ public class V10LiftAPI { * Set a lift to (not) offline * * @param liftName The name of the lift - * @param state true/false + * @param state true/false * @return 0 if set, -1 if null or doesn't exists, -2 if same state */ public int setOffline(String liftName, boolean state) { @@ -764,8 +768,7 @@ public class V10LiftAPI { * Check if a lift contains the block as rope * * @param liftName The name of the lift - * @param block The block - * + * @param block The block * @return true/false */ public boolean containsRope(String liftName, Block block) { @@ -792,7 +795,6 @@ public class V10LiftAPI { * Check if a block is a rope * * @param b The block - * * @return true/false */ public boolean isRope(Block b) { @@ -804,7 +806,8 @@ public class V10LiftAPI { /** * Send info about a lift to a player - * @param sender Where you want to send it to + * + * @param sender Where you want to send it to * @param liftName The name of the lift */ public void sendLiftInfo(CommandSender sender, String liftName) { @@ -813,9 +816,10 @@ public class V10LiftAPI { /** * Send info about a lift to a player - * @param ent Where you want to send it to + * + * @param ent Where you want to send it to * @param liftName The name of the lift - * @param lift The lift + * @param lift The lift */ public void sendLiftInfo(@Nonnull CommandSender ent, String liftName, @Nonnull Lift lift) { @@ -867,12 +871,12 @@ public class V10LiftAPI { /** * Add a rope to a lift * - * @param lift The name of the lift + * @param lift The name of the lift * @param world The world - * @param x The x-pos - * @param minY The min y-pos - * @param maxY The max y-pos - * @param z The z-pos + * @param x The x-pos + * @param minY The min y-pos + * @param maxY The max y-pos + * @param z The z-pos * @return 0 if added, -1 if null or doesn't exists, -2 if not same mat, -3 if already a rope, -4 if forbidden material */ public int addRope(String lift, World world, int x, int minY, int maxY, int z) { @@ -914,13 +918,13 @@ public class V10LiftAPI { /** * Remove a rope from a lift * - * @param lift The name of the lift + * @param lift The name of the lift * @param block The block - * * @return true/false */ public boolean removeRope(String lift, Block block) { - if (lift == null || block == null || !DataManager.containsLift(lift) || !containsRope(lift, block)) return false; + if (lift == null || block == null || !DataManager.containsLift(lift) || !containsRope(lift, block)) + return false; String world = block.getWorld().getName(); int x = block.getX(); @@ -944,7 +948,7 @@ public class V10LiftAPI { * Set the queue of a lift * * @param liftName The name of the lift - * @param queue The queue + * @param queue The queue * @return true/false */ public boolean setQueue(String liftName, LinkedHashMap queue) { @@ -961,10 +965,9 @@ public class V10LiftAPI { /** * Add a location to the queue * - * @param lift The name of the lift - * @param y The y-pos + * @param lift The name of the lift + * @param y The y-pos * @param world The world - * * @return true/false */ public boolean addToQueue(String lift, int y, World world) { @@ -974,11 +977,10 @@ public class V10LiftAPI { /** * Add a location to the queue * - * @param lift The name of the lift - * @param y The y-pos - * @param world The world + * @param lift The name of the lift + * @param y The y-pos + * @param world The world * @param floorName The name of the flor - * * @return true/false */ public boolean addToQueue(String lift, int y, @Nonnull World world, String floorName) { @@ -988,10 +990,9 @@ public class V10LiftAPI { /** * Add a location to the queue * - * @param lift The name of the lift - * @param floor The {@link Floor} + * @param lift The name of the lift + * @param floor The {@link Floor} * @param floorName The name of the flor - * * @return true/false */ public boolean addToQueue(String lift, Floor floor, String floorName) { diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/objects/Floor.java b/src/main/java/tech/sbdevelopment/v10lift/api/objects/Floor.java index d831ac1..38ad25c 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/objects/Floor.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/objects/Floor.java @@ -9,8 +9,13 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; -/** A floor object, for a floor in the lift. */ -@Getter @Setter @NoArgsConstructor @ToString +/** + * A floor object, for a floor in the lift. + */ +@Getter +@Setter +@NoArgsConstructor +@ToString public class Floor { private String world; private int y; @@ -22,7 +27,7 @@ public class Floor { /** * Construct a new Floor * - * @param y The y/height of the floor + * @param y The y/height of the floor * @param world The world of the floor */ public Floor(int y, String world) { diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/objects/Lift.java b/src/main/java/tech/sbdevelopment/v10lift/api/objects/Lift.java index c30b888..330489e 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/objects/Lift.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/objects/Lift.java @@ -8,35 +8,51 @@ import tech.sbdevelopment.v10lift.api.runnables.DoorCloser; import java.util.*; -/** A lift object, to create a lift. */ -@NoArgsConstructor @ToString +/** + * A lift object, to create a lift. + */ +@Getter +@NoArgsConstructor +@ToString public class Lift { - @Getter @Setter private String worldName; - @Getter @Setter private int y; - @Getter private HashSet owners; - @Getter private final TreeSet blocks = new TreeSet<>(); - @Getter private final LinkedHashMap floors = new LinkedHashMap<>(); - @Getter private final HashSet signs = new HashSet<>(); - @Getter private final HashSet inputs = new HashSet<>(); - @Getter private final HashSet offlineInputs = new HashSet<>(); - @Getter @Setter private LinkedHashMap queue = null; - @Getter private final HashSet ropes = new HashSet<>(); - @Getter private transient final ArrayList toMove = new ArrayList<>(); - @Getter @Setter private int speed; - @Getter @Setter private boolean realistic; - @Getter @Setter private boolean offline = false; - @Getter @Setter private boolean sound = true; - @Getter @Setter private boolean defective = false; - @Getter @Setter private String signText = null; - @Getter @Setter private int counter = 0; - @Getter @Setter private Floor doorOpen = null; - @Getter @Setter private DoorCloser doorCloser = null; + @Setter + private String worldName; + @Setter + private int y; + private HashSet owners; + private final TreeSet blocks = new TreeSet<>(); + private final LinkedHashMap floors = new LinkedHashMap<>(); + private final HashSet signs = new HashSet<>(); + private final HashSet inputs = new HashSet<>(); + private final HashSet offlineInputs = new HashSet<>(); + @Setter + private LinkedHashMap queue = null; + private final HashSet ropes = new HashSet<>(); + private transient final ArrayList toMove = new ArrayList<>(); + @Setter + private int speed; + @Setter + private boolean realistic; + @Setter + private boolean offline = false; + @Setter + private boolean sound = true; + @Setter + private boolean defective = false; + @Setter + private String signText = null; + @Setter + private int counter = 0; + @Setter + private Floor doorOpen = null; + @Setter + private DoorCloser doorCloser = null; /** * Construct a new Lift with multiple owners * - * @param owners The owners, by uuid - * @param speed The speed, 1 is slowest, higher is faster + * @param owners The owners, by uuid + * @param speed The speed, 1 is slowest, higher is faster * @param realistic Realistic lift, or not */ public Lift(HashSet owners, int speed, boolean realistic) { @@ -48,8 +64,8 @@ public class Lift { /** * Construct a new Lift with one owners * - * @param owner The owner, by uuid - * @param speed The speed, 1 is slowest, higher is faster + * @param owner The owner, by uuid + * @param speed The speed, 1 is slowest, higher is faster * @param realistic Realistic lift, or not */ public Lift(UUID owner, int speed, boolean realistic) { diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftBlock.java b/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftBlock.java index b5e0af6..407d696 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftBlock.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftBlock.java @@ -3,33 +3,39 @@ package tech.sbdevelopment.v10lift.api.objects; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.bukkit.Material; import org.bukkit.block.BlockFace; import javax.annotation.Nonnull; -import java.util.Arrays; import java.util.Map; -/** A liftblock object, for a block in a lift. */ +/** + * A liftblock object, for a block in a lift. + */ +@Getter @NoArgsConstructor +@ToString public class LiftBlock implements Comparable { - - @Getter @Setter private String world; - @Getter private int x; - @Getter @Setter private int y; - @Getter private int z; + private String world; + private int x; + @Setter + private int y; + private int z; //Only used for cabine blocks, because those need caching! - @Getter @Setter private Material mat; - @Getter private byte data; - @Getter private BlockFace face; - @Getter private String bisected; - @Getter private String slabtype; - @Getter private String[] signLines; + @Setter + private Material mat; + private byte data; + private BlockFace face; + private String bisected; + private String slabtype; + private String[] signLines; //Only used for inputs! - @Getter private String floor; - @Getter @Setter private boolean active = false; + private String floor; + @Setter + private boolean active = false; //Only used for chests public Map[] serializedItemStacks = null; @@ -38,9 +44,9 @@ public class LiftBlock implements Comparable { * A floor based liftblock, without material (no caching) * * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos * @param floor The floorname of the block */ public LiftBlock(String world, int x, int y, int z, String floor) { @@ -61,11 +67,11 @@ public class LiftBlock implements Comparable { * 1.12 liftblock, with material and data [NO SIGN] * * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param mat The Material of the block - * @param data The data of the block + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param mat The Material of the block + * @param data The data of the block */ public LiftBlock(String world, int x, int y, int z, Material mat, byte data) { this.world = world; @@ -84,12 +90,12 @@ public class LiftBlock implements Comparable { /** * 1.12 liftblock (signs) * - * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param mat The Material of the block - * @param data The data of the block + * @param world The world + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param mat The Material of the block + * @param data The data of the block * @param signLines The lines of the sign */ public LiftBlock(String world, int x, int y, int z, Material mat, byte data, String[] signLines) { @@ -110,10 +116,10 @@ public class LiftBlock implements Comparable { * 1.13 liftblock, without a direction * * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param mat The Material of the block + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param mat The Material of the block */ public LiftBlock(String world, int x, int y, int z, Material mat) { this.world = world; @@ -133,11 +139,11 @@ public class LiftBlock implements Comparable { * 1.13 liftblock with a direction * * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param mat The Material of the block - * @param face The blockface of the block + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param mat The Material of the block + * @param face The blockface of the block */ public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face) { this.world = world; @@ -156,12 +162,12 @@ public class LiftBlock implements Comparable { /** * 1.13 liftblock, with a direction and a bisected * - * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param mat The Material of the block - * @param face The blockface of the block + * @param world The world + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param mat The Material of the block + * @param face The blockface of the block * @param bisected The bisected of the block */ public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String bisected) { @@ -181,12 +187,12 @@ public class LiftBlock implements Comparable { /** * 1/13 liftblock (sign) * - * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param mat The Material of the block - * @param face The blockface of the block + * @param world The world + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param mat The Material of the block + * @param face The blockface of the block * @param signLines The lines of the sign */ public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String[] signLines) { @@ -206,11 +212,11 @@ public class LiftBlock implements Comparable { /** * 1.13 liftblock (slab) * - * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param mat The Material of the block + * @param world The world + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param mat The Material of the block * @param slabtype The typ of slab (low, high, double) */ public LiftBlock(String world, int x, int y, int z, Material mat, String slabtype) { @@ -264,22 +270,4 @@ public class LiftBlock implements Comparable { result = prime * result + z; return result; } - - @Override - public String toString() { - return "LiftBlock{" + - "world='" + world + '\'' + - ", x=" + x + - ", y=" + y + - ", z=" + z + - ", mat=" + mat + - ", data=" + data + - ", face=" + face + - ", bisected='" + bisected + '\'' + - ", signLines=" + Arrays.toString(signLines) + - ", floor='" + floor + '\'' + - ", active=" + active + - ", serializedItemStacks=" + Arrays.toString(serializedItemStacks) + - '}'; - } } diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftRope.java b/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftRope.java index 30d8b93..fe02fba 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftRope.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftRope.java @@ -3,13 +3,19 @@ package tech.sbdevelopment.v10lift.api.objects; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.bukkit.Material; import org.bukkit.block.BlockFace; import java.util.Objects; -/** A liftrope object, for a rope in the lift. */ -@Getter @Setter @NoArgsConstructor +/** + * A liftrope object, for a rope in the lift. + */ +@Getter +@Setter +@NoArgsConstructor +@ToString public class LiftRope { private Material type; private BlockFace face; @@ -23,13 +29,13 @@ public class LiftRope { /** * Construct a new liftrope * - * @param type The material of the rope - * @param face The face of the rope + * @param type The material of the rope + * @param face The face of the rope * @param world The world - * @param x The x-pos - * @param minY The starting x-pos - * @param maxY The stopping x-pos - * @param z The z-pos + * @param x The x-pos + * @param minY The starting x-pos + * @param maxY The stopping x-pos + * @param z The z-pos */ public LiftRope(Material type, BlockFace face, String world, int x, int minY, int maxY, int z) { this.type = type; @@ -65,18 +71,4 @@ public class LiftRope { result = prime * result + z; return result; } - - @Override - public String toString() { - return "LiftRope{" + - "type=" + type + - ", face=" + face + - ", world='" + world + '\'' + - ", x=" + x + - ", minY=" + minY + - ", maxY=" + maxY + - ", z=" + z + - ", currently=" + currently + - '}'; - } } diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftSign.java b/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftSign.java index f7a0212..899d367 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftSign.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/objects/LiftSign.java @@ -3,9 +3,15 @@ package tech.sbdevelopment.v10lift.api.objects; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; -/** A liftsign object, for a info sign for the lift. */ -@Getter @Setter @NoArgsConstructor +/** + * A liftsign object, for an info sign for the lift. + */ +@Getter +@Setter +@NoArgsConstructor +@ToString public class LiftSign { private String world; private int x; @@ -19,10 +25,10 @@ public class LiftSign { * Construct a new liftsign * * @param world The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param type The type of the sign + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param type The type of the sign * @param state The state of the sign */ public LiftSign(String world, int x, int y, int z, byte type, byte state) { @@ -63,17 +69,4 @@ public class LiftSign { result = prime * result + z; return result; } - - @Override - public String toString() { - return "LiftSign{" + - "world='" + world + '\'' + - ", x=" + x + - ", z=" + z + - ", y=" + y + - ", oldText='" + oldText + '\'' + - ", type=" + type + - ", state=" + state + - '}'; - } } diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/objects/V10Entity.java b/src/main/java/tech/sbdevelopment/v10lift/api/objects/V10Entity.java index e84d938..0313efa 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/objects/V10Entity.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/objects/V10Entity.java @@ -3,14 +3,19 @@ package tech.sbdevelopment.v10lift.api.objects; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import java.util.UUID; -/** A v10entity object, for a entity in the lift. */ -@Getter @NoArgsConstructor +/** + * A v10entity object, for an entity in the lift. + */ +@Getter +@NoArgsConstructor +@ToString public class V10Entity { private UUID entityUUID; private String world; @@ -18,17 +23,18 @@ public class V10Entity { private int locY; private int locZ; private int y; - @Setter private short step; + @Setter + private short step; /** * Construct a new V10LiftEntity * * @param entityUUID The UUID of the entity - * @param worldName The world - * @param x The x-pos - * @param y The y-pos - * @param z The z-pos - * @param cury The current y-pos + * @param worldName The world + * @param x The x-pos + * @param y The y-pos + * @param z The z-pos + * @param cury The current y-pos */ public V10Entity(UUID entityUUID, String worldName, int x, int y, int z, int cury) { this.entityUUID = entityUUID; @@ -93,17 +99,4 @@ public class V10Entity { public int hashCode() { return 31 + ((entityUUID == null) ? 0 : entityUUID.hashCode()); } - - @Override - public String toString() { - return "V10Entity{" + - "entityUUID=" + entityUUID + - ", world='" + world + '\'' + - ", locX=" + locX + - ", locY=" + locY + - ", locZ=" + locZ + - ", y=" + y + - ", step=" + step + - '}'; - } } diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/runnables/DoorCloser.java b/src/main/java/tech/sbdevelopment/v10lift/api/runnables/DoorCloser.java index 818e850..b07440b 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/runnables/DoorCloser.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/runnables/DoorCloser.java @@ -1,11 +1,13 @@ package tech.sbdevelopment.v10lift.api.runnables; +import org.bukkit.Bukkit; import tech.sbdevelopment.v10lift.V10LiftPlugin; import tech.sbdevelopment.v10lift.api.V10LiftAPI; import tech.sbdevelopment.v10lift.managers.DataManager; -import org.bukkit.Bukkit; -/** The DoorCloser runnable, used for checking if the door can be closed. */ +/** + * The DoorCloser runnable, used for checking if the door can be closed. + */ public class DoorCloser implements Runnable { private final String liftName; private final int taskID; diff --git a/src/main/java/tech/sbdevelopment/v10lift/api/runnables/MoveLift.java b/src/main/java/tech/sbdevelopment/v10lift/api/runnables/MoveLift.java index bb01ed4..0c63d49 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/api/runnables/MoveLift.java +++ b/src/main/java/tech/sbdevelopment/v10lift/api/runnables/MoveLift.java @@ -2,6 +2,14 @@ package tech.sbdevelopment.v10lift.api.runnables; import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XSound; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Chest; +import org.bukkit.block.Sign; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import tech.sbdevelopment.v10lift.V10LiftPlugin; import tech.sbdevelopment.v10lift.api.V10LiftAPI; import tech.sbdevelopment.v10lift.api.enums.LiftDirection; @@ -11,33 +19,26 @@ import tech.sbdevelopment.v10lift.managers.DataManager; import tech.sbdevelopment.v10lift.sbutils.LocationSerializer; import tech.sbdevelopment.v10lift.utils.ConfigUtil; import tech.sbdevelopment.v10lift.utils.DirectionUtil; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Chest; -import org.bukkit.block.Sign; -import org.bukkit.entity.Entity; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import tech.sbdevelopment.v10lift.api.objects.*; import java.lang.reflect.Method; import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.function.Supplier; -/** The MoveLift runnable, used for moving a lift. */ +/** + * The MoveLift runnable, used for moving a lift. + */ public class MoveLift implements Runnable { /* Packet teleportation method */ private final Method[] methods = ((Supplier) () -> { - try { - Method getHandle = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".entity.CraftEntity").getDeclaredMethod("getHandle"); - return new Method[] { - getHandle, getHandle.getReturnType().getDeclaredMethod("setPositionRotation", double.class, double.class, double.class, float.class, float.class) - }; - } catch (Exception ex) { - return null; - } + try { + Method getHandle = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".entity.CraftEntity").getDeclaredMethod("getHandle"); + return new Method[]{ + getHandle, getHandle.getReturnType().getDeclaredMethod("setPositionRotation", double.class, double.class, double.class, float.class, float.class) + }; + } catch (Exception ex) { + return null; + } }).get(); private final String liftName; @@ -250,7 +251,8 @@ public class MoveLift implements Runnable { while (toMoveIterator.hasNext()) { V10Entity v10ent = toMoveIterator.next(); if (v10ent.getStep() > 0) { - if (direction == LiftDirection.UP) v10ent.moveUp(); else v10ent.moveDown(); + if (direction == LiftDirection.UP) v10ent.moveUp(); + else v10ent.moveDown(); if (v10ent.getStep() > 16) { toMoveIterator.remove(); } @@ -426,7 +428,8 @@ public class MoveLift implements Runnable { if (lift.isRealistic()) lift.setCounter(ft); - if (lift.isSound() && block != null) XSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(block.getLocation(), 2.0F, 63.0F); + if (lift.isSound() && block != null) + XSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(block.getLocation(), 2.0F, 63.0F); } } diff --git a/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftCommand.java b/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftCommand.java index 851a5a2..bf449b2 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftCommand.java +++ b/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftCommand.java @@ -1,6 +1,15 @@ package tech.sbdevelopment.v10lift.commands; import com.cryptomorin.xseries.XMaterial; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import tech.sbdevelopment.v10lift.V10LiftPlugin; import tech.sbdevelopment.v10lift.api.V10LiftAPI; import tech.sbdevelopment.v10lift.api.objects.Floor; @@ -11,15 +20,6 @@ import tech.sbdevelopment.v10lift.managers.DataManager; import tech.sbdevelopment.v10lift.managers.VaultManager; import tech.sbdevelopment.v10lift.sbutils.LocationSerializer; import tech.sbdevelopment.v10lift.utils.ConfigUtil; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; import java.sql.SQLException; diff --git a/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftTabCompleter.java b/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftTabCompleter.java index 9954283..ee4826c 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftTabCompleter.java +++ b/src/main/java/tech/sbdevelopment/v10lift/commands/V10LiftTabCompleter.java @@ -1,15 +1,15 @@ package tech.sbdevelopment.v10lift.commands; -import tech.sbdevelopment.v10lift.api.objects.Lift; -import tech.sbdevelopment.v10lift.managers.DataManager; -import tech.sbdevelopment.v10lift.managers.VaultManager; -import tech.sbdevelopment.v10lift.V10LiftPlugin; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; +import tech.sbdevelopment.v10lift.V10LiftPlugin; +import tech.sbdevelopment.v10lift.api.objects.Lift; +import tech.sbdevelopment.v10lift.managers.DataManager; +import tech.sbdevelopment.v10lift.managers.VaultManager; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -21,6 +21,7 @@ public class V10LiftTabCompleter implements TabCompleter { private static final List COMMANDS = Arrays.asList("create", "delete", "rename", "abort", "whois", "edit", "floor", "input", "build", "rope", "door", "speed", "realistic", "repair", "disable", "whitelist", "reload", "help", "start", "stop", "offline"); private static final List SUBRENAME = Arrays.asList("add", "del", "rename"); private static final List SUB = Arrays.asList("add", "del"); + @Override public List onTabComplete(@Nonnull CommandSender commandSender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) { if (label.equalsIgnoreCase("v10lift")) { diff --git a/src/main/java/tech/sbdevelopment/v10lift/listeners/BlockBreakListener.java b/src/main/java/tech/sbdevelopment/v10lift/listeners/BlockBreakListener.java index a2e3f9e..6b68d73 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/listeners/BlockBreakListener.java +++ b/src/main/java/tech/sbdevelopment/v10lift/listeners/BlockBreakListener.java @@ -1,12 +1,5 @@ package tech.sbdevelopment.v10lift.listeners; -import tech.sbdevelopment.v10lift.api.V10LiftAPI; -import tech.sbdevelopment.v10lift.api.objects.Floor; -import tech.sbdevelopment.v10lift.api.objects.Lift; -import tech.sbdevelopment.v10lift.api.objects.LiftBlock; -import tech.sbdevelopment.v10lift.managers.DataManager; -import tech.sbdevelopment.v10lift.utils.ConfigUtil; -import tech.sbdevelopment.v10lift.utils.DoorUtil; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -14,6 +7,13 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; +import tech.sbdevelopment.v10lift.api.V10LiftAPI; +import tech.sbdevelopment.v10lift.api.objects.Floor; +import tech.sbdevelopment.v10lift.api.objects.Lift; +import tech.sbdevelopment.v10lift.api.objects.LiftBlock; +import tech.sbdevelopment.v10lift.managers.DataManager; +import tech.sbdevelopment.v10lift.utils.ConfigUtil; +import tech.sbdevelopment.v10lift.utils.DoorUtil; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/tech/sbdevelopment/v10lift/listeners/EntityDamageListener.java b/src/main/java/tech/sbdevelopment/v10lift/listeners/EntityDamageListener.java index 69947f6..a1c09a2 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/listeners/EntityDamageListener.java +++ b/src/main/java/tech/sbdevelopment/v10lift/listeners/EntityDamageListener.java @@ -1,8 +1,5 @@ package tech.sbdevelopment.v10lift.listeners; -import tech.sbdevelopment.v10lift.api.objects.Lift; -import tech.sbdevelopment.v10lift.api.objects.LiftBlock; -import tech.sbdevelopment.v10lift.managers.DataManager; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -10,6 +7,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; +import tech.sbdevelopment.v10lift.api.objects.Lift; +import tech.sbdevelopment.v10lift.api.objects.LiftBlock; +import tech.sbdevelopment.v10lift.managers.DataManager; public class EntityDamageListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/src/main/java/tech/sbdevelopment/v10lift/listeners/PlayerInteractListener.java b/src/main/java/tech/sbdevelopment/v10lift/listeners/PlayerInteractListener.java index 5256b95..e7dbd6e 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/listeners/PlayerInteractListener.java +++ b/src/main/java/tech/sbdevelopment/v10lift/listeners/PlayerInteractListener.java @@ -1,16 +1,6 @@ package tech.sbdevelopment.v10lift.listeners; import com.cryptomorin.xseries.XMaterial; -import tech.sbdevelopment.v10lift.V10LiftPlugin; -import tech.sbdevelopment.v10lift.api.V10LiftAPI; -import tech.sbdevelopment.v10lift.api.objects.Floor; -import tech.sbdevelopment.v10lift.api.objects.Lift; -import tech.sbdevelopment.v10lift.api.objects.LiftBlock; -import tech.sbdevelopment.v10lift.managers.DataManager; -import tech.sbdevelopment.v10lift.managers.ForbiddenBlockManager; -import tech.sbdevelopment.v10lift.managers.VaultManager; -import tech.sbdevelopment.v10lift.utils.ConfigUtil; -import tech.sbdevelopment.v10lift.utils.DoorUtil; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -27,6 +17,16 @@ import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import tech.sbdevelopment.v10lift.V10LiftPlugin; +import tech.sbdevelopment.v10lift.api.V10LiftAPI; +import tech.sbdevelopment.v10lift.api.objects.Floor; +import tech.sbdevelopment.v10lift.api.objects.Lift; +import tech.sbdevelopment.v10lift.api.objects.LiftBlock; +import tech.sbdevelopment.v10lift.managers.DataManager; +import tech.sbdevelopment.v10lift.managers.ForbiddenBlockManager; +import tech.sbdevelopment.v10lift.managers.VaultManager; +import tech.sbdevelopment.v10lift.utils.ConfigUtil; +import tech.sbdevelopment.v10lift.utils.DoorUtil; import java.util.*; @@ -42,8 +42,8 @@ public class PlayerInteractListener implements Listener { Material button = block.getType(); if (action == Action.RIGHT_CLICK_BLOCK - && e.getHand() != EquipmentSlot.OFF_HAND - && (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) { + && e.getHand() != EquipmentSlot.OFF_HAND + && (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) { String world = block.getWorld().getName(); int x = block.getX(); int y = block.getY(); @@ -104,7 +104,8 @@ public class PlayerInteractListener implements Listener { return; } - if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null))) return; + if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null))) + return; if (DataManager.containsEditLift(liftName)) return; e.setCancelled(true); if (lift.isDefective()) return; @@ -367,7 +368,8 @@ public class PlayerInteractListener implements Listener { return; } - if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null))) return; + if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null))) + return; if (DataManager.containsEditLift(liftName)) return; e.setCancelled(true); if (lift.isDefective()) return; diff --git a/src/main/java/tech/sbdevelopment/v10lift/listeners/SignChangeListener.java b/src/main/java/tech/sbdevelopment/v10lift/listeners/SignChangeListener.java index f0ec43c..fabda8a 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/listeners/SignChangeListener.java +++ b/src/main/java/tech/sbdevelopment/v10lift/listeners/SignChangeListener.java @@ -1,9 +1,5 @@ package tech.sbdevelopment.v10lift.listeners; -import tech.sbdevelopment.v10lift.api.objects.Lift; -import tech.sbdevelopment.v10lift.api.objects.LiftSign; -import tech.sbdevelopment.v10lift.managers.DataManager; -import tech.sbdevelopment.v10lift.utils.ConfigUtil; import org.bukkit.ChatColor; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -11,6 +7,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.SignChangeEvent; +import tech.sbdevelopment.v10lift.api.objects.Lift; +import tech.sbdevelopment.v10lift.api.objects.LiftSign; +import tech.sbdevelopment.v10lift.managers.DataManager; +import tech.sbdevelopment.v10lift.utils.ConfigUtil; public class SignChangeListener implements Listener { diff --git a/src/main/java/tech/sbdevelopment/v10lift/managers/DBManager.java b/src/main/java/tech/sbdevelopment/v10lift/managers/DBManager.java index 34e42f9..bffdb67 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/managers/DBManager.java +++ b/src/main/java/tech/sbdevelopment/v10lift/managers/DBManager.java @@ -1,10 +1,10 @@ package tech.sbdevelopment.v10lift.managers; import com.google.gson.Gson; +import org.bukkit.Bukkit; import tech.sbdevelopment.v10lift.V10LiftPlugin; import tech.sbdevelopment.v10lift.api.objects.Lift; import tech.sbdevelopment.v10lift.sbutils.SQLiteDB; -import org.bukkit.Bukkit; import java.sql.Connection; import java.sql.PreparedStatement; @@ -104,7 +104,7 @@ public class DBManager { * Save a lift to data * * @param liftName The name of the lift - * @param lift The lift itself + * @param lift The lift itself */ public void saveLift(String liftName, Lift lift, boolean sync) { Bukkit.getLogger().info("[V10Lift] Saving lift " + liftName + " to data..."); @@ -130,7 +130,8 @@ public class DBManager { statement.setString(1, liftName); statement.setBytes(2, liftData); statement.executeUpdate(); - } catch (SQLException ignored) {} + } catch (SQLException ignored) { + } try { String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?"; diff --git a/src/main/java/tech/sbdevelopment/v10lift/managers/VaultManager.java b/src/main/java/tech/sbdevelopment/v10lift/managers/VaultManager.java index d32e39b..6137aee 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/managers/VaultManager.java +++ b/src/main/java/tech/sbdevelopment/v10lift/managers/VaultManager.java @@ -1,10 +1,10 @@ package tech.sbdevelopment.v10lift.managers; import net.milkbowl.vault.permission.Permission; -import tech.sbdevelopment.v10lift.V10LiftPlugin; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; +import tech.sbdevelopment.v10lift.V10LiftPlugin; import java.util.Arrays; import java.util.HashSet; diff --git a/src/main/java/tech/sbdevelopment/v10lift/sbutils/ConfigUpdater.java b/src/main/java/tech/sbdevelopment/v10lift/sbutils/ConfigUpdater.java index 363587d..2950262 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/sbutils/ConfigUpdater.java +++ b/src/main/java/tech/sbdevelopment/v10lift/sbutils/ConfigUpdater.java @@ -19,14 +19,16 @@ import java.util.stream.Collectors; * Read the new file and scan for comments and ignored sections, if ignored section is found it is treated as a comment. * Read and write each line of the new config, if the old config has value for the given key it writes that value in the new config. * If a key has an attached comment above it, it is written first. + * * @author tchristofferson */ public class ConfigUpdater { /** * Update a yaml file from a resource inside your plugin jar - * @param plugin You plugin - * @param resourceName The yaml file name to update from, typically config.yml - * @param toUpdate The yaml file to update + * + * @param plugin You plugin + * @param resourceName The yaml file name to update from, typically config.yml + * @param toUpdate The yaml file to update * @param ignoredSections List of sections to ignore and copy from the current config * @throws IOException If an IOException occurs */ @@ -54,7 +56,8 @@ public class ConfigUpdater { //Write method doing the work. //It checks if key has a comment associated with it and writes comment then the key and value private static void write(FileConfiguration newConfig, FileConfiguration oldConfig, Map comments, List ignoredSections, BufferedWriter writer, Yaml yaml) throws IOException { - outer: for (String key : newConfig.getKeys(true)) { + outer: + for (String key : newConfig.getKeys(true)) { String[] keys = key.split("\\."); String actualKey = keys[keys.length - 1]; String comment = comments.remove(key); @@ -173,7 +176,8 @@ public class ConfigUpdater { StringBuilder keyBuilder = new StringBuilder(); int lastLineIndentCount = 0; - outer: for (int i = 0; i) value, actualKey, prefixSpaces.toString(), yaml)); } else { - builder.append(prefixSpaces.toString()).append(actualKey).append(": ").append(yaml.dump(value)); + builder.append(prefixSpaces).append(actualKey).append(": ").append(yaml.dump(value)); } } } @@ -239,12 +243,12 @@ public class ConfigUpdater { int currentSpaces = getSpaces(lines.get(index)); int indents = 0; - for (int i = index-1; i >= 0; i--){ + for (int i = index - 1; i >= 0; i--) { String line = lines.get(i); if (line == null || line.trim().equals("")) continue; int newSpaces = getSpaces(lines.get(i)); // differs at least two - if (newSpaces < currentSpaces - 1){ + if (newSpaces < currentSpaces - 1) { indents++; currentSpaces = newSpaces; } @@ -253,7 +257,7 @@ public class ConfigUpdater { return indents; } - private static int getSpaces(String line){ + private static int getSpaces(String line) { int spaces = 0; for (char c : line.toCharArray()) { if (c == ' ') { @@ -285,7 +289,7 @@ public class ConfigUpdater { } //Updates the keyBuilder and returns configLines number of indents - private static int setFullKey(StringBuilder keyBuilder, int index, List configLines, int lastLineIndentCount) { + private static int setFullKey(StringBuilder keyBuilder, int index, List configLines, int lastLineIndentCount) { int currentIndents = countIndents(index, configLines); String key = configLines.get(index).trim().split(":")[0]; diff --git a/src/main/java/tech/sbdevelopment/v10lift/sbutils/LocationSerializer.java b/src/main/java/tech/sbdevelopment/v10lift/sbutils/LocationSerializer.java index 2ea8df5..e9cdf8c 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/sbutils/LocationSerializer.java +++ b/src/main/java/tech/sbdevelopment/v10lift/sbutils/LocationSerializer.java @@ -11,7 +11,6 @@ public class LocationSerializer { * Deserialize a serialized location, without {@link Location#getYaw()} and {@link Location#getPitch()} * * @param string The location string - * * @return The location or null if error */ @Nullable @@ -33,7 +32,6 @@ public class LocationSerializer { * Deserialize a serialized location, with {@link Location#getYaw()} and {@link Location#getPitch()} * * @param string The location string - * * @return The location or null if error */ @Nonnull @@ -55,7 +53,6 @@ public class LocationSerializer { * Serialize a location, without {@link Location#getYaw()} and {@link Location#getPitch()} * * @param loc The location - * * @return The serialized string */ @Nullable @@ -68,7 +65,6 @@ public class LocationSerializer { * Serialize a location, with {@link Location#getYaw()} and {@link Location#getPitch()} * * @param loc The location - * * @return The serialized string */ @Nullable diff --git a/src/main/java/tech/sbdevelopment/v10lift/sbutils/SQLiteDB.java b/src/main/java/tech/sbdevelopment/v10lift/sbutils/SQLiteDB.java index 831e078..57e659c 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/sbutils/SQLiteDB.java +++ b/src/main/java/tech/sbdevelopment/v10lift/sbutils/SQLiteDB.java @@ -2,8 +2,8 @@ package tech.sbdevelopment.v10lift.sbutils; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import tech.sbdevelopment.v10lift.V10LiftPlugin; import org.bukkit.Bukkit; +import tech.sbdevelopment.v10lift.V10LiftPlugin; import java.io.File; import java.io.IOException; @@ -63,7 +63,7 @@ public class SQLiteDB { /** * Get the connection, to execute queries - * + *

* CREATE TABLE - execute() * SELECT - executeQuery() * UPDATE - executeUpdate() diff --git a/src/main/java/tech/sbdevelopment/v10lift/sbutils/YamlFile.java b/src/main/java/tech/sbdevelopment/v10lift/sbutils/YamlFile.java index 7ddec2a..081089d 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/sbutils/YamlFile.java +++ b/src/main/java/tech/sbdevelopment/v10lift/sbutils/YamlFile.java @@ -1,9 +1,9 @@ package tech.sbdevelopment.v10lift.sbutils; -import tech.sbdevelopment.v10lift.V10LiftPlugin; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import tech.sbdevelopment.v10lift.V10LiftPlugin; import java.io.File; import java.io.IOException; diff --git a/src/main/java/tech/sbdevelopment/v10lift/utils/ConfigUtil.java b/src/main/java/tech/sbdevelopment/v10lift/utils/ConfigUtil.java index 5958e6f..1cc90e9 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/utils/ConfigUtil.java +++ b/src/main/java/tech/sbdevelopment/v10lift/utils/ConfigUtil.java @@ -1,8 +1,8 @@ package tech.sbdevelopment.v10lift.utils; -import tech.sbdevelopment.v10lift.V10LiftPlugin; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import tech.sbdevelopment.v10lift.V10LiftPlugin; import javax.annotation.Nonnull; import java.util.HashMap; @@ -28,7 +28,7 @@ public class ConfigUtil { /** * Send a message from the messages.yml without variables * - * @param p The commandsender to send it to + * @param p The commandsender to send it to * @param path The path to look for */ public static void sendMessage(CommandSender p, @Nonnull String path) { @@ -50,8 +50,8 @@ public class ConfigUtil { /** * Get a message from the messages.yml with variables * - * @param p The commandsender to send it to - * @param path The path to look for + * @param p The commandsender to send it to + * @param path The path to look for * @param replacement The replacements - key: %Name% = value: TheName */ public static void sendMessage(CommandSender p, @Nonnull String path, Map replacement) { diff --git a/src/main/java/tech/sbdevelopment/v10lift/utils/DoorUtil.java b/src/main/java/tech/sbdevelopment/v10lift/utils/DoorUtil.java index bec0c34..abc5e18 100644 --- a/src/main/java/tech/sbdevelopment/v10lift/utils/DoorUtil.java +++ b/src/main/java/tech/sbdevelopment/v10lift/utils/DoorUtil.java @@ -14,12 +14,14 @@ public class DoorUtil { /** * Open a door, with 1.12.x- and 1.13.x+ support + * * @param b The block (door) * @return true if opened, false if not opened */ public static boolean openDoor(@Nonnull Block b) { if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_OPEN.play(b.getLocation()); - if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_OPEN.play(b.getLocation()); + if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) + XSound.BLOCK_WOODEN_DOOR_OPEN.play(b.getLocation()); if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_OPEN.play(b.getLocation()); if (XMaterial.supports(13)) { //1.13+ @@ -52,12 +54,14 @@ public class DoorUtil { /** * Close a door, with 1.12.x- and 1.13.x+ support + * * @param b The block (door) * @return true if opened, false if not opened */ public static boolean closeDoor(@Nonnull Block b) { if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_CLOSE.play(b.getLocation()); - if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_CLOSE.play(b.getLocation()); + if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) + XSound.BLOCK_WOODEN_DOOR_CLOSE.play(b.getLocation()); if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_CLOSE.play(b.getLocation()); if (XMaterial.supports(13)) { //1.13+