Compare commits
1 Commits
patch-tabc
...
patch-loop
Author | SHA1 | Date | |
---|---|---|---|
6949470e3b
|
@@ -1,40 +0,0 @@
|
|||||||
package net.md_5.bungee.api.event;
|
|
||||||
|
|
||||||
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.plugin.Cancellable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event called when an 1.13+ player uses tab completion.
|
|
||||||
* This event is fired after {@link TabCompleteEvent}.
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@ToString(callSuper = true)
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class BrigadierSuggestionsEvent extends TargetedEvent implements Cancellable
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancelled state.
|
|
||||||
*/
|
|
||||||
private boolean cancelled;
|
|
||||||
/**
|
|
||||||
* The message the player has already entered.
|
|
||||||
*/
|
|
||||||
private final String cursor;
|
|
||||||
/**
|
|
||||||
* 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 BrigadierSuggestionsEvent(Connection sender, Connection receiver, String cursor, Suggestions suggestions)
|
|
||||||
{
|
|
||||||
super( sender, receiver );
|
|
||||||
this.cursor = cursor;
|
|
||||||
this.suggestions = suggestions;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -9,8 +9,6 @@ import net.md_5.bungee.api.plugin.Cancellable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Event called when a player uses tab completion.
|
* Event called when a player uses tab completion.
|
||||||
* For 1.13+ clients, you can also use {@link BrigadierSuggestionsEvent} for
|
|
||||||
* more control of the suggestions.
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
|
@@ -19,29 +19,31 @@ public class BungeeSecurityManager extends SecurityManager
|
|||||||
private void checkRestricted(String text)
|
private void checkRestricted(String text)
|
||||||
{
|
{
|
||||||
Class[] context = getClassContext();
|
Class[] context = getClassContext();
|
||||||
for ( int i = 2; i < context.length; i++ )
|
int i = 2;
|
||||||
|
if ( i >= context.length )
|
||||||
{
|
{
|
||||||
ClassLoader loader = context[i].getClassLoader();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Bungee / system can do everything
|
ClassLoader loader = context[i].getClassLoader();
|
||||||
if ( loader == ClassLoader.getSystemClassLoader() || loader == null )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
AccessControlException ex = new AccessControlException( "Plugin violation: " + text );
|
// Bungee / system can do everything
|
||||||
if ( ENFORCE )
|
if ( loader == ClassLoader.getSystemClassLoader() || loader == null )
|
||||||
{
|
{
|
||||||
throw ex;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringWriter stack = new StringWriter();
|
AccessControlException ex = new AccessControlException( "Plugin violation: " + text );
|
||||||
ex.printStackTrace( new PrintWriter( stack ) );
|
if ( ENFORCE )
|
||||||
if ( seen.add( stack.toString() ) )
|
{
|
||||||
{
|
throw ex;
|
||||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Plugin performed restricted action, please inform them to use proper API methods: " + text, ex );
|
}
|
||||||
}
|
|
||||||
break;
|
StringWriter stack = new StringWriter();
|
||||||
|
ex.printStackTrace( new PrintWriter( stack ) );
|
||||||
|
if ( seen.add( stack.toString() ) )
|
||||||
|
{
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Plugin performed restricted action, please inform them to use proper API methods: " + text, ex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ import com.mojang.brigadier.suggestion.Suggestion;
|
|||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.ServerConnection.KeepAliveData;
|
import net.md_5.bungee.ServerConnection.KeepAliveData;
|
||||||
@@ -13,7 +14,6 @@ import net.md_5.bungee.UserConnection;
|
|||||||
import net.md_5.bungee.Util;
|
import net.md_5.bungee.Util;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.BrigadierSuggestionsEvent;
|
|
||||||
import net.md_5.bungee.api.event.ChatEvent;
|
import net.md_5.bungee.api.event.ChatEvent;
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
@@ -172,48 +172,34 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
TabCompleteEvent tabCompleteEvent = new TabCompleteEvent( con, con.getServer(), tabComplete.getCursor(), suggestions );
|
TabCompleteEvent tabCompleteEvent = new TabCompleteEvent( con, con.getServer(), tabComplete.getCursor(), suggestions );
|
||||||
bungee.getPluginManager().callEvent( tabCompleteEvent );
|
bungee.getPluginManager().callEvent( tabCompleteEvent );
|
||||||
|
|
||||||
List<String> legacyResults = tabCompleteEvent.getSuggestions();
|
if ( tabCompleteEvent.isCancelled() )
|
||||||
|
|
||||||
if ( con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_13 )
|
|
||||||
{
|
{
|
||||||
if ( tabCompleteEvent.isCancelled() )
|
throw CancelSendSignal.INSTANCE;
|
||||||
{
|
}
|
||||||
throw CancelSendSignal.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !legacyResults.isEmpty() )
|
List<String> results = tabCompleteEvent.getSuggestions();
|
||||||
{
|
if ( !results.isEmpty() )
|
||||||
con.unsafe().sendPacket( new TabCompleteResponse( legacyResults ) );
|
|
||||||
throw CancelSendSignal.INSTANCE;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
int start = tabComplete.getCursor().lastIndexOf( ' ' ) + 1;
|
// 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
|
||||||
int end = tabComplete.getCursor().length();
|
// Bungee plugins are adding results for commands they don't own anyway
|
||||||
StringRange lastArgumentRange = StringRange.between( start, end );
|
if ( con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_13 )
|
||||||
|
|
||||||
List<Suggestion> brigadier = new ArrayList<>( legacyResults.size() );
|
|
||||||
for ( String s : legacyResults )
|
|
||||||
{
|
{
|
||||||
brigadier.add( new Suggestion( lastArgumentRange, s ) );
|
con.unsafe().sendPacket( new TabCompleteResponse( results ) );
|
||||||
}
|
} else
|
||||||
|
|
||||||
BrigadierSuggestionsEvent tabCompleteRequestEvent = new BrigadierSuggestionsEvent( con, con.getServer(), tabComplete.getCursor(), new Suggestions( lastArgumentRange, brigadier ) );
|
|
||||||
tabCompleteRequestEvent.setCancelled( tabCompleteEvent.isCancelled() );
|
|
||||||
bungee.getPluginManager().callEvent( tabCompleteRequestEvent );
|
|
||||||
|
|
||||||
if ( tabCompleteRequestEvent.isCancelled() )
|
|
||||||
{
|
{
|
||||||
throw CancelSendSignal.INSTANCE;
|
int start = tabComplete.getCursor().lastIndexOf( ' ' ) + 1;
|
||||||
}
|
int end = tabComplete.getCursor().length();
|
||||||
|
StringRange range = StringRange.between( start, end );
|
||||||
|
|
||||||
Suggestions brigadierResults = tabCompleteRequestEvent.getSuggestions();
|
List<Suggestion> brigadier = new LinkedList<>();
|
||||||
|
for ( String s : results )
|
||||||
|
{
|
||||||
|
brigadier.add( new Suggestion( range, s ) );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !brigadierResults.isEmpty() )
|
con.unsafe().sendPacket( new TabCompleteResponse( tabComplete.getTransactionId(), new Suggestions( range, brigadier ) ) );
|
||||||
{
|
|
||||||
con.unsafe().sendPacket( new TabCompleteResponse( tabComplete.getTransactionId(), brigadierResults ) );
|
|
||||||
throw CancelSendSignal.INSTANCE;
|
|
||||||
}
|
}
|
||||||
|
throw CancelSendSignal.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user