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;
synchronized(entities){
entities.put(internalId, this); 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){
synchronized(entities){
for(REntity entity : entities.values()){ for(REntity entity : entities.values()){
entity.sendToPlayer(player); entity.sendToPlayer(player);
entity.sendLocation(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,11 +69,13 @@ public abstract class REntity {
public static void removeAll(){ public static void removeAll(){
int entity_counter = 0; int entity_counter = 0;
synchronized (entities){
while(!entities.isEmpty()){ while(!entities.isEmpty()){
entity_counter++; entity_counter++;
REntity entity = entities.values().iterator().next(); REntity entity = entities.values().iterator().next();
entity.remove(); entity.remove();
} }
}
System.out.println("Has to remove manually " + entity_counter + " entities!"); System.out.println("Has to remove manually " + entity_counter + " entities!");
} }
@ -96,8 +98,10 @@ public abstract class REntity {
connection.sendPacket(packet); connection.sendPacket(packet);
} }
Bukkit.getScheduler().runTask(SpectateSystem.get(), entity::die); Bukkit.getScheduler().runTask(SpectateSystem.get(), entity::die);
synchronized (entities){
entities.remove(internalId); entities.remove(internalId);
} }
}
public void sneak(boolean sneaking) { public void sneak(boolean sneaking) {
entity.setSneaking(sneaking); entity.setSneaking(sneaking);