Update to Minecraft 1.21.2

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-10-23 02:15:00 +11:00
parent 2c4beb962b
commit d3a23f42c3
522 changed files with 8501 additions and 6477 deletions

View File

@@ -15,4 +15,4 @@
+ this.player.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), advancementholder.toBukkit())); // CraftBukkit
advancementholder.value().rewards().grant(this.player);
advancementholder.value().display().ifPresent((advancementdisplay) -> {
if (advancementdisplay.shouldAnnounceChat() && this.player.level().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
if (advancementdisplay.shouldAnnounceChat() && this.player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/AdvancementDataWorld.java
+++ b/net/minecraft/server/AdvancementDataWorld.java
@@ -27,11 +27,15 @@
@@ -21,10 +21,14 @@
import net.minecraft.util.profiling.GameProfilerFiller;
import org.slf4j.Logger;
@@ -8,18 +8,17 @@
+import java.util.HashMap;
+// CraftBukkit end
+
public class AdvancementDataWorld extends ResourceDataJson {
public class AdvancementDataWorld extends ResourceDataJson<Advancement> {
private static final Logger LOGGER = LogUtils.getLogger();
public static final Gson GSON = (new GsonBuilder()).create();
- public Map<MinecraftKey, AdvancementHolder> advancements = Map.of();
+ public Map<MinecraftKey, AdvancementHolder> advancements = new HashMap<>(); // CraftBukkit - SPIGOT-7734: mutable
private AdvancementTree tree = new AdvancementTree();
private final HolderLookup.a registries;
@@ -55,7 +59,7 @@
}
@@ -40,7 +44,7 @@
this.validate(minecraftkey, advancement);
builder.put(minecraftkey, new AdvancementHolder(minecraftkey, advancement));
});
- this.advancements = builder.buildOrThrow();
+ this.advancements = new HashMap<>(builder.buildOrThrow()); // CraftBukkit - SPIGOT-7734: mutable

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/CustomFunctionData.java
+++ b/net/minecraft/server/CustomFunctionData.java
@@ -36,7 +36,7 @@
@@ -37,7 +37,7 @@
}
public CommandDispatcher<CommandListenerWrapper> getDispatcher() {

View File

@@ -1,7 +1,7 @@
--- a/net/minecraft/server/DispenserRegistry.java
+++ b/net/minecraft/server/DispenserRegistry.java
@@ -28,6 +28,12 @@
import net.minecraft.world.level.block.BlockFire;
@@ -29,6 +29,12 @@
import net.minecraft.world.level.block.state.BlockBase;
import org.slf4j.Logger;
+// CraftBukkit start
@@ -13,7 +13,7 @@
public class DispenserRegistry {
public static final PrintStream STDOUT = System.out;
@@ -39,6 +45,23 @@
@@ -40,6 +46,23 @@
public static void bootStrap() {
if (!DispenserRegistry.isBootstrapped) {
@@ -37,7 +37,7 @@
DispenserRegistry.isBootstrapped = true;
Instant instant = Instant.now();
@@ -58,6 +81,69 @@
@@ -59,6 +82,69 @@
wrapStreams();
DispenserRegistry.bootstrapDuration.set(Duration.between(instant, Instant.now()).toMillis());
}

View File

@@ -135,7 +135,7 @@
worldstem = (WorldStem) SystemUtils.blockUntilDone((executor) -> {
return WorldLoader.load(worldloader_c, (worldloader_a) -> {
+ worldLoader.set(worldloader_a); // CraftBukkit
IRegistry<WorldDimension> iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
IRegistry<WorldDimension> iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
if (dynamic1 != null) {
@@ -199,7 +248,7 @@
@@ -150,7 +150,7 @@
@@ -207,7 +256,7 @@
DedicatedServerProperties dedicatedserverproperties = dedicatedserversettings.getProperties();
worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration());
worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
- worldoptions = optionset.has(optionspec3) ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
+ worldoptions = optionset.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; // CraftBukkit
worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
@@ -213,5 +213,5 @@
- Main.LOGGER.info("Forcing world upgrade!");
+ Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit
WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, iregistrycustom, flag, flag1);
IChatBaseComponent ichatbasecomponent = null;
try {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -173,13 +173,38 @@
@@ -180,13 +180,38 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -29,7 +29,7 @@
+import org.bukkit.event.server.ServerLoadEvent;
+// CraftBukkit end
+
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements ServerInfo, ChunkIOErrorReporter, ICommandListener, AutoCloseable {
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements ServerInfo, ChunkIOErrorReporter, ICommandListener {
public static final Logger LOGGER = LogUtils.getLogger();
public static final String VANILLA_BRAND = "vanilla";
@@ -40,9 +40,9 @@
private static final int OVERLOADED_TICKS_THRESHOLD = 20;
private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeRange.NANOSECONDS_PER_SECOND;
private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100;
@@ -266,6 +291,19 @@
private volatile boolean isSaving;
private static final AtomicReference<RuntimeException> fatalException = new AtomicReference();
@@ -277,6 +302,19 @@
private final SuppressedExceptionCollector suppressedExceptions;
private final DiscontinuousFrame tickFrame;
+ // CraftBukkit start
+ public final WorldLoader.a worldLoader;
@@ -60,7 +60,7 @@
public static <S extends MinecraftServer> S spin(Function<Thread, S> function) {
AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new Thread(() -> {
@@ -279,14 +317,14 @@
@@ -290,14 +328,14 @@
thread.setPriority(8);
}
@@ -76,19 +76,19 @@
+ public MinecraftServer(OptionSet options, WorldLoader.a worldLoader, Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, Proxy proxy, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) {
super("Server");
this.metricsRecorder = InactiveMetricsRecorder.INSTANCE;
this.profiler = this.metricsRecorder.getProfiler();
@@ -309,7 +347,7 @@
this.customBossEvents = new BossBattleCustomData();
this.onMetricsRecordingStopped = (methodprofilerresults) -> {
@@ -321,7 +359,7 @@
this.suppressedExceptions = new SuppressedExceptionCollector();
this.registries = worldstem.registries();
this.worldData = worldstem.worldData();
- if (!this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) {
+ if (false && !this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { // CraftBukkit - initialised later
- if (!this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) {
+ if (false && !this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { // CraftBukkit - initialised later
throw new IllegalStateException("Missing Overworld dimension data");
} else {
this.proxy = proxy;
@@ -334,6 +372,33 @@
this.executor = SystemUtils.backgroundExecutor();
this.potionBrewing = PotionBrewer.bootstrap(this.worldData.enabledFeatures());
@@ -349,6 +387,33 @@
this.fuelValues = FuelValues.vanillaBurnTimes(this.registries.compositeAccess(), this.worldData.enabledFeatures());
this.tickFrame = TracyClient.createDiscontinuousFrame("Server Tick");
}
+ // CraftBukkit start
+ this.options = options;
@@ -120,7 +120,7 @@
}
private void readScoreboard(WorldPersistentData worldpersistentdata) {
@@ -342,7 +407,7 @@
@@ -357,7 +422,7 @@
protected abstract boolean initServer() throws IOException;
@@ -129,7 +129,7 @@
if (!JvmProfiler.INSTANCE.isRunning()) {
;
}
@@ -350,12 +415,8 @@
@@ -365,12 +430,8 @@
boolean flag = false;
ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted();
@@ -143,19 +143,19 @@
if (profiledduration != null) {
profiledduration.finish();
}
@@ -372,23 +433,217 @@
@@ -387,23 +448,217 @@
protected void forceDifficulty() {}
- protected void createLevels(WorldLoadListener worldloadlistener) {
- IWorldDataServer iworlddataserver = this.worldData.overworldData();
- boolean flag = this.worldData.isDebugWorld();
- IRegistry<WorldDimension> iregistry = this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM);
- IRegistry<WorldDimension> iregistry = this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM);
- WorldOptions worldoptions = this.worldData.worldGenOptions();
- long i = worldoptions.seed();
- long j = BiomeManager.obfuscateSeed(i);
- List<MobSpawner> list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
- WorldDimension worlddimension = (WorldDimension) iregistry.get(WorldDimension.OVERWORLD);
- WorldDimension worlddimension = (WorldDimension) iregistry.getValue(WorldDimension.OVERWORLD);
- WorldServer worldserver = new WorldServer(this, this.executor, this.storageSource, iworlddataserver, World.OVERWORLD, worlddimension, worldloadlistener, flag, j, list, true, (RandomSequences) null);
+ // CraftBukkit start
+ private void loadWorld0(String s) {
@@ -164,7 +164,7 @@
- this.levels.put(World.OVERWORLD, worldserver);
- WorldPersistentData worldpersistentdata = worldserver.getDataStorage();
+ IRegistryCustom.Dimension iregistrycustom_dimension = this.registries.compositeAccess();
+ IRegistry<WorldDimension> dimensions = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM);
+ IRegistry<WorldDimension> dimensions = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM);
+ for (WorldDimension worldDimension : dimensions) {
+ ResourceKey<WorldDimension> dimensionKey = dimensions.getResourceKey(worldDimension).get();
@@ -276,7 +276,7 @@
+
+ WorldDataServer worlddata;
+ WorldLoader.a worldloader_a = this.worldLoader;
+ IRegistry<WorldDimension> iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
+ IRegistry<WorldDimension> iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
+ if (dynamic != null) {
+ LevelDataAndDimensions leveldataanddimensions = Convertable.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen());
+
@@ -293,7 +293,7 @@
+ } else {
+ DedicatedServerProperties dedicatedserverproperties = ((DedicatedServer) this).getProperties();
+
+ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration());
+ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
+ worldoptions = options.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
+ worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
+ }
@@ -316,7 +316,7 @@
+ long i = worldoptions.seed();
+ long j = BiomeManager.obfuscateSeed(i);
+ List<MobSpawner> list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
+ WorldDimension worlddimension = (WorldDimension) dimensions.get(dimensionKey);
+ WorldDimension worlddimension = (WorldDimension) dimensions.getValue(dimensionKey);
+
+ org.bukkit.generator.WorldInfo worldInfo = new org.bukkit.craftbukkit.generator.CraftWorldInfo(iworlddataserver, worldSession, org.bukkit.World.Environment.getEnvironment(dimension), worlddimension.type().value());
+ if (biomeProvider == null && gen != null) {
@@ -375,7 +375,7 @@
if (!iworlddataserver.isInitialized()) {
try {
@@ -412,30 +667,8 @@
@@ -427,30 +682,8 @@
iworlddataserver.setInitialized(true);
}
@@ -407,7 +407,7 @@
private static void setInitialSpawn(WorldServer worldserver, IWorldDataServer iworlddataserver, boolean flag, boolean flag1) {
if (flag1) {
@@ -443,6 +676,21 @@
@@ -458,6 +691,21 @@
} else {
ChunkProviderServer chunkproviderserver = worldserver.getChunkSource();
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(chunkproviderserver.randomState().sampler().findSpawnPosition());
@@ -428,8 +428,8 @@
+ // CraftBukkit end
int i = chunkproviderserver.getGenerator().getSpawnHeight(worldserver);
if (i < worldserver.getMinBuildHeight()) {
@@ -501,8 +749,11 @@
if (i < worldserver.getMinY()) {
@@ -516,8 +764,11 @@
iworlddataserver.setGameType(EnumGamemode.SPECTATOR);
}
@@ -443,7 +443,7 @@
MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.dimension().location());
BlockPosition blockposition = worldserver.getSharedSpawnPos();
@@ -512,20 +763,22 @@
@@ -527,20 +778,22 @@
this.nextTickTimeNanos = SystemUtils.getNanos();
worldserver.setDefaultSpawnPos(blockposition, worldserver.getSharedSpawnAngle());
@@ -474,7 +474,7 @@
ForcedChunk forcedchunk = (ForcedChunk) worldserver1.getDataStorage().get(ForcedChunk.factory(), "chunks");
if (forcedchunk != null) {
@@ -540,10 +793,17 @@
@@ -555,10 +808,17 @@
}
}
@@ -488,14 +488,14 @@
- this.updateMobSpawningFlags();
+ // CraftBukkit start
+ // this.updateMobSpawningFlags();
+ worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
+ worldserver.setSpawnSettings(this.isSpawningMonsters());
+
+ this.forceTicks = false;
+ // CraftBukkit end
}
public EnumGamemode getDefaultGameType() {
@@ -573,12 +833,16 @@
@@ -588,12 +848,16 @@
worldserver.save((IProgressUpdate) null, flag1, worldserver.noSave && !flag2);
}
@@ -512,7 +512,7 @@
if (flag1) {
Iterator iterator1 = this.getAllLevels().iterator();
@@ -613,18 +877,40 @@
@@ -628,18 +892,40 @@
this.stopServer();
}
@@ -553,7 +553,7 @@
}
MinecraftServer.LOGGER.info("Saving worlds");
@@ -712,7 +998,7 @@
@@ -727,7 +1013,7 @@
}
this.nextTickTimeNanos = SystemUtils.getNanos();
@@ -562,7 +562,7 @@
this.status = this.buildServerStatus();
while (this.running) {
@@ -729,6 +1015,7 @@
@@ -744,6 +1030,7 @@
if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) {
long k = j / i;
@@ -570,15 +570,15 @@
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", j / TimeRange.NANOSECONDS_PER_MILLISECOND, k);
this.nextTickTimeNanos += k * i;
this.lastOverloadWarningNanos = this.nextTickTimeNanos;
@@ -742,6 +1029,7 @@
@@ -757,6 +1044,7 @@
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(SystemUtils.getNanos(), this.tickCount);
}
+ MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
this.nextTickTimeNanos += i;
this.startMetricsRecordingTick();
this.profiler.push("tick");
@@ -789,6 +1077,12 @@
try {
@@ -830,6 +1118,12 @@
this.services.profileCache().clearExecutor();
}
@@ -591,7 +591,7 @@
this.onServerExit();
}
@@ -848,7 +1142,14 @@
@@ -889,7 +1183,14 @@
}
private boolean haveTime() {
@@ -607,7 +607,7 @@
}
public static boolean throwIfFatalException() {
@@ -862,7 +1163,7 @@
@@ -903,7 +1204,7 @@
}
public static void setFatalException(RuntimeException runtimeexception) {
@@ -616,36 +616,49 @@
}
@Override
@@ -928,7 +1229,7 @@
@@ -977,7 +1278,7 @@
}
}
- protected void doRunTask(TickTask ticktask) {
+ public void doRunTask(TickTask ticktask) { // CraftBukkit - decompile error
this.getProfiler().incrementCounter("runTask");
Profiler.get().incrementCounter("runTask");
super.doRunTask(ticktask);
}
@@ -987,8 +1288,10 @@
@@ -1041,6 +1342,7 @@
this.autoSave();
}
+ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
this.tickConnection();
return;
}
@@ -1055,7 +1357,7 @@
}
--this.ticksUntilAutosave;
- if (this.ticksUntilAutosave <= 0) {
- this.ticksUntilAutosave = this.computeNextAutosaveInterval();
+ // CraftBukkit start
+ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) {
+ this.ticksUntilAutosave = this.autosavePeriod;
+ // CraftBukkit end
MinecraftServer.LOGGER.debug("Autosave started");
this.profiler.push("save");
this.saveEverything(true, false, false);
@@ -1076,11 +1379,26 @@
+ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) { // CraftBukkit
this.autoSave();
}
@@ -1074,7 +1376,7 @@
}
private void autoSave() {
- this.ticksUntilAutosave = this.computeNextAutosaveInterval();
+ this.ticksUntilAutosave = this.autosavePeriod; // CraftBukkit
MinecraftServer.LOGGER.debug("Autosave started");
GameProfilerFiller gameprofilerfiller = Profiler.get();
@@ -1154,11 +1456,26 @@
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing();
});
+ this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit
this.profiler.push("commandFunctions");
+ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
gameprofilerfiller.push("commandFunctions");
this.getFunctions().tick();
this.profiler.popPush("levels");
gameprofilerfiller.popPush("levels");
Iterator iterator = this.getAllLevels().iterator();
+ // CraftBukkit start
@@ -658,28 +671,28 @@
+ if (this.tickCount % 20 == 0) {
+ for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
+ EntityPlayer entityplayer = (EntityPlayer) this.getPlayerList().players.get(i);
+ entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
+ entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
+ }
+ }
+
while (iterator.hasNext()) {
WorldServer worldserver = (WorldServer) iterator.next();
@@ -1089,11 +1407,13 @@
@@ -1167,11 +1484,13 @@
return s + " " + String.valueOf(worldserver.dimension().location());
});
+ /* Drop global time updates
if (this.tickCount % 20 == 0) {
this.profiler.push("timeSync");
gameprofilerfiller.push("timeSync");
this.synchronizeTime(worldserver);
this.profiler.pop();
gameprofilerfiller.pop();
}
+ // CraftBukkit end */
this.profiler.push("tick");
gameprofilerfiller.push("tick");
@@ -1183,6 +1503,22 @@
@@ -1267,6 +1586,22 @@
return (WorldServer) this.levels.get(resourcekey);
}
@@ -702,7 +715,7 @@
public Set<ResourceKey<World>> levelKeys() {
return this.levels.keySet();
}
@@ -1212,7 +1548,7 @@
@@ -1296,7 +1631,7 @@
@DontObfuscate
public String getServerModName() {
@@ -711,7 +724,7 @@
}
public SystemReport fillSystemReport(SystemReport systemreport) {
@@ -1554,11 +1890,11 @@
@@ -1634,11 +1969,11 @@
public CompletableFuture<Void> reloadResources(Collection<String> collection) {
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
@@ -724,8 +737,8 @@
+ return stream.map(resourcepackrepository::getPack).filter(Objects::nonNull).map(ResourcePackLoader::open).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error
}, this).thenCompose((immutablelist) -> {
ResourceManager resourcemanager = new ResourceManager(EnumResourcePackType.SERVER_DATA, immutablelist);
@@ -1573,6 +1909,7 @@
List<IRegistry.a<?>> list = TagDataPack.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
@@ -1654,6 +1989,7 @@
}).thenAcceptAsync((minecraftserver_reloadableresources) -> {
this.resources.close();
this.resources = minecraftserver_reloadableresources;
@@ -733,16 +746,16 @@
this.packRepository.setSelected(collection);
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
@@ -1873,7 +2210,7 @@
@@ -1952,7 +2288,7 @@
final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules();
- GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor(this) {
+ GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { // CraftBukkit - decompile error
- gamerules.visitGameRuleTypes(new GameRules.GameRuleVisitor(this) {
+ gamerules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { // CraftBukkit - decompile error
@Override
public <T extends GameRules.GameRuleValue<T>> void visit(GameRules.GameRuleKey<T> gamerules_gamerulekey, GameRules.GameRuleDefinition<T> gamerules_gameruledefinition) {
list.add(String.format(Locale.ROOT, "%s=%s\n", gamerules_gamerulekey.getId(), gamerules.getRule(gamerules_gamerulekey)));
@@ -1979,7 +2316,7 @@
@@ -2058,7 +2394,7 @@
try {
label51:
{
@@ -751,7 +764,7 @@
try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules());
@@ -2029,6 +2366,22 @@
@@ -2108,6 +2444,22 @@
}
@@ -771,10 +784,10 @@
+ }
+ // CraftBukkit end
+
private void startMetricsRecordingTick() {
private GameProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(SystemUtils.timeSource, this.isDedicatedServer()), SystemUtils.timeSource, SystemUtils.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
@@ -2159,6 +2512,11 @@
@@ -2235,6 +2587,11 @@
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/commands/CommandGamerule.java
+++ b/net/minecraft/server/commands/CommandGamerule.java
@@ -31,7 +31,7 @@
@@ -34,7 +34,7 @@
static <T extends GameRules.GameRuleValue<T>> int setRule(CommandContext<CommandListenerWrapper> commandcontext, GameRules.GameRuleKey<T> gamerules_gamerulekey) {
CommandListenerWrapper commandlistenerwrapper = (CommandListenerWrapper) commandcontext.getSource();
@@ -9,7 +9,7 @@
t0.setFromArgument(commandcontext, "value");
commandlistenerwrapper.sendSuccess(() -> {
@@ -41,7 +41,7 @@
@@ -44,7 +44,7 @@
}
static <T extends GameRules.GameRuleValue<T>> int queryRule(CommandListenerWrapper commandlistenerwrapper, GameRules.GameRuleKey<T> gamerules_gamerulekey) {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/commands/CommandLoot.java
+++ b/net/minecraft/server/commands/CommandLoot.java
@@ -91,7 +91,7 @@
@@ -95,7 +95,7 @@
}
private static <T extends ArgumentBuilder<CommandListenerWrapper, T>> T addTargets(T t0, CommandLoot.c commandloot_c) {
@@ -9,7 +9,7 @@
return entityReplace(ArgumentEntity.getEntities(commandcontext, "entities"), ArgumentInventorySlot.getSlot(commandcontext, "slot"), list.size(), list, commandloot_a);
}).then(commandloot_c.construct(net.minecraft.commands.CommandDispatcher.argument("count", IntegerArgumentType.integer(0)), (commandcontext, list, commandloot_a) -> {
return entityReplace(ArgumentEntity.getEntities(commandcontext, "entities"), ArgumentInventorySlot.getSlot(commandcontext, "slot"), IntegerArgumentType.getInteger(commandcontext, "count"), list, commandloot_a);
@@ -246,6 +246,7 @@
@@ -250,6 +250,7 @@
private static int dropInWorld(CommandListenerWrapper commandlistenerwrapper, Vec3D vec3d, List<ItemStack> list, CommandLoot.a commandloot_a) throws CommandSyntaxException {
WorldServer worldserver = commandlistenerwrapper.getLevel();

View File

@@ -1,11 +1,11 @@
--- a/net/minecraft/server/commands/CommandSchedule.java
+++ b/net/minecraft/server/commands/CommandSchedule.java
@@ -55,7 +55,7 @@
@@ -58,7 +58,7 @@
} else {
long j = commandlistenerwrapper.getLevel().getGameTime() + (long) i;
MinecraftKey minecraftkey = (MinecraftKey) pair.getFirst();
- CustomFunctionCallbackTimerQueue<MinecraftServer> customfunctioncallbacktimerqueue = commandlistenerwrapper.getServer().getWorldData().overworldData().getScheduledEvents();
+ CustomFunctionCallbackTimerQueue<MinecraftServer> customfunctioncallbacktimerqueue = commandlistenerwrapper.getLevel().serverLevelData.overworldData().getScheduledEvents(); // CraftBukkit - SPIGOT-6667: Use world specific function timer
Optional<net.minecraft.commands.functions.CommandFunction<CommandListenerWrapper>> optional = ((Either) pair.getSecond()).left();
String s;
((Either) pair.getSecond()).ifLeft((net_minecraft_commands_functions_commandfunction) -> {
String s = minecraftkey.toString();

View File

@@ -13,8 +13,8 @@
commandspreadplayers_a = acommandspreadplayers_a[j++];
}
- entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot());
+ entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit - handle teleport reason
- entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), true);
+ entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit - handle teleport reason
d1 = Double.MAX_VALUE;
CommandSpreadPlayers.a[] acommandspreadplayers_a1 = acommandspreadplayers_a;
int k = acommandspreadplayers_a.length;

View File

@@ -1,7 +1,7 @@
--- a/net/minecraft/server/commands/CommandSummon.java
+++ b/net/minecraft/server/commands/CommandSummon.java
@@ -67,7 +67,7 @@
((EntityInsentient) entity).finalizeSpawn(commandlistenerwrapper.getLevel(), commandlistenerwrapper.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.COMMAND, (GroupDataEntity) null);
((EntityInsentient) entity).finalizeSpawn(commandlistenerwrapper.getLevel(), commandlistenerwrapper.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, (GroupDataEntity) null);
}
- if (!worldserver.tryAddFreshEntityWithPassengers(entity)) {

View File

@@ -1,10 +1,11 @@
--- a/net/minecraft/server/commands/CommandTeleport.java
+++ b/net/minecraft/server/commands/CommandTeleport.java
@@ -33,6 +33,13 @@
@@ -31,6 +31,14 @@
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.event.entity.EntityTeleportEvent;
@@ -14,35 +15,35 @@
public class CommandTeleport {
private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(IChatBaseComponent.translatable("commands.teleport.invalidPosition"));
@@ -155,7 +162,30 @@
float f2 = MathHelper.wrapDegrees(f);
float f3 = MathHelper.wrapDegrees(f1);
@@ -167,7 +175,30 @@
float f4 = MathHelper.wrapDegrees(f2);
float f5 = MathHelper.wrapDegrees(f3);
- if (entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3)) {
- if (entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true)) {
+ // CraftBukkit start - Teleport event
+ boolean result;
+ if (entity instanceof EntityPlayer player) {
+ result = player.teleportTo(worldserver, d0, d1, d2, set, f2, f3, PlayerTeleportEvent.TeleportCause.COMMAND);
+ result = player.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true, PlayerTeleportEvent.TeleportCause.COMMAND);
+ } else {
+ Location to = new Location(worldserver.getWorld(), d0, d1, d2, f2, f3);
+ Location to = new Location(worldserver.getWorld(), d3, d4, d5, f4, f5);
+ EntityTeleportEvent event = new EntityTeleportEvent(entity.getBukkitEntity(), entity.getBukkitEntity().getLocation(), to);
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+
+ d0 = to.getX();
+ d1 = to.getY();
+ d2 = to.getZ();
+ f2 = to.getYaw();
+ f3 = to.getPitch();
+ d3 = to.getX();
+ d4 = to.getY();
+ d5 = to.getZ();
+ f4 = to.getYaw();
+ f5 = to.getPitch();
+ worldserver = ((CraftWorld) to.getWorld()).getHandle();
+
+ result = entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3);
+ result = entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true);
+ }
+
+ if (result) {
+ // CraftBukkit end
if (commandteleport_a != null) {
commandteleport_a.perform(commandlistenerwrapper, entity);
if (lookat != null) {
lookat.perform(commandlistenerwrapper, entity);
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -60,6 +60,18 @@
@@ -59,6 +59,18 @@
import net.minecraft.world.level.storage.Convertable;
import org.slf4j.Logger;
@@ -19,7 +19,7 @@
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
static final Logger LOGGER = LogUtils.getLogger();
@@ -68,7 +80,7 @@
@@ -67,7 +79,7 @@
private final List<ServerCommand> consoleInput = Collections.synchronizedList(Lists.newArrayList());
@Nullable
private RemoteStatusListener queryThreadGs4;
@@ -28,7 +28,7 @@
@Nullable
private RemoteControlListener rconThread;
public DedicatedServerSettings settings;
@@ -82,10 +94,12 @@
@@ -81,10 +93,12 @@
private DebugSampleSubscriptionTracker debugSampleSubscriptionTracker;
public ServerLinks serverLinks;
@@ -41,10 +41,10 @@
this.settings = dedicatedserversettings;
- this.rconConsoleSource = new RemoteControlCommandListener(this);
+ // this.rconConsoleSource = new RemoteControlCommandListener(this); // CraftBukkit - remove field
this.textFilterClient = TextFilter.createFromConfig(dedicatedserversettings.getProperties().textFilteringConfig);
this.serverTextFilter = ServerTextFilter.createFromConfig(dedicatedserversettings.getProperties());
this.serverLinks = createServerLinks(dedicatedserversettings);
}
@@ -94,13 +108,44 @@
@@ -93,13 +107,44 @@
public boolean initServer() throws IOException {
Thread thread = new Thread("Server console handler") {
public void run() {
@@ -92,7 +92,7 @@
}
} catch (IOException ioexception) {
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
@@ -109,6 +154,29 @@
@@ -108,6 +153,29 @@
}
};
@@ -122,7 +122,7 @@
thread.setDaemon(true);
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER));
thread.start();
@@ -133,7 +201,7 @@
@@ -132,7 +200,7 @@
this.setMotd(dedicatedserverproperties.motd);
super.setPlayerIdleTimeout((Integer) dedicatedserverproperties.playerIdleTimeout.get());
this.setEnforceWhitelist(dedicatedserverproperties.enforceWhitelist);
@@ -131,7 +131,7 @@
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
InetAddress inetaddress = null;
@@ -157,6 +225,12 @@
@@ -156,6 +224,12 @@
return false;
}
@@ -144,7 +144,7 @@
if (!this.usesAuthentication()) {
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
@@ -171,7 +245,7 @@
@@ -170,7 +244,7 @@
if (!NameReferencingFileConverter.serverReadyAfterUserconversion(this)) {
return false;
} else {
@@ -153,7 +153,7 @@
this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList());
this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME);
long i = SystemUtils.getNanos();
@@ -179,13 +253,13 @@
@@ -178,13 +252,13 @@
TileEntitySkull.setup(this.services, this);
UserCache.setUsesAuthentication(this.usesAuthentication());
DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName());
@@ -169,7 +169,7 @@
}
if (dedicatedserverproperties.enableQuery) {
@@ -311,6 +385,7 @@
@@ -293,6 +367,7 @@
this.queryThreadGs4.stop();
}
@@ -177,7 +177,7 @@
}
@Override
@@ -332,7 +407,15 @@
@@ -314,7 +389,15 @@
while (!this.consoleInput.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.consoleInput.remove(0);
@@ -194,7 +194,7 @@
}
}
@@ -559,16 +642,52 @@
@@ -541,16 +624,52 @@
@Override
public String getPluginNames() {
@@ -251,7 +251,7 @@
}
public void storeUsingWhiteList(boolean flag) {
@@ -673,4 +792,15 @@
@@ -660,4 +779,15 @@
}
}
}

View File

@@ -30,7 +30,7 @@
this.difficulty = (EnumDifficulty) this.get("difficulty", dispatchNumberOrString(EnumDifficulty::byId, EnumDifficulty::byName), EnumDifficulty::getKey, EnumDifficulty.EASY);
this.gamemode = (EnumGamemode) this.get("gamemode", dispatchNumberOrString(EnumGamemode::byId, EnumGamemode::byName), EnumGamemode::getName, EnumGamemode.SURVIVAL);
this.levelName = this.get("level-name", "world");
@@ -165,13 +172,15 @@
@@ -167,13 +174,15 @@
this.initialDataPackConfiguration = getDatapackConfig(this.get("initial-enabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getEnabled())), this.get("initial-disabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getDisabled())));
}
@@ -50,7 +50,7 @@
}
@Nullable
@@ -252,10 +261,10 @@
@@ -254,10 +263,10 @@
}).orElseThrow(() -> {
return new IllegalStateException("Invalid datapack contents: can't find default preset");
});
@@ -62,11 +62,11 @@
+ return Optional.ofNullable(DedicatedServerProperties.WorldDimensionData.LEGACY_PRESET_NAMES.get(this.levelType)); // CraftBukkit - decompile error
});
Objects.requireNonNull(iregistry);
@@ -267,7 +276,7 @@
Objects.requireNonNull(holderlookup);
@@ -269,7 +278,7 @@
if (holder.is(WorldPresets.FLAT)) {
RegistryOps<JsonElement> registryops = iregistrycustom.createSerializationContext(JsonOps.INSTANCE);
RegistryOps<JsonElement> registryops = holderlookup_a.createSerializationContext(JsonOps.INSTANCE);
- DataResult dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings()));
+ DataResult<GeneratorSettingsFlat> dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings())); // CraftBukkit - decompile error
Logger logger = DedicatedServerProperties.LOGGER;

View File

@@ -1,18 +1,22 @@
--- a/net/minecraft/server/level/ChunkMapDistance.java
+++ b/net/minecraft/server/level/ChunkMapDistance.java
@@ -121,6 +121,11 @@
}
@@ -117,6 +117,15 @@
PlayerChunk playerchunk;
if (!this.chunksToUpdateFutures.isEmpty()) {
+ // CraftBukkit start - SPIGOT-7780: Call chunk unload events before updateHighestAllowedStatus
+ this.chunksToUpdateFutures.forEach((playerchunk) -> {
+ while (iterator.hasNext()) {
+ playerchunk = (PlayerChunk) iterator.next();
+ playerchunk.callEventIfUnloading(playerchunkmap);
+ });
+ }
+
+ iterator = this.chunksToUpdateFutures.iterator();
+ // CraftBukkit end
this.chunksToUpdateFutures.forEach((playerchunk) -> {
+
while (iterator.hasNext()) {
playerchunk = (PlayerChunk) iterator.next();
playerchunk.updateHighestAllowedStatus(playerchunkmap);
});
@@ -163,7 +168,7 @@
@@ -165,7 +174,7 @@
}
}
@@ -21,7 +25,7 @@
ArraySetSorted<Ticket<?>> arraysetsorted = this.getTickets(i);
int j = getTicketLevelAt(arraysetsorted);
Ticket<?> ticket1 = (Ticket) arraysetsorted.addOrGet(ticket);
@@ -173,13 +178,15 @@
@@ -175,13 +184,15 @@
this.ticketTracker.update(i, ticket.getTicketLevel(), true);
}
@@ -39,7 +43,7 @@
}
if (arraysetsorted.isEmpty()) {
@@ -187,6 +194,7 @@
@@ -189,6 +200,7 @@
}
this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false);
@@ -47,7 +51,7 @@
}
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -200,19 +208,33 @@
@@ -202,19 +214,33 @@
}
public <T> void addRegionTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -83,7 +87,7 @@
}
private ArraySetSorted<Ticket<?>> getTickets(long i) {
@@ -251,6 +273,7 @@
@@ -253,6 +279,7 @@
ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk();
long i = chunkcoordintpair.toLong();
ObjectSet<EntityPlayer> objectset = (ObjectSet) this.playersPerChunk.get(i);
@@ -91,7 +95,7 @@
objectset.remove(entityplayer);
if (objectset.isEmpty()) {
@@ -380,6 +403,26 @@
@@ -391,6 +418,26 @@
return !this.tickets.isEmpty();
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/ChunkProviderServer.java
+++ b/net/minecraft/server/level/ChunkProviderServer.java
@@ -82,6 +82,16 @@
@@ -96,6 +96,16 @@
this.clearCache();
}
@@ -17,7 +17,7 @@
@Override
public LightEngineThreaded getLightEngine() {
return this.lightEngine;
@@ -125,7 +135,7 @@
@@ -139,7 +149,7 @@
if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
IChunkAccess ichunkaccess = this.lastChunk[l];
@@ -26,7 +26,7 @@
return ichunkaccess;
}
}
@@ -138,7 +148,7 @@
@@ -152,7 +162,7 @@
Objects.requireNonNull(completablefuture);
chunkproviderserver_b.managedBlock(completablefuture::isDone);
ChunkResult<IChunkAccess> chunkresult = (ChunkResult) completablefuture.join();
@@ -35,7 +35,7 @@
if (ichunkaccess1 == null && flag) {
throw (IllegalStateException) SystemUtils.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError()));
@@ -218,7 +228,15 @@
@@ -232,7 +242,15 @@
int l = ChunkLevel.byStatus(chunkstatus);
PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k);
@@ -51,8 +51,8 @@
+ // CraftBukkit end
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.chunkAbsent(playerchunk, l)) {
GameProfilerFiller gameprofilerfiller = this.level.getProfiler();
@@ -237,7 +255,7 @@
GameProfilerFiller gameprofilerfiller = Profiler.get();
@@ -251,7 +269,7 @@
}
private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) {
@@ -61,7 +61,7 @@
}
@Override
@@ -292,11 +310,31 @@
@@ -310,12 +328,34 @@
@Override
public void close() throws IOException {
@@ -75,40 +75,63 @@
+ this.save(true);
+ }
+ // CraftBukkit end
this.dataStorage.close();
this.lightEngine.close();
this.chunkMap.close();
}
+ // CraftBukkit start - modelled on below
+ public void purgeUnload() {
+ this.level.getProfiler().push("purge");
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+
+ gameprofilerfiller.push("purge");
+ this.distanceManager.purgeStaleTickets();
+ this.runDistanceManagerUpdates();
+ this.level.getProfiler().popPush("unload");
+ gameprofilerfiller.popPush("unload");
+ this.chunkMap.tick(() -> true);
+ this.level.getProfiler().pop();
+ gameprofilerfiller.pop();
+ this.clearCache();
+ }
+ // CraftBukkit end
+
@Override
public void tick(BooleanSupplier booleansupplier, boolean flag) {
this.level.getProfiler().push("purge");
@@ -346,11 +384,11 @@
GameProfilerFiller gameprofilerfiller = Profiler.get();
@@ -402,14 +442,14 @@
this.lastSpawnState = spawnercreature_d;
gameprofilerfiller.popPush("spawnAndTick");
- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
this.lastSpawnState = spawnercreature_d;
gameprofilerfiller.popPush("spawnAndTick");
- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
List list1;
SystemUtils.shuffle(list, this.level.random);
int l = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L;
+ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
Iterator iterator1 = list.iterator();
if (flag && (this.spawnEnemies || this.spawnFriendlies)) {
- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L;
+ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
while (iterator1.hasNext()) {
@@ -560,13 +598,19 @@
- list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
+ list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit
} else {
list1 = List.of();
}
@@ -542,8 +582,14 @@
@Override
public void setSpawnSettings(boolean flag) {
+ // CraftBukkit start
+ this.setSpawnSettings(flag, this.spawnFriendlies);
+ }
+
+ public void setSpawnSettings(boolean flag, boolean spawnFriendlies) {
this.spawnEnemies = flag;
- this.spawnFriendlies = this.spawnFriendlies;
+ this.spawnFriendlies = spawnFriendlies;
+ // CraftBukkit end
}
public String getChunkDebugData(ChunkCoordIntPair chunkcoordintpair) {
@@ -619,13 +665,19 @@
}
@Override

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityPlayer.java
+++ b/net/minecraft/server/level/EntityPlayer.java
@@ -166,6 +166,40 @@
@@ -184,6 +184,41 @@
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import org.slf4j.Logger;
@@ -15,6 +15,7 @@
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.WeatherType;
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.CraftWorldBorder;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
@@ -28,20 +29,20 @@
+import org.bukkit.event.player.PlayerBedLeaveEvent;
+import org.bukkit.event.player.PlayerChangedMainHandEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerLocaleChangeEvent;
+import org.bukkit.event.player.PlayerPortalEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerSpawnChangeEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+import org.bukkit.event.player.PlayerToggleSneakEvent;
+import org.bukkit.inventory.MainHand;
+// CraftBukkit end
+
public class EntityPlayer extends EntityHuman {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -204,7 +238,7 @@
@@ -227,7 +262,7 @@
private int levitationStartTime;
private boolean disconnected;
private int requestedViewDistance;
@@ -50,7 +51,7 @@
@Nullable
private Vec3D startingToFallPosition;
@Nullable
@@ -235,6 +269,21 @@
@@ -261,6 +296,22 @@
private int containerCounter;
public boolean wonGame;
@@ -58,6 +59,7 @@
+ public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName;
+ public IChatBaseComponent listName;
+ public int listOrder = 0;
+ public org.bukkit.Location compassTarget;
+ public int newExp = 0;
+ public int newLevel = 0;
@@ -72,7 +74,21 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, ClientInformation clientinformation) {
super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile);
this.chatVisibility = EnumChatVisibility.FULL;
@@ -302,14 +351,67 @@
@@ -342,6 +393,13 @@
public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) {
EntityPlayer.this.sendSystemMessage(ichatbasecomponent);
}
+
+ // CraftBukkit start
+ @Override
+ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return getBukkitEntity();
+ }
+ // CraftBukkit end
};
this.textFilter = minecraftserver.createTextFilterForPlayer(this);
this.gameMode = minecraftserver.createGameModeForPlayer(this);
@@ -354,14 +412,67 @@
this.moveTo(this.adjustSpawnLocation(worldserver, worldserver.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
this.updateOptions(clientinformation);
this.object = null;
@@ -81,8 +97,8 @@
+ this.displayName = this.getScoreboardName();
+ this.bukkitPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth();
}
+ }
+
+ // Use method to resend items in hands in case of client desync, because the item use got cancelled.
+ // For example, when cancelling the leash event
+ public void resendItemInHands() {
@@ -128,9 +144,9 @@
+ }
+
+ return blockposition;
+ }
}
+ // CraftBukkit end
+
@Override
public BlockPosition adjustSpawnLocation(WorldServer worldserver, BlockPosition blockposition) {
AxisAlignedBB axisalignedbb = this.getDimensions(EntityPose.STANDING).makeBoundingBox(Vec3D.ZERO);
@@ -141,7 +157,30 @@
int i = Math.max(0, this.server.getSpawnRadius(worldserver));
int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
@@ -366,7 +468,7 @@
@@ -397,14 +508,20 @@
Objects.requireNonNull(blockposition);
crashreportsystemdetails.setDetail("Origin", blockposition::toString);
+ // CraftBukkit start - decompile error
+ int finalI = i;
crashreportsystemdetails.setDetail("Radius", () -> {
- return Integer.toString(i);
+ return Integer.toString(finalI);
+ // CraftBukkit end
});
crashreportsystemdetails.setDetail("Candidate", () -> {
return "[" + l2 + "," + i3 + "]";
});
+ // CraftBukkit start - decompile error
+ int finalL1 = l1;
crashreportsystemdetails.setDetail("Progress", () -> {
- return "" + l1 + " out of " + i1;
+ return "" + finalL1 + " out of " + i1;
+ // CraftBukkit end
});
throw new ReportedException(crashreport);
}
@@ -442,7 +559,7 @@
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker")));
logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -150,9 +189,9 @@
this.wardenSpawnTracker = wardenspawntracker;
});
}
@@ -381,17 +483,26 @@
if (nbttagcompound.contains("recipeBook", 10)) {
this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager());
@@ -459,17 +576,26 @@
return this.server.getRecipeManager().byKey(resourcekey).isPresent();
});
}
+ this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit
@@ -178,7 +217,7 @@
Logger logger1 = EntityPlayer.LOGGER;
Objects.requireNonNull(logger1);
@@ -406,7 +517,7 @@
@@ -484,7 +610,7 @@
dataresult = BlockPosition.CODEC.parse(DynamicOpsNBT.INSTANCE, nbtbase);
logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -187,7 +226,7 @@
this.raidOmenPosition = blockposition;
});
}
@@ -416,7 +527,7 @@
@@ -494,7 +620,7 @@
@Override
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(nbttagcompound);
@@ -196,7 +235,15 @@
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -437,7 +548,20 @@
@@ -528,6 +654,7 @@
nbttagcompound.put("SpawnDimension", nbtbase);
});
}
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) {
@@ -546,7 +673,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
@@ -215,18 +262,43 @@
+
+ if (persistVehicle && entity1 != null && entity != this && entity.hasExactlyOnePlayerPassenger()) {
+ // CraftBukkit end
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -462,6 +586,7 @@
nbttagcompound.put("SpawnDimension", nbtbase);
});
}
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
@@ -600,12 +740,12 @@
nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) {
@@ -475,6 +600,29 @@
if (!this.isPassenger()) {
EntityPlayer.LOGGER.warn("Couldn't reattach entity to player");
- entity.discard();
+ entity.discard(null); // CraftBukkit - add Bukkit remove cause
iterator = entity.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
entity1 = (Entity) iterator.next();
- entity1.discard();
+ entity1.discard(null); // CraftBukkit - add Bukkit remove cause
}
}
}
@@ -627,7 +767,7 @@
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
entityenderpearl.save(nbttagcompound1);
- DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location());
+ DataResult<NBTBase> dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location()); // CraftBukkit - decompile error
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -653,7 +793,7 @@
nbttaglist.forEach((nbtbase1) -> {
if (nbtbase1 instanceof NBTTagCompound nbttagcompound) {
if (nbttagcompound.contains("ender_pearl_dimension")) {
- DataResult dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension"));
+ DataResult<ResourceKey<World>> dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension")); // CraftBukkit - decompile error
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -688,6 +828,29 @@
}
@@ -256,7 +328,7 @@
public void setExperiencePoints(int i) {
float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f;
@@ -533,6 +681,11 @@
@@ -746,6 +909,11 @@
@Override
public void tick() {
@@ -268,7 +340,7 @@
this.gameMode.tick();
this.wardenSpawnTracker.tick();
--this.spawnInvulnerableTime;
@@ -613,7 +766,7 @@
@@ -822,7 +990,7 @@
}
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@@ -277,7 +349,7 @@
this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -644,6 +797,12 @@
@@ -853,6 +1021,12 @@
this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience));
}
@@ -290,7 +362,7 @@
if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel));
@@ -658,6 +817,20 @@
@@ -867,6 +1041,20 @@
CriterionTriggers.LOCATION.trigger(this);
}
@@ -311,7 +383,16 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -703,7 +876,8 @@
@@ -895,7 +1083,7 @@
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
if (this.tickCount % 20 == 0) {
if (this.getHealth() < this.getMaxHealth()) {
- this.heal(1.0F);
+ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit - added regain reason of "REGEN" for filtering purposes.
}
float f = this.foodData.getSaturationLevel();
@@ -948,7 +1136,8 @@
}
private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) {
@@ -321,16 +402,16 @@
scoreaccess.set(i);
});
}
@@ -712,9 +886,47 @@
@@ -957,9 +1146,47 @@
public void die(DamageSource damagesource) {
this.gameEvent(GameEvent.ENTITY_DIE);
boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
+ // CraftBukkit start - fire PlayerDeathEvent
+ if (this.isRemoved()) {
+ return;
+ }
+ java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<>(this.getInventory().getContainerSize());
+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
+ boolean keepInventory = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
- if (flag) {
- IChatBaseComponent ichatbasecomponent = this.getCombatTracker().getDeathMessage();
@@ -342,7 +423,7 @@
+ }
+ }
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
+ this.dropFromLootTable(damagesource, this.lastHurtByPlayerTime > 0);
+ this.dropFromLootTable(this.serverLevel(), damagesource, this.lastHurtByPlayerTime > 0);
+ this.dropCustomDeathLoot(this.serverLevel(), damagesource, flag);
+
+ loot.addAll(this.drops);
@@ -371,15 +452,15 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true;
@@ -745,12 +957,18 @@
if (this.level().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
@@ -990,12 +1217,18 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied();
}
-
- if (!this.isSpectator()) {
- this.dropAllDeathLoot(this.serverLevel(), damagesource);
+ // SPIGOT-5478 must be called manually now
+ this.dropExperience(damagesource.getEntity());
+ this.dropExperience(this.serverLevel(), damagesource.getEntity());
+ // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
+ if (!event.getKeepInventory()) {
+ this.getInventory().clearContent();
@@ -394,7 +475,7 @@
EntityLiving entityliving = this.getKillCredit();
if (entityliving != null) {
@@ -785,10 +1003,12 @@
@@ -1030,10 +1263,12 @@
if (entity != this) {
super.awardKillScore(entity, i, damagesource);
this.increaseScore(i);
@@ -409,7 +490,7 @@
} else {
this.awardStat(StatisticList.MOB_KILLS);
}
@@ -806,7 +1026,8 @@
@@ -1051,7 +1286,8 @@
int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@@ -419,7 +500,7 @@
}
}
@@ -856,10 +1077,16 @@
@@ -1101,10 +1337,16 @@
}
private boolean isPvpAllowed() {
@@ -428,53 +509,53 @@
+ return this.level().pvpMode;
}
- public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a) {
- public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a) {
+ // CraftBukkit start
+ public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a, PlayerRespawnEvent.RespawnReason reason) {
+ DimensionTransition dimensionTransition;
+ public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a, PlayerRespawnEvent.RespawnReason reason) {
+ TeleportTransition teleportTransition;
+ boolean isBedSpawn = false;
+ boolean isAnchorSpawn = false;
+ // CraftBukkit end
BlockPosition blockposition = this.getRespawnPosition();
float f = this.getRespawnAngle();
boolean flag1 = this.isRespawnForced();
@@ -871,13 +1098,32 @@
@@ -1116,13 +1358,32 @@
if (optional.isPresent()) {
EntityPlayer.RespawnPosAngle entityplayer_respawnposangle = (EntityPlayer.RespawnPosAngle) optional.get();
- return new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a);
- return new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a);
+ // CraftBukkit start
+ isBedSpawn = entityplayer_respawnposangle.isBedSpawn();
+ isAnchorSpawn = entityplayer_respawnposangle.isAnchorSpawn();
+ dimensionTransition = new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a);
+ teleportTransition = new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a);
+ // CraftBukkit end
} else {
- return DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a);
+ dimensionTransition = DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit
- return TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a);
+ teleportTransition = TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a); // CraftBukkit
}
} else {
- return new DimensionTransition(this.server.overworld(), this, dimensiontransition_a);
+ dimensionTransition = new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit
- return new TeleportTransition(this.server.overworld(), this, teleporttransition_a);
+ teleportTransition = new TeleportTransition(this.server.overworld(), this, teleporttransition_a); // CraftBukkit
}
+ // CraftBukkit start
+ if (reason == null) {
+ return dimensionTransition;
+ return teleportTransition;
+ }
+
+ Player respawnPlayer = this.getBukkitEntity();
+ Location location = CraftLocation.toBukkit(dimensionTransition.pos(), dimensionTransition.newLevel().getWorld(), dimensionTransition.yRot(), dimensionTransition.xRot());
+ Location location = CraftLocation.toBukkit(teleportTransition.position(), teleportTransition.newLevel().getWorld(), teleportTransition.yRot(), teleportTransition.xRot());
+
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn, isAnchorSpawn, reason);
+ this.level().getCraftServer().getPluginManager().callEvent(respawnEvent);
+
+ location = respawnEvent.getRespawnLocation();
+
+ return new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), dimensionTransition.speed(), location.getYaw(), location.getPitch(), dimensionTransition.missingRespawnBlock(), dimensionTransition.postDimensionTransition(), dimensionTransition.cause());
+ return new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), teleportTransition.deltaMovement(), location.getYaw(), location.getPitch(), teleportTransition.missingRespawnBlock(), teleportTransition.asPassenger(), teleportTransition.relatives(), teleportTransition.postTeleportTransition(), teleportTransition.cause());
+ // CraftBukkit end
}
public static Optional<EntityPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(WorldServer worldserver, BlockPosition blockposition, float f, boolean flag, boolean flag1) {
@@ -892,11 +1138,11 @@
@@ -1137,11 +1398,11 @@
}
return optional.map((vec3d) -> {
@@ -488,7 +569,7 @@
});
} else if (!flag) {
return Optional.empty();
@@ -905,7 +1151,7 @@
@@ -1150,7 +1411,7 @@
IBlockData iblockdata1 = worldserver.getBlockState(blockposition.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@@ -497,32 +578,49 @@
}
}
@@ -923,6 +1169,7 @@
@@ -1168,6 +1429,7 @@
@Nullable
@Override
public Entity changeDimension(DimensionTransition dimensiontransition) {
public EntityPlayer teleport(TeleportTransition teleporttransition) {
+ if (this.isSleeping()) return null; // CraftBukkit - SPIGOT-3154
if (this.isRemoved()) {
return null;
} else {
@@ -932,14 +1179,21 @@
@@ -1177,18 +1439,38 @@
WorldServer worldserver = dimensiontransition.newLevel();
WorldServer worldserver = teleporttransition.newLevel();
WorldServer worldserver1 = this.serverLevel();
- ResourceKey<World> resourcekey = worldserver1.dimension();
+ // CraftBukkit start
+ ResourceKey<WorldDimension> resourcekey = worldserver1.getTypeKey();
+
+ Location enter = this.getBukkitEntity().getLocation();
+ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(absolutePosition.position(), worldserver.getWorld(), absolutePosition.yRot(), absolutePosition.xRot());
+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, teleporttransition.cause());
+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
+ Location newExit = tpEvent.getTo();
+ if (tpEvent.isCancelled() || newExit == null) {
+ return null;
+ }
+ if (!newExit.equals(exit)) {
+ worldserver = ((CraftWorld) newExit.getWorld()).getHandle();
+ teleporttransition = new TeleportTransition(worldserver, CraftLocation.toVec3D(newExit), Vec3D.ZERO, newExit.getYaw(), newExit.getPitch(), teleporttransition.missingRespawnBlock(), teleporttransition.asPassenger(), Set.of(), teleporttransition.postTeleportTransition(), teleporttransition.cause());
+ }
+ // CraftBukkit end
if (!teleporttransition.asPassenger()) {
this.stopRiding();
}
- if (worldserver.dimension() == resourcekey) {
- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot());
+ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) { // CraftBukkit
+ boolean result = this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot(), dimensiontransition.cause());
+ if (!result) {
+ return null;
+ }
- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ // CraftBukkit start
+ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) {
+ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ // CraftBukkit end
this.connection.resetPosition();
dimensiontransition.postDimensionTransition().onTransition(this);
teleporttransition.postTeleportTransition().onTransition(this);
return this;
} else {
+ // CraftBukkit start
@@ -530,31 +628,22 @@
this.isChangingDimension = true;
WorldData worlddata = worldserver.getLevelData();
@@ -950,15 +1204,40 @@
@@ -1199,17 +1481,31 @@
playerlist.sendPlayerPermissionLevel(this);
worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
this.unsetRemoved();
+ */
+ // CraftBukkit end
worldserver1.getProfiler().push("moving");
GameProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("moving");
- if (resourcekey == World.OVERWORLD && worldserver.dimension() == World.NETHER) {
+ if (worldserver != null && resourcekey == WorldDimension.OVERWORLD && worldserver.getTypeKey() == WorldDimension.NETHER) { // CraftBukkit - empty to fall through to null to event
this.enteredNetherPosition = this.position();
}
+ // CraftBukkit start
+ Location enter = this.getBukkitEntity().getLocation();
+ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(dimensiontransition.pos(), worldserver.getWorld(), dimensiontransition.yRot(), dimensiontransition.xRot());
+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, dimensiontransition.cause());
+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
+ if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
+ return null;
+ }
+ exit = tpEvent.getTo();
+ worldserver = ((CraftWorld) exit.getWorld()).getHandle();
+ // CraftBukkit end
worldserver1.getProfiler().pop();
worldserver1.getProfiler().push("placing");
gameprofilerfiller.pop();
gameprofilerfiller.push("placing");
+ // CraftBukkit start
+ this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
+ WorldData worlddata = worldserver.getLevelData();
@@ -568,12 +657,12 @@
+ this.unsetRemoved();
+ // CraftBukkit end
this.setServerLevel(worldserver);
- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot());
+ this.connection.teleport(exit); // CraftBukkit - use internal teleport without event
- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); // CraftBukkit - use internal teleport without event
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
worldserver1.getProfiler().pop();
@@ -971,21 +1250,47 @@
gameprofilerfiller.pop();
@@ -1223,11 +1519,29 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -600,6 +689,10 @@
+ }
+ // CraftBukkit end
+
@Override
public void forceSetRotation(float f, float f1) {
this.connection.send(new ClientboundPlayerRotationPacket(f, f1));
@@ -1236,13 +1550,21 @@
public void triggerDimensionChangeTriggers(WorldServer worldserver) {
ResourceKey<World> resourcekey = worldserver.dimension();
ResourceKey<World> resourcekey1 = this.level().dimension();
@@ -624,7 +717,7 @@
this.enteredNetherPosition = null;
}
@@ -1002,19 +1307,17 @@
@@ -1259,19 +1581,17 @@
this.containerMenu.broadcastChanges();
}
@@ -648,7 +741,7 @@
if (this.level().isDay()) {
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW);
} else {
@@ -1031,7 +1334,36 @@
@@ -1288,7 +1608,36 @@
}
}
@@ -686,7 +779,7 @@
this.awardStat(StatisticList.SLEEP_IN_BED);
CriterionTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -1044,9 +1376,8 @@
@@ -1301,9 +1650,8 @@
return either;
}
}
@@ -697,7 +790,7 @@
}
@Override
@@ -1073,13 +1404,31 @@
@@ -1330,13 +1678,31 @@
@Override
public void stopSleepInBed(boolean flag, boolean flag1) {
@@ -730,7 +823,7 @@
}
}
@@ -1146,8 +1495,9 @@
@@ -1403,8 +1769,9 @@
this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos(), flag));
}
@@ -741,7 +834,7 @@
}
@Override
@@ -1155,13 +1505,35 @@
@@ -1412,13 +1779,35 @@
if (itileinventory == null) {
return OptionalInt.empty();
} else {
@@ -777,7 +870,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true);
@@ -1169,9 +1541,11 @@
@@ -1426,9 +1815,11 @@
return OptionalInt.empty();
} else {
@@ -791,7 +884,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1184,15 +1558,26 @@
@@ -1441,15 +1832,26 @@
@Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@@ -820,7 +913,7 @@
this.initMenu(this.containerMenu);
}
@@ -1215,6 +1600,7 @@
@@ -1472,6 +1874,7 @@
@Override
public void closeContainer() {
@@ -828,24 +921,7 @@
this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
this.doCloseContainer();
}
@@ -1237,6 +1623,16 @@
}
this.jumping = flag;
+ // CraftBukkit start
+ if (flag1 != this.isShiftKeyDown()) {
+ PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getBukkitEntity(), flag1);
+ this.server.server.getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
this.setShiftKeyDown(flag1);
}
@@ -1270,19 +1666,19 @@
@@ -1501,19 +1904,19 @@
i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) {
this.awardStat(StatisticList.SWIM_ONE_CM, i);
@@ -868,7 +944,7 @@
}
} else if (this.onClimbable()) {
if (d1 > 0.0D) {
@@ -1293,13 +1689,13 @@
@@ -1524,13 +1927,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(StatisticList.SPRINT_ONE_CM, i);
@@ -885,7 +961,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1342,7 +1738,7 @@
@@ -1573,7 +1976,7 @@
@Override
public void awardStat(Statistic<?> statistic, int i) {
this.stats.increment(this, statistic, i);
@@ -894,7 +970,7 @@
scoreaccess.add(i);
});
}
@@ -1350,7 +1746,7 @@
@@ -1581,7 +1984,7 @@
@Override
public void resetStat(Statistic<?> statistic) {
this.stats.setValue(this, statistic, 0);
@@ -903,7 +979,19 @@
}
@Override
@@ -1398,6 +1794,7 @@
@@ -1613,9 +2016,9 @@
super.jumpFromGround();
this.awardStat(StatisticList.JUMP);
if (this.isSprinting()) {
- this.causeFoodExhaustion(0.2F);
+ this.causeFoodExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent
} else {
- this.causeFoodExhaustion(0.05F);
+ this.causeFoodExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent
}
}
@@ -1641,6 +2044,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@@ -911,16 +999,7 @@
}
@Override
@@ -1433,7 +1830,7 @@
this.gameMode.setGameModeForPlayer(entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer());
this.onUpdateAbilities();
this.getAttributes().assignBaseValues(entityplayer.getAttributes());
- this.setHealth(this.getMaxHealth());
+ // this.setHealth(this.getMaxHealth()); // CraftBukkit
if (flag) {
this.getInventory().replaceWith(entityplayer.getInventory());
this.setHealth(entityplayer.getHealth());
@@ -1443,7 +1840,7 @@
@@ -1685,7 +2089,7 @@
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
@@ -928,8 +1007,17 @@
+ // this.addEffect(new MobEffect(mobeffect)); // CraftBukkit
}
this.experienceLevel = entityplayer.experienceLevel;
@@ -1465,7 +1862,7 @@
this.getInventory().replaceWith(entityplayer.getInventory());
@@ -1696,7 +2100,7 @@
this.portalProcess = entityplayer.portalProcess;
} else {
this.getAttributes().assignBaseValues(entityplayer.getAttributes());
- this.setHealth(this.getMaxHealth());
+ // this.setHealth(this.getMaxHealth()); // CraftBukkit
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || entityplayer.isSpectator()) {
this.getInventory().replaceWith(entityplayer.getInventory());
this.experienceLevel = entityplayer.experienceLevel;
@@ -1712,7 +2116,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -938,32 +1026,25 @@
this.seenCredits = entityplayer.seenCredits;
this.enteredNetherPosition = entityplayer.enteredNetherPosition;
this.chunkTrackingView = entityplayer.chunkTrackingView;
@@ -1516,6 +1913,12 @@
@@ -1768,7 +2172,7 @@
}
@Override
public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1) {
+ // CraftBukkit start
+ return teleportTo(worldserver, d0, d1, d2, set, f, f1, TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1, TeleportCause cause) {
+ // CraftBukkit end
- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag) {
+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag, TeleportCause cause) { // CraftBukkit
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2));
worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId());
@@ -1525,9 +1928,9 @@
@@ -1780,7 +2184,7 @@
this.setCamera(this);
}
if (worldserver == this.level()) {
- this.connection.teleport(d0, d1, d2, f, f1, set);
+ this.connection.teleport(d0, d1, d2, f, f1, set, cause); // CraftBukkit
} else {
- this.teleportTo(worldserver, d0, d1, d2, f, f1);
+ this.teleportTo(worldserver, d0, d1, d2, f, f1, cause); // CraftBukkit
}
- boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag);
+ boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag, cause); // CraftBukkit
this.setYHeadRot(f);
@@ -1635,6 +2038,16 @@
if (flag1) {
this.setYHeadRot(set.contains(Relative.Y_ROT) ? this.getYHeadRot() + f : f);
@@ -1897,6 +2301,16 @@
}
public void updateOptions(ClientInformation clientinformation) {
@@ -980,16 +1061,16 @@
this.language = clientinformation.language();
this.requestedViewDistance = clientinformation.viewDistance();
this.chatVisibility = clientinformation.chatVisibility();
@@ -1718,7 +2131,7 @@
@@ -1981,7 +2395,7 @@
if (world instanceof WorldServer) {
WorldServer worldserver = (WorldServer) world;
- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot());
+ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), TeleportCause.SPECTATE); // CraftBukkit
- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false);
+ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false, TeleportCause.SPECTATE); // CraftBukkit
}
if (entity != null) {
@@ -1755,7 +2168,7 @@
@@ -2018,11 +2432,11 @@
@Nullable
public IChatBaseComponent getTabListDisplayName() {
@@ -997,33 +1078,13 @@
+ return listName; // CraftBukkit
}
public int getTabListOrder() {
- return 0;
+ return listOrder; // CraftBukkit
}
@Override
@@ -1776,14 +2189,24 @@
return this.advancements;
}
+ // CraftBukkit start
public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1) {
+ this.teleportTo(worldserver, d0, d1, d2, f, f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ // CraftBukkit end
this.setCamera(this);
this.stopRiding();
+ /* CraftBukkit start - replace with bukkit handling for multi-world
if (worldserver == this.level()) {
this.connection.teleport(d0, d1, d2, f, f1);
} else {
this.changeDimension(new DimensionTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1, DimensionTransition.DO_NOTHING));
}
+ */
+ this.getBukkitEntity().teleport(new Location(worldserver.getWorld(), d0, d1, d2, f, f1), cause);
+ // CraftBukkit end
}
@@ -1809,6 +2232,32 @@
@@ -2065,6 +2479,32 @@
}
public void setRespawnPosition(ResourceKey<World> resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) {
@@ -1056,24 +1117,48 @@
if (blockposition != null) {
boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension);
@@ -1852,7 +2301,14 @@
@@ -2107,12 +2547,38 @@
}
@Override
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
- EntityItem entityitem = super.drop(itemstack, flag, flag1);
+ // CraftBukkit start - SPIGOT-2942: Add boolean to call event
+ return drop(itemstack, flag, flag1, true);
+ }
+
+ @Override
+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) {
+ EntityItem entityitem = super.drop(itemstack, flag, flag1, callEvent);
+ // CraftBukkit end
- public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) { // CraftBukkit - SPIGOT-2942: Add boolean to call event
EntityItem entityitem = this.createItemStackToDrop(itemstack, flag, flag1);
if (entityitem == null) {
return null;
@@ -2049,10 +2505,12 @@
this.awardStat(StatisticList.ITEM_BROKEN.get(item));
} else {
+ // CraftBukkit start - fire PlayerDropItemEvent
+ if (callEvent) {
+ Player player = (Player) this.getBukkitEntity();
+ org.bukkit.entity.Item drop = (org.bukkit.entity.Item) entityitem.getBukkitEntity();
+
+ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
+ if (flag1 && (cur == null || cur.getAmount() == 0)) {
+ // The complete stack was dropped
+ player.getInventory().setItemInHand(drop.getItemStack());
+ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) {
+ // Only one item is dropped
+ cur.setAmount(cur.getAmount() + 1);
+ player.getInventory().setItemInHand(cur);
+ } else {
+ // Fallback
+ player.getInventory().addItem(drop.getItemStack());
+ }
+ return null;
+ }
+ }
+ // CraftBukkit end
+
this.level().addFreshEntity(entityitem);
ItemStack itemstack1 = entityitem.getItem();
@@ -2394,10 +2860,12 @@
return TicketType.ENDER_PEARL.timeout();
}
- public static record RespawnPosAngle(Vec3D position, float yaw) {
@@ -1088,7 +1173,7 @@
}
private static float calculateLookAtYaw(Vec3D vec3d, BlockPosition blockposition) {
@@ -2061,4 +2519,147 @@
@@ -2406,4 +2874,146 @@
return (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
}
}
@@ -1195,7 +1280,6 @@
+
+ public void reset() {
+ float exp = 0;
+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY);
+
+ if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent)
+ exp = this.experienceProgress;
@@ -1207,7 +1291,7 @@
+ this.stopUsingItem(); // CraftBukkit - SPIGOT-6682: Clear active item on reset
+ this.setRemainingFireTicks(0);
+ this.fallDistance = 0;
+ this.foodData = new FoodMetaData(this);
+ this.foodData = new FoodMetaData();
+ this.experienceLevel = this.newLevel;
+ this.totalExperience = this.newTotalExp;
+ this.experienceProgress = 0;

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/net/minecraft/server/level/EntityTrackerEntry.java
@@ -46,6 +46,12 @@
@@ -50,6 +50,12 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -13,7 +13,7 @@
public class EntityTrackerEntry {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -70,8 +76,12 @@
@@ -74,8 +80,12 @@
private boolean wasOnGround;
@Nullable
private List<DataWatcher.c<?>> trackedDataValues;
@@ -27,7 +27,7 @@
this.level = worldserver;
this.broadcast = consumer;
this.entity = entity;
@@ -90,7 +100,7 @@
@@ -94,7 +104,7 @@
List<Entity> list = this.entity.getPassengers();
if (!list.equals(this.lastPassengers)) {
@@ -36,7 +36,7 @@
removedPassengers(list, this.lastPassengers).forEach((entity) -> {
if (entity instanceof EntityPlayer entityplayer) {
entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
@@ -103,18 +113,18 @@
@@ -107,18 +117,18 @@
Entity entity = this.entity;
if (entity instanceof EntityItemFrame entityitemframe) {
@@ -59,7 +59,7 @@
worldmap.tickCarriedBy(entityplayer, itemstack);
Packet<?> packet = worldmap.getUpdatePacket(mapid, entityplayer);
@@ -232,6 +242,27 @@
@@ -248,6 +258,27 @@
++this.tickCount;
if (this.entity.hurtMarked) {
@@ -87,7 +87,7 @@
this.entity.hurtMarked = false;
this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
}
@@ -260,7 +291,10 @@
@@ -298,7 +329,10 @@
public void sendPairingData(EntityPlayer entityplayer, Consumer<Packet<PacketListenerPlayOut>> consumer) {
if (this.entity.isRemoved()) {
@@ -99,7 +99,7 @@
}
Packet<PacketListenerPlayOut> packet = this.entity.getAddEntityPacket(this);
@@ -275,6 +309,12 @@
@@ -313,6 +347,12 @@
if (this.entity instanceof EntityLiving) {
Collection<AttributeModifiable> collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes();
@@ -112,7 +112,7 @@
if (!collection.isEmpty()) {
consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection));
}
@@ -305,6 +345,7 @@
@@ -344,6 +384,7 @@
if (!list.isEmpty()) {
consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list));
}
@@ -120,7 +120,7 @@
}
if (!this.entity.getPassengers().isEmpty()) {
@@ -358,6 +399,11 @@
@@ -396,6 +437,11 @@
Set<AttributeModifiable> set = ((EntityLiving) this.entity).getAttributes().getAttributesToSync();
if (!set.isEmpty()) {

View File

@@ -52,15 +52,15 @@
}
@Nullable
@@ -134,6 +150,7 @@
if (chunk != null) {
@@ -138,6 +154,7 @@
boolean flag = this.hasChangedSections;
int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY());
+ if (i < 0 || i >= this.changedBlocksPerSection.length) return; // CraftBukkit - SPIGOT-6086, SPIGOT-6296
+ if (i < 0 || i >= this.changedBlocksPerSection.length) return false; // CraftBukkit - SPIGOT-6086, SPIGOT-6296
if (this.changedBlocksPerSection[i] == null) {
this.hasChangedSections = true;
this.changedBlocksPerSection[i] = new ShortOpenHashSet();
@@ -208,8 +225,11 @@
@@ -224,8 +241,11 @@
PacketPlayOutMultiBlockChange packetplayoutmultiblockchange = new PacketPlayOutMultiBlockChange(sectionposition, shortset, chunksection);
this.broadcast(list, packetplayoutmultiblockchange);
@@ -73,7 +73,7 @@
});
}
}
@@ -275,7 +295,7 @@
@@ -291,7 +311,7 @@
this.pendingFullStateConfirmation = completablefuture1;
completablefuture.thenAccept((chunkresult) -> {
chunkresult.ifSuccess((chunk) -> {
@@ -82,7 +82,7 @@
});
});
}
@@ -285,6 +305,38 @@
@@ -301,6 +321,38 @@
playerchunkmap.onFullChunkStatusChange(this.pos, fullchunkstatus);
}
@@ -102,7 +102,7 @@
+ // 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.setUnsaved(true);
+ chunk.markUnsaved();
+ chunk.unloadCallback();
+ });
+ }
@@ -121,7 +121,7 @@
protected void updateFutures(PlayerChunkMap playerchunkmap, Executor executor) {
FullChunkStatus fullchunkstatus = ChunkLevel.fullStatus(this.oldTicketLevel);
FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel);
@@ -341,6 +393,26 @@
@@ -357,6 +409,26 @@
this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel);
this.oldTicketLevel = this.ticketLevel;

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
@@ -102,6 +102,10 @@
@@ -104,6 +104,10 @@
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.slf4j.Logger;
@@ -11,7 +11,7 @@
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, GeneratingChunkMap {
private static final ChunkResult<List<IChunkAccess>> UNLOADED_CHUNK_LIST_RESULT = ChunkResult.error("Unloaded chunks found in range");
@@ -145,6 +149,27 @@
@@ -149,6 +153,27 @@
public int serverViewDistance;
private final WorldGenContext worldGenContext;
@@ -39,7 +39,7 @@
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, StructureTemplateManager structuretemplatemanager, Executor executor, IAsyncTaskHandler<Runnable> iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
super(new RegionStorageInfo(convertable_conversionsession.getLevelId(), worldserver.dimension(), "chunk"), convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
this.visibleChunkMap = this.updatingChunkMap.clone();
@@ -164,7 +189,13 @@
@@ -170,7 +195,13 @@
IRegistryCustom iregistrycustom = worldserver.registryAccess();
long j = worldserver.getSeed();
@@ -54,7 +54,7 @@
this.randomState = RandomState.create((GeneratorSettingBase) chunkgeneratorabstract.generatorSettings().value(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
} else {
this.randomState = RandomState.create(GeneratorSettingBase.dummy(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
@@ -318,7 +349,7 @@
@@ -325,7 +356,7 @@
throw this.debugFuturesAndCreateReportedException(new IllegalStateException("At least one of the chunk futures were null"), "n/a");
}
@@ -63,7 +63,7 @@
if (ichunkaccess == null) {
return PlayerChunkMap.UNLOADED_CHUNK_LIST_RESULT;
@@ -937,7 +968,8 @@
@@ -977,7 +1008,8 @@
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
@@ -73,7 +73,7 @@
return chunk.getBlockEntities().size();
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
return chunk.getBlockTicks().count();
@@ -950,7 +982,7 @@
@@ -990,7 +1022,7 @@
private static String printFuture(CompletableFuture<ChunkResult<Chunk>> completablefuture) {
try {
@@ -82,13 +82,13 @@
return chunkresult != null ? (chunkresult.isSuccess() ? "done" : "unloaded") : "not completed";
} catch (CompletionException completionexception) {
@@ -962,12 +994,14 @@
@@ -1002,12 +1034,14 @@
private CompletableFuture<Optional<NBTTagCompound>> readChunk(ChunkCoordIntPair chunkcoordintpair) {
return this.read(chunkcoordintpair).thenApplyAsync((optional) -> {
- return optional.map(this::upgradeChunkTag);
+ return optional.map((nbttagcompound) -> upgradeChunkTag(nbttagcompound, chunkcoordintpair)); // CraftBukkit
}, SystemUtils.backgroundExecutor());
}, SystemUtils.backgroundExecutor().forName("upgradeChunk"));
}
- private NBTTagCompound upgradeChunkTag(NBTTagCompound nbttagcompound) {
@@ -99,8 +99,8 @@
+ // CraftBukkit end
}
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
@@ -1370,7 +1404,7 @@
void forEachSpawnCandidateChunk(Consumer<PlayerChunk> consumer) {
@@ -1424,7 +1458,7 @@
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
public EntityTracker(final Entity entity, final int i, final int j, final boolean flag) {
@@ -109,7 +109,7 @@
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.of((EntityAccess) entity);
@@ -1430,6 +1464,11 @@
@@ -1484,6 +1518,11 @@
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer) && PlayerChunkMap.this.isChunkTracked(entityplayer, this.entity.chunkPosition().x, this.entity.chunkPosition().z);

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerInteractManager.java
+++ b/net/minecraft/server/level/PlayerInteractManager.java
@@ -28,6 +28,27 @@
@@ -26,6 +26,27 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -28,7 +28,7 @@
public class PlayerInteractManager {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -58,9 +79,16 @@
@@ -56,9 +77,16 @@
if (enumgamemode == this.gameModeForPlayer) {
return false;
} else {
@@ -46,7 +46,7 @@
this.level.updateSleepingPlayerList();
if (enumgamemode == EnumGamemode.CREATIVE) {
this.player.resetCurrentImpulseContext();
@@ -94,7 +122,7 @@
@@ -92,7 +120,7 @@
}
public void tick() {
@@ -55,7 +55,7 @@
IBlockData iblockdata;
if (this.hasDelayedDestroy) {
@@ -148,11 +176,33 @@
@@ -146,11 +174,33 @@
if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) {
if (!this.level.mayInteract(this.player, blockposition)) {
@@ -89,7 +89,7 @@
if (this.isCreative()) {
this.destroyAndAck(blockposition, j, "creative destroy");
return;
@@ -168,7 +218,19 @@
@@ -166,7 +216,19 @@
float f = 1.0F;
iblockdata = this.level.getBlockState(blockposition);
@@ -110,7 +110,7 @@
EnchantmentManager.onHitBlock(this.level, this.player.getMainHandItem(), this.player, this.player, EnumItemSlot.MAINHAND, Vec3D.atCenterOf(blockposition), iblockdata, (item) -> {
this.player.onEquippedItemBroken(item, EnumItemSlot.MAINHAND);
});
@@ -176,6 +238,26 @@
@@ -174,6 +236,26 @@
f = iblockdata.getDestroyProgress(this.player, this.player.level(), blockposition);
}
@@ -137,7 +137,7 @@
if (!iblockdata.isAir() && f >= 1.0F) {
this.destroyAndAck(blockposition, j, "insta mine");
} else {
@@ -220,13 +302,15 @@
@@ -218,13 +300,15 @@
} else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) {
this.isDestroyingBlock = false;
if (!Objects.equals(this.destroyPos, blockposition)) {
@@ -154,7 +154,7 @@
}
}
@@ -244,10 +328,65 @@
@@ -242,10 +326,65 @@
public boolean destroyBlock(BlockPosition blockposition) {
IBlockData iblockdata = this.level.getBlockState(blockposition);
@@ -221,7 +221,7 @@
TileEntity tileentity = this.level.getBlockEntity(blockposition);
Block block = iblockdata.getBlock();
@@ -257,6 +396,10 @@
@@ -255,6 +394,10 @@
} else if (this.player.blockActionRestricted(this.level, blockposition, this.gameModeForPlayer)) {
return false;
} else {
@@ -232,7 +232,7 @@
IBlockData iblockdata1 = block.playerWillDestroy(this.level, blockposition, iblockdata, this.player);
boolean flag = this.level.removeBlock(blockposition, false);
@@ -265,19 +408,32 @@
@@ -263,19 +406,32 @@
}
if (this.isCreative()) {
@@ -268,7 +268,7 @@
}
}
}
@@ -315,14 +471,53 @@
@@ -321,14 +477,53 @@
}
}
@@ -290,7 +290,7 @@
+ cancelledBlock = !(itileinventory instanceof ITileInventory);
+ }
+
+ if (entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
+ if (entityplayer.getCooldowns().isOnCooldown(itemstack)) {
+ cancelledBlock = true;
+ }
+
@@ -322,11 +322,11 @@
if (itileinventory != null) {
entityplayer.openMenu(itileinventory);
@@ -353,7 +548,7 @@
@@ -359,7 +554,7 @@
}
}
- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack)) {
+ if (!itemstack.isEmpty() && !interactResult) { // add !interactResult SPIGOT-764
ItemActionContext itemactioncontext = new ItemActionContext(entityplayer, enumhand, movingobjectpositionblock);

View File

@@ -1,7 +1,7 @@
--- a/net/minecraft/server/level/TicketType.java
+++ b/net/minecraft/server/level/TicketType.java
@@ -22,6 +22,8 @@
public static final TicketType<BlockPosition> PORTAL = create("portal", BaseBlockPosition::compareTo, 300);
@@ -23,6 +23,8 @@
public static final TicketType<ChunkCoordIntPair> ENDER_PEARL = create("ender_pearl", Comparator.comparingLong(ChunkCoordIntPair::toLong), 40);
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

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
@@ -171,6 +171,23 @@
@@ -173,6 +173,23 @@
import net.minecraft.world.ticks.TickListServer;
import org.slf4j.Logger;
@@ -21,31 +21,28 @@
+import org.bukkit.event.world.TimeSkipEvent;
+// CraftBukkit end
+
public class WorldServer extends World implements GeneratorAccessSeed {
public class WorldServer extends World implements ServerEntityGetter, GeneratorAccessSeed {
public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0);
@@ -184,7 +201,7 @@
final List<EntityPlayer> players;
@@ -186,7 +203,7 @@
final List<EntityPlayer> players = Lists.newArrayList();
private final ChunkProviderServer chunkSource;
private final MinecraftServer server;
- public final IWorldDataServer serverLevelData;
+ public final WorldDataServer serverLevelData; // CraftBukkit - type
private int lastSpawnChunkRadius;
final EntityTickList entityTickList;
final EntityTickList entityTickList = new EntityTickList();
public final PersistentEntitySectionManager<Entity> entityManager;
@@ -211,12 +228,30 @@
@@ -213,13 +230,47 @@
private final boolean tickTime;
private final RandomSequences randomSequences;
- public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey<World> resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List<MobSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences) {
- IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess();
- Holder holder = worlddimension.type();
- super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
+ // CraftBukkit start
+ public final Convertable.ConversionSession convertable;
+ public final UUID uuid;
- Objects.requireNonNull(minecraftserver);
- super(iworlddataserver, resourcekey, iregistrycustom_dimension, holder, minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
+
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false);
+ }
@@ -57,19 +54,13 @@
+
+ // Add env and gen to constructor, IWorldDataServer -> WorldDataServer
+ public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, WorldDataServer iworlddataserver, ResourceKey<World> resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List<MobSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
+ // IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess(); // CraftBukkit - decompile error
+ // Holder holder = worlddimension.type(); // CraftBukkit - decompile error
+
+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error
+ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env);
+ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env);
+ this.pvpMode = minecraftserver.isPvpAllowed();
+ convertable = convertable_conversionsession;
+ uuid = WorldUUID.getUUID(convertable_conversionsession.levelDirectory.path().toFile());
+ // CraftBukkit end
this.players = Lists.newArrayList();
this.entityTickList = new EntityTickList();
this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier());
@@ -231,6 +266,22 @@
this.tickTime = flag1;
this.server = minecraftserver;
this.customSpawners = list;
this.serverLevelData = iworlddataserver;
ChunkGenerator chunkgenerator = worlddimension.generator();
@@ -77,7 +68,7 @@
+ serverLevelData.setWorld(this);
+
+ if (biomeProvider != null) {
+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().registryOrThrow(Registries.BIOME));
+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().lookupOrThrow(Registries.BIOME));
+ if (chunkgenerator instanceof ChunkGeneratorAbstract cga) {
+ chunkgenerator = new ChunkGeneratorAbstract(worldChunkManager, cga.settings);
+ } else if (chunkgenerator instanceof ChunkProviderFlat cpf) {
@@ -92,7 +83,7 @@
boolean flag2 = minecraftserver.forceSynchronousWrites();
DataFixer datafixer = minecraftserver.getFixerUpper();
EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(new SimpleRegionStorage(new RegionStorageInfo(convertable_conversionsession.getLevelId(), resourcekey, "entities"), convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, DataFixTypes.ENTITY_CHUNK), this, minecraftserver);
@@ -258,9 +309,9 @@
@@ -247,9 +298,9 @@
long l = minecraftserver.getWorldData().worldGenOptions().seed();
this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this.chunkSource.randomState(), this, chunkgenerator.getBiomeSource(), l, datafixer);
@@ -105,7 +96,7 @@
} else {
this.dragonFight = null;
}
@@ -270,6 +321,7 @@
@@ -259,6 +310,7 @@
this.randomSequences = (RandomSequences) Objects.requireNonNullElseGet(randomsequences, () -> {
return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences");
});
@@ -113,7 +104,7 @@
}
/** @deprecated */
@@ -314,12 +366,20 @@
@@ -304,12 +356,20 @@
long j;
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
@@ -137,7 +128,7 @@
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
}
@@ -354,7 +414,7 @@
@@ -344,7 +404,7 @@
this.handlingTick = false;
gameprofilerfiller.pop();
@@ -146,16 +137,7 @@
if (flag1) {
this.resetEmptyTime();
@@ -370,7 +430,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 if (!tickratemanager.isEntityFrozen(entity)) {
gameprofilerfiller.push("checkDespawn");
@@ -442,7 +502,7 @@
@@ -428,7 +488,7 @@
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
@@ -164,7 +146,7 @@
entityplayer.stopSleepInBed(false, false);
});
}
@@ -469,7 +529,7 @@
@@ -455,7 +515,7 @@
entityhorseskeleton.setTrap(true);
entityhorseskeleton.setAge(0);
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@@ -173,7 +155,7 @@
}
}
@@ -478,7 +538,7 @@
@@ -464,7 +524,7 @@
if (entitylightning != null) {
entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition));
entitylightning.setVisualOnly(flag1);
@@ -182,7 +164,7 @@
}
}
}
@@ -534,7 +594,7 @@
@@ -520,7 +580,7 @@
BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition1).value();
if (biomebase.shouldFreeze(this, blockposition2)) {
@@ -191,7 +173,7 @@
}
if (this.isRaining()) {
@@ -550,10 +610,10 @@
@@ -536,10 +596,10 @@
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSnow.LAYERS, j + 1);
Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1);
@@ -204,7 +186,7 @@
}
}
@@ -714,6 +774,7 @@
@@ -700,6 +760,7 @@
this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F);
}
@@ -212,7 +194,7 @@
if (this.oRainLevel != this.rainLevel) {
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension());
}
@@ -732,15 +793,48 @@
@@ -718,15 +779,48 @@
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel));
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, this.thunderLevel));
}
@@ -263,15 +245,15 @@
}
public void resetEmptyTime() {
@@ -775,6 +869,7 @@
@@ -762,6 +856,7 @@
});
gameprofilerfiller.incrementCounter("tickNonPassenger");
entity.tick();
+ entity.postTick(); // CraftBukkit
this.getProfiler().pop();
gameprofilerfiller.pop();
Iterator iterator = entity.getPassengers().iterator();
@@ -798,6 +893,7 @@
@@ -785,6 +880,7 @@
});
gameprofilerfiller.incrementCounter("tickPassenger");
entity1.rideTick();
@@ -279,7 +261,7 @@
gameprofilerfiller.pop();
Iterator iterator = entity1.getPassengers().iterator();
@@ -822,6 +918,7 @@
@@ -809,6 +905,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkSource();
if (!flag1) {
@@ -287,7 +269,7 @@
if (iprogressupdate != null) {
iprogressupdate.progressStartNoAbort(IChatBaseComponent.translatable("menu.savingLevel"));
}
@@ -839,11 +936,19 @@
@@ -826,11 +923,19 @@
}
}
@@ -301,14 +283,14 @@
+ // CraftBukkit end
}
private void saveLevelData() {
private void saveLevelData(boolean flag) {
if (this.dragonFight != null) {
- this.server.getWorldData().setEndDragonFightData(this.dragonFight.saveData());
+ this.serverLevelData.setEndDragonFightData(this.dragonFight.saveData()); // CraftBukkit
}
this.getChunkSource().getDataStorage().save();
@@ -908,18 +1013,40 @@
WorldPersistentData worldpersistentdata = this.getChunkSource().getDataStorage();
@@ -902,18 +1007,40 @@
@Override
public boolean addFreshEntity(Entity entity) {
@@ -352,7 +334,7 @@
}
}
@@ -944,24 +1071,37 @@
@@ -938,24 +1065,37 @@
this.entityManager.addNewEntity(entityplayer);
}
@@ -394,19 +376,19 @@
return true;
}
}
@@ -972,13 +1112,35 @@
@@ -966,13 +1106,35 @@
}
public void removePlayerImmediately(EntityPlayer entityplayer, Entity.RemovalReason entity_removalreason) {
- entityplayer.remove(entity_removalreason);
+ entityplayer.remove(entity_removalreason, null); // CraftBukkit - add Bukkit remove cause
}
+ }
+
+ // CraftBukkit start
+ public boolean strikeLightning(Entity entitylightning) {
+ return this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN);
+ }
+
}
+ public boolean strikeLightning(Entity entitylightning, LightningStrikeEvent.Cause cause) {
+ LightningStrikeEvent lightning = CraftEventFactory.callLightningStrikeEvent((org.bukkit.entity.LightningStrike) entitylightning.getBukkitEntity(), cause);
+
@@ -431,7 +413,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -987,6 +1149,12 @@
@@ -981,6 +1143,12 @@
double d1 = (double) blockposition.getY() - entityplayer.getY();
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
@@ -444,7 +426,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
@@ -1047,7 +1215,18 @@
@@ -1059,7 +1227,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@@ -464,19 +446,52 @@
NavigationAbstract navigationabstract = entityinsentient.getNavigation();
if (navigationabstract.shouldRecomputePath(blockposition)) {
@@ -1109,6 +1288,11 @@
@@ -1125,6 +1304,12 @@
@Override
public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder<SoundEffect> holder) {
Explosion explosion = this.explode(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, false, particleparam, particleparam1, holder);
public void explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder<SoundEffect> holder) {
+ // CraftBukkit start
+ if (explosion.wasCanceled) {
+ return explosion;
+ this.explode0(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, particleparam, particleparam1, holder);
+ }
+
+ public ServerExplosion explode0(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder<SoundEffect> holder) {
+ // CraftBukkit end
Explosion.Effect explosion_effect;
switch (world_a) {
@@ -1143,6 +1328,11 @@
case TRIGGER:
explosion_effect = Explosion.Effect.TRIGGER_BLOCK;
break;
+ // CraftBukkit start - handle custom explosion type
+ case STANDARD:
+ explosion_effect = Explosion.Effect.DESTROY;
+ break;
+ // CraftBukkit end
default:
throw new MatchException((String) null, (Throwable) null);
}
@@ -1152,6 +1342,11 @@
ServerExplosion serverexplosion = new ServerExplosion(this, entity, damagesource, explosiondamagecalculator, vec3d, f, flag, explosion_effect1);
serverexplosion.explode();
+ // CraftBukkit start
+ if (serverexplosion.wasCanceled) {
+ return serverexplosion;
+ }
+ // CraftBukkit end
ParticleParam particleparam2 = serverexplosion.isSmall() ? particleparam : particleparam1;
Iterator iterator = this.players.iterator();
if (!explosion.interactsWithBlocks()) {
explosion.clearToBlow();
@@ -1181,13 +1365,20 @@
@@ -1165,6 +1360,7 @@
}
}
+ return serverexplosion; // CraftBukkit
}
private Explosion.Effect getDestroyType(GameRules.GameRuleKey<GameRules.GameRuleBoolean> gamerules_gamerulekey) {
@@ -1225,13 +1421,20 @@
}
public <T extends ParticleParam> int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
@@ -499,7 +514,7 @@
++j;
}
}
@@ -1238,7 +1429,7 @@
@@ -1282,7 +1485,7 @@
@Nullable
public BlockPosition findNearestMapStructure(TagKey<Structure> tagkey, BlockPosition blockposition, int i, boolean flag) {
@@ -507,8 +522,8 @@
+ if (!this.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit
return null;
} else {
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().registryOrThrow(Registries.STRUCTURE).getTag(tagkey);
@@ -1280,11 +1471,22 @@
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(tagkey);
@@ -1324,11 +1527,22 @@
@Nullable
@Override
public WorldMap getMapData(MapId mapid) {
@@ -532,7 +547,7 @@
this.getServer().overworld().getDataStorage().set(mapid.key(), worldmap);
}
@@ -1595,6 +1797,11 @@
@@ -1639,6 +1853,11 @@
@Override
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
@@ -544,7 +559,7 @@
this.updateNeighborsAt(blockposition, block);
}
@@ -1614,12 +1821,12 @@
@@ -1658,12 +1877,12 @@
}
public boolean isFlat() {
@@ -559,7 +574,7 @@
}
@Nullable
@@ -1642,7 +1849,7 @@
@@ -1686,7 +1905,7 @@
private static <T> String getTypeCount(Iterable<T> iterable, Function<T, String> function) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
@@ -568,7 +583,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1651,7 +1858,7 @@
@@ -1695,7 +1914,7 @@
object2intopenhashmap.addTo(s, 1);
}
@@ -577,7 +592,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1796,6 +2003,8 @@
@@ -1854,6 +2073,8 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@@ -586,7 +601,7 @@
}
public void onTrackingEnd(Entity entity) {
@@ -1827,6 +2036,14 @@
@@ -1885,6 +2106,14 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/PlayerConnection.java
+++ b/net/minecraft/server/network/PlayerConnection.java
@@ -191,6 +191,67 @@
@@ -196,6 +196,69 @@
import net.minecraft.world.phys.shapes.VoxelShapes;
import org.slf4j.Logger;
@@ -13,7 +13,7 @@
+import net.minecraft.network.chat.OutgoingChatMessage;
+import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity;
+import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
+import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
+import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
+import net.minecraft.world.entity.EntityInsentient;
+import net.minecraft.world.entity.animal.Bucketable;
+import net.minecraft.world.entity.EntityLiving;
@@ -30,7 +30,9 @@
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftItemType;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.util.CraftChatMessage;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.craftbukkit.util.Waitable;
@@ -68,18 +70,7 @@
public class PlayerConnection extends ServerCommonPacketListenerImpl implements PacketListenerPlayIn, ServerPlayerConnection, TickablePacketListener {
static final Logger LOGGER = LogUtils.getLogger();
@@ -204,7 +265,9 @@
public final PlayerChunkSender chunkSender;
private int tickCount;
private int ackBlockChangesUpTo = -1;
- private int chatSpamTickCount;
+ // CraftBukkit start - multithreaded fields
+ private final AtomicInteger chatSpamTickCount = new AtomicInteger();
+ // CraftBukkit end
private int dropSpamTickCount;
private double firstGoodX;
private double firstGoodY;
@@ -239,7 +302,7 @@
@@ -245,7 +308,7 @@
private boolean waitingForSwitchToConfig;
public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) {
@@ -88,7 +79,7 @@
this.chunkSender = new PlayerChunkSender(networkmanager.isMemoryConnection());
this.player = entityplayer;
entityplayer.connection = this;
@@ -248,9 +311,25 @@
@@ -254,9 +317,25 @@
Objects.requireNonNull(minecraftserver);
this.signedMessageDecoder = SignedMessageChain.b.unsigned(uuid, minecraftserver::enforceSecureProfile);
@@ -115,29 +106,15 @@
@Override
public void tick() {
if (this.ackBlockChangesUpTo > -1) {
@@ -302,15 +381,21 @@
}
this.keepConnectionAlive();
+ // CraftBukkit start
+ for (int spam; (spam = this.chatSpamTickCount.get()) > 0 && !chatSpamTickCount.compareAndSet(spam, spam - 1); ) ;
+ /* Use thread-safe field access instead
if (this.chatSpamTickCount > 0) {
--this.chatSpamTickCount;
}
+ */
+ // CraftBukkit end
if (this.dropSpamTickCount > 0) {
--this.dropSpamTickCount;
}
@@ -311,6 +390,7 @@
this.chatSpamThrottler.tick();
this.dropSpamThrottler.tick();
if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && SystemUtils.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) {
+ this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.idling"));
}
@@ -399,6 +484,13 @@
@@ -399,6 +479,13 @@
if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) {
WorldServer worldserver = this.player.serverLevel();
@@ -151,7 +128,7 @@
double d0 = entity.getX();
double d1 = entity.getY();
double d2 = entity.getZ();
@@ -413,7 +505,33 @@
@@ -413,7 +500,33 @@
double d9 = entity.getDeltaMovement().lengthSqr();
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@@ -186,7 +163,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
this.send(new PacketPlayOutVehicleMove(entity));
return;
@@ -453,14 +571,76 @@
@@ -453,14 +566,76 @@
}
entity.absMoveTo(d3, d4, d5, f, f1);
@@ -261,9 +238,9 @@
+ // CraftBukkit end
+
this.player.serverLevel().getChunkSource().move(this.player);
entity.recordMovementThroughBlocks(new Vec3D(d0, d1, d2), entity.position());
Vec3D vec3d = new Vec3D(entity.getX() - d0, entity.getY() - d1, entity.getZ() - d2);
@@ -497,6 +677,7 @@
@@ -498,6 +673,7 @@
}
this.awaitingPositionFromClient = null;
@@ -271,16 +248,7 @@
}
}
@@ -504,7 +685,7 @@
@Override
public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.serverLevel());
- Optional optional = this.server.getRecipeManager().byKey(packetplayinrecipedisplayed.getRecipe());
+ Optional<? extends RecipeHolder<?>> optional = this.server.getRecipeManager().byKey(packetplayinrecipedisplayed.getRecipe()); // CraftBukkit - decompile error
RecipeBookServer recipebookserver = this.player.getRecipeBook();
Objects.requireNonNull(recipebookserver);
@@ -514,6 +695,7 @@
@@ -521,6 +697,7 @@
@Override
public void handleRecipeBookChangeSettingsPacket(PacketPlayInRecipeSettings packetplayinrecipesettings) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipesettings, this, this.player.serverLevel());
@@ -288,12 +256,12 @@
this.player.getRecipeBook().setBookSetting(packetplayinrecipesettings.getBookType(), packetplayinrecipesettings.isOpen(), packetplayinrecipesettings.isFiltering());
}
@@ -534,6 +716,12 @@
@@ -541,6 +718,12 @@
@Override
public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.serverLevel());
+ // CraftBukkit start
+ if (chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
+ if (!this.chatSpamThrottler.isIncrementAndUnderThreshold(1, 500) && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ this.disconnect(IChatBaseComponent.translatable("disconnect.spam"));
+ return;
+ }
@@ -301,7 +269,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand());
if (stringreader.canRead() && stringreader.peek() == '/') {
@@ -543,6 +731,7 @@
@@ -550,6 +733,7 @@
ParseResults<CommandListenerWrapper> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());
this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
@@ -309,7 +277,7 @@
Suggestions suggestions1 = suggestions.getList().size() <= 1000 ? suggestions : new Suggestions(suggestions.getRange(), suggestions.getList().subList(0, 1000));
this.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions1));
@@ -787,6 +976,13 @@
@@ -796,6 +980,13 @@
Container container = this.player.containerMenu;
if (container instanceof ContainerMerchant containermerchant) {
@@ -323,7 +291,7 @@
if (!containermerchant.stillValid(this.player)) {
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant);
return;
@@ -800,6 +996,13 @@
@@ -809,6 +1000,13 @@
@Override
public void handleEditBook(PacketPlayInBEdit packetplayinbedit) {
@@ -337,16 +305,7 @@
int i = packetplayinbedit.slot();
if (PlayerInventory.isHotbarSlot(i) || i == 40) {
@@ -808,7 +1011,7 @@
Objects.requireNonNull(list);
optional.ifPresent(list::add);
- Stream stream = packetplayinbedit.pages().stream().limit(100L);
+ Stream<String> stream = packetplayinbedit.pages().stream().limit(100L); // CraftBukkit - decompile error
Objects.requireNonNull(list);
stream.forEach(list::add);
@@ -823,12 +1026,16 @@
@@ -829,12 +1027,16 @@
}
private void updateBookContents(List<FilteredText> list, int i) {
@@ -356,7 +315,7 @@
+ ItemStack itemstack = handItem.copy();
+ // CraftBukkit end
if (itemstack.is(Items.WRITABLE_BOOK)) {
if (itemstack.has(DataComponents.WRITABLE_BOOK_CONTENT)) {
List<Filterable<String>> list1 = list.stream().map(this::filterableFromOutgoing).toList();
itemstack.set(DataComponents.WRITABLE_BOOK_CONTENT, new WritableBookContent(list1));
@@ -364,7 +323,7 @@
}
}
@@ -839,12 +1046,13 @@
@@ -845,12 +1047,13 @@
ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK);
itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT);
@@ -380,7 +339,7 @@
}
}
@@ -906,7 +1114,7 @@
@@ -912,7 +1115,7 @@
} else {
WorldServer worldserver = this.player.serverLevel();
@@ -389,7 +348,7 @@
if (this.tickCount == 0) {
this.resetPosition();
}
@@ -921,7 +1129,15 @@
@@ -927,7 +1130,15 @@
if (this.player.isPassenger()) {
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
this.player.serverLevel().getChunkSource().move(this.player);
@@ -405,7 +364,7 @@
double d3 = this.player.getX();
double d4 = this.player.getY();
double d5 = this.player.getZ();
@@ -943,15 +1159,33 @@
@@ -949,15 +1160,33 @@
++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@@ -432,16 +391,16 @@
+ speed = player.getAbilities().walkingSpeed * 10f;
+ }
+
if (!this.player.isChangingDimension() && (!this.player.level().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) || !flag)) {
if (this.shouldCheckPlayerMovement(flag)) {
float f2 = flag ? 300.0F : 100.0F;
- if (d10 - d9 > (double) (f2 * (float) i) && !this.isSingleplayerOwner()) {
+ if (d10 - d9 > Math.max(f2, Math.pow((double) (10.0F * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
- if (d10 - d9 > (double) (f2 * (float) i)) {
+ if (d10 - d9 > Math.max(f2, Math.pow((double) (10.0F * (float) i * speed), 2))) {
+ // CraftBukkit end
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8});
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
return;
@@ -973,6 +1207,7 @@
@@ -979,6 +1208,7 @@
boolean flag2 = this.player.verticalCollisionBelow;
this.player.move(EnumMoveType.PLAYER, new Vec3D(d6, d7, d8));
@@ -449,12 +408,12 @@
double d11 = d7;
d6 = d0 - this.player.getX();
@@ -991,9 +1226,75 @@
@@ -997,9 +1227,75 @@
}
if (!this.player.noPhysics && !this.player.isSleeping() && (flag3 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2))) {
- this.teleport(d3, d4, d5, f, f1);
+ this.internalTeleport(d3, d4, d5, f, f1, Collections.emptySet()); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet.
+ this.internalTeleport(d3, d4, d5, f, f1); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet.
this.player.doCheckFallDamage(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5, packetplayinflying.isOnGround());
} else {
+ // CraftBukkit start - fire PlayerMoveEvent
@@ -526,7 +485,7 @@
this.player.absMoveTo(d0, d1, d2, f, f1);
boolean flag4 = this.player.isAutoSpinAttack();
@@ -1030,6 +1331,7 @@
@@ -1049,6 +1345,7 @@
this.awaitingTeleportTime = this.tickCount;
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
}
@@ -534,38 +493,33 @@
return true;
} else {
@@ -1057,11 +1359,68 @@
return true;
@@ -1077,10 +1374,62 @@
}
+ // CraftBukkit start - Delegate to teleport(Location)
public void teleport(double d0, double d1, double d2, float f, float f1) {
- this.teleport(d0, d1, d2, f, f1, Collections.emptySet());
- this.teleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet());
+ // CraftBukkit start - Delegate to teleport(Location)
+ this.teleport(d0, d1, d2, f, f1, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleport(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) {
+ return this.teleport(d0, d1, d2, f, f1, Collections.emptySet(), cause);
+ return this.teleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet(), cause);
+ // CraftBukkit end
}
public void teleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set) {
+ this.teleport(d0, d1, d2, f, f1, set, PlayerTeleportEvent.TeleportCause.UNKNOWN);
public void teleport(PositionMoveRotation positionmoverotation, Set<Relative> set) {
+ // CraftBukkit start
+ this.teleport(positionmoverotation, set, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set, PlayerTeleportEvent.TeleportCause cause) { // CraftBukkit - Return event status
+ public boolean teleport(PositionMoveRotation positionmoverotation, Set<Relative> set, PlayerTeleportEvent.TeleportCause cause) { // CraftBukkit - Return event status
+ Player player = this.getCraftPlayer();
+ Location from = player.getLocation();
+
+ double x = d0;
+ double y = d1;
+ double z = d2;
+ float yaw = f;
+ float pitch = f1;
+
+ Location to = new Location(this.getCraftPlayer().getWorld(), x, y, z, yaw, pitch);
+ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this.player), positionmoverotation, set);
+ Location to = CraftLocation.toBukkit(absolutePosition.position(), this.getCraftPlayer().getWorld(), absolutePosition.yRot(), absolutePosition.xRot());
+ // SPIGOT-5171: Triggered on join
+ if (from.equals(to)) {
+ this.internalTeleport(d0, d1, d2, f, f1, set);
+ this.internalTeleport(positionmoverotation, set);
+ return true; // CraftBukkit - Return event status
+ }
+
@@ -575,51 +529,48 @@
+ if (event.isCancelled() || !to.equals(event.getTo())) {
+ set = Collections.emptySet(); // Can't relative teleport
+ to = event.isCancelled() ? event.getFrom() : event.getTo();
+ d0 = to.getX();
+ d1 = to.getY();
+ d2 = to.getZ();
+ f = to.getYaw();
+ f1 = to.getPitch();
+ positionmoverotation = new PositionMoveRotation(CraftLocation.toVec3D(to), Vec3D.ZERO, to.getYaw(), to.getPitch());
+ }
+
+ this.internalTeleport(d0, d1, d2, f, f1, set);
+ this.internalTeleport(positionmoverotation, set);
+ return !event.isCancelled(); // CraftBukkit - Return event status
+ }
+
+ public void teleport(Location dest) {
+ internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet());
+ this.internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch());
+ }
+
+ private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set) {
+ // CraftBukkit start
+ if (Float.isNaN(f)) {
+ f = 0;
+ private void internalTeleport(double d0, double d1, double d2, float f, float f1) {
+ this.internalTeleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet());
+ }
+
+ public void internalTeleport(PositionMoveRotation positionmoverotation, Set<Relative> set) {
+ if (Float.isNaN(positionmoverotation.yRot())) {
+ positionmoverotation = new PositionMoveRotation(positionmoverotation.position(), positionmoverotation.deltaMovement(), 0, positionmoverotation.xRot());
+ }
+ if (Float.isNaN(f1)) {
+ f1 = 0;
+ if (Float.isNaN(positionmoverotation.xRot())) {
+ positionmoverotation = new PositionMoveRotation(positionmoverotation.position(), positionmoverotation.deltaMovement(), positionmoverotation.yRot(), 0);
+ }
+
+ this.justTeleported = true;
+ // CraftBukkit end
double d3 = set.contains(RelativeMovement.X) ? this.player.getX() : 0.0D;
double d4 = set.contains(RelativeMovement.Y) ? this.player.getY() : 0.0D;
double d5 = set.contains(RelativeMovement.Z) ? this.player.getZ() : 0.0D;
@@ -1073,6 +1432,14 @@
this.awaitingTeleportTime = this.tickCount;
if (++this.awaitingTeleport == Integer.MAX_VALUE) {
this.awaitingTeleport = 0;
}
@@ -1088,12 +1437,20 @@
this.player.teleportSetPosition(positionmoverotation, set);
this.awaitingPositionFromClient = this.player.position();
+ // CraftBukkit start - update last location
+ this.lastPosX = this.awaitingPositionFromClient.x;
+ this.lastPosY = this.awaitingPositionFromClient.y;
+ this.lastPosZ = this.awaitingPositionFromClient.z;
+ this.lastYaw = f;
+ this.lastPitch = f1;
+ this.lastYaw = this.player.getYRot();
+ this.lastPitch = this.player.getXRot();
+ // CraftBukkit end
+
this.awaitingTeleportTime = this.tickCount;
this.player.absMoveTo(d0, d1, d2, f, f1);
this.player.connection.send(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport));
@@ -1081,6 +1448,7 @@
this.player.connection.send(PacketPlayOutPosition.of(this.awaitingTeleport, positionmoverotation, set));
}
@Override
public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.serverLevel());
@@ -627,7 +578,7 @@
BlockPosition blockposition = packetplayinblockdig.getPos();
this.player.resetLastActionTime();
@@ -1091,14 +1459,46 @@
@@ -1104,14 +1461,46 @@
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND);
@@ -676,7 +627,7 @@
this.player.drop(false);
}
@@ -1136,6 +1536,7 @@
@@ -1149,6 +1538,7 @@
@Override
public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.serverLevel());
@@ -684,15 +635,15 @@
this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence());
WorldServer worldserver = this.player.serverLevel();
EnumHand enumhand = packetplayinuseitem.getHand();
@@ -1158,6 +1559,7 @@
@@ -1171,6 +1561,7 @@
if (blockposition.getY() < i) {
if (blockposition.getY() <= i) {
if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) {
+ this.player.stopUsingItem(); // CraftBukkit - SPIGOT-4706
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enuminteractionresult.consumesAction()) {
@@ -1190,6 +1592,7 @@
@@ -1207,6 +1598,7 @@
@Override
public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.serverLevel());
@@ -700,7 +651,7 @@
this.ackBlockChangesUpTo(packetplayinblockplace.getSequence());
WorldServer worldserver = this.player.serverLevel();
EnumHand enumhand = packetplayinblockplace.getHand();
@@ -1204,6 +1607,47 @@
@@ -1221,6 +1613,47 @@
this.player.absRotateTo(f, f1);
}
@@ -747,17 +698,17 @@
+ // CraftBukkit end
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult.shouldSwing()) {
@@ -1224,7 +1668,7 @@
if (enuminteractionresult instanceof EnumInteractionResult.d) {
@@ -1245,7 +1678,7 @@
Entity entity = packetplayinspectate.getEntity(worldserver);
if (entity != null) {
- this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
+ this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
- this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true);
+ this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
return;
}
}
@@ -1245,6 +1689,13 @@
@@ -1266,6 +1699,13 @@
@Override
public void onDisconnect(DisconnectionDetails disconnectiondetails) {
@@ -771,7 +722,7 @@
PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), disconnectiondetails.reason().getString());
this.removePlayerFromWorld();
super.onDisconnect(disconnectiondetails);
@@ -1252,10 +1703,18 @@
@@ -1273,10 +1713,18 @@
private void removePlayerFromWorld() {
this.chatMessageChain.close();
@@ -791,7 +742,7 @@
this.player.getTextFilter().leave();
}
@@ -1270,7 +1729,16 @@
@@ -1291,7 +1739,16 @@
@Override
public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.serverLevel());
@@ -808,7 +759,7 @@
if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) {
this.player.stopUsingItem();
}
@@ -1279,11 +1747,18 @@
@@ -1300,11 +1757,18 @@
this.player.resetLastActionTime();
} else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
@@ -827,7 +778,7 @@
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packetplayinchat.lastSeenMessages());
if (!optional.isEmpty()) {
@@ -1297,7 +1772,7 @@
@@ -1318,7 +1782,7 @@
return;
}
@@ -836,7 +787,7 @@
IChatBaseComponent ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent());
this.chatMessageChain.append(completablefuture, (filteredtext) -> {
@@ -1305,19 +1780,36 @@
@@ -1326,19 +1790,36 @@
this.broadcastChatMessage(playerchatmessage1);
});
@@ -875,7 +826,7 @@
ParseResults<CommandListenerWrapper> parseresults = this.parseCommand(s);
if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) {
@@ -1334,19 +1826,37 @@
@@ -1355,19 +1836,37 @@
if (!optional.isEmpty()) {
this.tryHandleChat(serverboundchatcommandsignedpacket.command(), () -> {
@@ -916,7 +867,7 @@
} catch (SignedMessageChain.a signedmessagechain_a) {
this.handleMessageDecodeFailure(signedmessagechain_a);
return;
@@ -1354,10 +1864,10 @@
@@ -1375,10 +1874,10 @@
CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map);
@@ -929,7 +880,7 @@
}
private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) {
@@ -1433,14 +1943,20 @@
@@ -1454,14 +1953,20 @@
return com_mojang_brigadier_commanddispatcher.parse(s, this.player.createCommandSourceStack());
}
@@ -953,7 +904,7 @@
}
}
@@ -1469,6 +1985,116 @@
@@ -1490,6 +1995,116 @@
return false;
}
@@ -1070,7 +1021,7 @@
private PlayerChatMessage getSignedMessage(PacketPlayInChat packetplayinchat, LastSeenMessages lastseenmessages) throws SignedMessageChain.a {
SignedMessageBody signedmessagebody = new SignedMessageBody(packetplayinchat.message(), packetplayinchat.timeStamp(), packetplayinchat.salt(), lastseenmessages);
@@ -1476,13 +2102,33 @@
@@ -1497,13 +2112,33 @@
}
private void broadcastChatMessage(PlayerChatMessage playerchatmessage) {
@@ -1098,16 +1049,16 @@
}
private void detectRateSpam() {
- this.chatSpamTickCount += 20;
- if (this.chatSpamTickCount > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
- this.chatSpamThrottler.increment();
- if (!this.chatSpamThrottler.isUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ // CraftBukkit start - replaced with thread safe throttle
+ // this.chatSpamTickCount += 20;
+ if (this.chatSpamTickCount.addAndGet(20) > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ // this.chatSpamThrottler.increment();
+ if (!this.chatSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ // CraftBukkit end
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("disconnect.spam"));
}
@@ -1504,13 +2150,62 @@
@@ -1525,13 +2160,62 @@
@Override
public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel());
@@ -1170,7 +1121,7 @@
this.player.resetLastActionTime();
Entity entity;
@@ -1587,6 +2282,12 @@
@@ -1608,6 +2292,12 @@
}
public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) {
@@ -1183,7 +1134,7 @@
this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a));
this.addPendingMessage(playerchatmessage);
}
@@ -1614,6 +2315,7 @@
@@ -1635,6 +2325,7 @@
@Override
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel());
@@ -1191,9 +1142,9 @@
final WorldServer worldserver = this.player.serverLevel();
final Entity entity = packetplayinuseentity.getTarget(worldserver);
@@ -1628,13 +2330,51 @@
@@ -1649,13 +2340,51 @@
if (this.player.canInteractWithEntity(axisalignedbb, 1.0D)) {
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
- private void performInteraction(EnumHand enumhand, PlayerConnection.a playerconnection_a) {
+ private void performInteraction(EnumHand enumhand, PlayerConnection.a playerconnection_a, PlayerInteractEntityEvent event) { // CraftBukkit
@@ -1241,10 +1192,10 @@
+ }
+ // CraftBukkit end
+
if (enuminteractionresult.consumesAction()) {
CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, enuminteractionresult.indicateItemUse() ? itemstack1 : ItemStack.EMPTY, entity);
if (enuminteractionresult.shouldSwing()) {
@@ -1647,19 +2387,20 @@
if (enuminteractionresult instanceof EnumInteractionResult.d) {
EnumInteractionResult.d enuminteractionresult_d = (EnumInteractionResult.d) enuminteractionresult;
ItemStack itemstack2 = enuminteractionresult_d.wasItemInteraction() ? itemstack1 : ItemStack.EMPTY;
@@ -1671,19 +2400,20 @@
@Override
public void onInteraction(EnumHand enumhand) {
@@ -1268,7 +1219,7 @@
label23:
{
if (entity instanceof EntityArrow) {
@@ -1677,6 +2418,11 @@
@@ -1701,6 +2431,11 @@
}
PlayerConnection.this.player.attack(entity);
@@ -1280,28 +1231,30 @@
return;
}
}
@@ -1700,17 +2446,17 @@
@@ -1724,7 +2459,7 @@
case PERFORM_RESPAWN:
if (this.player.wonGame) {
this.player.wonGame = false;
- this.player = this.server.getPlayerList().respawn(this.player, true, Entity.RemovalReason.CHANGED_DIMENSION);
+ this.player = this.server.getPlayerList().respawn(this.player, true, Entity.RemovalReason.CHANGED_DIMENSION, RespawnReason.END_PORTAL); // CraftBukkit
this.resetPosition();
CriterionTriggers.CHANGED_DIMENSION.trigger(this.player, World.END, World.OVERWORLD);
} else {
if (this.player.getHealth() > 0.0F) {
@@ -1732,11 +2467,11 @@
return;
}
- this.player = this.server.getPlayerList().respawn(this.player, false, Entity.RemovalReason.KILLED);
+ this.player = this.server.getPlayerList().respawn(this.player, false, Entity.RemovalReason.KILLED, RespawnReason.DEATH); // CraftBukkit
this.resetPosition();
if (this.server.isHardcore()) {
this.player.setGameMode(EnumGamemode.SPECTATOR);
- ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
+ ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // CraftBukkit - per-world
- ((GameRules.GameRuleBoolean) this.player.serverLevel().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
+ ((GameRules.GameRuleBoolean) this.player.serverLevel().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // CraftBukkit - per-world
}
}
break;
@@ -1723,15 +2469,21 @@
@@ -1749,15 +2484,21 @@
@Override
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel());
@@ -1325,7 +1278,7 @@
this.player.containerMenu.sendAllDataToRemote();
} else if (!this.player.containerMenu.stillValid(this.player)) {
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
@@ -1744,7 +2496,284 @@
@@ -1770,7 +2511,284 @@
boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates();
@@ -1611,28 +1564,30 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
@@ -1774,9 +2803,18 @@
if (!this.player.containerMenu.stillValid(this.player)) {
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
} else {
- this.server.getRecipeManager().byKey(packetplayinautorecipe.getRecipe()).ifPresent((recipeholder) -> {
- ((ContainerRecipeBook) this.player.containerMenu).handlePlacement(packetplayinautorecipe.isShiftDown(), recipeholder, this.player);
+ // CraftBukkit start - implement PlayerRecipeBookClickEvent
+ org.bukkit.inventory.Recipe recipe = this.cserver.getRecipe(CraftNamespacedKey.fromMinecraft(packetplayinautorecipe.getRecipe()));
+ if (recipe == null) {
+ return;
+ }
+ org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, packetplayinautorecipe.isShiftDown());
@@ -1816,7 +2834,21 @@
return;
}
- ContainerRecipeBook.a containerrecipebook_a = containerrecipebook.handlePlacement(packetplayinautorecipe.useMaxItems(), this.player.isCreative(), recipeholder, this.player.serverLevel(), this.player.getInventory());
+ // CraftBukkit start - implement PlayerRecipeBookClickEvent
+ org.bukkit.inventory.Recipe recipe = recipeholder.toBukkitRecipe();
+ if (recipe == null) {
+ return;
+ }
+ org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, packetplayinautorecipe.useMaxItems());
+
+ // Cast to keyed should be safe as the recipe will never be a MerchantRecipe.
+ this.server.getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).ifPresent((recipeholder) -> {
+ ((ContainerRecipeBook) this.player.containerMenu).handlePlacement(event.isShiftClick(), recipeholder, this.player);
});
+ // CraftBukkit end
}
}
}
@@ -1784,6 +2822,7 @@
+ // Cast to keyed should be safe as the recipe will never be a MerchantRecipe.
+ recipeholder = this.server.getRecipeManager().byKey(CraftRecipe.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).orElse(null);
+ if (recipeholder == null) {
+ return;
+ }
+
+ ContainerRecipeBook.a containerrecipebook_a = containerrecipebook.handlePlacement(event.isShiftClick(), this.player.isCreative(), recipeholder, this.player.serverLevel(), this.player.getInventory());
+ // CraftBukkit end
if (containerrecipebook_a == ContainerRecipeBook.a.PLACE_GHOST_RECIPE) {
this.player.connection.send(new PacketPlayOutAutoRecipe(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
@@ -1832,6 +2864,7 @@
@Override
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel());
@@ -1640,7 +1595,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packetplayinenchantitem.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1826,6 +2865,43 @@
@@ -1875,6 +2908,43 @@
boolean flag1 = packetplayinsetcreativeslot.slotNum() >= 1 && packetplayinsetcreativeslot.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@@ -1684,7 +1639,7 @@
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).setByPlayer(itemstack);
@@ -1848,6 +2924,7 @@
@@ -1902,6 +2972,7 @@
}
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<FilteredText> list) {
@@ -1692,7 +1647,7 @@
this.player.resetLastActionTime();
WorldServer worldserver = this.player.serverLevel();
BlockPosition blockposition = packetplayinupdatesign.getPos();
@@ -1869,7 +2946,17 @@
@@ -1923,7 +2994,17 @@
@Override
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel());
@@ -1711,7 +1666,7 @@
}
@Override
@@ -1928,7 +3015,7 @@
@@ -1982,7 +3063,7 @@
if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested");
} else {
@@ -1720,7 +1675,7 @@
}
}
@@ -1953,8 +3040,10 @@
@@ -2007,8 +3088,10 @@
});
}
@@ -1732,4 +1687,4 @@
+ // CraftBukkit end
@Override
public EntityPlayer getPlayer() {
public void handleClientTickEnd(ServerboundClientTickEndPacket serverboundclienttickendpacket) {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -28,8 +28,44 @@
@@ -29,8 +29,44 @@
import net.minecraft.util.thread.IAsyncTaskHandler;
import org.slf4j.Logger;
@@ -46,7 +46,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
public static final int LATENCY_CHECK_INTERVAL = 15000;
private static final int CLOSED_LISTENER_TIMEOUT = 15000;
@@ -46,12 +82,24 @@
@@ -47,12 +83,24 @@
private int latency;
private volatile boolean suspendFlushingOnServerThread = false;
@@ -72,7 +72,7 @@
}
private void close() {
@@ -73,6 +121,7 @@
@@ -80,6 +128,7 @@
@Override
public void handleKeepAlive(ServerboundKeepAlivePacket serverboundkeepalivepacket) {
@@ -80,7 +80,7 @@
if (this.keepAlivePending && serverboundkeepalivepacket.getId() == this.keepAliveChallenge) {
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime);
@@ -87,8 +136,56 @@
@@ -94,8 +143,56 @@
@Override
public void handlePong(ServerboundPongPacket serverboundpongpacket) {}
@@ -138,7 +138,7 @@
@Override
public void handleResourcePackResponse(ServerboundResourcePackPacket serverboundresourcepackpacket) {
@@ -97,11 +194,18 @@
@@ -104,11 +201,18 @@
ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), serverboundresourcepackpacket.id());
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.requiredTexturePrompt.disconnect"));
}
@@ -157,8 +157,8 @@
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
}
@@ -109,7 +213,7 @@
this.server.getProfiler().push("keepAlive");
@@ -116,7 +220,7 @@
Profiler.get().push("keepAlive");
long i = SystemUtils.getMillis();
- if (!this.isSingleplayerOwner() && i - this.keepAliveTime >= 15000L) {
@@ -166,7 +166,7 @@
if (this.keepAlivePending) {
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
} else if (this.checkIfClosed(i)) {
@@ -149,6 +253,14 @@
@@ -156,6 +260,14 @@
}
public void send(Packet<?> packet, @Nullable PacketSendListener packetsendlistener) {
@@ -181,7 +181,7 @@
if (packet.isTerminal()) {
this.close();
}
@@ -173,15 +285,61 @@
@@ -180,15 +292,61 @@
}
public void disconnect(DisconnectionDetails disconnectiondetails) {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -103,6 +103,27 @@
@@ -104,6 +104,27 @@
import net.minecraft.world.scores.ScoreboardTeam;
import org.slf4j.Logger;
@@ -28,7 +28,7 @@
public abstract class PlayerList {
public static final File USERBANLIST_FILE = new File("banned-players.json");
@@ -115,14 +136,16 @@
@@ -116,14 +137,16 @@
private static final int SEND_PLAYER_INFO_INTERVAL = 600;
private static final SimpleDateFormat BAN_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
private final MinecraftServer server;
@@ -48,7 +48,7 @@
public final WorldNBTStorage playerIo;
private boolean doWhiteList;
private final LayeredRegistryAccess<RegistryLayer> registries;
@@ -133,13 +156,23 @@
@@ -134,13 +157,23 @@
private static final boolean ALLOW_LOGOUTIVATOR = false;
private int sendAllPlayerInfoIn;
@@ -74,7 +74,7 @@
this.server = minecraftserver;
this.registries = layeredregistryaccess;
this.maxPlayers = i;
@@ -149,25 +182,34 @@
@@ -150,25 +183,34 @@
public void placeNewPlayer(NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) {
GameProfile gameprofile = entityplayer.getGameProfile();
UserCache usercache = this.server.getProfileCache();
@@ -114,7 +114,7 @@
WorldServer worldserver = this.server.getLevel(resourcekey);
WorldServer worldserver1;
@@ -181,10 +223,11 @@
@@ -182,10 +224,11 @@
entityplayer.setServerLevel(worldserver1);
String s1 = networkmanager.getLoggableAddress(this.server.logIPs());
@@ -128,7 +128,7 @@
PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer, commonlistenercookie);
networkmanager.setupInboundProtocol(GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection);
@@ -194,6 +237,7 @@
@@ -195,6 +238,7 @@
boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING);
playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), this.server.levelKeys(), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, flag2, entityplayer.createCommonSpawnInfo(worldserver1), this.server.enforceSecureProfile()));
@@ -136,7 +136,7 @@
playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
playerconnection.send(new PacketPlayOutAbilities(entityplayer.getAbilities()));
playerconnection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected));
@@ -210,8 +254,10 @@
@@ -213,8 +257,10 @@
} else {
ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.player.joined.renamed", entityplayer.getDisplayName(), s);
}
@@ -148,7 +148,7 @@
playerconnection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
ServerPing serverping = this.server.getStatus();
@@ -219,18 +265,70 @@
@@ -222,17 +268,70 @@
entityplayer.sendServerStatus(serverping);
}
@@ -215,39 +215,15 @@
+ worldserver1 = entityplayer.serverLevel(); // CraftBukkit - Update in case join event changed it
+ // CraftBukkit end
this.sendActivePlayerEffects(entityplayer);
if (optional.isPresent() && ((NBTTagCompound) optional.get()).contains("RootVehicle", 10)) {
NBTTagCompound nbttagcompound = ((NBTTagCompound) optional.get()).getCompound("RootVehicle");
+ WorldServer finalWorldServer = worldserver1; // CraftBukkit - decompile error
Entity entity = EntityTypes.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver1, (entity1) -> {
- return !worldserver1.addWithUUID(entity1) ? null : entity1;
+ return !finalWorldServer.addWithUUID(entity1) ? null : entity1; // CraftBukkit - decompile error
});
if (entity != null) {
@@ -261,18 +359,20 @@
if (!entityplayer.isPassenger()) {
PlayerList.LOGGER.warn("Couldn't reattach entity to player");
- entity.discard();
+ entity.discard(null); // CraftBukkit - add Bukkit remove cause
iterator = entity.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
entity1 = (Entity) iterator.next();
- entity1.discard();
+ entity1.discard(null); // CraftBukkit - add Bukkit remove cause
}
}
}
}
entityplayer.loadAndSpawnEnderpearls(optional);
entityplayer.loadAndSpawnParentVehicle(optional);
entityplayer.initInventoryMenu();
+ // CraftBukkit - Moved from above, added world
+ PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getName().getString(), s1, entityplayer.getId(), worldserver1.serverLevelData.getLevelName(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ());
}
public void updateEntireScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
@@ -309,30 +409,31 @@
@@ -269,30 +368,31 @@
}
public void addWorldborderListener(WorldServer worldserver) {
@@ -284,7 +260,7 @@
}
@Override
@@ -359,14 +460,15 @@
@@ -319,14 +419,15 @@
}
protected void save(EntityPlayer entityplayer) {
@@ -302,7 +278,7 @@
if (advancementdataplayer != null) {
advancementdataplayer.save();
@@ -374,10 +476,24 @@
@@ -334,10 +435,24 @@
}
@@ -328,7 +304,7 @@
this.save(entityplayer);
if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getRootVehicle();
@@ -386,7 +502,7 @@
@@ -346,7 +461,7 @@
PlayerList.LOGGER.debug("Removing player mount");
entityplayer.stopRiding();
entity.getPassengersAndSelf().forEach((entity1) -> {
@@ -337,7 +313,16 @@
});
}
}
@@ -401,17 +517,66 @@
@@ -357,7 +472,7 @@
while (iterator.hasNext()) {
EntityEnderPearl entityenderpearl = (EntityEnderPearl) iterator.next();
- entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER);
+ entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER, EntityRemoveEvent.Cause.PLAYER_QUIT); // CraftBukkit - add Bukkit remove cause
}
worldserver.removePlayerImmediately(entityplayer, Entity.RemovalReason.UNLOADED_WITH_PLAYER);
@@ -369,17 +484,66 @@
if (entityplayer1 == entityplayer) {
this.playersByUUID.remove(uuid);
@@ -409,7 +394,7 @@
if (this.bans.isBanned(gameprofile)) {
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile);
@@ -420,9 +585,11 @@
@@ -388,9 +552,11 @@
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())));
}
@@ -423,7 +408,7 @@
} else if (this.ipBans.isBanned(socketaddress)) {
IpBanEntry ipbanentry = this.ipBans.get(socketaddress);
@@ -431,17 +598,32 @@
@@ -399,17 +565,32 @@
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.expiration", PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires())));
}
@@ -436,13 +421,13 @@
+ if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) {
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full");
+ }
+ }
}
+
+ cserver.getPluginManager().callEvent(event);
+ if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
+ loginlistener.disconnect(event.getKickMessage());
+ return null;
}
+ }
+ return entity;
}
@@ -461,7 +446,7 @@
UUID uuid = gameprofile.getId();
Set<EntityPlayer> set = Sets.newIdentityHashSet();
Iterator iterator = this.players.iterator();
@@ -469,22 +651,41 @@
@@ -437,22 +618,41 @@
}
return !set.isEmpty();
@@ -481,8 +466,8 @@
this.players.remove(entityplayer);
entityplayer.serverLevel().removePlayerImmediately(entityplayer, entity_removalreason);
+ /* CraftBukkit start
DimensionTransition dimensiontransition = entityplayer.findRespawnPositionAndUseSpawnBlock(flag, DimensionTransition.DO_NOTHING);
WorldServer worldserver = dimensiontransition.newLevel();
TeleportTransition teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING);
WorldServer worldserver = teleporttransition.newLevel();
EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver, entityplayer.getGameProfile(), entityplayer.clientInformation());
+ // */
+ EntityPlayer entityplayer1 = entityplayer;
@@ -496,7 +481,7 @@
entityplayer1.setMainArm(entityplayer.getMainArm());
+ // CraftBukkit - not required, just copies old location into reused entity
+ /*
if (!dimensiontransition.missingRespawnBlock()) {
if (!teleporttransition.missingRespawnBlock()) {
entityplayer1.copyRespawnPosition(entityplayer);
}
+ */
@@ -504,35 +489,35 @@
Iterator iterator = entityplayer.getTags().iterator();
@@ -494,11 +695,26 @@
@@ -462,11 +662,26 @@
entityplayer1.addTag(s);
}
+ // CraftBukkit start - fire PlayerRespawnEvent
+ DimensionTransition dimensiontransition;
+ TeleportTransition teleporttransition;
+ if (location == null) {
+ dimensiontransition = entityplayer.findRespawnPositionAndUseSpawnBlock(flag, DimensionTransition.DO_NOTHING, reason);
+ teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING, reason);
+
+ if (!flag) entityplayer.reset(); // SPIGOT-4785
+ } else {
+ dimensiontransition = new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getYaw(), location.getPitch(), DimensionTransition.DO_NOTHING);
+ teleporttransition = new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getYaw(), location.getPitch(), TeleportTransition.DO_NOTHING);
+ }
+ WorldServer worldserver = dimensiontransition.newLevel();
+ WorldServer worldserver = teleporttransition.newLevel();
+ entityplayer1.spawnIn(worldserver);
+ entityplayer1.unsetRemoved();
+ entityplayer1.setShiftKeyDown(false);
Vec3D vec3d = dimensiontransition.pos();
Vec3D vec3d = teleporttransition.position();
- entityplayer1.moveTo(vec3d.x, vec3d.y, vec3d.z, dimensiontransition.yRot(), dimensiontransition.xRot());
+ entityplayer1.forceSetPositionRotation(vec3d.x, vec3d.y, vec3d.z, dimensiontransition.yRot(), dimensiontransition.xRot());
- entityplayer1.moveTo(vec3d.x, vec3d.y, vec3d.z, teleporttransition.yRot(), teleporttransition.xRot());
+ entityplayer1.forceSetPositionRotation(vec3d.x, vec3d.y, vec3d.z, teleporttransition.yRot(), teleporttransition.xRot());
+ // CraftBukkit end
if (dimensiontransition.missingRespawnBlock()) {
if (teleporttransition.missingRespawnBlock()) {
entityplayer1.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
+ entityplayer1.setRespawnPosition(null, null, 0f, false, false, PlayerSpawnChangeEvent.Cause.RESET); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed
}
int i = flag ? 1 : 0;
@@ -506,17 +722,19 @@
@@ -474,17 +689,19 @@
WorldData worlddata = worldserver1.getLevelData();
entityplayer1.connection.send(new PacketPlayOutRespawn(entityplayer1.createCommonSpawnInfo(worldserver1), (byte) i));
@@ -555,9 +540,9 @@
+ }
+ // entityplayer1.initInventoryMenu();
entityplayer1.setHealth(entityplayer1.getHealth());
if (!flag) {
BlockPosition blockposition = BlockPosition.containing(dimensiontransition.pos());
@@ -526,6 +744,27 @@
BlockPosition blockposition = entityplayer1.getRespawnPosition();
WorldServer worldserver2 = this.server.getLevel(entityplayer1.getRespawnDimension());
@@ -496,6 +713,27 @@
entityplayer1.connection.send(new PacketPlayOutNamedSoundEffect(SoundEffects.RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 1.0F, 1.0F, worldserver.getRandom().nextLong()));
}
}
@@ -585,7 +570,7 @@
return entityplayer1;
}
@@ -554,7 +793,18 @@
@@ -524,7 +762,18 @@
public void tick() {
if (++this.sendAllPlayerInfoIn > 600) {
@@ -605,7 +590,7 @@
this.sendAllPlayerInfoIn = 0;
}
@@ -571,6 +821,25 @@
@@ -541,6 +790,25 @@
}
@@ -631,7 +616,7 @@
public void broadcastAll(Packet<?> packet, ResourceKey<World> resourcekey) {
Iterator iterator = this.players.iterator();
@@ -649,7 +918,7 @@
@@ -619,7 +887,7 @@
}
public void deop(GameProfile gameprofile) {
@@ -640,7 +625,7 @@
EntityPlayer entityplayer = this.getPlayer(gameprofile.getId());
if (entityplayer != null) {
@@ -673,6 +942,7 @@
@@ -643,6 +911,7 @@
entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, b0));
}
@@ -648,7 +633,7 @@
this.server.getCommands().sendCommands(entityplayer);
}
@@ -703,6 +973,12 @@
@@ -673,6 +942,12 @@
for (int i = 0; i < this.players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
@@ -661,7 +646,7 @@
if (entityplayer != entityhuman && entityplayer.level().dimension() == resourcekey) {
double d4 = d0 - entityplayer.getX();
double d5 = d1 - entityplayer.getY();
@@ -742,15 +1018,19 @@
@@ -712,15 +987,19 @@
public void reloadWhiteList() {}
public void sendLevelInfo(EntityPlayer entityplayer, WorldServer worldserver) {
@@ -685,7 +670,7 @@
}
entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.LEVEL_CHUNKS_LOAD_START, 0.0F));
@@ -759,8 +1039,16 @@
@@ -729,8 +1008,16 @@
public void sendAllPlayerInfo(EntityPlayer entityplayer) {
entityplayer.inventoryMenu.sendAllDataToRemote();
@@ -695,15 +680,15 @@
+ entityplayer.refreshEntityData(entityplayer); // CraftBukkkit - SPIGOT-7218: sync metadata
entityplayer.connection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected));
+ // CraftBukkit start - from GameRules
+ int i = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23;
+ int i = entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23;
+ entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, (byte) i));
+ float immediateRespawn = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F;
+ float immediateRespawn = entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F;
+ entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.IMMEDIATE_RESPAWN, immediateRespawn));
+ // CraftBukkit end
}
public int getPlayerCount() {
@@ -816,12 +1104,22 @@
@@ -786,12 +1073,22 @@
}
public void removeAll() {
@@ -728,7 +713,7 @@
public void broadcastSystemMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.broadcastSystemMessage(ichatbasecomponent, (entityplayer) -> {
return ichatbasecomponent;
@@ -879,16 +1177,23 @@
@@ -849,16 +1146,23 @@
return playerchatmessage.hasSignature() && !playerchatmessage.hasExpiredServer(Instant.now());
}
@@ -756,7 +741,7 @@
Path path = file2.toPath();
if (FileUtils.isPathNormalized(path) && FileUtils.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
@@ -897,7 +1202,7 @@
@@ -867,7 +1171,7 @@
}
serverstatisticmanager = new ServerStatisticManager(this.server, file1);
@@ -765,7 +750,7 @@
}
return serverstatisticmanager;
@@ -905,13 +1210,13 @@
@@ -875,13 +1179,13 @@
public AdvancementDataPlayer getPlayerAdvancements(EntityPlayer entityplayer) {
UUID uuid = entityplayer.getUUID();
@@ -781,7 +766,7 @@
}
advancementdataplayer.setPlayer(entityplayer);
@@ -962,13 +1267,20 @@
@@ -932,13 +1236,20 @@
}
public void reloadResources() {
@@ -802,4 +787,4 @@
+ // CraftBukkit end
this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries)));
PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getRecipeManager().getOrderedRecipes());
CraftingManager craftingmanager = this.server.getRecipeManager();