Advertisement
Guest User

Help

a guest
Jun 15th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. package me.Talentoman.click;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.Iterator;
  9. import java.util.LinkedList;
  10. import java.util.UUID;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.Server;
  16. import org.bukkit.command.ConsoleCommandSender;
  17. import org.bukkit.command.PluginCommand;
  18. import org.bukkit.configuration.file.FileConfiguration;
  19. import org.bukkit.configuration.file.YamlConfiguration;
  20. import org.bukkit.entity.Player;
  21. import org.bukkit.plugin.PluginManager;
  22. import org.bukkit.plugin.java.JavaPlugin;
  23. import org.bukkit.scheduler.BukkitScheduler;
  24.  
  25. public class Main extends JavaPlugin
  26. {
  27. public FileConfiguration config;
  28. public File playerdata;
  29. public FileConfiguration playercfg;
  30. private LogManager logManager = new LogManager(new File(getDataFolder(), "CLog/history-logger.log"));
  31.  
  32. public HashMap<UUID, Double> clickRate = new HashMap();
  33. public HashMap<UUID, Integer> clickCount = new HashMap();
  34.  
  35. private static Date dt = new Date();
  36. private static SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
  37. private static String time = df.format(dt);
  38.  
  39. ConsoleCommandSender console = Bukkit.getConsoleSender();
  40.  
  41. public void savePlayerData()
  42. {
  43. try
  44. {
  45. this.playercfg.save(this.playerdata);
  46. } catch (IOException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50.  
  51. public static void log(Level level, String msg)
  52. {
  53. Bukkit.getLogger().log(level, time + msg);
  54. }
  55.  
  56. public LogManager getLogManager()
  57. {
  58. return this.logManager;
  59. }
  60.  
  61. public void onEnable()
  62. {
  63. this.playerdata = new File(getDataFolder(), "playerdata.yml");
  64. this.playercfg = YamlConfiguration.loadConfiguration(this.playerdata);
  65.  
  66. this.config = getConfig();
  67.  
  68. Commands clicker = new Commands(this);
  69. getCommand("aac-reload").setExecutor(clicker);
  70.  
  71. Bukkit.getServer().getPluginManager().registerEvents(new Events(this), this);
  72.  
  73. getRate();
  74. saveDefaultConfig();
  75. savePlayerData();
  76. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Talentoman]" + ChatColor.GREEN + " Online");
  77. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Talentoman]" + ChatColor.GREEN + " Autoclicker detection activated!");
  78. }
  79.  
  80. public void getRate()
  81. {
  82. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  83. LinkedList<Double> ll = new LinkedList();
  84. double sum = 0.0D;
  85. double total = 0.0D;
  86.  
  87. public void run() {
  88. for (Player p : Bukkit.getOnlinePlayers())
  89. {
  90. if (Main.this.clickCount.containsKey(p.getUniqueId())) {
  91. double count = ((Integer)Main.this.clickCount.get(p.getUniqueId())).intValue();
  92. if (count > Main.this.playercfg.getDouble("Clicks.Maximum." + p.getUniqueId())) {
  93. Main.this.playercfg.set("Clicks.Maximum." + p.getUniqueId(), Double.valueOf(count));
  94. Main.this.savePlayerData();
  95. }
  96. if (count > Main.this.config.getInt("ClickPerSecound-Limit")) {
  97. for (Player on : Bukkit.getOnlinePlayers()) {
  98. if (Permissions.NOTIFICATION.hasPerms(on)) {
  99. on.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.this.config.getString("NotificationAtLimit").replace("%PLAYER%", p.getName()).replace("%CLICKS%", String.valueOf(count))));
  100. Main.this.getLogManager().log(String.format("[" + Main.time + "]" + " <" + p.getUniqueId() + "> " + "<" + p.getName() + "> " + " Has reached " + count + " clicks", new Object[0]));
  101. Main.this.getServer().dispatchCommand(Main.this.getServer().getConsoleSender(), ChatColor.translateAlternateColorCodes('&', Main.this.config.getString("Command").replace("%PLAYER%", p.getName()).replace("%CLICKS%", String.valueOf(count))));
  102. }
  103. if (Permissions.REPORT.hasPerms(on)) {
  104. p.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.this.config.getString("StaffAlertMessage").replace("%PLAYER%", p.getName()).replace("%CLICKS%", String.valueOf(count))));
  105.  
  106. }
  107. }
  108.  
  109. }
  110.  
  111. if (count > 0.0D) {
  112. this.ll.add(Double.valueOf(count));
  113. for (Iterator localIterator = this.ll.iterator(); localIterator.hasNext(); ) { double x = ((Double)localIterator.next()).doubleValue();
  114. x = count;
  115. this.total = (this.sum + x);
  116. }
  117. }
  118. this.total = 0.0D;
  119. try {
  120. this.ll.remove(); } catch (Exception localException) {
  121. }
  122. Main.this.clickCount.put(p.getUniqueId(), Integer.valueOf(0));
  123. }
  124. }
  125. }
  126. }
  127. , 0L, 20L);
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement