diff --git a/src/de/steamwar/lobby/display/NPC.java b/src/de/steamwar/lobby/display/NPC.java index 2040d5f..de0abfc 100644 --- a/src/de/steamwar/lobby/display/NPC.java +++ b/src/de/steamwar/lobby/display/NPC.java @@ -172,6 +172,9 @@ public class NPC { movePacketX.set(move, location.getX()); movePacketY.set(move, location.getY()); movePacketZ.set(move, location.getZ()); + namedSpawnX.set(namedSpawn, location.getX()); + namedSpawnY.set(namedSpawn, location.getY()); + namedSpawnZ.set(namedSpawn, location.getZ()); movePacketYaw.set(move, yaw); movePacketPitch.set(move, (byte)(int)(location.getPitch() * 256.0 / 360.0)); movePacketOnGround.set(move, true); diff --git a/src/de/steamwar/lobby/team/TeamPlayer.java b/src/de/steamwar/lobby/team/TeamPlayer.java index 41fefb1..56fbe46 100644 --- a/src/de/steamwar/lobby/team/TeamPlayer.java +++ b/src/de/steamwar/lobby/team/TeamPlayer.java @@ -36,11 +36,10 @@ import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; +import java.util.stream.Collectors; public class TeamPlayer extends BasicListener { @@ -59,12 +58,13 @@ public class TeamPlayer extends BasicListener { } private static final List cuboids = new ArrayList<>(); + static { cuboids.add(new Cuboid(1509, 52, 1464, 1510, 58, 1469)); cuboids.add(new Cuboid(1538, 52, 1464, 1539, 58, 1469)); cuboids.add(new Cuboid(1518, 55, 1433, 1530, 60, 1434)); cuboids.add(new Cuboid(1587, 52, 1471, 1588, 56, 1475)); - cuboids.add(new Cuboid(1479, 52, 1461, 1478, 56, 1463)); + cuboids.add(new Cuboid(1478, 52, 1461, 1479, 56, 1463)); } private static final World world = Bukkit.getWorlds().get(0); @@ -92,7 +92,7 @@ public class TeamPlayer extends BasicListener { 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); + world.setChunkForceLoaded(95 + x, 93 + z, setTo); } } } @@ -106,8 +106,33 @@ public class TeamPlayer extends BasicListener { spawnTeamPlayer(world, user); }); + AtomicInteger count = new AtomicInteger(); LobbySystem.getPlugin().getLogger().log(Level.INFO, "Loaded " + entities.size() + " team players"); Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { + count.incrementAndGet(); + if (count.get() % 20 * 60 * 60 == 0) { + count.set(0); + List steamwarUsers = SteamwarUser.getServerTeam(); + AtomicInteger added = new AtomicInteger(); + steamwarUsers.forEach(user -> { + if (!entities.containsKey(user.getUserName())) { + spawnTeamPlayer(world, user); + added.incrementAndGet(); + } + }); + AtomicInteger removed = new AtomicInteger(); + List names = steamwarUsers.stream().map(SteamwarUser::getUserName).collect(Collectors.toList()); + new HashSet<>(entities.keySet()).stream().filter(name -> !names.contains(name)).forEach(name -> { + world.getEntitiesByClasses(Villager.class).forEach(entity -> { + if (entity.getName().equals(name)) { + entity.remove(); + } + }); + entities.remove(name).delete(); + removed.incrementAndGet(); + }); + LobbySystem.getPlugin().getLogger().log(Level.INFO, "Loaded " + added.get() + " team players, removed " + removed.get() + " team players"); + } world.getEntitiesByClasses(Villager.class).forEach(entity -> { NPC npc = entities.get(entity.getName()); if (npc != null) {