From dbf20957a9cd7c93ee6e08d3f255f49df2066d97 Mon Sep 17 00:00:00 2001 From: Foorack Date: Wed, 9 Aug 2017 16:38:03 +1000 Subject: [PATCH] Expand API to get all player sent settings --- .../md_5/bungee/api/SkinConfiguration.java | 24 +++++++ .../bungee/api/connection/ProxiedPlayer.java | 64 +++++++++++++++++ .../md_5/bungee/PlayerSkinConfiguration.java | 69 +++++++++++++++++++ .../java/net/md_5/bungee/UserConnection.java | 45 ++++++++++++ 4 files changed, 202 insertions(+) create mode 100644 api/src/main/java/net/md_5/bungee/api/SkinConfiguration.java create mode 100644 proxy/src/main/java/net/md_5/bungee/PlayerSkinConfiguration.java diff --git a/api/src/main/java/net/md_5/bungee/api/SkinConfiguration.java b/api/src/main/java/net/md_5/bungee/api/SkinConfiguration.java new file mode 100644 index 00000000..28448ef6 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/SkinConfiguration.java @@ -0,0 +1,24 @@ +package net.md_5.bungee.api; + +/** + * Represents a player's skin settings. These settings can be changed by the + * player under Skin Configuration in the Options menu. + */ +public interface SkinConfiguration +{ + + boolean hasCape(); + + boolean hasJacket(); + + boolean hasLeftSleeve(); + + boolean hasRightSleeve(); + + boolean hasLeftPants(); + + boolean hasRightPants(); + + boolean hasHat(); + +} diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index 375815c4..16cfff8b 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -6,6 +6,7 @@ import java.util.UUID; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.SkinConfiguration; import net.md_5.bungee.api.Title; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.config.ServerInfo; @@ -17,6 +18,34 @@ import net.md_5.bungee.api.config.ServerInfo; public interface ProxiedPlayer extends Connection, CommandSender { + /** + * Represents the player's chat state. + */ + public enum ChatMode + { + + /** + * The player will see all chat. + */ + SHOWN, + /** + * The player will only see everything except messages marked as chat. + */ + COMMANDS_ONLY, + /** + * The chat is completely disabled, the player won't see anything. + */ + HIDDEN; + + } + + public enum MainHand + { + + LEFT, + RIGHT; + } + /** * Gets this player's display name. * @@ -142,6 +171,41 @@ public interface ProxiedPlayer extends Connection, CommandSender */ Locale getLocale(); + /** + * Gets this player's view distance. + * + * @return the view distance, or a reasonable default + */ + byte getViewDistance(); + + /** + * Gets this player's chat mode. + * + * @return the chat flags set, or a reasonable default + */ + ChatMode getChatMode(); + + /** + * Gets if this player has chat colors enabled or disabled. + * + * @return if chat colors are enabled + */ + boolean hasChatColors(); + + /** + * Gets this player's skin settings. + * + * @return the players skin setting + */ + SkinConfiguration getSkinParts(); + + /** + * Gets this player's main hand setting. + * + * @return main hand setting + */ + MainHand getMainHand(); + /** * Set the header and footer displayed in the tab player list. * diff --git a/proxy/src/main/java/net/md_5/bungee/PlayerSkinConfiguration.java b/proxy/src/main/java/net/md_5/bungee/PlayerSkinConfiguration.java new file mode 100644 index 00000000..a5c4e88a --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/PlayerSkinConfiguration.java @@ -0,0 +1,69 @@ +package net.md_5.bungee; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import net.md_5.bungee.api.SkinConfiguration; + +/* + * Bitmask, displayed Skin Parts flags: + * + * Bit 0 (0x01 ): Cape enabled + * Bit 1 (0x02): Jacket enabled + * Bit 2 (0x04): Left Sleeve enabled + * Bit 3 (0x08): Right Sleeve enabled + * Bit 4 (0x10): Left Pants Leg enabled + * Bit 5 (0x20): Right Pants Leg enabled + * Bit 6 (0x40): Hat enabled + * The most significant bit (bit 7, 0x80) appears to be unused. + */ +@AllArgsConstructor(access = AccessLevel.PUBLIC) +public class PlayerSkinConfiguration implements SkinConfiguration +{ + + // 127 = 01111111 + static final SkinConfiguration SKIN_SHOW_ALL = new PlayerSkinConfiguration( (byte) 127 ); + // + private final byte bitmask; + + @Override + public boolean hasCape() + { + return ( ( bitmask >> 0 ) & 1 ) == 1; + } + + @Override + public boolean hasJacket() + { + return ( ( bitmask >> 1 ) & 1 ) == 1; + } + + @Override + public boolean hasLeftSleeve() + { + return ( ( bitmask >> 2 ) & 1 ) == 1; + } + + @Override + public boolean hasRightSleeve() + { + return ( ( bitmask >> 3 ) & 1 ) == 1; + } + + @Override + public boolean hasLeftPants() + { + return ( ( bitmask >> 4 ) & 1 ) == 1; + } + + @Override + public boolean hasRightPants() + { + return ( ( bitmask >> 5 ) & 1 ) == 1; + } + + @Override + public boolean hasHat() + { + return ( ( bitmask >> 6 ) & 1 ) == 1; + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index fb50dabe..a21b30c8 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -27,6 +27,7 @@ import lombok.Setter; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.SkinConfiguration; import net.md_5.bungee.api.Title; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; @@ -547,6 +548,50 @@ public final class UserConnection implements ProxiedPlayer return ( locale == null && settings != null ) ? locale = Locale.forLanguageTag( settings.getLocale().replaceAll( "_", "-" ) ) : locale; } + @Override + public byte getViewDistance() + { + return ( settings != null ) ? settings.getViewDistance() : 10; + } + + @Override + public ProxiedPlayer.ChatMode getChatMode() + { + if ( settings == null ) + { + return ProxiedPlayer.ChatMode.SHOWN; + } + + switch ( settings.getChatFlags() ) + { + default: + case 0: + return ProxiedPlayer.ChatMode.SHOWN; + case 1: + return ProxiedPlayer.ChatMode.COMMANDS_ONLY; + case 2: + return ProxiedPlayer.ChatMode.HIDDEN; + } + } + + @Override + public boolean hasChatColors() + { + return settings == null || settings.isChatColours(); + } + + @Override + public SkinConfiguration getSkinParts() + { + return ( settings != null ) ? new PlayerSkinConfiguration( settings.getSkinParts() ) : PlayerSkinConfiguration.SKIN_SHOW_ALL; + } + + @Override + public ProxiedPlayer.MainHand getMainHand() + { + return ( settings != null && settings.getMainHand() == 1 ) ? ProxiedPlayer.MainHand.RIGHT : ProxiedPlayer.MainHand.LEFT; + } + @Override public boolean isForgeUser() {