ADD: voucher command
This commit is contained in:
parent
559ae95fed
commit
9e9ce74c55
8 changed files with 70 additions and 24 deletions
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>nl.iobyte</groupId>
|
||||
<artifactId>themeparkconnector</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.1</version>
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<resources>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>nl.iobyte</groupId>
|
||||
<artifactId>themeparkconnector</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.1</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
|
|
|
@ -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<Map<String, Object>> 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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 <voucher>")
|
||||
.addArgument(new StringArgument())
|
||||
.setAllowConsole(false);
|
||||
}
|
||||
|
||||
//Get Token and redeem ticket
|
||||
public void onCommand(ICommandExecutor sender, List<Object> 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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
version: 1.0
|
||||
version: 1.1
|
||||
|
||||
prefix: '&6&lThemeParkConnectorMC &r&f➢'
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue