Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java

120 lines
2.8 KiB
Java
Raw Normal View History

package nautilus.game.arcade.managers;
import java.util.HashSet;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class GameHostManager implements Listener
{
ArcadeManager Manager;
private Player _host;
private long _serverStartTime = System.currentTimeMillis();
private long _serverExpireTime = 43200000;
private long _lastOnline = System.currentTimeMillis();
private long _expireTime = 300000;
private HashSet<String> _whitelist = new HashSet<String>();
private HashSet<String> _blacklist = new HashSet<String>();
public GameHostManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
@EventHandler
public void updateHost(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
//No Host - Not MPS
if (Manager.GetHost() == null || Manager.GetHost().length() == 0)
return;
//Host Update
if (_host != null)
{
giveHostItem();
_lastOnline = System.currentTimeMillis();
}
}
@EventHandler
public void hostJoin(PlayerJoinEvent event)
{
if (Manager.GetHost() == null || Manager.GetHost().length() == 0)
return;
if (Manager.GetHost().equals(event.getPlayer().getName()))
{
System.out.println("Game Host Joined.");
_host = event.getPlayer();
}
}
@EventHandler
public void hostQuit(PlayerQuitEvent event)
{
if (Manager.GetHost() == null || Manager.GetHost().length() == 0)
return;
if (Manager.GetHost().equals(event.getPlayer().getName()))
{
System.out.println("Game Host Quit.");
_host = null;
}
}
public boolean isHostExpired()
{
if (Manager.GetHost() == null || Manager.GetHost().length() == 0)
return false;
return UtilTime.elapsed(_lastOnline, _expireTime) || UtilTime.elapsed(_serverStartTime, _serverExpireTime);
}
private void giveHostItem()
{
}
@EventHandler
public void whitelistCommand(PlayerCommandPreprocessEvent event)
{
if (_host == null || !event.getPlayer().equals(_host))
return;
if (!event.getMessage().toLowerCase().startsWith("/whitelist "))
return;
String[] args = event.getMessage().split(" ");
for (int i=1 ; i<args.length ; i++)
{
String name = args[i].toLowerCase();
if (_whitelist.add(name))
{
UtilPlayer.message(event.getPlayer(), F.main("Host", "Added " + F.elem(name) + " to the whitelist."));
}
}
}
}