From 584b2e738c66b1fc886294096ff6097eaac37cd9 Mon Sep 17 00:00:00 2001 From: thomas Date: Mon, 9 Aug 2021 12:32:11 +0200 Subject: [PATCH] Added custom command to syntax messages Added different total types for ridecount Implemented update manager --- .../java/nl/iobyte/themepark/ThemePark.java | 38 +++++++++++- .../api/config/enums/StorageKey.java | 5 ++ .../RideCountTotalTypeChangeEvent.java | 12 ++++ .../api/ridecount/RideCountService.java | 18 ++++++ .../api/ridecount/enums/TotalType.java | 11 ++++ .../themepark/commands/ThemeParkCommand.java | 5 +- .../commands/subcommands/HelpCommand.java | 4 +- .../commands/subcommands/ItemCommand.java | 4 +- .../commands/subcommands/MenuCommand.java | 6 +- .../attraction/AttractionCommands.java | 18 +++--- .../attraction/AttractionCoverCommand.java | 4 +- .../attraction/AttractionCreateCommand.java | 8 +-- .../attraction/AttractionListCommand.java | 10 ++-- .../attraction/AttractionLocationCommand.java | 4 +- .../attraction/AttractionNameCommand.java | 4 +- .../attraction/AttractionRegionCommand.java | 4 +- .../attraction/AttractionRemoveCommand.java | 4 +- .../attraction/AttractionStatusCommand.java | 4 +- .../attraction/AttractionWarpCommand.java | 4 +- .../subcommands/region/RegionCommands.java | 8 +-- .../region/RegionCreateCommand.java | 4 +- .../subcommands/region/RegionListCommand.java | 6 +- .../subcommands/region/RegionNameCommand.java | 4 +- .../region/RegionRemoveCommand.java | 4 +- .../ridecount/RideCountAddCommand.java | 4 +- .../RideCountChangeTotalTypeCommand.java | 28 +++++++++ .../ridecount/RideCountCommands.java | 5 +- .../ridecount/RideCountGetCommand.java | 4 +- .../status/StatusColorCommand.java | 4 +- .../subcommands/status/StatusCommands.java | 10 ++-- .../status/StatusHexColorCommand.java | 4 +- .../status/StatusMaterialCommand.java | 4 +- .../subcommands/status/StatusNameCommand.java | 4 +- .../status/StatusTeleportCommand.java | 4 +- .../themepark/listeners/PlayerListener.java | 60 ++++++++++++++++--- .../listeners/RideCountListener.java | 7 +++ src/main/resources/settings.yml | 5 ++ 37 files changed, 250 insertions(+), 86 deletions(-) create mode 100644 src/main/java/nl/iobyte/themepark/api/event/ridecount/RideCountTotalTypeChangeEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/ridecount/enums/TotalType.java create mode 100644 src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountChangeTotalTypeCommand.java diff --git a/src/main/java/nl/iobyte/themepark/ThemePark.java b/src/main/java/nl/iobyte/themepark/ThemePark.java index df96c41..b9e57da 100644 --- a/src/main/java/nl/iobyte/themepark/ThemePark.java +++ b/src/main/java/nl/iobyte/themepark/ThemePark.java @@ -2,8 +2,10 @@ package nl.iobyte.themepark; import nl.iobyte.menuapi.MenuAPI; import nl.iobyte.themepark.api.ThemeParkAPI; +import nl.iobyte.themepark.api.config.enums.StorageKey; import nl.iobyte.themepark.commands.ThemeParkCommand; import nl.iobyte.themepark.listeners.*; +import nl.iobyte.themepark.logger.ThemeParkLogger; import nl.iobyte.themepark.utils.UpdateManager; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -57,7 +59,41 @@ public class ThemePark extends JavaPlugin { } private void loadUpdateManager() { - //TODO new UpdateManager(this, 48648); + if(!api.getConfigurationManager().getBoolean(StorageKey.UPDATE_CHECK_ENABLED)) + return; + + UpdateManager manager = new UpdateManager(this, 48648); + manager.handleResponse((response, version) -> { + switch (response) { + case LATEST: + getLogger().info("You're running the latest version("+version.get()+")"); + break; + case THIS_NEWER: + getLogger().info("You're running a newer version("+version.get()+")"); + break; + case UNAVAILABLE: + getLogger().info("Unable to check for updates"); + break; + case FOUND_NEW: + getLogger().info("Found newer version("+version.get()+")"); + if(!api.getConfigurationManager().getBoolean(StorageKey.UPDATE_DOWNLOAD_ENABLED)) + return; + + manager.handleDownloadResponse((downloadResponse, fileName) -> { + switch (downloadResponse) { + case DONE: + getLogger().info("Update downloaded! If you restart your server, it will be loaded. Filename: " + fileName); + break; + case ERROR: + getLogger().severe("Something went wrong when trying downloading the latest version."); + break; + case UNAVAILABLE: + getLogger().warning("Unable to download the latest version."); + break; + } + }).runUpdate(); + } + }).check(); } public void onDisable() { 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 3b214e8..ebdcb5c 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 @@ -4,6 +4,11 @@ public enum StorageKey { //General Settings CMD(StorageLocation.SETTINGS, "cmd"), + RIDECOUNT_TOTAL_TYPE(StorageLocation.SETTINGS, "ridecount_total_type"), + + //Update Settings + UPDATE_CHECK_ENABLED(StorageLocation.SETTINGS, "update.check"), + UPDATE_DOWNLOAD_ENABLED(StorageLocation.SETTINGS, "update.download"), //Database Settings MYSQL_ENABLED(StorageLocation.SETTINGS, "mysql.enabled"), diff --git a/src/main/java/nl/iobyte/themepark/api/event/ridecount/RideCountTotalTypeChangeEvent.java b/src/main/java/nl/iobyte/themepark/api/event/ridecount/RideCountTotalTypeChangeEvent.java new file mode 100644 index 0000000..06c08a6 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/event/ridecount/RideCountTotalTypeChangeEvent.java @@ -0,0 +1,12 @@ +package nl.iobyte.themepark.api.event.ridecount; + +import nl.iobyte.themepark.api.event.objects.ChangeEvent; +import nl.iobyte.themepark.api.ridecount.enums.TotalType; + +public class RideCountTotalTypeChangeEvent extends ChangeEvent { + + public RideCountTotalTypeChangeEvent(TotalType old, TotalType current) { + super(old, current); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/ridecount/RideCountService.java b/src/main/java/nl/iobyte/themepark/api/ridecount/RideCountService.java index 77cf6cf..1bce299 100644 --- a/src/main/java/nl/iobyte/themepark/api/ridecount/RideCountService.java +++ b/src/main/java/nl/iobyte/themepark/api/ridecount/RideCountService.java @@ -1,6 +1,8 @@ package nl.iobyte.themepark.api.ridecount; import nl.iobyte.themepark.ThemePark; +import nl.iobyte.themepark.api.event.ridecount.RideCountTotalTypeChangeEvent; +import nl.iobyte.themepark.api.ridecount.enums.TotalType; import nl.iobyte.themepark.api.ridecount.objects.AttractionCount; import nl.iobyte.themepark.api.ridecount.objects.RideCount; import nl.iobyte.themepark.api.ridecount.objects.TopData; @@ -13,6 +15,22 @@ public class RideCountService { private final Map counts = new ConcurrentHashMap<>(); private final TopData topData = new TopData(); private boolean changed = false; + private TotalType type = TotalType.DAILY; + + public TotalType getType() { + return type; + } + + public void setType(TotalType type) { + if(this.type == type) + return; + + TotalType old = this.type; + this.type = type; + ThemePark.getInstance().getAPI().getEventDispatcher().call( + new RideCountTotalTypeChangeEvent(old, type) + ); + } public AttractionCount getCount(String id) { if(id == null || id.isEmpty()) diff --git a/src/main/java/nl/iobyte/themepark/api/ridecount/enums/TotalType.java b/src/main/java/nl/iobyte/themepark/api/ridecount/enums/TotalType.java new file mode 100644 index 0000000..98848b8 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/ridecount/enums/TotalType.java @@ -0,0 +1,11 @@ +package nl.iobyte.themepark.api.ridecount.enums; + +public enum TotalType { + + DAILY, + WEEKLY, + MONTHLY, + YEARLY, + TOTAL + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java b/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java index 814313c..f6f9d72 100644 --- a/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/ThemeParkCommand.java @@ -16,7 +16,6 @@ import nl.iobyte.themepark.commands.subcommands.ridecount.RideCountCommands; import nl.iobyte.themepark.commands.subcommands.status.StatusCommands; import org.bukkit.Bukkit; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -30,10 +29,10 @@ public class ThemeParkCommand { CommandFactory factory = new CommandFactory(cmd); factory.addSubCommand(new HelpCommand(factory)) - .addSubCommand(new MenuCommand()); + .addSubCommand(new MenuCommand(factory.getName())); //Admin - factory.addSubCommand(new ItemCommand()); + factory.addSubCommand(new ItemCommand(factory.getName())); //Region RegionCommands.load(factory); 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 58bcca7..0e2f20c 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/HelpCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/HelpCommand.java @@ -15,8 +15,8 @@ public class HelpCommand extends SubCommand { super(new String[]{"help"}); this.factory = factory; - addSyntax("/themepark help"); - addSyntax("/themepark help ") + addSyntax("/"+factory.getName()+" help"); + addSyntax("/"+factory.getName()+" help ") .addArgument(new IntegerArgument()); } 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 beadda9..24523bd 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/ItemCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ItemCommand.java @@ -13,10 +13,10 @@ import java.util.List; public class ItemCommand extends SubCommand { - public ItemCommand() { + public ItemCommand(String cmd) { super("themepark.admin", "item"); - addSyntax("/themepark item") + addSyntax("/"+cmd+" item") .setAllowConsole(false); } 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 290a937..ba204ab 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/MenuCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/MenuCommand.java @@ -12,13 +12,13 @@ import java.util.List; public class MenuCommand extends SubCommand { - public MenuCommand() { + public MenuCommand(String cmd) { super(new String[]{"menu"}); - addSyntax("/themepark menu") + addSyntax("/"+cmd+" menu") .setAllowConsole(false); - addSyntax("/themepark menu") + addSyntax("/"+cmd+" menu status") .addArgument(new StringArgument("status")) .setAllowConsole(false); } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCommands.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCommands.java index ef4ae7b..906b66b 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCommands.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCommands.java @@ -5,15 +5,15 @@ import nl.iobyte.commandapi.CommandFactory; public class AttractionCommands { public static void load(CommandFactory factory) { - factory.addSubCommand(new AttractionListCommand()) - .addSubCommand(new AttractionWarpCommand()) - .addSubCommand(new AttractionCreateCommand()) - .addSubCommand(new AttractionRegionCommand()) - .addSubCommand(new AttractionNameCommand()) - .addSubCommand(new AttractionCoverCommand()) - .addSubCommand(new AttractionStatusCommand()) - .addSubCommand(new AttractionLocationCommand()) - .addSubCommand(new AttractionRemoveCommand()); + factory.addSubCommand(new AttractionListCommand(factory.getName())) + .addSubCommand(new AttractionWarpCommand(factory.getName())) + .addSubCommand(new AttractionCreateCommand(factory.getName())) + .addSubCommand(new AttractionRegionCommand(factory.getName())) + .addSubCommand(new AttractionNameCommand(factory.getName())) + .addSubCommand(new AttractionCoverCommand(factory.getName())) + .addSubCommand(new AttractionStatusCommand(factory.getName())) + .addSubCommand(new AttractionLocationCommand(factory.getName())) + .addSubCommand(new AttractionRemoveCommand(factory.getName())); } } 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 bcbc02b..a5544f8 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 @@ -10,10 +10,10 @@ import java.util.List; public class AttractionCoverCommand extends SubCommand { - public AttractionCoverCommand() { + public AttractionCoverCommand(String cmd) { super("themepark.admin", "attraction", "cover"); - addSyntax("/themepark attraction cover ") + addSyntax("/"+cmd+" attraction cover ") .addArgument(new AttractionArgument()) .addArgument(new StringArgument()); } 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 b0f3414..45b78c7 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 @@ -18,21 +18,21 @@ import java.util.List; public class AttractionCreateCommand extends SubCommand { - public AttractionCreateCommand() { + public AttractionCreateCommand(String cmd) { super("themepark.admin", "attraction", "create"); - addSyntax("/themepark attraction create ") + addSyntax("/"+cmd+" attraction create ") .addArgument(new NoAttractionArgument()) .addArgument(new RegionArgument()) .addArgument(new MessageArgument()); - addSyntax("/themepark attraction create ") + addSyntax("/"+cmd+" attraction create ") .addArgument(new NoAttractionArgument()) .addArgument(new RegionArgument()) .addArgument(new MessageArgument()) .addArgument(new EnumArgument(Status.values())); - addSyntax("/themepark attraction create ") + addSyntax("/"+cmd+" attraction create ") .addArgument(new NoAttractionArgument()) .addArgument(new RegionArgument()) .addArgument(new MessageArgument()) 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 2436919..4306490 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 @@ -14,18 +14,18 @@ import java.util.List; public class AttractionListCommand extends SubCommand { - public AttractionListCommand() { + public AttractionListCommand(String cmd) { super("themepark.admin", "attraction", "list"); - addSyntax("/themepark attraction list"); + addSyntax("/"+cmd+" attraction list"); - addSyntax("/themepark attraction list ") + addSyntax("/"+cmd+" attraction list ") .addArgument(new IntegerArgument()); - addSyntax("/themepark attraction list ") + addSyntax("/"+cmd+" attraction list ") .addArgument(new RegionArgument()); - addSyntax("/themepark attraction list ") + addSyntax("/"+cmd+" attraction list ") .addArgument(new RegionArgument()) .addArgument(new IntegerArgument()); } 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 3a7e212..ec148d7 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 @@ -10,10 +10,10 @@ import java.util.List; public class AttractionLocationCommand extends SubCommand { - public AttractionLocationCommand() { + public AttractionLocationCommand(String cmd) { super("themepark.admin", "attraction", "location"); - addSyntax("/themepark attraction location ") + addSyntax("/"+cmd+" attraction location ") .addArgument(new AttractionArgument()) .setAllowConsole(false); } 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 dbcf260..0bb7bae 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 @@ -10,10 +10,10 @@ import java.util.List; public class AttractionNameCommand extends SubCommand { - public AttractionNameCommand() { + public AttractionNameCommand(String cmd) { super("themepark.admin", "attraction", "name"); - addSyntax("/themepark attraction name ") + addSyntax("/"+cmd+" attraction name ") .addArgument(new AttractionArgument()) .addArgument(new MessageArgument()); } 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 9d7201b..daa78db 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 @@ -11,10 +11,10 @@ import java.util.List; public class AttractionRegionCommand extends SubCommand { - public AttractionRegionCommand() { + public AttractionRegionCommand(String cmd) { super("themepark.admin", "attraction", "region"); - addSyntax("/themepark attraction region ") + addSyntax("/"+cmd+" attraction region ") .addArgument(new AttractionArgument()) .addArgument(new RegionArgument()); } 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 aa579a6..23221e3 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 @@ -10,10 +10,10 @@ import java.util.List; public class AttractionRemoveCommand extends SubCommand { - public AttractionRemoveCommand() { + public AttractionRemoveCommand(String cmd) { super("themepark.admin", "attraction", "remove"); - addSyntax("/themepark attraction remove ") + addSyntax("/"+cmd+" attraction remove ") .addArgument(new AttractionArgument()); } 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 ec434c6..6efbc94 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 @@ -13,10 +13,10 @@ import java.util.List; public class AttractionStatusCommand extends SubCommand { - public AttractionStatusCommand() { + public AttractionStatusCommand(String cmd) { super("themepark.admin", "attraction", "status"); - addSyntax("/themepark attraction status ") + addSyntax("/"+cmd+" attraction status ") .addArgument(new AttractionArgument()) .addArgument(new EnumArgument(Status.values())); } 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 4ab074c..d9597c5 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 @@ -12,10 +12,10 @@ import java.util.List; public class AttractionWarpCommand extends SubCommand { - public AttractionWarpCommand() { + public AttractionWarpCommand(String cmd) { super(new String[]{"attraction", "warp"}); - addSyntax("/themepark attraction warp ") + addSyntax("/"+cmd+" attraction warp ") .addArgument(new AttractionArgument()) .setAllowConsole(false); } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java index 86b74f6..e2319df 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java @@ -5,10 +5,10 @@ import nl.iobyte.commandapi.CommandFactory; public class RegionCommands { public static void load(CommandFactory factory) { - factory.addSubCommand(new RegionListCommand()) - .addSubCommand(new RegionCreateCommand()) - .addSubCommand(new RegionNameCommand()) - .addSubCommand(new RegionRemoveCommand()); + factory.addSubCommand(new RegionListCommand(factory.getName())) + .addSubCommand(new RegionCreateCommand(factory.getName())) + .addSubCommand(new RegionNameCommand(factory.getName())) + .addSubCommand(new RegionRemoveCommand(factory.getName())); } } 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 3a637ad..bddff00 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 @@ -12,10 +12,10 @@ import java.util.List; public class RegionCreateCommand extends SubCommand { - public RegionCreateCommand() { + public RegionCreateCommand(String cmd) { super("themepark.admin", "region", "create"); - addSyntax("/themepark region create ") + addSyntax("/"+cmd+" region create ") .addArgument(new NoRegionArgument()) .addArgument(new MessageArgument()); } 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 8f85840..48a71e5 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 @@ -12,12 +12,12 @@ import java.util.List; public class RegionListCommand extends SubCommand { - public RegionListCommand() { + public RegionListCommand(String cmd) { super("themepark.admin", "region", "list"); - addSyntax("/themepark region list"); + addSyntax("/"+cmd+" region list"); - addSyntax("/themepark region list ") + addSyntax("/"+cmd+" region list ") .addArgument(new IntegerArgument()); } 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 098a377..f5270ef 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 @@ -10,10 +10,10 @@ import java.util.List; public class RegionNameCommand extends SubCommand { - public RegionNameCommand() { + public RegionNameCommand(String cmd) { super("themepark.admin", "region", "name"); - addSyntax("/themepark region name ") + addSyntax("/"+cmd+" region name ") .addArgument(new RegionArgument()) .addArgument(new MessageArgument()); } 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 8195d3f..a7b7f58 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 @@ -10,10 +10,10 @@ import java.util.List; public class RegionRemoveCommand extends SubCommand { - public RegionRemoveCommand() { + public RegionRemoveCommand(String cmd) { super("themepark.admin", "region", "remove"); - addSyntax("/themepark region remove ") + addSyntax("/"+cmd+" region remove ") .addArgument(new RegionArgument()); } 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 a108588..e277abb 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 @@ -13,10 +13,10 @@ import java.util.List; public class RideCountAddCommand extends SubCommand { - public RideCountAddCommand() { + public RideCountAddCommand(String cmd) { super("themepark.admin", "ridecount", "add"); - addSyntax("/themepark ridecount add ") + addSyntax("/"+cmd+" ridecount add ") .addArgument(new AttractionArgument()) .addArgument(new PlayersArgument()) .addArgument(new IntegerArgument()); diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountChangeTotalTypeCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountChangeTotalTypeCommand.java new file mode 100644 index 0000000..54cbf56 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountChangeTotalTypeCommand.java @@ -0,0 +1,28 @@ +package nl.iobyte.themepark.commands.subcommands.ridecount; + +import nl.iobyte.commandapi.arguments.EnumArgument; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; +import nl.iobyte.themepark.ThemePark; +import nl.iobyte.themepark.api.message.Text; +import nl.iobyte.themepark.api.ridecount.enums.TotalType; +import java.util.List; + +public class RideCountChangeTotalTypeCommand extends SubCommand { + + public RideCountChangeTotalTypeCommand(String cmd) { + super("themepark.admin", "ridecount", "total_type"); + + addSyntax("/"+cmd+" ridecount total_type ") + .addArgument(new EnumArgument(TotalType.values())); + } + + + public void onCommand(ICommandExecutor sender, List list, int i) { + TotalType type = (TotalType) list.get(0); + + ThemePark.getInstance().getAPI().getRideCountService().setType(type); + sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ Changed total type for ridecount to: &f"+type.toString())); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountCommands.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountCommands.java index acaf0fe..cd757c0 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountCommands.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountCommands.java @@ -5,8 +5,9 @@ import nl.iobyte.commandapi.CommandFactory; public class RideCountCommands { public static void load(CommandFactory factory) { - factory.addSubCommand(new RideCountGetCommand()) - .addSubCommand(new RideCountAddCommand()); + factory.addSubCommand(new RideCountGetCommand(factory.getName())) + .addSubCommand(new RideCountAddCommand(factory.getName())) + .addSubCommand(new RideCountChangeTotalTypeCommand(factory.getName())); } } 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 0dd4152..8f6d793 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 @@ -13,10 +13,10 @@ import java.util.List; public class RideCountGetCommand extends SubCommand { - public RideCountGetCommand() { + public RideCountGetCommand(String cmd) { super("themepark.admin", "ridecount", "get"); - addSyntax("/themepark ridecount get ") + addSyntax("/"+cmd+" ridecount get ") .addArgument(new AttractionArgument()) .addArgument(new PlayerArgument()); } 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 b4a6734..d015d22 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 @@ -11,10 +11,10 @@ import java.util.List; public class StatusColorCommand extends SubCommand { - public StatusColorCommand() { + public StatusColorCommand(String cmd) { super("themepark.admin", "status", "color"); - addSyntax("/themepark status color ") + addSyntax("/"+cmd+" status color ") .addArgument(new EnumArgument(Status.values())) .addArgument(new StringArgument()); } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusCommands.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusCommands.java index dedb7ae..eee9bff 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusCommands.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusCommands.java @@ -5,11 +5,11 @@ import nl.iobyte.commandapi.CommandFactory; public class StatusCommands { public static void load(CommandFactory factory) { - factory.addSubCommand(new StatusNameCommand()) - .addSubCommand(new StatusColorCommand()) - .addSubCommand(new StatusHexColorCommand()) - .addSubCommand(new StatusMaterialCommand()) - .addSubCommand(new StatusTeleportCommand()); + factory.addSubCommand(new StatusNameCommand(factory.getName())) + .addSubCommand(new StatusColorCommand(factory.getName())) + .addSubCommand(new StatusHexColorCommand(factory.getName())) + .addSubCommand(new StatusMaterialCommand(factory.getName())) + .addSubCommand(new StatusTeleportCommand(factory.getName())); } } 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 60a595d..b7eeeae 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 @@ -12,10 +12,10 @@ import java.util.List; public class StatusHexColorCommand extends SubCommand { - public StatusHexColorCommand() { + public StatusHexColorCommand(String cmd) { super("themepark.admin", "status", "hex_color"); - addSyntax("/themepark status hex_color ") + addSyntax("/"+cmd+" status hex_color ") .addArgument(new EnumArgument(Status.values())) .addArgument(new StringArgument()); } 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 8884a75..b4abd5f 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 @@ -11,10 +11,10 @@ import java.util.List; public class StatusMaterialCommand extends SubCommand { - public StatusMaterialCommand() { + public StatusMaterialCommand(String cmd) { super("themepark.admin", "status", "material"); - addSyntax("/themepark status material ") + addSyntax("/"+cmd+" status material ") .addArgument(new EnumArgument(Status.values())) .addArgument(new MaterialArgument()); } 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 6d94c26..f017046 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 @@ -11,10 +11,10 @@ import java.util.List; public class StatusNameCommand extends SubCommand { - public StatusNameCommand() { + public StatusNameCommand(String cmd) { super("themepark.admin", "status", "name"); - addSyntax("/themepark status name ") + addSyntax("/"+cmd+" status name ") .addArgument(new EnumArgument(Status.values())) .addArgument(new MessageArgument()); } 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 99cd0e6..8854664 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 @@ -11,10 +11,10 @@ import java.util.List; public class StatusTeleportCommand extends SubCommand { - public StatusTeleportCommand() { + public StatusTeleportCommand(String cmd) { super("themepark.admin", "status", "teleport"); - addSyntax("/themepark status teleport ") + addSyntax("/"+cmd+" status teleport ") .addArgument(new EnumArgument(Status.values())) .addArgument(new BooleanArgument()); } diff --git a/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java b/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java index ae5a562..093dd65 100644 --- a/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java +++ b/src/main/java/nl/iobyte/themepark/listeners/PlayerListener.java @@ -6,6 +6,7 @@ import nl.iobyte.themepark.api.ThemeParkAPI; import nl.iobyte.themepark.api.config.ConfigurationManager; import nl.iobyte.themepark.api.config.enums.StorageKey; import nl.iobyte.themepark.api.message.Text; +import nl.iobyte.themepark.api.ridecount.enums.TotalType; import nl.iobyte.themepark.scheduler.ThemeParkScheduler; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -32,17 +33,58 @@ public class PlayerListener implements Listener { doItem(player); //Load RideCount data - Calendar calendar = new GregorianCalendar(); - calendar.setTime(new Date()); + TotalType type = api.getRideCountService().getType(); + String query; + Map parameters; + if(type == TotalType.TOTAL) { + query = "SELECT count, attraction_id, (SELECT sum(count) FROM counts AS t1 WHERE t1.uuid=t2.uuid AND t1.attraction_id=t2.attraction_id GROUP BY t1.uuid) AS total_count FROM counts AS t2 WHERE uuid=?"; + parameters = new HashMap<>(){{ + put(1, player.getUniqueId().toString()); + }}; + } else { + Calendar calendar = new GregorianCalendar(); + calendar.setTime(new Date()); + switch (type) { + case DAILY: + query = "SELECT count, attraction_id, (SELECT sum(count) FROM counts AS t1 WHERE t1.uuid=t2.uuid AND t1.attraction_id=t2.attraction_id AND t1.year=t2.year AND t1.day=t2.day GROUP BY t1.uuid) AS total_count FROM counts AS t2 WHERE uuid=? AND year=? AND day=?"; + parameters = new HashMap<>() {{ + put(1, player.getUniqueId().toString()); + put(2, calendar.get(Calendar.YEAR)); + put(3, calendar.get(Calendar.DAY_OF_YEAR)); + }}; + break; + case WEEKLY: + query = "SELECT count, attraction_id, (SELECT sum(count) FROM counts AS t1 WHERE t1.uuid=t2.uuid AND t1.attraction_id=t2.attraction_id AND t1.year=t2.year AND t1.week=t2.week GROUP BY t1.uuid) AS total_count FROM counts AS t2 WHERE uuid=? AND year=? AND week=?"; + parameters = new HashMap<>() {{ + put(1, player.getUniqueId().toString()); + put(2, calendar.get(Calendar.YEAR)); + put(3, calendar.get(Calendar.WEEK_OF_YEAR)); + }}; + break; + case MONTHLY: + query = "SELECT count, attraction_id, (SELECT sum(count) FROM counts AS t1 WHERE t1.uuid=t2.uuid AND t1.attraction_id=t2.attraction_id AND t1.year=t2.year AND t1.month=t2.month GROUP BY t1.uuid) AS total_count FROM counts AS t2 WHERE uuid=? AND year=? AND month=?"; + parameters = new HashMap<>() {{ + put(1, player.getUniqueId().toString()); + put(2, calendar.get(Calendar.YEAR)); + put(3, calendar.get(Calendar.MONTH)); + }}; + break; + case YEARLY: + query = "SELECT count, attraction_id, (SELECT sum(count) FROM counts AS t1 WHERE t1.uuid=t2.uuid AND t1.attraction_id=t2.attraction_id AND t1.year=t2.year GROUP BY t1.uuid) AS total_count FROM counts AS t2 WHERE uuid=? AND year=?"; + parameters = new HashMap<>() {{ + put(1, player.getUniqueId().toString()); + put(2, calendar.get(Calendar.YEAR)); + }}; + break; + default: + return; + } + } + api.getDatabaseService().executeQueryAsync( "local", - "SELECT count, attraction_id, (SELECT sum(count) FROM counts AS t1 WHERE t1.uuid=t2.uuid AND t1.attraction_id=t2.attraction_id AND t1.year=t2.year AND t1.month=? GROUP BY t1.uuid) AS total_count FROM counts AS t2 WHERE uuid=? AND year=? AND day=?", - new HashMap<>() {{ - put(1, calendar.get(Calendar.MONTH)); - put(2, player.getUniqueId().toString()); - put(3, calendar.get(Calendar.YEAR)); - put(4, calendar.get(Calendar.DAY_OF_YEAR)); - }} + query, + parameters ).setWhenSuccessful(result -> { if(result != null) for(Map row : result) diff --git a/src/main/java/nl/iobyte/themepark/listeners/RideCountListener.java b/src/main/java/nl/iobyte/themepark/listeners/RideCountListener.java index e22f0b9..38fdfa3 100644 --- a/src/main/java/nl/iobyte/themepark/listeners/RideCountListener.java +++ b/src/main/java/nl/iobyte/themepark/listeners/RideCountListener.java @@ -2,8 +2,10 @@ package nl.iobyte.themepark.listeners; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Attraction; +import nl.iobyte.themepark.api.config.enums.StorageKey; import nl.iobyte.themepark.api.database.objects.types.SQLiteDatabase; import nl.iobyte.themepark.api.event.ridecount.RideCountAddEvent; +import nl.iobyte.themepark.api.event.ridecount.RideCountTotalTypeChangeEvent; import nl.iobyte.themepark.api.message.MessageKey; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.api.ridecount.objects.RideCount; @@ -89,4 +91,9 @@ public class RideCountListener implements Listener { ); } + @EventHandler + public void onChance(RideCountTotalTypeChangeEvent e) { + ThemePark.getInstance().getAPI().getConfigurationManager().set(StorageKey.RIDECOUNT_TOTAL_TYPE, e.getCurrent()); + } + } diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index 6935723..a55ceb8 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -1,6 +1,11 @@ version: 1.2 cmd: "themepark" +ridecount_total_type: MONTHLY + +update: + check: true + download: true mysql: enabled: false