Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.antibot;
- import com.antibot.checks.SameIPCheck;
- import com.antibot.commands.CommandAntiBot;
- import com.google.common.io.ByteStreams;
- import net.md_5.bungee.api.ChatColor;
- import net.md_5.bungee.api.chat.ComponentBuilder;
- import net.md_5.bungee.api.connection.ProxiedPlayer;
- import net.md_5.bungee.api.plugin.Plugin;
- import net.md_5.bungee.config.Configuration;
- import net.md_5.bungee.config.ConfigurationProvider;
- import net.md_5.bungee.config.YamlConfiguration;
- import java.io.*;
- import java.util.concurrent.TimeUnit;
- /**
- * Created by Derek on 11/3/2014.
- * Time: 7:08 PM
- */
- public class AntiBot extends Plugin {
- public static AntiBot p;
- private Configuration configuration;
- @Override
- public void onEnable() {
- reload();
- }
- public void reload() {
- reloadConfig();
- unregisterChecks();
- unregisterCommands();
- p = this;
- registerChecks();
- registerCommands();
- }
- private void reloadConfig() {
- if (!getDataFolder().exists()) {
- getDataFolder().mkdir();
- }
- File configFile = new File(getDataFolder(), "config.yml");
- try {
- if (!configFile.exists()) {
- configFile.createNewFile();
- InputStream inputStream = getResourceAsStream("config.yml");
- OutputStream outputStream = new FileOutputStream(configFile);
- ByteStreams.copy(inputStream, outputStream);
- }
- configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
- ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, configFile);
- } catch (IOException e) {
- throw new RuntimeException("Unable to create configration file", e);
- }
- }
- private void unregisterChecks() {
- getProxy().getPluginManager().unregisterListeners(this);
- System.out.println(getProxy().getScheduler().cancel(this));
- }
- private void unregisterCommands() {
- getProxy().getPluginManager().unregisterCommands(this);
- }
- private void registerChecks() {
- if (configuration.getBoolean(ConfigPaths.CHECKS_SAME_IP_ENABLED)) {
- getProxy().getScheduler().schedule(this, new Runnable() {
- @Override
- public void run() {
- getProxy().getPluginManager().registerListener(AntiBot.p, new SameIPCheck());
- for (ProxiedPlayer proxiedPlayer : AntiBot.p.getProxy().getPlayers()) {
- if (proxiedPlayer.hasPermission("antibot.admin")) {
- proxiedPlayer.sendMessage(new ComponentBuilder("ยป ").color(ChatColor.DARK_RED).append("Same IP check enabled.").color(ChatColor.RED).create());
- }
- }
- }
- }, configuration.getInt(ConfigPaths.CHECKS_SAME_IP_ENABLE_DELAY), TimeUnit.SECONDS);
- }
- }
- private void registerCommands() {
- getProxy().getPluginManager().registerCommand(this, new CommandAntiBot());
- }
- public Configuration getConfiguration() {
- return configuration;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement