Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 20:40:07 +01:00
26734e83b0
* Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 8085edde SPIGOT-6918: Add SpawnCategory API and configurations for Axolotls 04c7e13c PR-719: Add Player Profile API 71564210 SPIGOT-6910: Add BlockDamageAbortEvent CraftBukkit Changes: febaa1c6 SPIGOT-6918: Add SpawnCategory API and configurations for Axolotls 9dafd109 Don't send updates over large distances bdac46b0 SPIGOT-6782: EntityPortalEvent should not destroy entity when setTo() uses same world as getFrom() 8f361ece PR-1002: Add Player Profile API 911875d4 Increase outdated build delay e5f8a767 SPIGOT-6917: Use main scoreboard for /trigger a672a531 Clean up callBlockDamageEvent 8e1bdeef SPIGOT-6910: Add BlockDamageAbortEvent Spigot Changes: 6edb62f3 Rebuild patches 7fbc6a1e Rebuild patches * Updated Upstream (CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing CraftBukkit Changes: de951355 SPIGOT-6927: Fix default value of spawn-limits in Worlds
153 Zeilen
6.8 KiB
Diff
153 Zeilen
6.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MiniDigger <admin@benndorf.dev>
|
|
Date: Mon, 20 Jan 2020 21:38:15 +0100
|
|
Subject: [PATCH] Implement Player Client Options API
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperSkinParts.java b/src/main/java/com/destroystokyo/paper/PaperSkinParts.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..b6f4400df3d8ec7e06a996de54f8cabba57885e1
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperSkinParts.java
|
|
@@ -0,0 +1,74 @@
|
|
+package com.destroystokyo.paper;
|
|
+
|
|
+import com.google.common.base.Objects;
|
|
+
|
|
+import java.util.StringJoiner;
|
|
+
|
|
+public class PaperSkinParts implements SkinParts {
|
|
+
|
|
+ private final int raw;
|
|
+
|
|
+ public PaperSkinParts(int raw) {
|
|
+ this.raw = raw;
|
|
+ }
|
|
+
|
|
+ public boolean hasCapeEnabled() {
|
|
+ return (raw & 1) == 1;
|
|
+ }
|
|
+
|
|
+ public boolean hasJacketEnabled() {
|
|
+ return (raw >> 1 & 1) == 1;
|
|
+ }
|
|
+
|
|
+ public boolean hasLeftSleeveEnabled() {
|
|
+ return (raw >> 2 & 1) == 1;
|
|
+ }
|
|
+
|
|
+ public boolean hasRightSleeveEnabled() {
|
|
+ return (raw >> 3 & 1) == 1;
|
|
+ }
|
|
+
|
|
+ public boolean hasLeftPantsEnabled() {
|
|
+ return (raw >> 4 & 1) == 1;
|
|
+ }
|
|
+
|
|
+ public boolean hasRightPantsEnabled() {
|
|
+ return (raw >> 5 & 1) == 1;
|
|
+ }
|
|
+
|
|
+ public boolean hasHatsEnabled() {
|
|
+ return (raw >> 6 & 1) == 1;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getRaw() {
|
|
+ return raw;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean equals(Object o) {
|
|
+ if (this == o) return true;
|
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
+ PaperSkinParts that = (PaperSkinParts) o;
|
|
+ return raw == that.raw;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int hashCode() {
|
|
+ return Objects.hashCode(raw);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String toString() {
|
|
+ return new StringJoiner(", ", PaperSkinParts.class.getSimpleName() + "[", "]")
|
|
+ .add("raw=" + raw)
|
|
+ .add("cape=" + hasCapeEnabled())
|
|
+ .add("jacket=" + hasJacketEnabled())
|
|
+ .add("leftSleeve=" + hasLeftSleeveEnabled())
|
|
+ .add("rightSleeve=" + hasRightSleeveEnabled())
|
|
+ .add("leftPants=" + hasLeftPantsEnabled())
|
|
+ .add("rightPants=" + hasRightPantsEnabled())
|
|
+ .add("hats=" + hasHatsEnabled())
|
|
+ .toString();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 9cbca14b0a111e57a1d01bcbcf2164ab8b53b1a5..cdb0eb8e21299ca70ed7ed5c1195d07f44e47838 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1830,6 +1830,7 @@ public class ServerPlayer extends Player {
|
|
public String locale = null; // CraftBukkit - add, lowercase // Paper - default to null
|
|
public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
|
|
public void updateOptions(ServerboundClientInformationPacket packet) {
|
|
+ new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(getBukkitEntity(), packet.language, packet.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packet.chatVisibility().name()), packet.chatColors(), new com.destroystokyo.paper.PaperSkinParts(packet.modelCustomisation()), packet.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT).callEvent(); // Paper - settings event
|
|
// CraftBukkit start
|
|
if (getMainArm() != packet.mainHand()) {
|
|
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 42062d64b7ea55f5360c435ef1953452d439029b..0a9d519596b074fd88fc3594d673189ef2c5e3d9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -551,6 +551,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
public void setSendViewDistance(int viewDistance) {
|
|
throw new NotImplementedException("Per-Player View Distance APIs need further understanding to properly implement (There are per world view distances though!)"); // TODO
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public <T> T getClientOption(com.destroystokyo.paper.ClientOption<T> type) {
|
|
+ if(com.destroystokyo.paper.ClientOption.SKIN_PARTS.equals(type)) {
|
|
+ return type.getType().cast(new com.destroystokyo.paper.PaperSkinParts(getHandle().getEntityData().get(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION)));
|
|
+ } else if(com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED.equals(type)) {
|
|
+ return type.getType().cast(getHandle().canChatInColor());
|
|
+ } else if(com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY.equals(type)) {
|
|
+ return type.getType().cast(getHandle().getChatVisibility() == null ? com.destroystokyo.paper.ClientOption.ChatVisibility.UNKNOWN : com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(getHandle().getChatVisibility().name()));
|
|
+ } else if(com.destroystokyo.paper.ClientOption.LOCALE.equals(type)) {
|
|
+ return type.getType().cast(getLocale());
|
|
+ } else if(com.destroystokyo.paper.ClientOption.MAIN_HAND.equals(type)) {
|
|
+ return type.getType().cast(getMainHand());
|
|
+ } else if(com.destroystokyo.paper.ClientOption.VIEW_DISTANCE.equals(type)) {
|
|
+ return type.getType().cast(getClientViewDistance());
|
|
+ }
|
|
+ throw new RuntimeException("Unknown settings type");
|
|
+ }
|
|
// Paper end
|
|
|
|
@Override
|
|
diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..6cd015dc5a2e012ac827c2b2d9aa5542b0591afb
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
@@ -0,0 +1,19 @@
|
|
+package io.papermc.paper.world;
|
|
+
|
|
+import com.destroystokyo.paper.ClientOption;
|
|
+import net.minecraft.network.chat.TranslatableComponent;
|
|
+import net.minecraft.world.entity.player.ChatVisiblity;
|
|
+import org.bukkit.Difficulty;
|
|
+import org.junit.Assert;
|
|
+import org.junit.Test;
|
|
+
|
|
+public class TranslationKeyTest {
|
|
+
|
|
+ @Test
|
|
+ public void testChatVisibilityKeys() {
|
|
+ for (ClientOption.ChatVisibility chatVisibility : ClientOption.ChatVisibility.values()) {
|
|
+ if (chatVisibility == ClientOption.ChatVisibility.UNKNOWN) continue;
|
|
+ Assert.assertEquals(chatVisibility + "'s translation key doesn't match", ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey());
|
|
+ }
|
|
+ }
|
|
+}
|