2020-08-29 13:11:57 +02:00
|
|
|
From f36d1c7e29ee37a364a530794c674bdab826e774 Mon Sep 17 00:00:00 2001
|
2019-03-16 08:08:11 +01:00
|
|
|
From: Shane Freeder <theboyetronic@gmail.com>
|
|
|
|
Date: Thu, 14 Mar 2019 07:44:06 +0000
|
|
|
|
Subject: [PATCH] Add ProxyDefineCommandsEvent
|
|
|
|
|
|
|
|
provides an event to allow plugins to intercept tab completions
|
|
|
|
sent to the client
|
|
|
|
|
|
|
|
diff --git a/api/src/main/java/io/github/waterfallmc/waterfall/event/ProxyDefineCommandsEvent.java b/api/src/main/java/io/github/waterfallmc/waterfall/event/ProxyDefineCommandsEvent.java
|
|
|
|
new file mode 100644
|
|
|
|
index 00000000..1fd4fc90
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/event/ProxyDefineCommandsEvent.java
|
|
|
|
@@ -0,0 +1,41 @@
|
|
|
|
+package io.github.waterfallmc.waterfall.event;
|
|
|
|
+
|
|
|
|
+import net.md_5.bungee.api.CommandSender;
|
|
|
|
+import net.md_5.bungee.api.connection.Connection;
|
|
|
|
+import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
|
|
+import net.md_5.bungee.api.event.TargetedEvent;
|
|
|
|
+import net.md_5.bungee.api.plugin.Command;
|
|
|
|
+import net.md_5.bungee.api.plugin.Event;
|
|
|
|
+
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import lombok.Data;
|
|
|
|
+import lombok.EqualsAndHashCode;
|
|
|
|
+import lombok.ToString;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Called when the proxy intercepts the command packet
|
|
|
|
+ * allowing for plugins to prevent commands being added
|
|
|
|
+ * to the clients which might not be wanted.
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ * <i>Plugin developers, please implement {@link Command#hasPermission(CommandSender)}
|
|
|
|
+ * properly in favor of this event.</i>
|
|
|
|
+ */
|
|
|
|
+@Data
|
|
|
|
+@ToString(callSuper = true)
|
|
|
|
+@EqualsAndHashCode(callSuper = true)
|
|
|
|
+public class ProxyDefineCommandsEvent extends TargetedEvent {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * The map of commands to be sent to the player
|
|
|
|
+ */
|
|
|
|
+ private final Map<String, Command> commands;
|
|
|
|
+
|
|
|
|
+ public ProxyDefineCommandsEvent(Connection sender, Connection receiver, Map<String, Command> commands) {
|
|
|
|
+ super(sender, receiver);
|
|
|
|
+ this.commands = commands;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
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
|
2020-08-29 13:11:57 +02:00
|
|
|
index 72b6e9be..ace177ba 100644
|
2019-03-16 08:08:11 +01:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
|
2020-01-21 18:36:22 +01:00
|
|
|
@@ -12,7 +12,8 @@ import com.mojang.brigadier.context.StringRange;
|
2019-04-23 10:09:26 +02:00
|
|
|
import com.mojang.brigadier.suggestion.Suggestion;
|
2019-03-16 08:08:11 +01:00
|
|
|
import com.mojang.brigadier.suggestion.Suggestions;
|
|
|
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
2019-04-23 10:09:26 +02:00
|
|
|
-import java.util.Objects; // Waterfall
|
2019-03-16 08:08:11 +01:00
|
|
|
+
|
|
|
|
+import io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent; // Waterfall
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.ByteBufAllocator;
|
|
|
|
import io.netty.buffer.Unpooled;
|
2020-01-21 18:36:22 +01:00
|
|
|
@@ -20,8 +21,10 @@ import io.netty.channel.unix.DomainSocketAddress;
|
2019-04-23 10:09:26 +02:00
|
|
|
import java.io.DataInput;
|
2020-01-21 18:36:22 +01:00
|
|
|
import java.net.InetSocketAddress;
|
2019-04-23 10:09:26 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap; // Waterfall
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
+import java.util.Objects; // Waterfall
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import net.md_5.bungee.ServerConnection;
|
2020-01-24 23:41:39 +01:00
|
|
|
import net.md_5.bungee.ServerConnection.KeepAliveData;
|
2020-08-29 13:11:57 +02:00
|
|
|
@@ -680,9 +683,25 @@ public class DownstreamBridge extends PacketHandler
|
2019-03-16 08:08:11 +01:00
|
|
|
{
|
|
|
|
boolean modified = false;
|
|
|
|
|
|
|
|
- for ( Map.Entry<String, Command> command : bungee.getPluginManager().getCommands() )
|
|
|
|
+ // Waterfall start
|
|
|
|
+ Map<String, Command> commandMap = new HashMap<>();
|
|
|
|
+ for ( Map.Entry<String, Command> commandEntry : bungee.getPluginManager().getCommands() ) {
|
|
|
|
+ if ( !bungee.getDisabledCommands().contains( commandEntry.getKey() )
|
|
|
|
+ && commands.getRoot().getChild( commandEntry.getKey() ) == null
|
|
|
|
+ && commandEntry.getValue().hasPermission( this.con ) ) {
|
|
|
|
+
|
|
|
|
+ commandMap.put( commandEntry.getKey(), commandEntry.getValue() );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ProxyDefineCommandsEvent event = new ProxyDefineCommandsEvent( this.server, this.con, commandMap );
|
|
|
|
+ bungee.getPluginManager().callEvent( event );
|
|
|
|
+
|
|
|
|
+ for ( Map.Entry<String, Command> command : event.getCommands().entrySet() )
|
|
|
|
{
|
|
|
|
- if ( !bungee.getDisabledCommands().contains( command.getKey() ) && commands.getRoot().getChild( command.getKey() ) == null && command.getValue().hasPermission( con ) )
|
|
|
|
+ //noinspection ConstantConditions
|
|
|
|
+ if ( true ) // Moved up
|
|
|
|
+ // Waterfall end
|
|
|
|
{
|
|
|
|
LiteralCommandNode dummy = LiteralArgumentBuilder.literal( command.getKey() )
|
|
|
|
.then( RequiredArgumentBuilder.argument( "args", StringArgumentType.greedyString() )
|
|
|
|
--
|
2020-08-29 13:11:57 +02:00
|
|
|
2.28.0
|
2019-03-16 08:08:11 +01:00
|
|
|
|