3
0
Fork 0

Added custom command to syntax messages

Added different total types for ridecount
Implemented update manager
This commit is contained in:
thomas 2021-08-09 12:32:11 +02:00
parent 08ff78c415
commit 584b2e738c
37 changed files with 250 additions and 86 deletions

View file

@ -2,8 +2,10 @@ package nl.iobyte.themepark;
import nl.iobyte.menuapi.MenuAPI; import nl.iobyte.menuapi.MenuAPI;
import nl.iobyte.themepark.api.ThemeParkAPI; import nl.iobyte.themepark.api.ThemeParkAPI;
import nl.iobyte.themepark.api.config.enums.StorageKey;
import nl.iobyte.themepark.commands.ThemeParkCommand; import nl.iobyte.themepark.commands.ThemeParkCommand;
import nl.iobyte.themepark.listeners.*; import nl.iobyte.themepark.listeners.*;
import nl.iobyte.themepark.logger.ThemeParkLogger;
import nl.iobyte.themepark.utils.UpdateManager; import nl.iobyte.themepark.utils.UpdateManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -57,7 +59,41 @@ public class ThemePark extends JavaPlugin {
} }
private void loadUpdateManager() { 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() { public void onDisable() {

View file

@ -4,6 +4,11 @@ public enum StorageKey {
//General Settings //General Settings
CMD(StorageLocation.SETTINGS, "cmd"), 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 //Database Settings
MYSQL_ENABLED(StorageLocation.SETTINGS, "mysql.enabled"), MYSQL_ENABLED(StorageLocation.SETTINGS, "mysql.enabled"),

View file

@ -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<TotalType> {
public RideCountTotalTypeChangeEvent(TotalType old, TotalType current) {
super(old, current);
}
}

View file

@ -1,6 +1,8 @@
package nl.iobyte.themepark.api.ridecount; package nl.iobyte.themepark.api.ridecount;
import nl.iobyte.themepark.ThemePark; 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.AttractionCount;
import nl.iobyte.themepark.api.ridecount.objects.RideCount; import nl.iobyte.themepark.api.ridecount.objects.RideCount;
import nl.iobyte.themepark.api.ridecount.objects.TopData; import nl.iobyte.themepark.api.ridecount.objects.TopData;
@ -13,6 +15,22 @@ public class RideCountService {
private final Map<String, AttractionCount> counts = new ConcurrentHashMap<>(); private final Map<String, AttractionCount> counts = new ConcurrentHashMap<>();
private final TopData topData = new TopData(); private final TopData topData = new TopData();
private boolean changed = false; 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) { public AttractionCount getCount(String id) {
if(id == null || id.isEmpty()) if(id == null || id.isEmpty())

View file

@ -0,0 +1,11 @@
package nl.iobyte.themepark.api.ridecount.enums;
public enum TotalType {
DAILY,
WEEKLY,
MONTHLY,
YEARLY,
TOTAL
}

View file

@ -16,7 +16,6 @@ import nl.iobyte.themepark.commands.subcommands.ridecount.RideCountCommands;
import nl.iobyte.themepark.commands.subcommands.status.StatusCommands; import nl.iobyte.themepark.commands.subcommands.status.StatusCommands;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap; import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -30,10 +29,10 @@ public class ThemeParkCommand {
CommandFactory factory = new CommandFactory(cmd); CommandFactory factory = new CommandFactory(cmd);
factory.addSubCommand(new HelpCommand(factory)) factory.addSubCommand(new HelpCommand(factory))
.addSubCommand(new MenuCommand()); .addSubCommand(new MenuCommand(factory.getName()));
//Admin //Admin
factory.addSubCommand(new ItemCommand()); factory.addSubCommand(new ItemCommand(factory.getName()));
//Region //Region
RegionCommands.load(factory); RegionCommands.load(factory);

View file

@ -15,8 +15,8 @@ public class HelpCommand extends SubCommand {
super(new String[]{"help"}); super(new String[]{"help"});
this.factory = factory; this.factory = factory;
addSyntax("/themepark help"); addSyntax("/"+factory.getName()+" help");
addSyntax("/themepark help <page>") addSyntax("/"+factory.getName()+" help <page>")
.addArgument(new IntegerArgument()); .addArgument(new IntegerArgument());
} }

View file

@ -13,10 +13,10 @@ import java.util.List;
public class ItemCommand extends SubCommand { public class ItemCommand extends SubCommand {
public ItemCommand() { public ItemCommand(String cmd) {
super("themepark.admin", "item"); super("themepark.admin", "item");
addSyntax("/themepark item") addSyntax("/"+cmd+" item")
.setAllowConsole(false); .setAllowConsole(false);
} }

View file

@ -12,13 +12,13 @@ import java.util.List;
public class MenuCommand extends SubCommand { public class MenuCommand extends SubCommand {
public MenuCommand() { public MenuCommand(String cmd) {
super(new String[]{"menu"}); super(new String[]{"menu"});
addSyntax("/themepark menu") addSyntax("/"+cmd+" menu")
.setAllowConsole(false); .setAllowConsole(false);
addSyntax("/themepark menu") addSyntax("/"+cmd+" menu status")
.addArgument(new StringArgument("status")) .addArgument(new StringArgument("status"))
.setAllowConsole(false); .setAllowConsole(false);
} }

View file

@ -5,15 +5,15 @@ import nl.iobyte.commandapi.CommandFactory;
public class AttractionCommands { public class AttractionCommands {
public static void load(CommandFactory factory) { public static void load(CommandFactory factory) {
factory.addSubCommand(new AttractionListCommand()) factory.addSubCommand(new AttractionListCommand(factory.getName()))
.addSubCommand(new AttractionWarpCommand()) .addSubCommand(new AttractionWarpCommand(factory.getName()))
.addSubCommand(new AttractionCreateCommand()) .addSubCommand(new AttractionCreateCommand(factory.getName()))
.addSubCommand(new AttractionRegionCommand()) .addSubCommand(new AttractionRegionCommand(factory.getName()))
.addSubCommand(new AttractionNameCommand()) .addSubCommand(new AttractionNameCommand(factory.getName()))
.addSubCommand(new AttractionCoverCommand()) .addSubCommand(new AttractionCoverCommand(factory.getName()))
.addSubCommand(new AttractionStatusCommand()) .addSubCommand(new AttractionStatusCommand(factory.getName()))
.addSubCommand(new AttractionLocationCommand()) .addSubCommand(new AttractionLocationCommand(factory.getName()))
.addSubCommand(new AttractionRemoveCommand()); .addSubCommand(new AttractionRemoveCommand(factory.getName()));
} }
} }

View file

@ -10,10 +10,10 @@ import java.util.List;
public class AttractionCoverCommand extends SubCommand { public class AttractionCoverCommand extends SubCommand {
public AttractionCoverCommand() { public AttractionCoverCommand(String cmd) {
super("themepark.admin", "attraction", "cover"); super("themepark.admin", "attraction", "cover");
addSyntax("/themepark attraction cover <id> <url>") addSyntax("/"+cmd+" attraction cover <id> <url>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.addArgument(new StringArgument()); .addArgument(new StringArgument());
} }

View file

@ -18,21 +18,21 @@ import java.util.List;
public class AttractionCreateCommand extends SubCommand { public class AttractionCreateCommand extends SubCommand {
public AttractionCreateCommand() { public AttractionCreateCommand(String cmd) {
super("themepark.admin", "attraction", "create"); super("themepark.admin", "attraction", "create");
addSyntax("/themepark attraction create <id> <region_id> <name>") addSyntax("/"+cmd+" attraction create <id> <region_id> <name>")
.addArgument(new NoAttractionArgument()) .addArgument(new NoAttractionArgument())
.addArgument(new RegionArgument()) .addArgument(new RegionArgument())
.addArgument(new MessageArgument()); .addArgument(new MessageArgument());
addSyntax("/themepark attraction create <id> <region_id> <name> <status>") addSyntax("/"+cmd+" attraction create <id> <region_id> <name> <status>")
.addArgument(new NoAttractionArgument()) .addArgument(new NoAttractionArgument())
.addArgument(new RegionArgument()) .addArgument(new RegionArgument())
.addArgument(new MessageArgument()) .addArgument(new MessageArgument())
.addArgument(new EnumArgument(Status.values())); .addArgument(new EnumArgument(Status.values()));
addSyntax("/themepark attraction create <id> <region_id> <name> <status> <url>") addSyntax("/"+cmd+" attraction create <id> <region_id> <name> <status> <url>")
.addArgument(new NoAttractionArgument()) .addArgument(new NoAttractionArgument())
.addArgument(new RegionArgument()) .addArgument(new RegionArgument())
.addArgument(new MessageArgument()) .addArgument(new MessageArgument())

View file

@ -14,18 +14,18 @@ import java.util.List;
public class AttractionListCommand extends SubCommand { public class AttractionListCommand extends SubCommand {
public AttractionListCommand() { public AttractionListCommand(String cmd) {
super("themepark.admin", "attraction", "list"); super("themepark.admin", "attraction", "list");
addSyntax("/themepark attraction list"); addSyntax("/"+cmd+" attraction list");
addSyntax("/themepark attraction list <page>") addSyntax("/"+cmd+" attraction list <page>")
.addArgument(new IntegerArgument()); .addArgument(new IntegerArgument());
addSyntax("/themepark attraction list <region>") addSyntax("/"+cmd+" attraction list <region>")
.addArgument(new RegionArgument()); .addArgument(new RegionArgument());
addSyntax("/themepark attraction list <region> <page>") addSyntax("/"+cmd+" attraction list <region> <page>")
.addArgument(new RegionArgument()) .addArgument(new RegionArgument())
.addArgument(new IntegerArgument()); .addArgument(new IntegerArgument());
} }

View file

@ -10,10 +10,10 @@ import java.util.List;
public class AttractionLocationCommand extends SubCommand { public class AttractionLocationCommand extends SubCommand {
public AttractionLocationCommand() { public AttractionLocationCommand(String cmd) {
super("themepark.admin", "attraction", "location"); super("themepark.admin", "attraction", "location");
addSyntax("/themepark attraction location <id>") addSyntax("/"+cmd+" attraction location <id>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.setAllowConsole(false); .setAllowConsole(false);
} }

View file

@ -10,10 +10,10 @@ import java.util.List;
public class AttractionNameCommand extends SubCommand { public class AttractionNameCommand extends SubCommand {
public AttractionNameCommand() { public AttractionNameCommand(String cmd) {
super("themepark.admin", "attraction", "name"); super("themepark.admin", "attraction", "name");
addSyntax("/themepark attraction name <id> <name>") addSyntax("/"+cmd+" attraction name <id> <name>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.addArgument(new MessageArgument()); .addArgument(new MessageArgument());
} }

View file

@ -11,10 +11,10 @@ import java.util.List;
public class AttractionRegionCommand extends SubCommand { public class AttractionRegionCommand extends SubCommand {
public AttractionRegionCommand() { public AttractionRegionCommand(String cmd) {
super("themepark.admin", "attraction", "region"); super("themepark.admin", "attraction", "region");
addSyntax("/themepark attraction region <attraction_id> <region_id>") addSyntax("/"+cmd+" attraction region <attraction_id> <region_id>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.addArgument(new RegionArgument()); .addArgument(new RegionArgument());
} }

View file

@ -10,10 +10,10 @@ import java.util.List;
public class AttractionRemoveCommand extends SubCommand { public class AttractionRemoveCommand extends SubCommand {
public AttractionRemoveCommand() { public AttractionRemoveCommand(String cmd) {
super("themepark.admin", "attraction", "remove"); super("themepark.admin", "attraction", "remove");
addSyntax("/themepark attraction remove <id>") addSyntax("/"+cmd+" attraction remove <id>")
.addArgument(new AttractionArgument()); .addArgument(new AttractionArgument());
} }

View file

@ -13,10 +13,10 @@ import java.util.List;
public class AttractionStatusCommand extends SubCommand { public class AttractionStatusCommand extends SubCommand {
public AttractionStatusCommand() { public AttractionStatusCommand(String cmd) {
super("themepark.admin", "attraction", "status"); super("themepark.admin", "attraction", "status");
addSyntax("/themepark attraction status <id> <status>") addSyntax("/"+cmd+" attraction status <id> <status>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.addArgument(new EnumArgument(Status.values())); .addArgument(new EnumArgument(Status.values()));
} }

View file

@ -12,10 +12,10 @@ import java.util.List;
public class AttractionWarpCommand extends SubCommand { public class AttractionWarpCommand extends SubCommand {
public AttractionWarpCommand() { public AttractionWarpCommand(String cmd) {
super(new String[]{"attraction", "warp"}); super(new String[]{"attraction", "warp"});
addSyntax("/themepark attraction warp <id>") addSyntax("/"+cmd+" attraction warp <id>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.setAllowConsole(false); .setAllowConsole(false);
} }

View file

@ -5,10 +5,10 @@ import nl.iobyte.commandapi.CommandFactory;
public class RegionCommands { public class RegionCommands {
public static void load(CommandFactory factory) { public static void load(CommandFactory factory) {
factory.addSubCommand(new RegionListCommand()) factory.addSubCommand(new RegionListCommand(factory.getName()))
.addSubCommand(new RegionCreateCommand()) .addSubCommand(new RegionCreateCommand(factory.getName()))
.addSubCommand(new RegionNameCommand()) .addSubCommand(new RegionNameCommand(factory.getName()))
.addSubCommand(new RegionRemoveCommand()); .addSubCommand(new RegionRemoveCommand(factory.getName()));
} }
} }

View file

@ -12,10 +12,10 @@ import java.util.List;
public class RegionCreateCommand extends SubCommand { public class RegionCreateCommand extends SubCommand {
public RegionCreateCommand() { public RegionCreateCommand(String cmd) {
super("themepark.admin", "region", "create"); super("themepark.admin", "region", "create");
addSyntax("/themepark region create <id> <name>") addSyntax("/"+cmd+" region create <id> <name>")
.addArgument(new NoRegionArgument()) .addArgument(new NoRegionArgument())
.addArgument(new MessageArgument()); .addArgument(new MessageArgument());
} }

View file

@ -12,12 +12,12 @@ import java.util.List;
public class RegionListCommand extends SubCommand { public class RegionListCommand extends SubCommand {
public RegionListCommand() { public RegionListCommand(String cmd) {
super("themepark.admin", "region", "list"); super("themepark.admin", "region", "list");
addSyntax("/themepark region list"); addSyntax("/"+cmd+" region list");
addSyntax("/themepark region list <page>") addSyntax("/"+cmd+" region list <page>")
.addArgument(new IntegerArgument()); .addArgument(new IntegerArgument());
} }

View file

@ -10,10 +10,10 @@ import java.util.List;
public class RegionNameCommand extends SubCommand { public class RegionNameCommand extends SubCommand {
public RegionNameCommand() { public RegionNameCommand(String cmd) {
super("themepark.admin", "region", "name"); super("themepark.admin", "region", "name");
addSyntax("/themepark region name <id> <name>") addSyntax("/"+cmd+" region name <id> <name>")
.addArgument(new RegionArgument()) .addArgument(new RegionArgument())
.addArgument(new MessageArgument()); .addArgument(new MessageArgument());
} }

View file

@ -10,10 +10,10 @@ import java.util.List;
public class RegionRemoveCommand extends SubCommand { public class RegionRemoveCommand extends SubCommand {
public RegionRemoveCommand() { public RegionRemoveCommand(String cmd) {
super("themepark.admin", "region", "remove"); super("themepark.admin", "region", "remove");
addSyntax("/themepark region remove <id>") addSyntax("/"+cmd+" region remove <id>")
.addArgument(new RegionArgument()); .addArgument(new RegionArgument());
} }

View file

@ -13,10 +13,10 @@ import java.util.List;
public class RideCountAddCommand extends SubCommand { public class RideCountAddCommand extends SubCommand {
public RideCountAddCommand() { public RideCountAddCommand(String cmd) {
super("themepark.admin", "ridecount", "add"); super("themepark.admin", "ridecount", "add");
addSyntax("/themepark ridecount add <attraction> <selector> <amount>") addSyntax("/"+cmd+" ridecount add <attraction> <selector> <amount>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.addArgument(new PlayersArgument()) .addArgument(new PlayersArgument())
.addArgument(new IntegerArgument()); .addArgument(new IntegerArgument());

View file

@ -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 <type>")
.addArgument(new EnumArgument(TotalType.values()));
}
public void onCommand(ICommandExecutor sender, List<Object> 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()));
}
}

View file

@ -5,8 +5,9 @@ import nl.iobyte.commandapi.CommandFactory;
public class RideCountCommands { public class RideCountCommands {
public static void load(CommandFactory factory) { public static void load(CommandFactory factory) {
factory.addSubCommand(new RideCountGetCommand()) factory.addSubCommand(new RideCountGetCommand(factory.getName()))
.addSubCommand(new RideCountAddCommand()); .addSubCommand(new RideCountAddCommand(factory.getName()))
.addSubCommand(new RideCountChangeTotalTypeCommand(factory.getName()));
} }
} }

View file

@ -13,10 +13,10 @@ import java.util.List;
public class RideCountGetCommand extends SubCommand { public class RideCountGetCommand extends SubCommand {
public RideCountGetCommand() { public RideCountGetCommand(String cmd) {
super("themepark.admin", "ridecount", "get"); super("themepark.admin", "ridecount", "get");
addSyntax("/themepark ridecount get <attraction> <player>") addSyntax("/"+cmd+" ridecount get <attraction> <player>")
.addArgument(new AttractionArgument()) .addArgument(new AttractionArgument())
.addArgument(new PlayerArgument()); .addArgument(new PlayerArgument());
} }

View file

@ -11,10 +11,10 @@ import java.util.List;
public class StatusColorCommand extends SubCommand { public class StatusColorCommand extends SubCommand {
public StatusColorCommand() { public StatusColorCommand(String cmd) {
super("themepark.admin", "status", "color"); super("themepark.admin", "status", "color");
addSyntax("/themepark status color <id> <color>") addSyntax("/"+cmd+" status color <id> <color>")
.addArgument(new EnumArgument(Status.values())) .addArgument(new EnumArgument(Status.values()))
.addArgument(new StringArgument()); .addArgument(new StringArgument());
} }

View file

@ -5,11 +5,11 @@ import nl.iobyte.commandapi.CommandFactory;
public class StatusCommands { public class StatusCommands {
public static void load(CommandFactory factory) { public static void load(CommandFactory factory) {
factory.addSubCommand(new StatusNameCommand()) factory.addSubCommand(new StatusNameCommand(factory.getName()))
.addSubCommand(new StatusColorCommand()) .addSubCommand(new StatusColorCommand(factory.getName()))
.addSubCommand(new StatusHexColorCommand()) .addSubCommand(new StatusHexColorCommand(factory.getName()))
.addSubCommand(new StatusMaterialCommand()) .addSubCommand(new StatusMaterialCommand(factory.getName()))
.addSubCommand(new StatusTeleportCommand()); .addSubCommand(new StatusTeleportCommand(factory.getName()));
} }
} }

View file

@ -12,10 +12,10 @@ import java.util.List;
public class StatusHexColorCommand extends SubCommand { public class StatusHexColorCommand extends SubCommand {
public StatusHexColorCommand() { public StatusHexColorCommand(String cmd) {
super("themepark.admin", "status", "hex_color"); super("themepark.admin", "status", "hex_color");
addSyntax("/themepark status hex_color <id> <color>") addSyntax("/"+cmd+" status hex_color <id> <color>")
.addArgument(new EnumArgument(Status.values())) .addArgument(new EnumArgument(Status.values()))
.addArgument(new StringArgument()); .addArgument(new StringArgument());
} }

View file

@ -11,10 +11,10 @@ import java.util.List;
public class StatusMaterialCommand extends SubCommand { public class StatusMaterialCommand extends SubCommand {
public StatusMaterialCommand() { public StatusMaterialCommand(String cmd) {
super("themepark.admin", "status", "material"); super("themepark.admin", "status", "material");
addSyntax("/themepark status material <status> <material>") addSyntax("/"+cmd+" status material <status> <material>")
.addArgument(new EnumArgument(Status.values())) .addArgument(new EnumArgument(Status.values()))
.addArgument(new MaterialArgument()); .addArgument(new MaterialArgument());
} }

View file

@ -11,10 +11,10 @@ import java.util.List;
public class StatusNameCommand extends SubCommand { public class StatusNameCommand extends SubCommand {
public StatusNameCommand() { public StatusNameCommand(String cmd) {
super("themepark.admin", "status", "name"); super("themepark.admin", "status", "name");
addSyntax("/themepark status name <id> <name>") addSyntax("/"+cmd+" status name <id> <name>")
.addArgument(new EnumArgument(Status.values())) .addArgument(new EnumArgument(Status.values()))
.addArgument(new MessageArgument()); .addArgument(new MessageArgument());
} }

View file

@ -11,10 +11,10 @@ import java.util.List;
public class StatusTeleportCommand extends SubCommand { public class StatusTeleportCommand extends SubCommand {
public StatusTeleportCommand() { public StatusTeleportCommand(String cmd) {
super("themepark.admin", "status", "teleport"); super("themepark.admin", "status", "teleport");
addSyntax("/themepark status teleport <id> <teleport>") addSyntax("/"+cmd+" status teleport <id> <teleport>")
.addArgument(new EnumArgument(Status.values())) .addArgument(new EnumArgument(Status.values()))
.addArgument(new BooleanArgument()); .addArgument(new BooleanArgument());
} }

View file

@ -6,6 +6,7 @@ import nl.iobyte.themepark.api.ThemeParkAPI;
import nl.iobyte.themepark.api.config.ConfigurationManager; import nl.iobyte.themepark.api.config.ConfigurationManager;
import nl.iobyte.themepark.api.config.enums.StorageKey; import nl.iobyte.themepark.api.config.enums.StorageKey;
import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.api.message.Text;
import nl.iobyte.themepark.api.ridecount.enums.TotalType;
import nl.iobyte.themepark.scheduler.ThemeParkScheduler; import nl.iobyte.themepark.scheduler.ThemeParkScheduler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -32,17 +33,58 @@ public class PlayerListener implements Listener {
doItem(player); doItem(player);
//Load RideCount data //Load RideCount data
TotalType type = api.getRideCountService().getType();
String query;
Map<Integer, Object> 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 calendar = new GregorianCalendar();
calendar.setTime(new Date()); 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( api.getDatabaseService().executeQueryAsync(
"local", "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=?", query,
new HashMap<>() {{ parameters
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));
}}
).setWhenSuccessful(result -> { ).setWhenSuccessful(result -> {
if(result != null) if(result != null)
for(Map<String, Object> row : result) for(Map<String, Object> row : result)

View file

@ -2,8 +2,10 @@ package nl.iobyte.themepark.listeners;
import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.ThemePark;
import nl.iobyte.themepark.api.attraction.objects.Attraction; 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.database.objects.types.SQLiteDatabase;
import nl.iobyte.themepark.api.event.ridecount.RideCountAddEvent; 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.MessageKey;
import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.api.message.Text;
import nl.iobyte.themepark.api.ridecount.objects.RideCount; 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());
}
} }

View file

@ -1,6 +1,11 @@
version: 1.2 version: 1.2
cmd: "themepark" cmd: "themepark"
ridecount_total_type: MONTHLY
update:
check: true
download: true
mysql: mysql:
enabled: false enabled: false