#2572: Add additional APIs regarding server restriction

This commit is contained in:
md_5 2019-01-03 16:35:32 +11:00
parent a12bb4cead
commit 4fa1d82b81
3 changed files with 36 additions and 2 deletions

View File

@ -43,6 +43,22 @@ public interface ServerInfo
*/
String getMotd();
/**
* Whether this server is restricted and therefore only players with the
* given permission can access it.
*
* @return if restricted
*/
boolean isRestricted();
/**
* Get the permission required to access this server. Only enforced when the
* server is restricted.
*
* @return access permission
*/
String getPermission();
/**
* Whether the player can access this server. It will only return false when
* the player has no permission and this server is restricted.

View File

@ -38,11 +38,23 @@ public class ServerConnectRequestTest
}
@Override
public boolean canAccess(CommandSender sender)
public boolean isRestricted()
{
return false;
}
@Override
public String getPermission()
{
return null;
}
@Override
public boolean canAccess(CommandSender sender)
{
return true;
}
@Override
public void sendData(String channel, byte[] data)
{

View File

@ -69,11 +69,17 @@ public class BungeeServerInfo implements ServerInfo
return Collections.unmodifiableCollection( new HashSet<>( players ) );
}
@Override
public String getPermission()
{
return "bungeecord.server." + name;
}
@Override
public boolean canAccess(CommandSender player)
{
Preconditions.checkNotNull( player, "player" );
return !restricted || player.hasPermission( "bungeecord.server." + name );
return !restricted || player.hasPermission( getPermission() );
}
@Override