Expand API to get all player sent settings

This commit is contained in:
Foorack 2017-08-09 16:38:03 +10:00 committed by md_5
parent da88d5c502
commit dbf20957a9
4 changed files with 202 additions and 0 deletions

View File

@ -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();
}

View File

@ -6,6 +6,7 @@ import java.util.UUID;
import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender; 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.Title;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.config.ServerInfo; 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 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. * Gets this player's display name.
* *
@ -142,6 +171,41 @@ public interface ProxiedPlayer extends Connection, CommandSender
*/ */
Locale getLocale(); 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. * Set the header and footer displayed in the tab player list.
* *

View File

@ -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;
}
}

View File

@ -27,6 +27,7 @@ import lombok.Setter;
import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.ProxyServer; 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.Title;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent; 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; 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 @Override
public boolean isForgeUser() public boolean isForgeUser()
{ {