diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 3912626..13aded2 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 nl.iobyte themeparkconnector - 3.1.0 + 3.1.1 clean package diff --git a/pom.xml b/pom.xml index 452f185..485069d 100755 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ nl.iobyte themeparkconnector - 3.1.0 + 3.1.1 diff --git a/src/main/java/nl/iobyte/themeparkconnector/api/show/ShowService.java b/src/main/java/nl/iobyte/themeparkconnector/api/show/ShowService.java index eb6cdaf..5ed7f9d 100755 --- a/src/main/java/nl/iobyte/themeparkconnector/api/show/ShowService.java +++ b/src/main/java/nl/iobyte/themeparkconnector/api/show/ShowService.java @@ -25,6 +25,10 @@ public class ShowService { if(uuid == null || voucher == null) return "Invalid parameters"; + Player player = Bukkit.getPlayer(uuid); + if(player == null) + return "Invalid player"; + try { ArrayList> resultSet = ThemePark.getInstance().getAPI().getDatabaseService().executeQuery( "remote", @@ -93,7 +97,6 @@ public class ShowService { NBTCompound compound = item.addCompound("data"); compound.setString("ticket", g.toJson(ticket, Ticket.class)); - Player player = Bukkit.getPlayer(uuid); player.getInventory().addItem(item.getItem()); return "true"; } catch(Exception e) { diff --git a/src/main/java/nl/iobyte/themeparkconnector/commands/ThemeParkConnectorCommand.java b/src/main/java/nl/iobyte/themeparkconnector/commands/ThemeParkConnectorCommand.java index 4f1bfc8..5659e9c 100755 --- a/src/main/java/nl/iobyte/themeparkconnector/commands/ThemeParkConnectorCommand.java +++ b/src/main/java/nl/iobyte/themeparkconnector/commands/ThemeParkConnectorCommand.java @@ -10,17 +10,20 @@ import nl.iobyte.themeparkconnector.commands.subcommands.*; import nl.iobyte.themeparkconnector.commands.subcommands.operator.OperatorCommands; import org.bukkit.entity.Player; +import java.util.Objects; + public class ThemeParkConnectorCommand { //Load command data public ThemeParkConnectorCommand() { CommandFactory factory = new CommandFactory("themeparkconnector"); factory.addSubCommand(new HelpCommand(factory)) - .addSubCommand(new ConnectCommand()); + .addSubCommand(new ConnectCommand()) + .addSubCommand(new VoucherCommand()); //Admin factory.addSubCommand(new StatusCommand()) - .addSubCommand(new NotificationCommand()) + .addSubCommand(new VoucherCommand()) .addSubCommand(new DisconnectCommand()); //Operator @@ -30,7 +33,7 @@ public class ThemeParkConnectorCommand { factory.addMiddleware(new PermissionMiddleware()); //Register command - ThemeParkConnector.getInstance().getCommand(factory.getName()).setExecutor((sender, command, s, args) -> { + Objects.requireNonNull(ThemeParkConnector.getInstance().getCommand(factory.getName())).setExecutor((sender, command, s, args) -> { ICommandExecutor executor = new ConsoleExecutor(sender); if(sender instanceof Player) executor = new PlayerExecutor((Player) sender); diff --git a/src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/VoucherCommand.java b/src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/VoucherCommand.java new file mode 100755 index 0000000..bf6e848 --- /dev/null +++ b/src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/VoucherCommand.java @@ -0,0 +1,39 @@ +package nl.iobyte.themeparkconnector.commands.subcommands; + +import nl.iobyte.commandapi.arguments.StringArgument; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; +import nl.iobyte.themeparkconnector.ThemeParkConnector; +import nl.iobyte.themeparkconnector.api.message.Text; +import org.bukkit.entity.Player; + +import java.util.List; + +public class VoucherCommand extends SubCommand { + + public VoucherCommand() { + super(new String[]{"redeem"}); + + addSyntax("/themeparkconnector redeem ") + .addArgument(new StringArgument()) + .setAllowConsole(false); + } + + //Get Token and redeem ticket + public void onCommand(ICommandExecutor sender, List objects, int i) { + String voucher = (String) objects.get(0); + + String result = ThemeParkConnector.getInstance().getAPI().getShowService().redeemTicket( + ((Player) sender.getOriginal()).getUniqueId(), + voucher + ); + if(result.equals("true")) { + sender.sendMessage(Text.color("&6Redeemed ticket with voucher: &L&f"+voucher)); + return; + } + + ThemeParkConnector.getInstance().getLogger().warning(result); + sender.sendMessage(Text.color("&4Invalid voucher: &L&f"+voucher)); + } + +} diff --git a/src/main/java/nl/iobyte/themeparkconnector/listeners/TicketListener.java b/src/main/java/nl/iobyte/themeparkconnector/listeners/TicketListener.java index 15b7f74..9d9e2e6 100755 --- a/src/main/java/nl/iobyte/themeparkconnector/listeners/TicketListener.java +++ b/src/main/java/nl/iobyte/themeparkconnector/listeners/TicketListener.java @@ -25,6 +25,7 @@ import org.bukkit.inventory.ItemStack; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Objects; public class TicketListener implements Listener { @@ -50,7 +51,7 @@ public class TicketListener implements Listener { } String date = e.getLine(2); - if(isValidFormat("HH:mm", date) && isValidFormat("HH:mm dd-MM-yyyy", date)) { + if(isInvalidFormat("HH:mm", date) && isInvalidFormat("HH:mm dd-MM-yyyy", date)) { player.sendMessage(Text.color("&4Can't make a TicketScanner with incorrect date, example: 20:00 or 20:00 04-04-2019")); return; } @@ -88,24 +89,24 @@ public class TicketListener implements Listener { } String id = ChatColor.stripColor(sign.getLine(1)); - if(id == null || id.isEmpty()) + if(id.isEmpty()) return; String date = ChatColor.stripColor(sign.getLine(2)); - if(date == null || date.isEmpty()) + if(date.isEmpty()) return; - if(isValidFormat("HH:mm", date) && isValidFormat("HH:mm dd-MM-yyyy", date)) { - System.out.println("Invalid date format"); + if(isInvalidFormat("HH:mm", date) && isInvalidFormat("HH:mm dd-MM-yyyy", date)) { + ThemeParkConnector.getInstance().getLogger().warning("Invalid date format"); return; } - if(isValidFormat("HH:mm dd-MM-yyyy", date)) + if(isInvalidFormat("HH:mm dd-MM-yyyy", date)) date = date + " " + format.format(new Date()); - Location location = LocationUtil.fromString(sign.getLocation().getWorld().getName() + ":" + sign.getLine(3)); + Location location = LocationUtil.fromString(Objects.requireNonNull(sign.getLocation().getWorld()).getName() + ":" + sign.getLine(3)); if(location == null) { - System.out.println("Invalid Location"); + ThemeParkConnector.getInstance().getLogger().warning("Invalid Location"); return; } @@ -118,30 +119,30 @@ public class TicketListener implements Listener { NBTItem it = new NBTItem(item); if(!it.hasKey("data")) { - System.out.println("Missing data key"); + ThemeParkConnector.getInstance().getLogger().warning("Missing data key"); return; } NBTCompound compound = it.getCompound("data"); if(!compound.hasKey("ticket")) { - System.out.println("Missing ticket key"); + ThemeParkConnector.getInstance().getLogger().warning("Missing ticket key"); return; } Gson g = new Gson(); Ticket ticket = g.fromJson(it.getCompound("data").getString("ticket"), Ticket.class); if(ticket == null) { - System.out.println("Couldn't get ticket class using Gson"); + ThemeParkConnector.getInstance().getLogger().warning("Couldn't get ticket class using Gson"); return; } if(!id.equals(ticket.getShowID())) { - System.out.println("Different show id"); + ThemeParkConnector.getInstance().getLogger().warning("Different show id"); return; } if(!date.equals(new SimpleDateFormat("HH:mm dd-MM-yyyy").format(ticket.getShowDate()))) { - System.out.println("Different date"); + ThemeParkConnector.getInstance().getLogger().warning("Different date"); return; } @@ -152,7 +153,7 @@ public class TicketListener implements Listener { Bukkit.getPluginManager().callEvent(event); int i = player.getInventory().getHeldItemSlot(); - player.getInventory().remove(player.getInventory().getItem(i)); + player.getInventory().remove(Objects.requireNonNull(player.getInventory().getItem(i))); if(!b) { player.sendMessage(Text.color("&4Invalid ticket.")); return; @@ -161,10 +162,10 @@ public class TicketListener implements Listener { if(!event.isCancelled()) player.teleport(location); - player.sendMessage(Text.color("&6Used ticket for Show: " + item.getItemMeta().getDisplayName())); + player.sendMessage(Text.color("&6Used ticket for Show: " + Objects.requireNonNull(item.getItemMeta()).getDisplayName())); } - private static boolean isValidFormat(String format, String value) { + private static boolean isInvalidFormat(String format, String value) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); Date date = sdf.parse(value); diff --git a/src/main/resources/message.yml b/src/main/resources/message.yml index e137e3b..feac1ba 100755 --- a/src/main/resources/message.yml +++ b/src/main/resources/message.yml @@ -1,4 +1,4 @@ -version: 1.0 +version: 1.1 prefix: '&6&lThemeParkConnectorMC &r&f➢' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 48e4376..04068bc 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemeParkConnector -version: 3.0.2 +version: ${project.version} author: IOByte website: 'https://www.iobyte.nl' main: nl.iobyte.themeparkconnector.ThemeParkConnector