Nearly done with waitingrows!
This commit is contained in:
parent
0c53cfae5e
commit
761dd4bf30
13 changed files with 437 additions and 139 deletions
15
pom.xml
15
pom.xml
|
@ -107,7 +107,7 @@
|
|||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>>http://maven.sk89q.com/repo/</url>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<name>jcenter</name>
|
||||
|
@ -133,7 +133,13 @@
|
|||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.1.0</version>
|
||||
<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>
|
||||
|
@ -163,5 +169,10 @@
|
|||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>19.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -7,10 +7,9 @@ import nl.sbdeveloper.themeparkplus.commands.TPPCMD;
|
|||
import nl.sbdeveloper.themeparkplus.listeners.*;
|
||||
import nl.sbdeveloper.themeparkplus.managers.DBManager;
|
||||
import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager;
|
||||
import nl.sbdeveloper.themeparkplus.sbutils.YamlFile;
|
||||
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;
|
||||
|
@ -19,7 +18,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
@ -35,8 +33,6 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
private static Economy econ = null;
|
||||
private static WebhookClient webhookClient;
|
||||
|
||||
private static WEUtil weUtil;
|
||||
|
||||
private int configVersion = 2;
|
||||
|
||||
@Override
|
||||
|
@ -113,18 +109,24 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
}).check();
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ThemePark")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("ThemePark") == null) {
|
||||
Bukkit.getLogger().severe("[ThemeParkPlus] Missing ThemePark! Please install it first.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) {
|
||||
Bukkit.getLogger().severe("[ThemeParkPlus] Missing WorldEdit! Please install it first.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) {
|
||||
Bukkit.getLogger().severe("[ThemeParkPlus] Missing WorldGuard! Please install it first.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!setupEconomy()) {
|
||||
Bukkit.getLogger().severe("[ThemeParkPlus] Missing Vault! Please install it first.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
|
@ -137,6 +139,7 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
Bukkit.getLogger().info("[ThemeParkPlus] Loading listeners...");
|
||||
Bukkit.getPluginManager().registerEvents(new DirectionalGateListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new FastpassListeners(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new SignListeners(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new WaitingTimeListener(), this);
|
||||
if (getSConfig().getFile().getBoolean("AntiFreerun.Enabled")) {
|
||||
Bukkit.getPluginManager().registerEvents(new AntiFreerunListener(), this);
|
||||
|
@ -163,15 +166,7 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
}
|
||||
|
||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading Lamp & Gate util...");
|
||||
try {
|
||||
new LGUtil();
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
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();
|
||||
new LGUtil();
|
||||
|
||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading data...");
|
||||
try {
|
||||
|
@ -218,10 +213,6 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
return econ;
|
||||
}
|
||||
|
||||
public static WEUtil getWEUtil() {
|
||||
return weUtil;
|
||||
}
|
||||
|
||||
public static WebhookClient getWebhookClient() {
|
||||
return webhookClient;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package nl.sbdeveloper.themeparkplus.api;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||
|
@ -8,6 +9,7 @@ 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 nl.sbdeveloper.themeparkplus.util.WorldGuardLegacyManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
@ -114,9 +116,16 @@ public class PlusAPI {
|
|||
* @param loc The location
|
||||
* @return The row
|
||||
*/
|
||||
@NotNull
|
||||
public static Optional<WaitingRow> getRow(Location loc) {
|
||||
return rows.values().stream().filter(row -> row.getRegion().contains(BukkitAdapter.asBlockVector(loc))).findFirst();
|
||||
@Nullable
|
||||
public static WaitingRow getRow(Location loc) {
|
||||
if (loc == null) return null;
|
||||
ApplicableRegionSet set = WorldGuardLegacyManager.getInstance().getApplicableRegionSet(loc);
|
||||
for (WaitingRow row : rows.values()) {
|
||||
if (set.getRegions().stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) {
|
||||
return row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,36 +1,34 @@
|
|||
package nl.sbdeveloper.themeparkplus.api.objects;
|
||||
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
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 Region region;
|
||||
@Getter @Setter private int waitingPlayers = 0;
|
||||
@Getter @Setter private double waitingTimeMinutes = 0;
|
||||
private ArrayList<Location> signLocations = new ArrayList<>();
|
||||
@Getter @Setter private String regionID;
|
||||
@Getter @Setter private transient int waitingPlayers = 0;
|
||||
@Getter @Setter private transient double waitingTimeMinutes = 0;
|
||||
private ArrayList<SignLocation> signLocations = new ArrayList<>();
|
||||
|
||||
public WaitingRow(String rideID, Region region) {
|
||||
public WaitingRow(String rideID, String regionID) {
|
||||
this.rideID = rideID;
|
||||
this.region = region;
|
||||
this.regionID = regionID;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getSignLocations() {
|
||||
public ArrayList<SignLocation> getSignLocations() {
|
||||
return signLocations;
|
||||
}
|
||||
|
||||
public void addSignLocation(Location loc) {
|
||||
public void addSignLocation(SignLocation loc) {
|
||||
this.signLocations.add(loc);
|
||||
}
|
||||
|
||||
public void removeSignLocation(Location loc) {
|
||||
public void removeSignLocation(SignLocation loc) {
|
||||
this.signLocations.remove(loc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +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.SignLocation;
|
||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
@ -42,7 +42,7 @@ public class SignListeners implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!API.isAttraction(e.getLine(2))) {
|
||||
if (!API.isAttraction(lines[2])) {
|
||||
p.sendMessage(ConfigUtil.getMessage("Fastpass.UnknownRide", Collections.singletonMap("ridename", e.getLine(2))));
|
||||
return;
|
||||
}
|
||||
|
@ -61,15 +61,18 @@ public class SignListeners implements Listener {
|
|||
e.setLine(0, sLineOne);
|
||||
e.setLine(1, sLineTwo);
|
||||
} else if (lines[1].equalsIgnoreCase("WaitingRow") && !lines[2].isEmpty() && !lines[3].isEmpty()) {
|
||||
WaitingRow foundRow = PlusAPI.getRow(lines[2]);
|
||||
if (foundRow == null) {
|
||||
foundRow = new WaitingRow(lines[2], lines[3]);
|
||||
PlusAPI.addRow(foundRow);
|
||||
}
|
||||
foundRow.addSignLocation(SignLocation.getFromLocation(e.getBlock().getLocation()));
|
||||
ThemeParkPlus.getData().save();
|
||||
|
||||
e.setLine(0, wrLineOne);
|
||||
e.setLine(1, wrLineTwo);
|
||||
|
||||
Region selected = ThemeParkPlus.getWEUtil().getSelection(p);
|
||||
|
||||
//AND SETUP
|
||||
WaitingRow row = new WaitingRow(lines[2], selected);
|
||||
PlusAPI.addRow(row);
|
||||
ThemeParkPlus.getData().save();
|
||||
e.setLine(2, ConfigUtil.makecolored(API.getAttraction(lines[2]).getName()));
|
||||
e.setLine(3, "0 min.");
|
||||
|
||||
p.sendMessage(ConfigUtil.getMessage("WaitingRow.SignCreated"));
|
||||
} else {
|
||||
|
@ -88,7 +91,7 @@ public class SignListeners implements Listener {
|
|||
if (row.getSignLocations().size() == 1) {
|
||||
PlusAPI.removeRow(row);
|
||||
} else {
|
||||
row.getSignLocations().remove(e.getBlock().getLocation());
|
||||
row.removeSignLocation(SignLocation.getFromLocation(e.getBlock().getLocation()));
|
||||
}
|
||||
ThemeParkPlus.getData().save();
|
||||
}
|
||||
|
|
|
@ -2,66 +2,95 @@ package nl.sbdeveloper.themeparkplus.listeners;
|
|||
|
||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||
import nl.sbdeveloper.themeparkplus.api.objects.SignLocation;
|
||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WaitingTimeListener implements Listener {
|
||||
|
||||
private static final double PER_PLAYER = ThemeParkPlus.getSConfig().getFile().getDouble("WaitingRow.MinutesPerPlayer");
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(@NotNull PlayerJoinEvent e) {
|
||||
doWaitingRowThings(null, e.getPlayer().getLocation().getBlock().getLocation());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(@NotNull PlayerQuitEvent e) {
|
||||
doWaitingRowThings(e.getPlayer().getLocation().getBlock().getLocation(), null);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(@NotNull PlayerTeleportEvent e) {
|
||||
if (e.getTo() == null) return;
|
||||
if ((e.getFrom().getBlockX() != e.getTo().getBlockX())
|
||||
|| (e.getFrom().getBlockY() != e.getTo().getBlockY())
|
||||
|| (e.getFrom().getBlockZ() != e.getTo().getBlockZ())) {
|
||||
doWaitingRowThings(e.getFrom().getBlock().getLocation(), e.getTo().getBlock().getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(@NotNull PlayerMoveEvent e) {
|
||||
if (e.getTo() == null) return;
|
||||
if ((e.getFrom().getBlockX() != e.getTo().getBlockX())
|
||||
|| (e.getFrom().getBlockY() != e.getTo().getBlockY())
|
||||
|| (e.getFrom().getBlockZ() != e.getTo().getBlockZ())) {
|
||||
Optional<WaitingRow> rowOptional = PlusAPI.getRow(e.getFrom());
|
||||
Optional<WaitingRow> rowOptional2 = PlusAPI.getRow(e.getTo());
|
||||
doWaitingRowThings(e.getFrom().getBlock().getLocation(), e.getTo().getBlock().getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
WaitingRow row = null;
|
||||
int waitingNew = 0;
|
||||
double waitingTimeNew = 0;
|
||||
if (!rowOptional.isPresent() && rowOptional2.isPresent()) {
|
||||
//ENTER
|
||||
row = rowOptional2.get();
|
||||
waitingNew = row.getWaitingPlayers() + 1;
|
||||
waitingTimeNew = row.getWaitingTimeMinutes() + PER_PLAYER;
|
||||
} else if (rowOptional.isPresent() && !rowOptional2.isPresent()) {
|
||||
//LEAVE
|
||||
row = rowOptional.get();
|
||||
waitingNew = row.getWaitingPlayers() - 1;
|
||||
waitingTimeNew = row.getWaitingTimeMinutes() - PER_PLAYER;
|
||||
}
|
||||
private void doWaitingRowThings(Location from, Location to) {
|
||||
WaitingRow row = PlusAPI.getRow(from);
|
||||
WaitingRow row2 = PlusAPI.getRow(to);
|
||||
|
||||
if (row == null) return;
|
||||
WaitingRow usedRow = null;
|
||||
int waitingNew = 0;
|
||||
double waitingTimeNew = 0;
|
||||
if (row == null && row2 != null) {
|
||||
//ENTER
|
||||
usedRow = row2;
|
||||
waitingNew = row2.getWaitingPlayers() + 1;
|
||||
waitingTimeNew = row2.getWaitingTimeMinutes() + PER_PLAYER;
|
||||
} else if (row != null && row2 == null){
|
||||
//LEAVE
|
||||
usedRow = row;
|
||||
waitingNew = row.getWaitingPlayers() - 1;
|
||||
waitingTimeNew = row.getWaitingTimeMinutes() - PER_PLAYER;
|
||||
}
|
||||
|
||||
row.setWaitingPlayers(waitingNew);
|
||||
row.setWaitingTimeMinutes(waitingTimeNew);
|
||||
if (usedRow == null) return;
|
||||
|
||||
for (Location location : row.getSignLocations()) {
|
||||
Block signblock = location.getBlock();
|
||||
BlockState signblocks = signblock.getState();
|
||||
if ((signblocks instanceof Sign)) {
|
||||
Sign signs = (Sign) signblocks;
|
||||
signs.setLine(3, waitingNew + " min.");
|
||||
signs.update();
|
||||
usedRow.setWaitingPlayers(waitingNew);
|
||||
usedRow.setWaitingTimeMinutes(waitingTimeNew);
|
||||
|
||||
for (SignLocation signLocation : usedRow.getSignLocations()) {
|
||||
BlockState signblocks = signLocation.getBlock().getState();
|
||||
if (signblocks instanceof Sign) {
|
||||
Sign signs = (Sign) signblocks;
|
||||
signs.setLine(3, waitingNew + " min.");
|
||||
signs.update();
|
||||
} else {
|
||||
Bukkit.getLogger().warning(ConfigUtil.getMessage("WaitingRow.WrongLocation", Collections.singletonMap("%ridename%", usedRow.getRideID())));
|
||||
if (usedRow.getSignLocations().size() == 1) {
|
||||
PlusAPI.removeRow(usedRow);
|
||||
} else {
|
||||
Bukkit.getLogger().warning(ConfigUtil.getMessage("WaitingRow.WrongLocation", Collections.singletonMap("%ridename%", row.getRideID())));
|
||||
PlusAPI.removeRow(row);
|
||||
ThemeParkPlus.getData().save();
|
||||
usedRow.removeSignLocation(signLocation);
|
||||
}
|
||||
ThemeParkPlus.getData().save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package nl.sbdeveloper.themeparkplus.managers;
|
|||
import com.google.gson.Gson;
|
||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||
import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer;
|
||||
import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB;
|
||||
import org.bukkit.Location;
|
||||
|
@ -27,6 +28,10 @@ public class DBManager {
|
|||
String query = "CREATE TABLE IF NOT EXISTS gates (gateLocation varchar(255) NOT NULL, gateData blob NOT NULL, UNIQUE (gateLocation))";
|
||||
PreparedStatement statement = con.prepareStatement(query);
|
||||
statement.execute();
|
||||
|
||||
query = "CREATE TABLE IF NOT EXISTS rows (rideID varchar(255) NOT NULL, rowData blob NOT NULL, UNIQUE (rideID))";
|
||||
statement = con.prepareStatement(query);
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -46,11 +51,24 @@ public class DBManager {
|
|||
Gate gate = gson.fromJson(json, Gate.class);
|
||||
PlusAPI.addGate(gate);
|
||||
}
|
||||
|
||||
/* Load rows */
|
||||
query = "SELECT * FROM rows";
|
||||
statement = con.prepareStatement(query);
|
||||
ResultSet rowSet = statement.executeQuery();
|
||||
while (rowSet.next()) {
|
||||
//Loading a gates...
|
||||
byte[] blob = rowSet.getBytes("rowData");
|
||||
String json = new String(blob);
|
||||
|
||||
Gson gson = new Gson();
|
||||
WaitingRow row = gson.fromJson(json, WaitingRow.class);
|
||||
PlusAPI.addRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
for (Map.Entry<Location, Gate> entry : PlusAPI.getGates().entrySet()) {
|
||||
|
||||
Gson gson = new Gson();
|
||||
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
||||
|
||||
|
@ -72,10 +90,33 @@ public class DBManager {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, WaitingRow> entry : PlusAPI.getRows().entrySet()) {
|
||||
|
||||
Gson gson = new Gson();
|
||||
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
||||
|
||||
try {
|
||||
String query = "INSERT INTO rows (rideID, rowData) VALUES (?, ?)";
|
||||
PreparedStatement statement = con.prepareStatement(query);
|
||||
statement.setString(1, entry.getKey());
|
||||
statement.setBytes(2, blob);
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException ignored) {}
|
||||
|
||||
try {
|
||||
String query2 = "UPDATE rows SET rowData = ? WHERE rideID = ?";
|
||||
PreparedStatement statement2 = con.prepareStatement(query2);
|
||||
statement2.setBytes(1, blob);
|
||||
statement2.setString(2, entry.getKey());
|
||||
statement2.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
data.closeSource();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class LGUtil {
|
|||
private static Object lampAanData;
|
||||
private static Object lampUitData;
|
||||
|
||||
public LGUtil() throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
public LGUtil() {
|
||||
offsets.add(new Vector(1, 0, 0));
|
||||
offsets.add(new Vector(-1, 0, 0));
|
||||
offsets.add(new Vector(0, 1, 0));
|
||||
|
@ -36,16 +36,17 @@ public class LGUtil {
|
|||
offsets.add(new Vector(0, 0, 1));
|
||||
offsets.add(new Vector(0, 0, -1));
|
||||
|
||||
Class<?> blockDataClass = Class.forName("org.bukkit.block.data.BlockData");
|
||||
Method methodCreateBlockData = Bukkit.class.getMethod("createBlockData", String.class);
|
||||
getBlockDataMethod = Block.class.getMethod("getBlockData");
|
||||
setBlockDataMethod = Block.class.getMethod("setBlockData", blockDataClass,
|
||||
Boolean.TYPE);
|
||||
getAsStringMethod = blockDataClass.getMethod("getAsString");
|
||||
lampAanData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=true]");
|
||||
lampUitData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=false]");
|
||||
|
||||
nieuweVersie = true;
|
||||
try {
|
||||
Class<?> blockDataClass = Class.forName("org.bukkit.block.data.BlockData");
|
||||
Method methodCreateBlockData = Bukkit.class.getMethod("createBlockData", String.class);
|
||||
getBlockDataMethod = Block.class.getMethod("getBlockData");
|
||||
setBlockDataMethod = Block.class.getMethod("setBlockData", blockDataClass,
|
||||
Boolean.TYPE);
|
||||
getAsStringMethod = blockDataClass.getMethod("getAsString");
|
||||
lampAanData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=true]");
|
||||
lampUitData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=false]");
|
||||
nieuweVersie = true;
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {}
|
||||
}
|
||||
|
||||
public static boolean zetLampAan(Block lampBlock) {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
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,47 +0,0 @@
|
|||
package nl.sbdeveloper.themeparkplus.util;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
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 WorldEditPlugin wep;
|
||||
|
||||
public WEUtil() {
|
||||
wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,195 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ version: ${project.version}
|
|||
main: nl.sbdeveloper.themeparkplus.ThemeParkPlus
|
||||
api-version: "1.13"
|
||||
authors: [SBDeveloper]
|
||||
softdepend: [Vault, ThemePark, WorldEdit]
|
||||
softdepend: [Vault, ThemePark, WorldEdit, WorldGuard]
|
||||
description: Plus version of ThemePark!
|
||||
website: https://sbdplugins.nl
|
||||
commands:
|
||||
|
|
Reference in a new issue