3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-21 05:50:05 +01:00
Paper/nms-patches/WorldServer.patch

553 Zeilen
26 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/WorldServer.java
+++ b/net/minecraft/server/WorldServer.java
2019-12-21 02:06:18 +01:00
@@ -36,6 +36,17 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import java.util.logging.Level;
2019-04-23 04:00:00 +02:00
+import org.bukkit.Bukkit;
+import org.bukkit.WeatherType;
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.server.MapInitializeEvent;
+import org.bukkit.event.weather.LightningStrikeEvent;
2019-12-21 02:06:18 +01:00
+import org.bukkit.event.world.TimeSkipEvent;
+// CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public class WorldServer extends World {
2019-04-25 04:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
2019-12-21 02:06:18 +01:00
@@ -60,12 +71,29 @@
2019-04-23 04:00:00 +02:00
@Nullable
private final MobSpawnerTrader mobSpawnerTrader;
2019-04-23 04:00:00 +02:00
- public WorldServer(MinecraftServer minecraftserver, Executor executor, WorldNBTStorage worldnbtstorage, WorldData worlddata, DimensionManager dimensionmanager, GameProfilerFiller gameprofilerfiller, WorldLoadListener worldloadlistener) {
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ private int tickPosition;
+
+ // Add env and gen to constructor
2019-04-23 04:00:00 +02:00
+ public WorldServer(MinecraftServer minecraftserver, Executor executor, WorldNBTStorage worldnbtstorage, WorldData worlddata, DimensionManager dimensionmanager, GameProfilerFiller gameprofilerfiller, WorldLoadListener worldloadlistener, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) {
super(worlddata, dimensionmanager, (world, worldprovider) -> {
2019-06-21 12:00:00 +02:00
- return new ChunkProviderServer((WorldServer) world, worldnbtstorage.getDirectory(), worldnbtstorage.getDataFixer(), worldnbtstorage.f(), executor, worldprovider.getChunkGenerator(), minecraftserver.getPlayerList().getViewDistance(), worldloadlistener, () -> {
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ ChunkGenerator<?> chunkGenerator;
+
+ if (gen != null) {
+ chunkGenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(world, world.getSeed(), gen);
+ } else {
+ chunkGenerator = worldprovider.getChunkGenerator();
+ }
+
2019-06-21 12:00:00 +02:00
+ return new ChunkProviderServer((WorldServer) world, worldnbtstorage.getDirectory(), worldnbtstorage.getDataFixer(), worldnbtstorage.f(), executor, chunkGenerator, minecraftserver.getPlayerList().getViewDistance(), worldloadlistener, () -> {
2019-04-23 04:00:00 +02:00
return minecraftserver.getWorldServer(DimensionManager.OVERWORLD).getWorldPersistentData();
});
- }, gameprofilerfiller, false);
+ // CraftBukkit end
+ }, gameprofilerfiller, false, gen, env);
+ this.pvpMode = minecraftserver.getPVP();
2015-02-26 23:41:06 +01:00
+ worlddata.world = this;
+ // CraftBukkit end
2018-12-25 22:00:00 +01:00
this.nextTickListBlock = new TickListServer<>(this, (block) -> {
2018-07-15 02:00:00 +02:00
return block == null || block.getBlockData().isAir();
2019-04-23 04:00:00 +02:00
}, IRegistry.BLOCK::getKey, IRegistry.BLOCK::get, this::b);
2019-12-21 02:06:18 +01:00
@@ -87,8 +115,43 @@
this.getWorldData().setGameType(minecraftserver.getGamemode());
}
- this.mobSpawnerTrader = this.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD ? new MobSpawnerTrader(this) : null;
+ this.mobSpawnerTrader = this.worldProvider.getDimensionManager().getType() == DimensionManager.OVERWORLD ? new MobSpawnerTrader(this) : null; // CraftBukkit - getType()
2019-04-23 04:00:00 +02:00
+ this.getServer().addWorld(this.getWorld()); // CraftBukkit
2019-12-21 02:06:18 +01:00
+ }
+
+ // CraftBukkit start
+ @Override
+ protected TileEntity getTileEntity(BlockPosition pos, boolean validate) {
+ TileEntity result = super.getTileEntity(pos, validate);
+ if (!validate || Thread.currentThread() != this.serverThread) {
+ // SPIGOT-5378: avoid deadlock, this can be called in loading logic (i.e lighting) but getType() will block on chunk load
+ return result;
+ }
+ Block type = getType(pos).getBlock();
+
+ if (result != null && type != Blocks.AIR) {
2019-12-10 23:00:00 +01:00
+ if (!result.getTileType().isValidBlock(type)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ }
+
+ return result;
+ }
+
+ private TileEntity fixTileEntity(BlockPosition pos, Block type, TileEntity found) {
+ this.getServer().getLogger().log(Level.SEVERE, "Block at {0}, {1}, {2} is {3} but has {4}" + ". "
+ + "Bukkit will attempt to fix this, but there may be additional damage that we cannot recover.", new Object[]{pos.getX(), pos.getY(), pos.getZ(), type, found});
+
+ if (type instanceof ITileEntity) {
+ TileEntity replacement = ((ITileEntity) type).createTile(this);
+ replacement.world = this;
+ this.setTileEntity(pos, replacement);
+ return replacement;
+ } else {
+ return found;
+ }
2019-12-21 02:06:18 +01:00
}
+ // CraftBukkit end
2019-12-21 02:06:18 +01:00
2019-12-10 23:00:00 +01:00
@Override
public BiomeBase a(int i, int j, int k) {
2019-12-21 02:06:18 +01:00
@@ -169,6 +232,7 @@
2019-05-14 02:00:00 +02:00
this.rainLevel = MathHelper.a(this.rainLevel, 0.0F, 1.0F);
}
2019-04-23 04:00:00 +02:00
+ /* CraftBukkit start
2019-05-14 02:00:00 +02:00
if (this.lastRainLevel != this.rainLevel) {
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(7, this.rainLevel)), this.worldProvider.getDimensionManager());
}
2019-12-21 02:06:18 +01:00
@@ -187,22 +251,51 @@
2019-05-14 02:00:00 +02:00
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.rainLevel));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.thunderLevel));
2019-04-23 04:00:00 +02:00
}
+ // */
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((EntityPlayer) this.players.get(idx)).world == this) {
+ ((EntityPlayer) this.players.get(idx)).tickWeather();
+ }
+ }
2015-02-26 23:41:06 +01:00
+
2019-04-23 04:00:00 +02:00
+ if (flag != this.isRaining()) {
+ // Only send weather packets to those affected
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((EntityPlayer) this.players.get(idx)).world == this) {
+ ((EntityPlayer) this.players.get(idx)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false);
+ }
+ }
+ }
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((EntityPlayer) this.players.get(idx)).world == this) {
2019-05-14 02:00:00 +02:00
+ ((EntityPlayer) this.players.get(idx)).updateWeather(this.lastRainLevel, this.rainLevel, this.lastThunderLevel, this.thunderLevel);
2019-04-23 04:00:00 +02:00
+ }
+ }
+ // CraftBukkit end
if (this.getWorldData().isHardcore() && this.getDifficulty() != EnumDifficulty.HARD) {
this.getWorldData().setDifficulty(EnumDifficulty.HARD);
}
2020-01-21 22:00:00 +01:00
if (this.everyoneSleeping && this.players.stream().noneMatch((entityplayer) -> {
2019-04-23 04:00:00 +02:00
- return !entityplayer.isSpectator() && !entityplayer.isDeeplySleeping();
+ return !entityplayer.isSpectator() && !entityplayer.isDeeplySleeping() && !entityplayer.fauxSleeping; // CraftBukkit
})) {
2020-01-21 22:00:00 +01:00
- this.everyoneSleeping = false;
2019-12-21 02:06:18 +01:00
+ // CraftBukkit start
+ long l = this.worldData.getDayTime() + 24000L;
+ TimeSkipEvent event = new TimeSkipEvent(this.getWorld(), TimeSkipEvent.SkipReason.NIGHT_SKIP, (l - l % 24000L) - this.getDayTime());
2019-06-21 12:00:00 +02:00
if (this.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE)) {
2019-12-21 02:06:18 +01:00
- long l = this.worldData.getDayTime() + 24000L;
+ getServer().getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ this.setDayTime(this.getDayTime() + event.getSkipAmount());
+ }
- this.setDayTime(l - l % 24000L);
}
2020-01-21 22:00:00 +01:00
- this.wakeupPlayers();
2019-12-21 02:06:18 +01:00
+ if (!event.isCancelled()) {
2020-01-21 22:00:00 +01:00
+ this.everyoneSleeping = false;
+ this.wakeupPlayers();
2019-12-21 02:06:18 +01:00
+ }
+ // CraftBukkit end
if (this.getGameRules().getBoolean(GameRules.DO_WEATHER_CYCLE)) {
this.clearWeather();
}
@@ -228,7 +321,7 @@
2019-12-10 23:00:00 +01:00
this.ad();
2019-04-23 04:00:00 +02:00
this.ticking = false;
gameprofilerfiller.exitEnter("entities");
- boolean flag3 = !this.players.isEmpty() || !this.getForceLoadedChunks().isEmpty();
+ boolean flag3 = true || !this.players.isEmpty() || !this.getForceLoadedChunks().isEmpty(); // CraftBukkit - this prevents entity cleanup, other issues on servers with no players
if (flag3) {
this.resetEmptyTime();
2019-12-21 02:06:18 +01:00
@@ -242,6 +335,11 @@
2019-04-23 04:00:00 +02:00
for (i = 0; i < this.globalEntityList.size(); ++i) {
entity = (Entity) this.globalEntityList.get(i);
+ // CraftBukkit start - Fixed an NPE
+ if (entity == null) {
+ continue;
+ }
+ // CraftBukkit end
this.a((entity1) -> {
++entity1.ticksLived;
entity1.tick();
2019-12-21 02:06:18 +01:00
@@ -260,6 +358,7 @@
2019-04-23 04:00:00 +02:00
Entity entity1 = (Entity) entry.getValue();
Entity entity2 = entity1.getVehicle();
+ /* CraftBukkit start - We prevent spawning in general, so this butchering is not needed
if (!this.server.getSpawnAnimals() && (entity1 instanceof EntityAnimal || entity1 instanceof EntityWaterAnimal)) {
entity1.die();
}
2019-12-21 02:06:18 +01:00
@@ -267,6 +366,7 @@
2019-04-23 04:00:00 +02:00
if (!this.server.getSpawnNPCs() && entity1 instanceof NPC) {
entity1.die();
}
+ // CraftBukkit end */
2019-12-10 23:00:00 +01:00
gameprofilerfiller.enter("checkDespawn");
if (!entity1.dead) {
2019-12-21 02:06:18 +01:00
@@ -312,7 +412,7 @@
2019-12-10 23:00:00 +01:00
}
2020-01-21 22:00:00 +01:00
private void wakeupPlayers() {
2019-12-10 23:00:00 +01:00
- ((List) this.players.stream().filter(EntityLiving::isSleeping).collect(Collectors.toList())).forEach((entityplayer) -> {
+ (this.players.stream().filter(EntityLiving::isSleeping).collect(Collectors.toList())).forEach((entityplayer) -> { // CraftBukkit - decompile error
entityplayer.wakeup(false, false);
});
}
2019-12-21 02:06:18 +01:00
@@ -339,10 +439,10 @@
2019-04-23 04:00:00 +02:00
entityhorseskeleton.r(true);
entityhorseskeleton.setAgeRaw(0);
entityhorseskeleton.setPosition((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
- this.addEntity(entityhorseskeleton);
+ this.addEntity(entityhorseskeleton, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
}
- this.strikeLightning(new EntityLightning(this, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, flag1));
+ this.strikeLightning(new EntityLightning(this, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, flag1), org.bukkit.event.weather.LightningStrikeEvent.Cause.WEATHER); // CraftBukkit
}
}
2019-12-21 02:06:18 +01:00
@@ -353,11 +453,11 @@
2019-04-23 04:00:00 +02:00
BiomeBase biomebase = this.getBiome(blockposition);
if (biomebase.a((IWorldReader) this, blockposition1)) {
- this.setTypeUpdate(blockposition1, Blocks.ICE.getBlockData());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.ICE.getBlockData(), null); // CraftBukkit
}
if (flag && biomebase.b(this, blockposition)) {
- this.setTypeUpdate(blockposition, Blocks.SNOW.getBlockData());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition, Blocks.SNOW.getBlockData(), null); // CraftBukkit
}
2019-12-10 23:00:00 +01:00
if (flag && this.getBiome(blockposition1).d() == BiomeBase.Precipitation.RAIN) {
2019-12-21 02:06:18 +01:00
@@ -404,7 +504,7 @@
2019-04-23 04:00:00 +02:00
protected BlockPosition a(BlockPosition blockposition) {
BlockPosition blockposition1 = this.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING, blockposition);
2019-05-14 02:00:00 +02:00
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(blockposition1, new BlockPosition(blockposition1.getX(), this.getBuildHeight(), blockposition1.getZ()))).g(3.0D);
2019-04-23 04:00:00 +02:00
- List<EntityLiving> list = this.a(EntityLiving.class, axisalignedbb, (entityliving) -> {
+ List<EntityLiving> list = this.a(EntityLiving.class, axisalignedbb, (java.util.function.Predicate<EntityLiving>) (entityliving) -> { // CraftBukkit - decompile error
return entityliving != null && entityliving.isAlive() && this.f(entityliving.getChunkCoordinates());
});
2019-12-21 02:06:18 +01:00
@@ -433,7 +533,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
- if (entityplayer.isSpectator()) {
+ if (entityplayer.isSpectator() || (entityplayer.fauxSleeping && !entityplayer.isSleeping())) { // CraftBukkit
++i;
} else if (entityplayer.isSleeping()) {
++j;
2019-12-21 02:06:18 +01:00
@@ -451,10 +551,22 @@
}
2019-04-23 04:00:00 +02:00
private void clearWeather() {
- this.worldData.setWeatherDuration(0);
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
this.worldData.setStorm(false);
- this.worldData.setThunderDuration(0);
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value.
+ // Not that everyone ever manages to get the whole server to sleep at the same time....
+ if (!this.worldData.hasStorm()) {
+ this.worldData.setWeatherDuration(0);
+ }
+ // CraftBukkit end
this.worldData.setThundering(false);
+ // CraftBukkit start
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value.
+ // Not that everyone ever manages to get the whole server to sleep at the same time....
+ if (!this.worldData.isThundering()) {
+ this.worldData.setThunderDuration(0);
+ }
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
public void resetEmptyTime() {
2020-01-21 22:00:00 +01:00
@@ -493,6 +605,7 @@
2019-04-23 04:00:00 +02:00
});
2020-01-21 22:00:00 +01:00
gameprofilerfiller.c("tickNonPassenger");
2019-04-23 04:00:00 +02:00
entity.tick();
+ entity.postTick(); // CraftBukkit
2020-01-21 22:00:00 +01:00
gameprofilerfiller.exit();
}
2020-01-21 22:00:00 +01:00
@@ -583,6 +696,22 @@
2019-12-10 23:00:00 +01:00
BlockPosition blockposition = worldchunkmanager.a(0, this.getSeaLevel(), 0, 256, list, random);
2018-07-15 02:00:00 +02:00
ChunkCoordIntPair chunkcoordintpair = blockposition == null ? new ChunkCoordIntPair(0, 0) : new ChunkCoordIntPair(blockposition);
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ if (this.generator != null) {
+ Random rand = new Random(this.getSeed());
+ org.bukkit.Location spawn = this.generator.getFixedSpawnLocation(((WorldServer) this).getWorld(), rand);
+
+ if (spawn != null) {
+ if (spawn.getWorld() != ((WorldServer) this).getWorld()) {
+ throw new IllegalStateException("Cannot set spawn point for " + this.worldData.getName() + " to be in another world (" + spawn.getWorld().getName() + ")");
+ } else {
+ this.worldData.setSpawn(new BlockPosition(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()));
+ return;
+ }
+ }
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
if (blockposition == null) {
2019-04-25 04:00:00 +02:00
WorldServer.LOGGER.warn("Unable to find spawn biome");
2018-07-15 02:00:00 +02:00
}
2020-01-21 22:00:00 +01:00
@@ -635,7 +764,7 @@
2019-12-10 23:00:00 +01:00
}
protected void g() {
- WorldGenFeatureConfigured<?, ?> worldgenfeatureconfigured = WorldGenerator.BONUS_CHEST.b((WorldGenFeatureConfiguration) WorldGenFeatureConfiguration.e);
+ WorldGenFeatureConfigured<?, ?> worldgenfeatureconfigured = WorldGenerator.BONUS_CHEST.b(WorldGenFeatureConfiguration.e); // CraftBukkit - decompile error
worldgenfeatureconfigured.a(this, this.getChunkProvider().getChunkGenerator(), this.random, new BlockPosition(this.worldData.b(), this.worldData.c(), this.worldData.d()));
}
2020-01-21 22:00:00 +01:00
@@ -649,6 +778,7 @@
2018-12-13 01:00:00 +01:00
ChunkProviderServer chunkproviderserver = this.getChunkProvider();
2019-04-23 04:00:00 +02:00
if (!flag1) {
+ org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
if (iprogressupdate != null) {
2018-07-15 02:00:00 +02:00
iprogressupdate.a(new ChatMessage("menu.savingLevel", new Object[0]));
}
2020-01-21 22:00:00 +01:00
@@ -660,6 +790,15 @@
chunkproviderserver.save(flag);
}
+
+ // CraftBukkit start - moved from MinecraftServer.saveChunks
+ WorldServer worldserver1 = this;
+ WorldData worlddata = worldserver1.getWorldData();
+
2019-12-10 23:00:00 +01:00
+ worldserver1.getWorldBorder().save(worlddata);
+ worlddata.setCustomBossEvents(this.server.getBossBattleCustomData().save());
+ worldserver1.getDataManager().saveWorldData(worlddata, this.server.getPlayerList().save());
+ // CraftBukkit end
}
2019-12-10 23:00:00 +01:00
protected void m_() throws ExceptionWorldConflict {
2020-01-21 22:00:00 +01:00
@@ -731,7 +870,8 @@
2019-07-20 01:00:00 +02:00
if (entity instanceof EntityInsentient) {
EntityInsentient entityinsentient = (EntityInsentient) entity;
2019-04-23 04:00:00 +02:00
2019-07-20 01:00:00 +02:00
- if (entityinsentient.isPersistent() || entityinsentient.I()) {
+ // CraftBukkit - Split out persistent check, don't apply it to special persistent mobs
2019-04-23 04:00:00 +02:00
+ if (entityinsentient.isTypeNotPersistent(0) && entityinsentient.isPersistent()) {
2019-07-20 01:00:00 +02:00
continue;
}
}
2020-01-21 22:00:00 +01:00
@@ -748,11 +888,24 @@
2019-04-23 04:00:00 +02:00
@Override
public boolean addEntity(Entity entity) {
- return this.addEntity0(entity);
+ // CraftBukkit start
+ return this.addEntity0(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Override
+ public boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity0(entity, reason);
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
public boolean addEntitySerialized(Entity entity) {
- return this.addEntity0(entity);
+ // CraftBukkit start
+ return this.addEntitySerialized(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public boolean addEntitySerialized(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity0(entity, reason);
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
public void addEntityTeleport(Entity entity) {
2020-01-21 22:00:00 +01:00
@@ -802,13 +955,18 @@
2019-04-23 04:00:00 +02:00
this.registerEntity(entityplayer);
}
2016-02-29 22:32:46 +01:00
2019-04-23 04:00:00 +02:00
- private boolean addEntity0(Entity entity) {
+ // CraftBukkit start
+ private boolean addEntity0(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
2016-02-29 22:32:46 +01:00
if (entity.dead) {
2019-04-25 04:00:00 +02:00
- WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getName(entity.getEntityType()));
+ // WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getName(entity.getEntityType())); // CraftBukkit
2019-04-23 04:00:00 +02:00
return false;
} else if (this.isUUIDTaken(entity)) {
2016-02-29 22:32:46 +01:00
return false;
} else {
2019-04-23 04:00:00 +02:00
+ if (!CraftEventFactory.doEntityAddEventCalling(this, entity, spawnReason)) {
+ return false;
+ }
+ // CraftBukkit end
2019-12-10 23:00:00 +01:00
IChunkAccess ichunkaccess = this.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, entity.attachedToPlayer);
2019-04-23 04:00:00 +02:00
if (!(ichunkaccess instanceof Chunk)) {
2020-01-21 22:00:00 +01:00
@@ -836,7 +994,7 @@
2019-04-23 04:00:00 +02:00
if (entity1 == null) {
return false;
} else {
2019-04-25 04:00:00 +02:00
- WorldServer.LOGGER.warn("Keeping entity {} that already exists with UUID {}", EntityTypes.getName(entity1.getEntityType()), entity.getUniqueID().toString());
+ // WorldServer.LOGGER.warn("Keeping entity {} that already exists with UUID {}", EntityTypes.getName(entity1.getEntityType()), entity.getUniqueID().toString()); // CraftBukkit
2019-04-23 04:00:00 +02:00
return true;
}
}
2020-01-21 22:00:00 +01:00
@@ -887,10 +1045,17 @@
2019-08-24 11:45:08 +02:00
}
this.getScoreboard().a(entity);
+ // CraftBukkit start - SPIGOT-5278
+ if (entity instanceof EntityDrowned) {
2019-12-10 23:00:00 +01:00
+ this.navigators.remove(((EntityDrowned) entity).navigationWater);
+ this.navigators.remove(((EntityDrowned) entity).navigationLand);
2019-08-24 11:45:08 +02:00
+ } else
+ // CraftBukkit end
if (entity instanceof EntityInsentient) {
2019-12-10 23:00:00 +01:00
this.navigators.remove(((EntityInsentient) entity).getNavigation());
}
+ entity.valid = false; // CraftBukkit
}
private void registerEntity(Entity entity) {
2020-01-21 22:00:00 +01:00
@@ -911,9 +1076,16 @@
2019-08-24 11:45:08 +02:00
this.entitiesByUUID.put(entity.getUniqueID(), entity);
this.getChunkProvider().addEntity(entity);
+ // CraftBukkit start - SPIGOT-5278
+ if (entity instanceof EntityDrowned) {
2019-12-10 23:00:00 +01:00
+ this.navigators.add(((EntityDrowned) entity).navigationWater);
+ this.navigators.add(((EntityDrowned) entity).navigationLand);
2019-08-24 11:45:08 +02:00
+ } else
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
if (entity instanceof EntityInsentient) {
2019-12-10 23:00:00 +01:00
this.navigators.add(((EntityInsentient) entity).getNavigation());
2019-04-23 04:00:00 +02:00
}
+ entity.valid = true; // CraftBukkit
}
}
2020-01-21 22:00:00 +01:00
@@ -944,6 +1116,18 @@
}
2019-04-23 04:00:00 +02:00
public void strikeLightning(EntityLightning entitylightning) {
+ // CraftBukkit start
+ this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN);
+ }
+
2019-04-23 04:00:00 +02:00
+ public void strikeLightning(EntityLightning entitylightning, LightningStrikeEvent.Cause cause) {
+ LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entitylightning.getBukkitEntity(), cause);
+ this.getServer().getPluginManager().callEvent(lightning);
+
+ if (lightning.isCancelled()) {
2019-04-23 04:00:00 +02:00
+ return;
+ }
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.globalEntityList.add(entitylightning);
2019-12-10 23:00:00 +01:00
this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entitylightning.locX(), entitylightning.locY(), entitylightning.locZ(), 512.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutSpawnEntityWeather(entitylightning));
}
2020-01-21 22:00:00 +01:00
@@ -952,6 +1136,12 @@
2019-04-23 04:00:00 +02:00
public void a(int i, BlockPosition blockposition, int j) {
Iterator iterator = this.server.getPlayerList().getPlayers().iterator();
+ // CraftBukkit start
+ EntityHuman entityhuman = null;
+ Entity entity = this.getEntity(i);
+ if (entity instanceof EntityHuman) entityhuman = (EntityHuman) entity;
+ // CraftBukkit end
+
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
2020-01-21 22:00:00 +01:00
@@ -960,6 +1150,12 @@
2019-12-10 23:00:00 +01:00
double d1 = (double) blockposition.getY() - entityplayer.locY();
double d2 = (double) blockposition.getZ() - entityplayer.locZ();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
+ continue;
+ }
+ // CraftBukkit end
+
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
2020-01-21 22:00:00 +01:00
@@ -1020,6 +1216,14 @@
2019-04-23 04:00:00 +02:00
@Override
2019-12-10 23:00:00 +01:00
public Explosion createExplosion(@Nullable Entity entity, @Nullable DamageSource damagesource, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ Explosion explosion = super.createExplosion(entity, damagesource, d0, d1, d2, f, flag, explosion_effect);
+
+ if (explosion.wasCanceled) {
+ return explosion;
+ }
2015-02-26 23:41:06 +01:00
+
+ /* Remove
2019-04-23 04:00:00 +02:00
Explosion explosion = new Explosion(this, entity, d0, d1, d2, f, flag, explosion_effect);
2018-07-15 02:00:00 +02:00
if (damagesource != null) {
2020-01-21 22:00:00 +01:00
@@ -1028,6 +1232,8 @@
2018-07-15 02:00:00 +02:00
explosion.a();
explosion.a(false);
+ */
+ // CraftBukkit end - TODO: Check if explosions are still properly implemented
2019-04-23 04:00:00 +02:00
if (explosion_effect == Explosion.Effect.NONE) {
explosion.clearBlocks();
}
2020-01-21 22:00:00 +01:00
@@ -1092,13 +1298,20 @@
}
2018-07-15 02:00:00 +02:00
public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
2019-12-10 23:00:00 +01:00
- PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, false, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
+ // CraftBukkit - visibility api support
+ return sendParticles(null, t0, d0, d1, d2, i, d3, d4, d5, d6, false);
+ }
2015-02-26 23:41:06 +01:00
+
+ public <T extends ParticleParam> int sendParticles(EntityPlayer sender, T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, boolean force) {
2019-12-10 23:00:00 +01:00
+ PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, force, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
int j = 0;
2018-07-15 02:00:00 +02:00
for (int k = 0; k < this.players.size(); ++k) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(k);
+ if (sender != null && !entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) continue; // CraftBukkit
- if (this.a(entityplayer, false, d0, d1, d2, packetplayoutworldparticles)) {
+ if (this.a(entityplayer, force, d0, d1, d2, packetplayoutworldparticles)) { // CraftBukkit
2018-07-15 02:00:00 +02:00
++j;
}
}
2020-01-21 22:00:00 +01:00
@@ -1180,7 +1393,13 @@
2019-04-23 04:00:00 +02:00
@Override
public WorldMap a(String s) {
return (WorldMap) this.getMinecraftServer().getWorldServer(DimensionManager.OVERWORLD).getWorldPersistentData().b(() -> {
- return new WorldMap(s);
+ // CraftBukkit start
+ // We only get here when the data file exists, but is not a valid map
+ WorldMap newMap = new WorldMap(s);
+ MapInitializeEvent event = new MapInitializeEvent(newMap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ return newMap;
+ // CraftBukkit end
}, s);
}