diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java index 0fe4120..dd312b5 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java @@ -13,6 +13,7 @@ import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager; import nl.sbdeveloper.themeparkplus.util.LGUtil; import nl.sbdeveloper.themeparkplus.util.License; import nl.sbdeveloper.themeparkplus.sbutils.YamlFile; +import nl.sbdeveloper.themeparkplus.util.WEUtil; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.RegisteredServiceProvider; @@ -37,6 +38,8 @@ public final class ThemeParkPlus extends JavaPlugin { private static Economy econ = null; private static WebhookClient webhookClient; + private static WEUtil weUtil; + private int configVersion = 2; @Override @@ -161,14 +164,17 @@ public final class ThemeParkPlus extends JavaPlugin { } } - Bukkit.getLogger().info("[ThemeParkPlus] Loading Lamp & Gate utils..."); + Bukkit.getLogger().info("[ThemeParkPlus] Loading Lamp & Gate util..."); try { new LGUtil(); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); - Bukkit.getLogger().severe("[ThemeParkPlus] Couldn't find classes for Lamp & Gate util. The plugin won't work as intended."); + Bukkit.getLogger().severe("[ThemeParkPlus] Lamp & Gate util not compatible with your Spigot version. The plugin won't work as intended."); } + Bukkit.getLogger().info("[ThemeParkPlus] Loading WorldEdit util..."); + weUtil = new WEUtil(); + Bukkit.getLogger().info("[ThemeParkPlus] Loading data..."); try { data.load(); @@ -214,6 +220,10 @@ public final class ThemeParkPlus extends JavaPlugin { return econ; } + public static WEUtil getWEUtil() { + return weUtil; + } + public static WebhookClient getWebhookClient() { return webhookClient; } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java index e7c94f2..b791758 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java @@ -4,6 +4,7 @@ import de.tr7zw.changeme.nbtapi.NBTItem; import me.paradoxpixel.themepark.api.attraction.Attraction; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.api.objects.Gate; +import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.XMaterial; import org.bukkit.Location; @@ -18,6 +19,7 @@ import java.util.List; public class PlusAPI { private static HashMap gates = new HashMap<>(); + private static HashMap rows = new HashMap<>(); /** * Add a gate @@ -66,6 +68,53 @@ public class PlusAPI { return gates; } + /** + * Add a row + * + * @param row The row + */ + public static void addRow(WaitingRow row) { + rows.put(row.getRideID(), row); + } + + /** + * Remove a row + * + * @param row The row + */ + public static void removeRow(@NotNull WaitingRow row) { + rows.remove(row.getRideID()); + } + + /** + * Check if a location is a row + * + * @param rideID The rideID + * @return true/false + */ + public static boolean isRow(String rideID) { + return rows.containsKey(rideID); + } + + /** + * Get a row by the location + * + * @param rideID The rideID + * @return The row + */ + public static WaitingRow getRow(String rideID) { + return rows.get(rideID); + } + + /** + * Get all the rows + * + * @return Map with location and rows + */ + public static HashMap getRows() { + return rows; + } + /** * Get the ticket itemstack * diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java index f1767d2..13105a4 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java @@ -1,7 +1,5 @@ package nl.sbdeveloper.themeparkplus.api.objects; -import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection; -import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.Region; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java index 53d86ac..8ddb12f 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java @@ -230,6 +230,7 @@ public class TPPCMD implements CommandExecutor { if (gate != null) { PlusAPI.addGate(gate); + ThemeParkPlus.getData().save(); } Block b = loc.getBlock(); @@ -268,6 +269,7 @@ public class TPPCMD implements CommandExecutor { Gate gate = PlusAPI.getGate(loc); if (gate != null) { PlusAPI.removeGate(gate); + ThemeParkPlus.getData().save(); } if (!LGUtil.isOpen(b)) { diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/DirectionalGateListener.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/DirectionalGateListener.java index 119619a..9b37f26 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/DirectionalGateListener.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/DirectionalGateListener.java @@ -1,5 +1,6 @@ package nl.sbdeveloper.themeparkplus.listeners; +import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection; import nl.sbdeveloper.themeparkplus.api.objects.Gate; @@ -38,9 +39,11 @@ public class DirectionalGateListener implements Listener { LGUtil.closeGate(oldBlock); } else { PlusAPI.removeGate(gate); + ThemeParkPlus.getData().save(); return; } PlusAPI.removeGate(gate); + ThemeParkPlus.getData().save(); } else { gate.setPassedCount(gate.getPassedCount() + 1); } @@ -60,9 +63,11 @@ public class DirectionalGateListener implements Listener { LGUtil.closeGate(oldBlock); } else { PlusAPI.removeGate(gate); + ThemeParkPlus.getData().save(); return; } PlusAPI.removeGate(gate); + ThemeParkPlus.getData().save(); } else { gate.setPassedCount(gate.getPassedCount() + 1); } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java index 19d79e4..008b9b1 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java @@ -1,7 +1,9 @@ package nl.sbdeveloper.themeparkplus.listeners; +import com.sk89q.worldedit.regions.Region; import me.paradoxpixel.themepark.api.API; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; +import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import org.bukkit.entity.Player; @@ -58,8 +60,12 @@ public class SignListeners implements Listener { e.setLine(0, wrLineOne); e.setLine(1, wrLineTwo); + Region selected = ThemeParkPlus.getWEUtil().getSelection(p); + //AND SETUP - WaitingRow row = new WaitingRow(); + WaitingRow row = new WaitingRow(lines[2], selected); + PlusAPI.addRow(row); + ThemeParkPlus.getData().save(); p.sendMessage(ConfigUtil.getMessage("WaitingRow.SignCreated")); } else { diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/WEUtil.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/WEUtil.java index a70c7fb..b5a44cd 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/WEUtil.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/WEUtil.java @@ -2,49 +2,44 @@ package nl.sbdeveloper.themeparkplus.util; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection; -import com.sk89q.worldedit.bukkit.selections.Selection; -import com.sk89q.worldedit.regions.Polygonal2DRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.regions.RegionSelector; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; public class WEUtil { - private static boolean newVersion; private static WorldEditPlugin wep; public WEUtil() { - newVersion = XMaterial.isNewVersion(); wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); } @Nullable - public static Region getSelection(Player p) { - if (newVersion) { - LocalSession l = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(p)); - Region s; - try { - s = l.getSelection(l.getSelectionWorld()); - } catch (IncompleteRegionException e) { - return null; - } - if (s instanceof Polygonal2DSelection) { - Polygonal2DSelection polySel = (Polygonal2DSelection) s; - int minY = polySel.getNativeMinimumPoint().getBlockY(); - int maxY = polySel.getNativeMaximumPoint().getBlockY(); - return new Polygonal2DRegion((World) polySel.getWorld(), polySel.getNativePoints(), minY, maxY); - } - } else { - Selection sel = wep.getSelection(p); - if (sel instanceof Polygonal2DSelection) { - Polygonal2DSelection polySel = (Polygonal2DSelection) sel; - int minY = polySel.getNativeMinimumPoint().getBlockY(); - int maxY = polySel.getNativeMaximumPoint().getBlockY(); - return new Polygonal2DRegion((World) polySel.getWorld(), polySel.getNativePoints(), minY, maxY); + public Region getSelection(Player p) { + LocalSession session; + try { + session = wep.getSession(p); + } catch (Exception e) { + // sometimes after a reload getSession create errors with WorldEdit, this prevent error spam + return null; + } + + return getSelectedRegion(session); + } + + @Nullable + private Region getSelectedRegion(@Nullable LocalSession session) { + if (session != null && session.getSelectionWorld() != null) { + RegionSelector selector = session.getRegionSelector(session.getSelectionWorld()); + + if (selector.isDefined()) { + try { + return selector.getRegion(); + } catch (IncompleteRegionException e) { + Bukkit.getLogger().warning("[ThemeParkPlus] Region still incomplete"); + } } } return null;