Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfriedrich committed Feb 28, 2022
2 parents 1d751eb + 7e47490 commit 3875ecd
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 77 deletions.
8 changes: 4 additions & 4 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<version>3.8.1</version>
<version>3.8.4</version>
<!-- not part of the API proper -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>1.7.0</version>
<version>1.7.2</version>
<!-- not part of the API proper -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>1.7.0</version>
<version>1.7.2</version>
<!-- not part of the API proper -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.30-SNAPSHOT</version>
<version>1.30</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
15 changes: 14 additions & 1 deletion api/src/main/java/net/md_5/bungee/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,24 @@ public static String unicode(char c)
* @return a string representing information about the {@link Throwable}
*/
public static String exception(Throwable t)
{
return exception( t, true );
}

/**
* Constructs a pretty one line version of a {@link Throwable}. Useful for
* debugging.
*
* @param t the {@link Throwable} to format.
* @param includeLineNumbers whether to include line numbers
* @return a string representing information about the {@link Throwable}
*/
public static String exception(Throwable t, boolean includeLineNumbers)
{
// TODO: We should use clear manually written exceptions
StackTraceElement[] trace = t.getStackTrace();
return t.getClass().getSimpleName() + " : " + t.getMessage()
+ ( ( trace.length > 0 ) ? " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber() : "" );
+ ( ( includeLineNumbers && trace.length > 0 ) ? " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber() : "" );
}

public static String csv(Iterable<?> objects)
Expand Down
4 changes: 2 additions & 2 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
<module name="OperatorWrap"/>
<module name="ParenPad">
<property name="option" value="nospace"/>
<property name="tokens" value="ANNOTATION, CTOR_DEF, METHOD_DEF"/>
<property name="tokens" value="ANNOTATION, CTOR_DEF, METHOD_DEF, LAMBDA"/>
</module>
<module name="ParenPad">
<property name="option" value="space"/>
<property name="tokens" value="ANNOTATION_FIELD_DEF, CTOR_CALL, DOT, ENUM_CONSTANT_DEF, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/>
<property name="tokens" value="ANNOTATION_FIELD_DEF, CTOR_CALL, DOT, ENUM_CONSTANT_DEF, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, RECORD_DEF"/>
</module>
<module name="SingleSpaceSeparator"/>
<module name="TypecastParenPad"/>
Expand Down
2 changes: 1 addition & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.30-SNAPSHOT</version>
<version>1.30</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
Expand Down
39 changes: 15 additions & 24 deletions event/src/main/java/net/md_5/bungee/event/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public void post(Object event)
{
for ( EventHandlerMethod method : handlers )
{
long start = System.nanoTime();

try
{
method.invoke( event );
Expand All @@ -55,6 +57,15 @@ public void post(Object event)
{
logger.log( Level.WARNING, MessageFormat.format( "Error dispatching event {0} to listener {1}", event, method.getListener() ), ex.getCause() );
}

long elapsed = System.nanoTime() - start;
if ( elapsed > 50000000 )
{
logger.log( Level.WARNING, "Plugin listener {0} took {1}ms to process event {2}!", new Object[]
{
method.getListener().getClass().getName(), elapsed / 1000000, event
} );
}
}
}
}
Expand All @@ -77,18 +88,8 @@ private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener)
} );
continue;
}
Map<Byte, Set<Method>> prioritiesMap = handler.get( params[0] );
if ( prioritiesMap == null )
{
prioritiesMap = new HashMap<>();
handler.put( params[0], prioritiesMap );
}
Set<Method> priority = prioritiesMap.get( annotation.priority() );
if ( priority == null )
{
priority = new HashSet<>();
prioritiesMap.put( annotation.priority(), priority );
}
Map<Byte, Set<Method>> prioritiesMap = handler.computeIfAbsent( params[0], k -> new HashMap<>() );
Set<Method> priority = prioritiesMap.computeIfAbsent( annotation.priority(), k -> new HashSet<>() );
priority.add( m );
}
}
Expand All @@ -103,20 +104,10 @@ public void register(Object listener)
{
for ( Map.Entry<Class<?>, Map<Byte, Set<Method>>> e : handler.entrySet() )
{
Map<Byte, Map<Object, Method[]>> prioritiesMap = byListenerAndPriority.get( e.getKey() );
if ( prioritiesMap == null )
{
prioritiesMap = new HashMap<>();
byListenerAndPriority.put( e.getKey(), prioritiesMap );
}
Map<Byte, Map<Object, Method[]>> prioritiesMap = byListenerAndPriority.computeIfAbsent( e.getKey(), k -> new HashMap<>() );
for ( Map.Entry<Byte, Set<Method>> entry : e.getValue().entrySet() )
{
Map<Object, Method[]> currentPriorityMap = prioritiesMap.get( entry.getKey() );
if ( currentPriorityMap == null )
{
currentPriorityMap = new HashMap<>();
prioritiesMap.put( entry.getKey(), currentPriorityMap );
}
Map<Object, Method[]> currentPriorityMap = prioritiesMap.computeIfAbsent( entry.getKey(), k -> new HashMap<>() );
currentPriorityMap.put( listener, entry.getValue().toArray( new Method[ 0 ] ) );
}
bakeHandlers( e.getKey() );
Expand Down
2 changes: 1 addition & 1 deletion native/mbedtls
Binary file modified native/src/main/resources/native-cipher.so
Binary file not shown.
21 changes: 3 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,10 @@
</repository>
</distributionManagement>

<!-- We really shouldn't depend on external repositories, but at least this is the Central staging one -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<properties>
<build.number>unknown</build.number>
<lombok.version>1.18.20</lombok.version>
<netty.version>4.1.70.Final</netty.version>
<lombok.version>1.18.22</lombok.version>
<netty.version>4.1.72.Final</netty.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -104,7 +89,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
15 changes: 15 additions & 0 deletions protocol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
<name>BungeeCord-Protocol</name>
<description>Minimal implementation of the Minecraft protocol for use in BungeeCord</description>

<!-- We really shouldn't depend on external repositories, but at least this is the Central staging one -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>net.md-5</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t

if ( in.isReadable() )
{
throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot.getDirection() );
throw new BadPacketException( "Packet " + protocol + ":" + prot.getDirection() + "/" + packetId + " (" + packet.getClass().getSimpleName() + ") larger than expected, extra bytes: " + in.readableBytes() );
}
} else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ProtocolConstants
public static final int MINECRAFT_1_17 = 755;
public static final int MINECRAFT_1_17_1 = 756;
public static final int MINECRAFT_1_18 = 757;
public static final int MINECRAFT_1_18_2 = 758;
public static final List<String> SUPPORTED_VERSIONS;
public static final List<Integer> SUPPORTED_VERSION_IDS;

Expand Down Expand Up @@ -90,7 +91,8 @@ public class ProtocolConstants
ProtocolConstants.MINECRAFT_1_16_4,
ProtocolConstants.MINECRAFT_1_17,
ProtocolConstants.MINECRAFT_1_17_1,
ProtocolConstants.MINECRAFT_1_18
ProtocolConstants.MINECRAFT_1_18,
ProtocolConstants.MINECRAFT_1_18_2
);

if ( SNAPSHOT_SUPPORT )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,20 @@ protected String getKey()
return "brigadier:string";
}
};
private static final ArgumentSerializer<String> RAW_STRING = new ArgumentSerializer<String>()
{
@Override
protected String read(ByteBuf buf)
{
return DefinedPacket.readString( buf );
}

@Override
protected void write(ByteBuf buf, String t)
{
DefinedPacket.writeString( t, buf );
}
};

static
{
Expand Down Expand Up @@ -551,6 +565,8 @@ protected String getKey()
PROVIDERS.put( "minecraft:test_argument", VOID ); // 1.16, debug
PROVIDERS.put( "minecraft:test_class", VOID ); // 1.16, debug
PROVIDERS.put( "minecraft:angle", VOID ); // 1.16.2
PROVIDERS.put( "minecraft:resource", RAW_STRING ); // 1.18.2
PROVIDERS.put( "minecraft:resource_or_tag", RAW_STRING ); // 1.18.2
}

private static ArgumentType<?> read(String key, ByteBuf buf)
Expand Down
6 changes: 3 additions & 3 deletions proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<version>3.8.1</version>
<version>3.8.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>1.7.0</version>
<version>1.7.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>1.7.0</version>
<version>1.7.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void ping(final Callback<ServerPing> callback, final int protocolVersion)
Preconditions.checkNotNull( callback, "callback" );

int pingCache = ProxyServer.getInstance().getConfig().getRemotePingCache();
if ( pingCache > 0 && cachedPing != null && ( lastPing - System.currentTimeMillis() ) > pingCache )
if ( pingCache > 0 && cachedPing != null && ( System.currentTimeMillis() - lastPing ) > pingCache )
{
cachedPing = null;
}
Expand Down
9 changes: 1 addition & 8 deletions proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ConnectTimeoutException;
import io.netty.util.internal.PlatformDependent;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
Expand Down Expand Up @@ -381,13 +380,7 @@ public void operationComplete(ChannelFuture future) throws Exception

private String connectionFailMessage(Throwable cause)
{
if ( cause instanceof ConnectTimeoutException )
{
return bungee.getTranslation( "timeout" );
} else
{
return cause.getClass().getName();
}
return Util.exception( cause, false );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import jline.console.completer.Completer;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer;
Expand All @@ -15,11 +18,21 @@ public class ConsoleCommandCompleter implements Completer
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates)
{
List<String> suggestions = new ArrayList<>();
proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, suggestions );
candidates.addAll( suggestions );

int lastSpace = buffer.lastIndexOf( ' ' );
if ( lastSpace == -1 )
{
String lowerCase = buffer.toLowerCase( Locale.ROOT );
candidates.addAll( proxy.getPluginManager().getCommands().stream()
.map( Map.Entry::getKey )
.filter( (name) -> name.toLowerCase( Locale.ROOT ).startsWith( lowerCase ) )
.collect( Collectors.toList() ) );
} else
{
List<String> suggestions = new ArrayList<>();
proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, suggestions );
candidates.addAll( suggestions );
}

return ( lastSpace == -1 ) ? cursor - buffer.length() : cursor - ( buffer.length() - lastSpace - 1 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.mojang.brigadier.context.StringRange;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.mojang.brigadier.tree.CommandNode;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
Expand Down Expand Up @@ -67,6 +67,13 @@
public class DownstreamBridge extends PacketHandler
{

// #3246: Recent versions of MinecraftForge alter Vanilla behaviour and require a command so that the executable flag is set
// If the flag is not set, then the command will appear and successfully tab complete, but cannot be successfully executed
private static final com.mojang.brigadier.Command DUMMY_COMMAND = (context) ->
{
return 0;
};
//
private final ProxyServer bungee;
private final UserConnection con;
private final ServerConnection server;
Expand Down Expand Up @@ -666,9 +673,9 @@ public void handle(Commands commands) throws Exception
{
if ( !bungee.getDisabledCommands().contains( command.getKey() ) && commands.getRoot().getChild( command.getKey() ) == null && command.getValue().hasPermission( con ) )
{
LiteralCommandNode dummy = LiteralArgumentBuilder.literal( command.getKey() )
CommandNode dummy = LiteralArgumentBuilder.literal( command.getKey() ).executes( DUMMY_COMMAND )
.then( RequiredArgumentBuilder.argument( "args", StringArgumentType.greedyString() )
.suggests( Commands.SuggestionRegistry.ASK_SERVER ) )
.suggests( Commands.SuggestionRegistry.ASK_SERVER ).executes( DUMMY_COMMAND ) )
.build();
commands.getRoot().addChild( dummy );

Expand Down
Loading

0 comments on commit 3875ecd

Please sign in to comment.