2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: MiniDigger <admin@minidigger.me>
|
|
|
|
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
|
2021-08-14 06:11:12 +02:00
|
|
|
index 0000000000000000000000000000000000000000..cedb51f9f3a9150035c2b44970a096448c441dd9
|
2021-06-11 14:02:28 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/ClientOption.java
|
2021-08-14 06:11:12 +02:00
|
|
|
@@ -0,0 +1,50 @@
|
2021-06-11 14:02:28 +02:00
|
|
|
+package com.destroystokyo.paper;
|
|
|
|
+
|
2021-08-14 06:11:12 +02:00
|
|
|
+import net.kyori.adventure.translation.Translatable;
|
|
|
|
+import net.kyori.adventure.util.Index;
|
2021-06-11 14:02:28 +02:00
|
|
|
+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);
|
|
|
|
+
|
|
|
|
+ private final Class<T> type;
|
|
|
|
+
|
|
|
|
+ private ClientOption(@NotNull Class<T> type) {
|
|
|
|
+ this.type = type;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public Class<T> getType() {
|
|
|
|
+ return type;
|
|
|
|
+ }
|
|
|
|
+
|
2021-08-14 06:11:12 +02:00
|
|
|
+ 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;
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
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..f7f171c4ee0b8339b2f8fbe82442d65f17202f28
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
|
|
|
|
@@ -0,0 +1,100 @@
|
|
|
|
+package com.destroystokyo.paper.event.player;
|
|
|
|
+
|
|
|
|
+import com.destroystokyo.paper.ClientOption;
|
|
|
|
+import com.destroystokyo.paper.ClientOption.ChatVisibility;
|
|
|
|
+import com.destroystokyo.paper.SkinParts;
|
|
|
|
+
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+
|
|
|
|
+import org.bukkit.entity.Player;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
|
|
|
+import org.bukkit.event.player.PlayerEvent;
|
|
|
|
+import org.bukkit.inventory.MainHand;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Called when the player changes his 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;
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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
|
2021-08-06 13:57:36 +02:00
|
|
|
index f42bf3bd0423850e7b7cba75b6c0d1d2c8421de0..768eca64aba4446fc341b71c12ff538169399f76 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/entity/Player.java
|
|
|
|
+++ b/src/main/java/org/bukkit/entity/Player.java
|
2021-08-06 13:57:36 +02:00
|
|
|
@@ -2,6 +2,7 @@ package org.bukkit.entity;
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.util.UUID;
|
|
|
|
+import com.destroystokyo.paper.ClientOption; // Paper
|
|
|
|
import com.destroystokyo.paper.Title; // Paper
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import com.destroystokyo.paper.profile.PlayerProfile; // Paper
|
2021-08-06 13:57:36 +02:00
|
|
|
@@ -2069,6 +2070,12 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
|
2021-06-11 14:02:28 +02:00
|
|
|
* 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 ClientOption<T> option);
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
// Spigot start
|