mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 20:59:12 +01:00
#2578: Add easy way to get proxy command iff it is enabled for that sender
This commit is contained in:
parent
712a60ffd2
commit
3889f8683d
@ -3,8 +3,11 @@ package net.md_5.bungee.api.event;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
import net.md_5.bungee.api.connection.Connection;
|
||||||
import net.md_5.bungee.api.plugin.Cancellable;
|
import net.md_5.bungee.api.plugin.Cancellable;
|
||||||
|
import net.md_5.bungee.api.plugin.PluginManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event called when a player sends a message to a server.
|
* Event called when a player sends a message to a server.
|
||||||
@ -39,4 +42,24 @@ public class ChatEvent extends TargetedEvent implements Cancellable
|
|||||||
{
|
{
|
||||||
return message.length() > 0 && message.charAt( 0 ) == '/';
|
return message.length() > 0 && message.charAt( 0 ) == '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether this message is run on this proxy server.
|
||||||
|
*
|
||||||
|
* @return if this command runs on the proxy
|
||||||
|
* @see PluginManager#isExecutableCommand(java.lang.String, net.md_5.bungee.api.CommandSender)
|
||||||
|
*/
|
||||||
|
public boolean isProxyCommand()
|
||||||
|
{
|
||||||
|
if ( !isCommand() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = message.indexOf( " " );
|
||||||
|
String commandName = ( index == -1 ) ? message.substring( 1 ) : message.substring( 1, index );
|
||||||
|
CommandSender sender = ( getSender() instanceof CommandSender ) ? (CommandSender) getSender() : null;
|
||||||
|
|
||||||
|
return ProxyServer.getInstance().getPluginManager().isExecutableCommand( commandName, sender );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,32 @@ public class PluginManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Command getCommandIfEnabled(String commandName, CommandSender sender)
|
||||||
|
{
|
||||||
|
String commandLower = commandName.toLowerCase( Locale.ROOT );
|
||||||
|
|
||||||
|
// Check if command is disabled when a player sent the command
|
||||||
|
if ( ( sender instanceof ProxiedPlayer ) && proxy.getDisabledCommands().contains( commandLower ) )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return commandMap.get( commandLower );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the command is registered and can possibly be executed by the
|
||||||
|
* sender (without taking permissions into account).
|
||||||
|
*
|
||||||
|
* @param commandName the name of the command
|
||||||
|
* @param sender the sender executing the command
|
||||||
|
* @return whether the command will be handled
|
||||||
|
*/
|
||||||
|
public boolean isExecutableCommand(String commandName, CommandSender sender)
|
||||||
|
{
|
||||||
|
return getCommandIfEnabled( commandName, sender ) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean dispatchCommand(CommandSender sender, String commandLine)
|
public boolean dispatchCommand(CommandSender sender, String commandLine)
|
||||||
{
|
{
|
||||||
return dispatchCommand( sender, commandLine, null );
|
return dispatchCommand( sender, commandLine, null );
|
||||||
@ -133,12 +159,7 @@ public class PluginManager
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String commandName = split[0].toLowerCase( Locale.ROOT );
|
Command command = getCommandIfEnabled( split[0], sender );
|
||||||
if ( sender instanceof ProxiedPlayer && proxy.getDisabledCommands().contains( commandName ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Command command = commandMap.get( commandName );
|
|
||||||
if ( command == null )
|
if ( command == null )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user