Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
31699ae9a8
* Updated Upstream (Bukkit/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 Bukkit Changes: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
251 Zeilen
8.8 KiB
Diff
251 Zeilen
8.8 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..1757055d821d9ec7c728aa6c1b52fa6aea591ae5
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
|
|
@@ -0,0 +1,136 @@
|
|
+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.ApiStatus;
|
|
+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 HANDLER_LIST = 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;
|
|
+ }
|
|
+
|
|
+ @ApiStatus.Internal
|
|
+ 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 this.locale;
|
|
+ }
|
|
+
|
|
+ public boolean hasLocaleChanged() {
|
|
+ return !this.locale.equals(this.player.getClientOption(ClientOption.LOCALE));
|
|
+ }
|
|
+
|
|
+ public int getViewDistance() {
|
|
+ return this.viewDistance;
|
|
+ }
|
|
+
|
|
+ public boolean hasViewDistanceChanged() {
|
|
+ return this.viewDistance != this.player.getClientOption(ClientOption.VIEW_DISTANCE);
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public ChatVisibility getChatVisibility() {
|
|
+ return this.chatVisibility;
|
|
+ }
|
|
+
|
|
+ public boolean hasChatVisibilityChanged() {
|
|
+ return this.chatVisibility != this.player.getClientOption(ClientOption.CHAT_VISIBILITY);
|
|
+ }
|
|
+
|
|
+ public boolean hasChatColorsEnabled() {
|
|
+ return this.chatColors;
|
|
+ }
|
|
+
|
|
+ public boolean hasChatColorsEnabledChanged() {
|
|
+ return this.chatColors != this.player.getClientOption(ClientOption.CHAT_COLORS_ENABLED);
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public SkinParts getSkinParts() {
|
|
+ return this.skinparts;
|
|
+ }
|
|
+
|
|
+ public boolean hasSkinPartsChanged() {
|
|
+ return this.skinparts.getRaw() != this.player.getClientOption(ClientOption.SKIN_PARTS).getRaw();
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public MainHand getMainHand() {
|
|
+ return this.mainHand;
|
|
+ }
|
|
+
|
|
+ public boolean hasMainHandChanged() {
|
|
+ return this.mainHand != this.player.getClientOption(ClientOption.MAIN_HAND);
|
|
+ }
|
|
+
|
|
+ public boolean allowsServerListings() {
|
|
+ return this.allowsServerListings;
|
|
+ }
|
|
+
|
|
+ public boolean hasAllowServerListingsChanged() {
|
|
+ return this.allowsServerListings != this.player.getClientOption(ClientOption.ALLOW_SERVER_LISTINGS);
|
|
+ }
|
|
+
|
|
+ public boolean hasTextFilteringEnabled() {
|
|
+ return this.textFilteringEnabled;
|
|
+ }
|
|
+
|
|
+ public boolean hasTextFilteringChanged() {
|
|
+ return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ @NotNull
|
|
+ public HandlerList getHandlers() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
|
|
index 2778f72af5de5cd339a8648c5631ff94d5ee1352..06872dcef2d7f158ca3f25fb69b56511a0a1a90e 100644
|
|
--- a/src/main/java/org/bukkit/entity/Player.java
|
|
+++ b/src/main/java/org/bukkit/entity/Player.java
|
|
@@ -3214,6 +3214,13 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
|
|
void resetCooldown();
|
|
// Paper end - attack cooldown API
|
|
|
|
+ // Paper start - client option API
|
|
+ /**
|
|
+ * @return the client option value of the player
|
|
+ */
|
|
+ <T> @NotNull T getClientOption(com.destroystokyo.paper.@NotNull ClientOption<T> option);
|
|
+ // Paper end - client option API
|
|
+
|
|
// Spigot start
|
|
public class Spigot extends Entity.Spigot {
|
|
|