3
0
Fork 0

Fixed gate direction, webhook issues, and more

This commit is contained in:
SBDeveloper 2022-09-02 20:23:35 +02:00
parent fb8cad6584
commit a2473b1189
20 changed files with 523 additions and 2751 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
.idea .idea
*.iml *.iml
target/

97
pom.xml
View file

@ -58,37 +58,32 @@
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.smartinvs</shadedPattern> <shadedPattern>nl.sbdeveloper.themeparkplus.libs.smartinvs</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>com/cryptomorin/xseries/XPotion*</exclude>
<exclude>com/cryptomorin/xseries/XItemStack*</exclude>
<exclude>com/cryptomorin/xseries/XEntity*</exclude>
<exclude>com/cryptomorin/xseries/XEnchantment*</exclude>
<exclude>com/cryptomorin/xseries/XBlock*</exclude>
<exclude>com/cryptomorin/xseries/XBiome*</exclude>
<exclude>com/cryptomorin/xseries/XMaterial*</exclude>
<exclude>com/cryptomorin/xseries/XSound*</exclude>
<exclude>com/cryptomorin/xseries/XTag*</exclude>
<exclude>com/cryptomorin/xseries/SkullUtils*</exclude>
<exclude>com/cryptomorin/xseries/NoteBlockMusic*</exclude>
<exclude>com/cryptomorin/xseries/particles/*</exclude>
<exclude>com/cryptomorin/xseries/messages/*</exclude>
<exclude>com/cryptomorin/xseries/unused/*</exclude>
<exclude>com/cryptomorin/xseries/SkullCacheListener*</exclude>
</excludes>
</filter>
</filters>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- &lt;!&ndash; Delombok the source for the javadoc &ndash;&gt;-->
<!-- <plugin>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok-maven-plugin</artifactId>-->
<!-- <version>1.18.12.0</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <phase>generate-sources</phase>-->
<!-- <goals>-->
<!-- <goal>delombok</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- &lt;!&ndash; Build the javadoc &ndash;&gt;-->
<!-- <plugin>-->
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
<!-- <version>3.2.0</version>-->
<!-- <configuration>-->
<!-- <release>11</release>-->
<!-- <sourceFileIncludes>-->
<!-- <include>nl/sbdeveloper/themeparkplus/api/*.java</include>-->
<!-- <include>nl/sbdeveloper/themeparkplus/api/enums/*.java</include>-->
<!-- <include>nl/sbdeveloper/themeparkplus/api/objects/*.java</include>-->
<!-- </sourceFileIncludes>-->
<!-- </configuration>-->
<!-- </plugin>-->
</plugins> </plugins>
<resources> <resources>
<resource> <resource>
@ -107,21 +102,26 @@
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
</repository> </repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository> <repository>
<id>sk89q-repo</id> <id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url> <url>https://maven.enginehub.org/repo/</url>
</repository> </repository>
<repository>
<id>enginehub-maven</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
<layout>default</layout>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version> <version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -141,13 +141,13 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.22</version> <version>1.18.24</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>de.tr7zw</groupId> <groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId> <artifactId>item-nbt-api</artifactId>
<version>2.9.2</version> <version>2.10.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.MilkBowl</groupId> <groupId>com.github.MilkBowl</groupId>
@ -163,18 +163,35 @@
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId> <artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version> <version>3.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>fr.minuskube.inv</groupId> <groupId>fr.minuskube.inv</groupId>
<artifactId>smart-invs</artifactId> <artifactId>smart-invs</artifactId>
<version>1.2.7</version> <version>1.2.7</version>
</dependency> </dependency>
<dependency>
<groupId>club.minnced</groupId>
<artifactId>discord-webhooks</artifactId>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.0.0</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.7-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -1,5 +1,7 @@
package nl.sbdeveloper.themeparkplus; package nl.sbdeveloper.themeparkplus;
import club.minnced.discord.webhook.WebhookClient;
import club.minnced.discord.webhook.WebhookClientBuilder;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import nl.sbdeveloper.themeparkplus.commands.TPPCMD; import nl.sbdeveloper.themeparkplus.commands.TPPCMD;
import nl.sbdeveloper.themeparkplus.listeners.*; import nl.sbdeveloper.themeparkplus.listeners.*;
@ -10,16 +12,10 @@ import nl.sbdeveloper.themeparkplus.sbutils.YamlFile;
import nl.sbdeveloper.themeparkplus.util.Inventory; import nl.sbdeveloper.themeparkplus.util.Inventory;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap;
import java.util.Objects;
public final class ThemeParkPlus extends JavaPlugin { public final class ThemeParkPlus extends JavaPlugin {
private static ThemeParkPlus instance; private static ThemeParkPlus instance;
@ -28,9 +24,7 @@ public final class ThemeParkPlus extends JavaPlugin {
private static YamlFile messages; private static YamlFile messages;
private static Economy econ = null; private static Economy econ = null;
private static String webhookURL; private static WebhookClient webhookClient;
private final int configVersion = 3;
private static boolean hasParkHook = false; private static boolean hasParkHook = false;
@ -38,13 +32,13 @@ public final class ThemeParkPlus extends JavaPlugin {
public void onEnable() { public void onEnable() {
instance = this; instance = this;
Bukkit.getLogger().info("[ThemeParkPlus] -------------------------------"); getLogger().info("-------------------------------");
Bukkit.getLogger().info("[ThemeParkPlus] ThemeParkPlus v" + this.getDescription().getVersion()); getLogger().info("ThemeParkPlus v" + this.getDescription().getVersion());
Bukkit.getLogger().info("[ThemeParkPlus] Made by SBDeveloper"); getLogger().info("Made by SBDeveloper");
Bukkit.getLogger().info("[ThemeParkPlus] "); getLogger().info(" ");
Bukkit.getLogger().info("[ThemeParkPlus] Loading Files..."); getLogger().info("Loading Files...");
config = new YamlFile("config"); config = new YamlFile("config");
config.loadDefaults(); config.loadDefaults();
@ -54,22 +48,6 @@ public final class ThemeParkPlus extends JavaPlugin {
messages = new YamlFile("messages"); messages = new YamlFile("messages");
messages.loadDefaults(); messages.loadDefaults();
Reader defConfigStream = new InputStreamReader(Objects.requireNonNull(getResource("config.yml")), StandardCharsets.UTF_8);
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
config.getFile().setDefaults(defConfig);
config.getFile().options().copyDefaults(true);
config.saveFile();
if (!config.getFile().contains("Version") || Objects.equals(config.getFile().getString("Version"), "")) {
config.getFile().set("Version", configVersion);
config.saveFile();
}
if (!Objects.equals(config.getFile().getString("Version"), String.valueOf(configVersion))) {
Bukkit.getLogger().info("[ThemeParkPlus] Updating outdated config...");
updateConfig();
}
getLogger().info("This copy is bought by %%__USERNAME__%% (%%__USER__%%)."); getLogger().info("This copy is bought by %%__USERNAME__%% (%%__USER__%%).");
getLogger().info("Validating your purchase..."); getLogger().info("Validating your purchase...");
Verify v = new Verify(this); Verify v = new Verify(this);
@ -78,27 +56,27 @@ public final class ThemeParkPlus extends JavaPlugin {
} }
if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) { if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) {
Bukkit.getLogger().severe("[ThemeParkPlus] Missing WorldEdit! Please install it first."); getLogger().severe("Missing WorldEdit! Please install it first.");
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
} }
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) { if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) {
Bukkit.getLogger().severe("[ThemeParkPlus] Missing WorldGuard! Please install it first."); getLogger().severe("Missing WorldGuard! Please install it first.");
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
} }
if (!setupEconomy()) { if (!setupEconomy()) {
Bukkit.getLogger().severe("[ThemeParkPlus] Missing Vault! Please install it first."); getLogger().severe("Missing Vault! Please install it first.");
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
} }
Bukkit.getLogger().info("[ThemeParkPlus] Loading commands..."); getLogger().info("Loading commands...");
getCommand("themeparkplus").setExecutor(new TPPCMD()); getCommand("themeparkplus").setExecutor(new TPPCMD());
Bukkit.getLogger().info("[ThemeParkPlus] Loading listeners..."); getLogger().info("Loading listeners...");
Bukkit.getPluginManager().registerEvents(new DirectionalGateListener(), this); Bukkit.getPluginManager().registerEvents(new DirectionalGateListener(), this);
Bukkit.getPluginManager().registerEvents(new SignListeners(), this); Bukkit.getPluginManager().registerEvents(new SignListeners(), this);
Bukkit.getPluginManager().registerEvents(new WaitingTimeListener(), this); Bukkit.getPluginManager().registerEvents(new WaitingTimeListener(), this);
@ -125,77 +103,67 @@ public final class ThemeParkPlus extends JavaPlugin {
if (URL != null) { if (URL != null) {
Bukkit.getPluginManager().registerEvents(new StatusChangeListener(), this); Bukkit.getPluginManager().registerEvents(new StatusChangeListener(), this);
Bukkit.getLogger().info("[ThemeParkPlus] Loading Discord webhook..."); getLogger().info("Loading Discord webhook...");
webhookURL = URL; WebhookClientBuilder builder = new WebhookClientBuilder(URL);
builder.setThreadFactory(job -> {
Thread thread = new Thread(job);
thread.setName("ThemeParkPlus");
thread.setDaemon(true);
return thread;
});
builder.setWait(true);
webhookClient = builder.build();
} else { } else {
Bukkit.getLogger().severe("[ThemeParkPlus] Couldn't load the webhook builder! The URL is null."); getLogger().severe("Couldn't load the webhook builder! The URL is null.");
} }
} }
} }
Bukkit.getLogger().info("[ThemeParkPlus] Loading GUI helper..."); getLogger().info("Loading GUI helper...");
Inventory.init(this); Inventory.init(this);
Bukkit.getLogger().info("[ThemeParkPlus] Loading data..."); getLogger().info("Loading data...");
try { try {
data.load(); data.load();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
Bukkit.getLogger().severe("[ThemeParkPlus] Couldn't load data! Something went wrong.");
} }
Bukkit.getLogger().info("[ThemeParkPlus] Loading metrics (can be disabled in the config of bStats)..."); getLogger().info("Loading metrics (can be disabled in the config of bStats)...");
new Metrics(this, 5023); new Metrics(this, 5023);
if (getSConfig().getFile().getBoolean("UpdateChecker.Enabled")) { if (getSConfig().getFile().getBoolean("UpdateChecker")) {
UpdateManager updateManager = new UpdateManager(this, UpdateManager.CheckType.POLYMART_PAID); UpdateManager updateManager = new UpdateManager(this, UpdateManager.CheckType.POLYMART_PAID);
updateManager.handleResponse((versionResponse, version) -> { updateManager.handleResponse((versionResponse, version) -> {
switch (versionResponse) { switch (versionResponse) {
case FOUND_NEW: case FOUND_NEW:
Bukkit.getLogger().warning("[ThemeParkPlus] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version.get()); getLogger().warning("There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version.get());
if (getSConfig().getFile().getBoolean("UpdateChecker.DownloadOnUpdate")) {
Bukkit.getLogger().info("[ThemeParkPlus] Trying to download the update. This could take some time...");
updateManager.handleDownloadResponse((downloadResponse, fileName) -> {
switch (downloadResponse) {
case DONE:
Bukkit.getLogger().info("[ThemeParkPlus] Update downloaded! If you restart your server, it will be loaded. Filename: " + fileName);
break;
case ERROR:
Bukkit.getLogger().severe("[ThemeParkPlus] Something went wrong when trying downloading the latest version.");
break;
case UNAVAILABLE:
Bukkit.getLogger().warning("[ThemeParkPlus] Unable to download the latest version.");
break;
}
}).runUpdate();
}
break; break;
case LATEST: case LATEST:
Bukkit.getLogger().info("[ThemeParkPlus] You are running the latest version [" + this.getDescription().getVersion() + "]!"); getLogger().info("You are running the latest version [" + this.getDescription().getVersion() + "]!");
break; break;
case THIS_NEWER: case THIS_NEWER:
Bukkit.getLogger().info("[ThemeParkPlus] You are running a newer version [" + this.getDescription().getVersion() + "]! This is probably fine."); getLogger().info("You are running a newer version [" + this.getDescription().getVersion() + "]! This is probably fine.");
break; break;
case UNAVAILABLE: case UNAVAILABLE:
Bukkit.getLogger().severe("[ThemeParkPlus] Unable to perform an update check."); getLogger().severe("Unable to perform an update check.");
break; break;
} }
}).check(); }).check();
} }
Bukkit.getLogger().info("[ThemeParkPlus] Plugin enabled!"); getLogger().info("Plugin enabled!");
Bukkit.getLogger().info("[ThemeParkPlus] -------------------------------"); getLogger().info("-------------------------------");
} }
@Override @Override
public void onDisable() { public void onDisable() {
Bukkit.getLogger().info("[ThemeParkPlus] Saving data..."); getLogger().info("Saving data...");
data.save(); data.save();
data.closeConnection(); data.closeConnection();
Bukkit.getLogger().info("[ThemeParkPlus] Plugin disabled!"); getLogger().info("Plugin disabled!");
instance = null; instance = null;
} }
@ -219,8 +187,8 @@ public final class ThemeParkPlus extends JavaPlugin {
return econ; return econ;
} }
public static String getWebhookURL() { public static WebhookClient getWebhookClient() {
return webhookURL; return webhookClient;
} }
public static boolean hasParkHook() { public static boolean hasParkHook() {
@ -238,28 +206,4 @@ public final class ThemeParkPlus extends JavaPlugin {
econ = rsp.getProvider(); econ = rsp.getProvider();
return econ != null; return econ != null;
} }
private void updateConfig() {
HashMap< String, Object > newConfig = getConfigVals();
for (String var: config.getFile().getKeys(false)) {
newConfig.remove(var);
}
if (newConfig.size() != 0) {
for (String key: newConfig.keySet()) {
config.getFile().set(key, newConfig.get(key));
}
config.getFile().set("Version", configVersion);
config.saveFile();
}
}
private HashMap<String, Object> getConfigVals() {
HashMap<String, Object> var = new HashMap <>();
Reader defConfigStream = new InputStreamReader(Objects.requireNonNull(getResource("config.yml")), StandardCharsets.UTF_8);
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
for (String key : defConfig.getKeys(false)) {
var.put(key, defConfig.get(key));
}
return var;
}
} }

View file

@ -1,17 +1,17 @@
package nl.sbdeveloper.themeparkplus.api; package nl.sbdeveloper.themeparkplus.api;
import com.cryptomorin.xseries.XMaterial;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import de.tr7zw.changeme.nbtapi.NBTItem; import de.tr7zw.changeme.nbtapi.NBTItem;
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.MalfunctionReport; import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport;
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.WGUtil;
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 java.util.*; import java.util.*;
@ -20,6 +20,8 @@ public class PlusAPI {
private static final HashMap<String, WaitingRow> rows = new HashMap<>(); private static final HashMap<String, WaitingRow> rows = new HashMap<>();
private static final HashMap<String, MalfunctionReport> reports = new HashMap<>(); private static final HashMap<String, MalfunctionReport> reports = new HashMap<>();
private PlusAPI() {}
public static void addReport(MalfunctionReport report) { public static void addReport(MalfunctionReport report) {
reports.put(report.getRideID(), report); reports.put(report.getRideID(), report);
} }
@ -36,7 +38,7 @@ public class PlusAPI {
return reports.containsKey(rideID); return reports.containsKey(rideID);
} }
public static HashMap<String, MalfunctionReport> getReports() { public static Map<String, MalfunctionReport> getReports() {
return reports; return reports;
} }
@ -83,7 +85,7 @@ public class PlusAPI {
* *
* @return Map with location and gate * @return Map with location and gate
*/ */
public static HashMap<Location, Gate> getGates() { public static Map<Location, Gate> getGates() {
return gates; return gates;
} }
@ -133,9 +135,10 @@ public class PlusAPI {
*/ */
public static WaitingRow getRow(Location loc) { public static WaitingRow getRow(Location loc) {
if (loc == null) return null; if (loc == null) return null;
Set<IWrappedRegion> set = WorldGuardWrapper.getInstance().getRegions(loc);
List<ProtectedRegion> regions = WGUtil.getRegionsInLocation(loc);
for (WaitingRow row : rows.values()) { for (WaitingRow row : rows.values()) {
if (set.stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) { if (regions.stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) {
return row; return row;
} }
} }
@ -157,7 +160,7 @@ public class PlusAPI {
* *
* @return Map with location and rows * @return Map with location and rows
*/ */
public static HashMap<String, WaitingRow> getRows() { public static Map<String, WaitingRow> getRows() {
return rows; return rows;
} }

View file

@ -1,6 +1,5 @@
package nl.sbdeveloper.themeparkplus.api.enums; package nl.sbdeveloper.themeparkplus.api.enums;
import nl.sbdeveloper.themeparkplus.util.DirectionUtil;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
public enum WalkingDirection { public enum WalkingDirection {
@ -14,6 +13,26 @@ public enum WalkingDirection {
WEST; WEST;
public BlockFace getBlockFace() { public BlockFace getBlockFace() {
return DirectionUtil.convertFacing(this); return BlockFace.valueOf(name());
}
public static WalkingDirection getDirection(int xOld, int zOld, int xNew, int zNew) {
int changeInX = xNew - xOld;
int changeInZ = zNew - zOld;
if (changeInZ != 0 && changeInX == 0) {
if (changeInZ < 0) {
return WalkingDirection.NORTH;
} else {
return WalkingDirection.SOUTH;
}
} else if (changeInX != 0 && changeInZ == 0) {
if (changeInX < 0) {
return WalkingDirection.WEST;
} else {
return WalkingDirection.EAST;
}
}
return null;
} }
} }

View file

@ -7,6 +7,7 @@ import lombok.Setter;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
@NoArgsConstructor @AllArgsConstructor @NoArgsConstructor @AllArgsConstructor
public class WaitingRow { public class WaitingRow {
@ -14,14 +15,14 @@ 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 final ArrayList<Location> signLocations = new ArrayList<>(); private final List<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<Location> getSignLocations() { public List<Location> getSignLocations() {
return signLocations; return signLocations;
} }

View file

@ -1,5 +1,6 @@
package nl.sbdeveloper.themeparkplus.commands; package nl.sbdeveloper.themeparkplus.commands;
import com.cryptomorin.xseries.XMaterial;
import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.ThemePark;
import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.api.PlusAPI;
@ -8,7 +9,6 @@ import nl.sbdeveloper.themeparkplus.api.objects.Gate;
import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
import nl.sbdeveloper.themeparkplus.util.Cuboid; import nl.sbdeveloper.themeparkplus.util.Cuboid;
import nl.sbdeveloper.themeparkplus.util.LGUtil; import nl.sbdeveloper.themeparkplus.util.LGUtil;
import nl.sbdeveloper.themeparkplus.util.XMaterial;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;

View file

@ -1,5 +1,6 @@
package nl.sbdeveloper.themeparkplus.gui; package nl.sbdeveloper.themeparkplus.gui;
import com.cryptomorin.xseries.XMaterial;
import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.content.InventoryContents; import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.SlotPos; import fr.minuskube.inv.content.SlotPos;
@ -12,7 +13,6 @@ import nl.sbdeveloper.themeparkplus.api.PlusAPI;
import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport; import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport;
import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
import nl.sbdeveloper.themeparkplus.util.Inventory; import nl.sbdeveloper.themeparkplus.util.Inventory;
import nl.sbdeveloper.themeparkplus.util.XMaterial;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View file

@ -5,7 +5,6 @@ import nl.sbdeveloper.themeparkplus.api.PlusAPI;
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection; import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
import nl.sbdeveloper.themeparkplus.api.objects.Gate; import nl.sbdeveloper.themeparkplus.api.objects.Gate;
import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
import nl.sbdeveloper.themeparkplus.util.DirectionUtil;
import nl.sbdeveloper.themeparkplus.util.LGUtil; import nl.sbdeveloper.themeparkplus.util.LGUtil;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -48,7 +47,7 @@ public class DirectionalGateListener implements Listener {
} }
} }
} else { } else {
WalkingDirection loopdir = DirectionUtil.getDirection(oldLoc.getBlockX(), oldLoc.getBlockZ(), newLoc.getBlockX(), newLoc.getBlockZ()); WalkingDirection loopdir = WalkingDirection.getDirection(oldLoc.getBlockX(), oldLoc.getBlockZ(), newLoc.getBlockX(), newLoc.getBlockZ());
if (loopdir == null) return; if (loopdir == null) return;
if (loopdir.getBlockFace() != gate.getDirection().getBlockFace()) { if (loopdir.getBlockFace() != gate.getDirection().getBlockFace()) {
e.getPlayer().teleport(oldLoc); e.getPlayer().teleport(oldLoc);

View file

@ -1,5 +1,6 @@
package nl.sbdeveloper.themeparkplus.listeners; package nl.sbdeveloper.themeparkplus.listeners;
import com.cryptomorin.xseries.XMaterial;
import de.tr7zw.changeme.nbtapi.NBTItem; import de.tr7zw.changeme.nbtapi.NBTItem;
import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.ThemePark;
import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.attraction.enums.Status;
@ -8,7 +9,6 @@ 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;
import nl.sbdeveloper.themeparkplus.util.LGUtil; import nl.sbdeveloper.themeparkplus.util.LGUtil;
import nl.sbdeveloper.themeparkplus.util.XMaterial;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;

View file

@ -1,5 +1,9 @@
package nl.sbdeveloper.themeparkplus.listeners; package nl.sbdeveloper.themeparkplus.listeners;
import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import club.minnced.discord.webhook.send.WebhookMessage;
import club.minnced.discord.webhook.send.WebhookMessageBuilder;
import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.attraction.enums.Status;
import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.attraction.objects.Attraction;
import nl.iobyte.themepark.api.event.attraction.AttractionPreStatusChangeEvent; import nl.iobyte.themepark.api.event.attraction.AttractionPreStatusChangeEvent;
@ -8,15 +12,10 @@ import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.api.PlusAPI;
import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport; import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport;
import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
import nl.sbdeveloper.themeparkplus.util.DiscordWebhook;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.awt.*;
import java.io.IOException;
/** /**
* Status change listener for malfunction menu and discord webhook * Status change listener for malfunction menu and discord webhook
*/ */
@ -58,24 +57,21 @@ public class StatusChangeListener implements Listener {
title = title.replaceAll("%Region%", regionName); title = title.replaceAll("%Region%", regionName);
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");
Color color = new Color(ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getCurrent().name())); Integer color = ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getCurrent().name());
if (copy == null || copyimg == null) return; if (copy == null || copyimg == null) return;
DiscordWebhook webhook = new DiscordWebhook(ThemeParkPlus.getWebhookURL()); WebhookEmbed embed = new WebhookEmbedBuilder()
.setTitle(new WebhookEmbed.EmbedTitle(title, null))
.setFooter(new WebhookEmbed.EmbedFooter(copy, copyimg))
.setColor(color)
.addField(new WebhookEmbed.EmbedField(false, rideName, statusAfter))
.build();
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject() WebhookMessage message = new WebhookMessageBuilder()
.setTitle(title) .addEmbeds(embed)
.setFooter(copy, copyimg) .build();
.setColor(color)
.addField(rideName, statusAfter, false);
webhook.addEmbed(embed); ThemeParkPlus.getWebhookClient().send(message);
try {
webhook.execute();
} catch (IOException ex) {
Bukkit.getLogger().severe("[ThemeParkPlus] Could not send the status update to Discord! See the error below:");
ex.printStackTrace();
}
} }
@EventHandler @EventHandler
@ -91,23 +87,20 @@ public class StatusChangeListener implements Listener {
title = title.replaceAll("%Region%", regionName); title = title.replaceAll("%Region%", regionName);
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");
Color color = new Color(ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getCurrent().name())); Integer color = ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getCurrent().name());
if (copy == null || copyimg == null) return; if (copy == null || copyimg == null) return;
DiscordWebhook webhook = new DiscordWebhook(ThemeParkPlus.getWebhookURL()); WebhookEmbed embed = new WebhookEmbedBuilder()
.setTitle(new WebhookEmbed.EmbedTitle(title, null))
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject() .setFooter(new WebhookEmbed.EmbedFooter(copy, copyimg))
.setTitle(title)
.setFooter(copy, copyimg)
.setColor(color) .setColor(color)
.addField(rideName, statusAfter, false); .addField(new WebhookEmbed.EmbedField(false, rideName, statusAfter))
.build();
webhook.addEmbed(embed); WebhookMessage message = new WebhookMessageBuilder()
try { .addEmbeds(embed)
webhook.execute(); .build();
} catch (IOException ex) {
Bukkit.getLogger().severe("[ThemeParkPlus] Could not send the status update to Discord! See the error below:"); ThemeParkPlus.getWebhookClient().send(message);
ex.printStackTrace();
}
} }
} }

View file

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
public class LocationSerializer { public class LocationSerializer {
private LocationSerializer() {}
/** /**
* Deserialize a serialized location, without {@link Location#getYaw()} and {@link Location#getPitch()} * Deserialize a serialized location, without {@link Location#getYaw()} and {@link Location#getPitch()}

View file

@ -12,7 +12,8 @@ import java.util.*;
public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable<Block> { public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable<Block> {
protected String worldName; protected String worldName;
protected final Vector minimumPoint, maximumPoint; protected final Vector minimumPoint;
protected final Vector maximumPoint;
public Cuboid(Cuboid cuboid) { public Cuboid(Cuboid cuboid) {
this(cuboid.worldName, cuboid.minimumPoint.getX(), cuboid.minimumPoint.getY(), cuboid.minimumPoint.getZ(), cuboid.maximumPoint.getX(), cuboid.maximumPoint.getY(), cuboid.maximumPoint.getZ()); this(cuboid.worldName, cuboid.minimumPoint.getX(), cuboid.minimumPoint.getY(), cuboid.minimumPoint.getZ(), cuboid.maximumPoint.getX(), cuboid.maximumPoint.getY(), cuboid.maximumPoint.getZ());

View file

@ -1,41 +0,0 @@
package nl.sbdeveloper.themeparkplus.util;
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
import org.bukkit.block.BlockFace;
public class DirectionUtil {
public static WalkingDirection getDirection(int xoud, int zoud, int xnieuw, int znieuw) {
int changeInX = xnieuw - xoud;
int changeInZ = znieuw - zoud;
if (changeInZ != 0 && changeInX == 0) {
if (changeInZ < 0) {
return WalkingDirection.NORTH;
} else {
return WalkingDirection.SOUTH;
}
} else if (changeInX != 0 && changeInZ == 0) {
if (changeInX < 0) {
return WalkingDirection.WEST;
} else {
return WalkingDirection.EAST;
}
}
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;
}
}
}

View file

@ -1,391 +0,0 @@
package nl.sbdeveloper.themeparkplus.util;
import javax.net.ssl.HttpsURLConnection;
import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Class used to execute Discord Webhooks with low effort
*/
public class DiscordWebhook {
private final String url;
private String content;
private String username;
private String avatarUrl;
private boolean tts;
private final List<EmbedObject> embeds = new ArrayList<>();
/**
* Constructs a new DiscordWebhook instance
*
* @param url The webhook URL obtained in Discord
*/
public DiscordWebhook(String url) {
this.url = url;
}
public void setContent(String content) {
this.content = content;
}
public void setUsername(String username) {
this.username = username;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public void setTts(boolean tts) {
this.tts = tts;
}
public void addEmbed(EmbedObject embed) {
this.embeds.add(embed);
}
public void execute() throws IOException {
if (this.content == null && this.embeds.isEmpty()) {
throw new IllegalArgumentException("Set content or add at least one EmbedObject");
}
JSONObject json = new JSONObject();
json.put("content", this.content);
json.put("username", this.username);
json.put("avatar_url", this.avatarUrl);
json.put("tts", this.tts);
if (!this.embeds.isEmpty()) {
List<JSONObject> embedObjects = new ArrayList<>();
for (EmbedObject embed : this.embeds) {
JSONObject jsonEmbed = new JSONObject();
jsonEmbed.put("title", embed.getTitle());
jsonEmbed.put("description", embed.getDescription());
jsonEmbed.put("url", embed.getUrl());
if (embed.getColor() != null) {
Color color = embed.getColor();
int rgb = color.getRed();
rgb = (rgb << 8) + color.getGreen();
rgb = (rgb << 8) + color.getBlue();
jsonEmbed.put("color", rgb);
}
EmbedObject.Footer footer = embed.getFooter();
EmbedObject.Image image = embed.getImage();
EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
EmbedObject.Author author = embed.getAuthor();
List<EmbedObject.Field> fields = embed.getFields();
if (footer != null) {
JSONObject jsonFooter = new JSONObject();
jsonFooter.put("text", footer.getText());
jsonFooter.put("icon_url", footer.getIconUrl());
jsonEmbed.put("footer", jsonFooter);
}
if (image != null) {
JSONObject jsonImage = new JSONObject();
jsonImage.put("url", image.getUrl());
jsonEmbed.put("image", jsonImage);
}
if (thumbnail != null) {
JSONObject jsonThumbnail = new JSONObject();
jsonThumbnail.put("url", thumbnail.getUrl());
jsonEmbed.put("thumbnail", jsonThumbnail);
}
if (author != null) {
JSONObject jsonAuthor = new JSONObject();
jsonAuthor.put("name", author.getName());
jsonAuthor.put("url", author.getUrl());
jsonAuthor.put("icon_url", author.getIconUrl());
jsonEmbed.put("author", jsonAuthor);
}
List<JSONObject> jsonFields = new ArrayList<>();
for (EmbedObject.Field field : fields) {
JSONObject jsonField = new JSONObject();
jsonField.put("name", field.getName());
jsonField.put("value", field.getValue());
jsonField.put("inline", field.isInline());
jsonFields.add(jsonField);
}
jsonEmbed.put("fields", jsonFields.toArray());
embedObjects.add(jsonEmbed);
}
json.put("embeds", embedObjects.toArray());
}
URL url = new URL(this.url);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStream stream = connection.getOutputStream();
stream.write(json.toString().getBytes(StandardCharsets.UTF_8));
stream.flush();
stream.close();
connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
connection.disconnect();
}
public static class EmbedObject {
private String title;
private String description;
private String url;
private Color color;
private Footer footer;
private Thumbnail thumbnail;
private Image image;
private Author author;
private final List<Field> fields = new ArrayList<>();
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getUrl() {
return url;
}
public Color getColor() {
return color;
}
public Footer getFooter() {
return footer;
}
public Thumbnail getThumbnail() {
return thumbnail;
}
public Image getImage() {
return image;
}
public Author getAuthor() {
return author;
}
public List<Field> getFields() {
return fields;
}
public EmbedObject setTitle(String title) {
this.title = title;
return this;
}
public EmbedObject setDescription(String description) {
this.description = description;
return this;
}
public EmbedObject setUrl(String url) {
this.url = url;
return this;
}
public EmbedObject setColor(Color color) {
this.color = color;
return this;
}
public EmbedObject setFooter(String text, String icon) {
this.footer = new Footer(text, icon);
return this;
}
public EmbedObject setThumbnail(String url) {
this.thumbnail = new Thumbnail(url);
return this;
}
public EmbedObject setImage(String url) {
this.image = new Image(url);
return this;
}
public EmbedObject setAuthor(String name, String url, String icon) {
this.author = new Author(name, url, icon);
return this;
}
public EmbedObject addField(String name, String value, boolean inline) {
this.fields.add(new Field(name, value, inline));
return this;
}
private static class Footer {
private final String text;
private final String iconUrl;
private Footer(String text, String iconUrl) {
this.text = text;
this.iconUrl = iconUrl;
}
private String getText() {
return text;
}
private String getIconUrl() {
return iconUrl;
}
}
private static class Thumbnail {
private final String url;
private Thumbnail(String url) {
this.url = url;
}
private String getUrl() {
return url;
}
}
private static class Image {
private final String url;
private Image(String url) {
this.url = url;
}
private String getUrl() {
return url;
}
}
private static class Author {
private final String name;
private final String url;
private final String iconUrl;
private Author(String name, String url, String iconUrl) {
this.name = name;
this.url = url;
this.iconUrl = iconUrl;
}
private String getName() {
return name;
}
private String getUrl() {
return url;
}
private String getIconUrl() {
return iconUrl;
}
}
private static class Field {
private final String name;
private final String value;
private final boolean inline;
private Field(String name, String value, boolean inline) {
this.name = name;
this.value = value;
this.inline = inline;
}
private String getName() {
return name;
}
private String getValue() {
return value;
}
private boolean isInline() {
return inline;
}
}
}
private static class JSONObject {
private final HashMap<String, Object> map = new HashMap<>();
void put(String key, Object value) {
if (value != null) {
map.put(key, value);
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
builder.append("{");
int i = 0;
for (Map.Entry<String, Object> entry : entrySet) {
Object val = entry.getValue();
builder.append(quote(entry.getKey())).append(":");
if (val instanceof String) {
builder.append(quote(String.valueOf(val)));
} else if (val instanceof Integer) {
builder.append(Integer.valueOf(String.valueOf(val)));
} else if (val instanceof Boolean) {
builder.append(val);
} else if (val instanceof JSONObject) {
builder.append(val.toString());
} else if (val.getClass().isArray()) {
builder.append("[");
int len = Array.getLength(val);
for (int j = 0; j < len; j++) {
builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : "");
}
builder.append("]");
}
builder.append(++i == entrySet.size() ? "}" : ",");
}
return builder.toString();
}
private String quote(String string) {
return "\"" + string + "\"";
}
}
}

View file

@ -21,11 +21,11 @@ public abstract class Inventory implements InventoryProvider {
private static InventoryManager manager; private static InventoryManager manager;
protected SmartInventory inventory; protected SmartInventory inventory;
public Inventory(int rows, String title) { protected Inventory(int rows, String title) {
this(rows, title, true); //Standaard sluitbaar! this(rows, title, true); //Standaard sluitbaar!
} }
public Inventory(int rows, String title, boolean closeable) { protected Inventory(int rows, String title, boolean closeable) {
this.inventory = SmartInventory.builder().id(title).provider(this).manager(manager).size(rows, 9).closeable(closeable).title(__("&8" + title)).build(); this.inventory = SmartInventory.builder().id(title).provider(this).manager(manager).size(rows, 9).closeable(closeable).title(__("&8" + title)).build();
} }

View file

@ -1,5 +1,6 @@
package nl.sbdeveloper.themeparkplus.util; package nl.sbdeveloper.themeparkplus.util;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;

View file

@ -0,0 +1,354 @@
/*
* This file is part of TCSummerCamp.
* Copyright (c) 2022 SBDevelopment - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Stijn Bannink <stijnbannink23@gmail.com>, June 2022
*/
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.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
/**
* WorldGuard class to make the usage of WorldGuard easy.
* This version only works with the latest build of WorldEdit & WorldGuard.
*
* <i>Note that if you do use this in one of your projects, leave this notice.</i>
* <i>Please do credit me if you do use this in one of your projects.</i>
*
* @author SBDeveloper [Fixed 1.13+ support]
*/
public class WGUtil {
public static WorldGuardPlugin wgp;
public static WorldEditPlugin wep;
/**
* Enables the utility.
*/
public static void load() {
try {
wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
wgp = (WorldGuardPlugin) Bukkit.getPluginManager().getPlugin("WorldGuard");
} catch (NullPointerException | ClassCastException ex) {
throw new IllegalStateException("This plugin requires WorldEdit & WorldGuard to function!");
}
}
/**
* Create a new region.
*
* @param p The player that creates the region.
* @param regionID The ID of the new region.
* @return The region created, or null.
*/
public static ProtectedRegion createRegion(Player p, String regionID) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(p.getWorld()));
if (rm == null) return null;
if (rm.hasRegion(regionID)) return null;
LocalSession l = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(p));
Region s;
try {
s = l.getSelection(l.getSelectionWorld());
} catch (IncompleteRegionException e) {
return null;
}
ProtectedRegion region;
if (s instanceof Polygonal2DRegion) {
Polygonal2DRegion polySel = (Polygonal2DRegion) s;
region = new ProtectedPolygonalRegion(regionID, polySel.getPoints(), polySel.getMinimumY(), polySel.getMaximumY());
} else {
region = new ProtectedCuboidRegion(regionID, s.getMinimumPoint(), s.getMaximumPoint());
}
rm.addRegion(region);
return region;
}
/**
* Remove a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to remove.
* @return true if success, false if not.
*/
public static boolean removeRegion(World world, String regionID) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return false;
if (!rm.hasRegion(regionID)) return false;
rm.removeRegion(regionID);
return true;
}
/**
* Get the region by its ID.
*
* @param world The world to look up the region with.
* @param regionID The ID of the region.
* @return An optional with the region, or an empty optional if no match was found.
*/
public static Optional<ProtectedRegion> getRegionById(World world, String regionID) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return Optional.empty();
return Optional.ofNullable(rm.getRegion(regionID));
}
/**
* Get the region by its ID.
* This method forces the region to be in a location.
*
* @param loc The location to look up the region with.
* @param regionID The ID of the region.
* @return An optional with the region, or an empty optional if no match was found.
*/
public static Optional<ProtectedRegion> getRegionById(Location loc, String regionID) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
if (rm == null) return Optional.empty();
return rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc)).getRegions().stream().filter(r -> r.getId().equals(regionID)).findFirst();
}
/**
* Get the regions a location is in.
*
* @param loc The location to look up with.
* @return The regions the location is in.
*/
public static List<ProtectedRegion> getRegionsInLocation(Location loc) {
List<ProtectedRegion> regions = new ArrayList<>();
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
if (rm == null) return regions;
regions.addAll(rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc)).getRegions());
return regions;
}
/**
* Check if a player is a member of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @param target The player to check for.
* @return true/false if found or not found. Null if the region does not exist.
*/
public static Boolean isMember(World world, String regionID, OfflinePlayer target) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return null;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return null;
return reg.getMembers().contains(target.getUniqueId());
}
/**
* Check if a player is an owner of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @param target The player to check for.
* @return true/false if found or not found. Null if the region does not exist.
*/
public static Boolean isOwner(World world, String regionID, OfflinePlayer target) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return null;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return null;
return reg.getOwners().contains(target.getUniqueId());
}
/**
* Add a player as a member of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @param target The player to add.
* @return true if success, false if not.
*/
public static boolean addMember(World world, String regionID, OfflinePlayer target) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return false;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return false;
reg.getMembers().addPlayer(target.getUniqueId());
return true;
}
/**
* Add a player as an owner of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @param target The player to add.
* @return true if success, false if not.
*/
public static boolean addOwner(World world, String regionID, OfflinePlayer target) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return false;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return false;
reg.getOwners().addPlayer(target.getUniqueId());
return true;
}
/**
* Remove a player as a member of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @param target The player to remove.
* @return true if success, false if not.
*/
public static boolean removeMember(World world, String regionID, OfflinePlayer target) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return false;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return false;
reg.getMembers().removePlayer(target.getUniqueId());
return true;
}
/**
* Remove a player as an owner of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @param target The player to remove.
* @return true if success, false if not.
*/
public static boolean removeOwner(World world, String regionID, OfflinePlayer target) {
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return false;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return false;
reg.getOwners().removePlayer(target.getUniqueId());
return true;
}
/**
* Get the members of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @return A list of the player UUIDs of the members
*/
public static List<UUID> getMembers(World world, String regionID) {
List<UUID> members = new ArrayList<>();
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return members;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return members;
members.addAll(reg.getMembers().getUniqueIds());
return members;
}
/**
* Get the members names of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @return A list of the player names of the members
*/
public static List<String> getMembersNames(World world, String regionID) {
List<String> members = new ArrayList<>();
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return members;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return members;
members.addAll(reg.getMembers().getPlayers());
return members;
}
/**
* Get the owners of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @return A list of the player UUIDs of the owners
*/
public static List<UUID> getOwners(World world, String regionID) {
List<UUID> owners = new ArrayList<>();
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return owners;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return owners;
owners.addAll(reg.getOwners().getUniqueIds());
return owners;
}
/**
* Get the owners names of a region.
*
* @param world The world the region is in.
* @param regionID The ID of the region to check for.
* @return A list of the player names of the owners
*/
public static List<String> getOwnersNames(World world, String regionID) {
List<String> owners = new ArrayList<>();
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (rm == null) return owners;
ProtectedRegion reg = rm.getRegion(regionID);
if (reg == null) return owners;
owners.addAll(reg.getOwners().getPlayers());
return owners;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,6 @@
AntiFreerun: AntiFreerun:
Enabled: false Enabled: false
UpdateChecker: UpdateChecker: true
Enabled: true
DownloadOnUpdate: true
MessageInConsole: true MessageInConsole: true
WaitingRow: WaitingRow:
MinutesPerPlayer: 1.5 MinutesPerPlayer: 1.5