2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/WorldServer.java
+++ b/net/minecraft/server/WorldServer.java
2016-10-16 08:20:12 +02:00
@@ -19,14 +19,26 @@
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();
2015-02-26 23:41:06 +01:00
private final MinecraftServer server;
2015-06-06 11:33:48 +02:00
public EntityTracker tracker;
2015-02-26 23:41:06 +01:00
private final PlayerChunkMap manager;
2016-02-29 22:32:46 +01:00
- private final Set<NextTickListEntry> nextTickListHash = Sets.newHashSet();
- private final TreeSet<NextTickListEntry> nextTickList = new TreeSet();
+ // private final Set<NextTickListEntry> nextTickListHash = Sets.newHashSet();
+ private final HashTreeSet<NextTickListEntry> nextTickList = new HashTreeSet<NextTickListEntry>(); // CraftBukkit - HashTreeSet
2015-04-13 12:04:38 +02:00
private final Map<UUID, Entity> entitiesByUUID = Maps.newHashMap();
public boolean savingDisabled;
2016-02-29 22:32:46 +01:00
private boolean O;
2016-10-16 08:20:12 +02:00
@@ -38,14 +50,22 @@
2016-02-29 22:32:46 +01:00
private int T;
2016-06-09 03:43:49 +02:00
private final List<NextTickListEntry> U = Lists.newArrayList();
2014-11-25 22:32:16 +01:00
- public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, WorldData worlddata, int i, MethodProfiler methodprofiler) {
2016-02-29 22:32:46 +01:00
- super(idatamanager, worlddata, DimensionManager.a(i).d(), methodprofiler, false);
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2014-11-25 22:32:16 +01:00
+ public final int dimension;
+
+ // Add env and gen to constructor
2015-02-26 23:41:06 +01:00
+ public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, WorldData worlddata, int i, MethodProfiler methodprofiler, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) {
2016-02-29 22:32:46 +01:00
+ super(idatamanager, worlddata, DimensionManager.a(env.getId()).d(), methodprofiler, false, gen, env);
2014-11-25 22:32:16 +01:00
+ this.dimension = i;
+ 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
this.server = minecraftserver;
this.tracker = new EntityTracker(this);
this.manager = new PlayerChunkMap(this);
2016-02-29 22:32:46 +01:00
this.worldProvider.a((World) this);
this.chunkProvider = this.n();
- this.portalTravelAgent = new PortalTravelAgent(this);
+ this.portalTravelAgent = new org.bukkit.craftbukkit.CraftTravelAgent(this); // CraftBukkit
this.H();
this.I();
2016-11-17 02:41:03 +01:00
this.getWorldBorder().a(minecraftserver.aE());
2016-10-16 08:20:12 +02:00
@@ -64,6 +84,7 @@
2015-03-16 12:32:53 +01:00
this.villages.a((World) this);
}
+ if (getServer().getScoreboardManager() == null) { // CraftBukkit
this.scoreboard = new ScoreboardServer(this.server);
PersistentScoreboard persistentscoreboard = (PersistentScoreboard) this.worldMaps.get(PersistentScoreboard.class, "scoreboard");
2016-10-16 08:20:12 +02:00
@@ -74,6 +95,11 @@
2015-03-16 12:32:53 +01:00
persistentscoreboard.a(this.scoreboard);
2016-02-29 22:32:46 +01:00
((ScoreboardServer) this.scoreboard).a((Runnable) (new RunnableSaveScoreboard(persistentscoreboard)));
2015-03-16 12:32:53 +01:00
+ // CraftBukkit start
+ } else {
+ this.scoreboard = getServer().getScoreboardManager().getMainScoreboard().getHandle();
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.B = new LootTableRegistry(new File(new File(this.dataManager.getDirectory(), "data"), "loot_tables"));
this.getWorldBorder().setCenter(this.worldData.B(), this.worldData.C());
this.getWorldBorder().setDamageAmount(this.worldData.H());
2016-10-16 08:20:12 +02:00
@@ -86,9 +112,98 @@
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) {
2015-02-26 23:41:06 +01:00
+ if (!(result instanceof BlockJukeBox.TileEntityRecordPlayer)) {
2014-11-25 22:32:16 +01:00
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.NOTEBLOCK) {
+ if (!(result instanceof TileEntityNote)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if (type == Blocks.MOB_SPAWNER) {
+ if (!(result instanceof TileEntityMobSpawner)) {
+ result = fixTileEntity(pos, type, result);
+ }
+ } else if ((type == Blocks.STANDING_SIGN) || (type == Blocks.WALL_SIGN)) {
+ 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);
+ }
+ }
+
+ 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(), org.bukkit.Material.getMaterial(Block.getId(type)).toString(), found});
+
2016-02-29 22:32:46 +01:00
+ if (type instanceof ITileEntity) {
+ TileEntity replacement = ((ITileEntity) type).a(this, type.toLegacyData(this.getType(pos)));
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;
+ }
+ }
+
+ private boolean canSpawn(int x, int z) {
+ if (this.generator != null) {
+ return this.generator.canSpawn(this.getWorld(), x, z);
+ } else {
+ return this.worldProvider.canSpawn(x, z);
+ }
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
public void doTick() {
super.doTick();
2015-02-26 23:41:06 +01:00
if (this.getWorldData().isHardcore() && this.getDifficulty() != EnumDifficulty.HARD) {
2016-10-16 08:20:12 +02:00
@@ -106,9 +221,11 @@
2016-02-29 22:32:46 +01:00
this.f();
2014-11-25 22:32:16 +01:00
}
2015-02-26 23:41:06 +01:00
- this.methodProfiler.a("mobSpawner");
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);
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);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
this.methodProfiler.c("chunkSource");
2016-10-16 08:20:12 +02:00
@@ -137,6 +254,8 @@
2016-02-29 22:32:46 +01:00
this.portalTravelAgent.a(this.getTime());
2014-11-25 22:32:16 +01:00
this.methodProfiler.b();
2016-02-29 22:32:46 +01:00
this.ao();
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ this.getWorld().processChunkGC(); // CraftBukkit
}
2016-05-10 13:47:39 +02:00
@Nullable
2016-10-16 08:20:12 +02:00
@@ -164,7 +283,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;
}
}
2016-11-17 02:41:03 +01:00
@@ -193,25 +312,46 @@
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
private void c() {
2014-11-25 22:32:16 +01:00
- this.worldData.setWeatherDuration(0);
2015-01-04 23:50:48 +01:00
this.worldData.setStorm(false);
2014-11-25 22:32:16 +01:00
- this.worldData.setThunderDuration(0);
+ // CraftBukkit start
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() {
2015-02-26 23:41:06 +01:00
if (this.O && !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 {
2016-11-17 02:41:03 +01:00
@@ -281,7 +421,7 @@
entityhorseskeleton.p(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
2016-03-13 16:38:07 +01:00
this.strikeLightning(new EntityLightning(this, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), true));
} else {
this.strikeLightning(new EntityLightning(this, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), false));
2016-12-09 02:45:21 +01:00
@@ -297,11 +437,11 @@
2014-11-25 22:32:16 +01:00
BlockPosition blockposition1 = blockposition.down();
2016-02-29 22:32:46 +01:00
if (this.v(blockposition1)) {
2014-11-25 22:32:16 +01:00
- this.setTypeUpdate(blockposition1, Blocks.ICE.getBlockData());
2016-12-09 02:45:21 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.ICE, null); // CraftBukkit
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
if (flag && this.f(blockposition, true)) {
2014-11-25 22:32:16 +01:00
- this.setTypeUpdate(blockposition, Blocks.SNOW_LAYER.getBlockData());
2016-12-09 02:45:21 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition, Blocks.SNOW_LAYER, null); // CraftBukkit
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
if (flag && this.getBiome(blockposition1).d()) {
2016-12-09 02:45:21 +01:00
@@ -376,7 +516,7 @@
2016-02-29 22:32:46 +01:00
public boolean b(BlockPosition blockposition, Block block) {
NextTickListEntry nextticklistentry = new NextTickListEntry(blockposition, block);
- return this.nextTickListHash.contains(nextticklistentry);
+ return this.nextTickList.contains(nextticklistentry); // CraftBukkit
}
public void a(BlockPosition blockposition, Block block, int i) {
2016-12-09 02:45:21 +01:00
@@ -415,8 +555,8 @@
2015-04-13 12:04:38 +02:00
nextticklistentry.a(j);
}
2016-02-29 22:32:46 +01:00
- if (!this.nextTickListHash.contains(nextticklistentry)) {
- this.nextTickListHash.add(nextticklistentry);
+ // CraftBukkit - use nextTickList
+ if (!this.nextTickList.contains(nextticklistentry)) {
this.nextTickList.add(nextticklistentry);
2015-04-13 12:04:38 +02:00
}
}
2016-12-09 02:45:21 +01:00
@@ -438,15 +578,15 @@
2015-04-13 12:04:38 +02:00
nextticklistentry.a((long) i + this.worldData.getTime());
}
2016-02-29 22:32:46 +01:00
- if (!this.nextTickListHash.contains(nextticklistentry)) {
- this.nextTickListHash.add(nextticklistentry);
+ // CraftBukkit - use nextTickList
+ if (!this.nextTickList.contains(nextticklistentry)) {
this.nextTickList.add(nextticklistentry);
2015-04-13 12:04:38 +02:00
}
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;
}
2016-12-09 02:45:21 +01:00
@@ -516,11 +656,17 @@
2015-04-13 12:04:38 +02:00
} else {
2016-02-29 22:32:46 +01:00
int i = this.nextTickList.size();
2015-04-13 12:04:38 +02:00
2016-02-29 22:32:46 +01:00
- if (i != this.nextTickListHash.size()) {
2015-04-13 12:04:38 +02:00
+ if (false) { // CraftBukkit
2014-11-25 22:32:16 +01:00
throw new IllegalStateException("TickNextTick list out of synch");
} else {
2016-03-30 21:50:59 +02:00
if (i > 65536) {
- i = 65536;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - If the server has too much to process over time, try to alleviate that
2016-03-30 21:50:59 +02:00
+ if (i > 20 * 65536) {
2014-11-25 22:32:16 +01:00
+ i = i / 20;
+ } else {
2016-03-30 21:50:59 +02:00
+ i = 65536;
2014-11-25 22:32:16 +01:00
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
this.methodProfiler.a("cleaning");
2016-12-09 02:45:21 +01:00
@@ -533,8 +679,9 @@
2015-04-13 12:04:38 +02:00
break;
}
2016-02-29 22:32:46 +01:00
+ // CraftBukkit - use nextTickList
this.nextTickList.remove(nextticklistentry);
- this.nextTickListHash.remove(nextticklistentry);
+ // this.nextTickListHash.remove(nextticklistentry);
this.U.add(nextticklistentry);
2015-04-13 12:04:38 +02:00
}
2016-12-09 02:45:21 +01:00
@@ -604,7 +751,7 @@
2015-03-15 22:11:15 +01:00
if (blockposition.getX() >= structureboundingbox.a && blockposition.getX() < structureboundingbox.d && blockposition.getZ() >= structureboundingbox.c && blockposition.getZ() < structureboundingbox.f) {
if (flag) {
2016-02-29 22:32:46 +01:00
if (i == 0) {
- this.nextTickListHash.remove(nextticklistentry);
+ // this.nextTickListHash.remove(nextticklistentry); // CraftBukkit - removed
}
2015-04-13 12:04:38 +02:00
2016-02-29 22:32:46 +01:00
iterator.remove();
2016-12-09 02:45:21 +01:00
@@ -622,6 +769,7 @@
2014-11-25 22:32:16 +01:00
return arraylist;
}
+ /* 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();
2016-12-09 02:45:21 +01:00
@@ -633,6 +781,7 @@
2014-11-25 22:32:16 +01:00
super.entityJoinedWorld(entity, flag);
}
+ // CraftBukkit end */
private boolean getSpawnNPCs() {
return this.server.getSpawnNPCs();
2016-12-09 02:45:21 +01:00
@@ -645,7 +794,54 @@
2016-02-29 22:32:46 +01:00
protected IChunkProvider n() {
2014-11-25 22:32:16 +01:00
IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider);
2015-02-26 23:41:06 +01:00
2016-02-29 22:32:46 +01:00
- return new ChunkProviderServer(this, ichunkloader, this.worldProvider.getChunkGenerator());
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
+
2016-02-29 22:32:46 +01:00
+ return new ChunkProviderServer(this, ichunkloader, gen);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2016-05-10 13:47:39 +02:00
+ }
+
+ public List<TileEntity> getTileEntities(int i, int j, int k, int l, int i1, int j1) {
+ ArrayList arraylist = Lists.newArrayList();
+
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Get tile entities from chunks instead of world
+ for (int chunkX = (i >> 4); chunkX <= ((l - 1) >> 4); chunkX++) {
+ for (int chunkZ = (k >> 4); chunkZ <= ((j1 - 1) >> 4); chunkZ++) {
+ Chunk chunk = getChunkAt(chunkX, chunkZ);
+ if (chunk == null) {
+ continue;
+ }
+ for (Object te : chunk.tileEntities.values()) {
+ TileEntity tileentity = (TileEntity) te;
+ if ((tileentity.position.getX() >= i) && (tileentity.position.getY() >= j) && (tileentity.position.getZ() >= k) && (tileentity.position.getX() < l) && (tileentity.position.getY() < i1) && (tileentity.position.getZ() < j1)) {
+ arraylist.add(tileentity);
+ }
+ }
+ }
+ }
+ /*
2016-05-10 13:47:39 +02:00
+ for (int k1 = 0; k1 < this.tileEntityList.size(); ++k1) {
+ TileEntity tileentity = (TileEntity) this.tileEntityList.get(k1);
+ BlockPosition blockposition = tileentity.getPosition();
+
+ if (blockposition.getX() >= i && blockposition.getY() >= j && blockposition.getZ() >= k && blockposition.getX() < l && blockposition.getY() < i1 && blockposition.getZ() < j1) {
+ arraylist.add(tileentity);
+ }
+ }
2014-11-25 22:32:16 +01:00
+ */
+ // CraftBukkit end
2016-05-10 13:47:39 +02:00
+
+ return arraylist;
2014-11-25 22:32:16 +01:00
}
2016-05-10 13:47:39 +02:00
public boolean a(EntityHuman entityhuman, BlockPosition blockposition) {
2016-12-09 02:45:21 +01:00
@@ -707,6 +903,23 @@
2014-11-25 22:32:16 +01:00
int j = this.worldProvider.getSeaLevel();
2016-02-29 22:32:46 +01:00
int k = 8;
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()));
+ this.isLoading = false;
+ return;
+ }
+ }
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
+
2014-11-25 22:32:16 +01:00
if (blockposition != null) {
i = blockposition.getX();
2015-02-26 23:41:06 +01:00
k = blockposition.getZ();
2016-12-09 02:45:21 +01:00
@@ -716,7 +929,7 @@
2014-11-25 22:32:16 +01:00
int l = 0;
- while (!this.worldProvider.canSpawn(i, k)) {
+ while (!this.canSpawn(i, k)) { // CraftBukkit - use our own canSpawn
i += random.nextInt(64) - random.nextInt(64);
k += random.nextInt(64) - random.nextInt(64);
++l;
2016-12-09 02:45:21 +01:00
@@ -758,6 +971,7 @@
2016-02-29 22:32:46 +01:00
ChunkProviderServer chunkproviderserver = this.getChunkProviderServer();
2014-11-25 22:32:16 +01:00
2016-02-29 22:32:46 +01:00
if (chunkproviderserver.e()) {
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) {
iprogressupdate.a("Saving level");
2014-12-03 20:35:33 +01:00
}
2016-12-09 02:45:21 +01:00
@@ -768,7 +982,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
2016-02-29 22:32:46 +01:00
+ 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()) {
2016-12-09 02:45:21 +01:00
@@ -803,6 +1018,12 @@
2016-03-02 23:57:53 +01:00
}
}
+ // CraftBukkit start - Save secondary data for nether/end
+ if (this instanceof SecondaryWorldServer) {
+ ((SecondaryWorldServer) this).c();
+ }
+ // CraftBukkit end
+
this.worldData.a(this.getWorldBorder().getSize());
this.worldData.d(this.getWorldBorder().getCenterX());
this.worldData.c(this.getWorldBorder().getCenterZ());
2016-12-09 02:45:21 +01:00
@@ -816,9 +1037,13 @@
2016-10-16 08:20:12 +02:00
this.worldMaps.a();
}
- public boolean addEntity(Entity entity) {
- return this.i(entity) ? super.addEntity(entity) : false;
+ // 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
+ return this.i(entity) ? super.addEntity(entity, spawnReason) : false;
}
+ // CraftBukkit end
public void a(Collection<Entity> collection) {
ArrayList arraylist = Lists.newArrayList(collection);
2016-12-09 02:45:21 +01:00
@@ -837,7 +1062,7 @@
2016-02-29 22:32:46 +01:00
private boolean i(Entity entity) {
if (entity.dead) {
2016-11-17 02:41:03 +01:00
- WorldServer.a.warn("Tried to add entity {} but it was marked as removed already", new Object[] { EntityTypes.a(entity)});
+ // WorldServer.a.warn("Tried to add entity {} but it was marked as removed already", new Object[] { EntityTypes.a(entity)}); // CraftBukkit
2016-02-29 22:32:46 +01:00
return false;
} else {
UUID uuid = entity.getUniqueID();
2016-12-09 02:45:21 +01:00
@@ -849,7 +1074,7 @@
2016-02-29 22:32:46 +01:00
this.f.remove(entity1);
} else {
if (!(entity instanceof EntityHuman)) {
2016-11-17 02:41:03 +01:00
- WorldServer.a.warn("Keeping entity {} that already exists with UUID {}", new Object[] { EntityTypes.a(entity1), uuid.toString()});
+ // WorldServer.a.warn("Keeping entity {} that already exists with UUID {}", new Object[] { EntityTypes.a(entity1), uuid.toString()}); // CraftBukkit
2016-02-29 22:32:46 +01:00
return false;
}
2016-12-09 02:45:21 +01:00
@@ -902,8 +1127,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)) {
2016-04-17 18:47:51 +02:00
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, this.worldProvider.getDimensionManager().getDimensionID(), new PacketPlayOutSpawnEntityWeather(entity));
+ 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;
2016-12-09 02:45:21 +01:00
@@ -919,10 +1152,20 @@
2014-11-25 22:32:16 +01:00
}
2016-05-10 13:47:39 +02:00
public Explosion createExplosion(@Nullable Entity entity, double d0, double d1, double d2, float f, boolean flag, boolean flag1) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ Explosion explosion = super.createExplosion(entity, d0, d1, d2, f, flag, flag1);
+
+ 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);
explosion.a();
explosion.a(false);
+ */
+ // CraftBukkit end - TODO: Check if explosions are still properly implemented
if (!flag1) {
explosion.clearBlocks();
}
2016-12-09 02:45:21 +01:00
@@ -968,7 +1211,8 @@
2014-11-25 22:32:16 +01:00
BlockActionData blockactiondata = (BlockActionData) iterator.next();
if (this.a(blockactiondata)) {
2016-02-29 22:32:46 +01:00
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, this.worldProvider.getDimensionManager().getDimensionID(), new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.d(), blockactiondata.b(), blockactiondata.c()));
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - this.worldProvider.dimension -> this.dimension
2016-02-29 22:32:46 +01:00
+ 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.d(), blockactiondata.b(), blockactiondata.c()));
2014-11-25 22:32:16 +01:00
}
}
2016-12-09 02:45:21 +01:00
@@ -991,6 +1235,7 @@
2016-02-29 22:32:46 +01:00
boolean flag = this.W();
2014-11-25 22:32:16 +01:00
2016-02-29 22:32:46 +01:00
super.t();
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start
2016-02-29 22:32:46 +01:00
if (this.n != this.o) {
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(7, this.o)), this.worldProvider.getDimensionManager().getDimensionID());
2014-11-25 22:32:16 +01:00
}
2016-12-09 02:45:21 +01:00
@@ -1009,6 +1254,21 @@
2016-02-29 22:32:46 +01:00
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.o));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.q));
2014-11-25 22:32:16 +01:00
}
+ // */
2016-02-29 22:32:46 +01:00
+ if (flag != this.W()) {
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) {
2016-02-29 22:32:46 +01:00
+ ((EntityPlayer) this.players.get(i)).updateWeather(this.n, this.o, this.p, this.q);
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
}
2016-12-09 02:45:21 +01:00
@@ -1038,10 +1298,20 @@
2014-11-25 22:32:16 +01:00
}
public void a(EnumParticle enumparticle, boolean flag, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, int... aint) {
+ // CraftBukkit - visibility api support
+ sendParticles(null, enumparticle, flag, d0, d1, d2, i, d3, d4, d5, d6, aint);
+ }
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ public void sendParticles(EntityPlayer sender, EnumParticle enumparticle, boolean flag, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, int... aint) {
+ // CraftBukkit end
PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(enumparticle, flag, (float) d0, (float) d1, (float) d2, (float) d3, (float) d4, (float) d5, (float) d6, i, aint);
for (int j = 0; j < this.players.size(); ++j) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(j);
2014-12-28 15:56:18 +01:00
+ if (sender != null && !entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) continue; // CraftBukkit
2016-02-29 22:32:46 +01:00
+ BlockPosition blockposition = entityplayer.getChunkCoordinates();
+ double d7 = blockposition.distanceSquared(d0, d1, d2);
+
2014-11-25 22:32:16 +01:00
2016-02-29 22:32:46 +01:00
this.a(entityplayer, flag, d0, d1, d2, packetplayoutworldparticles);
}