mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-12-26 10:37:46 +01:00
Add #183 - restricted servers
This commit is contained in:
parent
f02d17c979
commit
fea3642550
@ -208,9 +208,10 @@ public abstract class ProxyServer
|
|||||||
*
|
*
|
||||||
* @param name name of the server
|
* @param name name of the server
|
||||||
* @param address connectable Minecraft address + port of the server
|
* @param address connectable Minecraft address + port of the server
|
||||||
|
* @param restricted whether the server info restricted property will be set
|
||||||
* @return the constructed instance
|
* @return the constructed instance
|
||||||
*/
|
*/
|
||||||
public abstract ServerInfo constructServerInfo(String name, InetSocketAddress address);
|
public abstract ServerInfo constructServerInfo(String name, InetSocketAddress address, boolean restricted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the console overlord for this proxy. Being the console, this
|
* Returns the console overlord for this proxy. Being the console, this
|
||||||
|
@ -31,6 +31,10 @@ public abstract class ServerInfo
|
|||||||
* Players connected to a server defined by these properties.
|
* Players connected to a server defined by these properties.
|
||||||
*/
|
*/
|
||||||
private final Collection<ProxiedPlayer> players = new ArrayList<>();
|
private final Collection<ProxiedPlayer> players = new ArrayList<>();
|
||||||
|
/**
|
||||||
|
* If set to true, users will need special permissions to view this server.
|
||||||
|
*/
|
||||||
|
private final boolean restricted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a player to the internal set of this server.
|
* Add a player to the internal set of this server.
|
||||||
@ -79,4 +83,16 @@ public abstract class ServerInfo
|
|||||||
* @param callback the callback to call when the count has been retrieved.
|
* @param callback the callback to call when the count has been retrieved.
|
||||||
*/
|
*/
|
||||||
public abstract void ping(Callback<ServerPing> callback);
|
public abstract void ping(Callback<ServerPing> callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the player can access this server. It will only return false when
|
||||||
|
* the player has no permission and this server is restricted.
|
||||||
|
*
|
||||||
|
* @param player the player to check access for
|
||||||
|
* @return whether access is granted to this server
|
||||||
|
*/
|
||||||
|
public boolean canAccess(ProxiedPlayer player)
|
||||||
|
{
|
||||||
|
return restricted && player.hasPermission( "bungeecord.server." + name );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,9 +368,9 @@ public class BungeeCord extends ProxyServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerInfo constructServerInfo(String name, InetSocketAddress address)
|
public ServerInfo constructServerInfo(String name, InetSocketAddress address, boolean restricted)
|
||||||
{
|
{
|
||||||
return new BungeeServerInfo( name, address );
|
return new BungeeServerInfo( name, address, restricted );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,9 +26,9 @@ public class BungeeServerInfo extends ServerInfo
|
|||||||
@Getter
|
@Getter
|
||||||
private final Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
private final Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
public BungeeServerInfo(String name, InetSocketAddress address)
|
public BungeeServerInfo(String name, InetSocketAddress address, boolean restricted)
|
||||||
{
|
{
|
||||||
super( name, address );
|
super( name, address, restricted );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package net.md_5.bungee.command;
|
package net.md_5.bungee.command;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
@ -27,16 +29,22 @@ public class CommandServer extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
Map<String, ServerInfo> servers = BungeeCord.getInstance().config.getServers();
|
Map<String, ServerInfo> servers = ProxyServer.getInstance().getServers();
|
||||||
if ( args.length == 0 )
|
if ( args.length == 0 )
|
||||||
{
|
{
|
||||||
StringBuilder serverList = new StringBuilder();
|
StringBuilder serverList = new StringBuilder();
|
||||||
for ( String server : servers.keySet() )
|
for ( ServerInfo server : servers.values() )
|
||||||
{
|
{
|
||||||
serverList.append( server );
|
if ( server.canAccess( player ) )
|
||||||
serverList.append( ", " );
|
{
|
||||||
|
serverList.append( server );
|
||||||
|
serverList.append( ", " );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( serverList.length() != 0 )
|
||||||
|
{
|
||||||
|
serverList.setLength( serverList.length() - 2 );
|
||||||
}
|
}
|
||||||
serverList.setLength( serverList.length() - 2 );
|
|
||||||
player.sendMessage( ChatColor.GOLD + "You may connect to the following servers at this time: " + serverList.toString() );
|
player.sendMessage( ChatColor.GOLD + "You may connect to the following servers at this time: " + serverList.toString() );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@ -47,6 +55,9 @@ public class CommandServer extends Command
|
|||||||
} else if ( server.equals( player.getServer().getInfo() ) )
|
} else if ( server.equals( player.getServer().getInfo() ) )
|
||||||
{
|
{
|
||||||
player.sendMessage( ChatColor.RED + "You are already on this server." );
|
player.sendMessage( ChatColor.RED + "You are already on this server." );
|
||||||
|
} else if ( !server.canAccess( player ) )
|
||||||
|
{
|
||||||
|
player.sendMessage( ChatColor.RED + "You don't have permission to access this server" );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
player.connect( server );
|
player.connect( server );
|
||||||
|
@ -151,8 +151,9 @@ public class YamlConfig implements ConfigurationAdapter
|
|||||||
Map<String, Object> val = entry.getValue();
|
Map<String, Object> val = entry.getValue();
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
String addr = get( "address", "localhost:25565", val );
|
String addr = get( "address", "localhost:25565", val );
|
||||||
|
boolean restricted = get( "restricted", false );
|
||||||
InetSocketAddress address = Util.getAddr( addr );
|
InetSocketAddress address = Util.getAddr( addr );
|
||||||
ServerInfo info = ProxyServer.getInstance().constructServerInfo( name, address );
|
ServerInfo info = ProxyServer.getInstance().constructServerInfo( name, address, restricted );
|
||||||
ret.put( name, info );
|
ret.put( name, info );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user