1. Welcome to LilyPad. Download the project, explore the forums, and create your own LilyPad network.


    If you use the software and enjoy it or have a question, or would like to contribute to the future of the software directly or through resources, please sign up and join our little community.
TakeMeNL

LilypadWhitelist

whitelist bukkit no relog

  1. TakeMeNL
    Do you have a whitelist server within you server cloud?
    Do you not want to lose players because you are busy on the server and turned on the whitelist for a brief moment?

    DL: https://seafile.dutchmasterserver.nl/f/390bc547e6fa44f49d12/?dl=1

    Well you need LilypadWhitelist!


    Commands
    /lw reload - reloads the whitelist and settings
    /lw add [player] - adds player to the LilypadWhitelist
    /lw remove [player] - removes player from LilypadWhitelist
    /lw on|off - actives/deactivates LilypadWhitelist
    /lw list - List whitelist entries


    Permissions
    Only one permission: lilywhitelist.use - Default is OP.


    Config
    hubServer - This is you HUB/Lobby server name
    kickReason - This is the text that is being send to the player when the whitelist is on. You can use all color codes! &(0-9,a-f,k-o)
    whitelist.txt - This is the file where all names are stored.
    You can manually add players on each newline.
    Example:
    Code (text):
    TakeMeNL
    Player1
    Player2
    Player3
     

    Source Code
    For those who like to see the source code, here it is.
    If you see something weird, please let me know.
    Code (text):
    package com.DutchMasterServer.LilypadWhitelist;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;

    import lilypad.client.connect.api.Connect;
    import lilypad.client.connect.api.request.impl.RedirectRequest;
    import lilypad.client.connect.api.result.FutureResultListener;
    import lilypad.client.connect.api.result.StatusCode;
    import lilypad.client.connect.api.result.impl.RedirectResult;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class LilypadWhitelist extends JavaPlugin implements Listener {

        private FileConfiguration    config;
        private File                configFolder;
        private String                whitelistFile;
        private boolean                WhitelistEnabled;
        private String                hubServer;
        private String                kickReason;
        private String                prefix    = ChatColor.GREEN + "Lilypad" + ChatColor.WHITE + "Whitelist" + ChatColor.RESET;
        private List<String>        whitelistedPlayers;

        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
            config = getConfig();
            configFolder = getDataFolder();
            whitelistFile = configFolder.getAbsolutePath() + File.separator + "whitelist.txt";

            whitelistedPlayers = new ArrayList<String>();

            hubServer = config.getString("hubServer");
            kickReason = config.getString("kickReason");

            File fWhitelist = new File(whitelistFile);
            if (!fWhitelist.exists()) {
                getLogger().warning("whitelist file is missing, creating...");
                try {
                    fWhitelist.createNewFile();
                }
                catch (IOException ex) {
                    System.out.println("Failed to create whitelist.txt");
                }
            }

            loadWhitelist();

            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
        }

        public boolean isWhitelistActive() {
            return WhitelistEnabled;
        }

        public void setWhitelistActive(boolean b) {
            WhitelistEnabled = b;
        }

        public Connect getBukkitConnect() {
            return (Connect) getServer().getServicesManager().getRegistration(Connect.class).getProvider();
        }

        public void connectToServer(Player p, String server) {
            try {
                Connect c = getBukkitConnect();
                c.request(new RedirectRequest(server, p.getName())).registerListener(new FutureResultListener<RedirectResult>() {
                    public void onResult(RedirectResult redirectResult) {
                        if (redirectResult.getStatusCode() == StatusCode.SUCCESS) {
                            return;
                        }
                    }
                });

            }
            catch (Exception ex) {
                ex.printStackTrace();
            }
        }

        private static String parseChatColors(String m) {
            return m.replaceAll("&", "\u00A7");
        }

        private boolean loadWhitelist() {
            getLogger().info("Trying to load whitelist");

            try {
                whitelistedPlayers.clear();
                BufferedReader reader = new BufferedReader(new FileReader(whitelistFile));
                String line = reader.readLine();
                while (line != null) {
                    whitelistedPlayers.add(line);
                    line = reader.readLine();
                }
                reader.close();
            }
            catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }

        public boolean saveWhitelist() {
            try {
                BufferedWriter writer = new BufferedWriter(new FileWriter(configFolder.getAbsolutePath() + File.separator + "whitelist.txt"));
                for (String player : whitelistedPlayers) {
                    writer.write(player);
                    writer.newLine();
                }
                writer.close();
            }
            catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }

        public boolean reloadWhitelist() {
            return loadWhitelist();
        }

        public boolean isWhitelisted(Player p) {
            for (String player : whitelistedPlayers) {
                if (player.compareToIgnoreCase(p.getName()) == 0) {
                    return true;
                }
            }
            return false;
        }

        public boolean isOnWhitelist(String playerName) {
            for (String player : whitelistedPlayers) {
                if (player.compareToIgnoreCase(playerName) == 0)
                    return true;
            }
            return false;
        }

        public boolean addToWhitelist(String p) {
            if (!isOnWhitelist(p)) {
                whitelistedPlayers.add(p);
                return saveWhitelist();
            }
            return false;
        }

        public boolean removeFromWhitelist(String p) {
            for (int i = 0; i < whitelistedPlayers.size(); i++) {
                if (p.compareToIgnoreCase((String) whitelistedPlayers.get(i)) == 0) {
                    whitelistedPlayers.remove(i);
                    return saveWhitelist();
                }
            }
            return false;
        }

        public String getWhitelist() {
            String result = "";
            for (String player : whitelistedPlayers) {
                if (result.length() > 1) {
                    result = result + ", ";
                }
                result = result + player;
            }

            return result;
        }

        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("lilywhitelist")) {
                if (!sender.hasPermission("lilywhitelist.use")) {
                    sender.sendMessage(ChatColor.RED + "You don't have permission to do that!");
                    return true;
                }
                if (args.length < 1 || args[0].equalsIgnoreCase("help")) {
                    sender.sendMessage(ChatColor.YELLOW + "Commands:");
                    sender.sendMessage(ChatColor.YELLOW + "/lw reload  (reloads the whitelist and settings)");
                    sender.sendMessage(ChatColor.YELLOW + "/lw add [player]  (adds player to the " + prefix + ChatColor.YELLOW + ")");
                    sender.sendMessage(ChatColor.YELLOW + "/lw remove [player]  (removes player from " + prefix + ChatColor.YELLOW + ")");
                    sender.sendMessage(ChatColor.YELLOW + "/lw on|off  (actives/deactivates " + prefix + ChatColor.YELLOW + ")");
                    sender.sendMessage(ChatColor.YELLOW + "/lw list  (list whitelist entries)");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")) {
                    if (reloadWhitelist()) {
                        hubServer = config.getString("hubServer");
                        kickReason = config.getString("kickReason");
                        getLogger().info("- " + sender.getName() + " has reloaded the whitelist.");
                        sender.sendMessage("[" + prefix + "] - " + ChatColor.GREEN + "whitelist reloaded!");
                    }
                    return true;
                }
                if (args[0].equalsIgnoreCase("add")) {
                    if (args.length < 2) {
                        sender.sendMessage(ChatColor.RED + "/lw add [player]");
                    }
                    else if (addToWhitelist(args[1])) {
                        getLogger().info("- " + sender.getName() + " has added \"" + args[1] + "\" to the whitelist.");
                        sender.sendMessage("[" + prefix + "] - " + ChatColor.GREEN + "Player \"" + args[1] + "\" has been added to the whitelist!");
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Could not add player \"" + args[1] + "\"");
                    }
                    return true;
                }
                if (args[0].equalsIgnoreCase("remove")) {
                    if (args.length < 2) {
                        sender.sendMessage(ChatColor.RED + "/lw remove [player]");
                    }
                    else if (removeFromWhitelist(args[1])) {
                        getLogger().info("- " + sender.getName() + " has been removed \"" + args[1] + "\" from the whitelist.");
                        sender.sendMessage("[" + prefix + "] - " + ChatColor.GREEN + "Player \"" + args[1] + "\" has been removed from the whitelist!");
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Could not remove player \"" + args[1] + "\"");
                    }
                    return true;
                }
                if (args[0].equalsIgnoreCase("on")) {
                    setWhitelistActive(true);
                    getLogger().info("- " + sender.getName() + " has enabled the whitelist.");
                    sender.sendMessage("[" + prefix + "] - " + ChatColor.GREEN + "activated!");
                    return true;
                }
                if (args[0].equalsIgnoreCase("off")) {
                    setWhitelistActive(false);
                    getLogger().info("- " + sender.getName() + " has deactivated the whitelist.");
                    sender.sendMessage("[" + prefix + "] - " + ChatColor.RED + "deactivated!");
                    return true;
                }
                if (args[0].equalsIgnoreCase("list")) {
                    sender.sendMessage(ChatColor.YELLOW + "Players on whitelist: " + ChatColor.GRAY + getWhitelist());
                    return true;
                }
            }
            return true;
        }

        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            if (isWhitelistActive()) {
                reloadWhitelist();
                Player player = event.getPlayer();
                if (!isWhitelisted(player)) {
                    for (int x = 0; x <= 11; x++) {
                        player.sendMessage("");
                    }
                    event.setJoinMessage(parseChatColors(kickReason));
                    connectToServer(player, hubServer);
                }
            }
        }
    }
     

Recent Updates

  1. LilypadWhitelist 1.0 - First Upload

Recent Reviews

  1. Matt
    5/5,
    Good job!