13
0
Dieser Commit ist enthalten in:
Lixfel 2020-11-15 12:08:58 +01:00
Ursprung 1c1b55efac
Commit 4fa02d1296

Datei anzeigen

@ -41,7 +41,9 @@ public abstract class REntity {
protected REntity(int internalId, Entity entity){ protected REntity(int internalId, Entity entity){
this.internalId = internalId; this.internalId = internalId;
this.entity = entity; this.entity = entity;
entities.put(internalId, this); synchronized(entities){
entities.put(internalId, this);
}
for(Player player : Bukkit.getOnlinePlayers()){ for(Player player : Bukkit.getOnlinePlayers()){
sendToPlayer(player); sendToPlayer(player);
@ -49,17 +51,15 @@ public abstract class REntity {
} }
public static void playerJoins(Player player){ public static void playerJoins(Player player){
for(REntity entity : entities.values()){ synchronized(entities){
entity.sendToPlayer(player); for(REntity entity : entities.values()){
entity.sendLocation(player); entity.sendToPlayer(player);
entity.sendLocation(player);
}
} }
} }
protected static EntityLiving getShooter(){ protected static EntityLiving getShooter(){
for(REntity entity : entities.values()){
if(entity.entity instanceof EntityLiving)
return (EntityLiving) entity.entity;
}
return ((CraftPlayer)Bukkit.getOnlinePlayers().iterator().next()).getHandle(); return ((CraftPlayer)Bukkit.getOnlinePlayers().iterator().next()).getHandle();
} }
@ -69,10 +69,12 @@ public abstract class REntity {
public static void removeAll(){ public static void removeAll(){
int entity_counter = 0; int entity_counter = 0;
while(!entities.isEmpty()){ synchronized (entities){
entity_counter++; while(!entities.isEmpty()){
REntity entity = entities.values().iterator().next(); entity_counter++;
entity.remove(); REntity entity = entities.values().iterator().next();
entity.remove();
}
} }
System.out.println("Has to remove manually " + entity_counter + " entities!"); System.out.println("Has to remove manually " + entity_counter + " entities!");
} }
@ -96,7 +98,9 @@ public abstract class REntity {
connection.sendPacket(packet); connection.sendPacket(packet);
} }
Bukkit.getScheduler().runTask(SpectateSystem.get(), entity::die); Bukkit.getScheduler().runTask(SpectateSystem.get(), entity::die);
entities.remove(internalId); synchronized (entities){
entities.remove(internalId);
}
} }
public void sneak(boolean sneaking) { public void sneak(boolean sneaking) {