geforkt von Mirrors/Paper
efd47e3a68
* 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
248 Zeilen
8.6 KiB
Diff
248 Zeilen
8.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MiniDigger <admin@benndorf.dev>
|
|
Date: Mon, 20 Jan 2020 21:38:34 +0100
|
|
Subject: [PATCH] Add Player Client Options API
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/ClientOption.java b/src/main/java/com/destroystokyo/paper/ClientOption.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..f89bfeba29e6988db849957a508ca97ff5322242
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/ClientOption.java
|
|
@@ -0,0 +1,52 @@
|
|
+package com.destroystokyo.paper;
|
|
+
|
|
+import net.kyori.adventure.translation.Translatable;
|
|
+import net.kyori.adventure.util.Index;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+import org.bukkit.inventory.MainHand;
|
|
+
|
|
+public final class ClientOption<T> {
|
|
+
|
|
+ public static final ClientOption<SkinParts> SKIN_PARTS = new ClientOption<>(SkinParts.class);
|
|
+ public static final ClientOption<Boolean> CHAT_COLORS_ENABLED = new ClientOption<>(Boolean.class);
|
|
+ public static final ClientOption<ChatVisibility> CHAT_VISIBILITY = new ClientOption<>(ChatVisibility.class);
|
|
+ public static final ClientOption<String> LOCALE = new ClientOption<>(String.class);
|
|
+ public static final ClientOption<MainHand> MAIN_HAND = new ClientOption<>(MainHand.class);
|
|
+ public static final ClientOption<Integer> VIEW_DISTANCE = new ClientOption<>(Integer.class);
|
|
+ public static final ClientOption<Boolean> ALLOW_SERVER_LISTINGS = new ClientOption<>(Boolean.class);
|
|
+ public static final ClientOption<Boolean> TEXT_FILTERING_ENABLED = new ClientOption<>(Boolean.class);
|
|
+
|
|
+ private final Class<T> type;
|
|
+
|
|
+ private ClientOption(@NotNull Class<T> type) {
|
|
+ this.type = type;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public Class<T> getType() {
|
|
+ return type;
|
|
+ }
|
|
+
|
|
+ public enum ChatVisibility implements Translatable {
|
|
+ FULL("full"),
|
|
+ SYSTEM("system"),
|
|
+ HIDDEN("hidden"),
|
|
+ UNKNOWN("unknown");
|
|
+
|
|
+ public static Index<String, ChatVisibility> NAMES = Index.create(ChatVisibility.class, chatVisibility -> chatVisibility.name);
|
|
+ private final String name;
|
|
+
|
|
+ ChatVisibility(String name) {
|
|
+ this.name = name;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull String translationKey() {
|
|
+ if (this == UNKNOWN) {
|
|
+ throw new UnsupportedOperationException(this.name + " doesn't have a translation key");
|
|
+ }
|
|
+ return "options.chat.visibility." + this.name;
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/SkinParts.java b/src/main/java/com/destroystokyo/paper/SkinParts.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..4a0c39405d4fbed457787e3c6ded4cc6591bc8c2
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/SkinParts.java
|
|
@@ -0,0 +1,20 @@
|
|
+package com.destroystokyo.paper;
|
|
+
|
|
+public interface SkinParts {
|
|
+
|
|
+ boolean hasCapeEnabled();
|
|
+
|
|
+ boolean hasJacketEnabled();
|
|
+
|
|
+ boolean hasLeftSleeveEnabled();
|
|
+
|
|
+ boolean hasRightSleeveEnabled();
|
|
+
|
|
+ boolean hasLeftPantsEnabled();
|
|
+
|
|
+ boolean hasRightPantsEnabled();
|
|
+
|
|
+ boolean hasHatsEnabled();
|
|
+
|
|
+ int getRaw();
|
|
+}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..cf67dc7d465223710adbf2b798109f525d3b057d
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
|
|
@@ -0,0 +1,134 @@
|
|
+package com.destroystokyo.paper.event.player;
|
|
+
|
|
+import com.destroystokyo.paper.ClientOption;
|
|
+import com.destroystokyo.paper.ClientOption.ChatVisibility;
|
|
+import com.destroystokyo.paper.SkinParts;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.event.HandlerList;
|
|
+import org.bukkit.event.player.PlayerEvent;
|
|
+import org.bukkit.inventory.MainHand;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+import java.util.Map;
|
|
+
|
|
+/**
|
|
+ * Called when the player changes their client settings
|
|
+ */
|
|
+public class PlayerClientOptionsChangeEvent extends PlayerEvent {
|
|
+
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
+
|
|
+ private final String locale;
|
|
+ private final int viewDistance;
|
|
+ private final ChatVisibility chatVisibility;
|
|
+ private final boolean chatColors;
|
|
+ private final SkinParts skinparts;
|
|
+ private final MainHand mainHand;
|
|
+ private final boolean allowsServerListings;
|
|
+ private final boolean textFilteringEnabled;
|
|
+
|
|
+ @Deprecated
|
|
+ public PlayerClientOptionsChangeEvent(@NotNull Player player, @NotNull String locale, int viewDistance, @NotNull ChatVisibility chatVisibility, boolean chatColors, @NotNull SkinParts skinParts, @NotNull MainHand mainHand) {
|
|
+ super(player);
|
|
+ this.locale = locale;
|
|
+ this.viewDistance = viewDistance;
|
|
+ this.chatVisibility = chatVisibility;
|
|
+ this.chatColors = chatColors;
|
|
+ this.skinparts = skinParts;
|
|
+ this.mainHand = mainHand;
|
|
+ this.allowsServerListings = false;
|
|
+ this.textFilteringEnabled = false;
|
|
+ }
|
|
+
|
|
+ public PlayerClientOptionsChangeEvent(@NotNull Player player, @NotNull Map<ClientOption<?>, ?> options) {
|
|
+ super(player);
|
|
+
|
|
+ this.locale = (String) options.get(ClientOption.LOCALE);
|
|
+ this.viewDistance = (int) options.get(ClientOption.VIEW_DISTANCE);
|
|
+ this.chatVisibility = (ChatVisibility) options.get(ClientOption.CHAT_VISIBILITY);
|
|
+ this.chatColors = (boolean) options.get(ClientOption.CHAT_COLORS_ENABLED);
|
|
+ this.skinparts = (SkinParts) options.get(ClientOption.SKIN_PARTS);
|
|
+ this.mainHand = (MainHand) options.get(ClientOption.MAIN_HAND);
|
|
+ this.allowsServerListings = (boolean) options.get(ClientOption.ALLOW_SERVER_LISTINGS);
|
|
+ this.textFilteringEnabled = (boolean) options.get(ClientOption.TEXT_FILTERING_ENABLED);
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public String getLocale() {
|
|
+ return locale;
|
|
+ }
|
|
+
|
|
+ public boolean hasLocaleChanged() {
|
|
+ return !locale.equals(player.getClientOption(ClientOption.LOCALE));
|
|
+ }
|
|
+
|
|
+ public int getViewDistance() {
|
|
+ return viewDistance;
|
|
+ }
|
|
+
|
|
+ public boolean hasViewDistanceChanged() {
|
|
+ return viewDistance != player.getClientOption(ClientOption.VIEW_DISTANCE);
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public ChatVisibility getChatVisibility() {
|
|
+ return chatVisibility;
|
|
+ }
|
|
+
|
|
+ public boolean hasChatVisibilityChanged() {
|
|
+ return chatVisibility != player.getClientOption(ClientOption.CHAT_VISIBILITY);
|
|
+ }
|
|
+
|
|
+ public boolean hasChatColorsEnabled() {
|
|
+ return chatColors;
|
|
+ }
|
|
+
|
|
+ public boolean hasChatColorsEnabledChanged() {
|
|
+ return chatColors != player.getClientOption(ClientOption.CHAT_COLORS_ENABLED);
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public SkinParts getSkinParts() {
|
|
+ return skinparts;
|
|
+ }
|
|
+
|
|
+ public boolean hasSkinPartsChanged() {
|
|
+ return skinparts.getRaw() != player.getClientOption(ClientOption.SKIN_PARTS).getRaw();
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public MainHand getMainHand() {
|
|
+ return mainHand;
|
|
+ }
|
|
+
|
|
+ public boolean hasMainHandChanged() {
|
|
+ return mainHand != player.getClientOption(ClientOption.MAIN_HAND);
|
|
+ }
|
|
+
|
|
+ public boolean allowsServerListings() {
|
|
+ return allowsServerListings;
|
|
+ }
|
|
+
|
|
+ public boolean hasAllowServerListingsChanged() {
|
|
+ return allowsServerListings != player.getClientOption(ClientOption.ALLOW_SERVER_LISTINGS);
|
|
+ }
|
|
+
|
|
+ public boolean hasTextFilteringEnabled() {
|
|
+ return textFilteringEnabled;
|
|
+ }
|
|
+
|
|
+ public boolean hasTextFilteringChanged() {
|
|
+ return textFilteringEnabled != player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ @NotNull
|
|
+ public HandlerList getHandlers() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return handlers;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
|
|
index 23ded8a67663d887f636a2b04d7a7afb86ead22c..75c15bf4ad598fabc0b9598ab7a0bb57afa61111 100644
|
|
--- a/src/main/java/org/bukkit/entity/Player.java
|
|
+++ b/src/main/java/org/bukkit/entity/Player.java
|
|
@@ -2642,6 +2642,12 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
|
|
* Reset the cooldown counter to 0, effectively starting the cooldown period.
|
|
*/
|
|
void resetCooldown();
|
|
+
|
|
+ /**
|
|
+ * @return the client option value of the player
|
|
+ */
|
|
+ @NotNull
|
|
+ <T> T getClientOption(@NotNull com.destroystokyo.paper.ClientOption<T> option);
|
|
// Paper end
|
|
|
|
// Spigot start
|