From 0ef48f1dd1460c15545047dd672153ce9f0d6864 Mon Sep 17 00:00:00 2001 From: DigitalRegent Date: Sat, 11 Apr 2020 13:10:58 +0200 Subject: [PATCH] Brand support --- .../server/level/ServerPlayer.java.patch | 150 +++++++++--------- .../ServerCommonPacketListenerImpl.java.patch | 32 +++- .../craftbukkit/entity/CraftPlayer.java | 7 + 3 files changed, 105 insertions(+), 84 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch index 17075c2d6..411fa7cb1 100644 --- a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch @@ -114,7 +114,7 @@ @Nullable private Vec3 startingToFallPosition; @Nullable -@@ -258,7 +293,34 @@ +@@ -258,7 +293,35 @@ private final CommandSource commandSource; private int containerCounter; public boolean wonGame; @@ -145,11 +145,12 @@ + // CraftBukkit end + public boolean isRealPlayer; // Paper + public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent ++ public @Nullable String clientBrandName = null; // Paper - Brand support + public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) { super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile); this.chatVisibility = ChatVisiblity.FULL; -@@ -266,7 +328,7 @@ +@@ -266,7 +329,7 @@ this.canChatColor = true; this.lastActionTime = Util.getMillis(); this.requestedViewDistance = 2; @@ -158,7 +159,7 @@ this.lastSectionPos = SectionPos.of(0, 0, 0); this.chunkTrackingView = ChunkTrackingView.EMPTY; this.respawnDimension = Level.OVERWORLD; -@@ -340,6 +402,13 @@ +@@ -340,6 +403,13 @@ public void sendSystemMessage(Component message) { ServerPlayer.this.sendSystemMessage(message); } @@ -172,7 +173,7 @@ }; this.textFilter = server.createTextFilterForPlayer(this); this.gameMode = server.createGameModeForPlayer(this); -@@ -349,17 +418,71 @@ +@@ -349,17 +419,71 @@ this.server = server; this.stats = server.getPlayerList().getPlayerStats(this); this.advancements = server.getPlayerList().getPlayerAdvancements(this); @@ -247,7 +248,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 +518,20 @@ +@@ -395,14 +519,20 @@ Objects.requireNonNull(basePos); crashreportsystemdetails.setDetail("Origin", basePos::toString); @@ -270,7 +271,7 @@ }); throw new ReportedException(crashreport); } -@@ -440,7 +569,7 @@ +@@ -440,7 +570,7 @@ dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(NbtOps.INSTANCE, nbt.get("warden_spawn_tracker"))); logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); @@ -279,7 +280,7 @@ this.wardenSpawnTracker = wardenspawntracker; }); } -@@ -457,17 +586,26 @@ +@@ -457,17 +587,26 @@ return this.server.getRecipeManager().byKey(resourcekey).isPresent(); }); } @@ -307,7 +308,7 @@ Logger logger1 = ServerPlayer.LOGGER; Objects.requireNonNull(logger1); -@@ -482,7 +620,7 @@ +@@ -482,7 +621,7 @@ dataresult = BlockPos.CODEC.parse(NbtOps.INSTANCE, nbtbase); logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); @@ -316,7 +317,7 @@ this.raidOmenPosition = blockposition; }); } -@@ -492,7 +630,7 @@ +@@ -492,7 +631,7 @@ @Override public void addAdditionalSaveData(CompoundTag nbt) { super.addAdditionalSaveData(nbt); @@ -325,7 +326,7 @@ Logger logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -526,6 +664,7 @@ +@@ -526,6 +665,7 @@ nbt.put("SpawnDimension", nbtbase); }); } @@ -333,7 +334,7 @@ nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall); if (this.raidOmenPosition != null) { -@@ -544,7 +683,20 @@ +@@ -544,7 +684,20 @@ Entity entity = this.getRootVehicle(); Entity entity1 = this.getVehicle(); @@ -355,7 +356,7 @@ CompoundTag nbttagcompound1 = new CompoundTag(); CompoundTag nbttagcompound2 = new CompoundTag(); -@@ -564,7 +716,7 @@ +@@ -564,7 +717,7 @@ ServerLevel worldserver = (ServerLevel) world; CompoundTag nbttagcompound = ((CompoundTag) nbt.get()).getCompound("RootVehicle"); Entity entity = EntityType.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver, EntitySpawnReason.LOAD, (entity1) -> { @@ -364,7 +365,7 @@ }); if (entity == null) { -@@ -598,12 +750,12 @@ +@@ -598,12 +751,12 @@ if (!this.isPassenger()) { ServerPlayer.LOGGER.warn("Couldn't reattach entity to player"); @@ -379,7 +380,7 @@ } } } -@@ -625,7 +777,7 @@ +@@ -625,7 +778,7 @@ CompoundTag nbttagcompound1 = new CompoundTag(); entityenderpearl.save(nbttagcompound1); @@ -388,7 +389,7 @@ Logger logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -651,7 +803,7 @@ +@@ -651,7 +804,7 @@ nbttaglist.forEach((nbtbase1) -> { if (nbtbase1 instanceof CompoundTag nbttagcompound) { if (nbttagcompound.contains("ender_pearl_dimension")) { @@ -397,7 +398,7 @@ Logger logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -686,6 +838,29 @@ +@@ -686,6 +839,29 @@ } @@ -427,7 +428,7 @@ public void setExperiencePoints(int points) { float f = (float) this.getXpNeededForNextLevel(); float f1 = (f - 1.0F) / f; -@@ -744,6 +919,11 @@ +@@ -744,6 +920,11 @@ @Override public void tick() { @@ -439,7 +440,7 @@ this.tickClientLoadTimeout(); this.gameMode.tick(); this.wardenSpawnTracker.tick(); -@@ -751,9 +931,13 @@ +@@ -751,9 +932,13 @@ --this.invulnerableTime; } @@ -456,7 +457,7 @@ this.containerMenu = this.inventoryMenu; } -@@ -807,7 +991,7 @@ +@@ -807,7 +992,7 @@ public void doTick() { try { @@ -465,7 +466,7 @@ super.tick(); } -@@ -820,7 +1004,7 @@ +@@ -820,7 +1005,7 @@ } if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { @@ -474,7 +475,7 @@ this.lastSentHealth = this.getHealth(); this.lastSentFood = this.foodData.getFoodLevel(); this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; -@@ -851,6 +1035,12 @@ +@@ -851,6 +1036,12 @@ this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience)); } @@ -487,12 +488,10 @@ if (this.experienceLevel != this.lastRecordedLevel) { this.lastRecordedLevel = this.experienceLevel; this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel)); -@@ -863,8 +1053,22 @@ - - if (this.tickCount % 20 == 0) { +@@ -865,6 +1056,20 @@ CriteriaTriggers.LOCATION.trigger(this); -+ } -+ + } + + // CraftBukkit start - initialize oldLevel, fire PlayerLevelChangeEvent, and tick client-sided world border + if (this.oldLevel == -1) { + this.oldLevel = this.experienceLevel; @@ -501,8 +500,8 @@ + if (this.oldLevel != this.experienceLevel) { + CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel); + this.oldLevel = this.experienceLevel; - } - ++ } ++ + if (this.getBukkitEntity().hasClientWorldBorder()) { + ((CraftWorldBorder) this.getBukkitEntity().getWorldBorder()).getHandle().tick(); + } @@ -510,7 +509,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Player being ticked"); -@@ -893,7 +1097,7 @@ +@@ -893,7 +1098,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()) { @@ -519,7 +518,7 @@ } float f = this.foodData.getSaturationLevel(); -@@ -946,19 +1150,103 @@ +@@ -946,19 +1151,103 @@ } private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) { @@ -627,7 +626,7 @@ this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> { boolean flag1 = true; String s = ichatbasecomponent.getString(256); -@@ -988,12 +1276,23 @@ +@@ -988,12 +1277,23 @@ if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { this.tellNeutralMobsThatIDied(); } @@ -655,7 +654,7 @@ LivingEntity entityliving = this.getKillCredit(); if (entityliving != null) { -@@ -1028,10 +1327,12 @@ +@@ -1028,10 +1328,12 @@ public void awardKillScore(Entity entityKilled, DamageSource damageSource) { if (entityKilled != this) { super.awardKillScore(entityKilled, damageSource); @@ -671,7 +670,7 @@ } else { this.awardStat(Stats.MOB_KILLS); } -@@ -1049,7 +1350,8 @@ +@@ -1049,7 +1351,8 @@ int i = scoreboardteam.getColor().getId(); if (i >= 0 && i < criterions.length) { @@ -681,7 +680,7 @@ } } -@@ -1062,8 +1364,8 @@ +@@ -1062,8 +1365,8 @@ } else { Entity entity = source.getEntity(); @@ -692,7 +691,7 @@ if (!this.canHarmPlayer(entityhuman)) { return false; -@@ -1074,8 +1376,8 @@ +@@ -1074,8 +1377,8 @@ AbstractArrow entityarrow = (AbstractArrow) entity; Entity entity1 = entityarrow.getOwner(); @@ -703,7 +702,7 @@ if (!this.canHarmPlayer(entityhuman1)) { return false; -@@ -1083,38 +1385,78 @@ +@@ -1083,38 +1386,78 @@ } } @@ -790,7 +789,7 @@ } public static Optional findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) { -@@ -1129,11 +1471,11 @@ +@@ -1129,11 +1472,11 @@ } return optional.map((vec3d) -> { @@ -804,7 +803,7 @@ }); } else if (!spawnForced) { return Optional.empty(); -@@ -1142,7 +1484,7 @@ +@@ -1142,7 +1485,7 @@ BlockState iblockdata1 = world.getBlockState(pos.above()); boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1); @@ -813,7 +812,7 @@ } } -@@ -1160,6 +1502,7 @@ +@@ -1160,6 +1503,7 @@ @Nullable @Override public ServerPlayer teleport(TeleportTransition teleportTarget) { @@ -821,7 +820,7 @@ if (this.isRemoved()) { return null; } else { -@@ -1169,39 +1512,78 @@ +@@ -1169,39 +1513,78 @@ ServerLevel worldserver = teleportTarget.newLevel(); ServerLevel worldserver1 = this.serverLevel(); @@ -908,7 +907,7 @@ this.connection.resetPosition(); worldserver.addDuringTeleport(this); gameprofilerfiller.pop(); -@@ -1215,12 +1597,30 @@ +@@ -1215,12 +1598,30 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -939,7 +938,7 @@ public void forceSetRotation(float yaw, float pitch) { this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch)); } -@@ -1228,13 +1628,21 @@ +@@ -1228,13 +1629,21 @@ public void triggerDimensionChangeTriggers(ServerLevel origin) { ResourceKey resourcekey = origin.dimension(); ResourceKey resourcekey1 = this.level().dimension(); @@ -964,7 +963,7 @@ this.enteredNetherPosition = null; } -@@ -1251,36 +1659,63 @@ +@@ -1251,36 +1660,63 @@ this.containerMenu.broadcastChanges(); } @@ -1043,7 +1042,7 @@ this.awardStat(Stats.SLEEP_IN_BED); CriteriaTriggers.SLEPT_IN_BED.trigger(this); }); -@@ -1293,9 +1728,8 @@ +@@ -1293,9 +1729,8 @@ return either; } } @@ -1054,7 +1053,7 @@ } @Override -@@ -1322,13 +1756,31 @@ +@@ -1322,13 +1757,31 @@ @Override public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) { @@ -1087,7 +1086,7 @@ } } -@@ -1387,8 +1839,9 @@ +@@ -1387,8 +1840,9 @@ this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front)); } @@ -1098,7 +1097,7 @@ } @Override -@@ -1396,13 +1849,35 @@ +@@ -1396,13 +1850,35 @@ if (factory == null) { return OptionalInt.empty(); } else { @@ -1134,7 +1133,7 @@ if (container == null) { if (this.isSpectator()) { this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true); -@@ -1410,9 +1885,11 @@ +@@ -1410,9 +1886,11 @@ return OptionalInt.empty(); } else { @@ -1148,7 +1147,7 @@ return OptionalInt.of(this.containerCounter); } } -@@ -1425,15 +1902,26 @@ +@@ -1425,15 +1903,26 @@ @Override public void openHorseInventory(AbstractHorse horse, Container inventory) { @@ -1178,7 +1177,7 @@ this.initMenu(this.containerMenu); } -@@ -1456,6 +1944,13 @@ +@@ -1456,6 +1945,13 @@ @Override public void closeContainer() { @@ -1192,7 +1191,7 @@ this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId)); this.doCloseContainer(); } -@@ -1485,19 +1980,19 @@ +@@ -1485,19 +1981,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); @@ -1215,7 +1214,7 @@ } } else if (this.onClimbable()) { if (deltaY > 0.0D) { -@@ -1508,13 +2003,13 @@ +@@ -1508,13 +2004,13 @@ if (i > 0) { if (this.isSprinting()) { this.awardStat(Stats.SPRINT_ONE_CM, i); @@ -1232,7 +1231,7 @@ } } } else if (this.isFallFlying()) { -@@ -1557,7 +2052,7 @@ +@@ -1557,7 +2053,7 @@ @Override public void awardStat(Stat stat, int amount) { this.stats.increment(this, stat, amount); @@ -1241,7 +1240,7 @@ scoreaccess.add(amount); }); } -@@ -1565,7 +2060,7 @@ +@@ -1565,7 +2061,7 @@ @Override public void resetStat(Stat stat) { this.stats.setValue(this, stat, 0); @@ -1250,7 +1249,7 @@ } @Override -@@ -1597,9 +2092,9 @@ +@@ -1597,9 +2093,9 @@ super.jumpFromGround(); this.awardStat(Stats.JUMP); if (this.isSprinting()) { @@ -1262,7 +1261,7 @@ } } -@@ -1613,6 +2108,13 @@ +@@ -1613,6 +2109,13 @@ public void disconnect() { this.disconnected = true; this.ejectPassengers(); @@ -1276,7 +1275,7 @@ if (this.isSleeping()) { this.stopSleepInBed(true, false); } -@@ -1625,6 +2127,7 @@ +@@ -1625,6 +2128,7 @@ public void resetSentInfo() { this.lastSentHealth = -1.0E8F; @@ -1284,7 +1283,7 @@ } @Override -@@ -1661,7 +2164,7 @@ +@@ -1661,7 +2165,7 @@ this.onUpdateAbilities(); if (alive) { this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); @@ -1293,7 +1292,7 @@ this.setHealth(oldPlayer.getHealth()); this.foodData = oldPlayer.foodData; Iterator iterator = oldPlayer.getActiveEffects().iterator(); -@@ -1669,7 +2172,7 @@ +@@ -1669,7 +2173,7 @@ while (iterator.hasNext()) { MobEffectInstance mobeffect = (MobEffectInstance) iterator.next(); @@ -1302,7 +1301,7 @@ } this.getInventory().replaceWith(oldPlayer.getInventory()); -@@ -1680,7 +2183,7 @@ +@@ -1680,7 +2184,7 @@ this.portalProcess = oldPlayer.portalProcess; } else { this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); @@ -1311,7 +1310,7 @@ if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) { this.getInventory().replaceWith(oldPlayer.getInventory()); this.experienceLevel = oldPlayer.experienceLevel; -@@ -1696,7 +2199,7 @@ +@@ -1696,7 +2200,7 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -1320,7 +1319,7 @@ this.seenCredits = oldPlayer.seenCredits; this.enteredNetherPosition = oldPlayer.enteredNetherPosition; this.chunkTrackingView = oldPlayer.chunkTrackingView; -@@ -1752,19 +2255,19 @@ +@@ -1752,19 +2256,19 @@ } @Override @@ -1344,7 +1343,7 @@ } return flag1; -@@ -1861,8 +2364,13 @@ +@@ -1861,8 +2365,13 @@ } public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) { @@ -1359,7 +1358,7 @@ } } -@@ -1878,7 +2386,36 @@ +@@ -1878,7 +2387,36 @@ } public void updateOptions(ClientInformation clientOptions) { @@ -1396,7 +1395,7 @@ this.requestedViewDistance = clientOptions.viewDistance(); this.chatVisibility = clientOptions.chatVisibility(); this.canChatColor = clientOptions.chatColors(); -@@ -1957,12 +2494,27 @@ +@@ -1957,12 +2495,27 @@ this.camera = (Entity) (entity == null ? this : entity); if (entity1 != this.camera) { @@ -1425,7 +1424,7 @@ } if (entity != null) { -@@ -1999,11 +2551,11 @@ +@@ -1999,11 +2552,11 @@ @Nullable public Component getTabListDisplayName() { @@ -1439,7 +1438,7 @@ } @Override -@@ -2046,17 +2598,43 @@ +@@ -2046,17 +2599,43 @@ } public void setRespawnPosition(ResourceKey dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) { @@ -1490,7 +1489,7 @@ } else { this.respawnPosition = null; this.respawnDimension = Level.OVERWORLD; -@@ -2088,18 +2666,44 @@ +@@ -2088,18 +2667,44 @@ } @Override @@ -1539,7 +1538,7 @@ } this.awardStat(Stats.DROP); -@@ -2275,9 +2879,15 @@ +@@ -2275,9 +2880,15 @@ @Override public void stopRiding() { @@ -1556,7 +1555,7 @@ if (entity instanceof LivingEntity entityliving) { Iterator iterator = entityliving.getActiveEffects().iterator(); -@@ -2375,16 +2985,161 @@ +@@ -2375,10 +2986,12 @@ return TicketType.ENDER_PEARL.timeout(); } @@ -1572,11 +1571,10 @@ } private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) { - Vec3 vec3d1 = Vec3.atBottomCenterOf(currentPos).subtract(respawnPos).normalize(); - +@@ -2387,4 +3000,147 @@ 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; @@ -1601,7 +1599,7 @@ + public void setPlayerWeather(WeatherType type, boolean plugin) { + if (!plugin && this.weather != null) { + return; - } ++ } + + if (plugin) { + this.weather = type; @@ -1612,7 +1610,7 @@ + } else { + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0)); + } - } ++ } + + private float pluginRainPosition; + private float pluginRainPositionPrevious; diff --git a/paper-server/patches/sources/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch b/paper-server/patches/sources/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch index 3c23abd04..5851e690b 100644 --- a/paper-server/patches/sources/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch @@ -14,7 +14,7 @@ import net.minecraft.network.DisconnectionDetails; import net.minecraft.network.PacketSendListener; import net.minecraft.network.chat.Component; -@@ -22,39 +24,87 @@ +@@ -22,39 +24,88 @@ import net.minecraft.network.protocol.common.ServerboundPongPacket; import net.minecraft.network.protocol.common.ServerboundResourcePackPacket; import net.minecraft.network.protocol.cookie.ServerboundCookieResponsePacket; @@ -81,6 +81,7 @@ private volatile boolean suspendFlushingOnServerThread = false; + public final java.util.Map packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks + private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit ++ protected static final ResourceLocation MINECRAFT_BRAND = ResourceLocation.withDefaultNamespace("brand"); // Paper - Brand support - public ServerCommonPacketListenerImpl(MinecraftServer server, Connection connection, CommonListenerCookie clientData) { - this.server = server; @@ -110,7 +111,7 @@ private void close() { if (!this.closed) { this.closedListenerTime = Util.getMillis(); -@@ -80,13 +130,18 @@ +@@ -80,13 +131,18 @@ @Override public void handleKeepAlive(ServerboundKeepAlivePacket packet) { @@ -130,7 +131,7 @@ } } -@@ -94,8 +149,56 @@ +@@ -94,9 +150,71 @@ @Override public void handlePong(ServerboundPongPacket packet) {} @@ -141,13 +142,18 @@ @Override - public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {} + public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { ++ // Paper start - Brand support ++ if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload brandPayload) { ++ this.player.clientBrandName = brandPayload.brand(); ++ } ++ // Paper end - Brand support + if (!(packet.payload() instanceof DiscardedPayload)) { + return; + } + PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); + ResourceLocation identifier = packet.payload().type().id(); + ByteBuf payload = ((DiscardedPayload)packet.payload()).data(); -+ + + if (identifier.equals(ServerCommonPacketListenerImpl.CUSTOM_REGISTER)) { + try { + String channels = payload.toString(com.google.common.base.Charsets.UTF_8); @@ -172,6 +178,15 @@ + try { + byte[] data = new byte[payload.readableBytes()]; + payload.readBytes(data); ++ // Paper start - Brand support; Retain this incase upstream decides to 'break' the new mechanism in favour of backwards compat... ++ if (identifier.equals(MINECRAFT_BRAND)) { ++ try { ++ this.player.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.copiedBuffer(data)).readUtf(256); ++ } catch (StringIndexOutOfBoundsException ex) { ++ this.player.clientBrandName = "illegal"; ++ } ++ } ++ // Paper end - Brand support + this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), identifier.toString(), data); + } catch (Exception ex) { + ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex); @@ -185,10 +200,11 @@ + return (!this.player.joining && !this.connection.isConnected()) || this.processedDisconnect; // Paper - Fix duplication bugs + } + // CraftBukkit end - ++ @Override public void handleResourcePackResponse(ServerboundResourcePackPacket packet) { -@@ -104,28 +207,55 @@ + PacketUtils.ensureRunningOnSameThread(packet, this, (BlockableEventLoop) this.server); +@@ -104,28 +222,55 @@ ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), packet.id()); this.disconnect((Component) Component.translatable("multiplayer.requiredTexturePrompt.disconnect")); } @@ -250,7 +266,7 @@ Profiler.get().pop(); } -@@ -156,6 +286,14 @@ +@@ -156,6 +301,14 @@ } public void send(Packet packet, @Nullable PacketSendListener callbacks) { @@ -265,7 +281,7 @@ if (packet.isTerminal()) { this.close(); } -@@ -175,20 +313,72 @@ +@@ -175,20 +328,72 @@ } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 589c78cf8..42ee772b7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -3141,6 +3141,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player { // Paper end }; + // Paper start - brand support + @Override + public String getClientBrandName() { + return getHandle().clientBrandName; + } + // Paper end + public Player.Spigot spigot() { return this.spigot;