Advertisement
Guest User

AnitBot

a guest
Nov 25th, 2014
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. package com.antibot;
  2.  
  3. import com.antibot.checks.SameIPCheck;
  4. import com.antibot.commands.CommandAntiBot;
  5. import com.google.common.io.ByteStreams;
  6. import net.md_5.bungee.api.ChatColor;
  7. import net.md_5.bungee.api.chat.ComponentBuilder;
  8. import net.md_5.bungee.api.connection.ProxiedPlayer;
  9. import net.md_5.bungee.api.plugin.Plugin;
  10. import net.md_5.bungee.config.Configuration;
  11. import net.md_5.bungee.config.ConfigurationProvider;
  12. import net.md_5.bungee.config.YamlConfiguration;
  13.  
  14. import java.io.*;
  15. import java.util.concurrent.TimeUnit;
  16.  
  17. /**
  18.  * Created by Derek on 11/3/2014.
  19.  * Time: 7:08 PM
  20.  */
  21. public class AntiBot extends Plugin {
  22.  
  23.     public static AntiBot p;
  24.     private Configuration configuration;
  25.  
  26.     @Override
  27.     public void onEnable() {
  28.         reload();
  29.     }
  30.  
  31.     public void reload() {
  32.         reloadConfig();
  33.  
  34.         unregisterChecks();
  35.         unregisterCommands();
  36.  
  37.         p = this;
  38.  
  39.         registerChecks();
  40.         registerCommands();
  41.     }
  42.  
  43.     private void reloadConfig() {
  44.         if (!getDataFolder().exists()) {
  45.             getDataFolder().mkdir();
  46.         }
  47.  
  48.         File configFile = new File(getDataFolder(), "config.yml");
  49.         try {
  50.             if (!configFile.exists()) {
  51.                 configFile.createNewFile();
  52.                 InputStream inputStream = getResourceAsStream("config.yml");
  53.                 OutputStream outputStream = new FileOutputStream(configFile);
  54.                 ByteStreams.copy(inputStream, outputStream);
  55.             }
  56.             configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
  57.             ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, configFile);
  58.         } catch (IOException e) {
  59.             throw  new RuntimeException("Unable to create configration file", e);
  60.         }
  61.     }
  62.  
  63.     private void unregisterChecks() {
  64.         getProxy().getPluginManager().unregisterListeners(this);
  65.         System.out.println(getProxy().getScheduler().cancel(this));
  66.     }
  67.  
  68.     private void unregisterCommands() {
  69.         getProxy().getPluginManager().unregisterCommands(this);
  70.     }
  71.  
  72.     private void registerChecks() {
  73.         if (configuration.getBoolean(ConfigPaths.CHECKS_SAME_IP_ENABLED)) {
  74.             getProxy().getScheduler().schedule(this, new Runnable() {
  75.                 @Override
  76.                 public void run() {
  77.                     getProxy().getPluginManager().registerListener(AntiBot.p, new SameIPCheck());
  78.                     for (ProxiedPlayer proxiedPlayer : AntiBot.p.getProxy().getPlayers()) {
  79.                         if (proxiedPlayer.hasPermission("antibot.admin")) {
  80.                             proxiedPlayer.sendMessage(new ComponentBuilder("ยป ").color(ChatColor.DARK_RED).append("Same IP check enabled.").color(ChatColor.RED).create());
  81.                         }
  82.                     }
  83.                 }
  84.             }, configuration.getInt(ConfigPaths.CHECKS_SAME_IP_ENABLE_DELAY), TimeUnit.SECONDS);
  85.         }
  86.     }
  87.  
  88.     private void registerCommands() {
  89.         getProxy().getPluginManager().registerCommand(this, new CommandAntiBot());
  90.     }
  91.  
  92.     public Configuration getConfiguration() {
  93.         return configuration;
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement