Waterfall + Pandacube patches = PandaCord

This commit is contained in:
Marc Baloup
2021-08-13 20:23:24 +02:00
parent 0aaf9e4c58
commit 53f5c18f14
19 changed files with 3531 additions and 292 deletions

View File

@@ -0,0 +1,413 @@
From 5bd6939857a7272ad7c338e202a7196010121aa8 Mon Sep 17 00:00:00 2001
From: Marc Baloup <marc.baloup@laposte.net>
Date: Sat, 1 Oct 2016 23:26:27 +0200
Subject: [PATCH] Change projet configuration and POM for Pandacube
diff --git a/api/pom.xml b/api/pom.xml
index 0680a5a5..1d46bfb4 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -20,25 +19,25 @@
<dependencies>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-chat</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-config</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-event</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-protocol</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml
index 7a9e8258..0efba9cd 100644
--- a/bootstrap/pom.xml
+++ b/bootstrap/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-bootstrap</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -29,7 +28,7 @@
<dependencies>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-proxy</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
diff --git a/chat/pom.xml b/chat/pom.xml
index cfa0e16e..dbe64d6d 100644
--- a/chat/pom.xml
+++ b/chat/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-chat</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
diff --git a/config/pom.xml b/config/pom.xml
index 67e2500f..212c7371 100644
--- a/config/pom.xml
+++ b/config/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-config</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
diff --git a/event/pom.xml b/event/pom.xml
index 563783e9..4263081e 100644
--- a/event/pom.xml
+++ b/event/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-event</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
diff --git a/log/pom.xml b/log/pom.xml
index 3663d6d9..f1e8ace8 100644
--- a/log/pom.xml
+++ b/log/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-log</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -26,7 +25,7 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-chat</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
diff --git a/log4j/pom.xml b/log4j/pom.xml
index 7ec6e530..87c200d2 100644
--- a/log4j/pom.xml
+++ b/log4j/pom.xml
@@ -3,13 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-log4j</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
diff --git a/native/pom.xml b/native/pom.xml
index 652a869d..2f87f4c2 100644
--- a/native/pom.xml
+++ b/native/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-native</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
diff --git a/pom.xml b/pom.xml
index 8d86e36c..5b701203 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,14 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>io.github.waterfallmc</groupId>
- <artifactId>waterfall-super</artifactId>
- <version>dev-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>pom</packaging>
@@ -129,7 +122,7 @@
<artifactId>scriptus</artifactId>
<version>0.4.1</version>
<configuration>
- <format>git:${project.name}:${project.version}:%s:${build.number}</format>
+ <format>git:PandaCord:${project.version}:%s:${build.number}</format>
</configuration>
<executions>
<execution>
@@ -201,6 +194,62 @@
</configuration>
</plugin>
</plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse
+ m2e settings only. It has no influence on the Maven build itself. -->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>net.md-5</groupId>
+ <artifactId>scriptus</artifactId>
+ <versionRange>[0.3.1,)</versionRange>
+ <goals>
+ <goal>describe</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <execute>
+ <runOnIncremental>false</runOnIncremental>
+ </execute>
+ </action>
+ </pluginExecution>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <versionRange>[1.0.0,)</versionRange>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore />
+ </action>
+ </pluginExecution>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <versionRange>[3.0.0,)</versionRange>
+ <goals><goal>check</goal></goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
<profiles>
diff --git a/protocol/pom.xml b/protocol/pom.xml
index dbc0a3ab..dd16e74e 100644
--- a/protocol/pom.xml
+++ b/protocol/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-protocol</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -41,7 +40,7 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-chat</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
diff --git a/proxy/pom.xml b/proxy/pom.xml
index c3a2eeb6..fe3a2197 100644
--- a/proxy/pom.xml
+++ b/proxy/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-proxy</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -64,31 +63,31 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-api</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-log4j</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-native</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-protocol</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-query</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
diff --git a/query/pom.xml b/query/pom.xml
index dea7d85f..55baf2e0 100644
--- a/query/pom.xml
+++ b/query/pom.xml
@@ -4,13 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-parent</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-query</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -26,7 +25,7 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>io.github.waterfallmc</groupId>
+ <groupId>fr.pandacube.pandacord</groupId>
<artifactId>waterfall-api</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
--
2.32.0.windows.2

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,150 @@
From dbb2441936118788203dc43a4c4582ee71e017c8 Mon Sep 17 00:00:00 2001
From: Marc Baloup <marc.baloup@laposte.net>
Date: Sun, 2 Oct 2016 07:54:16 +0200
Subject: [PATCH] Multi-session with same Minecraft account with specific
permission
Players with permission bungeecord.multiple_connect can have multiples
connections with the same Minecraft account. To manage UUID and Name conflict,
an increment value is appended to the player name, and the uuid used is the
offline one. So be carefull: Spigot servers and plugins will considers 2
players from the same account like if they were 2 different MC account.
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
index 0f1716c0..b07d2e06 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
@@ -110,6 +110,17 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Getter
private String extraDataInHandshake = "";
+ @Getter
+ private boolean duplication = false;
+
+ @Getter
+ private String realName = null;
+
+ @Getter
+ private UUID realId = null;
+
+ private String gameName = null;
+
@Override
public boolean shouldHandle(PacketWrapper packet) throws Exception
{
@@ -364,6 +375,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" );
this.loginRequest = loginRequest;
+ this.realName = loginRequest.getData();
+ this.gameName = this.realName;
if ( getName().contains( " " ) )
{
@@ -378,9 +391,21 @@ public class InitialHandler extends PacketHandler implements PendingConnection
return;
}
+ ProxiedPlayer existingPlayer = bungee.getPlayer( getName() );
+
+ duplication = ( existingPlayer != null && existingPlayer.hasPermission( "bungeecord.multiple_connect" ) );
+
+ if ( duplication )
+ {
+ gameName = generateDuplicatedName( realName );
+ this.loginRequest.setData( gameName ); // gameName transmitted to Spigot server
+ }
+
+ offlineId = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + gameName ).getBytes( Charsets.UTF_8 ) );
+
// If offline mode and they are already on, don't allow connect
// We can just check by UUID here as names are based on UUID
- if ( !isOnlineMode() && bungee.getPlayer( getUniqueId() ) != null )
+ if ( !isOnlineMode() && bungee.getPlayer( offlineId ) != null && !duplication )
{
disconnect( bungee.getTranslation( "already_connected_proxy" ) );
return;
@@ -435,7 +460,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
BungeeCipher encrypt = EncryptionUtil.getCipher( true, sharedKey );
ch.addBefore( PipelineUtils.FRAME_PREPENDER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) );
- String encName = URLEncoder.encode( InitialHandler.this.getName(), "UTF-8" );
+ String encName = URLEncoder.encode( InitialHandler.this.realName, "UTF-8" );
MessageDigest sha = MessageDigest.getInstance( "SHA-1" );
for ( byte[] bit : new byte[][]
@@ -461,8 +486,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
if ( obj != null && obj.getId() != null )
{
loginProfile = obj;
- name = obj.getName();
- uniqueId = Util.getUUID( obj.getId() );
+ realName = obj.getName();
+ realId = Util.getUUID( obj.getId() );
+ if ( !duplication )
+ uniqueId = realId;
finish();
return;
}
@@ -470,7 +497,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
} else
{
disconnect( bungee.getTranslation( "mojang_fail" ) );
- bungee.getLogger().log( Level.SEVERE, "Error authenticating " + getName() + " with minecraft.net", error );
+ bungee.getLogger().log( Level.SEVERE, "Error authenticating " + realName + " with minecraft.net", error );
}
}
};
@@ -480,6 +507,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private void finish()
{
+
+ if ( uniqueId == null )
+ {
+ uniqueId = offlineId;
+ }
+
if ( isOnlineMode() )
{
// Check for multiple connections
@@ -510,12 +543,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
}
- offlineId = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) );
- if ( uniqueId == null )
- {
- uniqueId = offlineId;
- }
-
Callback<LoginEvent> complete = new Callback<LoginEvent>()
{
@Override
@@ -615,7 +642,22 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override
public String getName()
{
- return ( name != null ) ? name : ( loginRequest == null ) ? null : loginRequest.getData();
+ return gameName;
+ }
+
+ private String generateDuplicatedName(String original)
+ {
+ String newName;
+ int i = 0;
+ do
+ {
+ i++;
+ String strCount = Integer.toString( i );
+ if ( original.length() > 16 - strCount.length() )
+ original = original.substring( 0, 16 - strCount.length() );
+ newName = original + i;
+ } while ( bungee.getPlayer( newName ) != null );
+ return newName;
}
@Override
--
2.32.0.windows.2

View File

@@ -0,0 +1,43 @@
From e814af4ff1a9b377eb2642d4d317407072f373de Mon Sep 17 00:00:00 2001
From: Marc Baloup <marc.baloup@laposte.net>
Date: Tue, 29 Oct 2019 23:43:32 +0100
Subject: [PATCH] Inproved proxy and server branding (displayed in F3)
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
index cffe7a8d..51207270 100644
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
@@ -51,6 +51,7 @@ import java.util.logging.Logger;
import lombok.Getter;
import lombok.Setter;
import lombok.Synchronized;
+import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ProxyServer;
@@ -533,7 +534,7 @@ public class BungeeCord extends ProxyServer
@Override
public String getName()
{
- return "Waterfall";
+ return ChatColor.YELLOW + "[[" + ChatColor.GREEN + ChatColor.BOLD + "Pandacube" + ChatColor.YELLOW + "]]" + ChatColor.RESET;
}
@Override
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
index 9e180c30..72538ddb 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
@@ -293,7 +293,7 @@ public class DownstreamBridge extends PacketHandler
Preconditions.checkState( !serverBrand.contains( bungee.getName() ), "Cannot connect proxy to itself!" );
brand = ByteBufAllocator.DEFAULT.heapBuffer();
- DefinedPacket.writeString( bungee.getName() + " <- " + serverBrand, brand ); // Waterfall
+ DefinedPacket.writeString( bungee.getName() + " <- " + server.getInfo().getName() + " (" + serverBrand + ")", brand ); // Waterfall
pluginMessage.setData( brand );
brand.release();
// changes in the packet are ignored so we need to send it manually
--
2.32.0.windows.2

View File

@@ -0,0 +1,194 @@
From 999d7c782e22b1b1ac3bd614e8120c4b9d6d64cb Mon Sep 17 00:00:00 2001
From: Marc Baloup <marc.baloup@laposte.net>
Date: Sun, 21 Jun 2020 21:49:31 +0200
Subject: [PATCH] new event TabCompleteRequestEvent and deprecate
TabCompleteEvent
diff --git a/api/src/main/java/net/md_5/bungee/api/event/TabCompleteEvent.java b/api/src/main/java/net/md_5/bungee/api/event/TabCompleteEvent.java
index 2fcd8616..63031f7b 100644
--- a/api/src/main/java/net/md_5/bungee/api/event/TabCompleteEvent.java
+++ b/api/src/main/java/net/md_5/bungee/api/event/TabCompleteEvent.java
@@ -9,7 +9,9 @@ import net.md_5.bungee.api.plugin.Cancellable;
/**
* Event called when a player uses tab completion.
+ * @deprecated please use {@link TabCompleteRequestEvent} to support 1.13+ suggestions.
*/
+@Deprecated
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
diff --git a/api/src/main/java/net/md_5/bungee/api/event/TabCompleteRequestEvent.java b/api/src/main/java/net/md_5/bungee/api/event/TabCompleteRequestEvent.java
new file mode 100644
index 00000000..0093ae69
--- /dev/null
+++ b/api/src/main/java/net/md_5/bungee/api/event/TabCompleteRequestEvent.java
@@ -0,0 +1,85 @@
+package net.md_5.bungee.api.event;
+
+import com.google.common.base.Preconditions;
+import com.mojang.brigadier.context.StringRange;
+import com.mojang.brigadier.suggestion.Suggestions;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import net.md_5.bungee.api.connection.Connection;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import net.md_5.bungee.api.plugin.Cancellable;
+import net.md_5.bungee.protocol.ProtocolConstants;
+
+/**
+ * Event called when a player uses tab completion.
+ */
+@Data
+@ToString(callSuper = true)
+@EqualsAndHashCode(callSuper = true)
+public class TabCompleteRequestEvent extends TargetedEvent implements Cancellable
+{
+
+ /**
+ * Cancelled state.
+ */
+ private boolean cancelled;
+ /**
+ * The message the player has already entered.
+ */
+ private final String cursor;
+ /**
+ * Range corresponding to the last word of {@link #getCursor()}.
+ * If you want your suggestions to be compatible with 1.12 and older
+ * clients, you need to {@link #setSuggestions(Suggestions)} with
+ * a range equals to this one.
+ * For 1.13 and newer clients, any other range that cover any part of
+ * {@link #getCursor()} is fine.<br>
+ * To check if the client supports custom ranges, use
+ * {@link #supportsCustomRange()}.
+ */
+ private final StringRange legacyCompatibleRange;
+ /**
+ * The suggestions that will be sent to the client. If this list is empty,
+ * the request will be forwarded to the server.
+ */
+ private Suggestions suggestions;
+
+ public TabCompleteRequestEvent(Connection sender, Connection receiver, String cursor, StringRange legacyCompatibleRange, Suggestions suggestions)
+ {
+ super( sender, receiver );
+ this.cursor = cursor;
+ this.legacyCompatibleRange = legacyCompatibleRange;
+ this.suggestions = suggestions;
+ }
+
+ /**
+ * Sets the suggestions that will be sent to the client.
+ * If this list is empty, the request will be forwarded to the server.
+ * @param suggestions the new Suggestions. Cannot be null.
+ * @throws IllegalArgumentException if the client is on 1.12 or lower and
+ * {@code suggestions.getRange()} is not equals to {@link #legacyCompatibleRange}.
+ */
+ public void setSuggestions(Suggestions suggestions)
+ {
+ Preconditions.checkNotNull( suggestions );
+ Preconditions.checkArgument( supportsCustomRange() || legacyCompatibleRange.equals( suggestions.getRange() ),
+ "Clients on 1.12 or lower versions don't support the provided range for tab-completion: " + suggestions.getRange()
+ + ". Please use TabCompleteRequestEvent.getLegacyCompatibleRange() for legacy clients." );
+ this.suggestions = suggestions;
+ }
+
+ /**
+ * Convenient method to tell if the client supports custom range for
+ * suggestions.
+ * If the client is on 1.13 or above, this methods returns true, and any
+ * range can be used for {@link #setSuggestions(Suggestions)}. Otherwise,
+ * it returns false and the defined range must be equals to
+ * {@link #legacyCompatibleRange}.
+ * @return true if the client is on 1.13 or newer version, false otherwise.
+ */
+ public boolean supportsCustomRange()
+ {
+ return ( (ProxiedPlayer) getSender() ).getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13;
+ }
+}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
index d93d8851..bbb1ae91 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
@@ -6,7 +6,6 @@ import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import io.netty.channel.Channel;
import java.util.ArrayList;
-import java.util.LinkedList;
import java.util.List;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ServerConnection.KeepAliveData;
@@ -19,6 +18,7 @@ import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.SettingsChangedEvent;
import net.md_5.bungee.api.event.TabCompleteEvent;
+import net.md_5.bungee.api.event.TabCompleteRequestEvent;
import net.md_5.bungee.entitymap.EntityMap;
import net.md_5.bungee.forge.ForgeConstants;
import net.md_5.bungee.netty.ChannelWrapper;
@@ -200,32 +200,42 @@ public class UpstreamBridge extends PacketHandler
TabCompleteEvent tabCompleteEvent = new TabCompleteEvent( con, con.getServer(), tabComplete.getCursor(), suggestions );
bungee.getPluginManager().callEvent( tabCompleteEvent );
- if ( tabCompleteEvent.isCancelled() )
+ List<String> legacyResults = tabCompleteEvent.getSuggestions();
+
+ int start = tabComplete.getCursor().lastIndexOf( ' ' ) + 1;
+ int end = tabComplete.getCursor().length();
+ StringRange lastArgumentRange = StringRange.between( start, end );
+
+ List<Suggestion> brigadier = new ArrayList<>( legacyResults.size() );
+ for ( String s : legacyResults )
+ {
+ brigadier.add( new Suggestion( lastArgumentRange, s ) );
+ }
+
+ TabCompleteRequestEvent tabCompleteRequestEvent = new TabCompleteRequestEvent( con, con.getServer(), tabComplete.getCursor(), lastArgumentRange, new Suggestions( lastArgumentRange, brigadier ) );
+ tabCompleteRequestEvent.setCancelled( tabCompleteEvent.isCancelled() );
+ bungee.getPluginManager().callEvent( tabCompleteRequestEvent );
+
+ if ( tabCompleteRequestEvent.isCancelled() )
{
throw CancelSendSignal.INSTANCE;
}
- List<String> results = tabCompleteEvent.getSuggestions();
- if ( !results.isEmpty() )
+ Suggestions brigadierResults = tabCompleteRequestEvent.getSuggestions();
+
+ if ( !brigadierResults.isEmpty() )
{
- // Unclear how to handle 1.13 commands at this point. Because we don't inject into the command packets we are unlikely to get this far unless
- // Bungee plugins are adding results for commands they don't own anyway
if ( con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_13 )
{
+ List<String> results = new ArrayList<>( brigadierResults.getList().size() );
+ for ( Suggestion s : brigadierResults.getList() )
+ {
+ results.add( s.getText() );
+ }
con.unsafe().sendPacket( new TabCompleteResponse( results ) );
} else
{
- int start = tabComplete.getCursor().lastIndexOf( ' ' ) + 1;
- int end = tabComplete.getCursor().length();
- StringRange range = StringRange.between( start, end );
-
- List<Suggestion> brigadier = new LinkedList<>();
- for ( String s : results )
- {
- brigadier.add( new Suggestion( range, s ) );
- }
-
- con.unsafe().sendPacket( new TabCompleteResponse( tabComplete.getTransactionId(), new Suggestions( range, brigadier ) ) );
+ con.unsafe().sendPacket( new TabCompleteResponse( tabComplete.getTransactionId(), brigadierResults ) );
}
throw CancelSendSignal.INSTANCE;
}
--
2.32.0.windows.2