Update to Minecraft 1.18-pre5

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2021-11-22 09:00:00 +11:00
parent a852b81a69
commit 43702a9e10
700 changed files with 10286 additions and 10098 deletions

View File

@@ -1,15 +1,6 @@
--- a/net/minecraft/server/level/ChunkMapDistance.java
+++ b/net/minecraft/server/level/ChunkMapDistance.java
@@ -73,7 +73,7 @@
while (objectiterator.hasNext()) {
Entry<ArraySetSorted<Ticket<?>>> entry = (Entry) objectiterator.next();
- if (((ArraySetSorted) entry.getValue()).removeIf((ticket) -> {
+ if ((entry.getValue()).removeIf((ticket) -> { // CraftBukkit - decompile error
return ticket.b(this.ticketTickCounter);
})) {
this.ticketTracker.update(entry.getLongKey(), getLowestTicketLevel((ArraySetSorted) entry.getValue()), false);
@@ -109,10 +109,25 @@
@@ -125,10 +125,25 @@
}
if (!this.chunksToUpdateFutures.isEmpty()) {
@@ -23,7 +14,7 @@
+ iter.remove();
+ expectedSize--;
+
playerchunk.a(playerchunkmap, this.mainThreadExecutor);
playerchunk.updateFutures(playerchunkmap, this.mainThreadExecutor);
- });
- this.chunksToUpdateFutures.clear();
+
@@ -38,20 +29,17 @@
return true;
} else {
if (!this.ticketsToRelease.isEmpty()) {
@@ -148,23 +163,25 @@
@@ -164,7 +179,7 @@
}
}
- void addTicket(long i, Ticket<?> ticket) {
+ boolean addTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
ArraySetSorted<Ticket<?>> arraysetsorted = this.e(i);
int j = getLowestTicketLevel(arraysetsorted);
- Ticket<?> ticket1 = (Ticket) arraysetsorted.a((Object) ticket);
+ Ticket<?> ticket1 = (Ticket) arraysetsorted.a(ticket); // CraftBukkit - decompile error
ticket1.a(this.ticketTickCounter);
if (ticket.b() < j) {
this.ticketTracker.update(i, ticket.b(), true);
ArraySetSorted<Ticket<?>> arraysetsorted = this.getTickets(i);
int j = getTicketLevelAt(arraysetsorted);
Ticket<?> ticket1 = (Ticket) arraysetsorted.addOrGet(ticket);
@@ -174,13 +189,15 @@
this.ticketTracker.update(i, ticket.getTicketLevel(), true);
}
+ return ticket == ticket1; // CraftBukkit
@@ -59,7 +47,7 @@
- void removeTicket(long i, Ticket<?> ticket) {
+ boolean removeTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
ArraySetSorted<Ticket<?>> arraysetsorted = this.e(i);
ArraySetSorted<Ticket<?>> arraysetsorted = this.getTickets(i);
+ boolean removed = false; // CraftBukkit
if (arraysetsorted.remove(ticket)) {
@@ -68,49 +56,49 @@
}
if (arraysetsorted.isEmpty()) {
@@ -172,16 +189,29 @@
@@ -188,16 +205,29 @@
}
this.ticketTracker.update(i, getLowestTicketLevel(arraysetsorted), false);
this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false);
+ return removed; // CraftBukkit
}
public <T> void a(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
- this.addTicket(chunkcoordintpair.pair(), new Ticket<>(tickettype, i, t0));
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
- this.addTicket(chunkcoordintpair.toLong(), new Ticket<>(tickettype, i, t0));
+ // CraftBukkit start
+ this.addTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
+ }
+
+ public <T> boolean addTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkcoordintpair, int level, T identifier) {
+ return this.addTicket(chunkcoordintpair.pair(), new Ticket<>(ticketType, level, identifier));
+ return this.addTicket(chunkcoordintpair.toLong(), new Ticket<>(ticketType, level, identifier));
+ // CraftBukkit end
}
public <T> void b(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
public <T> void removeTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
- Ticket<T> ticket = new Ticket<>(tickettype, i, t0);
+ // CraftBukkit start
+ this.removeTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
+ }
- this.removeTicket(chunkcoordintpair.pair(), ticket);
- this.removeTicket(chunkcoordintpair.toLong(), ticket);
+ public <T> boolean removeTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkcoordintpair, int level, T identifier) {
+ Ticket<T> ticket = new Ticket<>(ticketType, level, identifier);
+
+ return this.removeTicket(chunkcoordintpair.pair(), ticket);
+ return this.removeTicket(chunkcoordintpair.toLong(), ticket);
+ // CraftBukkit end
}
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -224,6 +254,7 @@
public void b(SectionPosition sectionposition, EntityPlayer entityplayer) {
long i = sectionposition.r().pair();
public <T> void addRegionTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -252,6 +282,7 @@
ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk();
long i = chunkcoordintpair.toLong();
ObjectSet<EntityPlayer> objectset = (ObjectSet) this.playersPerChunk.get(i);
+ if (objectset == null) return; // CraftBukkit - SPIGOT-6208
objectset.remove(entityplayer);
if (objectset.isEmpty()) {
@@ -300,6 +331,26 @@
@@ -347,6 +378,26 @@
return this.tickingTicketsTracker;
}
+ // CraftBukkit start
@@ -122,7 +110,7 @@
+ ArraySetSorted<Ticket<?>> tickets = entry.getValue();
+ if (tickets.remove(target)) {
+ // copied from removeTicket
+ this.ticketTracker.update(entry.getLongKey(), getLowestTicketLevel(tickets), false);
+ this.ticketTracker.update(entry.getLongKey(), getTicketLevelAt(tickets), false);
+
+ // can't use entry after it's removed
+ if (tickets.isEmpty()) {

View File

@@ -6,7 +6,7 @@
+ // CraftBukkit start - properly implement isChunkLoaded
+ public boolean isChunkLoaded(int chunkX, int chunkZ) {
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunk(ChunkCoordIntPair.pair(chunkX, chunkZ));
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkCoordIntPair.asLong(chunkX, chunkZ));
+ if (chunk == null) {
+ return false;
+ }
@@ -14,7 +14,7 @@
+ }
+
+ public Chunk getChunkUnchecked(int chunkX, int chunkZ) {
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunk(ChunkCoordIntPair.pair(chunkX, chunkZ));
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkCoordIntPair.asLong(chunkX, chunkZ));
+ if (chunk == null) {
+ return null;
+ }
@@ -38,8 +38,8 @@
if (playerchunk == null) {
return null;
} else {
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.b(ChunkStatus.FULL).getNow((Object) null);
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.b(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow((Object) null);
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
if (either == null) {
return null;
@@ -48,43 +48,43 @@
+ IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
if (ichunkaccess1 != null) {
this.a(k, ichunkaccess1, ChunkStatus.FULL);
this.storeInCache(k, ichunkaccess1, ChunkStatus.FULL);
@@ -228,7 +246,15 @@
int l = 33 + ChunkStatus.a(chunkstatus);
PlayerChunk playerchunk = this.getChunk(k);
int l = 33 + ChunkStatus.getDistance(chunkstatus);
PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k);
- if (flag) {
+ // CraftBukkit start - don't add new ticket for currently unloading chunk
+ boolean currentlyUnloading = false;
+ if (playerchunk != null) {
+ PlayerChunk.State oldChunkState = PlayerChunk.getChunkState(playerchunk.oldTicketLevel);
+ PlayerChunk.State currentChunkState = PlayerChunk.getChunkState(playerchunk.getTicketLevel());
+ currentlyUnloading = (oldChunkState.isAtLeast(PlayerChunk.State.BORDER) && !currentChunkState.isAtLeast(PlayerChunk.State.BORDER));
+ PlayerChunk.State oldChunkState = PlayerChunk.getFullChunkStatus(playerchunk.oldTicketLevel);
+ PlayerChunk.State currentChunkState = PlayerChunk.getFullChunkStatus(playerchunk.getTicketLevel());
+ currentlyUnloading = (oldChunkState.isOrAfter(PlayerChunk.State.BORDER) && !currentChunkState.isOrAfter(PlayerChunk.State.BORDER));
+ }
+ if (flag && !currentlyUnloading) {
+ // CraftBukkit end
this.distanceManager.a(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.a(playerchunk, l)) {
GameProfilerFiller gameprofilerfiller = this.level.getMethodProfiler();
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.chunkAbsent(playerchunk, l)) {
GameProfilerFiller gameprofilerfiller = this.level.getProfiler();
@@ -247,7 +273,7 @@
}
private boolean a(@Nullable PlayerChunk playerchunk, int i) {
private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) {
- return playerchunk == null || playerchunk.getTicketLevel() > i;
+ return playerchunk == null || playerchunk.oldTicketLevel > i; // CraftBukkit using oldTicketLevel for isLoaded checks
}
@Override
@@ -307,7 +333,7 @@
}
@@ -314,7 +340,7 @@
} else if (!this.level.shouldTickBlocksAt(i)) {
return false;
} else {
- Either<Chunk, PlayerChunk.Failure> either = (Either) playerchunk.getTickingChunkFuture().getNow((Object) null);
+ Either<Chunk, PlayerChunk.Failure> either = (Either) playerchunk.getTickingChunkFuture().getNow(null); // CraftBukkit - decompile error
public boolean a(long i) {
- return this.a(i, PlayerChunk::a);
+ return this.a(i, (Function<PlayerChunk, CompletableFuture<Either<Chunk, PlayerChunk.Failure>>>) PlayerChunk::a); // CraftBukkit - decompile error
}
private boolean a(long i, Function<PlayerChunk, CompletableFuture<Either<Chunk, PlayerChunk.Failure>>> function) {
@@ -329,11 +355,31 @@
return either != null && either.left().isPresent();
}
@@ -327,11 +353,31 @@
@Override
public void close() throws IOException {
@@ -104,56 +104,50 @@
+ // CraftBukkit start - modelled on below
+ public void purgeUnload() {
+ this.level.getMethodProfiler().enter("purge");
+ this.distanceManager.purgeTickets();
+ this.tickDistanceManager();
+ this.level.getMethodProfiler().exitEnter("unload");
+ this.chunkMap.unloadChunks(() -> true);
+ this.level.getMethodProfiler().exit();
+ this.level.getProfiler().push("purge");
+ this.distanceManager.purgeStaleTickets();
+ this.runDistanceManagerUpdates();
+ this.level.getProfiler().popPush("unload");
+ this.chunkMap.tick(() -> true);
+ this.level.getProfiler().pop();
+ this.clearCache();
+ }
+ // CraftBukkit end
+
@Override
public void tick(BooleanSupplier booleansupplier) {
this.level.getMethodProfiler().enter("purge");
@@ -354,12 +400,12 @@
this.lastInhabitedUpdate = i;
WorldData worlddata = this.level.getWorldData();
boolean flag = this.level.isDebugWorld();
- boolean flag1 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag1 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !level.getPlayers().isEmpty(); // CraftBukkit
this.level.getProfiler().push("purge");
@@ -360,7 +406,7 @@
if (!flag) {
this.level.getMethodProfiler().enter("pollingChunks");
gameprofilerfiller.push("pollingChunks");
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
- boolean flag2 = worlddata.getTime() % 400L == 0L;
+ boolean flag2 = level.ticksPerAnimalSpawns != 0L && worlddata.getTime() % level.ticksPerAnimalSpawns == 0L; // CraftBukkit
- boolean flag1 = worlddata.getGameTime() % 400L == 0L;
+ boolean flag1 = level.ticksPerAnimalSpawns != 0L && worlddata.getGameTime() % level.ticksPerAnimalSpawns == 0L; // CraftBukkit
this.level.getMethodProfiler().enter("naturalSpawnCount");
int l = this.distanceManager.b();
@@ -394,7 +440,7 @@
gameprofilerfiller.push("naturalSpawnCount");
int l = this.distanceManager.getNaturalSpawnChunkCount();
@@ -381,7 +427,7 @@
}
this.level.getMethodProfiler().exitEnter("broadcast");
list.forEach((playerchunk) -> {
- Optional optional = ((Either) playerchunk.a().getNow(PlayerChunk.UNLOADED_LEVEL_CHUNK)).left();
+ Optional<Chunk> optional = ((Either) playerchunk.a().getNow(PlayerChunk.UNLOADED_LEVEL_CHUNK)).left(); // CraftBukkit - decompile error
gameprofilerfiller.popPush("spawnAndTick");
- boolean flag2 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag2 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !level.players().isEmpty(); // CraftBukkit
Objects.requireNonNull(playerchunk);
optional.ifPresent(playerchunk::a);
@@ -551,13 +597,19 @@
Collections.shuffle(list);
Iterator iterator1 = list.iterator();
@@ -571,18 +617,26 @@
}
@Override
- protected boolean executeNext() {
- protected boolean pollTask() {
+ // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
+ public boolean executeNext() {
+ public boolean pollTask() {
+ try {
if (ChunkProviderServer.this.tickDistanceManager()) {
if (ChunkProviderServer.this.runDistanceManagerUpdates()) {
return true;
} else {
ChunkProviderServer.this.lightEngine.queueUpdate();
return super.executeNext();
ChunkProviderServer.this.lightEngine.tryScheduleUpdate();
return super.pollTask();
}
+ } finally {
+ chunkMap.callbackExecutor.run();
@@ -161,4 +155,21 @@
+ // CraftBukkit end
}
}
}
- private static final class a extends Record {
+ // CraftBukkit start - decompile error
+ private static final record a(Chunk chunk, PlayerChunk holder) {
+ /*
final Chunk chunk;
final PlayerChunk holder;
@@ -602,6 +656,8 @@
public final boolean equals(Object object) {
return this.equals<invokedynamic>(this, object);
}
+ */
+ // CraftBukkit end
public Chunk chunk() {
return this.chunk;

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/net/minecraft/server/level/EntityTrackerEntry.java
@@ -42,6 +42,12 @@
@@ -40,6 +40,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -13,7 +13,7 @@
public class EntityTrackerEntry {
private static final Logger LOGGER = LogManager.getLogger();
@@ -63,8 +69,12 @@
@@ -61,8 +67,12 @@
private List<Entity> lastPassengers;
private boolean wasRiding;
private boolean wasOnGround;
@@ -27,12 +27,12 @@
this.ap = Vec3D.ZERO;
this.lastPassengers = Collections.emptyList();
this.level = worldserver;
@@ -84,22 +94,22 @@
@@ -82,22 +92,22 @@
if (!list.equals(this.lastPassengers)) {
this.lastPassengers = list;
- this.broadcast.accept(new PacketPlayOutMount(this.entity));
+ this.broadcastIncludingSelf(new PacketPlayOutMount(this.entity)); // CraftBukkit
+ this.broadcastAndSend(new PacketPlayOutMount(this.entity)); // CraftBukkit
}
- if (this.entity instanceof EntityItemFrame && this.tickCount % 10 == 0) {
@@ -42,26 +42,26 @@
- if (itemstack.getItem() instanceof ItemWorldMap) {
+ if (this.tickCount % 10 == 0 && itemstack.getItem() instanceof ItemWorldMap) { // CraftBukkit - Moved this.tickCounter % 10 logic here so item frames do not enter the other blocks
Integer integer = ItemWorldMap.d(itemstack);
WorldMap worldmap = ItemWorldMap.a(integer, (World) this.level);
Integer integer = ItemWorldMap.getMapId(itemstack);
WorldMap worldmap = ItemWorldMap.getSavedData(integer, this.level);
if (worldmap != null) {
- Iterator iterator = this.level.getPlayers().iterator();
- Iterator iterator = this.level.players().iterator();
+ Iterator<ServerPlayerConnection> iterator = this.trackedPlayers.iterator(); // CraftBukkit
while (iterator.hasNext()) {
- EntityPlayer entityplayer = (EntityPlayer) iterator.next();
+ EntityPlayer entityplayer = iterator.next().d(); // CraftBukkit
+ EntityPlayer entityplayer = iterator.next().getPlayer(); // CraftBukkit
worldmap.a((EntityHuman) entityplayer, itemstack);
Packet<?> packet = worldmap.a(integer, entityplayer);
@@ -142,6 +152,17 @@
worldmap.tickCarriedBy(entityplayer, itemstack);
Packet<?> packet = worldmap.getUpdatePacket(integer, entityplayer);
@@ -140,6 +150,17 @@
boolean flag2 = flag1 || this.tickCount % 60 == 0;
boolean flag3 = Math.abs(i - this.yRotp) >= 1 || Math.abs(j - this.xRotp) >= 1;
+ // CraftBukkit start - Code moved from below
+ if (flag2) {
+ this.d();
+ this.updateSentPos();
+ }
+
+ if (flag3) {
@@ -71,17 +71,17 @@
+ // CraftBukkit end
+
if (this.tickCount > 0 || this.entity instanceof EntityArrow) {
long k = PacketPlayOutEntity.a(vec3d.x);
long l = PacketPlayOutEntity.a(vec3d.y);
@@ -180,6 +201,7 @@
long k = PacketPlayOutEntity.entityToPacket(vec3d.x);
long l = PacketPlayOutEntity.entityToPacket(vec3d.y);
@@ -178,6 +199,7 @@
}
this.c();
this.sendDirtyEntityData();
+ /* CraftBukkit start - Code moved up
if (flag2) {
this.d();
this.updateSentPos();
}
@@ -188,6 +210,7 @@
@@ -186,6 +208,7 @@
this.yRotp = i;
this.xRotp = j;
}
@@ -89,11 +89,11 @@
this.wasRiding = false;
}
@@ -203,7 +226,27 @@
@@ -201,7 +224,27 @@
++this.tickCount;
if (this.entity.hurtMarked) {
- this.broadcastIncludingSelf(new PacketPlayOutEntityVelocity(this.entity));
- this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
+ // CraftBukkit start - Create PlayerVelocity event
+ boolean cancelled = false;
+
@@ -112,23 +112,23 @@
+ }
+
+ if (!cancelled) {
+ this.broadcastIncludingSelf(new PacketPlayOutEntityVelocity(this.entity));
+ this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
+ }
+ // CraftBukkit end
this.entity.hurtMarked = false;
}
@@ -218,13 +261,16 @@
@@ -216,13 +259,16 @@
PlayerConnection playerconnection = entityplayer.connection;
Objects.requireNonNull(entityplayer.connection);
- this.a(playerconnection::sendPacket);
+ this.a(playerconnection::sendPacket, entityplayer); // CraftBukkit - add player
this.entity.c(entityplayer);
- this.sendPairingData(playerconnection::send);
+ this.sendPairingData(playerconnection::send, entityplayer); // CraftBukkit - add player
this.entity.startSeenByPlayer(entityplayer);
}
- public void a(Consumer<Packet<?>> consumer) {
+ public void a(Consumer<Packet<?>> consumer, EntityPlayer entityplayer) { // CraftBukkit - add player
- public void sendPairingData(Consumer<Packet<?>> consumer) {
+ public void sendPairingData(Consumer<Packet<?>> consumer, EntityPlayer entityplayer) { // CraftBukkit - add player
if (this.entity.isRemoved()) {
- EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity {}", this.entity);
+ // CraftBukkit start - Remove useless error spam, just return
@@ -137,10 +137,10 @@
+ // CraftBukkit end
}
Packet<?> packet = this.entity.getPacket();
@@ -240,6 +286,12 @@
Packet<?> packet = this.entity.getAddEntityPacket();
@@ -238,6 +284,12 @@
if (this.entity instanceof EntityLiving) {
Collection<AttributeModifiable> collection = ((EntityLiving) this.entity).getAttributeMap().b();
Collection<AttributeModifiable> collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes();
+ // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health
+ if (this.entity.getId() == entityplayer.getId()) {
@@ -151,23 +151,23 @@
if (!collection.isEmpty()) {
consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection));
}
@@ -271,8 +323,14 @@
@@ -269,8 +321,14 @@
if (!list.isEmpty()) {
consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list));
}
+ ((EntityLiving) this.entity).updateEquipment(); // CraftBukkit - SPIGOT-3789: sync again immediately after sending
+ ((EntityLiving) this.entity).detectEquipmentUpdates(); // CraftBukkit - SPIGOT-3789: sync again immediately after sending
}
+ // CraftBukkit start - Fix for nonsensical head yaw
+ this.yHeadRotp = MathHelper.d(this.entity.getHeadRotation() * 256.0F / 360.0F);
+ this.yHeadRotp = MathHelper.floor(this.entity.getYHeadRot() * 256.0F / 360.0F);
+ consumer.accept(new PacketPlayOutEntityHeadRotation(this.entity, (byte) yHeadRotp));
+ // CraftBukkit end
+
if (this.entity instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) this.entity;
Iterator iterator = entityliving.getEffects().iterator();
@@ -313,6 +371,11 @@
Set<AttributeModifiable> set = ((EntityLiving) this.entity).getAttributeMap().getAttributes();
Iterator iterator = entityliving.getActiveEffects().iterator();
@@ -311,6 +369,11 @@
Set<AttributeModifiable> set = ((EntityLiving) this.entity).getAttributes().getDirtyAttributes();
if (!set.isEmpty()) {
+ // CraftBukkit start - Send scaled max health
@@ -175,6 +175,6 @@
+ ((EntityPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(set, false);
+ }
+ // CraftBukkit end
this.broadcastIncludingSelf(new PacketPlayOutUpdateAttributes(this.entity.getId(), set));
this.broadcastAndSend(new PacketPlayOutUpdateAttributes(this.entity.getId(), set));
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerChunk.java
+++ b/net/minecraft/server/level/PlayerChunk.java
@@ -38,6 +38,10 @@
@@ -35,6 +35,10 @@
import net.minecraft.world.level.chunk.ProtoChunkExtension;
import net.minecraft.world.level.lighting.LightEngine;
@@ -11,7 +11,7 @@
public class PlayerChunk {
public static final Either<IChunkAccess, PlayerChunk.Failure> UNLOADED_CHUNK = Either.right(PlayerChunk.Failure.UNLOADED);
@@ -75,11 +79,11 @@
@@ -72,11 +76,11 @@
this.fullChunkFuture = PlayerChunk.UNLOADED_LEVEL_CHUNK_FUTURE;
this.tickingChunkFuture = PlayerChunk.UNLOADED_LEVEL_CHUNK_FUTURE;
this.entityTickingChunkFuture = PlayerChunk.UNLOADED_LEVEL_CHUNK_FUTURE;
@@ -25,30 +25,30 @@
this.pos = chunkcoordintpair;
this.levelHeightAccessor = levelheightaccessor;
this.lightEngine = lightengine;
@@ -92,6 +96,19 @@
@@ -89,6 +93,19 @@
this.changedBlocksPerSection = new ShortSet[levelheightaccessor.getSectionsCount()];
}
+ // CraftBukkit start
+ public Chunk getFullChunk() {
+ if (!getChunkState(this.oldTicketLevel).isAtLeast(PlayerChunk.State.BORDER)) return null; // note: using oldTicketLevel for isLoaded checks
+ if (!getFullChunkStatus(this.oldTicketLevel).isOrAfter(PlayerChunk.State.BORDER)) return null; // note: using oldTicketLevel for isLoaded checks
+ return this.getFullChunkUnchecked();
+ }
+
+ public Chunk getFullChunkUnchecked() {
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> statusFuture = this.getStatusFutureUnchecked(ChunkStatus.FULL);
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> statusFuture = this.getFutureIfPresentUnchecked(ChunkStatus.FULL);
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either<IChunkAccess, PlayerChunk.Failure>) statusFuture.getNow(null);
+ return (either == null) ? null : (Chunk) either.left().orElse(null);
+ }
+ // CraftBukkit end
+
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getStatusFutureUnchecked(ChunkStatus chunkstatus) {
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = (CompletableFuture) this.futures.get(chunkstatus.c());
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getFutureIfPresentUnchecked(ChunkStatus chunkstatus) {
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = (CompletableFuture) this.futures.get(chunkstatus.getIndex());
@@ -117,9 +134,9 @@
@@ -114,9 +131,9 @@
@Nullable
public Chunk getChunk() {
CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture = this.a();
public Chunk getTickingChunk() {
CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture = this.getTickingChunkFuture();
- Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow((Object) null);
+ Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error
@@ -57,15 +57,15 @@
}
@Nullable
@@ -164,6 +181,7 @@
@@ -161,6 +178,7 @@
if (chunk != null) {
int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY());
+ if (i < 0 || i >= this.changedBlocksPerSection.length) return; // CraftBukkit - SPIGOT-6086, SPIGOT-6296
if (this.changedBlocksPerSection[i] == null) {
this.hasChangedSections = true;
this.changedBlocksPerSection[i] = new ShortArraySet();
@@ -274,7 +292,7 @@
this.changedBlocksPerSection[i] = new ShortOpenHashSet();
@@ -271,7 +289,7 @@
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = (CompletableFuture) this.futures.get(i);
if (completablefuture != null) {
@@ -74,7 +74,7 @@
boolean flag = either != null && either.right().isPresent();
if (!flag) {
@@ -341,7 +359,7 @@
@@ -338,7 +356,7 @@
this.pendingFullStateConfirmation = completablefuture1;
completablefuture.thenAccept((either) -> {
either.ifLeft((chunk) -> {
@@ -83,21 +83,21 @@
});
});
}
@@ -358,6 +376,30 @@
@@ -355,6 +373,30 @@
boolean flag1 = this.ticketLevel <= PlayerChunkMap.MAX_CHUNK_DISTANCE;
PlayerChunk.State playerchunk_state = getChunkState(this.oldTicketLevel);
PlayerChunk.State playerchunk_state1 = getChunkState(this.ticketLevel);
PlayerChunk.State playerchunk_state = getFullChunkStatus(this.oldTicketLevel);
PlayerChunk.State playerchunk_state1 = getFullChunkStatus(this.ticketLevel);
+ // CraftBukkit start
+ // ChunkUnloadEvent: Called before the chunk is unloaded: isChunkLoaded is still true and chunk can still be modified by plugins.
+ if (playerchunk_state.isAtLeast(PlayerChunk.State.BORDER) && !playerchunk_state1.isAtLeast(PlayerChunk.State.BORDER)) {
+ this.getStatusFutureUnchecked(ChunkStatus.FULL).thenAccept((either) -> {
+ if (playerchunk_state.isOrAfter(PlayerChunk.State.BORDER) && !playerchunk_state1.isOrAfter(PlayerChunk.State.BORDER)) {
+ this.getFutureIfPresentUnchecked(ChunkStatus.FULL).thenAccept((either) -> {
+ Chunk chunk = (Chunk)either.left().orElse(null);
+ if (chunk != null) {
+ playerchunkmap.callbackExecutor.execute(() -> {
+ // Minecraft will apply the chunks tick lists to the world once the chunk got loaded, and then store the tick
+ // lists again inside the chunk once the chunk becomes inaccessible and set the chunk's needsSaving flag.
+ // These actions may however happen deferred, so we manually set the needsSaving flag already here.
+ chunk.setNeedsSaving(true);
+ chunk.setUnsaved(true);
+ chunk.unloadCallback();
+ });
+ }
@@ -111,26 +111,17 @@
+ playerchunkmap.callbackExecutor.run();
+ }
+ // CraftBukkit end
CompletableFuture completablefuture;
if (flag) {
@@ -388,7 +430,7 @@
if (flag2 && !flag3) {
completablefuture = this.fullChunkFuture;
this.fullChunkFuture = PlayerChunk.UNLOADED_LEVEL_CHUNK_FUTURE;
- this.a(completablefuture.thenApply((either1) -> {
+ this.a(((CompletableFuture<Either<Chunk, PlayerChunk.Failure>>) completablefuture).thenApply((either1) -> { // CraftBukkit - decompile error
Objects.requireNonNull(playerchunkmap);
return either1.ifLeft(playerchunkmap::a);
}), "unfull");
@@ -432,6 +474,26 @@
Either<IChunkAccess, PlayerChunk.Failure> either = Either.right(new PlayerChunk.Failure() {
@@ -425,6 +467,26 @@
this.onLevelChange.a(this.pos, this::k, this.ticketLevel, this::d);
this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel);
this.oldTicketLevel = this.ticketLevel;
+ // CraftBukkit start
+ // ChunkLoadEvent: Called after the chunk is loaded: isChunkLoaded returns true and chunk is ready to be modified by plugins.
+ if (!playerchunk_state.isAtLeast(PlayerChunk.State.BORDER) && playerchunk_state1.isAtLeast(PlayerChunk.State.BORDER)) {
+ this.getStatusFutureUnchecked(ChunkStatus.FULL).thenAccept((either) -> {
+ if (!playerchunk_state.isOrAfter(PlayerChunk.State.BORDER) && playerchunk_state1.isOrAfter(PlayerChunk.State.BORDER)) {
+ this.getFutureIfPresentUnchecked(ChunkStatus.FULL).thenAccept((either) -> {
+ Chunk chunk = (Chunk)either.left().orElse(null);
+ if (chunk != null) {
+ playerchunkmap.callbackExecutor.execute(() -> {
@@ -149,4 +140,4 @@
+ // CraftBukkit end
}
public static ChunkStatus getChunkStatus(int i) {
public static ChunkStatus getStatus(int i) {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
@@ -91,6 +91,8 @@
@@ -95,6 +95,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -9,7 +9,7 @@
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
private static final byte CHUNK_TYPE_REPLACEABLE = -1;
@@ -129,6 +131,27 @@
@@ -133,6 +135,27 @@
private final Queue<Runnable> unloadQueue;
int viewDistance;
@@ -35,9 +35,9 @@
+ // CraftBukkit end
+
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, DefinedStructureManager definedstructuremanager, Executor executor, IAsyncTaskHandler<Runnable> iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
super(new File(convertable_conversionsession.a(worldserver.getDimensionKey()), "region"), datafixer, flag);
super(convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
this.visibleChunkMap = this.updatingChunkMap.clone();
@@ -281,9 +304,12 @@
@@ -326,9 +349,12 @@
return completablefuture1.thenApply((list1) -> {
List<IChunkAccess> list2 = Lists.newArrayList();
@@ -52,47 +52,39 @@
final Either<IChunkAccess, PlayerChunk.Failure> either = (Either) iterator.next();
Optional<IChunkAccess> optional = either.left();
@@ -390,7 +416,7 @@
this.j();
@@ -435,7 +461,7 @@
this.flushWorker();
} else {
this.visibleChunkMap.values().stream().filter(PlayerChunk::hasBeenLoaded).forEach((playerchunk) -> {
- IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkSave().getNow((Object) null);
+ IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkSave().getNow(null); // CraftBukkit - decompile error
this.visibleChunkMap.values().stream().filter(PlayerChunk::wasAccessibleSinceLastSave).forEach((playerchunk) -> {
- IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkToSave().getNow((Object) null);
+ IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkToSave().getNow(null); // CraftBukkit - decompile error
if (ichunkaccess instanceof ProtoChunkExtension || ichunkaccess instanceof Chunk) {
this.saveChunk(ichunkaccess);
@@ -401,7 +427,6 @@
}
this.save(ichunkaccess);
@@ -488,7 +514,7 @@
}
-
protected void unloadChunks(BooleanSupplier booleansupplier) {
GameProfilerFiller gameprofilerfiller = this.level.getMethodProfiler();
@@ -440,7 +465,7 @@
private void a(long i, PlayerChunk playerchunk) {
CompletableFuture<IChunkAccess> completablefuture = playerchunk.getChunkSave();
private void scheduleUnload(long i, PlayerChunk playerchunk) {
CompletableFuture<IChunkAccess> completablefuture = playerchunk.getChunkToSave();
- Consumer consumer = (ichunkaccess) -> {
+ Consumer<IChunkAccess> consumer = (ichunkaccess) -> { // CraftBukkit - decompile error
CompletableFuture<IChunkAccess> completablefuture1 = playerchunk.getChunkSave();
CompletableFuture<IChunkAccess> completablefuture1 = playerchunk.getChunkToSave();
if (completablefuture1 != completablefuture) {
@@ -616,7 +641,21 @@
@@ -664,7 +690,21 @@
private static void a(WorldServer worldserver, List<NBTTagCompound> list) {
private static void postLoadProtoChunk(WorldServer worldserver, List<NBTTagCompound> list) {
if (!list.isEmpty()) {
- worldserver.b(EntityTypes.a(list, (World) worldserver));
- worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver));
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
+ worldserver.b(EntityTypes.a(list, (World) worldserver).filter((entity) -> {
+ worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver).filter((entity) -> {
+ boolean needsRemoval = false;
+ net.minecraft.server.dedicated.DedicatedServer server = worldserver.getCraftServer().getServer();
+ if (!server.getSpawnNPCs() && entity instanceof net.minecraft.world.entity.npc.NPC) {
+ entity.die();
+ if (!server.areNpcsEnabled() && entity instanceof net.minecraft.world.entity.npc.NPC) {
+ entity.discard();
+ needsRemoval = true;
+ }
+ if (!server.getSpawnAnimals() && (entity instanceof net.minecraft.world.entity.animal.EntityAnimal || entity instanceof net.minecraft.world.entity.animal.EntityWaterAnimal)) {
+ entity.die();
+ if (!server.isSpawningAnimals() && (entity instanceof net.minecraft.world.entity.animal.EntityAnimal || entity instanceof net.minecraft.world.entity.animal.EntityWaterAnimal)) {
+ entity.discard();
+ needsRemoval = true;
+ }
+ return !needsRemoval;
@@ -101,35 +93,35 @@
}
}
@@ -844,7 +883,8 @@
@@ -894,7 +934,8 @@
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
- csvwriter.a(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getChunkStatus).orElse((Object) null), optional1.map(Chunk::getState).orElse((Object) null), a(playerchunk.c()), a(playerchunk.a()), a(playerchunk.b()), this.distanceManager.c(entry.getLongKey()), !this.isOutsideOfRange(chunkcoordintpair), optional1.map((chunk) -> {
- csvwriter.writeRow(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getStatus).orElse((Object) null), optional1.map(Chunk::getFullStatus).orElse((Object) null), printFuture(playerchunk.getFullChunkFuture()), printFuture(playerchunk.getTickingChunkFuture()), printFuture(playerchunk.getEntityTickingChunkFuture()), this.distanceManager.getTicketDebugString(i), this.anyPlayerCloseEnoughForSpawning(chunkcoordintpair), optional1.map((chunk) -> {
+ // CraftBukkit - decompile error
+ csvwriter.a(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getChunkStatus).orElse(null), optional1.map(Chunk::getState).orElse(null), a(playerchunk.c()), a(playerchunk.a()), a(playerchunk.b()), this.distanceManager.c(entry.getLongKey()), !this.isOutsideOfRange(chunkcoordintpair), optional1.map((chunk) -> {
return chunk.getTileEntities().size();
}).orElse(0));
}
@@ -853,7 +893,7 @@
+ csvwriter.writeRow(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getStatus).orElse(null), optional1.map(Chunk::getFullStatus).orElse(null), printFuture(playerchunk.getFullChunkFuture()), printFuture(playerchunk.getTickingChunkFuture()), printFuture(playerchunk.getEntityTickingChunkFuture()), this.distanceManager.getTicketDebugString(i), this.anyPlayerCloseEnoughForSpawning(chunkcoordintpair), optional1.map((chunk) -> {
return chunk.getBlockEntities().size();
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
return chunk.getBlockTicks().count();
@@ -907,7 +948,7 @@
private static String a(CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture) {
private static String printFuture(CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture) {
try {
- Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow((Object) null);
+ Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error
return either != null ? (String) either.map((chunk) -> {
return "done";
@@ -871,7 +911,7 @@
private NBTTagCompound readChunkData(ChunkCoordIntPair chunkcoordintpair) throws IOException {
@@ -925,7 +966,7 @@
private NBTTagCompound readChunk(ChunkCoordIntPair chunkcoordintpair) throws IOException {
NBTTagCompound nbttagcompound = this.read(chunkcoordintpair);
- return nbttagcompound == null ? null : this.getChunkData(this.level.getDimensionKey(), this.overworldDataStorage, nbttagcompound);
+ return nbttagcompound == null ? null : this.getChunkData(this.level.getTypeKey(), this.overworldDataStorage, nbttagcompound, chunkcoordintpair, level); // CraftBukkit
- return nbttagcompound == null ? null : this.upgradeChunkTag(this.level.dimension(), this.overworldDataStorage, nbttagcompound, this.generator.getTypeNameForDataFixer());
+ return nbttagcompound == null ? null : this.upgradeChunkTag(this.level.getTypeKey(), this.overworldDataStorage, nbttagcompound, this.generator.getTypeNameForDataFixer(), chunkcoordintpair, level); // CraftBukkit
}
boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) {
@@ -1238,7 +1278,7 @@
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
@@ -1349,7 +1390,7 @@
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
public EntityTracker(Entity entity, int i, int j, boolean flag) {
@@ -137,15 +129,17 @@
+ this.serverEntity = new EntityTrackerEntry(PlayerChunkMap.this.level, entity, j, flag, this::broadcast, seenBy); // CraftBukkit
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.a(entity);
@@ -1291,10 +1331,18 @@
this.lastSectionPos = SectionPosition.of(entity);
@@ -1402,12 +1443,20 @@
public void updatePlayer(EntityPlayer entityplayer) {
if (entityplayer != this.entity) {
- Vec3D vec3d = entityplayer.getPositionVector().d(this.serverEntity.b());
+ Vec3D vec3d = entityplayer.getPositionVector().d(this.entity.getPositionVector()); // MC-155077, SPIGOT-5113
int i = Math.min(this.b(), (PlayerChunkMap.this.viewDistance - 1) * 16);
boolean flag = vec3d.x >= (double) (-i) && vec3d.x <= (double) i && vec3d.z >= (double) (-i) && vec3d.z <= (double) i && this.entity.a(entityplayer);
- Vec3D vec3d = entityplayer.position().subtract(this.serverEntity.sentPos());
+ Vec3D vec3d = entityplayer.position().subtract(this.entity.position()); // MC-155077, SPIGOT-5113
double d0 = (double) Math.min(this.getEffectiveRange(), (PlayerChunkMap.this.viewDistance - 1) * 16);
double d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z;
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer);
+ // CraftBukkit start - respect vanish API
+ if (this.entity instanceof EntityPlayer) {
@@ -157,4 +151,4 @@
+ // CraftBukkit end
if (flag) {
if (this.seenBy.add(entityplayer.connection)) {
this.serverEntity.b(entityplayer);
this.serverEntity.addPairing(entityplayer);

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerInteractManager.java
+++ b/net/minecraft/server/level/PlayerInteractManager.java
@@ -25,6 +25,27 @@
@@ -24,6 +24,27 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -28,7 +28,7 @@
public class PlayerInteractManager {
private static final Logger LOGGER = LogManager.getLogger();
@@ -55,6 +76,13 @@
@@ -54,6 +75,13 @@
if (enumgamemode == this.gameModeForPlayer) {
return false;
} else {
@@ -39,93 +39,93 @@
+ return false;
+ }
+ // CraftBukkit end
this.a(enumgamemode, this.gameModeForPlayer);
this.setGameModeForPlayer(enumgamemode, this.gameModeForPlayer);
return true;
}
@@ -65,7 +93,7 @@
@@ -64,7 +92,7 @@
this.gameModeForPlayer = enumgamemode;
enumgamemode.a(this.player.getAbilities());
this.player.updateAbilities();
- this.player.server.getPlayerList().sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE, new EntityPlayer[]{this.player}));
+ this.player.server.getPlayerList().sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE, new EntityPlayer[]{this.player}), this.player); // CraftBukkit
this.level.everyoneSleeping();
enumgamemode.updatePlayerAbilities(this.player.getAbilities());
this.player.onUpdateAbilities();
- this.player.server.getPlayerList().broadcastAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE, new EntityPlayer[]{this.player}));
+ this.player.server.getPlayerList().broadcastAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE, new EntityPlayer[]{this.player}), this.player); // CraftBukkit
this.level.updateSleepingPlayerList();
}
@@ -87,7 +115,7 @@
@@ -86,7 +114,7 @@
}
public void a() {
public void tick() {
- ++this.gameTicks;
+ this.gameTicks = MinecraftServer.currentTick; // CraftBukkit;
IBlockData iblockdata;
if (this.hasDelayedDestroy) {
@@ -143,9 +171,31 @@
@@ -142,9 +170,31 @@
if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) {
if (!this.level.a((EntityHuman) this.player, blockposition)) {
if (!this.level.mayInteract(this.player, blockposition)) {
+ // CraftBukkit start - fire PlayerInteractEvent
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockposition, enumdirection, this.player.getInventory().getItemInHand(), EnumHand.MAIN_HAND);
this.player.connection.sendPacket(new PacketPlayOutBlockBreak(blockposition, this.level.getType(blockposition), packetplayinblockdig_enumplayerdigtype, false, "may not interact"));
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockposition, enumdirection, this.player.getInventory().getSelected(), EnumHand.MAIN_HAND);
this.player.connection.send(new PacketPlayOutBlockBreak(blockposition, this.level.getBlockState(blockposition), packetplayinblockdig_enumplayerdigtype, false, "may not interact"));
+ // Update any tile entity data for this block
+ TileEntity tileentity = level.getTileEntity(blockposition);
+ TileEntity tileentity = level.getBlockEntity(blockposition);
+ if (tileentity != null) {
+ this.player.connection.sendPacket(tileentity.getUpdatePacket());
+ this.player.connection.send(tileentity.getUpdatePacket());
+ }
+ // CraftBukkit end
+ return;
+ }
+
+ // CraftBukkit start
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockposition, enumdirection, this.player.getInventory().getItemInHand(), EnumHand.MAIN_HAND);
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockposition, enumdirection, this.player.getInventory().getSelected(), EnumHand.MAIN_HAND);
+ if (event.isCancelled()) {
+ // Let the client know the block still exists
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, blockposition));
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, blockposition));
+ // Update any tile entity data for this block
+ TileEntity tileentity = this.level.getTileEntity(blockposition);
+ TileEntity tileentity = this.level.getBlockEntity(blockposition);
+ if (tileentity != null) {
+ this.player.connection.sendPacket(tileentity.getUpdatePacket());
+ this.player.connection.send(tileentity.getUpdatePacket());
+ }
return;
}
+ // CraftBukkit end
if (this.isCreative()) {
this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "creative destroy");
@@ -161,11 +211,43 @@
this.destroyAndAck(blockposition, packetplayinblockdig_enumplayerdigtype, "creative destroy");
@@ -160,11 +210,43 @@
float f = 1.0F;
iblockdata = this.level.getType(blockposition);
iblockdata = this.level.getBlockState(blockposition);
- if (!iblockdata.isAir()) {
+ // CraftBukkit start - Swings at air do *NOT* exist.
+ if (event.useInteractedBlock() == Event.Result.DENY) {
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
+ IBlockData data = this.level.getType(blockposition);
+ IBlockData data = this.level.getBlockState(blockposition);
+ if (data.getBlock() instanceof BlockDoor) {
+ // For some reason *BOTH* the bottom/top part have to be marked updated.
+ boolean bottom = data.get(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER;
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, blockposition));
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, bottom ? blockposition.up() : blockposition.down()));
+ boolean bottom = data.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER;
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, blockposition));
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, bottom ? blockposition.above() : blockposition.below()));
+ } else if (data.getBlock() instanceof BlockTrapdoor) {
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, blockposition));
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, blockposition));
+ }
+ } else if (!iblockdata.isAir()) {
iblockdata.attack(this.level, blockposition, this.player);
f = iblockdata.getDamage(this.player, this.player.level, blockposition);
f = iblockdata.getDestroyProgress(this.player, this.player.level, blockposition);
}
+ if (event.useItemInHand() == Event.Result.DENY) {
+ // If we 'insta destroyed' then the client needs to be informed.
+ if (f > 1.0f) {
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, blockposition));
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, blockposition));
+ }
+ return;
+ }
+ org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockposition.getX(), blockposition.getY(), blockposition.getZ(), this.player.getInventory().getItemInHand(), f >= 1.0f);
+ org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockposition.getX(), blockposition.getY(), blockposition.getZ(), this.player.getInventory().getSelected(), f >= 1.0f);
+
+ if (blockEvent.isCancelled()) {
+ // Let the client know the block still exists
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, blockposition));
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, blockposition));
+ return;
+ }
+
@@ -135,42 +135,42 @@
+ // CraftBukkit end
+
if (!iblockdata.isAir() && f >= 1.0F) {
this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "insta mine");
this.destroyAndAck(blockposition, packetplayinblockdig_enumplayerdigtype, "insta mine");
} else {
@@ -209,7 +291,7 @@
@@ -208,7 +290,7 @@
} else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) {
this.isDestroyingBlock = false;
if (!Objects.equals(this.destroyPos, blockposition)) {
- PlayerInteractManager.LOGGER.warn("Mismatch in destroy block pos: {} {}", this.destroyPos, blockposition);
+ PlayerInteractManager.LOGGER.debug("Mismatch in destroy block pos: {} {}", this.destroyPos, blockposition); // CraftBukkit - SPIGOT-5457 sent by client when interact event cancelled
this.level.a(this.player.getId(), this.destroyPos, -1);
this.player.connection.sendPacket(new PacketPlayOutBlockBreak(this.destroyPos, this.level.getType(this.destroyPos), packetplayinblockdig_enumplayerdigtype, true, "aborted mismatched destroying"));
this.level.destroyBlockProgress(this.player.getId(), this.destroyPos, -1);
this.player.connection.send(new PacketPlayOutBlockBreak(this.destroyPos, this.level.getBlockState(this.destroyPos), packetplayinblockdig_enumplayerdigtype, true, "aborted mismatched destroying"));
}
@@ -225,17 +307,72 @@
if (this.breakBlock(blockposition)) {
this.player.connection.sendPacket(new PacketPlayOutBlockBreak(blockposition, this.level.getType(blockposition), packetplayinblockdig_enumplayerdigtype, true, s));
@@ -224,17 +306,72 @@
if (this.destroyBlock(blockposition)) {
this.player.connection.send(new PacketPlayOutBlockBreak(blockposition, this.level.getBlockState(blockposition), packetplayinblockdig_enumplayerdigtype, true, s));
} else {
- this.player.connection.sendPacket(new PacketPlayOutBlockBreak(blockposition, this.level.getType(blockposition), packetplayinblockdig_enumplayerdigtype, false, s));
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, blockposition)); // CraftBukkit - SPIGOT-5196
- this.player.connection.send(new PacketPlayOutBlockBreak(blockposition, this.level.getBlockState(blockposition), packetplayinblockdig_enumplayerdigtype, false, s));
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, blockposition)); // CraftBukkit - SPIGOT-5196
}
}
public boolean breakBlock(BlockPosition blockposition) {
IBlockData iblockdata = this.level.getType(blockposition);
public boolean destroyBlock(BlockPosition blockposition) {
IBlockData iblockdata = this.level.getBlockState(blockposition);
+ // CraftBukkit start - fire BlockBreakEvent
+ org.bukkit.block.Block bblock = CraftBlock.at(level, blockposition);
+ BlockBreakEvent event = null;
+
+ if (this.player instanceof EntityPlayer) {
+ // Sword + Creative mode pre-cancel
+ boolean isSwordNoBreak = !this.player.getItemInMainHand().getItem().a(iblockdata, this.level, blockposition, (EntityHuman) this.player);
+ boolean isSwordNoBreak = !this.player.getMainHandItem().getItem().canAttackBlock(iblockdata, this.level, blockposition, this.player);
+
+ // Tell client the block is gone immediately then process events
+ // Don't tell the client if its a creative sword break because its not broken!
+ if (level.getTileEntity(blockposition) == null && !isSwordNoBreak) {
+ PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(blockposition, Blocks.AIR.getBlockData());
+ this.player.connection.sendPacket(packet);
+ if (level.getBlockEntity(blockposition) == null && !isSwordNoBreak) {
+ PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(blockposition, Blocks.AIR.defaultBlockState());
+ this.player.connection.send(packet);
+ }
+
+ event = new BlockBreakEvent(bblock, this.player.getBukkitEntity());
@@ -179,12 +179,12 @@
+ event.setCancelled(isSwordNoBreak);
+
+ // Calculate default block experience
+ IBlockData nmsData = this.level.getType(blockposition);
+ IBlockData nmsData = this.level.getBlockState(blockposition);
+ Block nmsBlock = nmsData.getBlock();
+
+ ItemStack itemstack = this.player.getEquipment(EnumItemSlot.MAINHAND);
+ ItemStack itemstack = this.player.getItemBySlot(EnumItemSlot.MAINHAND);
+
+ if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.hasBlock(nmsBlock.getBlockData())) {
+ if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.hasCorrectToolForDrops(nmsBlock.defaultBlockState())) {
+ event.setExpToDrop(nmsBlock.getExpDrop(nmsData, this.level, blockposition, itemstack));
+ }
+
@@ -195,58 +195,58 @@
+ return false;
+ }
+ // Let the client know the block still exists
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(this.level, blockposition));
+ this.player.connection.send(new PacketPlayOutBlockChange(this.level, blockposition));
+
+ // Brute force all possible updates
+ for (EnumDirection dir : EnumDirection.values()) {
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(level, blockposition.shift(dir)));
+ this.player.connection.send(new PacketPlayOutBlockChange(level, blockposition.relative(dir)));
+ }
- if (!this.player.getItemInMainHand().getItem().a(iblockdata, (World) this.level, blockposition, (EntityHuman) this.player)) {
- if (!this.player.getMainHandItem().getItem().canAttackBlock(iblockdata, this.level, blockposition, this.player)) {
+ // Update any tile entity data for this block
+ TileEntity tileentity = this.level.getTileEntity(blockposition);
+ TileEntity tileentity = this.level.getBlockEntity(blockposition);
+ if (tileentity != null) {
+ this.player.connection.sendPacket(tileentity.getUpdatePacket());
+ this.player.connection.send(tileentity.getUpdatePacket());
+ }
+ return false;
+ }
+ }
+ // CraftBukkit end
+
+ if (false && !this.player.getItemInMainHand().getItem().a(iblockdata, (World) this.level, blockposition, (EntityHuman) this.player)) { // CraftBukkit - false
+ if (false && !this.player.getMainHandItem().getItem().canAttackBlock(iblockdata, this.level, blockposition, this.player)) { // CraftBukkit - false
return false;
} else {
+ iblockdata = this.level.getType(blockposition); // CraftBukkit - update state from plugins
+ iblockdata = this.level.getBlockState(blockposition); // CraftBukkit - update state from plugins
+ if (iblockdata.isAir()) return false; // CraftBukkit - A plugin set block to air without cancelling
TileEntity tileentity = this.level.getTileEntity(blockposition);
TileEntity tileentity = this.level.getBlockEntity(blockposition);
Block block = iblockdata.getBlock();
@@ -245,6 +382,10 @@
} else if (this.player.a((World) this.level, blockposition, this.gameModeForPlayer)) {
@@ -244,6 +381,10 @@
} else if (this.player.blockActionRestricted(this.level, blockposition, this.gameModeForPlayer)) {
return false;
} else {
+ // CraftBukkit start
+ org.bukkit.block.BlockState state = bblock.getState();
+ level.captureDrops = new ArrayList<>();
+ // CraftBukkit end
block.a((World) this.level, blockposition, iblockdata, (EntityHuman) this.player);
boolean flag = this.level.a(blockposition, false);
block.playerWillDestroy(this.level, blockposition, iblockdata, this.player);
boolean flag = this.level.removeBlock(blockposition, false);
@@ -253,19 +394,32 @@
@@ -252,19 +393,32 @@
}
if (this.isCreative()) {
- return true;
+ // return true; // CraftBukkit
} else {
ItemStack itemstack = this.player.getItemInMainHand();
ItemStack itemstack1 = itemstack.cloneItemStack();
boolean flag1 = this.player.hasBlock(iblockdata);
ItemStack itemstack = this.player.getMainHandItem();
ItemStack itemstack1 = itemstack.copy();
boolean flag1 = this.player.hasCorrectToolForDrops(iblockdata);
itemstack.a(this.level, iblockdata, blockposition, this.player);
itemstack.mineBlock(this.level, iblockdata, blockposition, this.player);
- if (flag && flag1) {
+ if (flag && flag1 && event.isDropItems()) { // CraftBukkit - Check if block should drop items
block.a(this.level, this.player, blockposition, iblockdata, tileentity, itemstack1);
block.playerDestroy(this.level, this.player, blockposition, iblockdata, tileentity, itemstack1);
}
- return true;
@@ -260,7 +260,7 @@
+
+ // Drop event experience
+ if (flag && event != null) {
+ iblockdata.getBlock().dropExperience(this.level, blockposition, event.getExpToDrop());
+ iblockdata.getBlock().popExperience(this.level, blockposition, event.getExpToDrop());
}
+
+ return true;
@@ -268,7 +268,7 @@
}
}
}
@@ -307,12 +461,52 @@
@@ -306,12 +460,52 @@
}
}
@@ -278,63 +278,63 @@
+ public BlockPosition interactPosition;
+ public EnumHand interactHand;
+ public ItemStack interactItemStack;
public EnumInteractionResult a(EntityPlayer entityplayer, World world, ItemStack itemstack, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
BlockPosition blockposition = movingobjectpositionblock.getBlockPosition();
IBlockData iblockdata = world.getType(blockposition);
public EnumInteractionResult useItemOn(EntityPlayer entityplayer, World world, ItemStack itemstack, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
BlockPosition blockposition = movingobjectpositionblock.getBlockPos();
IBlockData iblockdata = world.getBlockState(blockposition);
+ EnumInteractionResult enuminteractionresult = EnumInteractionResult.PASS;
+ boolean cancelledBlock = false;
if (this.gameModeForPlayer == EnumGamemode.SPECTATOR) {
ITileInventory itileinventory = iblockdata.b(world, blockposition);
ITileInventory itileinventory = iblockdata.getMenuProvider(world, blockposition);
+ cancelledBlock = !(itileinventory instanceof ITileInventory);
+ }
+
+ if (entityplayer.getCooldownTracker().hasCooldown(itemstack.getItem())) {
+ if (entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
+ cancelledBlock = true;
+ }
+
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand);
+ firedInteract = true;
+ interactResult = event.useItemInHand() == Event.Result.DENY;
+ interactPosition = blockposition.immutableCopy();
+ interactPosition = blockposition.immutable();
+ interactHand = enumhand;
+ interactItemStack = itemstack.cloneItemStack();
+ interactItemStack = itemstack.copy();
+
+ if (event.useInteractedBlock() == Event.Result.DENY) {
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
+ if (iblockdata.getBlock() instanceof BlockDoor) {
+ boolean bottom = iblockdata.get(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER;
+ entityplayer.connection.sendPacket(new PacketPlayOutBlockChange(world, bottom ? blockposition.up() : blockposition.down()));
+ boolean bottom = iblockdata.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER;
+ entityplayer.connection.send(new PacketPlayOutBlockChange(world, bottom ? blockposition.above() : blockposition.below()));
+ } else if (iblockdata.getBlock() instanceof BlockCake) {
+ entityplayer.getBukkitEntity().sendHealthUpdate(); // SPIGOT-1341 - reset health for cake
+ } else if (interactItemStack.getItem() instanceof ItemBisected) {
+ // send a correcting update to the client, as it already placed the upper half of the bisected item
+ entityplayer.connection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.shift(movingobjectpositionblock.getDirection()).up()));
+ entityplayer.connection.send(new PacketPlayOutBlockChange(world, blockposition.relative(movingobjectpositionblock.getDirection()).above()));
+
+ // send a correcting update to the client for the block above as well, this because of replaceable blocks (such as grass, sea grass etc)
+ entityplayer.connection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.up()));
+ entityplayer.connection.send(new PacketPlayOutBlockChange(world, blockposition.above()));
+ }
+ entityplayer.getBukkitEntity().updateInventory(); // SPIGOT-2867
+ enuminteractionresult = (event.useItemInHand() != Event.Result.ALLOW) ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS;
+ } else if (this.gameModeForPlayer == EnumGamemode.SPECTATOR) {
+ ITileInventory itileinventory = iblockdata.b(world, blockposition);
+ ITileInventory itileinventory = iblockdata.getMenuProvider(world, blockposition);
if (itileinventory != null) {
entityplayer.openContainer(itileinventory);
@@ -326,7 +520,7 @@
ItemStack itemstack1 = itemstack.cloneItemStack();
entityplayer.openMenu(itileinventory);
@@ -325,7 +519,7 @@
ItemStack itemstack1 = itemstack.copy();
if (!flag1) {
- EnumInteractionResult enuminteractionresult = iblockdata.interact(world, entityplayer, enumhand, movingobjectpositionblock);
+ enuminteractionresult = iblockdata.interact(world, entityplayer, enumhand, movingobjectpositionblock);
- EnumInteractionResult enuminteractionresult = iblockdata.use(world, entityplayer, enumhand, movingobjectpositionblock);
+ enuminteractionresult = iblockdata.use(world, entityplayer, enumhand, movingobjectpositionblock);
if (enuminteractionresult.a()) {
CriterionTriggers.ITEM_USED_ON_BLOCK.a(entityplayer, blockposition, itemstack1);
@@ -334,17 +528,17 @@
if (enuminteractionresult.consumesAction()) {
CriterionTriggers.ITEM_USED_ON_BLOCK.trigger(entityplayer, blockposition, itemstack1);
@@ -333,17 +527,17 @@
}
}
- if (!itemstack.isEmpty() && !entityplayer.getCooldownTracker().hasCooldown(itemstack.getItem())) {
- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
+ if (!itemstack.isEmpty() && enuminteractionresult != EnumInteractionResult.SUCCESS && !interactResult) { // add !interactResult SPIGOT-764
ItemActionContext itemactioncontext = new ItemActionContext(entityplayer, enumhand, movingobjectpositionblock);
EnumInteractionResult enuminteractionresult1;
@@ -342,16 +342,16 @@
if (this.isCreative()) {
int i = itemstack.getCount();
- enuminteractionresult1 = itemstack.placeItem(itemactioncontext);
+ enuminteractionresult1 = itemstack.placeItem(itemactioncontext, enumhand);
- enuminteractionresult1 = itemstack.useOn(itemactioncontext);
+ enuminteractionresult1 = itemstack.useOn(itemactioncontext, enumhand);
itemstack.setCount(i);
} else {
- enuminteractionresult1 = itemstack.placeItem(itemactioncontext);
+ enuminteractionresult1 = itemstack.placeItem(itemactioncontext, enumhand);
- enuminteractionresult1 = itemstack.useOn(itemactioncontext);
+ enuminteractionresult1 = itemstack.useOn(itemactioncontext, enumhand);
}
if (enuminteractionresult1.a()) {
@@ -352,10 +546,10 @@
if (enuminteractionresult1.consumesAction()) {
@@ -351,10 +545,10 @@
}
return enuminteractionresult1;
@@ -363,4 +363,4 @@
+ // CraftBukkit end
}
public void a(WorldServer worldserver) {
public void setLevel(WorldServer worldserver) {

View File

@@ -1,16 +1,16 @@
--- a/net/minecraft/server/level/RegionLimitedWorldAccess.java
+++ b/net/minecraft/server/level/RegionLimitedWorldAccess.java
@@ -308,6 +308,13 @@
@@ -319,6 +319,13 @@
@Override
public boolean addEntity(Entity entity) {
public boolean addFreshEntity(Entity entity) {
+ // CraftBukkit start
+ return addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ return addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Override
+ public boolean addEntity(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ public boolean addFreshEntity(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ // CraftBukkit end
int i = SectionPosition.a(entity.cW());
int j = SectionPosition.a(entity.dc());
int i = SectionPosition.blockToSectionCoord(entity.getBlockX());
int j = SectionPosition.blockToSectionCoord(entity.getBlockZ());

View File

@@ -1,11 +1,11 @@
--- a/net/minecraft/server/level/TicketType.java
+++ b/net/minecraft/server/level/TicketType.java
@@ -23,6 +23,8 @@
public static final TicketType<BlockPosition> PORTAL = a("portal", BaseBlockPosition::compareTo, 300);
public static final TicketType<Integer> POST_TELEPORT = a("post_teleport", Integer::compareTo, 5);
public static final TicketType<ChunkCoordIntPair> UNKNOWN = a("unknown", Comparator.comparingLong(ChunkCoordIntPair::pair), 1);
+ public static final TicketType<Unit> PLUGIN = a("plugin", (a, b) -> 0); // CraftBukkit
+ public static final TicketType<org.bukkit.plugin.Plugin> PLUGIN_TICKET = a("plugin_ticket", (plugin1, plugin2) -> plugin1.getClass().getName().compareTo(plugin2.getClass().getName())); // CraftBukkit
public static final TicketType<BlockPosition> PORTAL = create("portal", BaseBlockPosition::compareTo, 300);
public static final TicketType<Integer> POST_TELEPORT = create("post_teleport", Integer::compareTo, 5);
public static final TicketType<ChunkCoordIntPair> UNKNOWN = create("unknown", Comparator.comparingLong(ChunkCoordIntPair::toLong), 1);
+ public static final TicketType<Unit> PLUGIN = create("plugin", (a, b) -> 0); // CraftBukkit
+ public static final TicketType<org.bukkit.plugin.Plugin> PLUGIN_TICKET = create("plugin_ticket", (plugin1, plugin2) -> plugin1.getClass().getName().compareTo(plugin2.getClass().getName())); // CraftBukkit
public static <T> TicketType<T> a(String s, Comparator<T> comparator) {
public static <T> TicketType<T> create(String s, Comparator<T> comparator) {
return new TicketType<>(s, comparator, 0L);

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
@@ -152,6 +152,19 @@
@@ -147,6 +147,19 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -20,7 +20,7 @@
public class WorldServer extends World implements GeneratorAccessSeed {
public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0);
@@ -160,7 +173,7 @@
@@ -164,7 +177,7 @@
final List<EntityPlayer> players;
private final ChunkProviderServer chunkSource;
private final MinecraftServer server;
@@ -29,13 +29,13 @@
final EntityTickList entityTickList;
public final PersistentEntitySectionManager<Entity> entityManager;
public boolean noSave;
@@ -180,31 +193,52 @@
private final StructureManager structureFeatureManager;
@@ -186,9 +199,24 @@
private final StructureCheck structureCheck;
private final boolean tickTime;
- 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) {
- Objects.requireNonNull(minecraftserver);
- super(iworlddataserver, resourcekey, dimensionmanager, minecraftserver::getMethodProfiler, false, flag, i);
- super(iworlddataserver, resourcekey, dimensionmanager, minecraftserver::getProfiler, false, flag, i);
+
+ // CraftBukkit start
+ private int tickPosition;
@@ -43,39 +43,21 @@
+ public final UUID uuid;
+
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunkAt(x, z, false);
+ return this.chunkSource.getChunk(x, z, false);
+ }
+
+ // Add env and gen to constructor, WorldData -> WorldDataServer
+ 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, org.bukkit.generator.BiomeProvider biomeProvider) {
+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error
+ super(iworlddataserver, resourcekey, dimensionmanager, minecraftserver::getMethodProfiler, false, flag, i, gen, biomeProvider, env);
+ this.pvpMode = minecraftserver.getPVP();
+ super(iworlddataserver, resourcekey, dimensionmanager, minecraftserver::getProfiler, false, flag, i, gen, biomeProvider, env);
+ this.pvpMode = minecraftserver.isPvpAllowed();
+ convertable = convertable_conversionsession;
+ uuid = WorldUUID.getUUID(convertable_conversionsession.levelPath.toFile());
+ // CraftBukkit end
this.players = Lists.newArrayList();
this.entityTickList = new EntityTickList();
- Predicate predicate = (block) -> {
+ Predicate<Block> predicate = (block) -> { // CraftBukkit - decompile eror
return block == null || block.getBlockData().isAir();
};
RegistryBlocks registryblocks = IRegistry.BLOCK;
Objects.requireNonNull(registryblocks);
- this.blockTicks = new TickListServer<>(this, predicate, registryblocks::getKey, this::b);
- predicate = (fluidtype) -> {
+ this.blockTicks = new TickListServer<>(this, predicate, IRegistry.BLOCK::getKey, this::b); // CraftBukkit - decompile error
+ Predicate<FluidType> predicate2 = (fluidtype) -> { // CraftBukkit - decompile error
return fluidtype == null || fluidtype == FluidTypes.EMPTY;
};
registryblocks = IRegistry.FLUID;
Objects.requireNonNull(registryblocks);
- this.liquidTicks = new TickListServer<>(this, predicate, registryblocks::getKey, this::a);
+ this.liquidTicks = new TickListServer<>(this, predicate2, IRegistry.FLUID::getKey, this::a); // CraftBukkit - decompile error
this.navigatingMobs = new ObjectOpenHashSet();
this.blockEvents = new ObjectLinkedOpenHashSet();
this.dragonParts = new Int2ObjectOpenHashMap();
this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier());
@@ -200,7 +228,13 @@
this.tickTime = flag1;
this.server = minecraftserver;
this.customSpawners = list;
@@ -87,18 +69,18 @@
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
+ }
+ // CraftBukkit end
boolean flag2 = minecraftserver.isSyncChunkWrites();
DataFixer datafixer = minecraftserver.getDataFixer();
EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(this, new File(convertable_conversionsession.a(resourcekey), "entities"), datafixer, flag2, minecraftserver);
boolean flag2 = minecraftserver.forceSynchronousWrites();
DataFixer datafixer = minecraftserver.getFixerUpper();
EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(this, convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, minecraftserver);
@@ -231,14 +265,15 @@
iworlddataserver.setGameType(minecraftserver.getGamemode());
}
long l = minecraftserver.getWorldData().worldGenSettings().seed();
- this.structureFeatureManager = new StructureManager(this, minecraftserver.getSaveData().getGeneratorSettings());
+ this.structureFeatureManager = new StructureManager(this, this.serverLevelData.getGeneratorSettings()); // CraftBukkit
if (this.getDimensionManager().isCreateDragonBattle()) {
- this.dragonFight = new EnderDragonBattle(this, minecraftserver.getSaveData().getGeneratorSettings().getSeed(), minecraftserver.getSaveData().C());
+ this.dragonFight = new EnderDragonBattle(this, this.serverLevelData.getGeneratorSettings().getSeed(), this.serverLevelData.C()); // CraftBukkit
this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this, chunkgenerator.getBiomeSource(), l, datafixer);
- this.structureFeatureManager = new StructureManager(this, minecraftserver.getWorldData().worldGenSettings(), this.structureCheck);
+ this.structureFeatureManager = new StructureManager(this, this.serverLevelData.worldGenSettings(), structureCheck); // CraftBukkit
if (this.dimensionType().createDragonFight()) {
- this.dragonFight = new EnderDragonBattle(this, l, minecraftserver.getWorldData().endDragonFightData());
+ this.dragonFight = new EnderDragonBattle(this, this.serverLevelData.worldGenSettings().seed(), this.serverLevelData.endDragonFightData()); // CraftBukkit
} else {
this.dragonFight = null;
}
@@ -107,18 +89,101 @@
+ this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
}
public void a(int i, int j, boolean flag, boolean flag1) {
@@ -331,6 +366,7 @@
this.rainLevel = MathHelper.a(this.rainLevel, 0.0F, 1.0F);
public void setWeatherParameters(int i, int j, boolean flag, boolean flag1) {
@@ -270,12 +305,20 @@
long j;
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
+ // CraftBukkit start
+ j = this.levelData.getDayTime() + 24000L;
+ TimeSkipEvent event = new TimeSkipEvent(this.getWorld(), TimeSkipEvent.SkipReason.NIGHT_SKIP, (j - j % 24000L) - this.getDayTime());
if (this.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)) {
- j = this.levelData.getDayTime() + 24000L;
- this.setDayTime(j - j % 24000L);
+ getCraftServer().getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ this.setDayTime(this.getDayTime() + event.getSkipAmount());
+ }
}
- this.wakeUpAllPlayers();
+ if (!event.isCancelled()) {
+ this.wakeUpAllPlayers();
+ }
+ // CraftBukkit end
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
}
@@ -301,7 +344,7 @@
this.runBlockEvents();
this.handlingTick = false;
gameprofilerfiller.pop();
- boolean flag = !this.players.isEmpty() || !this.getForcedChunks().isEmpty();
+ boolean flag = true || !this.players.isEmpty() || !this.getForcedChunks().isEmpty(); // CraftBukkit - this prevents entity cleanup, other issues on servers with no players
if (flag) {
this.resetEmptyTime();
@@ -317,7 +360,7 @@
this.entityTickList.forEach((entity) -> {
if (!entity.isRemoved()) {
- if (this.shouldDiscardEntity(entity)) {
+ if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed
entity.discard();
} else {
gameprofilerfiller.push("checkDespawn");
@@ -389,7 +432,7 @@
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
- ((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.stopSleepInBed(false, false);
});
}
@@ -416,14 +459,14 @@
entityhorseskeleton.setTrap(true);
entityhorseskeleton.setAge(0);
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
- this.addFreshEntity(entityhorseskeleton);
+ this.addFreshEntity(entityhorseskeleton, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
}
EntityLightning entitylightning = (EntityLightning) EntityTypes.LIGHTNING_BOLT.create(this);
entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition));
entitylightning.setVisualOnly(flag1);
- this.addFreshEntity(entitylightning);
+ this.strikeLightning(entitylightning, org.bukkit.event.weather.LightningStrikeEvent.Cause.WEATHER); // CraftBukkit
}
}
@@ -434,12 +477,12 @@
BiomeBase biomebase = this.getBiome(blockposition);
if (biomebase.shouldFreeze(this, blockposition1)) {
- this.setBlockAndUpdate(blockposition1, Blocks.ICE.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.ICE.defaultBlockState(), null); // CraftBukkit
}
if (flag) {
if (biomebase.shouldSnow(this, blockposition)) {
- this.setBlockAndUpdate(blockposition, Blocks.SNOW.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition, Blocks.SNOW.defaultBlockState(), null); // CraftBukkit
}
IBlockData iblockdata = this.getBlockState(blockposition1);
@@ -635,6 +678,7 @@
this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F);
}
+ /* CraftBukkit start
if (this.oRainLevel != this.rainLevel) {
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel)), this.getDimensionKey());
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension());
}
@@ -349,16 +385,45 @@
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, this.thunderLevel));
@@ -653,14 +697,47 @@
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel));
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, this.thunderLevel));
}
+ // */
+ for (int idx = 0; idx < this.players.size(); ++idx) {
@@ -142,100 +207,17 @@
+ }
+ // CraftBukkit end
i = this.getGameRules().getInt(GameRules.RULE_PLAYERS_SLEEPING_PERCENTAGE);
if (this.sleepStatus.a(i) && this.sleepStatus.a(i, this.players)) {
+ // CraftBukkit start
+ long l = this.levelData.getDayTime() + 24000L;
+ TimeSkipEvent event = new TimeSkipEvent(this.getWorld(), TimeSkipEvent.SkipReason.NIGHT_SKIP, (l - l % 24000L) - this.getDayTime());
if (this.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)) {
- long l = this.levelData.getDayTime() + 24000L;
+ getCraftServer().getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ this.setDayTime(this.getDayTime() + event.getSkipAmount());
+ }
- this.setDayTime(l - l % 24000L);
}
- this.wakeupPlayers();
+ if (!event.isCancelled()) {
+ this.wakeupPlayers();
+ }
+ // CraftBukkit end
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE)) {
this.clearWeather();
}
@@ -380,7 +445,7 @@
this.aq();
this.handlingTick = false;
gameprofilerfiller.exit();
- 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();
@@ -396,7 +461,7 @@
this.entityTickList.a((entity) -> {
if (!entity.isRemoved()) {
- if (this.i(entity)) {
+ if (false && this.i(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed
entity.die();
} else {
gameprofilerfiller.enter("checkDespawn");
@@ -461,7 +526,7 @@
private void wakeupPlayers() {
this.sleepStatus.a();
- ((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);
});
}
@@ -488,14 +553,14 @@
entityhorseskeleton.v(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
}
EntityLightning entitylightning = (EntityLightning) EntityTypes.LIGHTNING_BOLT.a((World) this);
entitylightning.d(Vec3D.c((BaseBlockPosition) blockposition));
entitylightning.setEffect(flag1);
- this.addEntity(entitylightning);
+ this.strikeLightning(entitylightning, org.bukkit.event.weather.LightningStrikeEvent.Cause.WEATHER); // CraftBukkit
}
}
@@ -506,12 +571,12 @@
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) {
if (biomebase.b(this, blockposition)) {
- this.setTypeUpdate(blockposition, Blocks.SNOW.getBlockData());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition, Blocks.SNOW.getBlockData(), null); // CraftBukkit
}
IBlockData iblockdata = this.getType(blockposition1);
@@ -642,10 +707,22 @@
}
private void clearWeather() {
- this.serverLevelData.setWeatherDuration(0);
private void resetWeatherCycle() {
- this.serverLevelData.setRainTime(0);
+ // CraftBukkit start
this.serverLevelData.setStorm(false);
- this.serverLevelData.setThunderDuration(0);
this.serverLevelData.setRaining(false);
- this.serverLevelData.setThunderTime(0);
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value.
+ // Not that everyone ever manages to get the whole server to sleep at the same time....
+ if (!this.serverLevelData.hasStorm()) {
+ this.serverLevelData.setWeatherDuration(0);
+ if (!this.serverLevelData.isRaining()) {
+ this.serverLevelData.setRainTime(0);
+ }
+ // CraftBukkit end
this.serverLevelData.setThundering(false);
@@ -243,37 +225,37 @@
+ // 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.serverLevelData.isThundering()) {
+ this.serverLevelData.setThunderDuration(0);
+ this.serverLevelData.setThunderTime(0);
+ }
+ // CraftBukkit end
}
public void resetEmptyTime() {
@@ -680,6 +757,7 @@
@@ -695,6 +772,7 @@
});
gameprofilerfiller.c("tickNonPassenger");
gameprofilerfiller.incrementCounter("tickNonPassenger");
entity.tick();
+ entity.postTick(); // CraftBukkit
this.getMethodProfiler().exit();
this.getProfiler().pop();
Iterator iterator = entity.getPassengers().iterator();
@@ -703,6 +781,7 @@
@@ -718,6 +796,7 @@
});
gameprofilerfiller.c("tickPassenger");
entity1.passengerTick();
gameprofilerfiller.incrementCounter("tickPassenger");
entity1.rideTick();
+ entity1.postTick(); // CraftBukkit
gameprofilerfiller.exit();
gameprofilerfiller.pop();
Iterator iterator = entity1.getPassengers().iterator();
@@ -727,6 +806,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkProvider();
@@ -742,6 +821,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkSource();
if (!flag1) {
+ org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
if (iprogressupdate != null) {
iprogressupdate.a(new ChatMessage("menu.savingLevel"));
iprogressupdate.progressStartNoAbort(new ChatMessage("menu.savingLevel"));
}
@@ -744,11 +824,19 @@
@@ -759,11 +839,19 @@
}
}
@@ -281,105 +263,100 @@
+ // CraftBukkit start - moved from MinecraftServer.saveChunks
+ WorldServer worldserver1 = this;
+
+ serverLevelData.a(worldserver1.getWorldBorder().t());
+ serverLevelData.setCustomBossEvents(this.server.getBossBattleCustomData().save());
+ convertable.a(this.server.registryHolder, this.serverLevelData, this.server.getPlayerList().save());
+ serverLevelData.setWorldBorder(worldserver1.getWorldBorder().createSettings());
+ serverLevelData.setCustomBossEvents(this.server.getCustomBossEvents().save());
+ convertable.saveDataTag(this.server.registryHolder, this.serverLevelData, this.server.getPlayerList().getSingleplayerData());
+ // CraftBukkit end
}
private void ap() {
private void saveLevelData() {
if (this.dragonFight != null) {
- this.server.getSaveData().a(this.dragonFight.a());
+ this.serverLevelData.a(this.dragonFight.a()); // CraftBukkit
- this.server.getWorldData().setEndDragonFightData(this.dragonFight.saveData());
+ this.serverLevelData.setEndDragonFightData(this.dragonFight.saveData()); // CraftBukkit
}
this.getChunkProvider().getWorldPersistentData().a();
@@ -794,15 +882,34 @@
this.getChunkSource().getDataStorage().save();
@@ -809,15 +897,34 @@
@Override
public boolean addEntity(Entity entity) {
- return this.addEntity0(entity);
public boolean addFreshEntity(Entity entity) {
- return this.addEntity(entity);
+ // CraftBukkit start
+ return this.addEntity0(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ return this.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Override
+ public boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity0(entity, reason);
+ public boolean addFreshEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason);
+ // CraftBukkit end
}
public boolean addEntitySerialized(Entity entity) {
- return this.addEntity0(entity);
public boolean addWithUUID(Entity entity) {
- return this.addEntity(entity);
+ // CraftBukkit start
+ return this.addEntitySerialized(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ return this.addWithUUID(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public boolean addEntitySerialized(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity0(entity, reason);
+ public boolean addWithUUID(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason);
+ // CraftBukkit end
}
public void addEntityTeleport(Entity entity) {
- this.addEntity0(entity);
public void addDuringTeleport(Entity entity) {
- this.addEntity(entity);
+ // CraftBukkit start
+ this.addEntity0(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ this.addDuringTeleport(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public void addEntityTeleport(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ this.addEntity0(entity, reason);
+ public void addDuringTeleport(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ this.addEntity(entity, reason);
+ // CraftBukkit end
}
public void addPlayerCommand(EntityPlayer entityplayer) {
@@ -830,27 +937,39 @@
this.a((EntityPlayer) entity, Entity.RemovalReason.DISCARDED);
}
- this.entityManager.a((EntityAccess) entityplayer);
+ this.entityManager.a(entityplayer); // CraftBukkit - decompile error
public void addDuringCommandTeleport(EntityPlayer entityplayer) {
@@ -848,24 +955,36 @@
this.entityManager.addNewEntity(entityplayer);
}
- private boolean addEntity0(Entity entity) {
- private boolean addEntity(Entity entity) {
+ // CraftBukkit start
+ private boolean addEntity0(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
+ private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
if (entity.isRemoved()) {
- 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
- WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType()));
+ // WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
return false;
} else {
- return this.entityManager.a((EntityAccess) entity);
+ if (!CraftEventFactory.doEntityAddEventCalling(this, entity, spawnReason)) {
+ return false;
+ }
+ // CraftBukkit end
+
+ return this.entityManager.a(entity); // CraftBukkit - decompile error
return this.entityManager.addNewEntity(entity);
}
}
public boolean addAllEntitiesSafely(Entity entity) {
- Stream stream = entity.recursiveStream().map(Entity::getUniqueID);
public boolean tryAddFreshEntityWithPassengers(Entity entity) {
- Stream stream = entity.getSelfAndPassengers().map(Entity::getUUID);
+ // CraftBukkit start
+ return this.addAllEntitiesSafely(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ return this.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public boolean addAllEntitiesSafely(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ public boolean tryAddFreshEntityWithPassengers(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ // CraftBukkit end
+ Stream<UUID> stream = entity.recursiveStream().map(Entity::getUniqueID); // CraftBukkit - decompile error
+ Stream<UUID> stream = entity.getSelfAndPassengers().map(Entity::getUUID); // CraftBukkit - decompile error
PersistentEntitySectionManager persistententitysectionmanager = this.entityManager;
Objects.requireNonNull(this.entityManager);
if (stream.anyMatch(persistententitysectionmanager::a)) {
if (stream.anyMatch(persistententitysectionmanager::isLoaded)) {
return false;
} else {
- this.addAllEntities(entity);
+ this.addAllEntities(entity, reason); // CraftBukkit
- this.addFreshEntityWithPassengers(entity);
+ this.addFreshEntityWithPassengers(entity, reason); // CraftBukkit
return true;
}
}
@@ -863,10 +982,32 @@
entityplayer.a(entity_removalreason);
@@ -879,10 +998,32 @@
entityplayer.remove(entity_removalreason);
}
+ // CraftBukkit start
@@ -394,12 +371,12 @@
+ return false;
+ }
+
+ return this.addEntity(entitylightning);
+ return this.addFreshEntity(entitylightning);
+ }
+ // CraftBukkit end
+
@Override
public void a(int i, BlockPosition blockposition, int j) {
public void destroyBlockProgress(int i, BlockPosition blockposition, int j) {
Iterator iterator = this.server.getPlayerList().getPlayers().iterator();
+ // CraftBukkit start
@@ -411,9 +388,9 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -875,6 +1016,12 @@
double d1 = (double) blockposition.getY() - entityplayer.locY();
double d2 = (double) blockposition.getZ() - entityplayer.locZ();
@@ -891,6 +1032,12 @@
double d1 = (double) blockposition.getY() - entityplayer.getY();
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
+ // CraftBukkit start
+ if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
@@ -422,9 +399,9 @@
+ // CraftBukkit end
+
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
@@ -923,7 +1070,18 @@
@@ -938,7 +1085,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@@ -437,19 +414,19 @@
+ // This can happen because the pathfinder update below may trigger a chunk load, which in turn may cause more navigators to register
+ // In this case we just run the update again across all the iterators as the chunk will then be loaded
+ // As this is a relative edge case it is much faster than copying navigators (on either read or write)
+ notify(blockposition, iblockdata, iblockdata1, i);
+ sendBlockUpdated(blockposition, iblockdata, iblockdata1, i);
+ return;
+ }
+ // CraftBukkit end
NavigationAbstract navigationabstract = entityinsentient.getNavigation();
if (!navigationabstract.i()) {
@@ -946,10 +1104,20 @@
if (!navigationabstract.hasDelayedRecomputation()) {
@@ -961,10 +1119,20 @@
@Override
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) {
public Explosion explode(@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
+ Explosion explosion = super.createExplosion(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
+ Explosion explosion = super.explode(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
+
+ if (explosion.wasCanceled) {
+ return explosion;
@@ -458,17 +435,17 @@
+ /* Remove
Explosion explosion = new Explosion(this, entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
explosion.a();
explosion.a(false);
explosion.explode();
explosion.finalizeExplosion(false);
+ */
+ // CraftBukkit end - TODO: Check if explosions are still properly implemented
if (explosion_effect == Explosion.Effect.NONE) {
explosion.clearBlocks();
explosion.clearToBlow();
}
@@ -1023,13 +1191,20 @@
@@ -1045,13 +1213,20 @@
}
public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
public <T extends ParticleParam> int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
- 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);
@@ -483,72 +460,72 @@
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
- if (this.sendParticles(entityplayer, false, d0, d1, d2, packetplayoutworldparticles)) {
+ if (this.sendParticles(entityplayer, force, d0, d1, d2, packetplayoutworldparticles)) { // CraftBukkit
++j;
}
}
@@ -1079,7 +1254,7 @@
@@ -1101,7 +1276,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.serverLevelData.getGeneratorSettings().shouldGenerateMapFeatures() ? null : this.getChunkProvider().getChunkGenerator().findNearestMapFeature(this, structuregenerator, blockposition, i, flag); // CraftBukkit
public BlockPosition findNearestMapFeature(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) {
- return !this.server.getWorldData().worldGenSettings().generateFeatures() ? null : this.getChunkSource().getGenerator().findNearestMapFeature(this, structuregenerator, blockposition, i, flag);
+ return !this.serverLevelData.worldGenSettings().generateFeatures() ? null : this.getChunkSource().getGenerator().findNearestMapFeature(this, structuregenerator, blockposition, i, flag); // CraftBukkit
}
@Nullable
@@ -1116,11 +1291,21 @@
@@ -1138,11 +1313,21 @@
@Nullable
@Override
public WorldMap a(String s) {
- return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().a(WorldMap::b, s);
+ return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().a((nbttagcompound) -> {
+ // CraftBukkit start
public WorldMap getMapData(String s) {
- return (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap::load, s);
+ // CraftBukkit start
+ return (WorldMap) this.getServer().overworld().getDataStorage().get((nbttagcompound) -> {
+ // We only get here when the data file exists, but is not a valid map
+ WorldMap newMap = WorldMap.b(nbttagcompound);
+ WorldMap newMap = WorldMap.load(nbttagcompound);
+ newMap.id = s;
+ MapInitializeEvent event = new MapInitializeEvent(newMap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ return newMap;
+ // CraftBukkit end
+ }, s);
+ // CraftBukkit end
}
@Override
public void a(String s, WorldMap worldmap) {
public void setMapData(String s, WorldMap worldmap) {
+ worldmap.id = s; // CraftBukkit
this.getMinecraftServer().E().getWorldPersistentData().a(s, (PersistentBase) worldmap);
this.getServer().overworld().getDataStorage().set(s, worldmap);
}
@@ -1432,6 +1617,11 @@
@@ -1454,6 +1639,11 @@
@Override
public void update(BlockPosition blockposition, Block block) {
if (!this.isDebugWorld()) {
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
+ // CraftBukkit start
+ if (populating) {
+ return;
+ }
+ // CraftBukkit end
this.applyPhysics(blockposition, block);
this.updateNeighborsAt(blockposition, block);
}
@@ -1451,12 +1641,12 @@
@@ -1473,12 +1663,12 @@
}
public boolean isFlatWorld() {
- return this.server.getSaveData().getGeneratorSettings().isFlatWorld();
+ return this.serverLevelData.getGeneratorSettings().isFlatWorld(); // CraftBukkit
public boolean isFlat() {
- return this.server.getWorldData().worldGenSettings().isFlatWorld();
+ return this.serverLevelData.worldGenSettings().isFlatWorld(); // CraftBukkit
}
@Override
public long getSeed() {
- return this.server.getSaveData().getGeneratorSettings().getSeed();
+ return this.serverLevelData.getGeneratorSettings().getSeed(); // CraftBukkit
- return this.server.getWorldData().worldGenSettings().seed();
+ return this.serverLevelData.worldGenSettings().seed(); // CraftBukkit
}
@Nullable
@@ -1484,7 +1674,7 @@
private static <T> String a(Iterable<T> iterable, Function<T, String> function) {
@@ -1506,7 +1696,7 @@
private static <T> String getTypeCount(Iterable<T> iterable, Function<T, String> function) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
- Iterator iterator = iterable.iterator();
@@ -556,7 +533,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1493,7 +1683,7 @@
@@ -1515,7 +1705,7 @@
object2intopenhashmap.addTo(s, 1);
}
@@ -565,15 +542,15 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1504,17 +1694,33 @@
@@ -1526,17 +1716,33 @@
}
public static void a(WorldServer worldserver) {
public static void makeObsidianPlatform(WorldServer worldserver) {
+ // CraftBukkit start
+ WorldServer.a(worldserver, null);
+ WorldServer.makeObsidianPlatform(worldserver, null);
+ }
+
+ public static void a(WorldServer worldserver, Entity entity) {
+ public static void makeObsidianPlatform(WorldServer worldserver, Entity entity) {
+ // CraftBukkit end
BlockPosition blockposition = WorldServer.END_SPAWN_POINT;
int i = blockposition.getX();
@@ -582,13 +559,13 @@
+ // 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.betweenClosed(i - 2, j + 1, k - 2, i + 2, j + 3, k + 2).forEach((blockposition1) -> {
- worldserver.setBlockAndUpdate(blockposition1, Blocks.AIR.defaultBlockState());
+ blockList.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 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);
BlockPosition.betweenClosed(i - 2, j, k - 2, i + 2, j, k + 2).forEach((blockposition1) -> {
- worldserver.setBlockAndUpdate(blockposition1, Blocks.OBSIDIAN.defaultBlockState());
+ blockList.setBlock(blockposition1, Blocks.OBSIDIAN.defaultBlockState(), 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);
@@ -601,16 +578,16 @@
}
@Override
@@ -1601,6 +1807,7 @@
@@ -1629,6 +1835,7 @@
}
}
+ entity.valid = true; // CraftBukkit
}
public void a(Entity entity) {
@@ -1633,6 +1840,7 @@
gameeventlistenerregistrar.a(entity.level);
public void onTrackingEnd(Entity entity) {
@@ -1661,6 +1868,7 @@
gameeventlistenerregistrar.onListenerRemoved(entity.level);
}
+ entity.valid = false; // CraftBukkit