From 3f20b429f8e31346aa13ab94adf5be402f79f668 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Sat, 21 Nov 2020 11:29:17 +0100 Subject: [PATCH] v2.1.4 - Fixed bugs with fastpass and directional gates --- pom.xml | 4 ++-- .../themeparkplus/ThemeParkPlus.java | 2 +- .../api/enums/WalkingDirection.java | 20 +++++++---------- .../api/objects/MalfunctionReport.java | 2 +- .../listeners/FastpassListeners.java | 5 +++++ .../themeparkplus/util/DirectionUtil.java | 16 ++++++++++++++ .../themeparkplus/util/License.java | 22 ++++++++++++++----- src/main/resources/messages.yml | 1 + 8 files changed, 51 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index f164c2b..9734812 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ nl.SBDeveloper ThemeParkPlus - 2.1.3 + 2.1.4 jar ThemeParkPlus @@ -143,7 +143,7 @@ de.tr7zw item-nbt-api - 2.4.1 + 2.6.0 com.github.MilkBowl diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java index 4e2f3fa..fa23474 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java @@ -82,7 +82,7 @@ public final class ThemeParkPlus extends JavaPlugin { new License(this, "TP", config.getFile().getString("License")); if (getSConfig().getFile().getBoolean("UpdateChecker.Enabled")) { - UpdateManager updateManager = new UpdateManager(this, 7, UpdateManager.CheckType.SBDPLUGINS); + UpdateManager updateManager = new UpdateManager(this, 6, UpdateManager.CheckType.SBDPLUGINS); updateManager.handleResponse((versionResponse, version) -> { if (versionResponse == UpdateManager.VersionResponse.FOUND_NEW) { diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/enums/WalkingDirection.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/enums/WalkingDirection.java index acb3c79..a134b0f 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/enums/WalkingDirection.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/enums/WalkingDirection.java @@ -1,23 +1,19 @@ package nl.sbdeveloper.themeparkplus.api.enums; +import nl.sbdeveloper.themeparkplus.util.DirectionUtil; import org.bukkit.block.BlockFace; public enum WalkingDirection { /** - * The walking direction. Removed combinations because those can't be used in the commands. + * The walking direction. + * We can't use BlockFace here, because we only support 4 directions. */ - NORTH(BlockFace.NORTH), - EAST(BlockFace.EAST), - SOUTH(BlockFace.SOUTH), - WEST(BlockFace.WEST); - - private final BlockFace blockFace; - - WalkingDirection(BlockFace blockFace) { - this.blockFace = blockFace; - } + NORTH, + EAST, + SOUTH, + WEST; public BlockFace getBlockFace() { - return blockFace; + return DirectionUtil.convertFacing(this); } } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java index 9c17f7b..ac67429 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java @@ -8,7 +8,7 @@ import lombok.Setter; import java.time.LocalDateTime; import java.util.UUID; -/** Please don't use! It's not implemented yet. */ +/** @deprecated Please don't use! It's not implemented yet. */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class MalfunctionReport { private String rideID; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java index 6dfcd30..121b53a 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java @@ -103,6 +103,11 @@ public class FastpassListeners implements Listener { return; } + if (!nbtContent.getString("RideID").equals(att.getId())) { + e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.IncorrectTicket")); + return; + } + if (att.getStatus() != Status.OPEN && att.getStatus() != Status.ACTIVE) { e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.RideClosed")); return; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/DirectionUtil.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/DirectionUtil.java index ced196e..5305839 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/DirectionUtil.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/DirectionUtil.java @@ -1,6 +1,7 @@ package nl.sbdeveloper.themeparkplus.util; import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection; +import org.bukkit.block.BlockFace; import org.jetbrains.annotations.Nullable; public class DirectionUtil { @@ -25,4 +26,19 @@ public class DirectionUtil { } return null; } + + public static BlockFace convertFacing(WalkingDirection dir) { + switch (dir) { + case WEST: + return BlockFace.SOUTH; + case NORTH: + return BlockFace.WEST; + case EAST: + return BlockFace.NORTH; + case SOUTH: + return BlockFace.EAST; + default: + return null; + } + } } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java index 188c7fc..01eb583 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -38,9 +39,9 @@ public class License implements Listener { Written by Stijn Bannink , January 2020 */ - private JavaPlugin plugin; // The plugin instance - private String license; // The license code - private String prefix; // The correct prefix for this plugin + private final JavaPlugin plugin; // The plugin instance + private final String license; // The license code + private final String prefix; // The correct prefix for this plugin @Nullable private String invalidReason; // The reason the license is invalid, if null it's not invalid! @Nullable private static Boolean valid; // If true, it's valid, if false, it's not valid, if null it's not checked! @@ -243,16 +244,19 @@ public class License implements Listener { disable("404_error"); return null; } - BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)); String inputLine; + boolean firstLine = true; StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { + if (firstLine) { inputLine = removeUTF8BOM(inputLine); firstLine = false; } response.append(inputLine); } in.close(); JsonParser parser = new JsonParser(); - return parser.parse(response.toString()).getAsJsonObject(); + return parser.parse(response.toString().replace("´╗┐", "")).getAsJsonObject(); } private boolean checkPortValue(int input, @NotNull String dataValue) { @@ -293,6 +297,14 @@ public class License implements Listener { return false; } + private String removeUTF8BOM (String s) { + String UTF8_BOM = "\uFEFF"; + if (s.startsWith(UTF8_BOM)) { + s = s.substring(1); + } + return s; + } + /** * Check if the license is valid * diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 402fde3..8749371 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -21,6 +21,7 @@ Fastpass: Bought: '&aYou''ve successfully bought a ticket for the ride %ridename%&a. You''ve paid &f%price% &afor it.' Given: '&aYou''ve successfully given a ticket.' NoTicket: '&cYou need a fastpass ticket to go through the fastpass line.' + IncorrectTicket: '&cThis fastpass ticket is not for this ride.' RideClosed: '&cThis ride is closed.' Redeemed: '&aSuccessfully redeemed your fastpass ticket!' Lamp: