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 previousArguments) { + public ArgumentCheck checkArgument(ICommandExecutor sender, String[] args, List previousArguments) { return new ArgumentCheck(ThemePark.getInstance().getAPI().getAttractionService().hasAttraction(args[0]), 1); } /** * Get Attraction passed by command - * @param sender CommandSender + * @param sender ICommandExecutor * @param args Arguments passed by Command * @param previousArguments Previous arguments * @return Attraction */ - public Attraction getArgument(CommandSender sender, String[] args, List previousArguments) { + public Attraction getArgument(ICommandExecutor sender, String[] args, List previousArguments) { return ThemePark.getInstance().getAPI().getAttractionService().getAttraction(args[0]); } diff --git a/src/main/java/nl/iobyte/themepark/commands/arguments/MaterialArgument.java b/src/main/java/nl/iobyte/themepark/commands/arguments/MaterialArgument.java new file mode 100644 index 0000000..a64f626 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/arguments/MaterialArgument.java @@ -0,0 +1,24 @@ +package nl.iobyte.themepark.commands.arguments; + +import com.cryptomorin.xseries.XMaterial; +import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.ArgumentCheck; +import org.bukkit.ChatColor; +import java.util.List; + +public class MaterialArgument implements ICommandArgument { + + public String getMessage(String[] args) { + return "No material with name: "+ ChatColor.WHITE+args[0]; + } + + public ArgumentCheck checkArgument(ICommandExecutor iCommandExecutor, String[] args, List list) { + return new ArgumentCheck(XMaterial.matchXMaterial(args[0]).isPresent(), 1); + } + + public XMaterial getArgument(ICommandExecutor iCommandExecutor, String[] args, List list) { + return XMaterial.matchXMaterial(args[0]).orElse(XMaterial.RED_CONCRETE); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/arguments/NoAttractionArgument.java b/src/main/java/nl/iobyte/themepark/commands/arguments/NoAttractionArgument.java index 2581837..85daeda 100644 --- a/src/main/java/nl/iobyte/themepark/commands/arguments/NoAttractionArgument.java +++ b/src/main/java/nl/iobyte/themepark/commands/arguments/NoAttractionArgument.java @@ -4,7 +4,7 @@ import nl.iobyte.commandapi.interfaces.ICommandArgument; import nl.iobyte.commandapi.objects.ArgumentCheck; import nl.iobyte.themepark.ThemePark; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import java.util.List; public class NoAttractionArgument implements ICommandArgument { @@ -19,23 +19,23 @@ public class NoAttractionArgument implements ICommandArgument { /** * Check if argument is a not existing 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 previousArguments) { + public ArgumentCheck checkArgument(ICommandExecutor sender, String[] args, List previousArguments) { return new ArgumentCheck(!ThemePark.getInstance().getAPI().getAttractionService().hasAttraction(args[0]), 1); } /** * Get String passed by command - * @param sender CommandSender + * @param sender ICommandExecutor * @param args Arguments passed by Command * @param previousArguments Previous arguments * @return String */ - public String getArgument(CommandSender sender, String[] args, List previousArguments) { + public String getArgument(ICommandExecutor sender, String[] args, List previousArguments) { return args[0]; } diff --git a/src/main/java/nl/iobyte/themepark/commands/arguments/NoRegionArgument.java b/src/main/java/nl/iobyte/themepark/commands/arguments/NoRegionArgument.java index 55e13fc..069694f 100644 --- a/src/main/java/nl/iobyte/themepark/commands/arguments/NoRegionArgument.java +++ b/src/main/java/nl/iobyte/themepark/commands/arguments/NoRegionArgument.java @@ -4,7 +4,7 @@ import nl.iobyte.commandapi.interfaces.ICommandArgument; import nl.iobyte.commandapi.objects.ArgumentCheck; import nl.iobyte.themepark.ThemePark; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import java.util.List; public class NoRegionArgument implements ICommandArgument { @@ -19,23 +19,23 @@ public class NoRegionArgument implements ICommandArgument { /** * Check if argument is a not existing 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 previousArguments) { + public ArgumentCheck checkArgument(ICommandExecutor sender, String[] args, List previousArguments) { return new ArgumentCheck(!ThemePark.getInstance().getAPI().getAttractionService().hasRegion(args[0]), 1); } /** * Get String passed by command - * @param sender CommandSender + * @param sender ICommandExecutor * @param args Arguments passed by Command * @param previousArguments Previous arguments * @return String */ - public String getArgument(CommandSender sender, String[] args, List previousArguments) { + public String getArgument(ICommandExecutor sender, String[] args, List previousArguments) { return args[0]; } diff --git a/src/main/java/nl/iobyte/themepark/commands/arguments/PlayerArgument.java b/src/main/java/nl/iobyte/themepark/commands/arguments/PlayerArgument.java new file mode 100644 index 0000000..8088939 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/arguments/PlayerArgument.java @@ -0,0 +1,25 @@ +package nl.iobyte.themepark.commands.arguments; + +import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.ArgumentCheck; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import java.util.List; + +public class PlayerArgument implements ICommandArgument { + + public String getMessage(String[] args) { + return "No player with name: "+ ChatColor.WHITE+args[0]; + } + + public ArgumentCheck checkArgument(ICommandExecutor sender, String[] args, List list) { + return new ArgumentCheck(Bukkit.getPlayer(args[0]) != null, 1); + } + + public Player getArgument(ICommandExecutor sender, String[] args, List list) { + return Bukkit.getPlayer(args[0]); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/arguments/PlayersArgument.java b/src/main/java/nl/iobyte/themepark/commands/arguments/PlayersArgument.java new file mode 100644 index 0000000..605b10e --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/arguments/PlayersArgument.java @@ -0,0 +1,44 @@ +package nl.iobyte.themepark.commands.arguments; + +import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.ArgumentCheck; +import nl.iobyte.themepark.commands.objects.SpigotPlayerSelector; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import java.util.List; + +public class PlayersArgument implements ICommandArgument> { + + /** + * Message to display when giving an error + * @return String + */ + public String getMessage(String[] args) { + return "No player(s) found for: "+ ChatColor.WHITE+args[0]; + } + + /** + * Check if argument is valid Player + * @param sender ICommandExecutor + * @param args Arguments passed by Command + * @param list Previous arguments + * @return Boolean + */ + public ArgumentCheck checkArgument(ICommandExecutor sender, String[] args, List list) { + List players = new SpigotPlayerSelector(args[0]).getPlayers(sender); + return new ArgumentCheck(players != null && !players.isEmpty(), 1); + } + + /** + * Get Player passed by command + * @param sender ICommandExecutor + * @param args Arguments passed by Command + * @param list Previous arguments + * @return Player + */ + public List getArgument(ICommandExecutor sender, String[] args, List list) { + return new SpigotPlayerSelector(args[0]).getPlayers(sender); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/arguments/RegionArgument.java b/src/main/java/nl/iobyte/themepark/commands/arguments/RegionArgument.java index 2bcb9ed..944b778 100644 --- a/src/main/java/nl/iobyte/themepark/commands/arguments/RegionArgument.java +++ b/src/main/java/nl/iobyte/themepark/commands/arguments/RegionArgument.java @@ -5,7 +5,7 @@ import nl.iobyte.commandapi.objects.ArgumentCheck; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Region; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import java.util.List; public class RegionArgument implements ICommandArgument { @@ -20,23 +20,23 @@ public class RegionArgument implements ICommandArgument { /** * Check if argument is valid Region - * @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 previousArguments) { + public ArgumentCheck checkArgument(ICommandExecutor sender, String[] args, List previousArguments) { return new ArgumentCheck(ThemePark.getInstance().getAPI().getAttractionService().hasRegion(args[0]), 1); } /** * Get Region passed by command - * @param sender CommandSender + * @param sender ICommandExecutor * @param args Arguments passed by Command * @param previousArguments Previous arguments * @return Region */ - public Region getArgument(CommandSender sender, String[] args, List previousArguments) { + public Region getArgument(ICommandExecutor sender, String[] args, List previousArguments) { return ThemePark.getInstance().getAPI().getAttractionService().getRegion(args[0]); } diff --git a/src/main/java/nl/iobyte/themepark/commands/executors/ConsoleExecutor.java b/src/main/java/nl/iobyte/themepark/commands/executors/ConsoleExecutor.java new file mode 100644 index 0000000..b000a7c --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/executors/ConsoleExecutor.java @@ -0,0 +1,30 @@ +package nl.iobyte.themepark.commands.executors; + +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import org.bukkit.command.CommandSender; + +public class ConsoleExecutor implements ICommandExecutor { + + private final CommandSender executor; + + public ConsoleExecutor(CommandSender executor) { + this.executor = executor; + } + + public boolean isPlayer() { + return false; + } + + public boolean hasPermission(String s) { + return true; + } + + public void sendMessage(String s) { + executor.sendMessage(s); + } + + public Object getOriginal() { + return executor; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/executors/PlayerExecutor.java b/src/main/java/nl/iobyte/themepark/commands/executors/PlayerExecutor.java new file mode 100644 index 0000000..8d07bbe --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/executors/PlayerExecutor.java @@ -0,0 +1,30 @@ +package nl.iobyte.themepark.commands.executors; + +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import org.bukkit.entity.Player; + +public class PlayerExecutor implements ICommandExecutor { + + private final Player player; + + public PlayerExecutor(Player player) { + this.player = player; + } + + public boolean isPlayer() { + return true; + } + + public boolean hasPermission(String s) { + return player.hasPermission(s); + } + + public void sendMessage(String s) { + player.sendMessage(s); + } + + public Object getOriginal() { + return player; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/objects/Reflection.java b/src/main/java/nl/iobyte/themepark/commands/objects/Reflection.java new file mode 100644 index 0000000..5330ad7 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/objects/Reflection.java @@ -0,0 +1,24 @@ +package nl.iobyte.themepark.commands.objects; + +import java.util.HashMap; + +public class Reflection { + + private static final HashMap> classes = new HashMap<>(); + + public static Class getClass(String path) { + if(classes.containsKey(path)) + return classes.get(path); + + try { + Class clazz = Class.forName(path); + classes.put(path, clazz); + return clazz; + } catch (ClassNotFoundException e) { + e.printStackTrace(); + classes.put(path, null); + return null; + } + } + +} \ No newline at end of file diff --git a/src/main/java/nl/iobyte/themepark/commands/objects/SpigotPlayerSelector.java b/src/main/java/nl/iobyte/themepark/commands/objects/SpigotPlayerSelector.java new file mode 100644 index 0000000..9b7d323 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/objects/SpigotPlayerSelector.java @@ -0,0 +1,150 @@ +package nl.iobyte.themepark.commands.objects; + +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Use selectors in commands! + * + * @author Mindgamesnl + * + * Code from + * https://github.com/Mindgamesnl/OpenAudioMc/blob/master/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/players/objects/SpigotPlayerSelector.java + */ +public class SpigotPlayerSelector { + + private final String selector; + + public SpigotPlayerSelector(String selector) { + this.selector = selector; + } + + /** + * this turns selectors like @a[r=5] into a usable list, since + * 1.13 spigot removed this feature, FOR SOME REASON.. thanks guys.. + * + * @param sender the sender + * @return players following the selector + */ + public List getPlayers(ICommandExecutor sender) { + List players = new ArrayList<>(); + + if (selector.startsWith("@p")) { + //get Location + Location standPoint = getLocation(sender); + + if (getArgument("r").length() != 0) { + int radius = Integer.parseInt(getArgument("r")); + Bukkit.getOnlinePlayers().stream() + .filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName())) + .min(Comparator.comparing(player -> player.getLocation().distance(standPoint))) + .filter(player -> radius > player.getLocation().distance(standPoint)) + .ifPresent(players::add); + } + + if (getArgument("distance").length() != 0) { + int distance = Integer.parseInt(getArgument("distance")); + Bukkit.getOnlinePlayers().stream() + .filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName())) + .min(Comparator.comparing(player -> player.getLocation().distance(standPoint))) + .filter(player -> distance > player.getLocation().distance(standPoint)) + .ifPresent(players::add); + } else { + Bukkit.getOnlinePlayers().stream() + .filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName())) + .min(Comparator.comparing(player -> player.getLocation().distance(standPoint))) + .ifPresent(players::add); + } + } else if (selector.startsWith("@a")) { + //everyone + Location standPoint = getLocation(sender); + + if(getArgument("region").length() != 0) { + WGManager manager = WGManager.getInstance(); + String targetRegion = getArgument("region"); + for (Player player : Bukkit.getOnlinePlayers()) { + manager.getApplicableRegionSet(player.getLocation(standPoint)).forEach(region -> { + if (region.getId().equalsIgnoreCase(targetRegion)) + players.add(player); + }); + } + } else if (getArgument("r").length() != 0) { + int radius = Integer.parseInt(getArgument("r")); + players.addAll(Bukkit.getOnlinePlayers().stream() + .filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName())) + .filter(player -> radius > player.getLocation().distance(standPoint)) + .collect(Collectors.toList())); + } else if (getArgument("distance").length() != 0) { + int distance = Integer.parseInt(getArgument("distance")); + players.addAll(Bukkit.getOnlinePlayers().stream() + .filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName())) + .filter(player -> distance > player.getLocation().distance(standPoint)) + .collect(Collectors.toList())); + } + + else { + players.addAll(Bukkit.getOnlinePlayers().stream() + .filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName())) + .collect(Collectors.toList())); + } + } else if (selector.length() <= 16) { + //player + Player player = Bukkit.getPlayer(selector); + if (player != null) + players.add(player); + } + + return players; + } + + /** + * attempt to parse the location + * + * @param commandSender the sender + * @return the location or null + */ + private Location getLocation(ICommandExecutor commandSender) { + Location initialLocation = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); + if (commandSender.isPlayer()) { + initialLocation = ((Player) commandSender.getOriginal()).getLocation(); + } else if (commandSender.getOriginal() instanceof BlockCommandSender) { + initialLocation = ((BlockCommandSender) commandSender.getOriginal()).getBlock().getLocation(); + } + + if (!getArgument("x").equals("") && !getArgument("y").equals("") && !getArgument("z").equals("")) { + try { + int x = Integer.parseInt(getArgument("x")); + int y = Integer.parseInt(getArgument("y")); + int z = Integer.parseInt(getArgument("z")); + return new Location(initialLocation.getWorld(), x, y, z); + } catch (Exception e) { + return initialLocation; + } + } + + return initialLocation; + } + + private String getArgument(String key) { + StringBuilder result = new StringBuilder(); + String[] arguments = selector.split(key + "="); + if (arguments.length == 1) return ""; + for (byte type : arguments[1].getBytes()) { + char element = (char) type; + if (element == ',' || element == ']') { + return result.toString(); + } else { + result.append(element); + } + } + return result.toString(); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/objects/WGManager.java b/src/main/java/nl/iobyte/themepark/commands/objects/WGManager.java new file mode 100644 index 0000000..a6f1718 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/objects/WGManager.java @@ -0,0 +1,98 @@ +package nl.iobyte.themepark.commands.objects; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.managers.RegionManager; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.plugin.Plugin; +import java.lang.reflect.Method; + +public class WGManager { + + private static String wgVerStr = null; + private static WGManager instance = null; + + public static WGManager getInstance() { + if (instance == null) { + instance = new WGManager(); + } + + return instance; + } + + public WorldGuardPlugin getWorldGuard() { + Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"); + if ((!(plugin instanceof WorldGuardPlugin))) + return null; + + return (WorldGuardPlugin) plugin; + } + + public RegionManager getRegionManager(World w) { + if (getWgVer().contains("7.")) { + try { + Class wgClass = Reflection.getClass("com.sk89q.worldguard.WorldGuard"); + if(wgClass == null) + return null; + + Object instance = wgClass.getDeclaredMethod("getInstance").invoke(null); + Class wgInstanceClass = instance.getClass(); + + Object platform = wgInstanceClass.getDeclaredMethod("getPlatform").invoke(instance); + Class wgPlatformClass = platform.getClass(); + + Object regionContainer = wgPlatformClass.getDeclaredMethod("getRegionContainer").invoke(platform); + Class wgRegionContainer = regionContainer.getClass(); + + return (RegionManager) wgRegionContainer.getSuperclass() + .getMethod("get", com.sk89q.worldedit.world.World.class) + .invoke(regionContainer, new BukkitWorld(w)); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + return getWorldGuard().getRegionManager(w); + } + + return null; + } + + public ApplicableRegionSet getApplicableRegionSet(Location loc) { + if (getWgVer().contains("7.")) { + try { + RegionManager mngr = getRegionManager(loc.getWorld()); + + Class blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3"); + if(blockVector3 == null) + return null; + + Method applicableRegions = mngr.getClass().getDeclaredMethod("getApplicableRegions", blockVector3); + + Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class); + Object blockVector = blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ()); + + Object regionSet = applicableRegions.invoke(mngr, blockVector); + + return (ApplicableRegionSet) regionSet; + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } else { + return getRegionManager(loc.getWorld()).getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ())); + } + } + + + public String getWgVer() { + if (wgVerStr == null) + wgVerStr = Bukkit.getPluginManager().getPlugin("WorldGuard").getDescription().getVersion(); + + return wgVerStr; + } + +} \ No newline at end of file diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/HelpCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/HelpCommand.java index 613ec89..58bcca7 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/HelpCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/HelpCommand.java @@ -2,10 +2,9 @@ package nl.iobyte.themepark.commands.subcommands; import nl.iobyte.commandapi.CommandFactory; import nl.iobyte.commandapi.arguments.number.IntegerArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.message.Text; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import java.util.List; public class HelpCommand extends SubCommand { @@ -21,12 +20,8 @@ public class HelpCommand extends SubCommand { .addArgument(new IntegerArgument()); } - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - //Send CommandSender list of commands it has access to - public void onConsoleCommand(CommandSender sender, List list, int i) { + //Send ICommandExecutor list of commands it has access to + public void onCommand(ICommandExecutor sender, List list, int i) { List commands = factory.getApplicableSubCommands(sender); if(commands.size() <= 5) { sendSinglePage(sender, commands); @@ -36,7 +31,7 @@ public class HelpCommand extends SubCommand { sendMultiPage(sender, commands, list, i); } - private void sendSinglePage(CommandSender sender, List commands) { + private void sendSinglePage(ICommandExecutor sender, List commands) { sender.sendMessage(Text.color("&f&l>==== &6&lThemePark &l&f====<")); for (SubCommand command : commands) sender.sendMessage(Text.color("&f" + command.getApplicableSyntaxList(sender).get(0).getUsage())); @@ -44,7 +39,7 @@ public class HelpCommand extends SubCommand { sender.sendMessage(Text.color("&f&l>==== &6&lThemePark &l&f====<")); } - private void sendMultiPage(CommandSender sender, List commands, List list, int i) { + private void sendMultiPage(ICommandExecutor sender, List commands, List list, int i) { int page = 1; int pages = (int) Math.ceil(((double) commands.size()) / 5); if(i == 1) diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/ItemCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/ItemCommand.java index e810206..beadda9 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/ItemCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ItemCommand.java @@ -1,13 +1,13 @@ package nl.iobyte.themepark.commands.subcommands; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.menuapi.item.ItemBuilder; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.config.ConfigurationManager; import nl.iobyte.themepark.api.config.enums.StorageKey; import nl.iobyte.themepark.api.message.Text; import org.bukkit.Material; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; @@ -20,7 +20,7 @@ public class ItemCommand extends SubCommand { .setAllowConsole(false); } - public void onPlayerCommand(Player player, List objects, int i) { + public void onCommand(ICommandExecutor sender, List objects, int i) { ConfigurationManager manager = ThemePark.getInstance().getAPI().getConfigurationManager(); Material material = Material.getMaterial(manager.getString(StorageKey.MENU_ITEM_MATERIAL)); @@ -32,12 +32,10 @@ public class ItemCommand extends SubCommand { ItemBuilder builder = new ItemBuilder(material, 1, data); builder.setName(name); + Player player = (Player) sender.getOriginal(); player.getInventory().addItem(builder.getItem()); player.updateInventory(); player.sendMessage(Text.color("&6&lThemeParkMC &f➢ Added item to your inventory")); } - //Give CommandSender overview of Plugin status - public void onConsoleCommand(CommandSender sender, List objects, int i) {} - } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/MenuCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/MenuCommand.java index baa2a02..290a937 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/MenuCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/MenuCommand.java @@ -1,35 +1,36 @@ package nl.iobyte.themepark.commands.subcommands; import nl.iobyte.commandapi.arguments.StringArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; +import nl.iobyte.themepark.api.config.enums.StorageKey; import nl.iobyte.themepark.api.menu.MenuService; import nl.iobyte.themepark.scheduler.ThemeParkScheduler; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.List; public class MenuCommand extends SubCommand { public MenuCommand() { - super(null, "menu"); - - addSyntax("/themepark menu"); + super(new String[]{"menu"}); addSyntax("/themepark menu") - .addArgument(new StringArgument("status")); + .setAllowConsole(false); + + addSyntax("/themepark menu") + .addArgument(new StringArgument("status")) + .setAllowConsole(false); } - public void onPlayerCommand(Player player, List objects, int i) { + public void onCommand(ICommandExecutor player, List objects, int i) { MenuService service = ThemePark.getInstance().getAPI().getMenuService(); - if(i == 0) { - ThemeParkScheduler.runSync(() -> service.getMainMenu().open(player)); + if(i == 0 && ThemePark.getInstance().getAPI().getConfigurationManager().getBoolean(StorageKey.MENU_ENABLED_MAIN)) { + ThemeParkScheduler.runSync(() -> service.getMainMenu().open((Player) player.getOriginal())); return; } - ThemeParkScheduler.runSync(() -> service.getStatusMenu().open(player)); + ThemeParkScheduler.runSync(() -> service.getStatusMenu().open((Player) player.getOriginal())); } - public void onConsoleCommand(CommandSender sender, List objects, int i) {} - } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java index 8accb30..bcbc02b 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java @@ -1,12 +1,11 @@ package nl.iobyte.themepark.commands.subcommands.attraction; import nl.iobyte.commandapi.arguments.StringArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import java.util.List; public class AttractionCoverCommand extends SubCommand { @@ -19,13 +18,7 @@ public class AttractionCoverCommand extends SubCommand { .addArgument(new StringArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); String url = (String) list.get(1); attraction.setCover(url); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCreateCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCreateCommand.java index 3568b54..b0f3414 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCreateCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCreateCommand.java @@ -3,7 +3,7 @@ package nl.iobyte.themepark.commands.subcommands.attraction; import nl.iobyte.commandapi.arguments.EnumArgument; import nl.iobyte.commandapi.arguments.MessageArgument; import nl.iobyte.commandapi.arguments.StringArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.attraction.objects.Attraction; @@ -12,7 +12,7 @@ import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.NoAttractionArgument; import nl.iobyte.themepark.commands.arguments.RegionArgument; import org.bukkit.Location; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; @@ -40,13 +40,7 @@ public class AttractionCreateCommand extends SubCommand { .addArgument(new StringArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { String id = (String) list.get(0); Region region = (Region) list.get(1); String name = (String) list.get(2); @@ -59,8 +53,8 @@ public class AttractionCreateCommand extends SubCommand { cover = (String) list.get('4'); Location location = null; - if(sender instanceof Player) - location = ((Player) sender).getLocation(); + if(sender.isPlayer()) + location = ((Player) sender.getOriginal()).getLocation(); ThemePark.getInstance().getAPI().getAttractionService().addAttraction(new Attraction( id, diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionListCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionListCommand.java index e0850ff..2436919 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionListCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionListCommand.java @@ -2,14 +2,13 @@ package nl.iobyte.themepark.commands.subcommands.attraction; import com.google.common.collect.Iterables; import nl.iobyte.commandapi.arguments.number.IntegerArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.RegionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.Collection; import java.util.List; @@ -31,13 +30,8 @@ public class AttractionListCommand extends SubCommand { .addArgument(new IntegerArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { int page = 1; String title = "&6&lThemePark"; Collection attractions; @@ -62,7 +56,7 @@ public class AttractionListCommand extends SubCommand { } } - private void sendSinglePage(CommandSender sender, String title, Collection attractions) { + private void sendSinglePage(ICommandExecutor sender, String title, Collection attractions) { sender.sendMessage(Text.color("&f&l>==== &r"+title+" &l&f====<")); if(attractions.isEmpty()) { sender.sendMessage(Text.color("&6No attractions found")); @@ -78,7 +72,7 @@ public class AttractionListCommand extends SubCommand { sender.sendMessage(Text.color("&f&l>==== &r"+title+" &l&f====<")); } - private void sendMultiPage(CommandSender sender, int page, String title, Collection attractions) { + private void sendMultiPage(ICommandExecutor sender, int page, String title, Collection attractions) { int pages = (int) Math.ceil(((double) attractions.size()) / 5); if(page < 1 || page > pages) { sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ Page &6"+page+" &fdoesn't exist")); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java index bfa6ca3..3a7e212 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java @@ -1,10 +1,10 @@ package nl.iobyte.themepark.commands.subcommands.attraction; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; @@ -18,14 +18,11 @@ public class AttractionLocationCommand extends SubCommand { .setAllowConsole(false); } - @Override - public void onPlayerCommand(Player player, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); + Player player = (Player) sender.getOriginal(); attraction.setLocation(player.getLocation()); player.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the location of attraction &f"+attraction.getID())); } - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) {} - } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java index 5e9e096..dbcf260 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java @@ -1,12 +1,11 @@ package nl.iobyte.themepark.commands.subcommands.attraction; import nl.iobyte.commandapi.arguments.MessageArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; public class AttractionNameCommand extends SubCommand { @@ -19,16 +18,11 @@ public class AttractionNameCommand extends SubCommand { .addArgument(new MessageArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); String name = (String) list.get(1); attraction.setName(name); sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the name of attraction &f"+attraction.getID())); } + } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java index 780fdfc..9d7201b 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java @@ -1,13 +1,12 @@ package nl.iobyte.themepark.commands.subcommands.attraction; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; import nl.iobyte.themepark.commands.arguments.RegionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; public class AttractionRegionCommand extends SubCommand { @@ -19,17 +18,12 @@ public class AttractionRegionCommand extends SubCommand { .addArgument(new AttractionArgument()) .addArgument(new RegionArgument()); } - - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); Region region = (Region) list.get(1); attraction.setRegionID(region.getID()); sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the region of attraction &f"+attraction.getID())); } + } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java index 5eda678..aa579a6 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java @@ -1,12 +1,11 @@ package nl.iobyte.themepark.commands.subcommands.attraction; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; public class AttractionRemoveCommand extends SubCommand { @@ -18,13 +17,7 @@ public class AttractionRemoveCommand extends SubCommand { .addArgument(new AttractionArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); ThemePark.getInstance().getAPI().getAttractionService().removeAttraction(attraction.getID()); sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully removed attraction &f"+attraction.getID())); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java index 51ba374..ec434c6 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java @@ -1,13 +1,14 @@ package nl.iobyte.themepark.commands.subcommands.attraction; import nl.iobyte.commandapi.arguments.EnumArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; +import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.attraction.objects.Attraction; +import nl.iobyte.themepark.api.event.attraction.AttractionPreStatusChangeEvent; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; public class AttractionStatusCommand extends SubCommand { @@ -20,16 +21,25 @@ public class AttractionStatusCommand extends SubCommand { .addArgument(new EnumArgument(Status.values())); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); Status status = (Status) list.get(1); - attraction.setStatus(status); - sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the status of attraction &f"+attraction.getID())); + + AttractionPreStatusChangeEvent event = new AttractionPreStatusChangeEvent( + attraction, + attraction.getStatus(), + status + ); + ThemePark.getInstance().getAPI().getEventDispatcher().call( + event, + () -> { + if(event.isCancelled()) + return; + + attraction.setStatus(status); + sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the status of attraction &f"+attraction.getID())); + } + ); } + } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionWarpCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionWarpCommand.java index fbd4af3..4ab074c 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionWarpCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionWarpCommand.java @@ -1,27 +1,27 @@ package nl.iobyte.themepark.commands.subcommands.attraction; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.message.MessageKey; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; import nl.iobyte.themepark.scheduler.ThemeParkScheduler; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; public class AttractionWarpCommand extends SubCommand { public AttractionWarpCommand() { - super("themepark.admin", "attraction", "warp"); + super(new String[]{"attraction", "warp"}); addSyntax("/themepark attraction warp ") .addArgument(new AttractionArgument()) .setAllowConsole(false); } - @Override - public void onPlayerCommand(Player player, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { + Player player = (Player) sender.getOriginal(); Attraction attraction = (Attraction) list.get(0); if(!attraction.getStatus().canTeleport()) { String message = MessageKey.ATTRACTION_TELEPORT_STATUS.getMessage(); @@ -44,7 +44,4 @@ public class AttractionWarpCommand extends SubCommand { }); } - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) {} - } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java index d726b1e..3a637ad 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java @@ -1,13 +1,13 @@ package nl.iobyte.themepark.commands.subcommands.region; import nl.iobyte.commandapi.arguments.MessageArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.NoRegionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; + import java.util.List; public class RegionCreateCommand extends SubCommand { @@ -20,13 +20,7 @@ public class RegionCreateCommand extends SubCommand { .addArgument(new MessageArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { String id = (String) list.get(0); String name = (String) list.get(1); @@ -36,4 +30,5 @@ public class RegionCreateCommand extends SubCommand { )); sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully created region &f"+id)); } + } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionListCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionListCommand.java index 69714d3..8f85840 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionListCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionListCommand.java @@ -2,12 +2,11 @@ package nl.iobyte.themepark.commands.subcommands.region; import com.google.common.collect.Iterables; import nl.iobyte.commandapi.arguments.number.IntegerArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.message.Text; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.Collection; import java.util.List; @@ -22,13 +21,7 @@ public class RegionListCommand extends SubCommand { .addArgument(new IntegerArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Collection regions = ThemePark.getInstance().getAPI().getAttractionService().getRegions().values(); if(regions.size() <= 5) { sendSinglePage(sender, regions); @@ -37,7 +30,7 @@ public class RegionListCommand extends SubCommand { } } - private void sendSinglePage(CommandSender sender, Collection regions) { + private void sendSinglePage(ICommandExecutor sender, Collection regions) { sender.sendMessage(Text.color("&f&l>==== &6&lThemePark &l&f====<")); if(regions.isEmpty()) { sender.sendMessage(Text.color("&6No regions found")); @@ -49,7 +42,7 @@ public class RegionListCommand extends SubCommand { sender.sendMessage(Text.color("&f&l>==== &6&lThemePark &l&f====<")); } - private void sendMultiPage(CommandSender sender, Collection regions, List list, int i) { + private void sendMultiPage(ICommandExecutor sender, Collection regions, List list, int i) { int page = 1; int pages = (int) Math.ceil(((double) regions.size()) / 5); if(i == 1) diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java index 86de9af..098a377 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java @@ -1,12 +1,11 @@ package nl.iobyte.themepark.commands.subcommands.region; import nl.iobyte.commandapi.arguments.MessageArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.RegionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; public class RegionNameCommand extends SubCommand { @@ -19,16 +18,11 @@ public class RegionNameCommand extends SubCommand { .addArgument(new MessageArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Region region = (Region) list.get(0); String name = (String) list.get(1); region.setName(name); sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the name of region &f"+region.getID())); } + } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java index dc5b344..8195d3f 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java @@ -1,12 +1,11 @@ package nl.iobyte.themepark.commands.subcommands.region; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.RegionArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; public class RegionRemoveCommand extends SubCommand { @@ -18,15 +17,10 @@ public class RegionRemoveCommand extends SubCommand { .addArgument(new RegionArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + public void onCommand(ICommandExecutor sender, List list, int i) { Region region = (Region) list.get(0); ThemePark.getInstance().getAPI().getAttractionService().removeRegion(region.getID()); sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully removed region &f"+region.getID())); } + } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java index 58e9382..a108588 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java @@ -1,13 +1,13 @@ package nl.iobyte.themepark.commands.subcommands.ridecount; -import nl.iobyte.commandapi.arguments.PlayersArgument; import nl.iobyte.commandapi.arguments.number.IntegerArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.commands.arguments.AttractionArgument; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.themepark.commands.arguments.PlayersArgument; import org.bukkit.entity.Player; import java.util.List; @@ -22,13 +22,8 @@ public class RideCountAddCommand extends SubCommand { .addArgument(new IntegerArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); List players = (List) list.get(1); int amount = (Integer) list.get(2); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java index 475f44f..0dd4152 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java @@ -1,13 +1,13 @@ package nl.iobyte.themepark.commands.subcommands.ridecount; -import nl.iobyte.commandapi.arguments.PlayerArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.api.ridecount.objects.RideCount; import nl.iobyte.themepark.commands.arguments.AttractionArgument; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.themepark.commands.arguments.PlayerArgument; import org.bukkit.entity.Player; import java.util.List; @@ -21,13 +21,8 @@ public class RideCountGetCommand extends SubCommand { .addArgument(new PlayerArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); Player player = (Player) list.get(1); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusColorCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusColorCommand.java index 9e27bc3..b4a6734 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusColorCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusColorCommand.java @@ -2,10 +2,10 @@ package nl.iobyte.themepark.commands.subcommands.status; import nl.iobyte.commandapi.arguments.EnumArgument; import nl.iobyte.commandapi.arguments.StringArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.message.Text; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; @@ -19,13 +19,8 @@ public class StatusColorCommand extends SubCommand { .addArgument(new StringArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Status status = (Status) list.get(0); String color = (String) list.get(1); status.setColor(color); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusHexColorCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusHexColorCommand.java index f81b35d..60a595d 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusHexColorCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusHexColorCommand.java @@ -2,10 +2,10 @@ package nl.iobyte.themepark.commands.subcommands.status; import nl.iobyte.commandapi.arguments.EnumArgument; import nl.iobyte.commandapi.arguments.StringArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.message.Text; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; @@ -20,13 +20,8 @@ public class StatusHexColorCommand extends SubCommand { .addArgument(new StringArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Status status = (Status) list.get(0); String hex_color = (String) list.get(1); status.setHexColor(hex_color); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusMaterialCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusMaterialCommand.java index 7b82468..8884a75 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusMaterialCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusMaterialCommand.java @@ -2,14 +2,11 @@ package nl.iobyte.themepark.commands.subcommands.status; import com.cryptomorin.xseries.XMaterial; import nl.iobyte.commandapi.arguments.EnumArgument; -import nl.iobyte.commandapi.arguments.MaterialArgument; -import nl.iobyte.commandapi.arguments.number.ShortArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.message.Text; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import nl.iobyte.themepark.commands.arguments.MaterialArgument; import java.util.List; public class StatusMaterialCommand extends SubCommand { @@ -20,34 +17,15 @@ public class StatusMaterialCommand extends SubCommand { addSyntax("/themepark status material ") .addArgument(new EnumArgument(Status.values())) .addArgument(new MaterialArgument()); - - addSyntax("/themepark status material ") - .addArgument(new EnumArgument(Status.values())) - .addArgument(new MaterialArgument()) - .addArgument(new ShortArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Status status = (Status) list.get(0); - XMaterial material; - if(i == 0) { - material = XMaterial.matchXMaterial((Material) list.get(1)); - } else { - material = XMaterial.matchXMaterial(list.get(1).toString()+":"+list.get(2).toString()).orElse(null); - if(material == null) { - sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &4Unable to parse specified material:data")); - return; - } - } + XMaterial material = (XMaterial) list.get(1); status.setMaterial(material); - sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the material of status &f"+status.toString())); + sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the material of status &f"+ status)); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java index 5789ca9..6d94c26 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java @@ -2,10 +2,10 @@ package nl.iobyte.themepark.commands.subcommands.status; import nl.iobyte.commandapi.arguments.EnumArgument; import nl.iobyte.commandapi.arguments.MessageArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.message.Text; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; @@ -19,13 +19,8 @@ public class StatusNameCommand extends SubCommand { .addArgument(new MessageArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Status status = (Status) list.get(0); String name = (String) list.get(1); status.setName(name); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusTeleportCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusTeleportCommand.java index 33aa0e9..99cd0e6 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusTeleportCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusTeleportCommand.java @@ -2,10 +2,10 @@ package nl.iobyte.themepark.commands.subcommands.status; import nl.iobyte.commandapi.arguments.BooleanArgument; import nl.iobyte.commandapi.arguments.EnumArgument; -import nl.iobyte.commandapi.interfaces.SubCommand; +import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.message.Text; -import org.bukkit.command.CommandSender; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; import org.bukkit.entity.Player; import java.util.List; @@ -19,13 +19,8 @@ public class StatusTeleportCommand extends SubCommand { .addArgument(new BooleanArgument()); } - @Override - public void onPlayerCommand(Player player, List list, int i) { - onConsoleCommand(player, list, i); - } - - @Override - public void onConsoleCommand(CommandSender sender, List list, int i) { + + public void onCommand(ICommandExecutor sender, List list, int i) { Status status = (Status) list.get(0); boolean b = (boolean) list.get(1); status.setCanTeleport(b); diff --git a/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java b/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java index 04e1a66..941b137 100644 --- a/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java +++ b/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java @@ -96,7 +96,7 @@ public class PlayerListener implements Listener { e.setCancelled(true); Player player = e.getPlayer(); - ThemePark.getInstance().getAPI().getMenuService().getMainMenu().open(player); + Bukkit.dispatchCommand(player, "themepark menu"); } //Handle Menu item drop diff --git a/src/main/resources/menu.yml b/src/main/resources/menu.yml index 5dd6c7f..46a1769 100644 --- a/src/main/resources/menu.yml +++ b/src/main/resources/menu.yml @@ -12,6 +12,7 @@ menu: - world_nether - world_the_end main: + enabled: true size: 27 title: '&6&lThemePark' status: diff --git a/src/main/resources/message.yml b/src/main/resources/message.yml index 7e24db8..ae8ef56 100644 --- a/src/main/resources/message.yml +++ b/src/main/resources/message.yml @@ -1,7 +1,12 @@ -version: 1.0 +version: 1.1 prefix: '&6&lThemeParkMC &r&f➢' +menu: + previous: "&6&L\u23F4 Previous" + page: "&6Page &f" + next: "&6&LNext \u23F5" + ridecount: add: "{prefix} &aYou have ridden attraction: &f%NAME% &6%AMOUNT%x &afor a total of &6%TOTAL%x" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 79b2532..6e7bc54 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,10 @@ name: ThemePark -version: 3.0.0 +version: 3.0.2 author: IOByte website: 'https://www.iobyte.nl' main: nl.iobyte.themepark.ThemePark softdepend: [PlaceholderAPI,Train_Carts,Multiverse-Core,MultiWorld] api-version: 1.13 commands: - themepark: \ No newline at end of file + themepark: + aliases: [tp] \ No newline at end of file diff --git a/themepark.iml b/themepark.iml index 0630145..894ee5d 100644 --- a/themepark.iml +++ b/themepark.iml @@ -6,10 +6,9 @@ - - + @@ -20,7 +19,7 @@ - + @@ -40,11 +39,12 @@ - - - - - + + + + + + @@ -76,5 +76,14 @@ + + + + + + + + + \ No newline at end of file