2013-09-02 10:45:12 +02:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2014-11-08 00:28:06 +01:00
|
|
|
import java.util.Map;
|
2013-09-02 10:45:12 +02:00
|
|
|
|
2013-09-03 02:47:15 +02:00
|
|
|
import mineplex.core.common.Rank;
|
2013-09-02 10:45:12 +02:00
|
|
|
import mineplex.core.common.util.C;
|
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.core.common.util.UtilTime;
|
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
|
|
import nautilus.game.arcade.ArcadeManager;
|
|
|
|
import nautilus.game.arcade.game.Game.GameState;
|
|
|
|
|
2014-11-08 00:28:06 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2013-09-02 10:45:12 +02:00
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
2014-11-05 04:46:49 +01:00
|
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
2013-09-02 10:45:12 +02:00
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
|
|
|
|
public class IdleManager implements Listener
|
|
|
|
{
|
2014-11-08 00:28:06 +01:00
|
|
|
private final ArcadeManager _arcadeManager;
|
|
|
|
private final Map<Player, Float> _yaw = new HashMap<>();
|
|
|
|
private final Map<Player, Long> _idle = new HashMap<>();
|
|
|
|
private final Map<Player, Integer> _beep = new HashMap<>();
|
2013-09-02 10:45:12 +02:00
|
|
|
|
|
|
|
public IdleManager(ArcadeManager manager)
|
|
|
|
{
|
2014-11-08 00:28:06 +01:00
|
|
|
_arcadeManager = manager;
|
2013-09-02 10:45:12 +02:00
|
|
|
|
2015-02-26 06:07:07 +01:00
|
|
|
Bukkit.getPluginManager().registerEvents(this, getArcadeManager().getPlugin());
|
2013-09-02 10:45:12 +02:00
|
|
|
}
|
2014-11-05 04:46:49 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void ChatIdle(final AsyncPlayerChatEvent event)
|
|
|
|
{
|
2014-11-08 01:08:13 +01:00
|
|
|
if (!getArcadeManager().IsPlayerKickIdle())
|
2014-11-08 00:33:46 +01:00
|
|
|
return;
|
|
|
|
|
2015-02-26 06:07:07 +01:00
|
|
|
Bukkit.getServer().getScheduler().runTaskLater(getArcadeManager().getPlugin(), new Runnable()
|
2014-11-05 04:46:49 +01:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
_idle.put(event.getPlayer(), System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
}, 1);
|
|
|
|
}
|
2013-09-02 10:45:12 +02:00
|
|
|
|
|
|
|
@EventHandler
|
2014-11-08 00:28:06 +01:00
|
|
|
public void kickIdlePlayers(UpdateEvent event)
|
2013-09-02 10:45:12 +02:00
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.FAST)
|
|
|
|
return;
|
2013-09-09 10:06:44 +02:00
|
|
|
|
2014-11-08 00:28:06 +01:00
|
|
|
if (!getArcadeManager().IsPlayerKickIdle())
|
2013-09-14 12:03:24 +02:00
|
|
|
return;
|
|
|
|
|
2014-11-08 00:28:06 +01:00
|
|
|
if (getArcadeManager().GetGame() == null)
|
2014-05-03 09:23:10 +02:00
|
|
|
return;
|
|
|
|
|
2013-09-02 10:45:12 +02:00
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
|
|
{
|
|
|
|
if (!_yaw.containsKey(player) || !_idle.containsKey(player))
|
|
|
|
{
|
|
|
|
_yaw.put(player, player.getLocation().getYaw());
|
|
|
|
_idle.put(player, System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_yaw.get(player) == player.getLocation().getYaw())
|
|
|
|
{
|
2015-06-05 04:21:20 +02:00
|
|
|
if (UtilTime.elapsed(_idle.get(player), getArcadeManager().GetGame().IsLive() ? 240000 : 120000))
|
2013-09-02 10:45:12 +02:00
|
|
|
{
|
2014-11-08 00:28:06 +01:00
|
|
|
if (getArcadeManager().GetGame().GetState() != GameState.Recruit && !getArcadeManager().GetGame().IsAlive(player))
|
2013-09-02 10:45:12 +02:00
|
|
|
continue;
|
2013-09-03 02:47:15 +02:00
|
|
|
|
2014-11-08 00:28:06 +01:00
|
|
|
if (getArcadeManager().GetClients().Get(player).GetRank().Has(Rank.MODERATOR))
|
2013-09-03 02:47:15 +02:00
|
|
|
continue;
|
2013-09-02 10:45:12 +02:00
|
|
|
|
|
|
|
//Start Beeps
|
|
|
|
if (!_beep.containsKey(player))
|
|
|
|
{
|
|
|
|
_beep.put(player, 20);
|
|
|
|
}
|
|
|
|
//Countdown
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int count = _beep.get(player);
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
|
2015-01-11 09:42:31 +01:00
|
|
|
getArcadeManager().GetPortal().sendPlayerToServer(player, "Lobby");
|
2013-09-02 10:45:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float scale = (float) (0.8 + (((double)count/20d)*1.2));
|
|
|
|
player.playSound(player.getLocation(), Sound.NOTE_PLING, scale, scale);
|
|
|
|
|
|
|
|
if (count%2 == 0)
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, C.cGold + C.Bold + "You will be AFK removed in " + (count/2) + " seconds...");
|
|
|
|
}
|
|
|
|
|
|
|
|
count--;
|
|
|
|
_beep.put(player, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
_yaw.put(player, player.getLocation().getYaw());
|
|
|
|
_idle.put(player, System.currentTimeMillis());
|
|
|
|
_beep.remove(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2014-11-08 00:28:06 +01:00
|
|
|
public void onPlayerQuit(PlayerQuitEvent event)
|
2013-09-02 10:45:12 +02:00
|
|
|
{
|
|
|
|
_yaw.remove(event.getPlayer());
|
|
|
|
_idle.remove(event.getPlayer());
|
|
|
|
_beep.remove(event.getPlayer());
|
|
|
|
}
|
2014-11-08 00:28:06 +01:00
|
|
|
|
|
|
|
public ArcadeManager getArcadeManager()
|
|
|
|
{
|
|
|
|
return _arcadeManager;
|
|
|
|
}
|
2013-09-02 10:45:12 +02:00
|
|
|
}
|