♻️ Refactor of the folders and fixed shutdown task register
This commit is contained in:
parent
d6149955b3
commit
ca0d2dcd6d
41 changed files with 213 additions and 115 deletions
25
pom.xml
25
pom.xml
|
@ -85,6 +85,7 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Compile JAR -->
|
<!-- Compile JAR -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
@ -94,11 +95,17 @@
|
||||||
<compilerArgument>-parameters</compilerArgument>
|
<compilerArgument>-parameters</compilerArgument>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Delombok the source for the javadoc -->
|
<!-- Delombok the source for the javadoc -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok-maven-plugin</artifactId>
|
<artifactId>lombok-maven-plugin</artifactId>
|
||||||
<version>1.18.20.0</version>
|
<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>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>generate-sources</phase>
|
<phase>generate-sources</phase>
|
||||||
|
@ -108,17 +115,26 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Build the javadoc -->
|
<!-- Build the javadoc -->
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sourceFileIncludes>
|
<sourcepath>${project.build.directory}/delombok</sourcepath>
|
||||||
<include>nl/SBDeveloper/V10Lift/api/*.java</include>
|
|
||||||
<include>nl/SBDeveloper/V10Lift/api/objects/*.java</include>
|
<!-- Exclude all non-API packages -->
|
||||||
</sourceFileIncludes>
|
<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>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- SKIP the maven deploy -->
|
<!-- SKIP the maven deploy -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
@ -127,6 +143,7 @@
|
||||||
<skip>true</skip>
|
<skip>true</skip>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Deploy to nexus -->
|
<!-- Deploy to nexus -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class V10LiftPlugin extends JavaPlugin {
|
||||||
private static YamlFile config;
|
private static YamlFile config;
|
||||||
private static DBManager dbManager;
|
private static DBManager dbManager;
|
||||||
private static YamlFile messages;
|
private static YamlFile messages;
|
||||||
private static V10LiftAPI api;
|
|
||||||
private static boolean vault = false;
|
private static boolean vault = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,9 +59,6 @@ public class V10LiftPlugin extends JavaPlugin {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load the API
|
|
||||||
api = new V10LiftAPI();
|
|
||||||
|
|
||||||
//Load vault if found
|
//Load vault if found
|
||||||
if (VaultManager.setupPermissions()) {
|
if (VaultManager.setupPermissions()) {
|
||||||
Bukkit.getLogger().info("[V10Lift] Loading Vault hook for group whitelist support.");
|
Bukkit.getLogger().info("[V10Lift] Loading Vault hook for group whitelist support.");
|
||||||
|
@ -128,7 +124,7 @@ public class V10LiftPlugin extends JavaPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
dbManager.save();
|
dbManager.save(true);
|
||||||
dbManager.closeConnection();
|
dbManager.closeConnection();
|
||||||
|
|
||||||
instance = null;
|
instance = null;
|
||||||
|
@ -150,10 +146,6 @@ public class V10LiftPlugin extends JavaPlugin {
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static V10LiftAPI getAPI() {
|
|
||||||
return api;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isVaultEnabled() {
|
public static boolean isVaultEnabled() {
|
||||||
return vault;
|
return vault;
|
||||||
}
|
}
|
|
@ -25,6 +25,15 @@ 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 V10LiftAPI() {}
|
||||||
|
|
||||||
|
public static V10LiftAPI getInstance() {
|
||||||
|
if (instance == null) instance = new V10LiftAPI();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
/* Private API methods */
|
/* Private API methods */
|
||||||
private void sortFloors(@Nonnull Lift lift) {
|
private void sortFloors(@Nonnull Lift lift) {
|
||||||
ArrayList<Map.Entry<String, Floor>> as = new ArrayList<>(lift.getFloors().entrySet());
|
ArrayList<Map.Entry<String, Floor>> as = new ArrayList<>(lift.getFloors().entrySet());
|
||||||
|
@ -101,7 +110,7 @@ public class V10LiftAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
DataManager.removeLift(liftName);
|
DataManager.removeLift(liftName);
|
||||||
V10LiftPlugin.getDBManager().removeFromData(liftName);
|
V10LiftPlugin.getDBManager().remove(liftName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* All the enums used for V10Lift
|
||||||
|
*/
|
||||||
|
package nl.SBDeveloper.V10Lift.api.enums;
|
|
@ -1,6 +1,7 @@
|
||||||
package nl.SBDeveloper.V10Lift.api.runnables;
|
package nl.SBDeveloper.V10Lift.api.runnables;
|
||||||
|
|
||||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
|
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
|
||||||
import nl.SBDeveloper.V10Lift.managers.DataManager;
|
import nl.SBDeveloper.V10Lift.managers.DataManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ public class DoorCloser implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (V10LiftPlugin.getAPI().closeDoor(liftName)) stop();
|
if (V10LiftAPI.getInstance().closeDoor(liftName)) stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
|
@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.api.runnables;
|
||||||
import com.cryptomorin.xseries.XMaterial;
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import com.cryptomorin.xseries.XSound;
|
import com.cryptomorin.xseries.XSound;
|
||||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
|
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
|
||||||
import nl.SBDeveloper.V10Lift.api.enums.LiftDirection;
|
import nl.SBDeveloper.V10Lift.api.enums.LiftDirection;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.*;
|
import nl.SBDeveloper.V10Lift.api.objects.*;
|
||||||
import nl.SBDeveloper.V10Lift.managers.AntiCopyBlockManager;
|
import nl.SBDeveloper.V10Lift.managers.AntiCopyBlockManager;
|
||||||
|
@ -119,7 +120,7 @@ public class MoveLift implements Runnable {
|
||||||
if (changeOfDefect > 0.0D) {
|
if (changeOfDefect > 0.0D) {
|
||||||
double chance = ThreadLocalRandom.current().nextDouble(100);
|
double chance = ThreadLocalRandom.current().nextDouble(100);
|
||||||
if (chance < changeOfDefect) {
|
if (chance < changeOfDefect) {
|
||||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
V10LiftAPI.getInstance().setDefective(liftName, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +142,7 @@ public class MoveLift implements Runnable {
|
||||||
List<LiftBlock> antiCopyBlocks = new ArrayList<>();
|
List<LiftBlock> antiCopyBlocks = new ArrayList<>();
|
||||||
|
|
||||||
if (direction == LiftDirection.UP || direction == LiftDirection.DOWN) {
|
if (direction == LiftDirection.UP || direction == LiftDirection.DOWN) {
|
||||||
if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return;
|
if (!V10LiftAPI.getInstance().closeDoor(liftName)) return;
|
||||||
|
|
||||||
if (direction == LiftDirection.UP) {
|
if (direction == LiftDirection.UP) {
|
||||||
//MOVE ROPES
|
//MOVE ROPES
|
||||||
|
@ -149,7 +150,7 @@ public class MoveLift implements Runnable {
|
||||||
if (rope.getCurrently() > rope.getMaxY()) {
|
if (rope.getCurrently() > rope.getMaxY()) {
|
||||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
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();
|
lift.getToMove().clear();
|
||||||
queueIterator.remove();
|
queueIterator.remove();
|
||||||
return;
|
return;
|
||||||
|
@ -328,7 +329,7 @@ public class MoveLift implements Runnable {
|
||||||
if (rope.getCurrently() < rope.getMinY()) {
|
if (rope.getCurrently() < rope.getMinY()) {
|
||||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
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();
|
lift.getToMove().clear();
|
||||||
queueIterator.remove();
|
queueIterator.remove();
|
||||||
|
|
||||||
|
@ -420,7 +421,7 @@ public class MoveLift implements Runnable {
|
||||||
ls.setState((byte) 0);
|
ls.setState((byte) 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
V10LiftPlugin.getAPI().openDoor(lift, liftName, floorTo);
|
V10LiftAPI.getInstance().openDoor(lift, liftName, floorTo);
|
||||||
|
|
||||||
if (lift.isRealistic()) lift.setCounter(ft);
|
if (lift.isRealistic()) lift.setCounter(ft);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.commands;
|
||||||
|
|
||||||
import com.cryptomorin.xseries.XMaterial;
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
|
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.Floor;
|
import nl.SBDeveloper.V10Lift.api.objects.Floor;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.Lift;
|
import nl.SBDeveloper.V10Lift.api.objects.Lift;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
|
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
|
||||||
|
@ -261,7 +262,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
V10LiftAPI.getInstance().setDefective(liftName, true);
|
||||||
ConfigUtil.sendMessage(sender, "Disable.Disabled");
|
ConfigUtil.sendMessage(sender, "Disable.Disabled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -271,7 +272,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
if (args.length == 1 && sender instanceof Player) {
|
if (args.length == 1 && sender instanceof Player) {
|
||||||
//v10lift stop -> Get liftName from loc and floorName from sign
|
//v10lift stop -> Get liftName from loc and floorName from sign
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
liftName = V10LiftPlugin.getAPI().getLiftByLocation(p.getLocation());
|
liftName = V10LiftAPI.getInstance().getLiftByLocation(p.getLocation());
|
||||||
} else if (args.length == 1) {
|
} else if (args.length == 1) {
|
||||||
ConfigUtil.sendMessage(sender, "Stop.NonPlayer");
|
ConfigUtil.sendMessage(sender, "Stop.NonPlayer");
|
||||||
return true;
|
return true;
|
||||||
|
@ -303,7 +304,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
if (args.length == 1 && sender instanceof Player) {
|
if (args.length == 1 && sender instanceof Player) {
|
||||||
//v10lift start -> Get liftName from loc and floorName from sign
|
//v10lift start -> Get liftName from loc and floorName from sign
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
liftName = V10LiftPlugin.getAPI().getLiftByLocation(p.getLocation());
|
liftName = V10LiftAPI.getInstance().getLiftByLocation(p.getLocation());
|
||||||
} else if (args.length == 1) {
|
} else if (args.length == 1) {
|
||||||
ConfigUtil.sendMessage(sender, "Start.NonPlayer");
|
ConfigUtil.sendMessage(sender, "Start.NonPlayer");
|
||||||
return true;
|
return true;
|
||||||
|
@ -341,7 +342,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
Floor f = lift.getFloors().get(floorName);
|
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));
|
ConfigUtil.sendMessage(sender, "Start.Started", Collections.singletonMap("%Name%", liftName));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -354,13 +355,13 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
e.getValue().setQueue(null);
|
e.getValue().setQueue(null);
|
||||||
V10LiftPlugin.getAPI().sortLiftBlocks(lift);
|
V10LiftAPI.getInstance().sortLiftBlocks(lift);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataManager.clearMovingTasks();
|
DataManager.clearMovingTasks();
|
||||||
V10LiftPlugin.getSConfig().reloadConfig();
|
V10LiftPlugin.getSConfig().reloadConfig();
|
||||||
try {
|
try {
|
||||||
V10LiftPlugin.getDBManager().save();
|
V10LiftPlugin.getDBManager().save(true);
|
||||||
V10LiftPlugin.getDBManager().load();
|
V10LiftPlugin.getDBManager().load();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -406,7 +407,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
|
|
||||||
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||||
DataManager.removeBuilderPlayer(p.getUniqueId());
|
DataManager.removeBuilderPlayer(p.getUniqueId());
|
||||||
V10LiftPlugin.getAPI().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
|
V10LiftAPI.getInstance().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
|
||||||
abort = true;
|
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");
|
ConfigUtil.sendMessage(sender, "Repair.Repaired");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -557,7 +558,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
if (!DataManager.containsLift(liftName)) {
|
if (!DataManager.containsLift(liftName)) {
|
||||||
ConfigUtil.sendMessage(sender, "Whois.DoesntExists");
|
ConfigUtil.sendMessage(sender, "Whois.DoesntExists");
|
||||||
} else {
|
} else {
|
||||||
V10LiftPlugin.getAPI().sendLiftInfo(sender, liftName);
|
V10LiftAPI.getInstance().sendLiftInfo(sender, liftName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -731,7 +732,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
|
|
||||||
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||||
DataManager.removeBuilderPlayer(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");
|
ConfigUtil.sendMessage(sender, "Build.Disabled");
|
||||||
} else {
|
} else {
|
||||||
DataManager.addBuilderPlayer(p.getUniqueId());
|
DataManager.addBuilderPlayer(p.getUniqueId());
|
||||||
|
@ -754,7 +755,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.dispatchCommand(sender, "v10lift edit");
|
Bukkit.dispatchCommand(sender, "v10lift edit");
|
||||||
V10LiftPlugin.getAPI().renameLift(liftName, args[1]);
|
V10LiftAPI.getInstance().renameLift(liftName, args[1]);
|
||||||
Bukkit.dispatchCommand(sender, "v10lift edit " + args[1]);
|
Bukkit.dispatchCommand(sender, "v10lift edit " + args[1]);
|
||||||
|
|
||||||
ConfigUtil.sendMessage(sender, "Rename.Renamed");
|
ConfigUtil.sendMessage(sender, "Rename.Renamed");
|
||||||
|
@ -877,7 +878,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
if (args[1].equalsIgnoreCase("add")) {
|
if (args[1].equalsIgnoreCase("add")) {
|
||||||
Block b = p.getLocation().getBlock();
|
Block b = p.getLocation().getBlock();
|
||||||
String floorName = args[2];
|
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) {
|
switch (response) {
|
||||||
case 0:
|
case 0:
|
||||||
ConfigUtil.sendMessage(sender, "Floor.Added");
|
ConfigUtil.sendMessage(sender, "Floor.Added");
|
||||||
|
@ -894,7 +895,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
} else if (args[1].equalsIgnoreCase("del")) {
|
} else if (args[1].equalsIgnoreCase("del")) {
|
||||||
String floorName = args[2];
|
String floorName = args[2];
|
||||||
if (!V10LiftPlugin.getAPI().removeFloor(liftName, floorName)) {
|
if (!V10LiftAPI.getInstance().removeFloor(liftName, floorName)) {
|
||||||
ConfigUtil.sendMessage(sender, "General.InternalError");
|
ConfigUtil.sendMessage(sender, "General.InternalError");
|
||||||
} else {
|
} else {
|
||||||
ConfigUtil.sendMessage(sender, "Floor.Removed");
|
ConfigUtil.sendMessage(sender, "Floor.Removed");
|
||||||
|
@ -907,7 +908,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
|
|
||||||
String floorName = args[2];
|
String floorName = args[2];
|
||||||
String newFloorName = args[3];
|
String newFloorName = args[3];
|
||||||
int response = V10LiftPlugin.getAPI().renameFloor(liftName, floorName, newFloorName);
|
int response = V10LiftAPI.getInstance().renameFloor(liftName, floorName, newFloorName);
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case 0:
|
case 0:
|
||||||
ConfigUtil.sendMessage(sender, "Floor.Renamed");
|
ConfigUtil.sendMessage(sender, "Floor.Renamed");
|
||||||
|
@ -948,7 +949,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
DataManager.removeOfflineRemovesPlayer(p.getUniqueId());
|
DataManager.removeOfflineRemovesPlayer(p.getUniqueId());
|
||||||
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||||
DataManager.removeBuilderPlayer(p.getUniqueId());
|
DataManager.removeBuilderPlayer(p.getUniqueId());
|
||||||
V10LiftPlugin.getAPI().sortLiftBlocks(liftName);
|
V10LiftAPI.getInstance().sortLiftBlocks(liftName);
|
||||||
}
|
}
|
||||||
DataManager.removeRopeEditPlayer(p.getUniqueId());
|
DataManager.removeRopeEditPlayer(p.getUniqueId());
|
||||||
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
||||||
|
@ -1048,7 +1049,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!V10LiftPlugin.getAPI().removeLift(args[1])) {
|
if (!V10LiftAPI.getInstance().removeLift(args[1])) {
|
||||||
ConfigUtil.sendMessage(sender, "Delete.NotRemoved", Collections.singletonMap("%Name%", args[1]));
|
ConfigUtil.sendMessage(sender, "Delete.NotRemoved", Collections.singletonMap("%Name%", args[1]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1072,15 +1073,15 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!V10LiftPlugin.getAPI().createLift(p, args[1])) {
|
if (!V10LiftAPI.getInstance().createLift(p, args[1])) {
|
||||||
ConfigUtil.sendMessage(sender, "General.AlreadyExists");
|
ConfigUtil.sendMessage(sender, "General.AlreadyExists");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeSet<LiftBlock> blcks = DataManager.getLift(args[1]).getBlocks();
|
TreeSet<LiftBlock> blcks = DataManager.getLift(args[1]).getBlocks();
|
||||||
|
|
||||||
blocks.forEach(block -> V10LiftPlugin.getAPI().addBlockToLift(blcks, block));
|
blocks.forEach(block -> V10LiftAPI.getInstance().addBlockToLift(blcks, block));
|
||||||
V10LiftPlugin.getAPI().sortLiftBlocks(args[1]);
|
V10LiftAPI.getInstance().sortLiftBlocks(args[1]);
|
||||||
DataManager.removePlayer(p.getUniqueId());
|
DataManager.removePlayer(p.getUniqueId());
|
||||||
ConfigUtil.sendMessage(p, "Create.Created", Collections.singletonMap("%Name%", args[1]));
|
ConfigUtil.sendMessage(p, "Create.Created", Collections.singletonMap("%Name%", args[1]));
|
||||||
p.performCommand("v10lift edit " + args[1]);
|
p.performCommand("v10lift edit " + args[1]);
|
|
@ -1,5 +1,6 @@
|
||||||
package nl.SBDeveloper.V10Lift.listeners;
|
package nl.SBDeveloper.V10Lift.listeners;
|
||||||
|
|
||||||
|
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.Floor;
|
import nl.SBDeveloper.V10Lift.api.objects.Floor;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.Lift;
|
import nl.SBDeveloper.V10Lift.api.objects.Lift;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
|
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
|
||||||
|
@ -22,7 +23,7 @@ public class BlockBreakListener implements Listener {
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onBlockBreak(BlockBreakEvent e) {
|
public void onBlockBreak(BlockBreakEvent e) {
|
||||||
Block b = e.getBlock();
|
Block b = e.getBlock();
|
||||||
if (V10LiftPlugin.getAPI().isRope(b)) {
|
if (V10LiftAPI.getInstance().isRope(b)) {
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "General.RemoveRopeFirst");
|
ConfigUtil.sendMessage(e.getPlayer(), "General.RemoveRopeFirst");
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
|
@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.listeners;
|
||||||
|
|
||||||
import com.cryptomorin.xseries.XMaterial;
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
|
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.Floor;
|
import nl.SBDeveloper.V10Lift.api.objects.Floor;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.Lift;
|
import nl.SBDeveloper.V10Lift.api.objects.Lift;
|
||||||
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
|
import nl.SBDeveloper.V10Lift.api.objects.LiftBlock;
|
||||||
|
@ -52,7 +53,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
for (LiftBlock lb : lift.getOfflineInputs()) {
|
for (LiftBlock lb : lift.getOfflineInputs()) {
|
||||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
||||||
lb.setActive(!lb.isActive());
|
lb.setActive(!lb.isActive());
|
||||||
V10LiftPlugin.getAPI().setOffline(entry.getKey(), lb.isActive());
|
V10LiftAPI.getInstance().setOffline(entry.getKey(), lb.isActive());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +62,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
|
|
||||||
for (LiftBlock lb : lift.getInputs()) {
|
for (LiftBlock lb : lift.getInputs()) {
|
||||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
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);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -121,13 +122,13 @@ public class PlayerInteractListener implements Listener {
|
||||||
return;
|
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");
|
ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission");
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
V10LiftPlugin.getAPI().addToQueue(liftName, lift.getFloors().get(f), f);
|
V10LiftAPI.getInstance().addToQueue(liftName, lift.getFloors().get(f), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//BLOCK ADD
|
//BLOCK ADD
|
||||||
|
@ -140,7 +141,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
if (DataManager.containsPlayer(p.getUniqueId())) {
|
if (DataManager.containsPlayer(p.getUniqueId())) {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
e.setCancelled(true);
|
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) {
|
switch (res) {
|
||||||
case 0:
|
case 0:
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded");
|
ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded");
|
||||||
|
@ -210,7 +211,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
} else if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
} else if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
e.setCancelled(true);
|
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) {
|
switch (res) {
|
||||||
case 0:
|
case 0:
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded");
|
ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded");
|
||||||
|
@ -241,7 +242,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.OnlyUp");
|
ConfigUtil.sendMessage(e.getPlayer(), "Rope.OnlyUp");
|
||||||
return;
|
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) {
|
switch (res) {
|
||||||
case 0:
|
case 0:
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.Created");
|
ConfigUtil.sendMessage(e.getPlayer(), "Rope.Created");
|
||||||
|
@ -266,11 +267,11 @@ public class PlayerInteractListener implements Listener {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
Block block = e.getClickedBlock();
|
Block block = e.getClickedBlock();
|
||||||
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
||||||
if (!V10LiftPlugin.getAPI().containsRope(liftName, block)) {
|
if (!V10LiftAPI.getInstance().containsRope(liftName, block)) {
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.NotARope");
|
ConfigUtil.sendMessage(e.getPlayer(), "Rope.NotARope");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
V10LiftPlugin.getAPI().removeRope(liftName, block);
|
V10LiftAPI.getInstance().removeRope(liftName, block);
|
||||||
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.Removed");
|
ConfigUtil.sendMessage(e.getPlayer(), "Rope.Removed");
|
||||||
} else if (DataManager.containsDoorEditPlayer(p.getUniqueId())) {
|
} else if (DataManager.containsDoorEditPlayer(p.getUniqueId())) {
|
||||||
|
@ -314,7 +315,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
Lift lift = entry.getValue();
|
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)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,7 +361,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
}
|
}
|
||||||
p.getInventory().remove(new ItemStack(masterItem, masterAmount));
|
p.getInventory().remove(new ItemStack(masterItem, masterAmount));
|
||||||
}
|
}
|
||||||
V10LiftPlugin.getAPI().setDefective(liftName, false);
|
V10LiftAPI.getInstance().setDefective(liftName, false);
|
||||||
}
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -391,7 +392,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
sign.setLine(3, ChatColor.GREEN + f2);
|
sign.setLine(3, ChatColor.GREEN + f2);
|
||||||
} else if (!floor.getUserWhitelist().isEmpty() && !floor.getUserWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
|
} else if (!floor.getUserWhitelist().isEmpty() && !floor.getUserWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
|
||||||
sign.setLine(3, ChatColor.RED + f2);
|
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);
|
sign.setLine(3, ChatColor.RED + f2);
|
||||||
} else {
|
} else {
|
||||||
sign.setLine(3, ChatColor.YELLOW + f2);
|
sign.setLine(3, ChatColor.YELLOW + f2);
|
||||||
|
@ -410,13 +411,13 @@ public class PlayerInteractListener implements Listener {
|
||||||
return;
|
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");
|
ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission");
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
V10LiftPlugin.getAPI().addToQueue(liftName, lift.getFloors().get(f), f);
|
V10LiftAPI.getInstance().addToQueue(liftName, lift.getFloors().get(f), f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,9 @@ import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains a set with all the blocks who may not be copied
|
||||||
|
*/
|
||||||
public class AntiCopyBlockManager {
|
public class AntiCopyBlockManager {
|
||||||
private static final HashSet<XMaterial> antiCopy = new HashSet<>();
|
private static final HashSet<XMaterial> antiCopy = new HashSet<>();
|
||||||
|
|
||||||
|
@ -79,6 +82,12 @@ public class AntiCopyBlockManager {
|
||||||
antiCopy.add(XMaterial.JUKEBOX);
|
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) {
|
public static boolean isAntiCopy(Material mat) {
|
||||||
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
||||||
return antiCopy.contains(xmat);
|
return antiCopy.contains(xmat);
|
|
@ -12,12 +12,20 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DBManager manages the database
|
||||||
|
*/
|
||||||
public class DBManager {
|
public class DBManager {
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
private static SQLiteDB data;
|
private static SQLiteDB data;
|
||||||
private static Connection con;
|
private static Connection con;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the database manager
|
||||||
|
*
|
||||||
|
* @param name The name of the sqlite database file
|
||||||
|
*/
|
||||||
public DBManager(String name) {
|
public DBManager(String name) {
|
||||||
data = new SQLiteDB(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 {
|
public void load() throws SQLException {
|
||||||
String query = "SELECT * FROM lifts";
|
String query = "SELECT * FROM lifts";
|
||||||
PreparedStatement statement = con.prepareStatement(query);
|
PreparedStatement statement = con.prepareStatement(query);
|
||||||
|
@ -56,15 +69,20 @@ public class DBManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromData(String name) {
|
/**
|
||||||
if (!DataManager.containsLift(name)) {
|
* Remove a lift from data
|
||||||
Bukkit.getLogger().info("[V10Lift] Removing lift " + name + " to 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(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
String query = "DELETE FROM lifts WHERE liftName = ?";
|
String query = "DELETE FROM lifts WHERE liftName = ?";
|
||||||
PreparedStatement statement = con.prepareStatement(query);
|
PreparedStatement statement = con.prepareStatement(query);
|
||||||
statement.setString(1, name);
|
statement.setString(1, liftName);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -73,66 +91,74 @@ public class DBManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save all lifts to data
|
||||||
|
* This is done async
|
||||||
|
*/
|
||||||
public void save() {
|
public void save() {
|
||||||
|
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(), () -> {
|
||||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
saveLift(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
|
|
||||||
|
|
||||||
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) {
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
try {
|
saveLift(entry.getKey(), entry.getValue());
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
byte[] blob = gson.toJson(lift).getBytes();
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> updateLift(liftName, blob));
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getLogger().info("[V10Lift] Saving lift " + name + " to data...");
|
/**
|
||||||
|
* Update a lift in data
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param liftData The JSON blob of the lift object
|
||||||
|
*/
|
||||||
|
private void updateLift(String liftName, byte[] liftData) {
|
||||||
try {
|
try {
|
||||||
String query = "INSERT INTO lifts (liftName, liftData) VALUES (?, ?)";
|
String query = "INSERT INTO lifts (liftName, liftData) VALUES (?, ?)";
|
||||||
PreparedStatement statement = con.prepareStatement(query);
|
PreparedStatement statement = con.prepareStatement(query);
|
||||||
statement.setString(1, name);
|
statement.setString(1, liftName);
|
||||||
statement.setBytes(2, blob);
|
statement.setBytes(2, liftData);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
} catch (SQLException ignored) {
|
} catch (SQLException ignored) {}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
|
|
||||||
try {
|
try {
|
||||||
String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?";
|
String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?";
|
||||||
PreparedStatement statement2 = con.prepareStatement(query2);
|
PreparedStatement statement2 = con.prepareStatement(query2);
|
||||||
statement2.setBytes(1, blob);
|
statement2.setBytes(1, liftData);
|
||||||
statement2.setString(2, name);
|
statement2.setString(2, liftName);
|
||||||
statement2.executeUpdate();
|
statement2.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the connection with the database
|
||||||
|
*/
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
data.closeSource();
|
data.closeSource();
|
||||||
}
|
}
|
|
@ -5,6 +5,9 @@ import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains a set with all the blocks who may not be placed in a lift
|
||||||
|
*/
|
||||||
public class ForbiddenBlockManager {
|
public class ForbiddenBlockManager {
|
||||||
private static final HashSet<XMaterial> forbidden = new HashSet<>();
|
private static final HashSet<XMaterial> forbidden = new HashSet<>();
|
||||||
|
|
||||||
|
@ -41,6 +44,12 @@ public class ForbiddenBlockManager {
|
||||||
forbidden.add(XMaterial.STICKY_PISTON);
|
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) {
|
public static boolean isForbidden(Material mat) {
|
||||||
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
||||||
return forbidden.contains(xmat);
|
return forbidden.contains(xmat);
|
|
@ -13,6 +13,11 @@ import java.util.List;
|
||||||
public class VaultManager {
|
public class VaultManager {
|
||||||
private static Permission perms = null;
|
private static Permission perms = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the Vault permission API
|
||||||
|
*
|
||||||
|
* @return true if success, false if Vault not found
|
||||||
|
*/
|
||||||
public static boolean setupPermissions() {
|
public static boolean setupPermissions() {
|
||||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -22,17 +27,35 @@ public class VaultManager {
|
||||||
return true;
|
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() {
|
public static List<String> getGroups() {
|
||||||
return Arrays.asList(perms.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) {
|
public static boolean isGroup(String groupName) {
|
||||||
return Arrays.asList(perms.getGroups()).contains(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;
|
boolean found = false;
|
||||||
for (String group : whitelistSet) {
|
for (String group : groups) {
|
||||||
found = Arrays.asList(perms.getPlayerGroups(player)).contains(group);
|
found = Arrays.asList(perms.getPlayerGroups(player)).contains(group);
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
|
@ -64,9 +64,9 @@ public class SQLiteDB {
|
||||||
/**
|
/**
|
||||||
* Get the connection, to execute queries
|
* Get the connection, to execute queries
|
||||||
*
|
*
|
||||||
* CREATE TABLE -> execute()
|
* CREATE TABLE - execute()
|
||||||
* SELECT -> executeQuery()
|
* SELECT - executeQuery()
|
||||||
* UPDATE -> executeUpdate()
|
* UPDATE - executeUpdate()
|
||||||
*
|
*
|
||||||
* @return Connection
|
* @return Connection
|
||||||
*/
|
*/
|
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* The package with all the SBDevelopment utils
|
||||||
|
*/
|
||||||
|
package nl.SBDeveloper.V10Lift.sbutils;
|
|
@ -52,7 +52,7 @@ public class ConfigUtil {
|
||||||
*
|
*
|
||||||
* @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) {
|
||||||
if (V10LiftPlugin.getMessages().getFile().get(path) == null) {
|
if (V10LiftPlugin.getMessages().getFile().get(path) == null) {
|
|
@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
|
||||||
public class DoorUtil {
|
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
|
||||||
*/
|
*/
|
||||||
|
@ -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)
|
* @param b The block (door)
|
||||||
* @return true if opened, false if not opened
|
* @return true if opened, false if not opened
|
||||||
*/
|
*/
|
Loading…
Reference in a new issue