From 95cf389a69f7ebc4b0450122abf25b2828c7b2c1 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Wed, 22 Apr 2020 21:26:31 +0200 Subject: [PATCH] Fixed some issues --- .../themeparkplus/api/objects/Gate.java | 38 +++++++++++++++---- .../api/objects/MalfunctionReport.java | 11 ++---- .../themeparkplus/api/objects/WaitingRow.java | 3 ++ .../listeners/FastpassListeners.java | 16 ++++++-- src/main/resources/messages.yml | 2 +- 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/Gate.java b/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/Gate.java index 616fc53..e978562 100644 --- a/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/Gate.java +++ b/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/Gate.java @@ -1,13 +1,22 @@ package nl.sbdeveloper.themeparkplus.api.objects; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection; +import org.bukkit.Bukkit; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; -@Getter @Setter +import java.util.Objects; + +@Getter @Setter @NoArgsConstructor @AllArgsConstructor public class Gate { - private final Location loc; + private String world; + private int x; + private int y; + private int z; /* If max count */ private boolean hasMaxCount = false; @@ -24,8 +33,11 @@ public class Gate { * @param loc The gate location * @param direction The walking direction */ - public Gate(Location loc, WalkingDirection direction) { - this.loc = loc; + public Gate(@NotNull Location loc, WalkingDirection direction) { + this.world = Objects.requireNonNull(loc.getWorld(), "World is null!").getName(); + this.x = loc.getBlockX(); + this.y = loc.getBlockY(); + this.z = loc.getBlockZ(); this.isDirectional = true; this.direction = direction; } @@ -36,8 +48,11 @@ public class Gate { * @param loc The gate location * @param maxCount The max player count */ - public Gate(Location loc, int maxCount) { - this.loc = loc; + public Gate(@NotNull Location loc, int maxCount) { + this.world = Objects.requireNonNull(loc.getWorld(), "World is null!").getName(); + this.x = loc.getBlockX(); + this.y = loc.getBlockY(); + this.z = loc.getBlockZ(); this.hasMaxCount = true; this.maxCount = maxCount; } @@ -49,11 +64,18 @@ public class Gate { * @param maxCount The max player count * @param direction The walking direction */ - public Gate(Location loc, int maxCount, WalkingDirection direction) { - this.loc = loc; + public Gate(@NotNull Location loc, int maxCount, WalkingDirection direction) { + this.world = Objects.requireNonNull(loc.getWorld(), "World is null!").getName(); + this.x = loc.getBlockX(); + this.y = loc.getBlockY(); + this.z = loc.getBlockZ(); this.hasMaxCount = true; this.isDirectional = true; this.maxCount = maxCount; this.direction = direction; } + + public Location getLoc() { + return new Location(Bukkit.getWorld(this.world), this.x, this.y, this.z); + } } diff --git a/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java b/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java index 53d731e..4cc4fbd 100644 --- a/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java +++ b/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java @@ -1,22 +1,17 @@ package nl.sbdeveloper.themeparkplus.api.objects; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import java.time.LocalDateTime; import java.util.UUID; -@Getter @Setter +@Getter @Setter @NoArgsConstructor @AllArgsConstructor public class MalfunctionReport { private String rideID; private UUID reporterUUID; private LocalDateTime reportDate; private String reason; - - public MalfunctionReport(String rideID, UUID reporterUUID, LocalDateTime reportDate, String reason) { - this.rideID = rideID; - this.reporterUUID = reporterUUID; - this.reportDate = reportDate; - this.reason = reason; - } } diff --git a/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java b/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java index e5610e4..b67dc17 100644 --- a/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java +++ b/src/main/java/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java @@ -1,12 +1,15 @@ package nl.sbdeveloper.themeparkplus.api.objects; import com.sk89q.worldedit.regions.AbstractRegion; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import org.bukkit.Location; import java.util.ArrayList; +@NoArgsConstructor @AllArgsConstructor public class WaitingRow { @Getter @Setter private String rideID; @Getter @Setter private AbstractRegion region; diff --git a/src/main/java/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java b/src/main/java/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java index c3eaefe..92479fc 100644 --- a/src/main/java/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java +++ b/src/main/java/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java @@ -34,6 +34,9 @@ public class FastpassListeners implements Listener { Player p = e.getPlayer(); String[] lines = e.getLines(); + //Only check themeparkplus signs! + if (!lines[0].equalsIgnoreCase("[ThemeParkPlus]")) return; + if (!p.hasPermission("tpp.fastpass.create")) { p.sendMessage(ConfigUtil.getMessage("General.NoPermission")); return; @@ -49,10 +52,10 @@ public class FastpassListeners implements Listener { String sLineOne = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row1")); String sLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row2")); - if (lines[0].equalsIgnoreCase("[ThemeParkPlus]") && lines[1].equalsIgnoreCase("Machine") && !lines[2].isEmpty() && !lines[3].isEmpty()) { + if (lines[1].equalsIgnoreCase("Machine") && !lines[2].isEmpty() && !lines[3].isEmpty()) { e.setLine(0, mLineOne); e.setLine(1, mLineTwo); - } else if (lines[0].equalsIgnoreCase("[ThemeParkPlus]") && lines[1].equalsIgnoreCase("Scanner") && !lines[2].isEmpty() && !lines[3].isEmpty()) { + } else if (lines[1].equalsIgnoreCase("Scanner") && !lines[2].isEmpty() && !lines[3].isEmpty()) { e.setLine(0, sLineOne); e.setLine(1, sLineTwo); } else { @@ -132,9 +135,14 @@ public class FastpassListeners implements Listener { Attraction att = API.getAttraction(sign.getLine(2)); ItemStack content = e.getPlayer().getInventory().getItemInMainHand(); - NBTItem nbtContent = new NBTItem(content); if (content.getType() == Material.AIR - || !content.hasItemMeta() || !nbtContent.hasKey("RideID")) { + || !content.hasItemMeta()) { + e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.NoTicket")); + return; + } + + NBTItem nbtContent = new NBTItem(content); + if (!nbtContent.hasKey("RideID")) { e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.NoTicket")); return; } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 925c2ec..7beb2af 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -13,7 +13,7 @@ Gates: Closed: '&aThe gate is closed!' Fastpass: IncorrectSign: '&cThis sign is incorrect. Please read the wiki for more information.' - UnknownRide: '&cThe ride %ridename% &cdoes''nt exists.' + UnknownRide: '&cThe ride %ridename% &cdoesn''t exists.' NotEnoughMoney: '&cYou can''t pay this ticket.' AlreadyHaveTicket: '&cYou''ve already got a ticket for this ride.' Bought: '&aYou''ve successfully bought a ticket for the ride %ridename%&a. You''ve paid &f%price% &afor it.'