3
0
Fork 0

Some small fixes

This commit is contained in:
BuildTools 2020-01-28 19:16:19 +01:00
parent 41784cb4e8
commit ceafeebede
8 changed files with 47 additions and 63 deletions

View file

@ -11,7 +11,7 @@
<groupId>me.paradoxpixel</groupId> <groupId>me.paradoxpixel</groupId>
<artifactId>themepark</artifactId> <artifactId>themepark</artifactId>
<version>1.3</version> <version>1.3.1</version>
<repositories> <repositories>
<repository> <repository>

View file

@ -26,16 +26,22 @@ public class LocationUtils {
} }
public static Location toLocation(String string) { public static Location toLocation(String string) {
if(string == null) if(string == null || string.isEmpty()) {
System.out.println("LocationUtils: Incorrect String passed");
return null; return null;
}
String[] args = string.split(":"); String[] args = string.split(":");
if(args.length < 4) if(args.length < 4) {
System.out.println("LocationUtils: Not enough arguments");
return null; return null;
}
World world = Bukkit.getWorld(args[0]); World world = Bukkit.getWorld(args[0]);
if(world == null) if(world == null) {
System.out.println("LocationUtils: No world with name: "+args[0]);
return null; return null;
}
double x = Double.parseDouble(args[1]); double x = Double.parseDouble(args[1]);
double y = Double.parseDouble(args[2]); double y = Double.parseDouble(args[2]);

View file

@ -21,6 +21,8 @@ public enum Status {
return CLOSED; return CLOSED;
case "MAINTENANCE": case "MAINTENANCE":
return MAINTENANCE; return MAINTENANCE;
case "MALFUNCTION":
return MALFUNCTION;
case "ACTIVE": case "ACTIVE":
return ACTIVE; return ACTIVE;
case "INACTIVE": case "INACTIVE":

View file

@ -18,13 +18,18 @@ public class SignManager {
private static HashMap<Attraction, ArrayList<StatusSign>> signs = new HashMap<>(); private static HashMap<Attraction, ArrayList<StatusSign>> signs = new HashMap<>();
public static void loadSigns(Attraction attraction) { public static void loadSigns(Attraction attraction) {
if(attraction == null) if(attraction == null) {
System.out.println("SignManager: No attraction passed");
return; return;
}
if(!config.getConfig().contains("signs." + attraction.getId())) if(!config.getConfig().contains("signs." + attraction.getId())) {
System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId());
return; return;
}
if(!config.getConfig().isList("signs." + attraction.getId())) { if(!config.getConfig().isList("signs." + attraction.getId())) {
System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId());
config.getConfig().set("signs." + attraction.getId(), null); config.getConfig().set("signs." + attraction.getId(), null);
config.save(); config.save();
return; return;
@ -34,11 +39,15 @@ public class SignManager {
List<String> locations = config.getConfig().getStringList("signs." + attraction.getId()); List<String> locations = config.getConfig().getStringList("signs." + attraction.getId());
for(String string : locations) { for(String string : locations) {
Location location = LocationUtils.toLocation(string); Location location = LocationUtils.toLocation(string);
if(location == null) if(location == null) {
System.out.println("SignManager: Incorrect sign Location");
continue; continue;
}
if(!(location.getBlock().getState() instanceof Sign)) if(!(location.getBlock().getState() instanceof Sign)) {
return; System.out.println("SignManager: Block is not a sign at: "+string);
continue;
}
array.add(new StatusSign(attraction, location)); array.add(new StatusSign(attraction, location));
} }

View file

@ -19,19 +19,20 @@ public class Database {
} }
enabled = config.getConfig().getBoolean("mysql.enabled"); enabled = config.getConfig().getBoolean("mysql.enabled");
host = config.getConfig().getString("mysql.host"); String host = config.getConfig().getString("mysql.host");
port = config.getConfig().getInt("mysql.port"); int port = config.getConfig().getInt("mysql.port");
database = config.getConfig().getString("mysql.database"); String database = config.getConfig().getString("mysql.database");
user = config.getConfig().getString("mysql.user"); user = config.getConfig().getString("mysql.user");
password = config.getConfig().getString("mysql.password"); password = config.getConfig().getString("mysql.password");
url = config.getConfig().getString("mysql.url");
url = url.replace("%host%", host);
url = url.replace("%port%", Integer.toString(port));
url = url.replace("%database%", database);
} }
private boolean enabled; private boolean enabled;
private String host; private String user, password, url;
private int port;
private String database;
private String user;
private String password;
private Connection connection; private Connection connection;
private int TaskID; private int TaskID;
@ -43,7 +44,7 @@ public class Database {
public void connect() { public void connect() {
try { try {
Class.forName("com.mysql.jdbc.Driver").newInstance(); Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=false", user, password); connection = DriverManager.getConnection(url, user, password);
startPool(); startPool();
} catch(Exception e) { } catch(Exception e) {

View file

@ -36,12 +36,7 @@ public class ChangeListener implements Listener {
message = message.replace("{status}", StatusManager.getName(status)); message = message.replace("{status}", StatusManager.getName(status));
Bukkit.broadcastMessage(Utils.color(message)); Bukkit.broadcastMessage(Utils.color(message));
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction()));
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction());
}
});
} }
@EventHandler @EventHandler
@ -51,13 +46,7 @@ public class ChangeListener implements Listener {
AttractionMenu.reload(); AttractionMenu.reload();
SignManager.loadSigns(e.getAttraction()); SignManager.loadSigns(e.getAttraction());
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction()));
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction());
}
});
} }
@EventHandler @EventHandler
@ -67,17 +56,11 @@ public class ChangeListener implements Listener {
AttractionMenu.reload(); AttractionMenu.reload();
SignManager.remove(e.getAttraction()); SignManager.remove(e.getAttraction());
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
config.getConfig().set("attraction." + e.getAttraction().getId(), null); config.getConfig().set("attraction." + e.getAttraction().getId(), null);
config.save(); config.save();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction()));
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction());
}
});
} }
@EventHandler @EventHandler
@ -86,13 +69,7 @@ public class ChangeListener implements Listener {
return; return;
AttractionMenu.reload(); AttractionMenu.reload();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion()));
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion());
}
});
} }
@EventHandler @EventHandler
@ -101,13 +78,7 @@ public class ChangeListener implements Listener {
return; return;
AttractionMenu.reload(); AttractionMenu.reload();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion()));
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion());
}
});
} }
@EventHandler @EventHandler
@ -116,17 +87,11 @@ public class ChangeListener implements Listener {
return; return;
AttractionMenu.reload(); AttractionMenu.reload();
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
config.getConfig().set("region." + e.getRegion().getId(), null); config.getConfig().set("region." + e.getRegion().getId(), null);
config.save(); config.save();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion()));
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion());
}
});
} }

View file

@ -1,5 +1,5 @@
name: ThemePark name: ThemePark
version: 1.3 version: 1.3.1
main: me.paradoxpixel.themepark.ThemeParkPlugin main: me.paradoxpixel.themepark.ThemeParkPlugin
author: ParadoxPixel author: ParadoxPixel
softdepend: [PlaceholderAPI] softdepend: [PlaceholderAPI]

View file

@ -22,6 +22,7 @@ mysql:
database: 'database' database: 'database'
user: 'username' user: 'username'
password: 'password' password: 'password'
url: 'jdbc:mysql://%host%:%port%/%database%?useSSL=false'
CONSTRUCTION: CONSTRUCTION:
name: "&7Under Construction" name: "&7Under Construction"