diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index 67791cb..4428c69 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -3,7 +3,7 @@
4.0.0
nl.iobyte
themepark
- 3.0.0
+ 3.0.2
@@ -40,6 +40,10 @@
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
placeholderapi
https://repo.extendedclip.com/content/repositories/placeholderapi/
@@ -52,6 +56,10 @@
MG-Dev Jenkins CI Maven Repository
https://ci.mg-dev.eu/plugin/repository/everything
+
+ sk89q-repo
+ https://maven.enginehub.org/repo/
+
@@ -146,6 +154,62 @@
+
+ com.sk89q.worldguard
+ worldguard-legacy
+ 6.2
+ provided
+
+
+ com.sk89q.worldedit
+ worldedit-bukkit
+ 6.1.5
+ provided
+
+
+ com.sk89q.worldedit
+ worldedit-core
+ 6.1.4-SNAPSHOT
+ provided
+
+
+ truezip
+ de.schlichtherle
+
+
+ js
+ rhino
+
+
+ jsr305
+ com.google.code.findbugs
+
+
+ paranamer
+ com.thoughtworks.paranamer
+
+
+ jlibnoise
+ com.sk89q.lib
+
+
+ jchronic
+ com.sk89q
+
+
+ guava
+ com.google.guava
+
+
+ snakeyaml
+ org.yaml
+
+
+ gson
+ com.google.code.gson
+
+
+
11
diff --git a/pom.xml b/pom.xml
index 4646c09..5b5c949 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,9 +12,13 @@
nl.iobyte
themepark
- 3.0.0
+ 3.0.2
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
placeholderapi
https://repo.extendedclip.com/content/repositories/placeholderapi/
@@ -27,6 +31,10 @@
MG-Dev Jenkins CI Maven Repository
https://ci.mg-dev.eu/plugin/repository/everything
+
+ sk89q-repo
+ https://maven.enginehub.org/repo/
+
@@ -39,7 +47,7 @@
nl.iobyte
commandapi
- 1.1
+ 1.2
nl.iobyte
@@ -84,6 +92,24 @@
XSeries
8.1.0
+
+ com.sk89q.worldguard
+ worldguard-legacy
+ 6.2
+ provided
+
+
+ com.sk89q.worldedit
+ worldedit-bukkit
+ 6.1.5
+ provided
+
+
+ com.sk89q.worldedit
+ worldedit-core
+ 6.1.4-SNAPSHOT
+ provided
+
diff --git a/src/main/java/nl/iobyte/themepark/api/ThemeParkAPI.java b/src/main/java/nl/iobyte/themepark/api/ThemeParkAPI.java
index b62b802..d7b257f 100644
--- a/src/main/java/nl/iobyte/themepark/api/ThemeParkAPI.java
+++ b/src/main/java/nl/iobyte/themepark/api/ThemeParkAPI.java
@@ -9,12 +9,15 @@ import nl.iobyte.themepark.api.load.DataLoadService;
import nl.iobyte.themepark.api.menu.MenuService;
import nl.iobyte.themepark.api.ridecount.RideCountService;
import nl.iobyte.themepark.api.sign.SignManager;
+import nl.iobyte.themepark.api.sync.SyncService;
+import nl.iobyte.themepark.api.sync.enums.SyncType;
public class ThemeParkAPI {
//Data
private ConfigurationManager configurationManager;
private final DataLoadService dataLoadService = new DataLoadService();
+ private final SyncService syncService = new SyncService();
private final DatabaseService databaseService = new DatabaseService();
private final MenuService menuService = new MenuService();
private EventDispatcher eventDispatcher;
@@ -34,6 +37,7 @@ public class ThemeParkAPI {
//Load data
eventDispatcher = new EventDispatcher(ThemePark.getInstance());
dataLoadService.init();
+ syncService.init();
}
/**
@@ -41,6 +45,7 @@ public class ThemeParkAPI {
*/
public void disable() {
databaseService.stop();
+ syncService.callSync(SyncType.HALT);
}
/**
diff --git a/src/main/java/nl/iobyte/themepark/api/config/enums/StorageKey.java b/src/main/java/nl/iobyte/themepark/api/config/enums/StorageKey.java
index 5244307..15ff545 100644
--- a/src/main/java/nl/iobyte/themepark/api/config/enums/StorageKey.java
+++ b/src/main/java/nl/iobyte/themepark/api/config/enums/StorageKey.java
@@ -12,6 +12,7 @@ public enum StorageKey {
MYSQL_PASSWORD(StorageLocation.SETTINGS, "mysql.password"),
//Menu Settings
+ MENU_ENABLED_MAIN(StorageLocation.MENU, "main.menu.enabled"),
MENU_SIZE_MAIN(StorageLocation.MENU, "menu.main.size"),
MENU_TITLE_MAIN(StorageLocation.MENU, "menu.main.title"),
MENU_TITLE_STATUS(StorageLocation.MENU, "menu.status.title"),
diff --git a/src/main/java/nl/iobyte/themepark/api/config/objects/ConfigurationUpdater.java b/src/main/java/nl/iobyte/themepark/api/config/objects/ConfigurationUpdater.java
index 048cd5e..de1fe8e 100644
--- a/src/main/java/nl/iobyte/themepark/api/config/objects/ConfigurationUpdater.java
+++ b/src/main/java/nl/iobyte/themepark/api/config/objects/ConfigurationUpdater.java
@@ -18,7 +18,7 @@ public class ConfigurationUpdater {
public String getCurrentVersion() {
if(!config.contains("version"))
- return "1.0";
+ return "0.0";
return config.getString("version");
}
diff --git a/src/main/java/nl/iobyte/themepark/api/event/attraction/AttractionPreStatusChangeEvent.java b/src/main/java/nl/iobyte/themepark/api/event/attraction/AttractionPreStatusChangeEvent.java
new file mode 100644
index 0000000..ab86e18
--- /dev/null
+++ b/src/main/java/nl/iobyte/themepark/api/event/attraction/AttractionPreStatusChangeEvent.java
@@ -0,0 +1,24 @@
+package nl.iobyte.themepark.api.event.attraction;
+
+import nl.iobyte.themepark.api.attraction.enums.Status;
+import nl.iobyte.themepark.api.attraction.objects.Attraction;
+import nl.iobyte.themepark.api.event.objects.AttractionEvent;
+import org.bukkit.event.Cancellable;
+
+public class AttractionPreStatusChangeEvent extends AttractionEvent implements Cancellable {
+
+ private boolean b;
+
+ public AttractionPreStatusChangeEvent(Attraction attraction, Status old, Status current) {
+ super(attraction, old, current);
+ }
+
+ public boolean isCancelled() {
+ return b;
+ }
+
+ public void setCancelled(boolean b) {
+ this.b = b;
+ }
+
+}
diff --git a/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java b/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java
index be46f13..95cfc4c 100644
--- a/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java
+++ b/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java
@@ -120,7 +120,13 @@ public class StatusDataLoader implements IDataLoader {
for(String id : section.getKeys(false)) {
String name = config.getString("attractions."+id+".name");
String cover = config.getString("attractions."+id+".cover");
+ if(cover == null || cover.isEmpty())
+ cover = "https://via.placeholder.com/500x500";
+
Status status = Status.get(config.getString("attractions."+id+".status"));
+ if(status == null)
+ status = Status.CLOSED;
+
Location location = LocationUtil.fromString(config.getString("attractions."+id+".location"));
Attraction attraction = new Attraction(id, region.getID(), name, cover, status, location);
diff --git a/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java b/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java
index 1e4c72f..58fb289 100644
--- a/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java
+++ b/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java
@@ -13,6 +13,7 @@ import nl.iobyte.themepark.api.attraction.objects.Region;
import nl.iobyte.themepark.api.config.enums.StorageKey;
import nl.iobyte.themepark.api.menu.objects.actions.PageAction;
import nl.iobyte.themepark.api.menu.objects.actions.TPAction;
+import nl.iobyte.themepark.api.message.MessageKey;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -206,7 +207,7 @@ public class StatusMenu {
if(page_size > 1) {
ItemBuilder builder = new ItemBuilder(Material.MINECART);
- builder.setName("&6Page: &f" + (i + 1));
+ builder.setName(MessageKey.MENU_PAGE.getMessage().replaceAll("%PAGE%", Integer.toString(i + 1)));
page.setItem(size - 5, new MenuItem(builder.getItem(), true));
}
}
@@ -243,7 +244,7 @@ public class StatusMenu {
* @return MenuItem
*/
private MenuItem getNext(int page) {
- return getPage("&6&LNext \u23F5", page + 1);
+ return getPage(MessageKey.MENU_NEXT.getMessage(), page + 1);
}
/**
@@ -252,7 +253,7 @@ public class StatusMenu {
* @return MenuItem
*/
private MenuItem getPrevious(int page) {
- return getPage("&6&L\u23F4 Previous", page - 1);
+ return getPage(MessageKey.MENU_PREVIOUS.getMessage(), page - 1);
}
/**
diff --git a/src/main/java/nl/iobyte/themepark/api/menu/objects/actions/TPAction.java b/src/main/java/nl/iobyte/themepark/api/menu/objects/actions/TPAction.java
index c0befb8..b1f535e 100644
--- a/src/main/java/nl/iobyte/themepark/api/menu/objects/actions/TPAction.java
+++ b/src/main/java/nl/iobyte/themepark/api/menu/objects/actions/TPAction.java
@@ -14,7 +14,7 @@ public class TPAction extends MenuAction {
}
public void execute(Player player) {
- Bukkit.dispatchCommand(player, "pp attraction warp "+attraction.getID());
+ Bukkit.dispatchCommand(player, "themepark attraction warp "+attraction.getID());
}
}
diff --git a/src/main/java/nl/iobyte/themepark/api/message/MessageKey.java b/src/main/java/nl/iobyte/themepark/api/message/MessageKey.java
index 731b275..22267d7 100644
--- a/src/main/java/nl/iobyte/themepark/api/message/MessageKey.java
+++ b/src/main/java/nl/iobyte/themepark/api/message/MessageKey.java
@@ -9,16 +9,10 @@ public enum MessageKey {
//Prefix
PREFIX("prefix"),
- //Session
- CLIENT_UNABLE_TO_CONNECT("client.connect.unable"),
- CLIENT_GENERATE_TO_CONNECT("client.connect.generate"),
- CLIENT_CLICK_TO_CONNECT("client.connect.click"),
- CLIENT_HOVER_TO_CONNECT("client.connect.hover"),
-
- //Connection
- CLIENT_CONNECTION_EXISTS("client.connection.exists"),
- CLIENT_CONNECTION_OPEN("client.connection.open"),
- CLIENT_CONNECTION_CLOSED("client.connection.closed"),
+ //Menu
+ MENU_PREVIOUS("menu.previous"),
+ MENU_PAGE("menu.page"),
+ MENU_NEXT("menu.next"),
//Ridecount
RIDECOUNT_ADD("ridecount.add"),
diff --git a/src/main/java/nl/iobyte/themepark/api/sync/SyncService.java b/src/main/java/nl/iobyte/themepark/api/sync/SyncService.java
new file mode 100644
index 0000000..5536a57
--- /dev/null
+++ b/src/main/java/nl/iobyte/themepark/api/sync/SyncService.java
@@ -0,0 +1,72 @@
+package nl.iobyte.themepark.api.sync;
+
+import nl.iobyte.themepark.ThemePark;
+import nl.iobyte.themepark.api.sync.enums.SyncType;
+import nl.iobyte.themepark.api.sync.interfaces.ISync;
+import nl.iobyte.themepark.api.sync.objects.ConfigurationSync;
+import nl.iobyte.themepark.api.sync.objects.SignSync;
+import org.bukkit.Bukkit;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class SyncService {
+
+ private int TaskID = -1;
+ private final Map> synchronisations = new HashMap<>();
+
+ public SyncService() {
+ addSynchronisation(new ConfigurationSync(), SyncType.POLL, SyncType.HALT);
+ addSynchronisation(new SignSync(), SyncType.POLL, SyncType.HALT);
+ }
+
+ /**
+ * Start Synchronisation Service
+ */
+ public void init() {
+ if(TaskID != -1)
+ return;
+
+ //Boot
+ callSync(SyncType.BOOT);
+
+ //Register listeners for state changes
+ long delay = 15 * 60 * 20; //Set to every 15 minutes
+ TaskID = Bukkit.getScheduler().runTaskTimerAsynchronously(ThemePark.getInstance(), () -> callSync(SyncType.POLL), delay, delay).getTaskId();
+ }
+
+ /**
+ * Add ISync to Synchronisation Service
+ * @param sync ISync
+ * @param types SyncType[]
+ */
+ public void addSynchronisation(ISync sync, SyncType... types) {
+ if(sync == null || types == null || types.length == 0)
+ return;
+
+ for(SyncType type : types)
+ if(type != null)
+ Objects.requireNonNull(synchronisations.computeIfAbsent(
+ type,
+ syncType -> new ArrayList<>()
+ )).add(sync);
+ }
+
+ public ArrayList getOfType(SyncType type) {
+ if(type == null)
+ return null;
+
+ return synchronisations.getOrDefault(type, new ArrayList<>());
+ }
+
+ public void callSync(SyncType type) {
+ if(type == null)
+ return;
+
+ for(ISync sync : getOfType(type))
+ sync.sync();
+ }
+
+}
+
diff --git a/src/main/java/nl/iobyte/themepark/api/sync/enums/SyncType.java b/src/main/java/nl/iobyte/themepark/api/sync/enums/SyncType.java
new file mode 100644
index 0000000..d52501e
--- /dev/null
+++ b/src/main/java/nl/iobyte/themepark/api/sync/enums/SyncType.java
@@ -0,0 +1,9 @@
+package nl.iobyte.themepark.api.sync.enums;
+
+public enum SyncType {
+
+ BOOT,
+ POLL,
+ HALT
+
+}
diff --git a/src/main/java/nl/iobyte/themepark/api/sync/interfaces/ISync.java b/src/main/java/nl/iobyte/themepark/api/sync/interfaces/ISync.java
new file mode 100644
index 0000000..0150288
--- /dev/null
+++ b/src/main/java/nl/iobyte/themepark/api/sync/interfaces/ISync.java
@@ -0,0 +1,10 @@
+package nl.iobyte.themepark.api.sync.interfaces;
+
+public interface ISync {
+
+ /**
+ * Called when synchronising
+ */
+ void sync();
+
+}
\ No newline at end of file
diff --git a/src/main/java/nl/iobyte/themepark/api/sync/objects/ConfigurationSync.java b/src/main/java/nl/iobyte/themepark/api/sync/objects/ConfigurationSync.java
new file mode 100644
index 0000000..c49dfc6
--- /dev/null
+++ b/src/main/java/nl/iobyte/themepark/api/sync/objects/ConfigurationSync.java
@@ -0,0 +1,27 @@
+package nl.iobyte.themepark.api.sync.objects;
+
+import nl.iobyte.themepark.ThemePark;
+import nl.iobyte.themepark.api.ThemeParkAPI;
+import nl.iobyte.themepark.api.attraction.objects.Region;
+import nl.iobyte.themepark.api.config.enums.StorageLocation;
+import nl.iobyte.themepark.api.sync.interfaces.ISync;
+import nl.iobyte.themepark.logger.ThemeParkLogger;
+
+public class ConfigurationSync implements ISync {
+
+ /**
+ * Save all configuration files
+ */
+ public void sync() {
+ ThemeParkAPI api = ThemePark.getInstance().getAPI();
+ for(StorageLocation location : StorageLocation.values())
+ if(location != StorageLocation.SETTINGS)
+ api.getConfigurationManager().save(location);
+
+ for(Region region : api.getAttractionService().getRegions().values())
+ region.getConfiguration().save();
+
+ ThemeParkLogger.toConsole("Configuration data saved to file");
+ }
+
+}
diff --git a/src/main/java/nl/iobyte/themepark/api/sync/objects/SignSync.java b/src/main/java/nl/iobyte/themepark/api/sync/objects/SignSync.java
new file mode 100644
index 0000000..8a02661
--- /dev/null
+++ b/src/main/java/nl/iobyte/themepark/api/sync/objects/SignSync.java
@@ -0,0 +1,43 @@
+package nl.iobyte.themepark.api.sync.objects;
+
+import nl.iobyte.themepark.ThemePark;
+import nl.iobyte.themepark.api.ThemeParkAPI;
+import nl.iobyte.themepark.api.attraction.objects.Attraction;
+import nl.iobyte.themepark.api.config.ConfigurationManager;
+import nl.iobyte.themepark.api.config.enums.StorageLocation;
+import nl.iobyte.themepark.api.sign.SignManager;
+import nl.iobyte.themepark.api.sign.objects.StatusSign;
+import nl.iobyte.themepark.api.sync.interfaces.ISync;
+import nl.iobyte.themepark.logger.ThemeParkLogger;
+import nl.iobyte.themepark.utils.LocationUtil;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class SignSync implements ISync {
+
+ /**
+ * Save all configuration files
+ */
+ public void sync() {
+ ThemeParkAPI api = ThemePark.getInstance().getAPI();
+ SignManager manager = api.getSignManager();
+ ConfigurationManager config = api.getConfigurationManager();
+
+ for(Map.Entry> entry : manager.getSigns().entrySet()) {
+ List array = new ArrayList<>();
+ for(StatusSign sign : entry.getValue()) {
+ String str = LocationUtil.toString(sign.getLocation());
+ if(!str.isEmpty())
+ array.add(str);
+ }
+
+ config.set(StorageLocation.SIGN_DATA, "signs." + entry.getKey().getID(), array);
+ }
+
+ config.save(StorageLocation.SIGN_DATA);
+ ThemeParkLogger.toConsole("Sign data saved to file");
+ }
+
+}
+
diff --git a/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java b/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java
index 482385b..c794a79 100644
--- a/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java
+++ b/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java
@@ -1,8 +1,11 @@
package nl.iobyte.themepark.commands;
import nl.iobyte.commandapi.CommandFactory;
+import nl.iobyte.commandapi.interfaces.ICommandExecutor;
import nl.iobyte.commandapi.middlewares.PermissionMiddleware;
import nl.iobyte.themepark.ThemePark;
+import nl.iobyte.themepark.commands.executors.ConsoleExecutor;
+import nl.iobyte.themepark.commands.executors.PlayerExecutor;
import nl.iobyte.themepark.commands.subcommands.HelpCommand;
import nl.iobyte.themepark.commands.subcommands.ItemCommand;
import nl.iobyte.themepark.commands.subcommands.MenuCommand;
@@ -10,6 +13,10 @@ import nl.iobyte.themepark.commands.subcommands.attraction.AttractionCommands;
import nl.iobyte.themepark.commands.subcommands.region.RegionCommands;
import nl.iobyte.themepark.commands.subcommands.ridecount.RideCountCommands;
import nl.iobyte.themepark.commands.subcommands.status.StatusCommands;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
public class ThemeParkCommand {
@@ -38,7 +45,14 @@ public class ThemeParkCommand {
factory.addMiddleware(new PermissionMiddleware());
//Register command
- factory.registerCommand(ThemePark.getInstance());
+ ThemePark.getInstance().getCommand(factory.getName()).setExecutor((sender, command, s, args) -> {
+ ICommandExecutor executor = new ConsoleExecutor(sender);
+ if(sender instanceof Player)
+ executor = new PlayerExecutor((Player) sender);
+
+ factory.onCommand(executor, args);
+ return true;
+ });
}
}
diff --git a/src/main/java/nl/iobyte/themepark/commands/arguments/AttractionArgument.java b/src/main/java/nl/iobyte/themepark/commands/arguments/AttractionArgument.java
index fb5cfb5..efd3091 100644
--- a/src/main/java/nl/iobyte/themepark/commands/arguments/AttractionArgument.java
+++ b/src/main/java/nl/iobyte/themepark/commands/arguments/AttractionArgument.java
@@ -5,7 +5,7 @@ import nl.iobyte.commandapi.objects.ArgumentCheck;
import nl.iobyte.themepark.ThemePark;
import nl.iobyte.themepark.api.attraction.objects.Attraction;
import org.bukkit.ChatColor;
-import org.bukkit.command.CommandSender;
+import nl.iobyte.commandapi.interfaces.ICommandExecutor;
import java.util.List;
public class AttractionArgument implements ICommandArgument {
@@ -20,23 +20,23 @@ public class AttractionArgument implements ICommandArgument {
/**
* Check if argument is valid Attraction
- * @param sender CommandSender
+ * @param sender ICommandExecutor
* @param args Arguments passed by Command
* @param previousArguments Previous arguments
* @return Boolean
*/
- public ArgumentCheck checkArgument(CommandSender sender, String[] args, List