13
0
Dieser Commit ist enthalten in:
Lixfel 2022-01-29 11:55:59 +01:00
Ursprung 3d7c0810c2
Commit 57e3d40300
4 geänderte Dateien mit 105 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -15,6 +15,7 @@ import lombok.Data;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -62,7 +63,7 @@ public class PortalCommand extends SWCommand {
if (noPermissions(player)) return;
PortalLocations tuple = getSelection(player);
if (tuple == null) return;
new Portal(portalName, tuple.k, tuple.v, portal -> new FightserverPortal(portal, gamemode.toLowerCase(), order, target));
new Portal(portalName, tuple.k, tuple.v, portal -> new FightserverPortal(portal, gamemode.toLowerCase(), order, target, new ArrayList<>(), new ArrayList<>()));
}
@Register({"create", "teleport"})
@ -82,6 +83,36 @@ public class PortalCommand extends SWCommand {
new Portal(portalName, tuple.k, tuple.v, portal -> new StackPortal(portal, portalDestination, String.join(" ", command)));
}
@Register({"addblue"})
public void portalAddBlue(Player player, Portal portal) {
FightserverPortal handler = (FightserverPortal) portal.getHandler();
handler.addBlue(locationOfPlayer(player));
}
@Register({"addred"})
public void portalAddRed(Player player, Portal portal) {
FightserverPortal handler = (FightserverPortal) portal.getHandler();
handler.addRed(locationOfPlayer(player));
}
private Location locationOfPlayer(Player player) {
Location l = player.getLocation();
l.setYaw(((CraftPlayer)player).getHandle().getHeadRotation());
return l;
}
@Register({"removeblue"})
public void portalRemoveBlue(Player player, Portal portal, int i) {
FightserverPortal handler = (FightserverPortal) portal.getHandler();
handler.removeBlue(i-1);
}
@Register({"removered"})
public void portalRemoveRed(Player player, Portal portal, int i) {
FightserverPortal handler = (FightserverPortal) portal.getHandler();
handler.removeRed(i-1);
}
@Register("remove")
public void portalRemove(Player player, Portal portal) {
if (noPermissions(player)) return;

Datei anzeigen

@ -58,6 +58,10 @@ public class NPC {
private static final Reflection.FieldAccessor<Double> namedSpawnZ = Reflection.getField(namedSpawnPacket, double.class, 2);
private static final Reflection.FieldAccessor<Byte> namedSpawnYaw = Reflection.getField(namedSpawnPacket, byte.class, 0);
private static final Reflection.FieldAccessor<Byte> namedSpawnPitch = Reflection.getField(namedSpawnPacket, byte.class, 1);
private static final Class<?> headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation");
private static final Reflection.ConstructorInvoker headRotationConstructor = Reflection.getConstructor(headRotationPacket);
private static final Reflection.FieldAccessor<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0);
private static final Reflection.FieldAccessor<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0);
private final Displayable display;
@ -68,6 +72,7 @@ public class NPC {
private final Object addPlayerInfo;
private final Object namedSpawn;
private final Object headRotation;
private final Object removePlayerInfo;
private final Object destroy;
@ -76,6 +81,7 @@ public class NPC {
this.uuid = uuid;
this.name = name;
this.location = location;
byte yaw = (byte)(int)(location.getYaw() * 256.0 / 360.0);
GameProfile profile = new GameProfile(uuid, name);
addPlayerInfo = playerInfoPacket(addPlayer, profile);
@ -88,15 +94,20 @@ public class NPC {
namedSpawnX.set(namedSpawn, location.getX());
namedSpawnY.set(namedSpawn, location.getY());
namedSpawnZ.set(namedSpawn, location.getZ());
namedSpawnYaw.set(namedSpawn, (byte)(int)(location.getYaw() * 256.0 / 360.0));
namedSpawnYaw.set(namedSpawn, yaw);
namedSpawnPitch.set(namedSpawn, (byte)(int)(location.getPitch() * 256.0 / 360.0));
headRotation = headRotationConstructor.invoke();
headRotationEntity.set(headRotation, entityId);
headRotationYaw.set(headRotation, yaw);
display = new Displayable(location, this::show, this::hide);
}
private void show(Player player) {
TinyProtocol.instance.sendPacket(player, addPlayerInfo);
TinyProtocol.instance.sendPacket(player, namedSpawn);
TinyProtocol.instance.sendPacket(player, headRotation);
}
private void hide(Player player) {

Datei anzeigen

@ -20,8 +20,11 @@
package de.steamwar.lobby.portal;
import de.steamwar.comms.packets.FightInfoPacket;
import de.steamwar.lobby.display.Hologram;
import de.steamwar.lobby.Fightserver;
import de.steamwar.lobby.LobbySystem;
import de.steamwar.lobby.display.Hologram;
import de.steamwar.lobby.display.NPC;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@ -45,29 +48,41 @@ public class FightserverPortal implements PortalHandler, Comparable<FightserverP
private final String gamemode;
private final int order;
private final String target;
private final Hologram hologram;
private final List<Location> bluePlayers;
private final List<Location> redPlayers;
private Fightserver server = null;
private PortalHandler handler = new DummyPortal();
public FightserverPortal(Map<String, Object> section, Portal portal) {
this.portal = portal;
this.gamemode = (String) section.get("group");
this.target = (String) section.get("target");
this.order = (int) section.get("order");
hologram = new Hologram(null, portal.getPos1().clone().add(portal.getOrientation().clone().divide(new Vector(2, 2, 2))), "");
private final Hologram hologram;
private final List<NPC> blueNPCs = new ArrayList<>();
private final List<NPC> redNPCs = new ArrayList<>();
init();
public FightserverPortal(Map<String, Object> section, Portal portal) {
this(
portal,
(String) section.get("group"),
(int) section.get("order"),
(String) section.get("target"),
(List<Location>) section.getOrDefault("bluePlayers", new ArrayList<>()),
(List<Location>) section.getOrDefault("redPlayers", new ArrayList<>())
);
}
public FightserverPortal(Portal portal, String gamemode, int order, String target) {
public FightserverPortal(Portal portal, String gamemode, int order, String target, List<Location> bluePlayers, List<Location> redPlayers) {
this.portal = portal;
this.gamemode = gamemode;
this.order = order;
this.target = target;
this.bluePlayers = bluePlayers;
this.redPlayers = redPlayers;
hologram = new Hologram(null, portal.getPos1().clone().add(portal.getOrientation().clone().divide(new Vector(2, 2, 2))), "");
init();
setServer(null);
List<FightserverPortal> list = portals.computeIfAbsent(gamemode, mode -> new ArrayList<>());
list.add(this);
list.sort(null);
}
public void setServer(Fightserver server) {
@ -93,19 +108,44 @@ public class FightserverPortal implements PortalHandler, Comparable<FightserverP
}
public void updateBluePlayers() {
updateNPCs(bluePlayers, blueNPCs, server != null ? server.current().getBluePlayers() : Collections.emptyList());
}
public void updateRedPlayers() {
updateNPCs(redPlayers, redNPCs, server != null ? server.current().getRedPlayers() : Collections.emptyList());
}
private void init() {
setServer(null);
private void updateNPCs(List<Location> locations, List<NPC> npcs, List<Integer> players) {
npcs.forEach(NPC::delete);
npcs.clear();
List<FightserverPortal> list = portals.computeIfAbsent(gamemode, mode -> new ArrayList<>());
list.add(this);
list.sort(null);
for(int i = 0; i < players.size(); i++) {
if(i >= locations.size())
break;
SteamwarUser user = SteamwarUser.get(players.get(i));
npcs.add(new NPC(locations.get(i), user.getUUID(), user.getUserName()));
}
}
public void addBlue(Location location) {
bluePlayers.add(location);
LobbySystem.config().save();
}
public void addRed(Location location) {
redPlayers.add(location);
LobbySystem.config().save();
}
public void removeBlue(int i) {
bluePlayers.remove(i);
LobbySystem.config().save();
}
public void removeRed(int i) {
redPlayers.remove(i);
LobbySystem.config().save();
}
private void setHandler(PortalHandler handler) {
@ -123,6 +163,8 @@ public class FightserverPortal implements PortalHandler, Comparable<FightserverP
map.put("group", gamemode);
map.put("order", order);
map.put("target", target);
map.put("bluePlayers", bluePlayers);
map.put("redPlayers", redPlayers);
}
@Override

Datei anzeigen

@ -151,7 +151,7 @@ public class Portal implements PortalHandler, ConfigurationSerializable {
return id;
}
PortalHandler getHandler() {
public PortalHandler getHandler() {
return handler;
}