SteamWar/BauSystem2.0
Archiviert
12
0

Update Warp and WarpCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-11-12 17:36:00 +01:00
Ursprung 8535213deb
Commit ce532fbb6d
5 geänderte Dateien mit 62 neuen und 88 gelöschten Zeilen

Datei anzeigen

@ -565,7 +565,6 @@ WARP_LIST_PREVIOUS_PAGE=§eVorherige Seite
WARP_LIST_PAGE=§e Seite ({0}/{1}) »» WARP_LIST_PAGE=§e Seite ({0}/{1}) »»
WARP_LIST_NEXT_PAGE=§eNächste Seite WARP_LIST_NEXT_PAGE=§eNächste Seite
WARP_INFO_NAME=§7Name: §e{0} WARP_INFO_NAME=§7Name: §e{0}
WARP_INFO_CREATOR=§7Ersteller: §e{0}
WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt
WARP_HELP_2=§8/§ewarp §8[§7Name§8] - §7Teleportiere dich zu einen Warp-Punkt WARP_HELP_2=§8/§ewarp §8[§7Name§8] - §7Teleportiere dich zu einen Warp-Punkt
WARP_HELP_3=§8/§ewarp info §8[§7Name§8] - §7Infos zu einem Punkt WARP_HELP_3=§8/§ewarp info §8[§7Name§8] - §7Infos zu einem Punkt

Datei anzeigen

@ -24,28 +24,29 @@ import lombok.Getter;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import java.time.Instant; import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
// TODO: Rewrite! // TODO: Rewrite!
@Getter @Getter
public class Warp { public class Warp {
private final YAPIONObject object; private static Map<String, Warp> warpMap = new HashMap<>();
private String name; private String name;
private Location location; private Location location;
private Material mat; private Material mat;
private String creator;
private Warp(YAPIONObject object) { public Warp(String name, Player player) {
this.object = object; this.name = name;
name = object.getPlainValue("name"); this.location = player.getLocation();
this.mat = Material.COMPASS;
warpMap.put(name, this);
}
public Warp(String name, YAPIONObject object) {
this.name = name;
double x = object.getPlainValue("x"); double x = object.getPlainValue("x");
double y = object.getPlainValue("y"); double y = object.getPlainValue("y");
double z = object.getPlainValue("z"); double z = object.getPlainValue("z");
@ -53,55 +54,34 @@ public class Warp {
float pitch = object.getPlainValue("pitch"); float pitch = object.getPlainValue("pitch");
location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, 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"); warpMap.put(name, this);
} }
private Warp() { public YAPIONObject output() {
object = new YAPIONObject(); YAPIONObject yapionObject = new YAPIONObject();
yapionObject.add("x", location.getX());
yapionObject.add("y", location.getY());
yapionObject.add("z", location.getZ());
yapionObject.add("yaw", location.getYaw());
yapionObject.add("pitch", location.getPitch());
yapionObject.add("material", mat.toString());
return yapionObject;
}
public static Set<String> getWarpNames() {
return warpMap.keySet();
} }
public static List<Warp> getWarps() { public static List<Warp> getWarps() {
List<Warp> warpList = new ArrayList<>(); return new ArrayList<>(warpMap.values());
YAPIONArray warpsObject = WorldData.getWarpData();
warpsObject.forEach(yapionAnyType -> warpList.add(new Warp((YAPIONObject) yapionAnyType)));
return warpList;
} }
public static Optional<Warp> getWarp(String name) { public static Warp getWarp(String name) {
YAPIONArray warpsObject = WorldData.getWarpData(); return warpMap.get(name);
return warpsObject.stream().filter(yapionAnyType -> name.equals(((YAPIONObject) yapionAnyType).getPlainValueOrDefault("name", null))).map(yapionAnyType -> new Warp((YAPIONObject) yapionAnyType)).findAny();
}
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.setName(name);
warp.setLocation(new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch));
warp.setMat(mat);
warp.setCreator(creator);
YAPIONArray warpsObject = WorldData.getWarpData();
warpsObject.add(warp.object);
return warp;
}
public static Warp createWarp(String name, Player player, Material mat) {
Location loc = player.getLocation();
return createWarp(name, loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), mat, player.getName());
}
public void setName(String name) {
this.name = name;
object.add("name", name);
} }
public void setMat(Material mat) { public void setMat(Material mat) {
this.mat = mat; this.mat = mat;
object.add("material", mat.name());
}
public void setCreator(String creator) {
this.creator = creator;
object.add("owner", creator);
} }
public void setLocation(Location location) { public void setLocation(Location location) {
@ -109,37 +89,12 @@ public class Warp {
} }
public void delete() { public void delete() {
YAPIONArray warpsObject = WorldData.getWarpData(); warpMap.remove(name);
warpsObject.removeIf(yapionAnyType -> ((YAPIONObject) yapionAnyType).getPlainValue("name").equals(name)); WorldData.getWarpData().remove(name);
} }
public void teleport(Player player) { public void teleport(Player player) {
player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN); player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1); player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
} }
public void normalize(String str) {
/*
x > x
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()));
}
}
} }

Datei anzeigen

@ -21,8 +21,11 @@ package de.steamwar.bausystem.features.warp;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.Disable;
import de.steamwar.bausystem.linkage.Enable;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
@ -33,12 +36,17 @@ import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
public class WarpCommand extends SWCommand { @Linked(LinkageType.DISABLE_LINK)
@Linked(LinkageType.ENABLE_LINK)
public class WarpCommand extends SWCommand implements Disable, Enable {
private static final String[] FORBIDDEN_NAMES = new String[]{ private static final String[] FORBIDDEN_NAMES = new String[]{
"add", "create", "delete", "list", "info", "gui" "add", "create", "delete", "list", "info", "gui"
@ -50,9 +58,7 @@ public class WarpCommand extends SWCommand {
@ClassMapper(Warp.class) @ClassMapper(Warp.class)
public static TypeMapper<Warp> getWarpMapper() { public static TypeMapper<Warp> getWarpMapper() {
return SWCommandUtils.createMapper(s -> Warp.getWarp(s).orElse(null), (commandSender, s) -> { return SWCommandUtils.createMapper(Warp::getWarp, (commandSender, s) -> new ArrayList<>(Warp.getWarpNames()));
return Warp.getWarps().stream().map(Warp::getName).collect(Collectors.toList());
});
} }
@Register(help = true) @Register(help = true)
@ -80,11 +86,11 @@ public class WarpCommand extends SWCommand {
return; return;
} }
} }
if (Warp.getWarp(name).isPresent()) { if (Warp.getWarp(name) != null) {
BauSystem.MESSAGE.send("WARP_EXISTS", player, name); BauSystem.MESSAGE.send("WARP_EXISTS", player, name);
return; return;
} }
Warp.createWarp(name, player, Material.BEACON); new Warp(name, player);
BauSystem.MESSAGE.send("WARP_CREATED", player, name); BauSystem.MESSAGE.send("WARP_CREATED", player, name);
} }
@ -150,7 +156,6 @@ public class WarpCommand extends SWCommand {
public void warpInfo(Player player, Warp warp) { public void warpInfo(Player player, Warp warp) {
BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName()); BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName());
BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName()); BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName());
BauSystem.MESSAGE.sendPrefixless("WARP_INFO_CREATOR", player, warp.getCreator());
BauSystem.MESSAGE.sendPrefixless("WARP_LOC_X", player, warp.getLocation().getX()); BauSystem.MESSAGE.sendPrefixless("WARP_LOC_X", player, warp.getLocation().getX());
BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Y", player, warp.getLocation().getY()); BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Y", player, warp.getLocation().getY());
BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Z", player, warp.getLocation().getZ()); BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Z", player, warp.getLocation().getZ());
@ -178,4 +183,19 @@ public class WarpCommand extends SWCommand {
player.performCommand("warp list " + String.join(" ", args)); player.performCommand("warp list " + String.join(" ", args));
} }
} }
@Override
public void enable() {
WorldData.getWarpData().forEach((name, yapionAnyType) -> {
new Warp(name, (YAPIONObject) yapionAnyType);
});
}
@Override
public void disable() {
YAPIONObject yapionObject = WorldData.getWarpData();
for (Warp warp : Warp.getWarps()) {
yapionObject.add(warp.getName(), warp.output());
}
}
} }

Datei anzeigen

@ -47,8 +47,8 @@ public enum LinkageType {
// NORMAL // NORMAL
COMMAND(-1, false, SWCommand.class::isAssignableFrom), COMMAND(-1, false, SWCommand.class::isAssignableFrom),
ENABLE_LINK(0, false, Enable.class::isInstance, o -> ((Enable) o).enable()), ENABLE_LINK(0, false, Enable.class::isAssignableFrom, o -> ((Enable) o).enable()),
DISABLE_LINK(0, true, Disable.class::isInstance, o -> ((Disable) o).disable()), DISABLE_LINK(0, true, Disable.class::isAssignableFrom, o -> ((Disable) o).disable()),
PLAIN(1, false, clazz -> true), PLAIN(1, false, clazz -> true),
LISTENER(2, false, Listener.class::isAssignableFrom, o -> Bukkit.getPluginManager().registerEvents((Listener) o, BauSystem.getInstance())), LISTENER(2, false, Listener.class::isAssignableFrom, o -> Bukkit.getPluginManager().registerEvents((Listener) o, BauSystem.getInstance())),
UNLINK_LISTENER(2, true, Listener.class::isAssignableFrom, o -> HandlerList.unregisterAll((Listener) o)), UNLINK_LISTENER(2, true, Listener.class::isAssignableFrom, o -> HandlerList.unregisterAll((Listener) o)),

Datei anzeigen

@ -48,8 +48,8 @@ public class WorldData {
return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject()); return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject());
} }
public YAPIONArray getWarpData() { public YAPIONObject getWarpData() {
return getWorldData().getYAPIONArrayOrSetDefault("warps", new YAPIONArray()); return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject());
} }
public YAPIONObject getSimulatorData() { public YAPIONObject getSimulatorData() {