Minecraft 1.16 support + RGB ChatColor preview

This commit is contained in:
md_5 2020-06-24 07:00:00 +10:00
parent 2f54c94372
commit d0fd673b60
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
36 changed files with 760 additions and 227 deletions

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-API</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-bootstrap</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Bootstrap</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Chat</name>

View File

@ -1,122 +1,126 @@
package net.md_5.bungee.api;
import com.google.common.base.Preconditions;
import java.awt.Color;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import lombok.Getter;
/**
* Simplistic enumeration of all supported color values for chat.
*/
public enum ChatColor
public final class ChatColor
{
/**
* Represents black.
*/
BLACK( '0', "black" ),
/**
* Represents dark blue.
*/
DARK_BLUE( '1', "dark_blue" ),
/**
* Represents dark green.
*/
DARK_GREEN( '2', "dark_green" ),
/**
* Represents dark blue (aqua).
*/
DARK_AQUA( '3', "dark_aqua" ),
/**
* Represents dark red.
*/
DARK_RED( '4', "dark_red" ),
/**
* Represents dark purple.
*/
DARK_PURPLE( '5', "dark_purple" ),
/**
* Represents gold.
*/
GOLD( '6', "gold" ),
/**
* Represents gray.
*/
GRAY( '7', "gray" ),
/**
* Represents dark gray.
*/
DARK_GRAY( '8', "dark_gray" ),
/**
* Represents blue.
*/
BLUE( '9', "blue" ),
/**
* Represents green.
*/
GREEN( 'a', "green" ),
/**
* Represents aqua.
*/
AQUA( 'b', "aqua" ),
/**
* Represents red.
*/
RED( 'c', "red" ),
/**
* Represents light purple.
*/
LIGHT_PURPLE( 'd', "light_purple" ),
/**
* Represents yellow.
*/
YELLOW( 'e', "yellow" ),
/**
* Represents white.
*/
WHITE( 'f', "white" ),
/**
* Represents magical characters that change around randomly.
*/
MAGIC( 'k', "obfuscated" ),
/**
* Makes the text bold.
*/
BOLD( 'l', "bold" ),
/**
* Makes a line appear through the text.
*/
STRIKETHROUGH( 'm', "strikethrough" ),
/**
* Makes the text appear underlined.
*/
UNDERLINE( 'n', "underline" ),
/**
* Makes the text italic.
*/
ITALIC( 'o', "italic" ),
/**
* Resets all previous chat colors or formats.
*/
RESET( 'r', "reset" );
/**
* The special character which prefixes all chat colour codes. Use this if
* you need to dynamically convert colour codes from your custom format.
*/
public static final char COLOR_CHAR = '\u00A7';
public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRr";
public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx";
/**
* Pattern to remove all colour codes.
*/
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile( "(?i)" + String.valueOf( COLOR_CHAR ) + "[0-9A-FK-OR]" );
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile( "(?i)" + String.valueOf( COLOR_CHAR ) + "[0-9A-FK-ORX]" );
/**
* Colour instances keyed by their active character.
*/
private static final Map<Character, ChatColor> BY_CHAR = new HashMap<Character, ChatColor>();
/**
* The code appended to {@link #COLOR_CHAR} to make usable colour.
* Colour instances keyed by their name.
*/
private final char code;
private static final Map<String, ChatColor> BY_NAME = new HashMap<String, ChatColor>();
/**
* Represents black.
*/
public static final ChatColor BLACK = new ChatColor( '0', "black" );
/**
* Represents dark blue.
*/
public static final ChatColor DARK_BLUE = new ChatColor( '1', "dark_blue" );
/**
* Represents dark green.
*/
public static final ChatColor DARK_GREEN = new ChatColor( '2', "dark_green" );
/**
* Represents dark blue (aqua).
*/
public static final ChatColor DARK_AQUA = new ChatColor( '3', "dark_aqua" );
/**
* Represents dark red.
*/
public static final ChatColor DARK_RED = new ChatColor( '4', "dark_red" );
/**
* Represents dark purple.
*/
public static final ChatColor DARK_PURPLE = new ChatColor( '5', "dark_purple" );
/**
* Represents gold.
*/
public static final ChatColor GOLD = new ChatColor( '6', "gold" );
/**
* Represents gray.
*/
public static final ChatColor GRAY = new ChatColor( '7', "gray" );
/**
* Represents dark gray.
*/
public static final ChatColor DARK_GRAY = new ChatColor( '8', "dark_gray" );
/**
* Represents blue.
*/
public static final ChatColor BLUE = new ChatColor( '9', "blue" );
/**
* Represents green.
*/
public static final ChatColor GREEN = new ChatColor( 'a', "green" );
/**
* Represents aqua.
*/
public static final ChatColor AQUA = new ChatColor( 'b', "aqua" );
/**
* Represents red.
*/
public static final ChatColor RED = new ChatColor( 'c', "red" );
/**
* Represents light purple.
*/
public static final ChatColor LIGHT_PURPLE = new ChatColor( 'd', "light_purple" );
/**
* Represents yellow.
*/
public static final ChatColor YELLOW = new ChatColor( 'e', "yellow" );
/**
* Represents white.
*/
public static final ChatColor WHITE = new ChatColor( 'f', "white" );
/**
* Represents magical characters that change around randomly.
*/
public static final ChatColor MAGIC = new ChatColor( 'k', "obfuscated" );
/**
* Makes the text bold.
*/
public static final ChatColor BOLD = new ChatColor( 'l', "bold" );
/**
* Makes a line appear through the text.
*/
public static final ChatColor STRIKETHROUGH = new ChatColor( 'm', "strikethrough" );
/**
* Makes the text appear underlined.
*/
public static final ChatColor UNDERLINE = new ChatColor( 'n', "underline" );
/**
* Makes the text italic.
*/
public static final ChatColor ITALIC = new ChatColor( 'o', "italic" );
/**
* Resets all previous chat colors or formats.
*/
public static final ChatColor RESET = new ChatColor( 'r', "reset" );
/**
* This colour's colour char prefixed by the {@link #COLOR_CHAR}.
*/
@ -124,22 +128,46 @@ public enum ChatColor
@Getter
private final String name;
static
{
for ( ChatColor colour : values() )
{
BY_CHAR.put( colour.code, colour );
}
}
private ChatColor(char code, String name)
{
this.code = code;
this.name = name;
this.toString = new String( new char[]
{
COLOR_CHAR, code
} );
BY_CHAR.put( code, this );
BY_NAME.put( name.toUpperCase( Locale.ROOT ), this );
}
private ChatColor(String name, String toString)
{
this.name = name;
this.toString = toString;
}
@Override
public int hashCode()
{
int hash = 7;
hash = 53 * hash + Objects.hashCode( this.toString );
return hash;
}
@Override
public boolean equals(Object obj)
{
if ( this == obj )
{
return true;
}
if ( obj == null || getClass() != obj.getClass() )
{
return false;
}
final ChatColor other = (ChatColor) obj;
return Objects.equals( this.toString, other.toString );
}
@Override
@ -188,4 +216,82 @@ public enum ChatColor
{
return BY_CHAR.get( code );
}
public static ChatColor of(Color color)
{
return of( "#" + Integer.toHexString( color.getRGB() ).substring( 2 ) );
}
public static ChatColor of(String string)
{
Preconditions.checkArgument( string != null, "string cannot be null" );
if ( string.startsWith( "#" ) && string.length() == 7 )
{
try
{
Integer.parseInt( string.substring( 1 ), 16 );
} catch ( NumberFormatException ex )
{
throw new IllegalArgumentException( "Illegal hex string " + string );
}
StringBuilder magic = new StringBuilder( COLOR_CHAR + "x" );
for ( char c : string.substring( 1 ).toCharArray() )
{
magic.append( COLOR_CHAR ).append( c );
}
return new ChatColor( string, magic.toString() );
}
ChatColor defined = BY_NAME.get( string.toUpperCase( Locale.ROOT ) );
if ( defined != null )
{
return defined;
}
throw new IllegalArgumentException( "Could not parse ChatColor " + string );
}
/**
* See {@link Enum#valueOf(java.lang.Class, java.lang.String)}.
*
* @param name color name
* @return ChatColor
* @deprecated holdover from when this class was an enum
*/
@Deprecated
public static ChatColor valueOf(String name)
{
Preconditions.checkNotNull( name, "Name is null" );
ChatColor defined = BY_NAME.get( name );
Preconditions.checkArgument( defined != null, "No enum constant " + ChatColor.class.getName() + "." + name );
return defined;
}
/**
* Get an array of all defined colors and formats.
*
* @return copied array of all colors and formats
* @deprecated holdover from when this class was an enum
*/
@Deprecated
public ChatColor[] values()
{
return BY_CHAR.values().toArray( new ChatColor[ BY_CHAR.values().size() ] );
}
/**
* See {@link Enum#name()}.
*
* @return constant name
* @deprecated holdover from when this class was an enum
*/
@Deprecated
public String name()
{
return getName().toUpperCase( Locale.ROOT );
}
}

View File

@ -23,6 +23,10 @@ public abstract class BaseComponent
* The color of this component and any child components (unless overridden)
*/
private ChatColor color;
/**
* The font of this component and any child components (unless overridden)
*/
private String font;
/**
* Whether this component and any child components (unless overridden) is
* bold
@ -147,6 +151,10 @@ public abstract class BaseComponent
{
setColor( component.getColorRaw() );
}
if ( replace || font == null )
{
setFont( component.getFontRaw() );
}
if ( replace || bold == null )
{
setBold( component.isBoldRaw() );
@ -283,6 +291,36 @@ public abstract class BaseComponent
return color;
}
/**
* Returns the font of this component. This uses the parent's font if this
* component doesn't have one.
*
* @return the font of this component, or null if default font
*/
public String getFont()
{
if ( color == null )
{
if ( parent == null )
{
return null;
}
return parent.getFont();
}
return font;
}
/**
* Returns the font of this component without checking the parents font. May
* return null
*
* @return the font of this component
*/
public String getFontRaw()
{
return font;
}
/**
* Returns whether this component is bold. This uses the parent's setting if
* this component hasn't been set. false is returned if none of the parent
@ -461,7 +499,7 @@ public abstract class BaseComponent
*/
public boolean hasFormatting()
{
return color != null || bold != null
return color != null || font != null || bold != null
|| italic != null || underlined != null
|| strikethrough != null || obfuscated != null
|| insertion != null || hoverEvent != null || clickEvent != null;

View File

@ -63,7 +63,27 @@ public final class TextComponent extends BaseComponent
{
c += 32;
}
ChatColor format = ChatColor.getByChar( c );
ChatColor format;
if ( c == 'x' && i + 12 < message.length() )
{
StringBuilder hex = new StringBuilder( "#" );
for ( int j = 0; j < 6; j++ )
{
hex.append( message.charAt( i + 2 + ( j * 2 ) ) );
}
try
{
format = ChatColor.of( hex.toString() );
} catch ( IllegalArgumentException ex )
{
format = null;
}
i += 12;
} else
{
format = ChatColor.getByChar( c );
}
if ( format == null )
{
continue;
@ -76,29 +96,30 @@ public final class TextComponent extends BaseComponent
builder = new StringBuilder();
components.add( old );
}
switch ( format )
if ( format == ChatColor.BOLD )
{
case BOLD:
component.setBold( true );
break;
case ITALIC:
component.setItalic( true );
break;
case UNDERLINE:
component.setUnderlined( true );
break;
case STRIKETHROUGH:
component.setStrikethrough( true );
break;
case MAGIC:
component.setObfuscated( true );
break;
case RESET:
format = defaultColor;
default:
component = new TextComponent();
component.setColor( format );
break;
component.setBold( true );
} else if ( format == ChatColor.ITALIC )
{
component.setItalic( true );
} else if ( format == ChatColor.UNDERLINE )
{
component.setUnderlined( true );
} else if ( format == ChatColor.STRIKETHROUGH )
{
component.setStrikethrough( true );
} else if ( format == ChatColor.MAGIC )
{
component.setObfuscated( true );
} else if ( format == ChatColor.RESET )
{
format = defaultColor;
component = new TextComponent();
component.setColor( format );
} else
{
component = new TextComponent();
component.setColor( format );
}
continue;
}

View File

@ -20,7 +20,11 @@ public class BaseComponentSerializer
{
if ( object.has( "color" ) )
{
component.setColor( ChatColor.valueOf( object.get( "color" ).getAsString().toUpperCase( Locale.ROOT ) ) );
component.setColor( ChatColor.of( object.get( "color" ).getAsString() ) );
}
if ( object.has( "font" ) )
{
component.setFont( object.get( "font" ).getAsString() );
}
if ( object.has( "bold" ) )
{
@ -93,6 +97,10 @@ public class BaseComponentSerializer
{
object.addProperty( "color", component.getColorRaw().getName() );
}
if ( component.getFontRaw() != null )
{
object.addProperty( "font", component.getFontRaw() );
}
if ( component.isBoldRaw() != null )
{
object.addProperty( "bold", component.isBoldRaw() );

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -433,6 +434,17 @@ public class ComponentsTest
Assert.assertNotEquals( first, second );
}
@Test
public void testLegacyHack()
{
BaseComponent[] hexColored = new ComponentBuilder().color( ChatColor.of( Color.GRAY ) ).append( "Test" ).create();
String legacy = TextComponent.toLegacyText( hexColored );
BaseComponent[] reColored = TextComponent.fromLegacyText( legacy );
Assert.assertArrayEquals( hexColored, reColored );
}
private String fromAndToLegacyText(String legacyText)
{
return BaseComponent.toLegacyText( TextComponent.fromLegacyText( legacyText ) );

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-config</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Config</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-event</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Event</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-log</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Log</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-alert</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cmd_alert</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-find</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cmd_find</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-list</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cmd_list</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-send</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cmd_send</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-server</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cmd_server</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>BungeeCord Modules</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module-reconnect-yaml</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>reconnect_yaml</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-native</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Native</name>

View File

@ -5,7 +5,7 @@
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>BungeeCord-Parent</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-protocol</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Protocol</name>
@ -58,5 +58,11 @@
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>se.llbit</groupId>
<artifactId>jo-nbt</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -67,21 +67,24 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_9, 0x1F ),
map( ProtocolConstants.MINECRAFT_1_13, 0x21 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x20 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x21 )
map( ProtocolConstants.MINECRAFT_1_15, 0x21 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x20 )
);
TO_CLIENT.registerPacket(
Login.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x23 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x25 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x26 )
map( ProtocolConstants.MINECRAFT_1_15, 0x26 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x25 )
);
TO_CLIENT.registerPacket(
Chat.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0F ),
map( ProtocolConstants.MINECRAFT_1_13, 0x0E ),
map( ProtocolConstants.MINECRAFT_1_15, 0x0F )
map( ProtocolConstants.MINECRAFT_1_15, 0x0F ),
map( ProtocolConstants.MINECRAFT_1_16, 0x0E )
);
TO_CLIENT.registerPacket(
Respawn.class,
@ -91,12 +94,14 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_12_1, 0x35 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x38 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x3A ),
map( ProtocolConstants.MINECRAFT_1_15, 0x3B )
map( ProtocolConstants.MINECRAFT_1_15, 0x3B ),
map( ProtocolConstants.MINECRAFT_1_16, 0x3A )
);
TO_CLIENT.registerPacket(
BossBar.class,
map( ProtocolConstants.MINECRAFT_1_9, 0x0C ),
map( ProtocolConstants.MINECRAFT_1_15, 0x0D )
map( ProtocolConstants.MINECRAFT_1_15, 0x0D ),
map( ProtocolConstants.MINECRAFT_1_16, 0x0C )
);
TO_CLIENT.registerPacket(
PlayerListItem.class, // PlayerInfo
@ -105,14 +110,16 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_12_1, 0x2E ),
map( ProtocolConstants.MINECRAFT_1_13, 0x30 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x33 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x34 )
map( ProtocolConstants.MINECRAFT_1_15, 0x34 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x33 )
);
TO_CLIENT.registerPacket(
TabCompleteResponse.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x3A ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0E ),
map( ProtocolConstants.MINECRAFT_1_13, 0x10 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x11 )
map( ProtocolConstants.MINECRAFT_1_15, 0x11 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x10 )
);
TO_CLIENT.registerPacket(
ScoreboardObjective.class,
@ -160,7 +167,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_9, 0x18 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x19 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x18 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x19 )
map( ProtocolConstants.MINECRAFT_1_15, 0x19 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x18 )
);
TO_CLIENT.registerPacket(
Kick.class,
@ -168,7 +176,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_9, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_13, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_14, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_15, 0x1B )
map( ProtocolConstants.MINECRAFT_1_15, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_16, 0x1A )
);
TO_CLIENT.registerPacket(
Title.class,
@ -177,7 +186,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_12_1, 0x48 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x4B ),
map( ProtocolConstants.MINECRAFT_1_14, 0x4F ),
map( ProtocolConstants.MINECRAFT_1_15, 0x50 )
map( ProtocolConstants.MINECRAFT_1_15, 0x50 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x4F )
);
TO_CLIENT.registerPacket(
PlayerListHeaderFooter.class,
@ -188,7 +198,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_12_1, 0x4A ),
map( ProtocolConstants.MINECRAFT_1_13, 0x4E ),
map( ProtocolConstants.MINECRAFT_1_14, 0x53 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x54 )
map( ProtocolConstants.MINECRAFT_1_15, 0x54 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x53 )
);
TO_CLIENT.registerPacket(
EntityStatus.class,
@ -196,21 +207,25 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_9, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_13, 0x1C ),
map( ProtocolConstants.MINECRAFT_1_14, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_15, 0x1C )
map( ProtocolConstants.MINECRAFT_1_15, 0x1C ),
map( ProtocolConstants.MINECRAFT_1_16, 0x1B )
);
TO_CLIENT.registerPacket(
Commands.class,
map( ProtocolConstants.MINECRAFT_1_13, 0x11 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x12 )
map( ProtocolConstants.MINECRAFT_1_15, 0x12 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x11 )
);
TO_CLIENT.registerPacket(
GameState.class,
map( ProtocolConstants.MINECRAFT_1_15, 0x1F )
map( ProtocolConstants.MINECRAFT_1_15, 0x1F ),
map( ProtocolConstants.MINECRAFT_1_16, 0x1E )
);
TO_CLIENT.registerPacket(
ViewDistance.class,
map( ProtocolConstants.MINECRAFT_1_14, 0x41 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x42 )
map( ProtocolConstants.MINECRAFT_1_15, 0x42 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x41 )
);
TO_SERVER.registerPacket(
@ -220,7 +235,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_12, 0x0C ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x0B ),
map( ProtocolConstants.MINECRAFT_1_13, 0x0E ),
map( ProtocolConstants.MINECRAFT_1_14, 0x0F )
map( ProtocolConstants.MINECRAFT_1_14, 0x0F ),
map( ProtocolConstants.MINECRAFT_1_16, 0x10 )
);
TO_SERVER.registerPacket(
Chat.class,

View File

@ -28,6 +28,7 @@ public class ProtocolConstants
public static final int MINECRAFT_1_15 = 573;
public static final int MINECRAFT_1_15_1 = 575;
public static final int MINECRAFT_1_15_2 = 578;
public static final int MINECRAFT_1_16 = 735;
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
"1.8.x",
"1.9.x",
@ -36,7 +37,8 @@ public class ProtocolConstants
"1.12.x",
"1.13.x",
"1.14.x",
"1.15.x"
"1.15.x",
"1.16.x"
);
public static final List<Integer> SUPPORTED_VERSION_IDS = Arrays.asList(
ProtocolConstants.MINECRAFT_1_8,
@ -60,7 +62,8 @@ public class ProtocolConstants
ProtocolConstants.MINECRAFT_1_14_4,
ProtocolConstants.MINECRAFT_1_15,
ProtocolConstants.MINECRAFT_1_15_1,
ProtocolConstants.MINECRAFT_1_15_2
ProtocolConstants.MINECRAFT_1_15_2,
ProtocolConstants.MINECRAFT_1_16
);
public enum Direction

View File

@ -1,6 +1,7 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -16,14 +17,21 @@ import net.md_5.bungee.protocol.ProtocolConstants;
public class Chat extends DefinedPacket
{
private static final UUID EMPTY_UUID = new UUID( 0L, 0L );
private String message;
private byte position;
private UUID sender;
public Chat(String message)
{
this( message, (byte) 0 );
}
public Chat(String message, byte position)
{
this( message, position, EMPTY_UUID );
}
@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
@ -31,6 +39,10 @@ public class Chat extends DefinedPacket
if ( direction == ProtocolConstants.Direction.TO_CLIENT )
{
position = buf.readByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
sender = readUUID( buf );
}
}
}
@ -41,6 +53,10 @@ public class Chat extends DefinedPacket
if ( direction == ProtocolConstants.Direction.TO_CLIENT )
{
buf.writeByte( position );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
writeUUID( sender, buf );
}
}
}

View File

@ -547,6 +547,9 @@ public class Commands extends DefinedPacket
PROVIDERS.put( "minecraft:entity_summon", VOID );
PROVIDERS.put( "minecraft:dimension", VOID );
PROVIDERS.put( "minecraft:time", VOID ); // 1.14
PROVIDERS.put( "minecraft:uuid", VOID ); // 1.16
PROVIDERS.put( "minecraft:test_argument", VOID ); // 1.16, debug
PROVIDERS.put( "minecraft:test_class", VOID ); // 1.16, debug
}
private static ArgumentType<?> read(String key, ByteBuf buf)
@ -617,6 +620,7 @@ public class Commands extends DefinedPacket
PROVIDERS.put( "minecraft:ask_server", ASK_SERVER );
registerDummy( "minecraft:all_recipes" );
registerDummy( "minecraft:available_sounds" );
registerDummy( "minecraft:available_biomes" );
registerDummy( "minecraft:summonable_entities" );
}

View File

@ -1,6 +1,14 @@
package net.md_5.bungee.protocol.packet;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -8,6 +16,8 @@ import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import se.llbit.nbt.NamedTag;
import se.llbit.nbt.Tag;
@Data
@NoArgsConstructor
@ -18,7 +28,11 @@ public class Login extends DefinedPacket
private int entityId;
private short gameMode;
private int dimension;
private short previousGameMode;
private Set<String> worldNames;
private Tag dimensions;
private Object dimension;
private String worldName;
private long seed;
private short difficulty;
private short maxPlayers;
@ -26,13 +40,36 @@ public class Login extends DefinedPacket
private int viewDistance;
private boolean reducedDebugInfo;
private boolean normalRespawn;
private boolean debug;
private boolean flat;
@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
entityId = buf.readInt();
gameMode = buf.readUnsignedByte();
if ( protocolVersion > ProtocolConstants.MINECRAFT_1_9 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
previousGameMode = buf.readUnsignedByte();
worldNames = new HashSet<>();
int worldCount = readVarInt( buf );
Preconditions.checkArgument( worldCount < 128, "Too many worlds %s", worldCount );
for ( int i = 0; i < worldCount; i++ )
{
worldNames.add( readString( buf ) );
}
dimensions = NamedTag.read( new DataInputStream( new ByteBufInputStream( buf ) ) );
Preconditions.checkArgument( !dimensions.isError(), "Error reading dimensions: %s", dimensions.error() );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
dimension = readString( buf );
worldName = readString( buf );
} else if ( protocolVersion > ProtocolConstants.MINECRAFT_1_9 )
{
dimension = buf.readInt();
} else
@ -48,7 +85,10 @@ public class Login extends DefinedPacket
difficulty = buf.readUnsignedByte();
}
maxPlayers = buf.readUnsignedByte();
levelType = readString( buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_16 )
{
levelType = readString( buf );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_14 )
{
viewDistance = readVarInt( buf );
@ -61,6 +101,11 @@ public class Login extends DefinedPacket
{
normalRespawn = buf.readBoolean();
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
debug = buf.readBoolean();
flat = buf.readBoolean();
}
}
@Override
@ -68,12 +113,35 @@ public class Login extends DefinedPacket
{
buf.writeInt( entityId );
buf.writeByte( gameMode );
if ( protocolVersion > ProtocolConstants.MINECRAFT_1_9 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
buf.writeInt( dimension );
buf.writeByte( previousGameMode );
writeVarInt( worldNames.size(), buf );
for ( String world : worldNames )
{
writeString( world, buf );
}
try
{
dimensions.write( new DataOutputStream( new ByteBufOutputStream( buf ) ) );
} catch ( IOException ex )
{
throw new RuntimeException( "Exception writing dimensions", ex );
}
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
writeString( (String) dimension, buf );
writeString( worldName, buf );
} else if ( protocolVersion > ProtocolConstants.MINECRAFT_1_9 )
{
buf.writeInt( ( (Number) dimension ).intValue() );
} else
{
buf.writeByte( dimension );
buf.writeByte( ( (Number) dimension ).byteValue() );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_15 )
{
@ -84,7 +152,10 @@ public class Login extends DefinedPacket
buf.writeByte( difficulty );
}
buf.writeByte( maxPlayers );
writeString( levelType, buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_16 )
{
writeString( levelType, buf );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_14 )
{
writeVarInt( viewDistance, buf );
@ -97,6 +168,11 @@ public class Login extends DefinedPacket
{
buf.writeBoolean( normalRespawn );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
buf.writeBoolean( debug );
buf.writeBoolean( flat );
}
}
@Override

View File

@ -1,12 +1,14 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
@Data
@NoArgsConstructor
@ -15,20 +17,32 @@ import net.md_5.bungee.protocol.DefinedPacket;
public class LoginSuccess extends DefinedPacket
{
private String uuid;
private UUID uuid;
private String username;
@Override
public void read(ByteBuf buf)
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
uuid = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
uuid = readUUID( buf );
} else
{
uuid = UUID.fromString( readString( buf ) );
}
username = readString( buf );
}
@Override
public void write(ByteBuf buf)
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeString( uuid, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
writeUUID( uuid, buf );
} else
{
writeString( uuid.toString(), buf );
}
writeString( username, buf );
}

View File

@ -16,16 +16,28 @@ import net.md_5.bungee.protocol.ProtocolConstants;
public class Respawn extends DefinedPacket
{
private int dimension;
private Object dimension;
private String worldName;
private long seed;
private short difficulty;
private short gameMode;
private short previousGameMode;
private String levelType;
private boolean debug;
private boolean flat;
private boolean copyMeta;
@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
dimension = buf.readInt();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
dimension = readString( buf );
worldName = readString( buf );
} else
{
dimension = buf.readInt();
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_15 )
{
seed = buf.readLong();
@ -35,13 +47,29 @@ public class Respawn extends DefinedPacket
difficulty = buf.readUnsignedByte();
}
gameMode = buf.readUnsignedByte();
levelType = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
previousGameMode = buf.readUnsignedByte();
debug = buf.readBoolean();
flat = buf.readBoolean();
copyMeta = buf.readBoolean();
} else
{
levelType = readString( buf );
}
}
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
buf.writeInt( dimension );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
writeString( (String) dimension, buf );
writeString( worldName, buf );
} else
{
buf.writeInt( ( (Number) dimension ).intValue() );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_15 )
{
buf.writeLong( seed );
@ -51,7 +79,16 @@ public class Respawn extends DefinedPacket
buf.writeByte( difficulty );
}
buf.writeByte( gameMode );
writeString( levelType, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
buf.writeByte( previousGameMode );
buf.writeBoolean( debug );
buf.writeBoolean( flat );
buf.writeBoolean( copyMeta );
} else
{
writeString( levelType, buf );
}
}
@Override

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-proxy</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Proxy</name>
@ -85,12 +85,6 @@
<version>5.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>se.llbit</groupId>
<artifactId>jo-nbt</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>

View File

@ -1,17 +0,0 @@
package net.md_5.bungee;
import net.md_5.bungee.protocol.packet.ClientStatus;
import net.md_5.bungee.protocol.packet.PluginMessage;
import net.md_5.bungee.protocol.packet.Respawn;
public class PacketConstants
{
public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, 0, (byte) 0, (byte) 0, "default" );
public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, 0, (byte) 0, (byte) 0, "default" );
public static final ClientStatus CLIENT_LOGIN = new ClientStatus( (byte) 0 );
public static final PluginMessage FORGE_MOD_REQUEST = new PluginMessage( "FML", new byte[]
{
0, 0, 0, 0, 0, 2
}, false );
}

View File

@ -212,8 +212,8 @@ public class ServerConnector extends PacketHandler
user.setServerEntityId( login.getEntityId() );
// Set tab list size, TODO: what shall we do about packet mutability
Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getSeed(), login.getDifficulty(),
(byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.isReducedDebugInfo(), login.isNormalRespawn() );
Login modLogin = new Login( login.getEntityId(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(),
(byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isDebug(), login.isFlat() );
user.unsafe().sendPacket( modLogin );
@ -259,13 +259,23 @@ public class ServerConnector extends PacketHandler
}
user.setDimensionChange( true );
if ( login.getDimension() == user.getDimension() )
if ( login.getDimension().equals( user.getDimension() ) )
{
user.unsafe().sendPacket( new Respawn( ( login.getDimension() >= 0 ? -1 : 0 ), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) );
Object newDim;
String worldName = login.getWorldName();
if ( login.getDimension() instanceof Number )
{
newDim = ( ( (Number) login.getDimension() ).intValue() >= 0 ? -1 : 0 );
} else
{
newDim = worldName = ( "minecraft:overworld".equals( login.getDimension() ) ) ? "minecraft:the_nether" : "minecraft:overworld";
}
user.unsafe().sendPacket( new Respawn( newDim, worldName, login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
}
user.setServerEntityId( login.getEntityId() );
user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) );
user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
if ( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_14 )
{
user.unsafe().sendPacket( new ViewDistance( login.getViewDistance() ) );

View File

@ -84,7 +84,7 @@ public final class UserConnection implements ProxiedPlayer
private ServerConnection server;
@Getter
@Setter
private int dimension;
private Object dimension;
@Getter
@Setter
private boolean dimensionChange = true;

View File

@ -529,7 +529,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() );
userCon.init();
unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between
unsafe.sendPacket( new LoginSuccess( getUniqueId(), getName() ) );
ch.setProtocol( Protocol.GAME );
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );

View File

@ -61,6 +61,8 @@ public abstract class EntityMap
case ProtocolConstants.MINECRAFT_1_15_1:
case ProtocolConstants.MINECRAFT_1_15_2:
return EntityMap_1_15.INSTANCE;
case ProtocolConstants.MINECRAFT_1_16:
return EntityMap_1_16.INSTANCE;
}
throw new RuntimeException( "Version " + version + " has no entity map" );
}

View File

@ -0,0 +1,187 @@
package net.md_5.bungee.entitymap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
class EntityMap_1_16 extends EntityMap
{
static final EntityMap_1_16 INSTANCE = new EntityMap_1_16();
EntityMap_1_16()
{
addRewrite( 0x00, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Object : PacketPlayOutSpawnEntity
addRewrite( 0x01, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Experience Orb : PacketPlayOutSpawnEntityExperienceOrb
addRewrite( 0x02, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Mob : PacketPlayOutSpawnEntityLiving
addRewrite( 0x03, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Painting : PacketPlayOutSpawnEntityPainting
addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Player : PacketPlayOutNamedEntitySpawn
addRewrite( 0x05, ProtocolConstants.Direction.TO_CLIENT, true ); // Animation : PacketPlayOutAnimation
addRewrite( 0x08, ProtocolConstants.Direction.TO_CLIENT, true ); // Block Break Animation : PacketPlayOutBlockBreakAnimation
addRewrite( 0x1B, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus
addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove
addRewrite( 0x29, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook
addRewrite( 0x2A, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook
addRewrite( 0x2B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity
addRewrite( 0x38, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect
addRewrite( 0x3B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation
addRewrite( 0x3E, ProtocolConstants.Direction.TO_CLIENT, true ); // Camera : PacketPlayOutCamera
addRewrite( 0x44, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Metadata : PacketPlayOutEntityMetadata
addRewrite( 0x45, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity : PacketPlayOutAttachEntity
addRewrite( 0x46, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Velocity : PacketPlayOutEntityVelocity
addRewrite( 0x47, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment : PacketPlayOutEntityEquipment
addRewrite( 0x4B, ProtocolConstants.Direction.TO_CLIENT, true ); // Set Passengers : PacketPlayOutMount
addRewrite( 0x55, ProtocolConstants.Direction.TO_CLIENT, true ); // Collect Item : PacketPlayOutCollect
addRewrite( 0x56, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Teleport : PacketPlayOutEntityTeleport
addRewrite( 0x58, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Properties : PacketPlayOutUpdateAttributes
addRewrite( 0x59, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Effect : PacketPlayOutEntityEffect
addRewrite( 0x0E, ProtocolConstants.Direction.TO_SERVER, true ); // Use Entity : PacketPlayInUseEntity
addRewrite( 0x1C, ProtocolConstants.Direction.TO_SERVER, true ); // Entity Action : PacketPlayInEntityAction
}
@Override
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protocolVersion)
{
super.rewriteClientbound( packet, oldId, newId );
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
switch ( packetId )
{
case 0x45 /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( packet, oldId, newId, readerIndex + packetIdLength + 4 );
break;
case 0x55 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.readVarInt( packet );
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
break;
case 0x4B /* Set Passengers : PacketPlayOutMount */:
DefinedPacket.readVarInt( packet );
jumpIndex = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x37 /* Destroy Entities : PacketPlayOutEntityDestroy */:
int count = DefinedPacket.readVarInt( packet );
int[] ids = new int[ count ];
for ( int i = 0; i < count; i++ )
{
ids[i] = DefinedPacket.readVarInt( packet );
}
packet.readerIndex( jumpIndex );
packet.writerIndex( jumpIndex );
DefinedPacket.writeVarInt( count, packet );
for ( int id : ids )
{
if ( id == oldId )
{
id = newId;
} else if ( id == newId )
{
id = oldId;
}
DefinedPacket.writeVarInt( id, packet );
}
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
DefinedPacket.readVarInt( packet );
DefinedPacket.readUUID( packet );
int type = DefinedPacket.readVarInt( packet );
if ( type == 2 || type == 102 || type == 72 ) // arrow, fishing_bobber or spectral_arrow
{
if ( type == 2 || type == 72 ) // arrow or spectral_arrow
{
oldId = oldId + 1;
newId = newId + 1;
}
packet.skipBytes( 26 ); // double, double, double, byte, byte
int position = packet.readerIndex();
int readId = packet.readInt();
if ( readId == oldId )
{
packet.setInt( position, newId );
} else if ( readId == newId )
{
packet.setInt( position, oldId );
}
}
break;
case 0x04 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
packet.writerIndex( previous );
}
break;
case 0x32 /* Combat Event : PacketPlayOutCombatEvent */:
int event = packet.readUnsignedByte();
if ( event == 1 /* End Combat*/ )
{
DefinedPacket.readVarInt( packet );
rewriteInt( packet, oldId, newId, packet.readerIndex() );
} else if ( event == 2 /* Entity Dead */ )
{
int position = packet.readerIndex();
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
packet.readerIndex( position );
DefinedPacket.readVarInt( packet );
rewriteInt( packet, oldId, newId, packet.readerIndex() );
}
break;
case 0x44 /* EntityMetadata : PacketPlayOutEntityMetadata */:
DefinedPacket.readVarInt( packet ); // Entity ID
rewriteMetaVarInt( packet, oldId + 1, newId + 1, 7, protocolVersion ); // fishing hook
rewriteMetaVarInt( packet, oldId, newId, 8, protocolVersion ); // fireworks (et al)
rewriteMetaVarInt( packet, oldId, newId, 16, protocolVersion ); // guardian beam
break;
case 0x50 /* Entity Sound Effect : PacketPlayOutEntitySound */:
DefinedPacket.readVarInt( packet );
DefinedPacket.readVarInt( packet );
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
break;
}
packet.readerIndex( readerIndex );
}
@Override
public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
{
super.rewriteServerbound( packet, oldId, newId );
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x2C /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
packet.writerIndex( previous );
}
}
packet.readerIndex( readerIndex );
}
}

View File

@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-query</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Query</name>