daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest May 16th, 2018 92 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. package net.minemora.LobbyAFK;
  2.  
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Random;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.player.AsyncPlayerChatEvent;
  14. import org.bukkit.event.player.PlayerJoinEvent;
  15. import org.bukkit.event.player.PlayerMoveEvent;
  16. import org.bukkit.event.player.PlayerQuitEvent;
  17. import org.bukkit.plugin.java.JavaPlugin;
  18. import org.bukkit.scheduler.BukkitRunnable;
  19.  
  20. import com.google.common.io.ByteArrayDataOutput;
  21. import com.google.common.io.ByteStreams;
  22.  
  23.  
  24. public class LobbyAFK extends JavaPlugin implements Listener {
  25.    
  26.     FileConfiguration config = getConfig();
  27.    
  28.     String pluginMode;
  29.     int timetosend;
  30.     List<String> lobbies;
  31.     List<String> afklobbies;
  32.    
  33.     Map<String,Long> lastactiontime = new HashMap<>();
  34.    
  35.     @Override
  36.     public void onEnable() {
  37.        
  38.         this.saveDefaultConfig();
  39.        
  40.         pluginMode = config.getString("plugin_mode").toLowerCase();
  41.         timetosend = config.getInt("time_to_send");
  42.         lobbies = config.getStringList("lobbies");
  43.         afklobbies = config.getStringList("afk_lobbies");
  44.        
  45.         getServer().getPluginManager().registerEvents(this, this);
  46.        
  47.         this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
  48.        
  49.         if(pluginMode.equals("lobby")) {
  50.             new BukkitRunnable() {
  51.                
  52.                 @Override
  53.                 public void run() {
  54.                     long currenttime = System.currentTimeMillis();
  55.                     for(Player p : Bukkit.getOnlinePlayers()) {
  56.                         if(currenttime - lastactiontime.get(p.getName()) >= timetosend*1000) {
  57.                             sendPlayer(p);
  58.                         }
  59.                     }
  60.                 }
  61.             }.runTaskTimerAsynchronously(this, 0L, 100L);
  62.         }
  63.        
  64.         getLogger().info("Loaded fine! with plugin mode: " + pluginMode);
  65.        
  66.     }
  67.    
  68.     @EventHandler
  69.     public void onPlayerJoin(PlayerJoinEvent e) {
  70.         updateCounter(e.getPlayer());
  71.     }
  72.    
  73.     @EventHandler
  74.     public void onPlayerMove(PlayerMoveEvent e) {
  75.         updateCounter(e.getPlayer());
  76.     }
  77.    
  78.     @EventHandler
  79.     public void onAsyncPlayerChat(AsyncPlayerChatEvent e) {
  80.         updateCounter(e.getPlayer());
  81.     }
  82.    
  83.     @EventHandler
  84.     public void onPlayerQuit(PlayerQuitEvent e) {
  85.         lastactiontime.remove(e.getPlayer().getName());
  86.     }
  87.    
  88.     public void updateCounter(Player p) {
  89.        
  90.         if(pluginMode.equals("afk")) {
  91.             sendPlayer(p);
  92.             return;
  93.         }
  94.         else if (pluginMode.equals("lobby")){
  95.             lastactiontime.put(p.getName(), System.currentTimeMillis());
  96.         }
  97.     }
  98.    
  99.     public void sendPlayer(Player p) {
  100.         String server = null;
  101.         if(pluginMode.equals("afk")) {
  102.             Random rand = new Random();
  103.             server = lobbies.get(rand.nextInt(lobbies.size()));
  104.         }
  105.         else if(pluginMode.equals("lobby")) {
  106.             Random rand = new Random();
  107.             server = afklobbies.get(rand.nextInt(afklobbies.size()));
  108.         }
  109.         ByteArrayDataOutput out = ByteStreams.newDataOutput();
  110.         out.writeUTF("Connect");
  111.         out.writeUTF(server);
  112.         p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
  113.     }
  114.  
  115. }
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