SteamWar/BauSystem2.0
Archiviert
12
0

Add /warp feature #55

Zusammengeführt
YoyoNow hat 8 Commits von warp nach master 2021-11-12 19:33:24 +01:00 zusammengeführt
Nur Änderungen aus Commit 8b3b2f9ddb werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -31,6 +31,7 @@ import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
@Getter @Getter
public class Warp { public class Warp {
@ -38,22 +39,19 @@ public class Warp {
private final Instant created; private final Instant created;
private final YAPIONObject object; private final YAPIONObject object;
private String name; private String name;
private double x; private Location location;
private double y;
private double z;
private float yaw;
private float pitch;
private Material mat; private Material mat;
private String creator; private String creator;
private Warp(YAPIONObject object) { private Warp(YAPIONObject object) {
this.object = object; this.object = object;
name = object.getPlainValue("name"); name = object.getPlainValue("name");
x = object.getPlainValue("x"); double x = object.getPlainValue("x");
y = object.getPlainValue("y"); double y = object.getPlainValue("y");
z = object.getPlainValue("z"); double z = object.getPlainValue("z");
yaw = object.getPlainValue("yaw"); float yaw = object.getPlainValue("yaw");
pitch = object.getPlainValue("pitch"); float pitch = object.getPlainValue("pitch");
location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch);
mat = Material.getMaterial(object.getPlainValue("material")); mat = Material.getMaterial(object.getPlainValue("material"));
creator = object.getPlainValue("owner"); creator = object.getPlainValue("owner");
created = Instant.ofEpochSecond(object.getPlainValue("time")); created = Instant.ofEpochSecond(object.getPlainValue("time"));
@ -80,11 +78,7 @@ public class Warp {
public static Warp createWarp(String name, double x, double y, double z, float yaw, float pitch, Material mat, String creator) { public static Warp createWarp(String name, double x, double y, double z, float yaw, float pitch, Material mat, String creator) {
Warp warp = new Warp(); Warp warp = new Warp();
warp.setName(name); warp.setName(name);
warp.setX(x); warp.setLocation(new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch));
warp.setY(y);
warp.setZ(z);
warp.setYaw(yaw);
warp.setPitch(pitch);
warp.setMat(mat); warp.setMat(mat);
warp.setCreator(creator); warp.setCreator(creator);
YAPIONArray warpsObject = WorldData.getWarpData(); YAPIONArray warpsObject = WorldData.getWarpData();
@ -103,31 +97,6 @@ public class Warp {
object.add("name", name); object.add("name", name);
} }
public void setX(double x) {
this.x = x;
object.add("x", x);
}
public void setY(double y) {
this.y = y;
object.add("y", y);
}
public void setZ(double z) {
this.z = z;
object.add("z", z);
}
public void setYaw(float yaw) {
this.yaw = yaw;
object.add("yaw", yaw);
}
public void setPitch(float pitch) {
this.pitch = pitch;
object.add("pitch", pitch);
}
public void setMat(Material mat) { public void setMat(Material mat) {
this.mat = mat; this.mat = mat;
object.add("material", mat.name()); object.add("material", mat.name());
@ -138,18 +107,55 @@ public class Warp {
object.add("owner", creator); object.add("owner", creator);
} }
public void setLocation(Location location) {
this.location = location;
}
public void delete() { public void delete() {
YAPIONArray warpsObject = WorldData.getWarpData(); YAPIONArray warpsObject = WorldData.getWarpData();
warpsObject.removeIf(yapionAnyType -> ((YAPIONObject) yapionAnyType).getPlainValue("name").equals(name)); warpsObject.removeIf(yapionAnyType -> ((YAPIONObject) yapionAnyType).getPlainValue("name").equals(name));
} }
public Location toLocation() { public void teleport(Player player) {
return new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
} }
public void teleport(Player player) { public void normalize(String str) {
Location loc = toLocation(); /*
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); x > x
player.playSound(loc, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1); y > y
z > z
w > yaw
p > pitch
*/
if(str.contains("x")) {
location.setX(0.5 + location.getBlockX());
}
if(str.contains("y")) {
location.setY(location.getBlockY());
}
if(str.contains("z")) {
location.setZ(0.5 + location.getBlockZ());
}
if(str.contains("w")) {
location.setYaw(Location.normalizeYaw(location.getYaw()));
}
if(str.contains("p")) {
location.setPitch(Location.normalizePitch(location.getPitch()));
}
save();
}
private void save() {
object.add("name", name);
YAPIONObject loc = new YAPIONObject();
loc.add("x", location.getX());
loc.add("y", location.getY());
loc.add("z", location.getZ());
loc.add("yaw", location.getYaw());
loc.add("pitch", location.getPitch());
object.add("location", loc);
object.add("creator", creator);
} }
} }