Configurable container update tick rate

This commit is contained in:
Sudzzy 2016-03-02 23:34:44 -06:00
parent adb6c35b17
commit 5b0e06e8e8

View File

@ -114,10 +114,12 @@
@Nullable
private Vec3 startingToFallPosition;
@Nullable
@@ -259,6 +294,24 @@
@@ -258,6 +293,25 @@
private final CommandSource commandSource;
private int containerCounter;
public boolean wonGame;
+ private int containerUpdateDelay; // Paper - Configurable container update tick rate
+
+ // CraftBukkit start
+ public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName;
@ -135,11 +137,10 @@
+ public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
+ // CraftBukkit end
+ public boolean isRealPlayer; // Paper
+
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
@@ -266,7 +319,7 @@
@@ -266,7 +320,7 @@
this.canChatColor = true;
this.lastActionTime = Util.getMillis();
this.requestedViewDistance = 2;
@ -148,7 +149,7 @@
this.lastSectionPos = SectionPos.of(0, 0, 0);
this.chunkTrackingView = ChunkTrackingView.EMPTY;
this.respawnDimension = Level.OVERWORLD;
@@ -340,6 +393,13 @@
@@ -340,6 +394,13 @@
public void sendSystemMessage(Component message) {
ServerPlayer.this.sendSystemMessage(message);
}
@ -162,7 +163,7 @@
};
this.textFilter = server.createTextFilterForPlayer(this);
this.gameMode = server.createGameModeForPlayer(this);
@@ -352,14 +412,68 @@
@@ -352,14 +413,68 @@
this.moveTo(this.adjustSpawnLocation(world, world.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
this.updateOptions(clientOptions);
this.object = null;
@ -232,7 +233,7 @@
int i = Math.max(0, this.server.getSpawnRadius(world));
int j = Mth.floor(world.getWorldBorder().getDistanceToBorder((double) basePos.getX(), (double) basePos.getZ()));
@@ -395,14 +509,20 @@
@@ -395,14 +510,20 @@
Objects.requireNonNull(basePos);
crashreportsystemdetails.setDetail("Origin", basePos::toString);
@ -255,7 +256,7 @@
});
throw new ReportedException(crashreport);
}
@@ -440,7 +560,7 @@
@@ -440,7 +561,7 @@
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(NbtOps.INSTANCE, nbt.get("warden_spawn_tracker")));
logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@ -264,7 +265,7 @@
this.wardenSpawnTracker = wardenspawntracker;
});
}
@@ -457,17 +577,26 @@
@@ -457,17 +578,26 @@
return this.server.getRecipeManager().byKey(resourcekey).isPresent();
});
}
@ -292,7 +293,7 @@
Logger logger1 = ServerPlayer.LOGGER;
Objects.requireNonNull(logger1);
@@ -482,7 +611,7 @@
@@ -482,7 +612,7 @@
dataresult = BlockPos.CODEC.parse(NbtOps.INSTANCE, nbtbase);
logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@ -301,7 +302,7 @@
this.raidOmenPosition = blockposition;
});
}
@@ -492,7 +621,7 @@
@@ -492,7 +622,7 @@
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
@ -310,7 +311,7 @@
Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -526,6 +655,7 @@
@@ -526,6 +656,7 @@
nbt.put("SpawnDimension", nbtbase);
});
}
@ -318,7 +319,7 @@
nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) {
@@ -544,7 +674,20 @@
@@ -544,7 +675,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
@ -340,7 +341,7 @@
CompoundTag nbttagcompound1 = new CompoundTag();
CompoundTag nbttagcompound2 = new CompoundTag();
@@ -598,12 +741,12 @@
@@ -598,12 +742,12 @@
if (!this.isPassenger()) {
ServerPlayer.LOGGER.warn("Couldn't reattach entity to player");
@ -355,7 +356,7 @@
}
}
}
@@ -625,7 +768,7 @@
@@ -625,7 +769,7 @@
CompoundTag nbttagcompound1 = new CompoundTag();
entityenderpearl.save(nbttagcompound1);
@ -364,7 +365,7 @@
Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -651,7 +794,7 @@
@@ -651,7 +795,7 @@
nbttaglist.forEach((nbtbase1) -> {
if (nbtbase1 instanceof CompoundTag nbttagcompound) {
if (nbttagcompound.contains("ender_pearl_dimension")) {
@ -373,12 +374,10 @@
Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -684,7 +827,30 @@
}
}
@@ -686,6 +830,29 @@
}
+ }
+
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
+ public void spawnIn(Level world) {
+ this.setLevel(world);
@ -399,12 +398,13 @@
+ this.setPos(position);
+ }
+ this.gameMode.setLevel((ServerLevel) world);
}
+ }
+ // CraftBukkit end
+
public void setExperiencePoints(int points) {
float f = (float) this.getXpNeededForNextLevel();
@@ -744,6 +910,11 @@
float f1 = (f - 1.0F) / f;
@@ -744,6 +911,11 @@
@Override
public void tick() {
@ -416,7 +416,20 @@
this.tickClientLoadTimeout();
this.gameMode.tick();
this.wardenSpawnTracker.tick();
@@ -820,7 +991,7 @@
@@ -751,7 +923,11 @@
--this.invulnerableTime;
}
- this.containerMenu.broadcastChanges();
+ if (--this.containerUpdateDelay <= 0) {
+ this.containerMenu.broadcastChanges();
+ this.containerUpdateDelay = this.level().paperConfig().tickRates.containerUpdate;
+ }
+ // Paper end - Configurable container update tick rate
if (!this.containerMenu.stillValid(this)) {
this.closeContainer();
this.containerMenu = this.inventoryMenu;
@@ -820,7 +996,7 @@
}
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@ -425,7 +438,7 @@
this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -851,6 +1022,12 @@
@@ -851,6 +1027,12 @@
this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience));
}
@ -438,7 +451,7 @@
if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel));
@@ -865,6 +1042,20 @@
@@ -865,6 +1047,20 @@
CriteriaTriggers.LOCATION.trigger(this);
}
@ -459,7 +472,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -893,7 +1084,7 @@
@@ -893,7 +1089,7 @@
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
if (this.tickCount % 20 == 0) {
if (this.getHealth() < this.getMaxHealth()) {
@ -468,7 +481,7 @@
}
float f = this.foodData.getSaturationLevel();
@@ -946,7 +1137,8 @@
@@ -946,7 +1142,8 @@
}
private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) {
@ -478,7 +491,7 @@
scoreaccess.set(score);
});
}
@@ -955,10 +1147,43 @@
@@ -955,10 +1152,43 @@
public void die(DamageSource damageSource) {
this.gameEvent(GameEvent.ENTITY_DIE);
boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
@ -524,7 +537,7 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true;
String s = ichatbasecomponent.getString(256);
@@ -988,12 +1213,18 @@
@@ -988,12 +1218,18 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied();
}
@ -547,7 +560,7 @@
LivingEntity entityliving = this.getKillCredit();
if (entityliving != null) {
@@ -1028,10 +1259,12 @@
@@ -1028,10 +1264,12 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled != this) {
super.awardKillScore(entityKilled, damageSource);
@ -563,7 +576,7 @@
} else {
this.awardStat(Stats.MOB_KILLS);
}
@@ -1049,7 +1282,8 @@
@@ -1049,7 +1287,8 @@
int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < criterions.length) {
@ -573,7 +586,7 @@
}
}
@@ -1062,8 +1296,8 @@
@@ -1062,8 +1301,8 @@
} else {
Entity entity = source.getEntity();
@ -584,7 +597,7 @@
if (!this.canHarmPlayer(entityhuman)) {
return false;
@@ -1074,8 +1308,8 @@
@@ -1074,8 +1313,8 @@
AbstractArrow entityarrow = (AbstractArrow) entity;
Entity entity1 = entityarrow.getOwner();
@ -595,7 +608,7 @@
if (!this.canHarmPlayer(entityhuman1)) {
return false;
@@ -1088,33 +1322,63 @@
@@ -1088,33 +1327,63 @@
}
@Override
@ -666,7 +679,7 @@
}
public static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) {
@@ -1129,11 +1393,11 @@
@@ -1129,11 +1398,11 @@
}
return optional.map((vec3d) -> {
@ -680,7 +693,7 @@
});
} else if (!spawnForced) {
return Optional.empty();
@@ -1142,7 +1406,7 @@
@@ -1142,7 +1411,7 @@
BlockState iblockdata1 = world.getBlockState(pos.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@ -689,7 +702,7 @@
}
}
@@ -1160,6 +1424,7 @@
@@ -1160,6 +1429,7 @@
@Nullable
@Override
public ServerPlayer teleport(TeleportTransition teleportTarget) {
@ -697,7 +710,7 @@
if (this.isRemoved()) {
return null;
} else {
@@ -1169,39 +1434,73 @@
@@ -1169,39 +1439,73 @@
ServerLevel worldserver = teleportTarget.newLevel();
ServerLevel worldserver1 = this.serverLevel();
@ -779,7 +792,7 @@
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
gameprofilerfiller.pop();
@@ -1215,12 +1514,30 @@
@@ -1215,12 +1519,30 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -810,7 +823,7 @@
public void forceSetRotation(float yaw, float pitch) {
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
}
@@ -1228,13 +1545,21 @@
@@ -1228,13 +1550,21 @@
public void triggerDimensionChangeTriggers(ServerLevel origin) {
ResourceKey<Level> resourcekey = origin.dimension();
ResourceKey<Level> resourcekey1 = this.level().dimension();
@ -835,7 +848,7 @@
this.enteredNetherPosition = null;
}
@@ -1251,36 +1576,63 @@
@@ -1251,36 +1581,63 @@
this.containerMenu.broadcastChanges();
}
@ -914,7 +927,7 @@
this.awardStat(Stats.SLEEP_IN_BED);
CriteriaTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -1293,9 +1645,8 @@
@@ -1293,9 +1650,8 @@
return either;
}
}
@ -925,7 +938,7 @@
}
@Override
@@ -1322,13 +1673,31 @@
@@ -1322,13 +1678,31 @@
@Override
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
@ -958,7 +971,7 @@
}
}
@@ -1387,8 +1756,9 @@
@@ -1387,8 +1761,9 @@
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
}
@ -969,7 +982,7 @@
}
@Override
@@ -1396,13 +1766,35 @@
@@ -1396,13 +1771,35 @@
if (factory == null) {
return OptionalInt.empty();
} else {
@ -1005,7 +1018,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true);
@@ -1410,9 +1802,11 @@
@@ -1410,9 +1807,11 @@
return OptionalInt.empty();
} else {
@ -1019,7 +1032,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1425,15 +1819,26 @@
@@ -1425,15 +1824,26 @@
@Override
public void openHorseInventory(AbstractHorse horse, Container inventory) {
@ -1048,7 +1061,7 @@
this.initMenu(this.containerMenu);
}
@@ -1456,6 +1861,7 @@
@@ -1456,6 +1866,7 @@
@Override
public void closeContainer() {
@ -1056,7 +1069,7 @@
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
this.doCloseContainer();
}
@@ -1485,19 +1891,19 @@
@@ -1485,19 +1896,19 @@
i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F);
if (i > 0) {
this.awardStat(Stats.SWIM_ONE_CM, i);
@ -1079,7 +1092,7 @@
}
} else if (this.onClimbable()) {
if (deltaY > 0.0D) {
@@ -1508,13 +1914,13 @@
@@ -1508,13 +1919,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(Stats.SPRINT_ONE_CM, i);
@ -1096,7 +1109,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1557,7 +1963,7 @@
@@ -1557,7 +1968,7 @@
@Override
public void awardStat(Stat<?> stat, int amount) {
this.stats.increment(this, stat, amount);
@ -1105,7 +1118,7 @@
scoreaccess.add(amount);
});
}
@@ -1565,7 +1971,7 @@
@@ -1565,7 +1976,7 @@
@Override
public void resetStat(Stat<?> stat) {
this.stats.setValue(this, stat, 0);
@ -1114,7 +1127,7 @@
}
@Override
@@ -1597,9 +2003,9 @@
@@ -1597,9 +2008,9 @@
super.jumpFromGround();
this.awardStat(Stats.JUMP);
if (this.isSprinting()) {
@ -1126,7 +1139,7 @@
}
}
@@ -1625,6 +2031,7 @@
@@ -1625,6 +2036,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@ -1134,7 +1147,7 @@
}
@Override
@@ -1661,7 +2068,7 @@
@@ -1661,7 +2073,7 @@
this.onUpdateAbilities();
if (alive) {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1143,7 +1156,7 @@
this.setHealth(oldPlayer.getHealth());
this.foodData = oldPlayer.foodData;
Iterator iterator = oldPlayer.getActiveEffects().iterator();
@@ -1669,7 +2076,7 @@
@@ -1669,7 +2081,7 @@
while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
@ -1152,7 +1165,7 @@
}
this.getInventory().replaceWith(oldPlayer.getInventory());
@@ -1680,7 +2087,7 @@
@@ -1680,7 +2092,7 @@
this.portalProcess = oldPlayer.portalProcess;
} else {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1161,7 +1174,7 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) {
this.getInventory().replaceWith(oldPlayer.getInventory());
this.experienceLevel = oldPlayer.experienceLevel;
@@ -1696,7 +2103,7 @@
@@ -1696,7 +2108,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -1170,7 +1183,7 @@
this.seenCredits = oldPlayer.seenCredits;
this.enteredNetherPosition = oldPlayer.enteredNetherPosition;
this.chunkTrackingView = oldPlayer.chunkTrackingView;
@@ -1752,19 +2159,19 @@
@@ -1752,19 +2164,19 @@
}
@Override
@ -1194,7 +1207,7 @@
}
return flag1;
@@ -1861,8 +2268,13 @@
@@ -1861,8 +2273,13 @@
}
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
@ -1209,7 +1222,7 @@
}
}
@@ -1878,7 +2290,18 @@
@@ -1878,7 +2295,18 @@
}
public void updateOptions(ClientInformation clientOptions) {
@ -1228,7 +1241,7 @@
this.requestedViewDistance = clientOptions.viewDistance();
this.chatVisibility = clientOptions.chatVisibility();
this.canChatColor = clientOptions.chatColors();
@@ -1962,7 +2385,7 @@
@@ -1962,7 +2390,7 @@
if (world instanceof ServerLevel) {
ServerLevel worldserver = (ServerLevel) world;
@ -1237,7 +1250,7 @@
}
if (entity != null) {
@@ -1999,11 +2422,11 @@
@@ -1999,11 +2427,11 @@
@Nullable
public Component getTabListDisplayName() {
@ -1251,7 +1264,7 @@
}
@Override
@@ -2046,17 +2469,43 @@
@@ -2046,17 +2474,43 @@
}
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
@ -1302,7 +1315,7 @@
} else {
this.respawnPosition = null;
this.respawnDimension = Level.OVERWORLD;
@@ -2088,18 +2537,44 @@
@@ -2088,18 +2542,44 @@
}
@Override
@ -1351,7 +1364,7 @@
}
this.awardStat(Stats.DROP);
@@ -2375,16 +2850,160 @@
@@ -2375,10 +2855,12 @@
return TicketType.ENDER_PEARL.timeout();
}
@ -1367,11 +1380,10 @@
}
private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) {
Vec3 vec3d1 = Vec3.atBottomCenterOf(currentPos).subtract(respawnPos).normalize();
@@ -2387,4 +2869,146 @@
return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
+ }
+ }
}
}
+
+ // CraftBukkit start - Add per-player time and weather.
+ public long timeOffset = 0;
@ -1423,7 +1435,7 @@
+ if (this.pluginRainPositionPrevious != this.pluginRainPosition) {
+ this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.RAIN_LEVEL_CHANGE, this.pluginRainPosition));
+ }
}
+ }
+
+ if (oldThunder != newThunder) {
+ if (this.weather == WeatherType.DOWNFALL || this.weather == null) {
@ -1432,7 +1444,7 @@
+ this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE, 0));
+ }
+ }
}
+ }
+
+ public void tickWeather() {
+ if (this.weather == null) return;