daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ru.ensemplix.enAfk;
  2.  
  3. import java.util.HashMap;
  4. import java.util.logging.Logger;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Server;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.plugin.PluginDescriptionFile;
  10. import org.bukkit.plugin.PluginManager;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12. import org.bukkit.scheduler.BukkitScheduler;
  13.  
  14. public class enAfk extends JavaPlugin
  15. {
  16.   public static Logger log = Logger.getLogger("Minecraft");
  17.   public static PluginDescriptionFile pdfFile;
  18.   public static HashMap<String, Long> playerLastActivity = new HashMap();
  19.   public static HashMap<String, Location> playerLastPosition = new HashMap();
  20.  
  21.   public void onEnable()
  22.   {
  23.     pdfFile = getDescription();
  24.     PluginDescriptionFile pdfFile = getDescription();
  25.  
  26.     PluginManager pm = getServer().getPluginManager();
  27.  
  28.     pm.registerEvents(new enPlayerListener(), this);
  29.  
  30.     log.info("[" + pdfFile.getName() + "]" + " v " + pdfFile.getVersion() + " is enabled!");
  31.  
  32.     getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
  33.     {
  34.       public void run()
  35.       {
  36.         for (Player player : enAfk.this.getServer().getOnlinePlayers())
  37.         {
  38.           if (enAfk.playerLastActivity.get(player.getName()) == null) {
  39.             enAfk.playerLastActivity.put(player.getName(), Long.valueOf(System.currentTimeMillis() / 1000L));
  40.           }
  41.  
  42.           Location loc = (Location)enAfk.playerLastPosition.get(player.getName());
  43.           Location newloc = player.getLocation();
  44.           if (loc == null) {
  45.             enAfk.playerLastPosition.put(player.getName(), newloc);
  46.           }
  47.           else if ((loc.getWorld() != newloc.getWorld()) || (loc.distance(newloc) > 5.0D)) {
  48.             enAfk.playerLastPosition.put(player.getName(), newloc);
  49.             enAfk.playerLastActivity.put(player.getName(), Long.valueOf(System.currentTimeMillis() / 1000L));
  50.           }
  51.  
  52.           if (System.currentTimeMillis() / 1000L > ((Long)enAfk.playerLastActivity.get(player.getName())).longValue() + 600L)
  53.             player.kickPlayer(ChatColor.YELLOW + "Вы были в АФК слишком долго");
  54.         }
  55.       }
  56.     }
  57.     , 60L, 2000L);
  58.   }
  59.  
  60.   public void onDisable()
  61.   {
  62.     getServer().getScheduler().cancelTasks(this);
  63.     playerLastActivity.clear();
  64.     playerLastPosition.clear();
  65.     log.info("[" + pdfFile.getName() + "]" + " v " + pdfFile.getVersion() + " is disabled!");
  66.   }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top