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

588 Zeilen
27 KiB
Diff

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 @@
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;
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;
+import org.bukkit.event.weather.LightningStrikeEvent;
2019-12-21 02:06:18 +01:00
+import org.bukkit.event.world.TimeSkipEvent;
+// 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;
- public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey<World> resourcekey, ResourceKey<DimensionManager> resourcekey1, DimensionManager dimensionmanager, WorldLoadListener worldloadlistener, ChunkGenerator chunkgenerator, boolean flag, long i, List<MobSpawner> list, boolean flag1) {
- super(iworlddataserver, resourcekey, resourcekey1, dimensionmanager, minecraftserver::getMethodProfiler, false, flag, i);
+
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;
+
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
+ public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey<World> resourcekey, ResourceKey<DimensionManager> resourcekey1, 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, resourcekey1, dimensionmanager, minecraftserver::getMethodProfiler, false, flag, i, gen, env);
+ this.pvpMode = minecraftserver.getPVP();
2020-06-25 02:00:00 +02:00
+ convertable = convertable_conversionsession;
+ uuid = WorldUUID.getUUID(convertable_conversionsession.folder.toFile());
+ // 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, () -> {
return minecraftserver.D().getWorldPersistentData();
});
+ // CraftBukkit end
this.portalTravelAgent = new PortalTravelAgent(this);
this.N();
this.O();
@@ -97,8 +131,42 @@
} else {
this.dragonBattle = null;
}
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();
2020-06-25 02:00:00 +02:00
+ 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
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);
}
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());
}
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 @@
this.ah();
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);
entitylightning.c(Vec3D.c((BaseBlockPosition) blockposition));
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);
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) {
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
return entityliving != null && entityliving.isAlive() && this.f(entityliving.getChunkCoordinates());
});
2020-06-25 02:00:00 +02:00
@@ -465,7 +565,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;
2020-06-25 02:00:00 +02:00
@@ -483,10 +583,22 @@
}
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);
+ // 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);
+ }
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
this.worldDataServer.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....
2020-06-25 02:00:00 +02:00
+ if (!this.worldDataServer.isThundering()) {
+ this.worldDataServer.setThunderDuration(0);
+ }
+ // 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();
}
2020-06-25 02:00:00 +02:00
@@ -615,6 +728,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) {
2020-06-25 02:00:00 +02:00
iprogressupdate.a(new ChatMessage("menu.savingLevel"));
}
2020-06-25 02:00:00 +02:00
@@ -626,6 +740,14 @@
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());
+ // CraftBukkit end
}
2020-06-25 02:00:00 +02:00
private void ag() {
@@ -691,11 +813,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-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);
2019-04-23 04:00:00 +02:00
if (!(ichunkaccess instanceof Chunk)) {
2020-06-25 02:00:00 +02:00
@@ -779,7 +919,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-06-25 02:00:00 +02:00
@@ -830,10 +970,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-06-25 02:00:00 +02:00
@@ -854,9 +1001,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-06-25 02:00:00 +02:00
@@ -886,10 +1040,33 @@
this.everyoneSleeping();
}
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
+ public boolean strikeLightning(Entity entitylightning) {
+ return this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN);
+ }
+
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);
+ this.getServer().getPluginManager().callEvent(lightning);
+
+ if (lightning.isCancelled()) {
2020-06-25 02:00:00 +02:00
+ return false;
+ }
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-06-25 02:00:00 +02:00
@@ -898,6 +1075,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-06-25 02:00:00 +02:00
@@ -958,10 +1141,20 @@
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) {
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ Explosion explosion = super.createExplosion(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
+
+ if (explosion.wasCanceled) {
+ return explosion;
+ }
2015-02-26 23:41:06 +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
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-06-25 02:00:00 +02:00
@@ -1026,13 +1219,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;
}
}
@@ -1074,7 +1274,7 @@
@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-06-25 02:00:00 +02:00
@@ -1105,7 +1305,13 @@
2019-04-23 04:00:00 +02:00
@Override
public WorldMap a(String s) {
2020-06-25 02:00:00 +02:00
return (WorldMap) this.getMinecraftServer().D().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-06-25 02:00:00 +02:00
@@ -1412,6 +1618,11 @@
@Override
public void update(BlockPosition blockposition, Block block) {
if (!this.isDebugWorld()) {
+ // CraftBukkit start
+ if (populating) {
+ return;
+ }
+ // CraftBukkit end
this.applyPhysics(blockposition, block);
}
@@ -1426,12 +1637,12 @@
}
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
@@ -1440,16 +1651,32 @@
}
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
}
}