2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/WorldServer.java
+++ b/net/minecraft/server/WorldServer.java
2018-08-26 04:00:00 +02:00
@@ -21,6 +21,18 @@
2014-11-25 22:32:16 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import java.util.logging.Level;
+
+import org.bukkit.WeatherType;
+import org.bukkit.block.BlockState;
2015-04-13 12:04:38 +02:00
+import org.bukkit.craftbukkit.util.HashTreeSet;
2014-11-25 22:32:16 +01:00
+
+import org.bukkit.event.block.BlockFormEvent;
2016-10-16 08:20:12 +02:00
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.weather.LightningStrikeEvent;
+// CraftBukkit end
+
public class WorldServer extends World implements IAsyncTaskHandler {
private static final Logger a = LogManager.getLogger();
2018-08-26 04:00:00 +02:00
@@ -39,28 +51,36 @@
2018-07-15 02:00:00 +02:00
ObjectLinkedOpenHashSet<BlockActionData> d;
2018-08-26 04:00:00 +02:00
private boolean P;
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
- public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, PersistentCollection persistentcollection, WorldData worlddata, DimensionManager dimensionmanager, MethodProfiler methodprofiler) {
- super(idatamanager, persistentcollection, worlddata, dimensionmanager.e(), methodprofiler, false);
2018-07-15 02:00:00 +02:00
- Predicate predicate = (block) -> {
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2018-08-26 04:00:00 +02:00
+ public final DimensionManager dimension;
2014-11-25 22:32:16 +01:00
+
+ // Add env and gen to constructor
2018-08-26 04:00:00 +02:00
+ public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, PersistentCollection persistentcollection, WorldData worlddata, DimensionManager dimensionmanager, MethodProfiler methodprofiler, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) {
+ super(idatamanager, persistentcollection, worlddata, DimensionManager.a(env.getId()).e(), methodprofiler, false, gen, env);
+ this.dimension = dimensionmanager;
2014-11-25 22:32:16 +01:00
+ this.pvpMode = minecraftserver.getPVP();
2015-02-26 23:41:06 +01:00
+ worlddata.world = this;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
+ Predicate<Block> predicate = (block) -> { // CraftBukkit - decompile error
return block == null || block.getBlockData().isAir();
};
2018-08-26 04:00:00 +02:00
IRegistry iregistry = IRegistry.BLOCK;
2018-07-15 02:00:00 +02:00
2018-08-26 04:00:00 +02:00
IRegistry.BLOCK.getClass();
Function function = iregistry::getKey;
- IRegistry iregistry1 = IRegistry.BLOCK;
+ IRegistry<Block> iregistry1 = IRegistry.BLOCK; // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
2018-08-26 04:00:00 +02:00
IRegistry.BLOCK.getClass();
- this.nextTickListBlock = new TickListServer(this, predicate, function, iregistry1::getOrDefault, this::b);
2018-07-15 02:00:00 +02:00
- predicate = (fluidtype) -> {
2018-08-26 04:00:00 +02:00
+ this.nextTickListBlock = new TickListServer<>(this, predicate, function, iregistry1::getOrDefault, this::b); // CraftBukkit - decompile error
+ Predicate<FluidType> predicate2 = (fluidtype) -> { // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
return fluidtype == null || fluidtype == FluidTypes.a;
};
2018-08-26 04:00:00 +02:00
iregistry = IRegistry.FLUID;
IRegistry.FLUID.getClass();
function = iregistry::getKey;
- iregistry1 = IRegistry.FLUID;
+ IRegistry<FluidType> iregistry2 = IRegistry.FLUID; // CraftBukkit - decompile error
IRegistry.FLUID.getClass();
- this.nextTickListFluid = new TickListServer(this, predicate, function, iregistry1::getOrDefault, this::a);
+ this.nextTickListFluid = new TickListServer<>(this, predicate2, function, iregistry2::getOrDefault, this::a); // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
this.siegeManager = new VillageSiege(this);
this.d = new ObjectLinkedOpenHashSet();
2014-11-25 22:32:16 +01:00
this.server = minecraftserver;
2018-08-26 04:00:00 +02:00
@@ -68,7 +88,7 @@
2014-11-25 22:32:16 +01:00
this.manager = new PlayerChunkMap(this);
2016-02-29 22:32:46 +01:00
this.worldProvider.a((World) this);
2018-08-26 04:00:00 +02:00
this.chunkProvider = this.r();
2016-02-29 22:32:46 +01:00
- this.portalTravelAgent = new PortalTravelAgent(this);
+ this.portalTravelAgent = new org.bukkit.craftbukkit.CraftTravelAgent(this); // CraftBukkit
2018-07-15 02:00:00 +02:00
this.P();
2018-08-26 04:00:00 +02:00
this.Q();
this.getWorldBorder().a(minecraftserver.au());
2018-07-15 02:00:00 +02:00
@@ -86,6 +106,7 @@
2015-03-16 12:32:53 +01:00
this.villages.a((World) this);
}
+ if (getServer().getScoreboardManager() == null) { // CraftBukkit
2018-08-26 04:00:00 +02:00
PersistentScoreboard persistentscoreboard = (PersistentScoreboard) this.a(DimensionManager.OVERWORLD, PersistentScoreboard::new, "scoreboard");
2015-03-16 12:32:53 +01:00
2018-07-15 02:00:00 +02:00
if (persistentscoreboard == null) {
@@ -95,6 +116,7 @@
2015-03-16 12:32:53 +01:00
2018-07-15 02:00:00 +02:00
persistentscoreboard.a((Scoreboard) this.server.getScoreboard());
this.server.getScoreboard().a((Runnable) (new RunnableSaveScoreboard(persistentscoreboard)));
+ } // CraftBukkit
2016-02-29 22:32:46 +01:00
this.getWorldBorder().setCenter(this.worldData.B(), this.worldData.C());
this.getWorldBorder().setDamageAmount(this.worldData.H());
2017-05-14 04:00:00 +02:00
this.getWorldBorder().setDamageBuffer(this.worldData.G());
2018-07-15 02:00:00 +02:00
@@ -106,9 +128,130 @@
2016-02-29 22:32:46 +01:00
this.getWorldBorder().setSize(this.worldData.D());
2015-03-11 11:15:39 +01:00
}
+ // CraftBukkit start
+ if (generator != null) {
+ getWorld().getPopulators().addAll(generator.getDefaultPopulators(getWorld()));
+ }
+ // CraftBukkit end
+
2014-11-25 22:32:16 +01:00
return this;
}
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ @Override
+ public TileEntity getTileEntity(BlockPosition pos) {
+ TileEntity result = super.getTileEntity(pos);
+ Block type = getType(pos).getBlock();
+
+ if (type == Blocks.CHEST) {
+ if (!(result instanceof TileEntityChest)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.FURNACE) {
+ if (!(result instanceof TileEntityFurnace)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.DROPPER) {
+ if (!(result instanceof TileEntityDropper)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.DISPENSER) {
+ if (!(result instanceof TileEntityDispenser)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.JUKEBOX) {
2018-07-15 02:00:00 +02:00
+ if (!(result instanceof TileEntityJukeBox)) {
2014-11-25 22:32:16 +01:00
+ result = fixTileEntity(pos, type, result);
+ }
2018-07-15 02:00:00 +02:00
+ } else if (type == Blocks.SPAWNER) {
2014-11-25 22:32:16 +01:00
+ if (!(result instanceof TileEntityMobSpawner)) {
+ result = fixTileEntity(pos, type, result);
+ }
2018-07-15 02:00:00 +02:00
+ } else if ((type == Blocks.SIGN) || (type == Blocks.WALL_SIGN)) {
2014-11-25 22:32:16 +01:00
+ if (!(result instanceof TileEntitySign)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.ENDER_CHEST) {
+ if (!(result instanceof TileEntityEnderChest)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.BREWING_STAND) {
+ if (!(result instanceof TileEntityBrewingStand)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.BEACON) {
+ if (!(result instanceof TileEntityBeacon)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.HOPPER) {
+ if (!(result instanceof TileEntityHopper)) {
+ result = fixTileEntity(pos, type, result);
+ }
2017-06-11 00:32:29 +02:00
+ } else if (type == Blocks.ENCHANTING_TABLE) {
+ if (!(result instanceof TileEntityEnchantTable)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.END_PORTAL) {
2017-06-12 19:41:18 +02:00
+ if (!(result instanceof TileEntityEnderPortal)) {
2017-06-11 00:32:29 +02:00
+ result = fixTileEntity(pos, type, result);
+ }
2018-07-15 02:00:00 +02:00
+ } else if (type instanceof BlockSkullAbstract) {
2017-06-11 00:32:29 +02:00
+ if (!(result instanceof TileEntitySkull)) {
+ result = fixTileEntity(pos, type, result);
+ }
2018-07-15 02:00:00 +02:00
+ } else if (type == Blocks.DAYLIGHT_DETECTOR) {
2017-06-11 00:32:29 +02:00
+ if (!(result instanceof TileEntityLightDetector)) {
+ result = fixTileEntity(pos, type, result);
+ }
2018-07-15 02:00:00 +02:00
+ } else if (type == Blocks.COMPARATOR) {
2017-06-11 00:32:29 +02:00
+ if (!(result instanceof TileEntityComparator)) {
+ result = fixTileEntity(pos, type, result);
+ }
2018-07-15 02:00:00 +02:00
+ }else if (type instanceof BlockBannerAbstract) {
2017-06-11 00:32:29 +02:00
+ if (!(result instanceof TileEntityBanner)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.STRUCTURE_BLOCK) {
+ if (!(result instanceof TileEntityStructure)) {
+ result = fixTileEntity(pos, type, result);
+ }
2017-06-12 19:41:18 +02:00
+ } else if (type == Blocks.END_GATEWAY) {
2017-06-11 00:32:29 +02:00
+ if (!(result instanceof TileEntityEndGateway)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.COMMAND_BLOCK) {
+ if (!(result instanceof TileEntityCommand)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.STRUCTURE_BLOCK) {
+ if (!(result instanceof TileEntityStructure)) {
+ result = fixTileEntity(pos, type, result);
+ }
2018-07-15 02:00:00 +02:00
+ } else if (type instanceof BlockBed) {
2017-06-11 00:32:29 +02:00
+ if (!(result instanceof TileEntityBed)) {
+ result = fixTileEntity(pos, type, result);
+ }
2014-11-25 22:32:16 +01:00
+ }
+
+ 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}" + ". "
2018-07-15 02:00:00 +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});
2014-11-25 22:32:16 +01:00
+
2016-02-29 22:32:46 +01:00
+ if (type instanceof ITileEntity) {
2018-07-15 02:00:00 +02:00
+ TileEntity replacement = ((ITileEntity) type).a(this);
2014-11-25 22:32:16 +01:00
+ replacement.world = this;
+ this.setTileEntity(pos, replacement);
+ return replacement;
+ } else {
+ this.getServer().getLogger().severe("Don't know how to fix for this type... Can't do anything! :(");
+ return found;
+ }
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2018-08-26 04:00:00 +02:00
public void doTick(BooleanSupplier booleansupplier) {
this.P = true;
super.doTick(booleansupplier);
2018-07-15 02:00:00 +02:00
@@ -128,9 +271,12 @@
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
this.methodProfiler.a("spawner");
2014-11-25 22:32:16 +01:00
- if (this.getGameRules().getBoolean("doMobSpawning") && this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
2016-02-29 22:32:46 +01:00
- this.spawnerCreature.a(this, this.allowMonsters, this.allowAnimals, this.worldData.getTime() % 400L == 0L);
2018-07-15 02:00:00 +02:00
- this.getChunkProviderServer().a(this, this.allowMonsters, this.allowAnimals);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Only call spawner if we have players online and the world allows for mobs or animals
+ long time = this.worldData.getTime();
+ if (this.getGameRules().getBoolean("doMobSpawning") && this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES && (this.allowMonsters || this.allowAnimals) && (this instanceof WorldServer && this.players.size() > 0)) {
2016-02-29 22:32:46 +01:00
+ this.spawnerCreature.a(this, this.allowMonsters && (this.ticksPerMonsterSpawns != 0 && time % this.ticksPerMonsterSpawns == 0L), this.allowAnimals && (this.ticksPerAnimalSpawns != 0 && time % this.ticksPerAnimalSpawns == 0L), this.worldData.getTime() % 400L == 0L);
2018-07-15 02:00:00 +02:00
+ this.getChunkProviderServer().a(this, this.allowMonsters && (this.ticksPerMonsterSpawns != 0 && time % this.ticksPerMonsterSpawns == 0L), this.allowAnimals && (this.ticksPerAnimalSpawns != 0 && time % this.ticksPerAnimalSpawns == 0L));
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
this.methodProfiler.c("chunkSource");
2018-07-15 02:00:00 +02:00
@@ -160,6 +306,8 @@
this.methodProfiler.e();
2018-08-26 04:00:00 +02:00
this.an();
this.P = false;
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ this.getWorld().processChunkGC(); // CraftBukkit
}
2018-07-15 02:00:00 +02:00
public boolean j_() {
@@ -191,7 +339,7 @@
2014-11-25 22:32:16 +01:00
2015-05-05 22:43:47 +02:00
if (entityhuman.isSpectator()) {
2014-11-25 22:32:16 +01:00
++i;
- } else if (entityhuman.isSleeping()) {
2015-02-26 23:41:06 +01:00
+ } else if (entityhuman.isSleeping() || entityhuman.fauxSleeping) {
2014-11-25 22:32:16 +01:00
++j;
}
}
2018-07-15 02:00:00 +02:00
@@ -223,25 +371,46 @@
2014-11-25 22:32:16 +01:00
}
2018-08-26 04:00:00 +02:00
private void b() {
2014-11-25 22:32:16 +01:00
- this.worldData.setWeatherDuration(0);
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
2015-01-04 23:50:48 +01:00
this.worldData.setStorm(false);
2014-11-25 22:32:16 +01:00
- this.worldData.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....
+ if (!this.worldData.hasStorm()) {
2014-11-25 22:32:16 +01:00
+ this.worldData.setWeatherDuration(0);
+ }
2015-01-04 23:50:48 +01:00
+ // 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()) {
2014-11-25 22:32:16 +01:00
+ this.worldData.setThunderDuration(0);
+ }
+ // CraftBukkit end
}
public boolean everyoneDeeplySleeping() {
2018-08-26 04:00:00 +02:00
if (this.J && !this.isClientSide) {
2014-11-25 22:32:16 +01:00
Iterator iterator = this.players.iterator();
+ // CraftBukkit - This allows us to assume that some people are in bed but not really, allowing time to pass in spite of AFKers
+ boolean foundActualSleepers = false;
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
EntityHuman entityhuman;
do {
if (!iterator.hasNext()) {
- return true;
+ return foundActualSleepers;
}
entityhuman = (EntityHuman) iterator.next();
2016-02-29 22:32:46 +01:00
- } while (entityhuman.isSpectator() || entityhuman.isDeeplySleeping());
2015-04-13 12:04:38 +02:00
+
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ if (entityhuman.isDeeplySleeping()) {
+ foundActualSleepers = true;
+ }
2015-09-06 07:05:56 +02:00
+ } while (!entityhuman.isSpectator() || entityhuman.isDeeplySleeping() || entityhuman.fauxSleeping);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
return false;
} else {
2018-08-26 04:00:00 +02:00
@@ -316,7 +485,7 @@
2018-07-15 02:00:00 +02:00
entityhorseskeleton.s(true);
2016-11-17 02:41:03 +01: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
2018-08-26 04:00:00 +02:00
}
this.strikeLightning(new EntityLightning(this, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, flag2));
2018-07-15 02:00:00 +02:00
@@ -332,11 +501,11 @@
BiomeBase biomebase = this.getBiome(blockposition);
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
if (biomebase.a((IWorldReader) this, blockposition1)) {
2014-11-25 22:32:16 +01:00
- this.setTypeUpdate(blockposition1, Blocks.ICE.getBlockData());
2017-06-03 09:39:03 +02:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.ICE.getBlockData(), null); // CraftBukkit
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
if (flag && biomebase.b(this, blockposition)) {
- this.setTypeUpdate(blockposition, Blocks.SNOW.getBlockData());
2018-07-19 07:44:55 +02:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition, Blocks.SNOW.getBlockData(), null); // CraftBukkit
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
if (flag && this.getBiome(blockposition1).c() == BiomeBase.Precipitation.RAIN) {
@@ -385,7 +554,7 @@
protected BlockPosition a(BlockPosition blockposition) {
BlockPosition blockposition1 = this.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING, blockposition);
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(blockposition1, new BlockPosition(blockposition1.getX(), this.getHeight(), blockposition1.getZ()))).g(3.0D);
- List list = this.a(EntityLiving.class, axisalignedbb, (entityliving) -> {
+ List list = this.a(EntityLiving.class, axisalignedbb, (Predicate<EntityLiving>) (entityliving) -> { // CraftBukkit - decompile error
return entityliving != null && entityliving.isAlive() && this.e(entityliving.getChunkCoordinates());
});
@@ -401,7 +570,7 @@
2014-11-25 22:32:16 +01:00
}
public void tickEntities() {
- if (this.players.isEmpty()) {
2015-02-26 23:41:06 +01:00
+ if (false && this.players.isEmpty()) { // CraftBukkit - this prevents entity cleanup, other issues on servers with no players
2016-02-29 22:32:46 +01:00
if (this.emptyTime++ >= 300) {
2014-11-25 22:32:16 +01:00
return;
}
2018-07-15 02:00:00 +02:00
@@ -490,6 +659,7 @@
2015-04-13 12:04:38 +02:00
2014-11-25 22:32:16 +01:00
}
+ /* CraftBukkit start - We prevent spawning in general, so this butchering is not needed
public void entityJoinedWorld(Entity entity, boolean flag) {
if (!this.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
entity.die();
2018-07-15 02:00:00 +02:00
@@ -501,6 +671,7 @@
2014-11-25 22:32:16 +01:00
super.entityJoinedWorld(entity, flag);
}
+ // CraftBukkit end */
private boolean getSpawnNPCs() {
return this.server.getSpawnNPCs();
2018-07-15 02:00:00 +02:00
@@ -513,7 +684,21 @@
2018-08-26 04:00:00 +02:00
protected IChunkProvider r() {
2014-11-25 22:32:16 +01:00
IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider);
2015-02-26 23:41:06 +01:00
2018-07-15 02:00:00 +02:00
- return new ChunkProviderServer(this, ichunkloader, this.worldProvider.getChunkGenerator(), this.server);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ org.bukkit.craftbukkit.generator.InternalChunkGenerator gen;
+
+ if (this.generator != null) {
+ gen = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, this.getSeed(), this.generator);
+ } else if (this.worldProvider instanceof WorldProviderHell) {
+ gen = new org.bukkit.craftbukkit.generator.NetherChunkGenerator(this, this.getSeed());
+ } else if (this.worldProvider instanceof WorldProviderTheEnd) {
+ gen = new org.bukkit.craftbukkit.generator.SkyLandsChunkGenerator(this, this.getSeed());
+ } else {
+ gen = new org.bukkit.craftbukkit.generator.NormalChunkGenerator(this, this.getSeed());
+ }
2015-02-26 23:41:06 +01:00
+
2018-07-15 02:00:00 +02:00
+ return new ChunkProviderServer(this, ichunkloader, gen, this.server);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
2016-05-10 13:47:39 +02:00
public boolean a(EntityHuman entityhuman, BlockPosition blockposition) {
2018-07-15 02:00:00 +02:00
@@ -572,6 +757,22 @@
BlockPosition blockposition = worldchunkmanager.a(0, 0, 256, list, random);
ChunkCoordIntPair chunkcoordintpair = blockposition == null ? new ChunkCoordIntPair(0, 0) : new ChunkCoordIntPair(blockposition);
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +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) {
WorldServer.a.warn("Unable to find spawn biome");
}
@@ -647,6 +848,7 @@
2016-02-29 22:32:46 +01:00
ChunkProviderServer chunkproviderserver = this.getChunkProviderServer();
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
if (chunkproviderserver.d()) {
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) {
2018-07-15 02:00:00 +02:00
iprogressupdate.a(new ChatMessage("menu.savingLevel", new Object[0]));
2014-12-03 20:35:33 +01:00
}
2018-07-15 02:00:00 +02:00
@@ -657,7 +859,8 @@
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
chunkproviderserver.a(flag);
- ArrayList arraylist = Lists.newArrayList(chunkproviderserver.a());
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - ArrayList -> Collection
2018-08-26 04:00:00 +02:00
+ java.util.Collection arraylist = chunkproviderserver.a();
2015-02-26 23:41:06 +01:00
Iterator iterator = arraylist.iterator();
2014-11-25 22:32:16 +01:00
while (iterator.hasNext()) {
2018-08-26 04:00:00 +02:00
@@ -691,6 +894,12 @@
2016-03-02 23:57:53 +01:00
}
}
+ // CraftBukkit start - Save secondary data for nether/end
+ if (this instanceof SecondaryWorldServer) {
2018-07-15 02:00:00 +02:00
+ ((SecondaryWorldServer) this).c(); // As above
2016-03-02 23:57:53 +01:00
+ }
+ // CraftBukkit end
+
this.worldData.a(this.getWorldBorder().getSize());
this.worldData.d(this.getWorldBorder().getCenterX());
this.worldData.c(this.getWorldBorder().getCenterZ());
2018-08-26 04:00:00 +02:00
@@ -705,9 +914,13 @@
this.h().a();
2016-10-16 08:20:12 +02:00
}
- public boolean addEntity(Entity entity) {
2016-12-20 21:00:00 +01:00
- return this.j(entity) ? super.addEntity(entity) : false;
2016-10-16 08:20:12 +02:00
+ // CraftBukkit start
+ public boolean addEntity(Entity entity, SpawnReason spawnReason) { // Changed signature, added SpawnReason
+ // World.addEntity(Entity) will call this, and we still want to perform
+ // existing entity checking when it's called with a SpawnReason
2016-12-20 21:00:00 +01:00
+ return this.j(entity) ? super.addEntity(entity, spawnReason) : false;
2016-10-16 08:20:12 +02:00
}
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
public void a(Stream<Entity> stream) {
stream.forEach((entity) -> {
@@ -721,7 +934,7 @@
2016-02-29 22:32:46 +01:00
2016-12-20 21:00:00 +01:00
private boolean j(Entity entity) {
2016-02-29 22:32:46 +01:00
if (entity.dead) {
2018-07-15 02:00:00 +02:00
- WorldServer.a.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getName(entity.P()));
+ // WorldServer.a.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getName(entity.P())); // CraftBukkit
2016-02-29 22:32:46 +01:00
return false;
} else {
UUID uuid = entity.getUniqueID();
2018-08-26 04:00:00 +02:00
@@ -733,7 +946,7 @@
2018-07-15 02:00:00 +02:00
this.g.remove(entity1);
2016-02-29 22:32:46 +01:00
} else {
if (!(entity instanceof EntityHuman)) {
2018-07-15 02:00:00 +02:00
- WorldServer.a.warn("Keeping entity {} that already exists with UUID {}", EntityTypes.getName(entity1.P()), uuid.toString());
+ // WorldServer.a.warn("Keeping entity {} that already exists with UUID {}", EntityTypes.getName(entity1.P()), uuid.toString()); // CraftBukkit
2016-02-29 22:32:46 +01:00
return false;
}
2018-08-26 04:00:00 +02:00
@@ -786,8 +999,16 @@
2014-11-25 22:32:16 +01:00
}
public boolean strikeLightning(Entity entity) {
+ // CraftBukkit start
+ LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
+ this.getServer().getPluginManager().callEvent(lightning);
+
+ if (lightning.isCancelled()) {
+ return false;
+ }
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
if (super.strikeLightning(entity)) {
2018-08-26 04:00:00 +02:00
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutSpawnEntityWeather(entity));
2016-04-17 18:47:51 +02:00
+ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, dimension, new PacketPlayOutSpawnEntityWeather(entity)); // CraftBukkit - Use dimension
2014-11-25 22:32:16 +01:00
return true;
2016-04-17 18:47:51 +02:00
} else {
return false;
2018-08-26 04:00:00 +02:00
@@ -803,6 +1024,14 @@
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
public Explosion createExplosion(@Nullable Entity entity, DamageSource damagesource, double d0, double d1, double d2, float f, boolean flag, boolean flag1) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
+ Explosion explosion = super.createExplosion(entity, damagesource, d0, d1, d2, f, flag, flag1);
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
Explosion explosion = new Explosion(this, entity, d0, d1, d2, f, flag, flag1);
2018-07-15 02:00:00 +02:00
if (damagesource != null) {
2018-08-26 04:00:00 +02:00
@@ -811,6 +1040,8 @@
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
if (!flag1) {
explosion.clearBlocks();
}
2018-08-26 04:00:00 +02:00
@@ -837,7 +1068,8 @@
2018-07-15 02:00:00 +02:00
BlockActionData blockactiondata = (BlockActionData) this.d.removeFirst();
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
if (this.a(blockactiondata)) {
2018-08-26 04:00:00 +02:00
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.b(), blockactiondata.c(), blockactiondata.d()));
2018-07-15 02:00:00 +02:00
+ // CraftBukkit - this.worldProvider.dimension -> this.dimension
+ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, dimension, new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.b(), blockactiondata.c(), blockactiondata.d()));
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
@@ -858,6 +1090,7 @@
2017-05-19 13:00:13 +02:00
boolean flag = this.isRaining();
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
super.w();
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start
2018-07-15 02:00:00 +02:00
if (this.o != this.p) {
2018-08-26 04:00:00 +02:00
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(7, this.p)), this.worldProvider.getDimensionManager());
2014-11-25 22:32:16 +01:00
}
2018-08-26 04:00:00 +02:00
@@ -876,6 +1109,21 @@
2018-07-15 02:00:00 +02:00
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.p));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.r));
2014-11-25 22:32:16 +01:00
}
+ // */
2017-05-19 13:00:13 +02:00
+ if (flag != this.isRaining()) {
2014-11-25 22:32:16 +01:00
+ // Only send weather packets to those affected
+ for (int i = 0; i < this.players.size(); ++i) {
+ if (((EntityPlayer) this.players.get(i)).world == this) {
+ ((EntityPlayer) this.players.get(i)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false);
+ }
+ }
+ }
2014-12-02 16:13:07 +01:00
+ for (int i = 0; i < this.players.size(); ++i) {
+ if (((EntityPlayer) this.players.get(i)).world == this) {
2018-07-15 02:00:00 +02:00
+ ((EntityPlayer) this.players.get(i)).updateWeather(this.o, this.p, this.q, this.r);
2014-12-02 16:13:07 +01:00
+ }
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
}
2018-08-26 10:26:09 +02:00
@@ -909,13 +1157,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) {
2018-08-26 10:26:09 +02:00
- PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, false, (float) d0, (float) d1, (float) 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) {
+ PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, force, (float) d0, (float) d1, (float) 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
}
}