Search in sources :

Example 1 with BanList

use of org.bukkit.BanList in project Glowstone by GlowstoneMC.

the class EventFactory method onPlayerLogin.

/**
 * Handles post-hooks for a player login, including the name and IP banlists, whitelist policy
 * and occupancy limit.
 *
 * @param player the login
 * @param hostname the hostname that was used to connect to the server
 * @return the completed event
 */
public PlayerLoginEvent onPlayerLogin(GlowPlayer player, String hostname) {
    Server server = player.getServer();
    InetAddress address = player.getAddress().getAddress();
    String addressString = address.getHostAddress();
    PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, address);
    BanList nameBans = server.getBanList(Type.NAME);
    BanList ipBans = server.getBanList(Type.IP);
    if (nameBans.isBanned(player.getName())) {
        event.disallow(Result.KICK_BANNED, Kick.BANNED.get(nameBans.getBanEntry(player.getName()).getReason()));
    } else if (ipBans.isBanned(addressString)) {
        event.disallow(Result.KICK_BANNED, Kick.BANNED.get(ipBans.getBanEntry(addressString).getReason()));
    } else if (checkWhitelisted(player, event) && server.getOnlinePlayers().size() >= server.getMaxPlayers()) {
        event.disallow(Result.KICK_FULL, Kick.FULL.get(server.getMaxPlayers()));
    }
    return callEvent(event);
}
Also used : Server(org.bukkit.Server) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) InetAddress(java.net.InetAddress) BanList(org.bukkit.BanList)

Example 2 with BanList

use of org.bukkit.BanList in project Glowstone by GlowstoneMC.

the class PardonCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    if (args.length != 1) {
        sendUsageMessage(sender, commandMessages);
        return false;
    }
    String name = args[0];
    final GlowServer server = (GlowServer) ServerProvider.getServer();
    // asynchronously lookup player
    server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
        if (ex != null) {
            new LocalizedStringImpl("pardon.exception", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
            ex.printStackTrace();
            return;
        }
        BanList banList = server.getBanList(BanList.Type.NAME);
        String exactName = player.getName();
        if (!banList.isBanned(exactName)) {
            new LocalizedStringImpl("pardon.not-banned", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, exactName);
            return;
        }
        banList.pardon(exactName);
        new LocalizedStringImpl("pardon.done", commandMessages.getResourceBundle()).send(sender, exactName);
    });
    // todo: asynchronous command callbacks?
    return true;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowServer(net.glowstone.GlowServer) BanList(org.bukkit.BanList)

Aggregations

BanList (org.bukkit.BanList)2 InetAddress (java.net.InetAddress)1 GlowServer (net.glowstone.GlowServer)1 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)1 Server (org.bukkit.Server)1 PlayerLoginEvent (org.bukkit.event.player.PlayerLoginEvent)1