Hey! I tried the following code to make it so that when people leave the server they have 2 minutes to rejoin. If they do not rejoin in that time they are suppose to be removed from the white-list. I also only want this to be able to happen after the game has started. But I cannot get it to work. Any ideas on how to fix it? Thanks! Code: @EventHandler(priority=EventPriority.HIGHEST) public void onQuit(PlayerQuitEvent event){ Player player = event.getPlayer(); Bukkit.broadcastMessage(ChatColor.YELLOW +player.getName()+ " left the server and will be removed from white-list in 2 minutes if not re-joined."); delay2(player); } public void delay2(final Player player){ getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ public void run(){ if(player.isOnline()){ }else{ player.setWhitelisted(false); Bukkit.broadcastMessage(ChatColor.RED +player.getName()+" is out of the game!"); } } }, 2400L);
Make a boolean called Countdown or something and make it true when the countdown starts, and false when it ends. Then, check if the Countdown is true and then remove the player from the whitelist. Technically this: Code:java //Top of classpublic boolean countdown = false; @EventHandlerpublic void onQuit(PlayerQuitEvent event){Player player = event.getPlayer();Bukkit.broadcastMessage(ChatColor.YELLOW +player.getName()+ " left the server and will be removed from white-list in 2 minutes if not re-joined.");if(Countdown = true){player.setWhitelisted(false);Bukkit.broadcastMessage(ChatColor.RED +player.getName()+" is out of the game!");}else return; } public void delay2(final Player player){getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){public void run(){//Beginning of countdowncountdown = true;//End of countdowncountdown = false;}}, 2400L);} That would technically be the code, but I explained so you wouldn't get confused. Hope this helped! ~Gabe
FabeGabeMC This will not work when multiple players left. It's pretty simple, you just need to listen to PlayerJoinEvent. Code:java @EventHandlerpublic void onPlayerJoin(PlayerJoinEvent event) { if (System.currentTimeMillis - ((OfflinePlayer) event.getPlayer()).getLastPlayed() > 60 * 2 * 1000) { ((OfflinePlayer) event.getPlayer()).setWhitelisted(false); event.getPlayer().kickPlayer("HAHAHA You haven't logged in for a soooo long time!!"); }} EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Not really.. you have not tested it yet, right. Code:java //Top of classpublic boolean countdown = false; @EventHandlerpublic void onQuit(PlayerQuitEvent event){Player player = event.getPlayer();Bukkit.broadcastMessage(ChatColor.YELLOW +player.getName()+ " left the server and will be removed from white-list in 2 minutes if not re-joined.");if(Countdown = true){player.setWhitelisted(false);Bukkit.broadcastMessage(ChatColor.RED +player.getName()+" is out of the game!");}else return; } public void delay2(final Player player){getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){public void run(){//Beginning of countdowncountdown = true;//End of countdowncountdown = false;}}, 2400L);} 1. Code:java if(Countdown = true) won't work.. first the 'C' is uppercase, second '=' operator is not same as '==', it's an assignment operator. 2. What is the logic here in onQuit() and delay2() method? After broadcasting message, why you check if variable Countdown equals true? Also in the BukkitRunnable, you assign true to countdown, and you immediately assign false to countdown. What's the meaning? If your code really worked, you must made some changes to it like below. Code:java //Top of classpublic ArrayList<UUID> expired = new ArrayList<UUID>(); @EventHandlerpublic void onJoin(PlayerJoinEvent event){if (expired.contains(event.getPlayer())) {event.getPlayer().kickPlayer("You have already expired.");}} @EventHandlerpublic void onQuit(PlayerQuitEvent event){Player player = event.getPlayer();Bukkit.broadcastMessage(ChatColor.YELLOW +player.getName()+ " left the server and will be removed from white-list in 2 minutes if not re-joined.");final UUID uuid = event.getPlayer().getUniqueId();new BukkitRunnable() {public void run() {for (Player player : Bukkit.getOnlinePlayers()) {if (player.getUniqueId() == uuid) { // Player is online againreturn;}}// If notexpired.add(uuid);((OfflinePlayer) event.getPlayer()).setWhitelisted(false);Bukkit.broadcastMessage(ChatColor.RED +player.getName()+" is out of the game!");}}.runTaskLater(2400L);} And obviously, it's much complex.
FabeGabeMC I tested out the code you posted, it gave me a bunch of errors. Not that I needed to, just by looking at it, I could already tell.
Stop replying like "yea it works for me, it works for me". When others point out you are wrong, and what they are saying are actually true and proved, please admit your mistake. Your code even has compiling error. How is it possible then, to work for you, "lol"?