Update to WorldGuard's 1.16 API (#904)
* Update to WorldGuard's 1.16 API * Swap to Gson for JSON, WG was providing old lib * Also JUnit
This commit is contained in:
parent
4e373e7b98
commit
230b2bb5cc
13
pom.xml
13
pom.xml
|
|
@ -23,7 +23,7 @@
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>worldedit-worldguard-repo</id>
|
<id>worldedit-worldguard-repo</id>
|
||||||
<url>http://maven.sk89q.com/repo/</url>
|
<url>https://maven.enginehub.org/repo/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>essx-repo</id>
|
<id>essx-repo</id>
|
||||||
|
|
@ -79,8 +79,8 @@
|
||||||
<!--Worldguard dependency-->
|
<!--Worldguard dependency-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
<artifactId>worldguard-legacy</artifactId>
|
<artifactId>worldguard-bukkit</artifactId>
|
||||||
<version>7.0.0-SNAPSHOT</version>
|
<version>7.0.4-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
|
@ -114,6 +114,13 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--Tests-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@
|
||||||
package me.ryanhamshire.GriefPrevention;
|
package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
@ -21,7 +22,7 @@ class UUIDFetcher
|
||||||
{
|
{
|
||||||
private static int PROFILES_PER_REQUEST = 100;
|
private static int PROFILES_PER_REQUEST = 100;
|
||||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||||
private final JSONParser jsonParser = new JSONParser();
|
private final Gson gson = new Gson();
|
||||||
private final List<String> names;
|
private final List<String> names;
|
||||||
private final boolean rateLimiting;
|
private final boolean rateLimiting;
|
||||||
|
|
||||||
|
|
@ -102,17 +103,17 @@ class UUIDFetcher
|
||||||
for (int i = 0; i * PROFILES_PER_REQUEST < names.size(); i++)
|
for (int i = 0; i * PROFILES_PER_REQUEST < names.size(); i++)
|
||||||
{
|
{
|
||||||
boolean retry = false;
|
boolean retry = false;
|
||||||
JSONArray array = null;
|
JsonArray array = null;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
HttpURLConnection connection = createConnection();
|
HttpURLConnection connection = createConnection();
|
||||||
String body = JSONArray.toJSONString(names.subList(i * PROFILES_PER_REQUEST, Math.min((i + 1) * PROFILES_PER_REQUEST, names.size())));
|
String body = gson.toJson(names.subList(i * PROFILES_PER_REQUEST, Math.min((i + 1) * PROFILES_PER_REQUEST, names.size())));
|
||||||
writeBody(connection, body);
|
writeBody(connection, body);
|
||||||
retry = false;
|
retry = false;
|
||||||
array = null;
|
array = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
array = gson.fromJson(new InputStreamReader(connection.getInputStream()), JsonArray.class);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
@ -144,11 +145,11 @@ class UUIDFetcher
|
||||||
}
|
}
|
||||||
} while (retry);
|
} while (retry);
|
||||||
|
|
||||||
for (Object profile : array)
|
for (JsonElement profile : array)
|
||||||
{
|
{
|
||||||
JSONObject jsonProfile = (JSONObject) profile;
|
JsonObject jsonProfile = profile.getAsJsonObject();
|
||||||
String id = (String) jsonProfile.get("id");
|
String id = jsonProfile.get("id").getAsString();
|
||||||
String name = (String) jsonProfile.get("name");
|
String name = jsonProfile.get("name").getAsString();
|
||||||
UUID uuid = UUIDFetcher.getUUID(id);
|
UUID uuid = UUIDFetcher.getUUID(id);
|
||||||
GriefPrevention.AddLogEntry(name + " --> " + uuid.toString());
|
GriefPrevention.AddLogEntry(name + " --> " + uuid.toString());
|
||||||
lookupCache.put(name, uuid);
|
lookupCache.put(name, uuid);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
import com.sk89q.worldguard.bukkit.BukkitPlayer;
|
import com.sk89q.worldguard.bukkit.BukkitPlayer;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.flags.Flags;
|
import com.sk89q.worldguard.protection.flags.Flags;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
|
@ -28,11 +28,12 @@ class WorldGuardWrapper
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BukkitPlayer localPlayer = new BukkitPlayer(this.worldGuard, creatingPlayer);
|
BukkitPlayer localPlayer = new BukkitPlayer(this.worldGuard, creatingPlayer);
|
||||||
World world = WorldGuard.getInstance().getPlatform().getMatcher().getWorldByName(lesserCorner.getWorld().getName());
|
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
|
||||||
|
World world = platform.getMatcher().getWorldByName(lesserCorner.getWorld().getName());
|
||||||
|
|
||||||
if (new RegionPermissionModel(localPlayer).mayIgnoreRegionProtection(world)) return true;
|
if (platform.getSessionManager().hasBypass(localPlayer, world)) return true;
|
||||||
|
|
||||||
RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(world);
|
RegionManager manager = platform.getRegionContainer().get(world);
|
||||||
|
|
||||||
if (manager != null)
|
if (manager != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user