Add PlayerSettings API

This commit is contained in:
Leymooo
2018-08-25 15:22:09 +03:00
parent ebb1810392
commit 1b4c537c81
8 changed files with 188 additions and 19 deletions

View File

@@ -0,0 +1,24 @@
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.playersettings.PlayerSettings;
import com.velocitypowered.api.proxy.Player;
public class PlayerSettingsChangedEvent {
private final Player player;
private final PlayerSettings playerSettings;
public PlayerSettingsChangedEvent(Player player, PlayerSettings playerSettings) {
this.player = Preconditions.checkNotNull(player, "player");
this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings");
}
public Player getPlayer() {
return player;
}
//New settings
public PlayerSettings getPlayerSettings() {
return playerSettings;
}
}

View File

@@ -0,0 +1,29 @@
package com.velocitypowered.api.playersettings;
import java.util.Locale;
public interface PlayerSettings {
Locale getLocate();
byte getViewDistance();
ChatMode getChatMode();
boolean hasChatColors();
SkinParts getSkinParts();
MainHand getMainHand();
public enum ChatMode {
SHOWN,
COMMANDS_ONLY,
HIDDEN
}
public enum MainHand {
LEFT,
RIGHT
}
}

View File

@@ -0,0 +1,39 @@
package com.velocitypowered.api.playersettings;
public class SkinParts {
static final SkinParts SKIN_SHOW_ALL = new SkinParts((byte) 127);
private final byte bitmask;
public SkinParts(byte skinBitmask) {
this.bitmask = skinBitmask;
}
public boolean hasCape() {
return ((bitmask >> 0) & 1) == 1;
}
public boolean hasJacket() {
return ((bitmask >> 1) & 1) == 1;
}
public boolean hasLeftSleeve() {
return ((bitmask >> 2) & 1) == 1;
}
public boolean hasRightSleeve() {
return ((bitmask >> 3) & 1) == 1;
}
public boolean hasLeftPants() {
return ((bitmask >> 4) & 1) == 1;
}
public boolean hasRightPants() {
return ((bitmask >> 5) & 1) == 1;
}
public boolean hasHat() {
return ((bitmask >> 6) & 1) == 1;
}
}

View File

@@ -1,6 +1,7 @@
package com.velocitypowered.api.proxy;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.playersettings.PlayerSettings;
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
import com.velocitypowered.api.proxy.server.ServerInfo;
@@ -32,7 +33,9 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
* @return an {@link Optional} the server that the player is connected to, which may be empty
*/
Optional<ServerConnection> getCurrentServer();
PlayerSettings getPlayerSettings();
/**
* Sends a chat message to the player's client.
* @param component the chat message to send