geforkt von Mirrors/Velocity
Add PlayerSettings API
Dieser Commit ist enthalten in:
Ursprung
ebb1810392
Commit
1b4c537c81
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.velocitypowered.api.proxy;
|
package com.velocitypowered.api.proxy;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
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.ChannelMessageSink;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
@ -33,6 +34,8 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
|||||||
*/
|
*/
|
||||||
Optional<ServerConnection> getCurrentServer();
|
Optional<ServerConnection> getCurrentServer();
|
||||||
|
|
||||||
|
PlayerSettings getPlayerSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat message to the player's client.
|
* Sends a chat message to the player's client.
|
||||||
* @param component the chat message to send
|
* @param component the chat message to send
|
||||||
|
@ -12,16 +12,12 @@ import com.velocitypowered.proxy.protocol.remap.EntityIdRemapper;
|
|||||||
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
|
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
|
||||||
import com.velocitypowered.proxy.util.ThrowableUtils;
|
import com.velocitypowered.proxy.util.ThrowableUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.EventLoop;
|
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
import net.kyori.text.format.TextColor;
|
import net.kyori.text.format.TextColor;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles communication with the connected Minecraft client. This is effectively the primary nerve center that
|
* Handles communication with the connected Minecraft client. This is effectively the primary nerve center that
|
||||||
@ -65,7 +61,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (packet instanceof ClientSettings) {
|
if (packet instanceof ClientSettings) {
|
||||||
player.setClientSettings((ClientSettings) packet);
|
player.setPlayerSettings((ClientSettings) packet);
|
||||||
// forward it on
|
// forward it on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.velocitypowered.proxy.connection.client;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.playersettings.PlayerSettings;
|
||||||
|
import com.velocitypowered.api.playersettings.SkinParts;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class ClientSettingsWrapper implements PlayerSettings {
|
||||||
|
|
||||||
|
public static PlayerSettings DEFAULT = new ClientSettingsWrapper(new ClientSettings("en_US", (byte) 10, 0, true, (short)127, 1));
|
||||||
|
|
||||||
|
private final ClientSettings settings;
|
||||||
|
private final SkinParts parts;
|
||||||
|
private Locale locale = null;
|
||||||
|
|
||||||
|
public ClientSettingsWrapper(ClientSettings settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
this.parts = new SkinParts((byte) settings.getSkinParts());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Locale getLocate() {
|
||||||
|
return locale == null ? locale = Locale.forLanguageTag(settings.getLocale().replaceAll("_", "-")) : locale; //Will throw error if locale not found
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getViewDistance() {
|
||||||
|
return settings.getViewDistance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatMode getChatMode() {
|
||||||
|
int chat = settings.getChatVisibility();
|
||||||
|
if (chat < 0 || chat > 2) {
|
||||||
|
return ChatMode.SHOWN;
|
||||||
|
}
|
||||||
|
return ChatMode.values()[chat];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasChatColors() {
|
||||||
|
return settings.isChatColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkinParts getSkinParts() {
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MainHand getMainHand() {
|
||||||
|
return settings.getMainHand() == 1 ? MainHand.RIGHT : MainHand.LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -2,9 +2,11 @@ package com.velocitypowered.proxy.connection.client;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||||
import com.velocitypowered.api.permission.PermissionFunction;
|
import com.velocitypowered.api.permission.PermissionFunction;
|
||||||
import com.velocitypowered.api.permission.PermissionProvider;
|
import com.velocitypowered.api.permission.PermissionProvider;
|
||||||
|
import com.velocitypowered.api.playersettings.PlayerSettings;
|
||||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
@ -55,6 +57,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
private VelocityServerConnection connectedServer;
|
private VelocityServerConnection connectedServer;
|
||||||
private ClientSettings clientSettings;
|
private ClientSettings clientSettings;
|
||||||
private VelocityServerConnection connectionInFlight;
|
private VelocityServerConnection connectionInFlight;
|
||||||
|
private PlayerSettings settings;
|
||||||
|
|
||||||
public ConnectedPlayer(GameProfile profile, MinecraftConnection connection, InetSocketAddress virtualHost) {
|
public ConnectedPlayer(GameProfile profile, MinecraftConnection connection, InetSocketAddress virtualHost) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
@ -85,6 +88,16 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlayerSettings getPlayerSettings() {
|
||||||
|
return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerSettings(ClientSettings settings) {
|
||||||
|
this.settings = new ClientSettingsWrapper(settings);
|
||||||
|
VelocityServer.getServer().getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, this.settings));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getRemoteAddress() {
|
public InetSocketAddress getRemoteAddress() {
|
||||||
return (InetSocketAddress) connection.getChannel().remoteAddress();
|
return (InetSocketAddress) connection.getChannel().remoteAddress();
|
||||||
@ -162,10 +175,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
return clientSettings;
|
return clientSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClientSettings(ClientSettings clientSettings) {
|
|
||||||
this.clientSettings = clientSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleConnectionException(ServerInfo info, Throwable throwable) {
|
public void handleConnectionException(ServerInfo info, Throwable throwable) {
|
||||||
String error = ThrowableUtils.briefDescription(throwable);
|
String error = ThrowableUtils.briefDescription(throwable);
|
||||||
String userMessage;
|
String userMessage;
|
||||||
|
@ -6,6 +6,7 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
public class ClientSettings implements MinecraftPacket {
|
public class ClientSettings implements MinecraftPacket {
|
||||||
|
|
||||||
private String locale;
|
private String locale;
|
||||||
private byte viewDistance;
|
private byte viewDistance;
|
||||||
private int chatVisibility;
|
private int chatVisibility;
|
||||||
@ -13,6 +14,18 @@ public class ClientSettings implements MinecraftPacket {
|
|||||||
private short skinParts;
|
private short skinParts;
|
||||||
private int mainHand;
|
private int mainHand;
|
||||||
|
|
||||||
|
public ClientSettings() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientSettings(String locale, byte viewDistance, int chatVisibility, boolean chatColors, short skinParts, int mainHand) {
|
||||||
|
this.locale = locale;
|
||||||
|
this.viewDistance = viewDistance;
|
||||||
|
this.chatVisibility = chatVisibility;
|
||||||
|
this.chatColors = chatColors;
|
||||||
|
this.skinParts = skinParts;
|
||||||
|
this.mainHand = mainHand;
|
||||||
|
}
|
||||||
|
|
||||||
public String getLocale() {
|
public String getLocale() {
|
||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
@ -63,14 +76,14 @@ public class ClientSettings implements MinecraftPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ClientSettings{" +
|
return "ClientSettings{"
|
||||||
"locale='" + locale + '\'' +
|
+ "locale='" + locale + '\''
|
||||||
", viewDistance=" + viewDistance +
|
+ ", viewDistance=" + viewDistance
|
||||||
", chatVisibility=" + chatVisibility +
|
+ ", chatVisibility=" + chatVisibility
|
||||||
", chatColors=" + chatColors +
|
+ ", chatColors=" + chatColors
|
||||||
", skinParts=" + skinParts +
|
+ ", skinParts=" + skinParts
|
||||||
", mainHand=" + mainHand +
|
+ ", mainHand=" + mainHand
|
||||||
'}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren