TeamHalle #6
@ -22,8 +22,13 @@ package de.steamwar.lobby.display;
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.v1_15_R1.DataWatcher;
|
||||
import net.minecraft.server.v1_15_R1.DataWatcherRegistry;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -108,14 +113,14 @@ public class NPC {
|
||||
return packet;
|
||||
}
|
||||
|
||||
private static Object skinPartsDataWatcherObject = getDataWatcherObject(17, Byte.class);
|
||||
private static Object skinPartsDataWatcherObject = getDataWatcherObject(16, Byte.class);
|
||||
|
||||
private final Displayable display;
|
||||
|
||||
private final int entityId;
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private final Location location;
|
||||
private Location location;
|
||||
|
||||
private final Object addPlayerInfo;
|
||||
private final Object namedSpawn;
|
||||
@ -156,6 +161,7 @@ public class NPC {
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
byte yaw = (byte)(int)(location.getYaw() * 256.0 / 360.0);
|
||||
headRotationYaw.set(headRotation, yaw);
|
||||
move = movePacketConstructor.invoke();
|
||||
@ -178,9 +184,7 @@ public class NPC {
|
||||
}
|
||||
|
||||
private void show(Player player) {
|
||||
if (Bukkit.getOnlinePlayers().stream().noneMatch(p -> p.getUniqueId().equals(uuid))) {
|
||||
TinyProtocol.instance.sendPacket(player, addPlayerInfo);
|
||||
}
|
||||
TinyProtocol.instance.sendPacket(player, addPlayerInfo);
|
||||
TinyProtocol.instance.sendPacket(player, namedSpawn);
|
||||
TinyProtocol.instance.sendPacket(player, headRotation);
|
||||
TinyProtocol.instance.sendPacket(player, skinParts);
|
||||
|
@ -37,28 +37,33 @@ import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeamPlayer extends BasicListener {
|
||||
|
||||
private static Map<Entity, NPC> entities = new HashMap<>();
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
private static final Map<String, NPC> entities = new HashMap<>();
|
||||
|
||||
public static void spawnTeamPlayer(World world, String name) {
|
||||
Location location = new Location(world, 1524.5, 52, 1481.5);
|
||||
NPC npc = new NPC(location, SteamwarUser.get(name).getUUID(), name);
|
||||
public static void spawnTeamPlayer(World world, SteamwarUser steamwarUser) {
|
||||
Location location = new Location(world, 1524.5, 52, 1484.5);
|
||||
String name = steamwarUser.getUserName();
|
||||
NPC npc = new NPC(location, steamwarUser.getUUID(), name);
|
||||
Villager villager = (Villager) world.spawnEntity(location, EntityType.VILLAGER);
|
||||
villager.setSilent(true);
|
||||
villager.setInvulnerable(true);
|
||||
villager.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false, false, false));
|
||||
villager.setCustomName(name);
|
||||
villager.setProfession(Villager.Profession.NITWIT);
|
||||
entities.put(villager, npc);
|
||||
entities.put(name, npc);
|
||||
}
|
||||
|
||||
public static void cleanup() {
|
||||
entities.forEach((entity, npc) -> entity.remove());
|
||||
forceLoad(world, true);
|
||||
world.getEntitiesByClasses(Villager.class).forEach(Entity::remove);
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
||||
forceLoad(world, false);
|
||||
}
|
||||
|
||||
private void forceLoad(World world, boolean setTo) {
|
||||
private static void forceLoad(World world, boolean setTo) {
|
||||
for (int x = -10; x < 10; x++) {
|
||||
for (int z = -10; z < 10; z++) {
|
||||
world.setChunkForceLoaded(95 + x , 93 + z, setTo);
|
||||
@ -67,18 +72,21 @@ public class TeamPlayer extends BasicListener {
|
||||
}
|
||||
|
||||
{
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Und das wartest du bei jeder Teammitgliedänderung? bitte aus der Datenbank holen... Und das wartest du bei jeder Teammitgliedänderung? bitte aus der Datenbank holen...
YoyoNow
hat
Ja ich werde es aus der DB holen, wo soll ich den SQL quack dafür schmeißen? Ja ich werde es aus der DB holen, wo soll ich den SQL quack dafür schmeißen?
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
forceLoad(world, true);
|
||||
world.getEntitiesByClasses(Villager.class).forEach(Entity::remove);
|
||||
forceLoad(world, false);
|
||||
|
||||
SteamwarUser.getServerTeam().forEach(user -> {
|
||||
spawnTeamPlayer(world, user.getUserName());
|
||||
spawnTeamPlayer(world, user);
|
||||
});
|
||||
|
||||
LobbySystem.getPlugin().getLogger().log(Level.INFO, "Loaded " + entities.size() + " team players");
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> {
|
||||
entities.forEach((entity, npc) -> {
|
||||
npc.setLocation(entity.getLocation());
|
||||
world.getEntitiesByClasses(Villager.class).forEach(entity -> {
|
||||
NPC npc = entities.get(entity.getName());
|
||||
if (npc != null) {
|
||||
npc.setLocation(entity.getLocation());
|
||||
}
|
||||
});
|
||||
}, 1L, 1L);
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Bitte nicht den Weltnamen hardcoden...
Ist die Lobby denn immer die
Bukkit.getWorlds().get(0)