Fixed register at shutdown exception, refactor of the folder structure #61

Merged
stijnb1234 merged 2 commits from development into master 2022-06-10 18:38:18 +00:00
41 changed files with 213 additions and 115 deletions
Showing only changes of commit ca0d2dcd6d - Show all commits

25
pom.xml
View file

@ -85,6 +85,7 @@
</execution>
</executions>
</plugin>
<!-- Compile JAR -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@ -94,11 +95,17 @@
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<!-- Delombok the source for the javadoc -->
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.20.0</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
@ -108,17 +115,26 @@
</execution>
</executions>
</plugin>
<!-- Build the javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<sourceFileIncludes>
<include>nl/SBDeveloper/V10Lift/api/*.java</include>
<include>nl/SBDeveloper/V10Lift/api/objects/*.java</include>
</sourceFileIncludes>
<sourcepath>${project.build.directory}/delombok</sourcepath>
<!-- Exclude all non-API packages -->
<sourceFileExcludes>
<exclude>nl/SBDeveloper/V10Lift/*.java</exclude>
<exclude>nl/SBDeveloper/V10Lift/commands/*.java</exclude>
<exclude>nl/SBDeveloper/V10Lift/listeners/*.java</exclude>
<exclude>nl/SBDeveloper/V10Lift/sbutils/*.java</exclude>
<exclude>nl/SBDeveloper/V10Lift/utils/*.java</exclude>
</sourceFileExcludes>
</configuration>
</plugin>
<!-- SKIP the maven deploy -->
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
@ -127,6 +143,7 @@
<skip>true</skip>
</configuration>
</plugin>
<!-- Deploy to nexus -->
<plugin>
<groupId>org.sonatype.plugins</groupId>

View file

@ -28,7 +28,6 @@ public class V10LiftPlugin extends JavaPlugin {
private static YamlFile config;
private static DBManager dbManager;
private static YamlFile messages;
private static V10LiftAPI api;
private static boolean vault = false;
@Override
@ -60,9 +59,6 @@ public class V10LiftPlugin extends JavaPlugin {
e.printStackTrace();
}
//Load the API
api = new V10LiftAPI();
//Load vault if found
if (VaultManager.setupPermissions()) {
Bukkit.getLogger().info("[V10Lift] Loading Vault hook for group whitelist support.");
@ -128,7 +124,7 @@ public class V10LiftPlugin extends JavaPlugin {
@Override
public void onDisable() {
dbManager.save();
dbManager.save(true);
dbManager.closeConnection();
instance = null;
@ -150,10 +146,6 @@ public class V10LiftPlugin extends JavaPlugin {
return messages;
}
public static V10LiftAPI getAPI() {
return api;
}
public static boolean isVaultEnabled() {
return vault;
}

View file

@ -25,6 +25,15 @@ import java.util.*;
/** The Main API class, for all the API methods */
public class V10LiftAPI {
private static V10LiftAPI instance;
private V10LiftAPI() {}
public static V10LiftAPI getInstance() {
if (instance == null) instance = new V10LiftAPI();
return instance;
}
/* Private API methods */
private void sortFloors(@Nonnull Lift lift) {
ArrayList<Map.Entry<String, Floor>> as = new ArrayList<>(lift.getFloors().entrySet());
@ -101,7 +110,7 @@ public class V10LiftAPI {
}
DataManager.removeLift(liftName);
V10LiftPlugin.getDBManager().removeFromData(liftName);
V10LiftPlugin.getDBManager().remove(liftName);
return true;
}

View file

@ -0,0 +1,4 @@
/**
* All the enums used for V10Lift
*/
package nl.SBDeveloper.V10Lift.api.enums;

View file

@ -1,6 +1,7 @@
package nl.SBDeveloper.V10Lift.api.runnables;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
import nl.SBDeveloper.V10Lift.managers.DataManager;
import org.bukkit.Bukkit;
@ -18,7 +19,7 @@ public class DoorCloser implements Runnable {
@Override
public void run() {
if (V10LiftPlugin.getAPI().closeDoor(liftName)) stop();
if (V10LiftAPI.getInstance().closeDoor(liftName)) stop();
}
public void stop() {

View file

@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.api.runnables;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
import nl.SBDeveloper.V10Lift.api.enums.LiftDirection;
import nl.SBDeveloper.V10Lift.api.objects.*;
import nl.SBDeveloper.V10Lift.managers.AntiCopyBlockManager;
@ -119,7 +120,7 @@ public class MoveLift implements Runnable {
if (changeOfDefect > 0.0D) {
double chance = ThreadLocalRandom.current().nextDouble(100);
if (chance < changeOfDefect) {
V10LiftPlugin.getAPI().setDefective(liftName, true);
V10LiftAPI.getInstance().setDefective(liftName, true);
return;
}
}
@ -141,7 +142,7 @@ public class MoveLift implements Runnable {
List<LiftBlock> antiCopyBlocks = new ArrayList<>();
if (direction == LiftDirection.UP || direction == LiftDirection.DOWN) {
if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return;
if (!V10LiftAPI.getInstance().closeDoor(liftName)) return;
if (direction == LiftDirection.UP) {
//MOVE ROPES
@ -149,7 +150,7 @@ public class MoveLift implements Runnable {
if (rope.getCurrently() > rope.getMaxY()) {
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
V10LiftPlugin.getAPI().setDefective(liftName, true);
V10LiftAPI.getInstance().setDefective(liftName, true);
lift.getToMove().clear();
queueIterator.remove();
return;
@ -328,7 +329,7 @@ public class MoveLift implements Runnable {
if (rope.getCurrently() < rope.getMinY()) {
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
V10LiftPlugin.getAPI().setDefective(liftName, true);
V10LiftAPI.getInstance().setDefective(liftName, true);
lift.getToMove().clear();
queueIterator.remove();
@ -420,7 +421,7 @@ public class MoveLift implements Runnable {
ls.setState((byte) 0);
}
V10LiftPlugin.getAPI().openDoor(lift, liftName, floorTo);
V10LiftAPI.getInstance().openDoor(lift, liftName, floorTo);
if (lift.isRealistic()) lift.setCounter(ft);

View file

@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.commands;
import com.cryptomorin.xseries.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
import nl.SBDeveloper.V10Lift.api.objects.Floor;
import nl.SBDeveloper.V10Lift.api.objects.Lift;
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
@ -261,7 +262,7 @@ public class V10LiftCommand implements CommandExecutor {
return true;
}
V10LiftPlugin.getAPI().setDefective(liftName, true);
V10LiftAPI.getInstance().setDefective(liftName, true);
ConfigUtil.sendMessage(sender, "Disable.Disabled");
return true;
}
@ -271,7 +272,7 @@ public class V10LiftCommand implements CommandExecutor {
if (args.length == 1 && sender instanceof Player) {
//v10lift stop -> Get liftName from loc and floorName from sign
Player p = (Player) sender;
liftName = V10LiftPlugin.getAPI().getLiftByLocation(p.getLocation());
liftName = V10LiftAPI.getInstance().getLiftByLocation(p.getLocation());
} else if (args.length == 1) {
ConfigUtil.sendMessage(sender, "Stop.NonPlayer");
return true;
@ -303,7 +304,7 @@ public class V10LiftCommand implements CommandExecutor {
if (args.length == 1 && sender instanceof Player) {
//v10lift start -> Get liftName from loc and floorName from sign
Player p = (Player) sender;
liftName = V10LiftPlugin.getAPI().getLiftByLocation(p.getLocation());
liftName = V10LiftAPI.getInstance().getLiftByLocation(p.getLocation());
} else if (args.length == 1) {
ConfigUtil.sendMessage(sender, "Start.NonPlayer");
return true;
@ -341,7 +342,7 @@ public class V10LiftCommand implements CommandExecutor {
}
Floor f = lift.getFloors().get(floorName);
V10LiftPlugin.getAPI().addToQueue(liftName, f, floorName);
V10LiftAPI.getInstance().addToQueue(liftName, f, floorName);
ConfigUtil.sendMessage(sender, "Start.Started", Collections.singletonMap("%Name%", liftName));
return true;
}
@ -354,13 +355,13 @@ public class V10LiftCommand implements CommandExecutor {
}
e.getValue().setQueue(null);
V10LiftPlugin.getAPI().sortLiftBlocks(lift);
V10LiftAPI.getInstance().sortLiftBlocks(lift);
}
DataManager.clearMovingTasks();
V10LiftPlugin.getSConfig().reloadConfig();
try {
V10LiftPlugin.getDBManager().save();
V10LiftPlugin.getDBManager().save(true);
V10LiftPlugin.getDBManager().load();
} catch (SQLException e) {
e.printStackTrace();
@ -406,7 +407,7 @@ public class V10LiftCommand implements CommandExecutor {
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
DataManager.removeBuilderPlayer(p.getUniqueId());
V10LiftPlugin.getAPI().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
V10LiftAPI.getInstance().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
abort = true;
}
@ -473,7 +474,7 @@ public class V10LiftCommand implements CommandExecutor {
}
}
}
V10LiftPlugin.getAPI().setDefective(liftName, false);
V10LiftAPI.getInstance().setDefective(liftName, false);
ConfigUtil.sendMessage(sender, "Repair.Repaired");
return true;
}
@ -557,7 +558,7 @@ public class V10LiftCommand implements CommandExecutor {
if (!DataManager.containsLift(liftName)) {
ConfigUtil.sendMessage(sender, "Whois.DoesntExists");
} else {
V10LiftPlugin.getAPI().sendLiftInfo(sender, liftName);
V10LiftAPI.getInstance().sendLiftInfo(sender, liftName);
}
}
return true;
@ -731,7 +732,7 @@ public class V10LiftCommand implements CommandExecutor {
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
DataManager.removeBuilderPlayer(p.getUniqueId());
V10LiftPlugin.getAPI().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
V10LiftAPI.getInstance().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
ConfigUtil.sendMessage(sender, "Build.Disabled");
} else {
DataManager.addBuilderPlayer(p.getUniqueId());
@ -754,7 +755,7 @@ public class V10LiftCommand implements CommandExecutor {
}
Bukkit.dispatchCommand(sender, "v10lift edit");
V10LiftPlugin.getAPI().renameLift(liftName, args[1]);
V10LiftAPI.getInstance().renameLift(liftName, args[1]);
Bukkit.dispatchCommand(sender, "v10lift edit " + args[1]);
ConfigUtil.sendMessage(sender, "Rename.Renamed");
@ -877,7 +878,7 @@ public class V10LiftCommand implements CommandExecutor {
if (args[1].equalsIgnoreCase("add")) {
Block b = p.getLocation().getBlock();
String floorName = args[2];
int response = V10LiftPlugin.getAPI().addFloor(liftName, floorName, new Floor(b.getY() - 1, b.getWorld().getName()));
int response = V10LiftAPI.getInstance().addFloor(liftName, floorName, new Floor(b.getY() - 1, b.getWorld().getName()));
switch (response) {
case 0:
ConfigUtil.sendMessage(sender, "Floor.Added");
@ -894,7 +895,7 @@ public class V10LiftCommand implements CommandExecutor {
}
} else if (args[1].equalsIgnoreCase("del")) {
String floorName = args[2];
if (!V10LiftPlugin.getAPI().removeFloor(liftName, floorName)) {
if (!V10LiftAPI.getInstance().removeFloor(liftName, floorName)) {
ConfigUtil.sendMessage(sender, "General.InternalError");
} else {
ConfigUtil.sendMessage(sender, "Floor.Removed");
@ -907,7 +908,7 @@ public class V10LiftCommand implements CommandExecutor {
String floorName = args[2];
String newFloorName = args[3];
int response = V10LiftPlugin.getAPI().renameFloor(liftName, floorName, newFloorName);
int response = V10LiftAPI.getInstance().renameFloor(liftName, floorName, newFloorName);
switch (response) {
case 0:
ConfigUtil.sendMessage(sender, "Floor.Renamed");
@ -948,7 +949,7 @@ public class V10LiftCommand implements CommandExecutor {
DataManager.removeOfflineRemovesPlayer(p.getUniqueId());
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
DataManager.removeBuilderPlayer(p.getUniqueId());
V10LiftPlugin.getAPI().sortLiftBlocks(liftName);
V10LiftAPI.getInstance().sortLiftBlocks(liftName);
}
DataManager.removeRopeEditPlayer(p.getUniqueId());
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
@ -1048,7 +1049,7 @@ public class V10LiftCommand implements CommandExecutor {
return true;
}
if (!V10LiftPlugin.getAPI().removeLift(args[1])) {
if (!V10LiftAPI.getInstance().removeLift(args[1])) {
ConfigUtil.sendMessage(sender, "Delete.NotRemoved", Collections.singletonMap("%Name%", args[1]));
return true;
}
@ -1072,15 +1073,15 @@ public class V10LiftCommand implements CommandExecutor {
return true;
}
if (!V10LiftPlugin.getAPI().createLift(p, args[1])) {
if (!V10LiftAPI.getInstance().createLift(p, args[1])) {
ConfigUtil.sendMessage(sender, "General.AlreadyExists");
return true;
}
TreeSet<LiftBlock> blcks = DataManager.getLift(args[1]).getBlocks();
blocks.forEach(block -> V10LiftPlugin.getAPI().addBlockToLift(blcks, block));
V10LiftPlugin.getAPI().sortLiftBlocks(args[1]);
blocks.forEach(block -> V10LiftAPI.getInstance().addBlockToLift(blcks, block));
V10LiftAPI.getInstance().sortLiftBlocks(args[1]);
DataManager.removePlayer(p.getUniqueId());
ConfigUtil.sendMessage(p, "Create.Created", Collections.singletonMap("%Name%", args[1]));
p.performCommand("v10lift edit " + args[1]);

View file

@ -1,5 +1,6 @@
package nl.SBDeveloper.V10Lift.listeners;
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
import nl.SBDeveloper.V10Lift.api.objects.Floor;
import nl.SBDeveloper.V10Lift.api.objects.Lift;
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
@ -22,7 +23,7 @@ public class BlockBreakListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
Block b = e.getBlock();
if (V10LiftPlugin.getAPI().isRope(b)) {
if (V10LiftAPI.getInstance().isRope(b)) {
ConfigUtil.sendMessage(e.getPlayer(), "General.RemoveRopeFirst");
e.setCancelled(true);
return;

View file

@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.listeners;
import com.cryptomorin.xseries.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
import nl.SBDeveloper.V10Lift.api.objects.Floor;
import nl.SBDeveloper.V10Lift.api.objects.Lift;
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
@ -52,7 +53,7 @@ public class PlayerInteractListener implements Listener {
for (LiftBlock lb : lift.getOfflineInputs()) {
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
lb.setActive(!lb.isActive());
V10LiftPlugin.getAPI().setOffline(entry.getKey(), lb.isActive());
V10LiftAPI.getInstance().setOffline(entry.getKey(), lb.isActive());
return;
}
}
@ -61,7 +62,7 @@ public class PlayerInteractListener implements Listener {
for (LiftBlock lb : lift.getInputs()) {
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
V10LiftPlugin.getAPI().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor());
V10LiftAPI.getInstance().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor());
e.setCancelled(true);
return;
}
@ -121,13 +122,13 @@ public class PlayerInteractListener implements Listener {
return;
}
if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.userHasAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) {
if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.inAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) {
ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission");
e.setCancelled(true);
return;
}
V10LiftPlugin.getAPI().addToQueue(liftName, lift.getFloors().get(f), f);
V10LiftAPI.getInstance().addToQueue(liftName, lift.getFloors().get(f), f);
}
//BLOCK ADD
@ -140,7 +141,7 @@ public class PlayerInteractListener implements Listener {
if (DataManager.containsPlayer(p.getUniqueId())) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
e.setCancelled(true);
int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getPlayer(p.getUniqueId()), e.getClickedBlock());
int res = V10LiftAPI.getInstance().switchBlockAtLift(DataManager.getPlayer(p.getUniqueId()), e.getClickedBlock());
switch (res) {
case 0:
ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded");
@ -210,7 +211,7 @@ public class PlayerInteractListener implements Listener {
} else if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
e.setCancelled(true);
int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getEditPlayer(p.getUniqueId()), e.getClickedBlock());
int res = V10LiftAPI.getInstance().switchBlockAtLift(DataManager.getEditPlayer(p.getUniqueId()), e.getClickedBlock());
switch (res) {
case 0:
ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded");
@ -241,7 +242,7 @@ public class PlayerInteractListener implements Listener {
ConfigUtil.sendMessage(e.getPlayer(), "Rope.OnlyUp");
return;
}
int res = V10LiftPlugin.getAPI().addRope(DataManager.getEditPlayer(p.getUniqueId()), now.getWorld(), start.getX(), now.getY(), start.getY(), start.getZ());
int res = V10LiftAPI.getInstance().addRope(DataManager.getEditPlayer(p.getUniqueId()), now.getWorld(), start.getX(), now.getY(), start.getY(), start.getZ());
switch (res) {
case 0:
ConfigUtil.sendMessage(e.getPlayer(), "Rope.Created");
@ -266,11 +267,11 @@ public class PlayerInteractListener implements Listener {
e.setCancelled(true);
Block block = e.getClickedBlock();
String liftName = DataManager.getEditPlayer(p.getUniqueId());
if (!V10LiftPlugin.getAPI().containsRope(liftName, block)) {
if (!V10LiftAPI.getInstance().containsRope(liftName, block)) {
ConfigUtil.sendMessage(e.getPlayer(), "Rope.NotARope");
return;
}
V10LiftPlugin.getAPI().removeRope(liftName, block);
V10LiftAPI.getInstance().removeRope(liftName, block);
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
ConfigUtil.sendMessage(e.getPlayer(), "Rope.Removed");
} else if (DataManager.containsDoorEditPlayer(p.getUniqueId())) {
@ -314,7 +315,7 @@ public class PlayerInteractListener implements Listener {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
Lift lift = entry.getValue();
if (lift.getBlocks().contains(lb) || lift.getInputs().contains(lb) || lift.getSigns().contains(lb) || lift.getRopes().contains(lb) || lift.getOfflineInputs().contains(lb)) {
V10LiftPlugin.getAPI().sendLiftInfo(p, entry.getKey(), lift);
V10LiftAPI.getInstance().sendLiftInfo(p, entry.getKey(), lift);
return;
}
}
@ -360,7 +361,7 @@ public class PlayerInteractListener implements Listener {
}
p.getInventory().remove(new ItemStack(masterItem, masterAmount));
}
V10LiftPlugin.getAPI().setDefective(liftName, false);
V10LiftAPI.getInstance().setDefective(liftName, false);
}
e.setCancelled(true);
return;
@ -391,7 +392,7 @@ public class PlayerInteractListener implements Listener {
sign.setLine(3, ChatColor.GREEN + f2);
} else if (!floor.getUserWhitelist().isEmpty() && !floor.getUserWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
sign.setLine(3, ChatColor.RED + f2);
} else if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.userHasAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) {
} else if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.inAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) {
sign.setLine(3, ChatColor.RED + f2);
} else {
sign.setLine(3, ChatColor.YELLOW + f2);
@ -410,13 +411,13 @@ public class PlayerInteractListener implements Listener {
return;
}
if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.userHasAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) {
if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.inAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) {
ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission");
e.setCancelled(true);
return;
}
V10LiftPlugin.getAPI().addToQueue(liftName, lift.getFloors().get(f), f);
V10LiftAPI.getInstance().addToQueue(liftName, lift.getFloors().get(f), f);
}
}
}

View file

@ -5,6 +5,9 @@ import org.bukkit.Material;
import java.util.HashSet;
/**
* This class contains a set with all the blocks who may not be copied
*/
public class AntiCopyBlockManager {
private static final HashSet<XMaterial> antiCopy = new HashSet<>();
@ -79,6 +82,12 @@ public class AntiCopyBlockManager {
antiCopy.add(XMaterial.JUKEBOX);
}
/**
* Check if this block may not be copied
*
* @param mat The material to check for
* @return true = not copy this block
*/
public static boolean isAntiCopy(Material mat) {
XMaterial xmat = XMaterial.matchXMaterial(mat);
return antiCopy.contains(xmat);

View file

@ -12,12 +12,20 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
/**
* The DBManager manages the database
*/
public class DBManager {
private static final Gson gson = new Gson();
private static SQLiteDB data;
private static Connection con;
/**
* Construct the database manager
*
* @param name The name of the sqlite database file
*/
public DBManager(String name) {
data = new SQLiteDB(name);
@ -32,6 +40,11 @@ public class DBManager {
}
}
/**
* Load the database from data
*
* @throws SQLException If the SQL SELECT fails
*/
public void load() throws SQLException {
String query = "SELECT * FROM lifts";
PreparedStatement statement = con.prepareStatement(query);
@ -56,15 +69,20 @@ public class DBManager {
}
}
public void removeFromData(String name) {
if (!DataManager.containsLift(name)) {
Bukkit.getLogger().info("[V10Lift] Removing lift " + name + " to data...");
/**
* Remove a lift from data
*
* @param liftName The name of the lift
*/
public void remove(String liftName) {
if (!DataManager.containsLift(liftName)) {
Bukkit.getLogger().info("[V10Lift] Removing lift " + liftName + " to data...");
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
try {
String query = "DELETE FROM lifts WHERE liftName = ?";
PreparedStatement statement = con.prepareStatement(query);
statement.setString(1, name);
statement.setString(1, liftName);
statement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
@ -73,66 +91,74 @@ public class DBManager {
}
}
/**
* Save all lifts to data
* This is done async
*/
public void save() {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
byte[] blob = gson.toJson(entry.getValue()).getBytes();
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
save(false);
}
/**
* Save all lifts to data
* @param force true if sync, false if async
*/
public void save(boolean force) {
if (!force) {
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
try {
String query = "INSERT INTO lifts (liftName, liftData) VALUES (?, ?)";
PreparedStatement statement = con.prepareStatement(query);
statement.setString(1, entry.getKey());
statement.setBytes(2, blob);
statement.executeUpdate();
} catch (SQLException ignored) {
}
});
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
try {
String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?";
PreparedStatement statement2 = con.prepareStatement(query2);
statement2.setBytes(1, blob);
statement2.setString(2, entry.getKey());
statement2.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
saveLift(entry.getKey(), entry.getValue());
}
});
} else {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
saveLift(entry.getKey(), entry.getValue());
}
}
}
public void saveLift(String name, Lift lift) {
/**
* Save a lift to data
*
* @param liftName The name of the lift
* @param lift The lift itself
*/
public void saveLift(String liftName, Lift lift) {
Bukkit.getLogger().info("[V10Lift] Saving lift " + liftName + " to data...");
byte[] blob = gson.toJson(lift).getBytes();
Bukkit.getLogger().info("[V10Lift] Saving lift " + name + " to data...");
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
try {
String query = "INSERT INTO lifts (liftName, liftData) VALUES (?, ?)";
PreparedStatement statement = con.prepareStatement(query);
statement.setString(1, name);
statement.setBytes(2, blob);
statement.executeUpdate();
} catch (SQLException ignored) {
}
});
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
try {
String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?";
PreparedStatement statement2 = con.prepareStatement(query2);
statement2.setBytes(1, blob);
statement2.setString(2, name);
statement2.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
});
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> updateLift(liftName, blob));
}
/**
* Update a lift in data
*
* @param liftName The name of the lift
* @param liftData The JSON blob of the lift object
*/
private void updateLift(String liftName, byte[] liftData) {
try {
String query = "INSERT INTO lifts (liftName, liftData) VALUES (?, ?)";
PreparedStatement statement = con.prepareStatement(query);
statement.setString(1, liftName);
statement.setBytes(2, liftData);
statement.executeUpdate();
} catch (SQLException ignored) {}
try {
String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?";
PreparedStatement statement2 = con.prepareStatement(query2);
statement2.setBytes(1, liftData);
statement2.setString(2, liftName);
statement2.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Close the connection with the database
*/
public void closeConnection() {
data.closeSource();
}

View file

@ -5,6 +5,9 @@ import org.bukkit.Material;
import java.util.HashSet;
/**
* This class contains a set with all the blocks who may not be placed in a lift
*/
public class ForbiddenBlockManager {
private static final HashSet<XMaterial> forbidden = new HashSet<>();
@ -41,6 +44,12 @@ public class ForbiddenBlockManager {
forbidden.add(XMaterial.STICKY_PISTON);
}
/**
* Check if this block may not be placed in a lift
*
* @param mat The material to check for
* @return true = not place this block
*/
public static boolean isForbidden(Material mat) {
XMaterial xmat = XMaterial.matchXMaterial(mat);
return forbidden.contains(xmat);

View file

@ -13,6 +13,11 @@ import java.util.List;
public class VaultManager {
private static Permission perms = null;
/**
* Setup the Vault permission API
*
* @return true if success, false if Vault not found
*/
public static boolean setupPermissions() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
@ -22,17 +27,35 @@ public class VaultManager {
return true;
}
/**
* Get all the groups in the server
*
* @return A list with all the names of all the groups in the server
*/
public static List<String> getGroups() {
return Arrays.asList(perms.getGroups());
}
/**
* Check if a group exists
*
* @param groupName The name of the group
* @return true if exists
*/
public static boolean isGroup(String groupName) {
return Arrays.asList(perms.getGroups()).contains(groupName);
}
public static boolean userHasAnyGroup(Player player, HashSet<String> whitelistSet) {
/**
* Check if a user is in any of the groups provided
*
* @param player The player to check for
* @param groups The groups to check for
* @return true if in a group
*/
public static boolean inAnyGroup(Player player, HashSet<String> groups) {
boolean found = false;
for (String group : whitelistSet) {
for (String group : groups) {
found = Arrays.asList(perms.getPlayerGroups(player)).contains(group);
}
return found;

View file

@ -64,9 +64,9 @@ public class SQLiteDB {
/**
* Get the connection, to execute queries
*
* CREATE TABLE -> execute()
* SELECT -> executeQuery()
* UPDATE -> executeUpdate()
* CREATE TABLE - execute()
* SELECT - executeQuery()
* UPDATE - executeUpdate()
*
* @return Connection
*/

View file

@ -0,0 +1,4 @@
/**
* The package with all the SBDevelopment utils
*/
package nl.SBDeveloper.V10Lift.sbutils;

View file

@ -52,7 +52,7 @@ public class ConfigUtil {
*
* @param p The commandsender to send it to
* @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) {
if (V10LiftPlugin.getMessages().getFile().get(path) == null) {

View file

@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
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)
* @return true if opened, false if not opened
*/
@ -51,7 +51,7 @@ 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)
* @return true if opened, false if not opened
*/