mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 12:06:15 +01:00
Added location reflection methods (ours -> bukkit), should not be used often -> Got to add wrappers.
This commit is contained in:
parent
5b3a2d58b4
commit
54d33bb21c
@ -1,5 +1,8 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Created 2015-02-11 for PlotSquared
|
||||
*
|
||||
@ -156,4 +159,22 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
public String toString() {
|
||||
return "\"plotsquaredlocation\":{" + "\"x\":" + x + ",\"y\":" + y + ",\"z\":" + z + ",\"yaw\":" + yaw + ",\"pitch\":" + pitch + ",\"world\":\"" + world + "\"}";
|
||||
}
|
||||
|
||||
private Object getBukkitWorld() {
|
||||
try {
|
||||
Class clazz = Class.forName("org.bukkit.Bukkit");
|
||||
return clazz.getMethod("getWorld", String.class).invoke(null, world);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object toBukkitLocation() {
|
||||
try {
|
||||
Constructor constructor = Class.forName("org.bukkit.Location").getConstructor(Class.forName("org.bukkit.World"), double.class, double.class, double.class, float.class, float.class);
|
||||
return constructor.newInstance(Class.forName("org.bukkit.World").cast(getBukkitWorld()), x, y, z, yaw, pitch);
|
||||
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user