Updated to ThemePark v2
This commit is contained in:
parent
8a332b4fbd
commit
73ba5bfaa9
18 changed files with 536 additions and 614 deletions
37
pom.xml
37
pom.xml
|
@ -45,7 +45,11 @@
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
||||||
<shadedPattern>nl.sbdeveloper.themeparkplus.nbtapi</shadedPattern>
|
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.nbtapi</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.codemc.worldguardwrapper</pattern>
|
||||||
|
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.worldguardwrapper</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -93,17 +97,13 @@
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>codemc-repo</id>
|
|
||||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>CodeMC</id>
|
<id>codemc-repo</id>
|
||||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>sk89q-repo</id>
|
<id>sk89q-repo</id>
|
||||||
|
@ -120,27 +120,15 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.paradoxpixel</groupId>
|
<groupId>me.paradoxpixel</groupId>
|
||||||
<artifactId>themepark</artifactId>
|
<artifactId>themepark</artifactId>
|
||||||
<version>1.4.4</version>
|
<version>2.1.1</version>
|
||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${pom.basedir}/src/lib/themepark-1.4.4.jar</systemPath>
|
<systemPath>${pom.basedir}/src/lib/themepark-2.1.1.jar</systemPath>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sk89q.worldedit</groupId>
|
|
||||||
<artifactId>worldedit-bukkit</artifactId>
|
|
||||||
<version>6.1.4-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
|
||||||
<artifactId>worldguard-legacy</artifactId>
|
|
||||||
<version>6.2</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@ -180,5 +168,10 @@
|
||||||
<version>1.7</version>
|
<version>1.7</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||||
|
<artifactId>worldguardwrapper</artifactId>
|
||||||
|
<version>1.1.9-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
Binary file not shown.
BIN
src/lib/themepark-2.1.1.jar
Normal file
BIN
src/lib/themepark-2.1.1.jar
Normal file
Binary file not shown.
|
@ -1,25 +1,21 @@
|
||||||
package nl.sbdeveloper.themeparkplus.api;
|
package nl.sbdeveloper.themeparkplus.api;
|
||||||
|
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
||||||
import nl.sbdeveloper.themeparkplus.util.WorldGuardLegacyManager;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.codemc.worldguardwrapper.WorldGuardWrapper;
|
||||||
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class PlusAPI {
|
public class PlusAPI {
|
||||||
private static HashMap<Location, Gate> gates = new HashMap<>();
|
private static HashMap<Location, Gate> gates = new HashMap<>();
|
||||||
|
@ -119,9 +115,9 @@ public class PlusAPI {
|
||||||
@Nullable
|
@Nullable
|
||||||
public static WaitingRow getRow(Location loc) {
|
public static WaitingRow getRow(Location loc) {
|
||||||
if (loc == null) return null;
|
if (loc == null) return null;
|
||||||
ApplicableRegionSet set = WorldGuardLegacyManager.getInstance().getApplicableRegionSet(loc);
|
Set<IWrappedRegion> set = WorldGuardWrapper.getInstance().getRegions(loc);
|
||||||
for (WaitingRow row : rows.values()) {
|
for (WaitingRow row : rows.values()) {
|
||||||
if (set.getRegions().stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) {
|
if (set.stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) {
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import lombok.Setter;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/** @deprecated Please don't use! It's not implemented yet. */
|
/** Please don't use! It's not implemented yet. */
|
||||||
@Getter @Setter @NoArgsConstructor @AllArgsConstructor
|
@Getter @Setter @NoArgsConstructor @AllArgsConstructor
|
||||||
public class MalfunctionReport {
|
public class MalfunctionReport {
|
||||||
private String rideID;
|
private String rideID;
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package nl.sbdeveloper.themeparkplus.api.objects;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Getter @Setter @NoArgsConstructor @AllArgsConstructor
|
|
||||||
public class SignLocation {
|
|
||||||
private String worldName;
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private int z;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static SignLocation getFromLocation(@NotNull Location in) {
|
|
||||||
return new SignLocation(Objects.requireNonNull(in.getWorld()).getName(), in.getBlockX(), in.getBlockY(), in.getBlockZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block getBlock() {
|
|
||||||
return Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -13,22 +14,22 @@ public class WaitingRow {
|
||||||
@Getter @Setter private String regionID;
|
@Getter @Setter private String regionID;
|
||||||
@Getter @Setter private transient int waitingPlayers = 0;
|
@Getter @Setter private transient int waitingPlayers = 0;
|
||||||
@Getter private transient double waitingTimeMinutes = 0;
|
@Getter private transient double waitingTimeMinutes = 0;
|
||||||
private ArrayList<SignLocation> signLocations = new ArrayList<>();
|
private ArrayList<Location> signLocations = new ArrayList<>();
|
||||||
|
|
||||||
public WaitingRow(String rideID, String regionID) {
|
public WaitingRow(String rideID, String regionID) {
|
||||||
this.rideID = rideID;
|
this.rideID = rideID;
|
||||||
this.regionID = regionID;
|
this.regionID = regionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<SignLocation> getSignLocations() {
|
public ArrayList<Location> getSignLocations() {
|
||||||
return signLocations;
|
return signLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSignLocation(SignLocation loc) {
|
public void addSignLocation(Location loc) {
|
||||||
this.signLocations.add(loc);
|
this.signLocations.add(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSignLocation(SignLocation loc) {
|
public void removeSignLocation(Location loc) {
|
||||||
this.signLocations.remove(loc);
|
this.signLocations.remove(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.sbdeveloper.themeparkplus.commands;
|
package nl.sbdeveloper.themeparkplus.commands;
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.API;
|
import nl.iobyte.themepark.api.API;
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
|
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package nl.sbdeveloper.themeparkplus.listeners;
|
package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import me.paradoxpixel.themepark.api.API;
|
import nl.iobyte.themepark.api.API;
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package nl.sbdeveloper.themeparkplus.listeners;
|
package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.API;
|
import nl.iobyte.themepark.api.API;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.SignLocation;
|
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
@ -66,7 +65,7 @@ public class SignListeners implements Listener {
|
||||||
foundRow = new WaitingRow(lines[2], lines[3]);
|
foundRow = new WaitingRow(lines[2], lines[3]);
|
||||||
PlusAPI.addRow(foundRow);
|
PlusAPI.addRow(foundRow);
|
||||||
}
|
}
|
||||||
foundRow.addSignLocation(SignLocation.getFromLocation(e.getBlock().getLocation()));
|
foundRow.addSignLocation(e.getBlock().getLocation());
|
||||||
ThemeParkPlus.getData().save();
|
ThemeParkPlus.getData().save();
|
||||||
|
|
||||||
e.setLine(0, wrLineOne);
|
e.setLine(0, wrLineOne);
|
||||||
|
@ -91,7 +90,7 @@ public class SignListeners implements Listener {
|
||||||
if (row.getSignLocations().size() == 1) {
|
if (row.getSignLocations().size() == 1) {
|
||||||
PlusAPI.removeRow(row);
|
PlusAPI.removeRow(row);
|
||||||
} else {
|
} else {
|
||||||
row.removeSignLocation(SignLocation.getFromLocation(e.getBlock().getLocation()));
|
row.removeSignLocation(e.getBlock().getLocation());
|
||||||
}
|
}
|
||||||
ThemeParkPlus.getData().save();
|
ThemeParkPlus.getData().save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
import club.minnced.discord.webhook.send.WebhookEmbed;
|
import club.minnced.discord.webhook.send.WebhookEmbed;
|
||||||
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
|
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent;
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
import nl.iobyte.themepark.api.events.attraction.ChangeStatusEvent;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -17,18 +17,18 @@ import org.jetbrains.annotations.NotNull;
|
||||||
*/
|
*/
|
||||||
public class StatusChangeListener implements Listener {
|
public class StatusChangeListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onStatusChange(@NotNull StatusChangeEvent e) {
|
public void onStatusChange(@NotNull ChangeStatusEvent e) {
|
||||||
if (e.getStatusAfter() != Status.GLOBAL) {
|
if (e.getAfter() != Status.GLOBAL) {
|
||||||
String title = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.Title");
|
String title = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.Title");
|
||||||
if (title == null) return;
|
if (title == null) return;
|
||||||
|
|
||||||
String rideName = ChatColor.stripColor(ConfigUtil.makecolored(e.getAttraction().getName()));
|
String rideName = ChatColor.stripColor(ConfigUtil.makecolored(e.getAttraction().getName()));
|
||||||
String statusAfter = ChatColor.stripColor(ConfigUtil.makecolored(StatusManager.getName(e.getStatusAfter())));
|
String statusAfter = ChatColor.stripColor(ConfigUtil.makecolored(StatusManager.getName(e.getAfter())));
|
||||||
|
|
||||||
title = title.replaceAll("%RideName%", rideName);
|
title = title.replaceAll("%RideName%", rideName);
|
||||||
String copy = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.Copyright");
|
String copy = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.Copyright");
|
||||||
String copyimg = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.CopyrightImage");
|
String copyimg = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.CopyrightImage");
|
||||||
Integer color = ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getStatusAfter().toString());
|
Integer color = ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getAfter().toString());
|
||||||
if (copy == null || copyimg == null) return;
|
if (copy == null || copyimg == null) return;
|
||||||
|
|
||||||
WebhookEmbed embed = new WebhookEmbedBuilder()
|
WebhookEmbed embed = new WebhookEmbedBuilder()
|
||||||
|
|
|
@ -2,7 +2,6 @@ package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.SignLocation;
|
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -77,7 +76,7 @@ public class WaitingTimeListener implements Listener {
|
||||||
usedRow.setWaitingPlayers(waitingNew);
|
usedRow.setWaitingPlayers(waitingNew);
|
||||||
usedRow.setWaitingTimeMinutes(waitingTimeNew);
|
usedRow.setWaitingTimeMinutes(waitingTimeNew);
|
||||||
|
|
||||||
for (SignLocation signLocation : usedRow.getSignLocations()) {
|
for (Location signLocation : usedRow.getSignLocations()) {
|
||||||
BlockState signblocks = signLocation.getBlock().getState();
|
BlockState signblocks = signLocation.getBlock().getState();
|
||||||
if (signblocks instanceof Sign) {
|
if (signblocks instanceof Sign) {
|
||||||
Sign signs = (Sign) signblocks;
|
Sign signs = (Sign) signblocks;
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package nl.sbdeveloper.themeparkplus.managers;
|
package nl.sbdeveloper.themeparkplus.managers;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer;
|
import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer;
|
||||||
import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB;
|
import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB;
|
||||||
|
import nl.sbdeveloper.themeparkplus.util.LocationGsonAdapter;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
@ -37,6 +40,11 @@ public class DBManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Gson getGson() {
|
||||||
|
return new GsonBuilder().registerTypeAdapter(Location.class, new LocationGsonAdapter()).create();
|
||||||
|
}
|
||||||
|
|
||||||
public void load() throws SQLException {
|
public void load() throws SQLException {
|
||||||
/* Load gates */
|
/* Load gates */
|
||||||
String query = "SELECT * FROM gates";
|
String query = "SELECT * FROM gates";
|
||||||
|
@ -47,7 +55,7 @@ public class DBManager {
|
||||||
byte[] blob = gateSet.getBytes("gateData");
|
byte[] blob = gateSet.getBytes("gateData");
|
||||||
String json = new String(blob);
|
String json = new String(blob);
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = getGson();
|
||||||
Gate gate = gson.fromJson(json, Gate.class);
|
Gate gate = gson.fromJson(json, Gate.class);
|
||||||
PlusAPI.addGate(gate);
|
PlusAPI.addGate(gate);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +69,7 @@ public class DBManager {
|
||||||
byte[] blob = rowSet.getBytes("rowData");
|
byte[] blob = rowSet.getBytes("rowData");
|
||||||
String json = new String(blob);
|
String json = new String(blob);
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = getGson();
|
||||||
WaitingRow row = gson.fromJson(json, WaitingRow.class);
|
WaitingRow row = gson.fromJson(json, WaitingRow.class);
|
||||||
PlusAPI.addRow(row);
|
PlusAPI.addRow(row);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +77,7 @@ public class DBManager {
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
for (Map.Entry<Location, Gate> entry : PlusAPI.getGates().entrySet()) {
|
for (Map.Entry<Location, Gate> entry : PlusAPI.getGates().entrySet()) {
|
||||||
Gson gson = new Gson();
|
Gson gson = getGson();
|
||||||
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -93,7 +101,7 @@ public class DBManager {
|
||||||
|
|
||||||
for (Map.Entry<String, WaitingRow> entry : PlusAPI.getRows().entrySet()) {
|
for (Map.Entry<String, WaitingRow> entry : PlusAPI.getRows().entrySet()) {
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = getGson();
|
||||||
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -2,9 +2,8 @@ package nl.sbdeveloper.themeparkplus.sbutils;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import javax.annotation.Nonnull;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public class LocationSerializer {
|
public class LocationSerializer {
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ public class LocationSerializer {
|
||||||
* @return The location or null if error
|
* @return The location or null if error
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Location deserialize(@Nonnull String string) {
|
public static Location deserialize(@NotNull String string) {
|
||||||
String[] split = string.split("_");
|
String[] split = string.split("_");
|
||||||
|
|
||||||
if (split.length < 4) return null;
|
if (split.length < 4) return null;
|
||||||
|
@ -37,8 +36,8 @@ public class LocationSerializer {
|
||||||
*
|
*
|
||||||
* @return The location or null if error
|
* @return The location or null if error
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@NotNull
|
||||||
public static Location deserializePY(@Nonnull String string) {
|
public static Location deserializePY(@NotNull String string) {
|
||||||
String[] split = string.split("_");
|
String[] split = string.split("_");
|
||||||
|
|
||||||
//world_x_y_z
|
//world_x_y_z
|
||||||
|
@ -60,7 +59,7 @@ public class LocationSerializer {
|
||||||
* @return The serialized string
|
* @return The serialized string
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String serialize(@Nonnull Location loc) {
|
public static String serialize(@NotNull Location loc) {
|
||||||
if (loc.getWorld() == null) return null;
|
if (loc.getWorld() == null) return null;
|
||||||
return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ();
|
return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ();
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,7 @@ public class LocationSerializer {
|
||||||
* @return The serialized string
|
* @return The serialized string
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String serializePY(@Nonnull Location loc) {
|
public static String serializePY(@NotNull Location loc) {
|
||||||
if (loc.getWorld() == null) return null;
|
if (loc.getWorld() == null) return null;
|
||||||
return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ() + "_" + loc.getYaw() + "_" + loc.getPitch();
|
return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ() + "_" + loc.getYaw() + "_" + loc.getPitch();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package nl.sbdeveloper.themeparkplus.util;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class LocationGsonAdapter extends TypeAdapter<Location> {
|
||||||
|
private static Gson g = new Gson();
|
||||||
|
|
||||||
|
private static Type seriType = new TypeToken<Map<String, Object>>(){}.getType();
|
||||||
|
|
||||||
|
private static String UUID = "uuid";
|
||||||
|
private static String X = "x";
|
||||||
|
private static String Y = "y";
|
||||||
|
private static String Z = "z";
|
||||||
|
private static String YAW = "yaw";
|
||||||
|
private static String PITCH = "pitch";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter jsonWriter, Location location) throws IOException {
|
||||||
|
if(location == null) {
|
||||||
|
jsonWriter.nullValue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
jsonWriter.value(getRaw(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location read(JsonReader jsonReader) throws IOException {
|
||||||
|
if(jsonReader.peek() == JsonToken.NULL) {
|
||||||
|
jsonReader.nextNull();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return fromRaw(jsonReader.nextString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRaw (Location location) {
|
||||||
|
Map<String, Object> serial = new HashMap<>();
|
||||||
|
serial.put(UUID, location.getWorld().getUID().toString());
|
||||||
|
serial.put(X, Double.toString(location.getX()));
|
||||||
|
serial.put(Y, Double.toString(location.getY()));
|
||||||
|
serial.put(Z, Double.toString(location.getZ()));
|
||||||
|
serial.put(YAW, Float.toString(location.getYaw()));
|
||||||
|
serial.put(PITCH, Float.toString(location.getPitch()));
|
||||||
|
return g.toJson(serial);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location fromRaw (String raw) {
|
||||||
|
Map<String, Object> keys = g.fromJson(raw, seriType);
|
||||||
|
World w = Bukkit.getWorld(java.util.UUID.fromString((String) keys.get(UUID)));
|
||||||
|
return new Location(w, Double.parseDouble((String) keys.get(X)), Double.parseDouble((String) keys.get(Y)), Double.parseDouble((String) keys.get(Z)),
|
||||||
|
Float.parseFloat((String) keys.get(YAW)), Float.parseFloat((String) keys.get(PITCH)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,38 +0,0 @@
|
||||||
package nl.sbdeveloper.themeparkplus.util;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class Reflection {
|
|
||||||
private static String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Class<?> getCraftBukkitClass(String name) {
|
|
||||||
try {
|
|
||||||
return Class.forName("org.bukkit.craftbukkit." + version + "." + name);
|
|
||||||
} catch (ClassNotFoundException var2) {
|
|
||||||
var2.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Class<?> getNMSClass(String name) {
|
|
||||||
try {
|
|
||||||
return Class.forName("net.minecraft.server." + version + "." + name);
|
|
||||||
} catch (ClassNotFoundException var2) {
|
|
||||||
var2.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Class<?> getClass(String name) {
|
|
||||||
try {
|
|
||||||
return Class.forName(name);
|
|
||||||
} catch (ClassNotFoundException var2) {
|
|
||||||
var2.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,195 +0,0 @@
|
||||||
package nl.sbdeveloper.themeparkplus.util;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
|
||||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class WorldGuardLegacyManager {
|
|
||||||
|
|
||||||
private static String wgVerStr = null;
|
|
||||||
private static WorldGuardLegacyManager instance = null;
|
|
||||||
|
|
||||||
public static WorldGuardLegacyManager getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new WorldGuardLegacyManager();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldGuardPlugin getWorldGuard() {
|
|
||||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
|
|
||||||
if (!(plugin instanceof WorldGuardPlugin)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (WorldGuardPlugin) plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldEditPlugin getWorldEdit() {
|
|
||||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
|
||||||
if (!(plugin instanceof WorldEditPlugin)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (WorldEditPlugin) plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProtectedRegion getLowerCasePlot(World w, String regionname) {
|
|
||||||
for (ProtectedRegion pr : getRegionManager(w).getRegions().values()) {
|
|
||||||
if (pr.getId().toLowerCase().equalsIgnoreCase(regionname)) {
|
|
||||||
return pr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegionManager getRegionManager(World w) {
|
|
||||||
if (getWgVer().contains("7.")) {
|
|
||||||
try {
|
|
||||||
Class<?> wgClass = Reflection.getClass("com.sk89q.worldguard.WorldGuard");
|
|
||||||
|
|
||||||
Object instance = wgClass.getDeclaredMethod("getInstance").invoke(null);
|
|
||||||
Class<?> wgInstanceClass = instance.getClass();
|
|
||||||
|
|
||||||
Object platform = wgInstanceClass.getDeclaredMethod("getPlatform").invoke(instance);
|
|
||||||
Class<?> wgPlatformClass = platform.getClass();
|
|
||||||
|
|
||||||
Object regionContainer = wgPlatformClass.getDeclaredMethod("getRegionContainer").invoke(platform);
|
|
||||||
Class<?> wgRegionContainer = regionContainer.getClass();
|
|
||||||
|
|
||||||
return (RegionManager) wgRegionContainer.getSuperclass()
|
|
||||||
.getMethod("get", com.sk89q.worldedit.world.World.class)
|
|
||||||
.invoke(regionContainer, new BukkitWorld(w));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return getWorldGuard().getRegionManager(w);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public List<ProtectedRegion> getRegions(Location loc) {
|
|
||||||
ArrayList<ProtectedRegion> regions = new ArrayList<>();
|
|
||||||
if (getWgVer().contains("7.")) {
|
|
||||||
try {
|
|
||||||
RegionManager mngr = getRegionManager(loc.getWorld());
|
|
||||||
|
|
||||||
Class<?> blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3");
|
|
||||||
|
|
||||||
Method applicableRegions = mngr.getClass().getDeclaredMethod("getApplicableRegions", blockVector3);
|
|
||||||
|
|
||||||
Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class);
|
|
||||||
Object blockVector = blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
|
|
||||||
Object regionSet = applicableRegions.invoke(mngr, blockVector);
|
|
||||||
|
|
||||||
Method getregions = regionSet.getClass().getMethod("getRegions");
|
|
||||||
|
|
||||||
regions = new ArrayList<>(((HashSet<ProtectedRegion>) getregions.invoke(regionSet)));
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
regions = new ArrayList<>(getRegionManager(loc.getWorld())
|
|
||||||
.getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ())).getRegions());
|
|
||||||
}
|
|
||||||
|
|
||||||
regions.sort(Comparator.comparing(ProtectedRegion::getPriority));
|
|
||||||
return regions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProtectedCuboidRegion getProtectedCubiodRegion(String regionname, Location loc1, Location loc2) {
|
|
||||||
if (getWgVer().contains("7.")) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
Object bvloc1 = getBlockVectorV3(loc1);
|
|
||||||
Object bvloc2 = getBlockVectorV3(loc2);
|
|
||||||
|
|
||||||
Class<?> prCbRg = Reflection.getClass("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion");
|
|
||||||
|
|
||||||
return (ProtectedCuboidRegion) prCbRg.getConstructor(String.class, bvloc1.getClass(), bvloc2.getClass())
|
|
||||||
.newInstance(regionname, bvloc1, bvloc2);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return new ProtectedCuboidRegion(regionname,
|
|
||||||
new com.sk89q.worldedit.BlockVector(loc1.getX(), loc1.getY(), loc1.getZ()),
|
|
||||||
new com.sk89q.worldedit.BlockVector(loc2.getX(), loc2.getY(), loc2.getZ()));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getBlockVectorV3(@NotNull Location loc) throws Exception {
|
|
||||||
Class<?> blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3");
|
|
||||||
|
|
||||||
Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class);
|
|
||||||
return blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlagRegistry getFlagRegistry() {
|
|
||||||
if (getWgVer().contains("7.")) {
|
|
||||||
try {
|
|
||||||
Class<?> wgClass = Reflection.getClass("com.sk89q.worldguard.WorldGuard");
|
|
||||||
|
|
||||||
Object instance = wgClass.getDeclaredMethod("getInstance").invoke(null);
|
|
||||||
Class<?> wgInstanceClass = instance.getClass();
|
|
||||||
Method declaredMethod = wgInstanceClass.getDeclaredMethod("getFlagRegistry");
|
|
||||||
return (FlagRegistry) declaredMethod.invoke(instance);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return getWorldGuard().getFlagRegistry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicableRegionSet getApplicableRegionSet(Location loc) {
|
|
||||||
if (getWgVer().contains("7.")) {
|
|
||||||
try {
|
|
||||||
RegionManager mngr = getRegionManager(loc.getWorld());
|
|
||||||
|
|
||||||
Class<?> blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3");
|
|
||||||
|
|
||||||
Method applicableRegions = mngr.getClass().getDeclaredMethod("getApplicableRegions", blockVector3);
|
|
||||||
|
|
||||||
Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class);
|
|
||||||
Object blockVector = blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
|
|
||||||
Object regionSet = applicableRegions.invoke(mngr, blockVector);
|
|
||||||
|
|
||||||
return (ApplicableRegionSet) regionSet;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return getRegionManager(loc.getWorld()).getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getWgVer() {
|
|
||||||
if (wgVerStr == null) {
|
|
||||||
wgVerStr = Bukkit.getPluginManager().getPlugin("WorldGuard").getDescription().getVersion();
|
|
||||||
}
|
|
||||||
return wgVerStr;
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
Reference in a new issue