3
0
Fork 0

Fixed a lot of issues, removed sbutil, ...

This commit is contained in:
stijnb1234 2020-06-01 13:43:13 +02:00
parent 95cf389a69
commit 328b8d670f
29 changed files with 841 additions and 149 deletions

View file

@ -0,0 +1,54 @@
package nl.sbdeveloper.themeparkplus.util;
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ConfigUtil {
@NotNull
public static String makecolored(String str) {
return ChatColor.translateAlternateColorCodes('&', str);
}
@NotNull
public static List<String> getLore(String path, Map<String, String> vars) {
ArrayList<String> response = new ArrayList<>();
for (String str : ThemeParkPlus.getSConfig().getFile().getStringList(path)) {
for (Map.Entry<String, String> entry : vars.entrySet()) {
str = str.replaceAll(entry.getKey(), entry.getValue());
}
response.add(makecolored(str));
}
return response;
}
@NotNull
public static String getMessage(String path) {
return getMessage(path, new HashMap<>());
}
@NotNull
public static String getMessage(String path, Map<String, String> vars) {
String message = ThemeParkPlus.getMessages().getFile().getString(path);
if (message == null) return "";
for (Map.Entry<String, String> entry : vars.entrySet()) {
message = message.replaceAll(entry.getKey(), entry.getValue());
}
return makecolored(message);
}
public static boolean sendConsole(CommandSender sender) {
if (sender instanceof ConsoleCommandSender) {
return ThemeParkPlus.getSConfig().getFile().getBoolean("MessageInConsole");
} else {
return true;
}
}
}

View file

@ -0,0 +1,177 @@
package nl.sbdeveloper.themeparkplus.util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable<Block> {
protected String worldName;
protected final Vector minimumPoint, maximumPoint;
public Cuboid(@NotNull Cuboid cuboid) {
this(cuboid.worldName, cuboid.minimumPoint.getX(), cuboid.minimumPoint.getY(), cuboid.minimumPoint.getZ(), cuboid.maximumPoint.getX(), cuboid.maximumPoint.getY(), cuboid.maximumPoint.getZ());
}
public Cuboid(Location loc) {
this(loc, loc);
}
public Cuboid(Location loc1, Location loc2) {
if (loc1 != null && loc2 != null) {
if (loc1.getWorld() != null && loc2.getWorld() != null) {
if (!loc1.getWorld().getUID().equals(loc2.getWorld().getUID()))
throw new IllegalStateException("The 2 locations of the cuboid must be in the same world!");
} else {
throw new NullPointerException("One/both of the worlds is/are null!");
}
this.worldName = loc1.getWorld().getName();
double xPos1 = Math.min(loc1.getX(), loc2.getX());
double yPos1 = Math.min(loc1.getY(), loc2.getY());
double zPos1 = Math.min(loc1.getZ(), loc2.getZ());
double xPos2 = Math.max(loc1.getX(), loc2.getX());
double yPos2 = Math.max(loc1.getY(), loc2.getY());
double zPos2 = Math.max(loc1.getZ(), loc2.getZ());
this.minimumPoint = new Vector(xPos1, yPos1, zPos1);
this.maximumPoint = new Vector(xPos2, yPos2, zPos2);
} else {
throw new NullPointerException("One/both of the locations is/are null!");
}
}
public Cuboid(String worldName, double x1, double y1, double z1, double x2, double y2, double z2) {
if (worldName == null || Bukkit.getServer().getWorld(worldName) == null)
throw new NullPointerException("One/both of the worlds is/are null!");
this.worldName = worldName;
double xPos1 = Math.min(x1, x2);
double xPos2 = Math.max(x1, x2);
double yPos1 = Math.min(y1, y2);
double yPos2 = Math.max(y1, y2);
double zPos1 = Math.min(z1, z2);
double zPos2 = Math.max(z1, z2);
this.minimumPoint = new Vector(xPos1, yPos1, zPos1);
this.maximumPoint = new Vector(xPos2, yPos2, zPos2);
}
public boolean containsLocation(Location location) {
return location != null && location.getWorld().getName().equals(this.worldName) && location.toVector().isInAABB(this.minimumPoint, this.maximumPoint);
}
public boolean containsVector(Vector vector) {
return vector != null && vector.isInAABB(this.minimumPoint, this.maximumPoint);
}
public List<Block> getBlocks() {
List<Block> blockList = new ArrayList<>();
World world = this.getWorld();
if (world != null) {
for (int x = this.minimumPoint.getBlockX(); x <= this.maximumPoint.getBlockX(); x++) {
for (int y = this.minimumPoint.getBlockY(); y <= this.maximumPoint.getBlockY() && y <= world.getMaxHeight(); y++) {
for (int z = this.minimumPoint.getBlockZ(); z <= this.maximumPoint.getBlockZ(); z++) {
blockList.add(world.getBlockAt(x, y, z));
}
}
}
}
return blockList;
}
public Location getLowerLocation() {
return this.minimumPoint.toLocation(this.getWorld());
}
public double getLowerX() {
return this.minimumPoint.getX();
}
public double getLowerY() {
return this.minimumPoint.getY();
}
public double getLowerZ() {
return this.minimumPoint.getZ();
}
public Location getUpperLocation() {
return this.maximumPoint.toLocation(this.getWorld());
}
public double getUpperX() {
return this.maximumPoint.getX();
}
public double getUpperY() {
return this.maximumPoint.getY();
}
public double getUpperZ() {
return this.maximumPoint.getZ();
}
public double getVolume() {
return (this.getUpperX() - this.getLowerX() + 1) * (this.getUpperY() - this.getLowerY() + 1) * (this.getUpperZ() - this.getLowerZ() + 1);
}
public World getWorld() {
World world = Bukkit.getServer().getWorld(this.worldName);
if (world == null) throw new NullPointerException("World '" + this.worldName + "' is not loaded.");
return world;
}
public void setWorld(World world) {
if (world != null) this.worldName = world.getName();
else throw new NullPointerException("The world cannot be null.");
}
@Override
public Cuboid clone() {
return new Cuboid(this);
}
@Override
public ListIterator<Block> iterator() {
return this.getBlocks().listIterator();
}
@Override
public Map<String, Object> serialize() {
Map<String, Object> serializedCuboid = new HashMap<>();
serializedCuboid.put("worldName", this.worldName);
serializedCuboid.put("x1", this.minimumPoint.getX());
serializedCuboid.put("x2", this.maximumPoint.getX());
serializedCuboid.put("y1", this.minimumPoint.getY());
serializedCuboid.put("y2", this.maximumPoint.getY());
serializedCuboid.put("z1", this.minimumPoint.getZ());
serializedCuboid.put("z2", this.maximumPoint.getZ());
return serializedCuboid;
}
@Nullable
public static Cuboid deserialize(Map<String, Object> serializedCuboid) {
try {
String worldName = (String) serializedCuboid.get("worldName");
double xPos1 = (Double) serializedCuboid.get("x1");
double xPos2 = (Double) serializedCuboid.get("x2");
double yPos1 = (Double) serializedCuboid.get("y1");
double yPos2 = (Double) serializedCuboid.get("y2");
double zPos1 = (Double) serializedCuboid.get("z1");
double zPos2 = (Double) serializedCuboid.get("z2");
return new Cuboid(worldName, xPos1, yPos1, zPos1, xPos2, yPos2, zPos2);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}

View file

@ -0,0 +1,28 @@
package nl.sbdeveloper.themeparkplus.util;
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
import org.jetbrains.annotations.Nullable;
public class DirectionUtil {
@Nullable
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;
}
}

View file

@ -0,0 +1,291 @@
package nl.sbdeveloper.themeparkplus.util;
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class LGUtil {
private static List<Vector> offsets = new ArrayList<>();
private static List <Block> nearbyBlocks = new ArrayList<>();
private static boolean nieuweVersie = false;
private static Method getBlockDataMethod;
private static Method setBlockDataMethod;
private static Method getAsStringMethod;
private static Object lampAanData;
private static Object lampUitData;
public LGUtil() throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
offsets.add(new Vector(1, 0, 0));
offsets.add(new Vector(-1, 0, 0));
offsets.add(new Vector(0, 1, 0));
offsets.add(new Vector(0, -1, 0));
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;
}
public static boolean zetLampAan(Block lampBlock) {
if (nieuweVersie) {
if ((isLamp(lampBlock)) && (!isAan(lampBlock))) {
setBlockData(lampBlock, lampAanData);
return true;
}
return false;
}
if (!isAan(lampBlock)) {
final Block neighbor = getNeighbor(lampBlock);
if (neighbor != null) {
BlockState neighborState = neighbor.getState();
try {
for (org.bukkit.util.Vector offset: offsets) {
Block neighborOfNeighbor = neighbor.getLocation().add(offset).getBlock();
if ((neighborOfNeighbor.getX() != lampBlock.getX()) || (neighborOfNeighbor.getY() != lampBlock.getY()) || (neighborOfNeighbor.getZ() != lampBlock.getZ())) {
nearbyBlocks.add(neighborOfNeighbor);
}
}
neighbor.setType(Material.REDSTONE_BLOCK);
} catch (Exception e) {
e.printStackTrace();
} finally {
neighborState.update(true, false);
Bukkit.getScheduler().runTaskLater(ThemeParkPlus.getInstance(), () -> {
for (Vector offset: offsets) {
Block neighborOfNeighbor = neighbor.getLocation().add(offset).getBlock();
nearbyBlocks.remove(neighborOfNeighbor);
}
}, 1L);
}
return true;
}
}
return false;
}
public static boolean zetLampUit(Block lampBlock) {
if (nieuweVersie) {
if ((isLamp(lampBlock)) && (isAan(lampBlock))) {
setBlockData(lampBlock, lampUitData);
return true;
}
return false;
}
if (isAan(lampBlock)) {
lampBlock.setType(Objects.requireNonNull(Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[0])));
return true;
}
return false;
}
public static boolean openGate(Block b) {
return openGate(b, getDirection(b));
}
public static boolean openGate(Block b, BlockFace openFace) {
if (nieuweVersie) {
org.bukkit.block.data.BlockData blockData = b.getBlockData();
if (isOpenable(b)) {
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
if (op.isOpen()) return false;
op.setOpen(true);
b.setBlockData(blockData);
org.bukkit.block.data.Directional dir = (org.bukkit.block.data.Directional) blockData;
dir.setFacing(openFace);
b.setBlockData(blockData);
return true;
}
} else {
BlockState state = b.getState();
if (isOpenable(b)) {
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
if (openable.isOpen()) return false;
openable.setOpen(true);
state.setData((org.bukkit.material.MaterialData) openable);
state.update();
org.bukkit.material.Directional dir = (org.bukkit.material.Directional) state.getData();
dir.setFacingDirection(openFace);
state.setData((org.bukkit.material.MaterialData) dir);
state.update();
return true;
}
}
return false;
}
public static boolean closeGate(Block b) {
if (nieuweVersie) {
org.bukkit.block.data.BlockData blockData = b.getBlockData();
if (isOpenable(b)) {
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
if (!op.isOpen()) {
return false;
}
op.setOpen(false);
b.setBlockData(blockData);
return true;
}
} else {
BlockState state = b.getState();
if (isOpenable(b)) {
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
if (!openable.isOpen()) {
return false;
}
openable.setOpen(false);
state.setData((org.bukkit.material.MaterialData) openable);
state.update();
return true;
}
}
return false;
}
@Nullable
public static BlockFace getDirection(Block b) {
if (nieuweVersie) {
org.bukkit.block.data.BlockData blockData = b.getBlockData();
if (isOpenable(b)) {
org.bukkit.block.data.Directional dir = (org.bukkit.block.data.Directional) blockData;
return dir.getFacing();
}
} else {
BlockState state = b.getState();
if (isOpenable(b)) {
org.bukkit.material.Directional dir = (org.bukkit.material.Directional) state.getData();
return dir.getFacing();
}
}
return null;
}
public static boolean isOpen(Block b) {
if (nieuweVersie) {
org.bukkit.block.data.BlockData blockData = b.getBlockData();
if (isOpenable(b)) {
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
return op.isOpen();
}
} else {
BlockState state = b.getState();
if (isOpenable(b)) {
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
return openable.isOpen();
}
}
return false;
}
/* Gate codes sponsored by MrWouter <3 */
public static boolean isOpenable(Block b) {
if (b == null) {
return false;
}
if (nieuweVersie) {
return b.getBlockData() instanceof org.bukkit.block.data.Openable;
} else {
return b.getState().getData() instanceof org.bukkit.material.Openable;
}
}
private static Block getNeighbor(Block lampBlock) {
List<Block> possibleNeighbors = new ArrayList<>();
if (lampBlock.getLocation().getY() > 0.0D) {
possibleNeighbors.add(lampBlock.getLocation().add(0.0D, -1.0D, 0.0D).getBlock());
}
if (lampBlock.getLocation().getY() < 255.0D) {
possibleNeighbors.add(lampBlock.getLocation().add(0.0D, 1.0D, 0.0D).getBlock());
}
possibleNeighbors.add(lampBlock.getLocation().add(0.0D, 0.0D, 1.0D).getBlock());
possibleNeighbors.add(lampBlock.getLocation().add(0.0D, 0.0D, -1.0D).getBlock());
possibleNeighbors.add(lampBlock.getLocation().add(1.0D, 0.0D, 0.0D).getBlock());
possibleNeighbors.add(lampBlock.getLocation().add(-1.0D, 0.0D, 0.0D).getBlock());
for (Block neighbor: possibleNeighbors) {
if (neighbor.getType() == Material.AIR) {
return neighbor;
}
}
for (Block neighbor: possibleNeighbors) {
if ((neighbor.getState().getClass().getSimpleName().equals("CraftBlockState")) && (neighbor.getType() != Material.valueOf(XMaterial.PISTON_HEAD.getLegacy()[0]) && neighbor.getType() != Material.valueOf(XMaterial.MOVING_PISTON.getLegacy()[1])) && (neighbor.getType() != Material.valueOf("REDSTONE_LAMP_ON"))) {
return neighbor;
}
}
for (Block neighbor: possibleNeighbors) {
if ((neighbor.getState().getClass().getSimpleName().equals("CraftBlockState")) && (neighbor.getType() != Material.valueOf(XMaterial.PISTON_HEAD.getLegacy()[0]) && neighbor.getType() != Material.valueOf(XMaterial.MOVING_PISTON.getLegacy()[1]))) {
return neighbor;
}
}
return null;
}
private static boolean isAan(Block lamp) {
return ((nieuweVersie) && (Objects.requireNonNull(getAsString(getBlockData(lamp))).contains("lit=true"))) || ((!nieuweVersie) && (lamp.getType() == Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[1])));
}
private static boolean isLamp(Block lamp) {
if (nieuweVersie) {
return lamp.getType() == XMaterial.REDSTONE_LAMP.parseMaterial();
} else {
return lamp.getType() == Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[1])
|| lamp.getType() == Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[0]);
}
}
private static void setBlockData(Block lamp, Object blockData) {
try {
setBlockDataMethod.invoke(lamp, blockData,
Boolean.FALSE);
} catch (Exception e) {
e.printStackTrace();
}
}
private static Object getBlockData(Block lamp) {
try {
return getBlockDataMethod.invoke(lamp);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static String getAsString(Object blockData) {
try {
return (String) getAsStringMethod.invoke(blockData, new Object[0]);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View file

@ -0,0 +1,264 @@
package nl.sbdeveloper.themeparkplus.util;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
/**
* License class for SBDevelopment
*
* v1.3 - Changed in 03-03-2020
*
* @author Stijn [SBDeveloper]
* @since 23-12-2019
*/
public class License {
/*
This file is part of ActionFoto.
Copyright (c) 2018-2020 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>, January 2020
*/
private Plugin plugin;
private String license;
private String prefix;
/**
* Construct a new license
* @param plugin The Main class [Javaplugin]
* @param prefix The prefix, like TPP or AF
* @param license The license from the config
*/
public License(Plugin plugin, String prefix, String license) {
this.prefix = prefix;
this.plugin = plugin;
this.license = license;
startTimer();
}
private void startTimer() {
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
if (!validateLicense()) {
Bukkit.getLogger().severe("[" + prefix + "] License is incorrect!");
}
}, 0, 20 * 60 * 60);
}
/**
* Check a license
*
* @return true/false
*/
private boolean validateLicense() {
String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/" + this.license;
@Nullable JsonObject res;
try {
res = sendGETRequestJSON(url);
} catch (IOException e) {
disable("GET_request_error");
return false;
}
if (res == null) {
disable("GET_request_error_2");
return false;
}
JsonObject dat = res.get("data").getAsJsonObject();
int stat = dat.get("status").getAsInt();
if (stat == 404) {
disable("status_404_error");
return false;
}
if (dat.get("licenseKey").isJsonNull()) {
disable("license_null_error");
return false;
}
if (!dat.get("licenseKey").getAsString().split("-")[0].contains(prefix)) {
disable("prefix_error");
return false;
}
switch(dat.get("status").getAsString()) {
case "2":
//activate?
break;
case "3":
//it's good
break;
default:
disable("status_error");
return false;
}
//Not activated? Activate it!
if (dat.get("timesActivated").isJsonNull() || dat.get("timesActivated").getAsString().equalsIgnoreCase("0")) {
return activate();
}
if (dat.get("expiresAt").isJsonNull()) {
disable("null_error");
return false;
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
try {
date = format.parse(dat.get("expiresAt").getAsString());
} catch (ParseException e) {
e.printStackTrace();
disable("null_error");
return false;
}
if (!(Objects.requireNonNull(date).after(new Date()))) {
disable("expired_error");
return false;
}
if (!dat.get("ipcheck").getAsBoolean()) {
disable("ip_error");
return false;
}
if (dat.get("port").isJsonNull()) {
disable("null_error");
return false;
}
try {
int por = dat.get("port").getAsInt();
if (por != Bukkit.getServer().getPort()) {
disable("port_error");
return false;
}
} catch(NumberFormatException e) {
disable("null_error");
return false;
}
return true;
}
/**
* Activate the license (private)
*
* @return true/false
*/
private boolean activate() {
String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/activate/" + this.license + "?port=" + Bukkit.getServer().getPort();
@Nullable JsonObject res;
try {
res = sendGETRequestJSON(url);
} catch (IOException e) {
e.printStackTrace();
disable("GET_request_error");
return false;
}
if (res == null) {
disable("GET_request_error_2");
return false;
}
JsonObject dat = res.get("data").getAsJsonObject();
int stat = dat.get("status").getAsInt();
if (stat == 404) {
disable("status_404_error");
return false;
}
if (dat.get("licenseKey").isJsonNull()) {
disable("license_null_error");
return false;
}
if (!dat.get("licenseKey").getAsString().split("-")[0].contains(prefix)) {
disable("prefix_error");
return false;
}
switch(dat.get("status").getAsString()) {
case "2":
//activate?
break;
case "3":
//it's good
break;
default:
disable("status_error");
return false;
}
//Still not activated? Something is wrong...
return !dat.get("timesActivated").isJsonNull() && !dat.get("timesActivated").getAsString().equalsIgnoreCase("0");
}
/**
* Disable the plugin (private)
*
* @param reason The disabling reason
*/
private void disable(String reason) {
Bukkit.getScheduler().runTask(plugin, () -> {
Bukkit.getLogger().severe("[" + plugin.getName() + "] " + "Stopping plugin because licensing system check failed.");
Bukkit.getLogger().severe("[" + plugin.getName() + "] " + "Reason: " + reason);
Bukkit.getPluginManager().disablePlugin(plugin);
});
}
/**
* Send an GET request with JSONObject response
*
* @param uri The URL
*
* @return The JSONObject
* @throws IOException URL errors
*/
@Nullable
private JsonObject sendGETRequestJSON(String uri) throws IOException {
URL url = new URL(uri);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
String authStringEnc = "Y2tfMGEzNWEzMWE2NzExNmM3NDg2MGEwYTJhNjUxNGVjZjM4NTBmM2JmMDpjc185NmYxZGNlYjI4MWRkZDExOTBjMzQ3ZjJjYzMwMGNjZTIzYWNhODI1";
con.setRequestProperty("Authorization", "Basic " + authStringEnc);
int code = con.getResponseCode();
if (code == 404) {
disable("404_error");
return null;
}
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
JsonParser parser = new JsonParser();
return parser.parse(response.toString()).getAsJsonObject();
}
}

View file

@ -0,0 +1,52 @@
package nl.sbdeveloper.themeparkplus.util;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public class WEUtil {
private static boolean newVersion;
private static WorldEditPlugin wep;
public WEUtil() {
newVersion = XMaterial.isNewVersion();
wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
}
@Nullable
public static Region getSelection(Player p) {
if (newVersion) {
LocalSession l = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(p));
Region s;
try {
s = l.getSelection(l.getSelectionWorld());
} catch (IncompleteRegionException e) {
return null;
}
if (s instanceof Polygonal2DSelection) {
Polygonal2DSelection polySel = (Polygonal2DSelection) s;
int minY = polySel.getNativeMinimumPoint().getBlockY();
int maxY = polySel.getNativeMaximumPoint().getBlockY();
return new Polygonal2DRegion((World) polySel.getWorld(), polySel.getNativePoints(), minY, maxY);
}
} else {
Selection sel = wep.getSelection(p);
if (sel instanceof Polygonal2DSelection) {
Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
int minY = polySel.getNativeMinimumPoint().getBlockY();
int maxY = polySel.getNativeMaximumPoint().getBlockY();
return new Polygonal2DRegion((World) polySel.getWorld(), polySel.getNativePoints(), minY, maxY);
}
}
return null;
}
}

File diff suppressed because it is too large Load diff