13
0

Update TeamPlayer on DB update ever hour
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-03-26 15:40:51 +01:00
Ursprung c6beebed05
Commit 1de921b7ff
2 geänderte Dateien mit 34 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -172,6 +172,9 @@ public class NPC {
movePacketX.set(move, location.getX()); movePacketX.set(move, location.getX());
movePacketY.set(move, location.getY()); movePacketY.set(move, location.getY());
movePacketZ.set(move, location.getZ()); movePacketZ.set(move, location.getZ());
namedSpawnX.set(namedSpawn, location.getX());
namedSpawnY.set(namedSpawn, location.getY());
namedSpawnZ.set(namedSpawn, location.getZ());
movePacketYaw.set(move, yaw); movePacketYaw.set(move, yaw);
movePacketPitch.set(move, (byte)(int)(location.getPitch() * 256.0 / 360.0)); movePacketPitch.set(move, (byte)(int)(location.getPitch() * 256.0 / 360.0));
movePacketOnGround.set(move, true); movePacketOnGround.set(move, true);

Datei anzeigen

@ -36,11 +36,10 @@ import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.concurrent.atomic.AtomicInteger;
import java.util.List;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors;
public class TeamPlayer extends BasicListener { public class TeamPlayer extends BasicListener {
@ -59,12 +58,13 @@ public class TeamPlayer extends BasicListener {
} }
private static final List<Cuboid> cuboids = new ArrayList<>(); private static final List<Cuboid> cuboids = new ArrayList<>();
static { static {
cuboids.add(new Cuboid(1509, 52, 1464, 1510, 58, 1469)); cuboids.add(new Cuboid(1509, 52, 1464, 1510, 58, 1469));
cuboids.add(new Cuboid(1538, 52, 1464, 1539, 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(1518, 55, 1433, 1530, 60, 1434));
cuboids.add(new Cuboid(1587, 52, 1471, 1588, 56, 1475)); 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); 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) { private static void forceLoad(World world, boolean setTo) {
for (int x = -10; x < 10; x++) { for (int x = -10; x < 10; x++) {
for (int z = -10; z < 10; z++) { 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); spawnTeamPlayer(world, user);
}); });
AtomicInteger count = new AtomicInteger();
LobbySystem.getPlugin().getLogger().log(Level.INFO, "Loaded " + entities.size() + " team players"); LobbySystem.getPlugin().getLogger().log(Level.INFO, "Loaded " + entities.size() + " team players");
Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> {
count.incrementAndGet();
if (count.get() % 20 * 60 * 60 == 0) {
count.set(0);
List<SteamwarUser> 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<String> 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 -> { world.getEntitiesByClasses(Villager.class).forEach(entity -> {
NPC npc = entities.get(entity.getName()); NPC npc = entities.get(entity.getName());
if (npc != null) { if (npc != null) {