Formatted code

This commit is contained in:
Stijn Bannink 2023-08-13 16:19:15 +02:00
parent c12af96b9a
commit 8fe6e6766a
24 changed files with 321 additions and 325 deletions

View file

@ -1,5 +1,10 @@
package tech.sbdevelopment.v10lift; 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.V10LiftCommand;
import tech.sbdevelopment.v10lift.commands.V10LiftTabCompleter; import tech.sbdevelopment.v10lift.commands.V10LiftTabCompleter;
import tech.sbdevelopment.v10lift.listeners.BlockBreakListener; 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.ConfigUpdater;
import tech.sbdevelopment.v10lift.sbutils.UpdateManager; import tech.sbdevelopment.v10lift.sbutils.UpdateManager;
import tech.sbdevelopment.v10lift.sbutils.YamlFile; 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.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
@ -23,9 +24,11 @@ import java.util.Collections;
public class V10LiftPlugin extends JavaPlugin { public class V10LiftPlugin extends JavaPlugin {
@Getter
private static V10LiftPlugin instance; private static V10LiftPlugin instance;
private static YamlFile config; private static YamlFile config;
private static DBManager dbManager; private static DBManager dbManager;
@Getter
private static YamlFile messages; private static YamlFile messages;
private static boolean vault = false; private static boolean vault = false;
@ -129,10 +132,6 @@ public class V10LiftPlugin extends JavaPlugin {
instance = null; instance = null;
} }
public static V10LiftPlugin getInstance() {
return instance;
}
public static YamlFile getSConfig() { public static YamlFile getSConfig() {
return config; return config;
} }
@ -141,10 +140,6 @@ public class V10LiftPlugin extends JavaPlugin {
return dbManager; return dbManager;
} }
public static YamlFile getMessages() {
return messages;
}
public static boolean isVaultEnabled() { public static boolean isVaultEnabled() {
return vault; return vault;
} }

View file

@ -1,6 +1,14 @@
package tech.sbdevelopment.v10lift.api; package tech.sbdevelopment.v10lift.api;
import com.cryptomorin.xseries.XMaterial; 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.V10LiftPlugin;
import tech.sbdevelopment.v10lift.api.objects.*; import tech.sbdevelopment.v10lift.api.objects.*;
import tech.sbdevelopment.v10lift.api.runnables.DoorCloser; 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.ConfigUtil;
import tech.sbdevelopment.v10lift.utils.DirectionUtil; import tech.sbdevelopment.v10lift.utils.DirectionUtil;
import tech.sbdevelopment.v10lift.utils.DoorUtil; 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 javax.annotation.Nonnull;
import java.util.*; import java.util.*;
/** The Main API class, for all the API methods */ /**
* The Main API class, for all the API methods
*/
public class V10LiftAPI { public class V10LiftAPI {
private static V10LiftAPI instance; private static V10LiftAPI instance;
private V10LiftAPI() {} private V10LiftAPI() {
}
public static V10LiftAPI getInstance() { public static V10LiftAPI getInstance() {
if (instance == null) instance = new V10LiftAPI(); if (instance == null) instance = new V10LiftAPI();
@ -64,7 +66,7 @@ public class V10LiftAPI {
/** /**
* Create a new Lift * 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 * @param liftName The name of the lift
* @return true if created, false if null or already exists * @return true if created, false if null or already exists
*/ */
@ -137,7 +139,7 @@ public class V10LiftAPI {
* Rename a lift * Rename a lift
* *
* @param liftName The name of the 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) { public void renameLift(String liftName, String newName) {
if (liftName == null || newName == null || !DataManager.containsLift(liftName)) return; if (liftName == null || newName == null || !DataManager.containsLift(liftName)) return;
@ -160,7 +162,7 @@ public class V10LiftAPI {
* Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after!
* *
* @param liftName The name of the lift * @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 * @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) { public int addBlockToLift(String liftName, Block block) {
@ -174,7 +176,7 @@ public class V10LiftAPI {
* Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after!
* *
* @param blocks The blockset * @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 * @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added
*/ */
public int addBlockToLift(Set<LiftBlock> blocks, @Nonnull Block block) { public int addBlockToLift(Set<LiftBlock> blocks, @Nonnull Block block) {
@ -214,7 +216,7 @@ public class V10LiftAPI {
* Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after!
* *
* @param blocks The blockset * @param blocks The blockset
* @param block The LiftBlock * @param block The LiftBlock
* @return 0 if added, -2 if forbidden, -3 if already added * @return 0 if added, -2 if forbidden, -3 if already added
*/ */
public int addBlockToLift(@Nonnull Set<LiftBlock> blocks, @Nonnull LiftBlock block) { public int addBlockToLift(@Nonnull Set<LiftBlock> blocks, @Nonnull LiftBlock block) {
@ -229,7 +231,7 @@ public class V10LiftAPI {
* Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after!
* *
* @param liftName The name of the lift * @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 * @return 0 if removed, -1 if null or doesn't exists, -2 if not added
*/ */
public int removeBlockFromLift(String liftName, Block block) { public int removeBlockFromLift(String liftName, Block block) {
@ -273,11 +275,11 @@ public class V10LiftAPI {
* Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after!
* *
* @param liftName The name of the lift * @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 * @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) { 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); return switchBlockAtLift(DataManager.getLift(liftName).getBlocks(), block);
} }
@ -286,11 +288,11 @@ public class V10LiftAPI {
* Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after! * Use {@link V10LiftAPI#sortLiftBlocks(String liftName)} after!
* *
* @param blocks The blockset * @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 * @return 0 if added, 1 if removed, -1 if null or doesn't exists, -2 if not added
*/ */
public int switchBlockAtLift(TreeSet<LiftBlock> blocks, Block block) { public int switchBlockAtLift(TreeSet<LiftBlock> blocks, Block block) {
if (blocks == null || block == null) return -1; if (blocks == null || block == null) return -1;
Material type = block.getType(); Material type = block.getType();
if (ForbiddenBlockManager.isForbidden(type)) return -2; if (ForbiddenBlockManager.isForbidden(type)) return -2;
LiftBlock lb; LiftBlock lb;
@ -394,9 +396,9 @@ public class V10LiftAPI {
/** /**
* Open the door * Open the door
* *
* @param lift The lift * @param lift The lift
* @param liftName The name of the lift * @param liftName The name of the lift
* @param f The floor * @param f The floor
* @return true/false * @return true/false
*/ */
public boolean openDoor(Lift lift, String liftName, Floor f) { public boolean openDoor(Lift lift, String liftName, Floor f) {
@ -498,14 +500,16 @@ public class V10LiftAPI {
/** /**
* Adds a new floor to a lift * 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 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 * @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) { 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 (liftName == null || floorName == null || floor == null || !DataManager.containsLift(liftName) || floor.getWorld() == null)
if (floor.getY() > Objects.requireNonNull(Bukkit.getServer().getWorld(floor.getWorld()), "World is null at addNewFloor!").getMaxHeight()) return -2; 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(); if (floorName.length() > 13) floorName = floorName.substring(0, 13).trim();
Lift lift = DataManager.getLift(liftName); Lift lift = DataManager.getLift(liftName);
if (lift.getFloors().containsKey(floorName) || lift.getFloors().containsValue(floor)) return -3; if (lift.getFloors().containsKey(floorName) || lift.getFloors().containsValue(floor)) return -3;
@ -518,7 +522,7 @@ public class V10LiftAPI {
/** /**
* Removes a floor from a lift * 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 * @param floorName The name of the floor
* @return true if removed, false if null or doesn't exists * @return true if removed, false if null or doesn't exists
*/ */
@ -536,8 +540,8 @@ public class V10LiftAPI {
* Rename a floor from a lift * Rename a floor from a lift
* *
* @param liftName The name of the lift * @param liftName The name of the lift
* @param oldName The old name of the floor * @param oldName The old name of the floor
* @param newName The new 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 * @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) { public int renameFloor(String liftName, String oldName, String newName) {
@ -580,7 +584,7 @@ public class V10LiftAPI {
* Set a lift to (not) defective * Set a lift to (not) defective
* *
* @param liftName The name of the lift * @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 * @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) { public int setDefective(String liftName, boolean state) {
@ -650,7 +654,7 @@ public class V10LiftAPI {
/** /**
* Get the userWhitelist of a lift * 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 * @param floorName The name of the floor
* @return list with UUIDs of the players * @return list with UUIDs of the players
*/ */
@ -668,7 +672,7 @@ public class V10LiftAPI {
/** /**
* Get the groupWhitelist of a lift * 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 * @param floorName The name of the floor
* @return list with groupnames * @return list with groupnames
*/ */
@ -698,7 +702,7 @@ public class V10LiftAPI {
* Set a lift to (not) offline * Set a lift to (not) offline
* *
* @param liftName The name of the lift * @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 * @return 0 if set, -1 if null or doesn't exists, -2 if same state
*/ */
public int setOffline(String liftName, boolean state) { public int setOffline(String liftName, boolean state) {
@ -764,8 +768,7 @@ public class V10LiftAPI {
* Check if a lift contains the block as rope * Check if a lift contains the block as rope
* *
* @param liftName The name of the lift * @param liftName The name of the lift
* @param block The block * @param block The block
*
* @return true/false * @return true/false
*/ */
public boolean containsRope(String liftName, Block block) { public boolean containsRope(String liftName, Block block) {
@ -792,7 +795,6 @@ public class V10LiftAPI {
* Check if a block is a rope * Check if a block is a rope
* *
* @param b The block * @param b The block
*
* @return true/false * @return true/false
*/ */
public boolean isRope(Block b) { public boolean isRope(Block b) {
@ -804,7 +806,8 @@ public class V10LiftAPI {
/** /**
* Send info about a lift to a player * 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 * @param liftName The name of the lift
*/ */
public void sendLiftInfo(CommandSender sender, String liftName) { public void sendLiftInfo(CommandSender sender, String liftName) {
@ -813,9 +816,10 @@ public class V10LiftAPI {
/** /**
* Send info about a lift to a player * 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 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) { public void sendLiftInfo(@Nonnull CommandSender ent, String liftName, @Nonnull Lift lift) {
@ -867,12 +871,12 @@ public class V10LiftAPI {
/** /**
* Add a rope to a lift * 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 world The world
* @param x The x-pos * @param x The x-pos
* @param minY The min y-pos * @param minY The min y-pos
* @param maxY The max y-pos * @param maxY The max y-pos
* @param z The z-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 * @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) { 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 * Remove a rope from a lift
* *
* @param lift The name of the lift * @param lift The name of the lift
* @param block The block * @param block The block
*
* @return true/false * @return true/false
*/ */
public boolean removeRope(String lift, Block block) { 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(); String world = block.getWorld().getName();
int x = block.getX(); int x = block.getX();
@ -944,7 +948,7 @@ public class V10LiftAPI {
* Set the queue of a lift * Set the queue of a lift
* *
* @param liftName The name of the lift * @param liftName The name of the lift
* @param queue The queue * @param queue The queue
* @return true/false * @return true/false
*/ */
public boolean setQueue(String liftName, LinkedHashMap<String, Floor> queue) { public boolean setQueue(String liftName, LinkedHashMap<String, Floor> queue) {
@ -961,10 +965,9 @@ public class V10LiftAPI {
/** /**
* Add a location to the queue * Add a location to the queue
* *
* @param lift The name of the lift * @param lift The name of the lift
* @param y The y-pos * @param y The y-pos
* @param world The world * @param world The world
*
* @return true/false * @return true/false
*/ */
public boolean addToQueue(String lift, int y, World world) { public boolean addToQueue(String lift, int y, World world) {
@ -974,11 +977,10 @@ public class V10LiftAPI {
/** /**
* Add a location to the queue * Add a location to the queue
* *
* @param lift The name of the lift * @param lift The name of the lift
* @param y The y-pos * @param y The y-pos
* @param world The world * @param world The world
* @param floorName The name of the flor * @param floorName The name of the flor
*
* @return true/false * @return true/false
*/ */
public boolean addToQueue(String lift, int y, @Nonnull World world, String floorName) { 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 * Add a location to the queue
* *
* @param lift The name of the lift * @param lift The name of the lift
* @param floor The {@link Floor} * @param floor The {@link Floor}
* @param floorName The name of the flor * @param floorName The name of the flor
*
* @return true/false * @return true/false
*/ */
public boolean addToQueue(String lift, Floor floor, String floorName) { public boolean addToQueue(String lift, Floor floor, String floorName) {

View file

@ -9,8 +9,13 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; 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 { public class Floor {
private String world; private String world;
private int y; private int y;
@ -22,7 +27,7 @@ public class Floor {
/** /**
* Construct a new 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 * @param world The world of the floor
*/ */
public Floor(int y, String world) { public Floor(int y, String world) {

View file

@ -8,35 +8,51 @@ import tech.sbdevelopment.v10lift.api.runnables.DoorCloser;
import java.util.*; 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 { public class Lift {
@Getter @Setter private String worldName; @Setter
@Getter @Setter private int y; private String worldName;
@Getter private HashSet<UUID> owners; @Setter
@Getter private final TreeSet<LiftBlock> blocks = new TreeSet<>(); private int y;
@Getter private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>(); private HashSet<UUID> owners;
@Getter private final HashSet<LiftSign> signs = new HashSet<>(); private final TreeSet<LiftBlock> blocks = new TreeSet<>();
@Getter private final HashSet<LiftBlock> inputs = new HashSet<>(); private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>();
@Getter private final HashSet<LiftBlock> offlineInputs = new HashSet<>(); private final HashSet<LiftSign> signs = new HashSet<>();
@Getter @Setter private LinkedHashMap<String, Floor> queue = null; private final HashSet<LiftBlock> inputs = new HashSet<>();
@Getter private final HashSet<LiftRope> ropes = new HashSet<>(); private final HashSet<LiftBlock> offlineInputs = new HashSet<>();
@Getter private transient final ArrayList<V10Entity> toMove = new ArrayList<>(); @Setter
@Getter @Setter private int speed; private LinkedHashMap<String, Floor> queue = null;
@Getter @Setter private boolean realistic; private final HashSet<LiftRope> ropes = new HashSet<>();
@Getter @Setter private boolean offline = false; private transient final ArrayList<V10Entity> toMove = new ArrayList<>();
@Getter @Setter private boolean sound = true; @Setter
@Getter @Setter private boolean defective = false; private int speed;
@Getter @Setter private String signText = null; @Setter
@Getter @Setter private int counter = 0; private boolean realistic;
@Getter @Setter private Floor doorOpen = null; @Setter
@Getter @Setter private DoorCloser doorCloser = null; 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 * Construct a new Lift with multiple owners
* *
* @param owners The owners, by uuid * @param owners The owners, by uuid
* @param speed The speed, 1 is slowest, higher is faster * @param speed The speed, 1 is slowest, higher is faster
* @param realistic Realistic lift, or not * @param realistic Realistic lift, or not
*/ */
public Lift(HashSet<UUID> owners, int speed, boolean realistic) { public Lift(HashSet<UUID> owners, int speed, boolean realistic) {
@ -48,8 +64,8 @@ public class Lift {
/** /**
* Construct a new Lift with one owners * Construct a new Lift with one owners
* *
* @param owner The owner, by uuid * @param owner The owner, by uuid
* @param speed The speed, 1 is slowest, higher is faster * @param speed The speed, 1 is slowest, higher is faster
* @param realistic Realistic lift, or not * @param realistic Realistic lift, or not
*/ */
public Lift(UUID owner, int speed, boolean realistic) { public Lift(UUID owner, int speed, boolean realistic) {

View file

@ -3,33 +3,39 @@ package tech.sbdevelopment.v10lift.api.objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
/** A liftblock object, for a block in a lift. */ /**
* A liftblock object, for a block in a lift.
*/
@Getter
@NoArgsConstructor @NoArgsConstructor
@ToString
public class LiftBlock implements Comparable<LiftBlock> { public class LiftBlock implements Comparable<LiftBlock> {
private String world;
@Getter @Setter private String world; private int x;
@Getter private int x; @Setter
@Getter @Setter private int y; private int y;
@Getter private int z; private int z;
//Only used for cabine blocks, because those need caching! //Only used for cabine blocks, because those need caching!
@Getter @Setter private Material mat; @Setter
@Getter private byte data; private Material mat;
@Getter private BlockFace face; private byte data;
@Getter private String bisected; private BlockFace face;
@Getter private String slabtype; private String bisected;
@Getter private String[] signLines; private String slabtype;
private String[] signLines;
//Only used for inputs! //Only used for inputs!
@Getter private String floor; private String floor;
@Getter @Setter private boolean active = false; @Setter
private boolean active = false;
//Only used for chests //Only used for chests
public Map<String, Object>[] serializedItemStacks = null; public Map<String, Object>[] serializedItemStacks = null;
@ -38,9 +44,9 @@ public class LiftBlock implements Comparable<LiftBlock> {
* A floor based liftblock, without material (no caching) * A floor based liftblock, without material (no caching)
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param floor The floorname of the block * @param floor The floorname of the block
*/ */
public LiftBlock(String world, int x, int y, int z, String floor) { public LiftBlock(String world, int x, int y, int z, String floor) {
@ -61,11 +67,11 @@ public class LiftBlock implements Comparable<LiftBlock> {
* 1.12 liftblock, with material and data [NO SIGN] * 1.12 liftblock, with material and data [NO SIGN]
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param mat The Material of the block * @param mat The Material of the block
* @param data The data of the block * @param data The data of the block
*/ */
public LiftBlock(String world, int x, int y, int z, Material mat, byte data) { public LiftBlock(String world, int x, int y, int z, Material mat, byte data) {
this.world = world; this.world = world;
@ -84,12 +90,12 @@ public class LiftBlock implements Comparable<LiftBlock> {
/** /**
* 1.12 liftblock (signs) * 1.12 liftblock (signs)
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param mat The Material of the block * @param mat The Material of the block
* @param data The data of the block * @param data The data of the block
* @param signLines The lines of the sign * @param signLines The lines of the sign
*/ */
public LiftBlock(String world, int x, int y, int z, Material mat, byte data, String[] signLines) { 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<LiftBlock> {
* 1.13 liftblock, without a direction * 1.13 liftblock, without a direction
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param mat The Material of the block * @param mat The Material of the block
*/ */
public LiftBlock(String world, int x, int y, int z, Material mat) { public LiftBlock(String world, int x, int y, int z, Material mat) {
this.world = world; this.world = world;
@ -133,11 +139,11 @@ public class LiftBlock implements Comparable<LiftBlock> {
* 1.13 liftblock with a direction * 1.13 liftblock with a direction
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param mat The Material of the block * @param mat The Material of the block
* @param face The blockface of the block * @param face The blockface of the block
*/ */
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face) { public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face) {
this.world = world; this.world = world;
@ -156,12 +162,12 @@ public class LiftBlock implements Comparable<LiftBlock> {
/** /**
* 1.13 liftblock, with a direction and a bisected * 1.13 liftblock, with a direction and a bisected
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param mat The Material of the block * @param mat The Material of the block
* @param face The blockface of the block * @param face The blockface of the block
* @param bisected The bisected 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) { 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<LiftBlock> {
/** /**
* 1/13 liftblock (sign) * 1/13 liftblock (sign)
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param mat The Material of the block * @param mat The Material of the block
* @param face The blockface of the block * @param face The blockface of the block
* @param signLines The lines of the sign * @param signLines The lines of the sign
*/ */
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String[] signLines) { 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<LiftBlock> {
/** /**
* 1.13 liftblock (slab) * 1.13 liftblock (slab)
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param mat The Material of the block * @param mat The Material of the block
* @param slabtype The typ of slab (low, high, double) * @param slabtype The typ of slab (low, high, double)
*/ */
public LiftBlock(String world, int x, int y, int z, Material mat, String slabtype) { public LiftBlock(String world, int x, int y, int z, Material mat, String slabtype) {
@ -264,22 +270,4 @@ public class LiftBlock implements Comparable<LiftBlock> {
result = prime * result + z; result = prime * result + z;
return result; 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) +
'}';
}
} }

View file

@ -3,13 +3,19 @@ package tech.sbdevelopment.v10lift.api.objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import java.util.Objects; 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 { public class LiftRope {
private Material type; private Material type;
private BlockFace face; private BlockFace face;
@ -23,13 +29,13 @@ public class LiftRope {
/** /**
* Construct a new liftrope * Construct a new liftrope
* *
* @param type The material of the rope * @param type The material of the rope
* @param face The face of the rope * @param face The face of the rope
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param minY The starting x-pos * @param minY The starting x-pos
* @param maxY The stopping x-pos * @param maxY The stopping x-pos
* @param z The z-pos * @param z The z-pos
*/ */
public LiftRope(Material type, BlockFace face, String world, int x, int minY, int maxY, int z) { public LiftRope(Material type, BlockFace face, String world, int x, int minY, int maxY, int z) {
this.type = type; this.type = type;
@ -65,18 +71,4 @@ public class LiftRope {
result = prime * result + z; result = prime * result + z;
return result; return result;
} }
@Override
public String toString() {
return "LiftRope{" +
"type=" + type +
", face=" + face +
", world='" + world + '\'' +
", x=" + x +
", minY=" + minY +
", maxY=" + maxY +
", z=" + z +
", currently=" + currently +
'}';
}
} }

View file

@ -3,9 +3,15 @@ package tech.sbdevelopment.v10lift.api.objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; 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 { public class LiftSign {
private String world; private String world;
private int x; private int x;
@ -19,10 +25,10 @@ public class LiftSign {
* Construct a new liftsign * Construct a new liftsign
* *
* @param world The world * @param world The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param type The type of the sign * @param type The type of the sign
* @param state The state of the sign * @param state The state of the sign
*/ */
public LiftSign(String world, int x, int y, int z, byte type, byte state) { 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; result = prime * result + z;
return result; return result;
} }
@Override
public String toString() {
return "LiftSign{" +
"world='" + world + '\'' +
", x=" + x +
", z=" + z +
", y=" + y +
", oldText='" + oldText + '\'' +
", type=" + type +
", state=" + state +
'}';
}
} }

View file

@ -3,14 +3,19 @@ package tech.sbdevelopment.v10lift.api.objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import java.util.UUID; 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 { public class V10Entity {
private UUID entityUUID; private UUID entityUUID;
private String world; private String world;
@ -18,17 +23,18 @@ public class V10Entity {
private int locY; private int locY;
private int locZ; private int locZ;
private int y; private int y;
@Setter private short step; @Setter
private short step;
/** /**
* Construct a new V10LiftEntity * Construct a new V10LiftEntity
* *
* @param entityUUID The UUID of the entity * @param entityUUID The UUID of the entity
* @param worldName The world * @param worldName The world
* @param x The x-pos * @param x The x-pos
* @param y The y-pos * @param y The y-pos
* @param z The z-pos * @param z The z-pos
* @param cury The current y-pos * @param cury The current y-pos
*/ */
public V10Entity(UUID entityUUID, String worldName, int x, int y, int z, int cury) { public V10Entity(UUID entityUUID, String worldName, int x, int y, int z, int cury) {
this.entityUUID = entityUUID; this.entityUUID = entityUUID;
@ -93,17 +99,4 @@ public class V10Entity {
public int hashCode() { public int hashCode() {
return 31 + ((entityUUID == null) ? 0 : entityUUID.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 +
'}';
}
} }

View file

@ -1,11 +1,13 @@
package tech.sbdevelopment.v10lift.api.runnables; package tech.sbdevelopment.v10lift.api.runnables;
import org.bukkit.Bukkit;
import tech.sbdevelopment.v10lift.V10LiftPlugin; import tech.sbdevelopment.v10lift.V10LiftPlugin;
import tech.sbdevelopment.v10lift.api.V10LiftAPI; import tech.sbdevelopment.v10lift.api.V10LiftAPI;
import tech.sbdevelopment.v10lift.managers.DataManager; 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 { public class DoorCloser implements Runnable {
private final String liftName; private final String liftName;
private final int taskID; private final int taskID;

View file

@ -2,6 +2,14 @@ package tech.sbdevelopment.v10lift.api.runnables;
import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound; 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.V10LiftPlugin;
import tech.sbdevelopment.v10lift.api.V10LiftAPI; import tech.sbdevelopment.v10lift.api.V10LiftAPI;
import tech.sbdevelopment.v10lift.api.enums.LiftDirection; 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.sbutils.LocationSerializer;
import tech.sbdevelopment.v10lift.utils.ConfigUtil; import tech.sbdevelopment.v10lift.utils.ConfigUtil;
import tech.sbdevelopment.v10lift.utils.DirectionUtil; 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.lang.reflect.Method;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Supplier; 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 { public class MoveLift implements Runnable {
/* Packet teleportation method */ /* Packet teleportation method */
private final Method[] methods = ((Supplier<Method[]>) () -> { private final Method[] methods = ((Supplier<Method[]>) () -> {
try { try {
Method getHandle = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".entity.CraftEntity").getDeclaredMethod("getHandle"); Method getHandle = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".entity.CraftEntity").getDeclaredMethod("getHandle");
return new Method[] { return new Method[]{
getHandle, getHandle.getReturnType().getDeclaredMethod("setPositionRotation", double.class, double.class, double.class, float.class, float.class) getHandle, getHandle.getReturnType().getDeclaredMethod("setPositionRotation", double.class, double.class, double.class, float.class, float.class)
}; };
} catch (Exception ex) { } catch (Exception ex) {
return null; return null;
} }
}).get(); }).get();
private final String liftName; private final String liftName;
@ -250,7 +251,8 @@ public class MoveLift implements Runnable {
while (toMoveIterator.hasNext()) { while (toMoveIterator.hasNext()) {
V10Entity v10ent = toMoveIterator.next(); V10Entity v10ent = toMoveIterator.next();
if (v10ent.getStep() > 0) { 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) { if (v10ent.getStep() > 16) {
toMoveIterator.remove(); toMoveIterator.remove();
} }
@ -426,7 +428,8 @@ public class MoveLift implements Runnable {
if (lift.isRealistic()) lift.setCounter(ft); 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);
} }
} }

View file

@ -1,6 +1,15 @@
package tech.sbdevelopment.v10lift.commands; package tech.sbdevelopment.v10lift.commands;
import com.cryptomorin.xseries.XMaterial; 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.V10LiftPlugin;
import tech.sbdevelopment.v10lift.api.V10LiftAPI; import tech.sbdevelopment.v10lift.api.V10LiftAPI;
import tech.sbdevelopment.v10lift.api.objects.Floor; 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.managers.VaultManager;
import tech.sbdevelopment.v10lift.sbutils.LocationSerializer; import tech.sbdevelopment.v10lift.sbutils.LocationSerializer;
import tech.sbdevelopment.v10lift.utils.ConfigUtil; 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 javax.annotation.Nonnull;
import java.sql.SQLException; import java.sql.SQLException;

View file

@ -1,15 +1,15 @@
package tech.sbdevelopment.v10lift.commands; 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.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; 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 javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,6 +21,7 @@ public class V10LiftTabCompleter implements TabCompleter {
private static final List<String> 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<String> 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<String> SUBRENAME = Arrays.asList("add", "del", "rename"); private static final List<String> SUBRENAME = Arrays.asList("add", "del", "rename");
private static final List<String> SUB = Arrays.asList("add", "del"); private static final List<String> SUB = Arrays.asList("add", "del");
@Override @Override
public List<String> onTabComplete(@Nonnull CommandSender commandSender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) { public List<String> onTabComplete(@Nonnull CommandSender commandSender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) {
if (label.equalsIgnoreCase("v10lift")) { if (label.equalsIgnoreCase("v10lift")) {

View file

@ -1,12 +1,5 @@
package tech.sbdevelopment.v10lift.listeners; 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.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -14,6 +7,13 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; 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.Map;
import java.util.Objects; import java.util.Objects;

View file

@ -1,8 +1,5 @@
package tech.sbdevelopment.v10lift.listeners; 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.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -10,6 +7,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent; 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 { public class EntityDamageListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View file

@ -1,16 +1,6 @@
package tech.sbdevelopment.v10lift.listeners; package tech.sbdevelopment.v10lift.listeners;
import com.cryptomorin.xseries.XMaterial; 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.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -27,6 +17,16 @@ import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; 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.*; import java.util.*;
@ -42,8 +42,8 @@ public class PlayerInteractListener implements Listener {
Material button = block.getType(); Material button = block.getType();
if (action == Action.RIGHT_CLICK_BLOCK if (action == Action.RIGHT_CLICK_BLOCK
&& e.getHand() != EquipmentSlot.OFF_HAND && e.getHand() != EquipmentSlot.OFF_HAND
&& (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) { && (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) {
String world = block.getWorld().getName(); String world = block.getWorld().getName();
int x = block.getX(); int x = block.getX();
int y = block.getY(); int y = block.getY();
@ -104,7 +104,8 @@ public class PlayerInteractListener implements Listener {
return; 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; if (DataManager.containsEditLift(liftName)) return;
e.setCancelled(true); e.setCancelled(true);
if (lift.isDefective()) return; if (lift.isDefective()) return;
@ -367,7 +368,8 @@ public class PlayerInteractListener implements Listener {
return; 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; if (DataManager.containsEditLift(liftName)) return;
e.setCancelled(true); e.setCancelled(true);
if (lift.isDefective()) return; if (lift.isDefective()) return;

View file

@ -1,9 +1,5 @@
package tech.sbdevelopment.v10lift.listeners; 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.ChatColor;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,6 +7,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent; 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 { public class SignChangeListener implements Listener {

View file

@ -1,10 +1,10 @@
package tech.sbdevelopment.v10lift.managers; package tech.sbdevelopment.v10lift.managers;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.bukkit.Bukkit;
import tech.sbdevelopment.v10lift.V10LiftPlugin; import tech.sbdevelopment.v10lift.V10LiftPlugin;
import tech.sbdevelopment.v10lift.api.objects.Lift; import tech.sbdevelopment.v10lift.api.objects.Lift;
import tech.sbdevelopment.v10lift.sbutils.SQLiteDB; import tech.sbdevelopment.v10lift.sbutils.SQLiteDB;
import org.bukkit.Bukkit;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -104,7 +104,7 @@ public class DBManager {
* Save a lift to data * Save a lift to data
* *
* @param liftName The name of the lift * @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) { public void saveLift(String liftName, Lift lift, boolean sync) {
Bukkit.getLogger().info("[V10Lift] Saving lift " + liftName + " to data..."); Bukkit.getLogger().info("[V10Lift] Saving lift " + liftName + " to data...");
@ -130,7 +130,8 @@ public class DBManager {
statement.setString(1, liftName); statement.setString(1, liftName);
statement.setBytes(2, liftData); statement.setBytes(2, liftData);
statement.executeUpdate(); statement.executeUpdate();
} catch (SQLException ignored) {} } catch (SQLException ignored) {
}
try { try {
String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?"; String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?";

View file

@ -1,10 +1,10 @@
package tech.sbdevelopment.v10lift.managers; package tech.sbdevelopment.v10lift.managers;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;

View file

@ -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 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. * 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. * If a key has an attached comment above it, it is written first.
*
* @author tchristofferson * @author tchristofferson
*/ */
public class ConfigUpdater { public class ConfigUpdater {
/** /**
* Update a yaml file from a resource inside your plugin jar * 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 plugin You plugin
* @param toUpdate The yaml file to update * @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 * @param ignoredSections List of sections to ignore and copy from the current config
* @throws IOException If an IOException occurs * @throws IOException If an IOException occurs
*/ */
@ -54,7 +56,8 @@ public class ConfigUpdater {
//Write method doing the work. //Write method doing the work.
//It checks if key has a comment associated with it and writes comment then the key and value //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<String, String> comments, List<String> ignoredSections, BufferedWriter writer, Yaml yaml) throws IOException { private static void write(FileConfiguration newConfig, FileConfiguration oldConfig, Map<String, String> comments, List<String> 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[] keys = key.split("\\.");
String actualKey = keys[keys.length - 1]; String actualKey = keys[keys.length - 1];
String comment = comments.remove(key); String comment = comments.remove(key);
@ -173,7 +176,8 @@ public class ConfigUpdater {
StringBuilder keyBuilder = new StringBuilder(); StringBuilder keyBuilder = new StringBuilder();
int lastLineIndentCount = 0; int lastLineIndentCount = 0;
outer: for (int i = 0; i<lines.size(); i++) { outer:
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i); String line = lines.get(i);
if (line != null && line.trim().startsWith("-")) if (line != null && line.trim().startsWith("-"))
continue; continue;
@ -228,7 +232,7 @@ public class ConfigUpdater {
} else if (value instanceof List) { } else if (value instanceof List) {
builder.append(getListAsString((List<?>) value, actualKey, prefixSpaces.toString(), yaml)); builder.append(getListAsString((List<?>) value, actualKey, prefixSpaces.toString(), yaml));
} else { } 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 currentSpaces = getSpaces(lines.get(index));
int indents = 0; int indents = 0;
for (int i = index-1; i >= 0; i--){ for (int i = index - 1; i >= 0; i--) {
String line = lines.get(i); String line = lines.get(i);
if (line == null || line.trim().equals("")) continue; if (line == null || line.trim().equals("")) continue;
int newSpaces = getSpaces(lines.get(i)); int newSpaces = getSpaces(lines.get(i));
// differs at least two // differs at least two
if (newSpaces < currentSpaces - 1){ if (newSpaces < currentSpaces - 1) {
indents++; indents++;
currentSpaces = newSpaces; currentSpaces = newSpaces;
} }
@ -253,7 +257,7 @@ public class ConfigUpdater {
return indents; return indents;
} }
private static int getSpaces(String line){ private static int getSpaces(String line) {
int spaces = 0; int spaces = 0;
for (char c : line.toCharArray()) { for (char c : line.toCharArray()) {
if (c == ' ') { if (c == ' ') {
@ -285,7 +289,7 @@ public class ConfigUpdater {
} }
//Updates the keyBuilder and returns configLines number of indents //Updates the keyBuilder and returns configLines number of indents
private static int setFullKey(StringBuilder keyBuilder, int index, List<String> configLines, int lastLineIndentCount) { private static int setFullKey(StringBuilder keyBuilder, int index, List<String> configLines, int lastLineIndentCount) {
int currentIndents = countIndents(index, configLines); int currentIndents = countIndents(index, configLines);
String key = configLines.get(index).trim().split(":")[0]; String key = configLines.get(index).trim().split(":")[0];

View file

@ -11,7 +11,6 @@ public class LocationSerializer {
* Deserialize a serialized location, without {@link Location#getYaw()} and {@link Location#getPitch()} * Deserialize a serialized location, without {@link Location#getYaw()} and {@link Location#getPitch()}
* *
* @param string The location string * @param string The location string
*
* @return The location or null if error * @return The location or null if error
*/ */
@Nullable @Nullable
@ -33,7 +32,6 @@ public class LocationSerializer {
* Deserialize a serialized location, with {@link Location#getYaw()} and {@link Location#getPitch()} * Deserialize a serialized location, with {@link Location#getYaw()} and {@link Location#getPitch()}
* *
* @param string The location string * @param string The location string
*
* @return The location or null if error * @return The location or null if error
*/ */
@Nonnull @Nonnull
@ -55,7 +53,6 @@ public class LocationSerializer {
* Serialize a location, without {@link Location#getYaw()} and {@link Location#getPitch()} * Serialize a location, without {@link Location#getYaw()} and {@link Location#getPitch()}
* *
* @param loc The location * @param loc The location
*
* @return The serialized string * @return The serialized string
*/ */
@Nullable @Nullable
@ -68,7 +65,6 @@ public class LocationSerializer {
* Serialize a location, with {@link Location#getYaw()} and {@link Location#getPitch()} * Serialize a location, with {@link Location#getYaw()} and {@link Location#getPitch()}
* *
* @param loc The location * @param loc The location
*
* @return The serialized string * @return The serialized string
*/ */
@Nullable @Nullable

View file

@ -2,8 +2,8 @@ package tech.sbdevelopment.v10lift.sbutils;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -63,7 +63,7 @@ public class SQLiteDB {
/** /**
* Get the connection, to execute queries * Get the connection, to execute queries
* * <p>
* CREATE TABLE - execute() * CREATE TABLE - execute()
* SELECT - executeQuery() * SELECT - executeQuery()
* UPDATE - executeUpdate() * UPDATE - executeUpdate()

View file

@ -1,9 +1,9 @@
package tech.sbdevelopment.v10lift.sbutils; package tech.sbdevelopment.v10lift.sbutils;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View file

@ -1,8 +1,8 @@
package tech.sbdevelopment.v10lift.utils; package tech.sbdevelopment.v10lift.utils;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import tech.sbdevelopment.v10lift.V10LiftPlugin;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.HashMap; import java.util.HashMap;
@ -28,7 +28,7 @@ public class ConfigUtil {
/** /**
* Send a message from the messages.yml without variables * 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 * @param path The path to look for
*/ */
public static void sendMessage(CommandSender p, @Nonnull String path) { 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 * Get a message from the messages.yml with variables
* *
* @param p The commandsender to send it to * @param p The commandsender to send it to
* @param path The path to look for * @param path The path to look for
* @param replacement The replacements - key: %Name% = value: TheName * @param replacement The replacements - key: %Name% = value: TheName
*/ */
public static void sendMessage(CommandSender p, @Nonnull String path, Map<String, String> replacement) { public static void sendMessage(CommandSender p, @Nonnull String path, Map<String, String> replacement) {

View file

@ -14,12 +14,14 @@ public class DoorUtil {
/** /**
* Open a door, with 1.12.x- and 1.13.x+ support * Open a door, with 1.12.x- and 1.13.x+ support
*
* @param b The block (door) * @param b The block (door)
* @return true if opened, false if not opened * @return true if opened, false if not opened
*/ */
public static boolean openDoor(@Nonnull Block b) { 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() == 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 (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_OPEN.play(b.getLocation());
if (XMaterial.supports(13)) { if (XMaterial.supports(13)) {
//1.13+ //1.13+
@ -52,12 +54,14 @@ public class DoorUtil {
/** /**
* Close a door, with 1.12.x- and 1.13.x+ support * Close a door, with 1.12.x- and 1.13.x+ support
*
* @param b The block (door) * @param b The block (door)
* @return true if opened, false if not opened * @return true if opened, false if not opened
*/ */
public static boolean closeDoor(@Nonnull Block b) { 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() == 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 (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_CLOSE.play(b.getLocation());
if (XMaterial.supports(13)) { if (XMaterial.supports(13)) {
//1.13+ //1.13+