2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/WorldServer.java
+++ b/net/minecraft/server/WorldServer.java
2020-06-25 02:00:00 +02:00
@@ -35,6 +35,18 @@
2014-11-25 22:32:16 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
2019-10-18 10:58:39 +02:00
+import java.util.logging.Level;
2019-04-23 04:00:00 +02:00
+import org.bukkit.Bukkit;
2014-11-25 22:32:16 +01:00
+import org.bukkit.WeatherType;
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2020-06-25 02:00:00 +02:00
+import org.bukkit.craftbukkit.util.WorldUUID;
2019-04-23 04:00:00 +02:00
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.server.MapInitializeEvent;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.weather.LightningStrikeEvent;
2019-12-21 02:06:18 +01:00
+import org.bukkit.event.world.TimeSkipEvent;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
2020-06-25 02:00:00 +02:00
public class WorldServer extends World implements GeneratorAccessSeed {
public static final BlockPosition a = new BlockPosition(100, 50, 0);
@@ -46,7 +58,7 @@
private final ChunkProviderServer chunkProvider;
boolean tickingEntities;
private final MinecraftServer server;
- public final IWorldDataServer worldDataServer;
+ public final WorldDataServer worldDataServer; // CraftBukkit - type
public boolean savingDisabled;
private boolean everyoneSleeping;
private int emptyTime;
@@ -63,8 +75,23 @@
private final StructureManager structureManager;
private final boolean Q;
2020-08-11 23:00:00 +02:00
- public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey<World> resourcekey, DimensionManager dimensionmanager, WorldLoadListener worldloadlistener, ChunkGenerator chunkgenerator, boolean flag, long i, List<MobSpawner> list, boolean flag1) {
- super(iworlddataserver, resourcekey, dimensionmanager, minecraftserver::getMethodProfiler, false, flag, i);
2020-06-25 02:00:00 +02:00
+
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ private int tickPosition;
2020-06-25 02:00:00 +02:00
+ public final Convertable.ConversionSession convertable;
+ public final UUID uuid;
2014-11-25 22:32:16 +01:00
+
2020-06-25 02:00:00 +02:00
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return this.chunkProvider.getChunkAt(x, z, false);
+ }
2019-04-23 04:00:00 +02:00
+
2020-06-25 02:00:00 +02:00
+ // Add env and gen to constructor, WorldData -> WorldDataServer
2020-08-11 23:00:00 +02:00
+ public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey<World> resourcekey, DimensionManager dimensionmanager, WorldLoadListener worldloadlistener, ChunkGenerator chunkgenerator, boolean flag, long i, List<MobSpawner> list, boolean flag1, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) {
+ super(iworlddataserver, resourcekey, dimensionmanager, minecraftserver::getMethodProfiler, false, flag, i, gen, env);
2014-11-25 22:32:16 +01:00
+ this.pvpMode = minecraftserver.getPVP();
2020-06-25 02:00:00 +02:00
+ convertable = convertable_conversionsession;
+ uuid = WorldUUID.getUUID(convertable_conversionsession.folder.toFile());
2014-11-25 22:32:16 +01:00
+ // 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();
2020-06-25 02:00:00 +02:00
}, IRegistry.BLOCK::getKey, this::b);
@@ -76,10 +103,17 @@
this.Q = flag1;
this.server = minecraftserver;
this.mobSpawners = list;
- this.worldDataServer = iworlddataserver;
+ // CraftBukkit start
+ this.worldDataServer = (WorldDataServer) iworlddataserver;
+ worldDataServer.world = this;
+ if (gen != null) {
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
+ }
+
this.chunkProvider = new ChunkProviderServer(this, convertable_conversionsession, minecraftserver.getDataFixer(), minecraftserver.getDefinedStructureManager(), executor, chunkgenerator, minecraftserver.getPlayerList().getViewDistance(), minecraftserver.isSyncChunkWrites(), worldloadlistener, () -> {
2020-08-11 23:00:00 +02:00
return minecraftserver.E().getWorldPersistentData();
2020-06-25 02:00:00 +02:00
});
+ // CraftBukkit end
this.portalTravelAgent = new PortalTravelAgent(this);
2020-08-11 23:00:00 +02:00
this.P();
this.Q();
2020-07-17 00:56:56 +02:00
@@ -91,14 +125,48 @@
iworlddataserver.setGameType(minecraftserver.getGamemode());
}
- this.structureManager = new StructureManager(this, minecraftserver.getSaveData().getGeneratorSettings());
+ this.structureManager = new StructureManager(this, this.worldDataServer.getGeneratorSettings()); // CraftBukkit
if (this.getDimensionManager().isCreateDragonBattle()) {
2020-08-11 23:00:00 +02:00
- this.dragonBattle = new EnderDragonBattle(this, minecraftserver.getSaveData().getGeneratorSettings().getSeed(), minecraftserver.getSaveData().C());
+ this.dragonBattle = new EnderDragonBattle(this, this.worldDataServer.getGeneratorSettings().getSeed(), this.worldDataServer.C()); // CraftBukkit
2020-06-25 02:00:00 +02:00
} else {
this.dragonBattle = null;
2015-03-16 12:32:53 +01:00
}
2019-04-23 04:00:00 +02:00
+ this.getServer().addWorld(this.getWorld()); // CraftBukkit
2019-12-21 02:06:18 +01:00
+ }
+
2019-10-18 10:58:39 +02:00
+ // CraftBukkit start
+ @Override
2019-12-23 01:59:51 +01:00
+ protected TileEntity getTileEntity(BlockPosition pos, boolean validate) {
+ TileEntity result = super.getTileEntity(pos, validate);
+ if (!validate || Thread.currentThread() != this.serverThread) {
2019-10-20 09:50:26 +02:00
+ // SPIGOT-5378: avoid deadlock, this can be called in loading logic (i.e lighting) but getType() will block on chunk load
+ return result;
+ }
2019-10-18 10:58:39 +02:00
+ Block type = getType(pos).getBlock();
2020-06-25 02:00:00 +02:00
2019-10-18 10:58:39 +02:00
+ if (result != null && type != Blocks.AIR) {
2019-12-10 23:00:00 +01:00
+ if (!result.getTileType().isValidBlock(type)) {
2019-10-18 10:58:39 +02:00
+ result = fixTileEntity(pos, type, result);
+ }
+ }
+
+ return result;
+ }
+
+ private TileEntity fixTileEntity(BlockPosition pos, Block type, TileEntity found) {
2019-10-19 23:05:55 +02:00
+ this.getServer().getLogger().log(Level.SEVERE, "Block at {0}, {1}, {2} is {3} but has {4}" + ". "
2019-10-18 10:58:39 +02:00
+ + "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
}
2019-10-18 10:58:39 +02:00
+ // CraftBukkit end
2019-12-21 02:06:18 +01:00
2020-06-25 02:00:00 +02:00
public void a(int i, int j, boolean flag, boolean flag1) {
this.worldDataServer.a(i);
@@ -189,6 +257,7 @@
2019-05-14 02:00:00 +02:00
this.rainLevel = MathHelper.a(this.rainLevel, 0.0F, 1.0F);
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
+ /* CraftBukkit start
2019-05-14 02:00:00 +02:00
if (this.lastRainLevel != this.rainLevel) {
2020-06-25 02:00:00 +02:00
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, this.rainLevel)), this.getDimensionKey());
2014-11-25 22:32:16 +01:00
}
2020-06-25 02:00:00 +02:00
@@ -207,18 +276,47 @@
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, this.rainLevel));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.i, 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
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();
}
2020-06-25 02:00:00 +02:00
@@ -240,7 +338,7 @@
2020-08-11 23:00:00 +02:00
this.aj();
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();
2020-06-25 02:00:00 +02:00
@@ -259,6 +357,7 @@
Entity entity = (Entity) entry.getValue();
Entity entity1 = entity.getVehicle();
2019-04-23 04:00:00 +02:00
+ /* CraftBukkit start - We prevent spawning in general, so this butchering is not needed
2020-06-25 02:00:00 +02:00
if (!this.server.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
entity.die();
2019-04-23 04:00:00 +02:00
}
2020-06-25 02:00:00 +02:00
@@ -266,6 +365,7 @@
if (!this.server.getSpawnNPCs() && entity instanceof NPC) {
entity.die();
2019-04-23 04:00:00 +02:00
}
+ // CraftBukkit end */
2019-12-10 23:00:00 +01:00
gameprofilerfiller.enter("checkDespawn");
2020-06-25 02:00:00 +02:00
if (!entity.dead) {
@@ -340,7 +440,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);
});
}
2020-06-25 02:00:00 +02:00
@@ -367,14 +467,14 @@
entityhorseskeleton.t(true);
2019-04-23 04:00:00 +02:00
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
}
2020-06-25 02:00:00 +02:00
EntityLightning entitylightning = (EntityLightning) EntityTypes.LIGHTNING_BOLT.a((World) this);
2020-08-11 23:00:00 +02:00
entitylightning.d(Vec3D.c((BaseBlockPosition) blockposition));
2020-06-25 02:00:00 +02:00
entitylightning.setEffect(flag1);
- this.addEntity(entitylightning);
+ this.strikeLightning(entitylightning, org.bukkit.event.weather.LightningStrikeEvent.Cause.WEATHER); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
}
2020-06-25 02:00:00 +02:00
@@ -385,11 +485,11 @@
2019-04-23 04:00:00 +02:00
BiomeBase biomebase = this.getBiome(blockposition);
2020-08-11 23:00:00 +02:00
if (biomebase.a(this, blockposition1)) {
2019-04-23 04:00:00 +02:00
- 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
}
2020-08-11 23:00:00 +02:00
if (flag && this.getBiome(blockposition1).c() == BiomeBase.Precipitation.RAIN) {
2020-06-25 02:00:00 +02:00
@@ -436,7 +536,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
2020-08-11 23:00:00 +02:00
return entityliving != null && entityliving.isAlive() && this.e(entityliving.getChunkCoordinates());
2019-04-23 04:00:00 +02:00
});
2014-11-25 22:32:16 +01:00
2020-06-25 02:00:00 +02:00
@@ -465,7 +565,7 @@
2019-05-08 12:34:41 +02:00
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
2014-11-25 22:32:16 +01:00
2019-05-08 12:34:41 +02:00
- if (entityplayer.isSpectator()) {
+ if (entityplayer.isSpectator() || (entityplayer.fauxSleeping && !entityplayer.isSleeping())) { // CraftBukkit
2014-11-25 22:32:16 +01:00
++i;
2019-05-08 12:34:41 +02:00
} else if (entityplayer.isSleeping()) {
2014-11-25 22:32:16 +01:00
++j;
2020-06-25 02:00:00 +02:00
@@ -483,10 +583,22 @@
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
private void clearWeather() {
2020-06-25 02:00:00 +02:00
- this.worldDataServer.setWeatherDuration(0);
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
this.worldDataServer.setStorm(false);
- this.worldDataServer.setThunderDuration(0);
2015-01-04 23:50:48 +01:00
+ // 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....
2020-06-25 02:00:00 +02:00
+ if (!this.worldDataServer.hasStorm()) {
+ this.worldDataServer.setWeatherDuration(0);
2014-11-25 22:32:16 +01:00
+ }
2015-01-04 23:50:48 +01:00
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
this.worldDataServer.setThundering(false);
2015-01-04 23:50:48 +01:00
+ // 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....
2020-06-25 02:00:00 +02:00
+ if (!this.worldDataServer.isThundering()) {
+ this.worldDataServer.setThunderDuration(0);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
public void resetEmptyTime() {
2020-06-25 02:00:00 +02:00
@@ -527,6 +639,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();
2014-11-25 22:32:16 +01:00
}
2020-06-25 02:00:00 +02:00
@@ -615,6 +728,7 @@
2018-12-13 01:00:00 +01:00
ChunkProviderServer chunkproviderserver = this.getChunkProvider();
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
if (!flag1) {
2014-12-03 20:35:33 +01:00
+ org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
2014-11-25 22:32:16 +01:00
if (iprogressupdate != null) {
2020-06-25 02:00:00 +02:00
iprogressupdate.a(new ChatMessage("menu.savingLevel"));
2014-12-03 20:35:33 +01:00
}
2020-07-17 00:56:56 +02:00
@@ -626,11 +740,19 @@
2019-06-25 13:02:13 +02:00
chunkproviderserver.save(flag);
}
+
+ // CraftBukkit start - moved from MinecraftServer.saveChunks
+ WorldServer worldserver1 = this;
+
2020-06-25 02:00:00 +02:00
+ worldDataServer.a(worldserver1.getWorldBorder().t());
+ worldDataServer.setCustomBossEvents(this.server.getBossBattleCustomData().save());
+ convertable.a(this.server.f, this.worldDataServer, this.server.getPlayerList().save());
2019-06-25 13:02:13 +02:00
+ // CraftBukkit end
}
2020-08-11 23:00:00 +02:00
private void ai() {
2020-07-17 00:56:56 +02:00
if (this.dragonBattle != null) {
- this.server.getSaveData().a(this.dragonBattle.a());
+ this.worldDataServer.a(this.dragonBattle.a()); // CraftBukkit
}
this.getChunkProvider().getWorldPersistentData().a();
2020-06-25 02:00:00 +02:00
@@ -691,11 +813,24 @@
2014-11-25 22:32:16 +01:00
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
2016-10-16 08:20:12 +02:00
}
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
2016-10-16 08:20:12 +02:00
}
2019-04-23 04:00:00 +02:00
public void addEntityTeleport(Entity entity) {
2020-06-25 02:00:00 +02:00
@@ -745,13 +880,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);
2018-09-15 11:16:42 +02:00
2019-04-23 04:00:00 +02:00
if (!(ichunkaccess instanceof Chunk)) {
2020-08-11 23:00:00 +02:00
@@ -780,7 +920,7 @@
2019-04-23 04:00:00 +02:00
if (entity1 == null) {
return false;
} else {
2020-08-11 23:00:00 +02:00
- WorldServer.LOGGER.warn("Trying to add entity with duplicated UUID {}. Existing {}#{}, new: {}#{}", uuid, EntityTypes.getName(entity1.getEntityType()), entity1.getId(), EntityTypes.getName(entity.getEntityType()), entity.getId());
+ // WorldServer.LOGGER.warn("Trying to add entity with duplicated UUID {}. Existing {}#{}, new: {}#{}", uuid, EntityTypes.getName(entity1.getEntityType()), entity1.getId(), EntityTypes.getName(entity.getEntityType()), entity.getId()); // CraftBukkit
2019-04-23 04:00:00 +02:00
return true;
}
}
2020-08-11 23:00:00 +02:00
@@ -809,11 +949,16 @@
}
public boolean addAllEntitiesSafely(Entity entity) {
+ // CraftBukkit start
+ return this.addAllEntitiesSafely(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public boolean addAllEntitiesSafely(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ // CraftBukkit end
if (entity.co().anyMatch(this::isUUIDTaken)) {
return false;
} else {
- this.addAllEntities(entity);
- return true;
+ return this.addAllEntities(entity, reason); // CraftBukkit
}
}
@@ -863,10 +1008,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());
2019-04-27 01:25:38 +02:00
}
+ entity.valid = false; // CraftBukkit
}
private void registerEntity(Entity entity) {
2020-08-11 23:00:00 +02:00
@@ -887,9 +1039,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-08-11 23:00:00 +02:00
@@ -919,10 +1078,33 @@
2020-06-25 02:00:00 +02:00
this.everyoneSleeping();
2014-11-25 22:32:16 +01:00
}
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
+ public boolean strikeLightning(Entity entitylightning) {
+ return this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN);
2018-09-15 11:16:42 +02:00
+ }
+
2020-06-25 02:00:00 +02:00
+ public boolean strikeLightning(Entity entitylightning, LightningStrikeEvent.Cause cause) {
2019-04-23 04:00:00 +02:00
+ LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entitylightning.getBukkitEntity(), cause);
2014-11-25 22:32:16 +01:00
+ this.getServer().getPluginManager().callEvent(lightning);
+
+ if (lightning.isCancelled()) {
2020-06-25 02:00:00 +02:00
+ return false;
2014-11-25 22:32:16 +01:00
+ }
2020-06-25 02:00:00 +02:00
+
+ return this.addEntity(entitylightning);
+ }
+ // CraftBukkit end
+
@Override
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-08-11 23:00:00 +02:00
@@ -931,6 +1113,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-08-11 23:00:00 +02:00
@@ -991,10 +1179,20 @@
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
@Override
2020-06-25 02:00:00 +02:00
public Explosion createExplosion(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ Explosion explosion = super.createExplosion(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
2014-11-25 22:32:16 +01:00
+
+ if (explosion.wasCanceled) {
+ return explosion;
+ }
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ /* Remove
2020-06-25 02:00:00 +02:00
Explosion explosion = new Explosion(this, entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
2018-07-15 02:00:00 +02:00
2014-11-25 22:32:16 +01: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) {
2014-11-25 22:32:16 +01:00
explosion.clearBlocks();
}
2020-08-11 23:00:00 +02:00
@@ -1059,13 +1257,20 @@
2014-11-25 22:32:16 +01:00
}
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);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - visibility api support
2018-08-26 10:26:09 +02:00
+ return sendParticles(null, t0, d0, d1, d2, i, d3, d4, d5, d6, false);
2014-11-25 22:32:16 +01:00
+ }
2015-02-26 23:41:06 +01:00
+
2018-08-26 10:26:09 +02: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);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
int j = 0;
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
for (int k = 0; k < this.players.size(); ++k) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(k);
2014-12-28 15:56:18 +01:00
+ if (sender != null && !entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) continue; // CraftBukkit
2014-11-25 22:32:16 +01:00
2018-08-26 10:26:09 +02:00
- 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;
2018-08-26 10:26:09 +02:00
}
}
2020-08-11 23:00:00 +02:00
@@ -1107,7 +1312,7 @@
2020-06-30 02:29:41 +02:00
@Nullable
public BlockPosition a(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) {
- return !this.server.getSaveData().getGeneratorSettings().shouldGenerateMapFeatures() ? null : this.getChunkProvider().getChunkGenerator().findNearestMapFeature(this, structuregenerator, blockposition, i, flag);
+ return !this.worldDataServer.getGeneratorSettings().shouldGenerateMapFeatures() ? null : this.getChunkProvider().getChunkGenerator().findNearestMapFeature(this, structuregenerator, blockposition, i, flag); // CraftBukkit
}
@Nullable
2020-08-11 23:00:00 +02:00
@@ -1145,7 +1350,13 @@
2019-04-23 04:00:00 +02:00
@Override
public WorldMap a(String s) {
2020-08-11 23:00:00 +02:00
return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().b(() -> {
2019-04-23 04:00:00 +02:00
- 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);
}
2020-08-11 23:00:00 +02:00
@@ -1456,6 +1667,11 @@
2020-06-25 02:00:00 +02:00
@Override
public void update(BlockPosition blockposition, Block block) {
if (!this.isDebugWorld()) {
+ // CraftBukkit start
+ if (populating) {
+ return;
+ }
+ // CraftBukkit end
this.applyPhysics(blockposition, block);
}
2020-08-11 23:00:00 +02:00
@@ -1470,12 +1686,12 @@
2020-06-25 02:00:00 +02:00
}
public boolean isFlatWorld() {
- return this.server.getSaveData().getGeneratorSettings().isFlatWorld();
+ return this.worldDataServer.getGeneratorSettings().isFlatWorld(); // CraftBukkit
}
@Override
public long getSeed() {
- return this.server.getSaveData().getGeneratorSettings().getSeed();
+ return this.worldDataServer.getGeneratorSettings().getSeed(); // CraftBukkit
}
@Nullable
2020-08-11 23:00:00 +02:00
@@ -1494,16 +1710,32 @@
2020-06-25 02:00:00 +02:00
}
public static void a(WorldServer worldserver) {
+ // CraftBukkit start
+ WorldServer.a(worldserver, null);
+ }
+
+ public static void a(WorldServer worldserver, Entity entity) {
+ // CraftBukkit end
BlockPosition blockposition = WorldServer.a;
int i = blockposition.getX();
int j = blockposition.getY() - 2;
int k = blockposition.getZ();
+ // CraftBukkit start
+ org.bukkit.craftbukkit.util.BlockStateListPopulator blockList = new org.bukkit.craftbukkit.util.BlockStateListPopulator(worldserver);
BlockPosition.b(i - 2, j + 1, k - 2, i + 2, j + 3, k + 2).forEach((blockposition1) -> {
- worldserver.setTypeUpdate(blockposition1, Blocks.AIR.getBlockData());
+ blockList.setTypeAndData(blockposition1, Blocks.AIR.getBlockData(), 3);
});
BlockPosition.b(i - 2, j, k - 2, i + 2, j, k + 2).forEach((blockposition1) -> {
- worldserver.setTypeUpdate(blockposition1, Blocks.OBSIDIAN.getBlockData());
+ blockList.setTypeAndData(blockposition1, Blocks.OBSIDIAN.getBlockData(), 3);
});
+ org.bukkit.World bworld = worldserver.getWorld();
+ org.bukkit.event.world.PortalCreateEvent portalEvent = new org.bukkit.event.world.PortalCreateEvent((List<org.bukkit.block.BlockState>) (List) blockList.getList(), bworld, (entity == null) ? null : entity.getBukkitEntity(), org.bukkit.event.world.PortalCreateEvent.CreateReason.END_PLATFORM);
+
+ worldserver.getServer().getPluginManager().callEvent(portalEvent);
+ if (!portalEvent.isCancelled()) {
+ blockList.updateList();
+ }
+ // CraftBukkit end
}
}