2014-11-07 01:52:58 +01:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
2014-12-17 03:37:14 +01:00
|
|
|
import java.util.ArrayList;
|
2015-03-16 04:10:58 +01:00
|
|
|
import java.util.HashMap;
|
2014-11-07 01:52:58 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
|
2014-12-17 03:37:14 +01:00
|
|
|
import mineplex.core.common.Rank;
|
2014-11-07 02:14:33 +01:00
|
|
|
import mineplex.core.common.util.C;
|
2014-11-07 01:52:58 +01:00
|
|
|
import mineplex.core.common.util.F;
|
2014-11-07 02:14:33 +01:00
|
|
|
import mineplex.core.common.util.UtilGear;
|
2014-11-07 01:52:58 +01:00
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2014-12-22 03:19:45 +01:00
|
|
|
import mineplex.core.common.util.UtilServer;
|
2015-07-24 21:24:21 +02:00
|
|
|
import mineplex.core.common.util.UtilTextBottom;
|
2014-11-07 01:52:58 +01:00
|
|
|
import mineplex.core.common.util.UtilTime;
|
2015-07-27 19:18:37 +02:00
|
|
|
import mineplex.core.game.GameCategory;
|
2014-11-07 02:14:33 +01:00
|
|
|
import mineplex.core.itemstack.ItemStackFactory;
|
2014-11-07 01:52:58 +01:00
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
|
|
import nautilus.game.arcade.ArcadeManager;
|
2014-11-07 02:14:33 +01:00
|
|
|
import nautilus.game.arcade.GameType;
|
|
|
|
import nautilus.game.arcade.game.Game.GameState;
|
2014-12-18 01:45:15 +01:00
|
|
|
import nautilus.game.arcade.gui.privateServer.PrivateServerShop;
|
2015-07-24 21:24:21 +02:00
|
|
|
import nautilus.game.arcade.gui.privateServer.page.GameVotingPage;
|
2014-11-07 01:52:58 +01:00
|
|
|
|
2014-11-07 02:14:33 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2014-12-23 06:20:20 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2015-03-12 02:14:49 +01:00
|
|
|
import org.bukkit.GameMode;
|
2014-11-07 02:14:33 +01:00
|
|
|
import org.bukkit.Material;
|
2014-12-22 03:19:45 +01:00
|
|
|
import org.bukkit.Sound;
|
2014-11-07 01:52:58 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
2014-11-07 02:14:33 +01:00
|
|
|
import org.bukkit.event.HandlerList;
|
2014-11-07 01:52:58 +01:00
|
|
|
import org.bukkit.event.Listener;
|
2015-01-26 01:20:02 +01:00
|
|
|
import org.bukkit.event.inventory.InventoryType;
|
2014-11-07 01:52:58 +01:00
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
2014-11-07 02:14:33 +01:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2014-11-07 01:52:58 +01:00
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
2015-07-23 19:24:41 +02:00
|
|
|
import org.bukkit.event.player.PlayerLoginEvent;
|
2014-11-07 01:52:58 +01:00
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
2015-03-16 04:10:58 +01:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2014-11-07 01:52:58 +01:00
|
|
|
|
|
|
|
public class GameHostManager implements Listener
|
|
|
|
{
|
2014-12-22 06:31:13 +01:00
|
|
|
private ArrayList<GameType> ultraGames = new ArrayList<GameType>();
|
|
|
|
private ArrayList<GameType> heroGames = new ArrayList<GameType>();
|
|
|
|
private ArrayList<GameType> legendGames = new ArrayList<GameType>();
|
2014-12-16 18:42:06 +01:00
|
|
|
|
2014-11-07 01:52:58 +01:00
|
|
|
ArcadeManager Manager;
|
|
|
|
|
|
|
|
private Player _host;
|
2014-12-22 00:51:19 +01:00
|
|
|
private Rank _hostRank;
|
2014-11-07 01:52:58 +01:00
|
|
|
private long _serverStartTime = System.currentTimeMillis();
|
2014-12-23 03:01:44 +01:00
|
|
|
private long _serverExpireTime = 21600000;
|
2014-11-07 01:52:58 +01:00
|
|
|
private long _lastOnline = System.currentTimeMillis();
|
|
|
|
private long _expireTime = 300000;
|
2014-12-23 00:37:02 +01:00
|
|
|
private boolean _hostExpired = false;
|
2014-12-16 18:42:06 +01:00
|
|
|
|
|
|
|
private HashSet<Player> _onlineAdmins = new HashSet<Player>();
|
|
|
|
private HashSet<String> _adminList = new HashSet<String>();
|
2014-11-07 01:52:58 +01:00
|
|
|
private HashSet<String> _whitelist = new HashSet<String>();
|
|
|
|
private HashSet<String> _blacklist = new HashSet<String>();
|
2014-12-16 18:42:06 +01:00
|
|
|
|
2014-12-18 01:45:15 +01:00
|
|
|
private PrivateServerShop _shop;
|
2014-11-07 01:52:58 +01:00
|
|
|
|
2015-03-12 02:14:49 +01:00
|
|
|
private boolean _isEventServer = false;
|
|
|
|
|
2015-03-16 04:10:58 +01:00
|
|
|
private HashMap<Player, Boolean> _permissionMap = new HashMap<Player, Boolean>();
|
2015-07-24 21:24:21 +02:00
|
|
|
|
|
|
|
private boolean _voteInProgress = false;
|
|
|
|
private HashMap<String, GameType> _votes = new HashMap<String, GameType>();
|
2015-07-25 13:48:39 +02:00
|
|
|
private int _voteNotificationStage = 1;
|
2015-03-16 04:10:58 +01:00
|
|
|
|
2014-11-07 01:52:58 +01:00
|
|
|
public GameHostManager(ArcadeManager manager)
|
|
|
|
{
|
|
|
|
Manager = manager;
|
2014-12-18 01:45:15 +01:00
|
|
|
_shop = new PrivateServerShop(manager, manager.GetClients(), manager.GetDonation());
|
2015-02-26 06:07:07 +01:00
|
|
|
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
|
2014-12-23 01:39:03 +01:00
|
|
|
|
|
|
|
//Ultra Games
|
|
|
|
ultraGames.add(GameType.Smash);
|
|
|
|
|
|
|
|
ultraGames.add(GameType.BaconBrawl);
|
|
|
|
ultraGames.add(GameType.DeathTag);
|
|
|
|
ultraGames.add(GameType.DragonEscape);
|
|
|
|
ultraGames.add(GameType.Dragons);
|
|
|
|
ultraGames.add(GameType.Micro);
|
|
|
|
ultraGames.add(GameType.Paintball);
|
|
|
|
ultraGames.add(GameType.Quiver);
|
|
|
|
ultraGames.add(GameType.Runner);
|
|
|
|
ultraGames.add(GameType.Sheep);
|
|
|
|
ultraGames.add(GameType.Snake);
|
|
|
|
ultraGames.add(GameType.SneakyAssassins);
|
|
|
|
ultraGames.add(GameType.TurfWars);
|
|
|
|
ultraGames.add(GameType.Spleef);
|
2015-07-19 21:51:34 +02:00
|
|
|
ultraGames.add(GameType.Lobbers);
|
2014-12-16 18:42:06 +01:00
|
|
|
|
2014-12-23 01:39:03 +01:00
|
|
|
//Hero Games
|
|
|
|
heroGames.add(GameType.ChampionsDominate);
|
|
|
|
heroGames.add(GameType.ChampionsTDM);
|
|
|
|
heroGames.add(GameType.HideSeek);
|
|
|
|
heroGames.add(GameType.Draw);
|
2014-12-22 03:19:45 +01:00
|
|
|
|
2014-12-23 01:39:03 +01:00
|
|
|
//Legend Games
|
|
|
|
legendGames.add(GameType.Bridge);
|
|
|
|
legendGames.add(GameType.SurvivalGames);
|
|
|
|
legendGames.add(GameType.CastleSiege);
|
2015-02-24 20:45:31 +01:00
|
|
|
legendGames.add(GameType.WitherAssault);
|
|
|
|
legendGames.add(GameType.Wizards);
|
2015-05-16 06:38:43 +02:00
|
|
|
legendGames.add(GameType.Build);
|
|
|
|
legendGames.add(GameType.UHC);
|
|
|
|
legendGames.add(GameType.MineStrike);
|
2015-06-26 09:31:35 +02:00
|
|
|
legendGames.add(GameType.Skywars);
|
2015-07-24 17:03:53 +02:00
|
|
|
// Team variants - Currently being remade.
|
|
|
|
/*
|
2015-05-16 06:38:43 +02:00
|
|
|
legendGames.add(GameType.DragonEscapeTeams);
|
|
|
|
legendGames.add(GameType.DragonsTeams);
|
|
|
|
legendGames.add(GameType.QuiverTeams);
|
|
|
|
legendGames.add(GameType.SmashTeams);
|
|
|
|
legendGames.add(GameType.SpleefTeams);
|
|
|
|
legendGames.add(GameType.SurvivalGamesTeams);
|
2015-07-24 17:03:53 +02:00
|
|
|
*/
|
2015-07-23 19:24:41 +02:00
|
|
|
//Rejected / Other
|
|
|
|
legendGames.add(GameType.Evolution);
|
|
|
|
legendGames.add(GameType.MilkCow);
|
|
|
|
legendGames.add(GameType.SearchAndDestroy);
|
|
|
|
legendGames.add(GameType.ZombieSurvival);
|
2015-07-29 15:22:49 +02:00
|
|
|
legendGames.add(GameType.SurvivalGamesTeams);
|
|
|
|
legendGames.add(GameType.SkywarsTeams);
|
|
|
|
legendGames.add(GameType.SmashTeams);
|
|
|
|
legendGames.add(GameType.SnowFight);
|
|
|
|
legendGames.add(GameType.Gravity);
|
|
|
|
legendGames.add(GameType.Barbarians);
|
|
|
|
legendGames.add(GameType.SmashDomination);
|
2015-05-16 06:38:43 +02:00
|
|
|
|
2014-12-22 06:31:13 +01:00
|
|
|
//Config Defaults
|
|
|
|
if (Manager.GetHost() != null && Manager.GetHost().length() > 0)
|
|
|
|
{
|
|
|
|
setDefaultConfig();
|
|
|
|
}
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
2014-12-16 18:42:06 +01:00
|
|
|
|
2015-07-27 19:18:37 +02:00
|
|
|
public ArrayList<GameType> hasWarning()
|
|
|
|
{
|
|
|
|
ArrayList<GameType> games = new ArrayList<>();
|
|
|
|
games.add(GameType.Evolution);
|
|
|
|
games.add(GameType.MilkCow);
|
|
|
|
games.add(GameType.SearchAndDestroy);
|
|
|
|
games.add(GameType.ZombieSurvival);
|
|
|
|
return games;
|
|
|
|
}
|
|
|
|
|
2014-11-07 01:52:58 +01:00
|
|
|
@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;
|
|
|
|
|
2015-03-12 02:14:49 +01:00
|
|
|
// Set as event server
|
|
|
|
if (Manager.GetGame() != null && Manager.GetGame().GetType() == GameType.Event)
|
|
|
|
{
|
|
|
|
setEventServer(true);
|
|
|
|
}
|
|
|
|
|
2014-12-16 18:42:06 +01:00
|
|
|
// Admins update
|
2014-12-22 03:19:45 +01:00
|
|
|
for (Player player : UtilServer.getPlayers())
|
2014-12-16 18:42:06 +01:00
|
|
|
{
|
2014-12-23 03:01:44 +01:00
|
|
|
if (player.equals(_host) || _adminList.contains(player.getName()) || Manager.GetClients().Get(player).GetRank().Has(Rank.ADMIN))
|
2014-12-22 03:19:45 +01:00
|
|
|
{
|
|
|
|
if (Manager.GetGame() == null || Manager.GetGame().GetState() == GameState.Recruit)
|
|
|
|
giveAdminItem(player);
|
|
|
|
}
|
2014-12-23 03:01:44 +01:00
|
|
|
|
2015-03-16 04:19:43 +01:00
|
|
|
if (player.equals(_host) || (isAdmin(player, false) && isEventServer()))
|
2014-12-23 03:01:44 +01:00
|
|
|
_lastOnline = System.currentTimeMillis();
|
2014-12-16 18:42:06 +01:00
|
|
|
}
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
|
|
|
|
2015-07-24 21:24:21 +02:00
|
|
|
@EventHandler
|
|
|
|
public void voteNotification(UpdateEvent e)
|
|
|
|
{
|
2015-07-29 15:48:12 +02:00
|
|
|
if (e.getType() != UpdateType.FAST)
|
2015-07-24 21:24:21 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!_voteInProgress)
|
|
|
|
return;
|
|
|
|
|
2015-07-25 13:48:39 +02:00
|
|
|
if (_voteNotificationStage == 1)
|
2015-07-24 21:24:21 +02:00
|
|
|
{
|
2015-07-29 15:48:12 +02:00
|
|
|
UtilTextBottom.display(C.cYellow + C.Bold + "Type " + C.cGold + C.Bold + "/vote" + C.cYellow + C.Bold + " to vote for next game", UtilServer.getPlayers());
|
2015-07-25 13:48:39 +02:00
|
|
|
_voteNotificationStage++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (_voteNotificationStage == 2)
|
|
|
|
{
|
2015-07-29 15:48:12 +02:00
|
|
|
UtilTextBottom.display(C.cGold + C.Bold + "Type " + C.cYellow + C.Bold + "/vote" + C.cGold + C.Bold + " to vote for next game", UtilServer.getPlayers());
|
2015-07-25 13:48:39 +02:00
|
|
|
_voteNotificationStage = 1;
|
|
|
|
return;
|
2015-07-24 21:24:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 19:24:41 +02:00
|
|
|
@EventHandler
|
|
|
|
public void whitelistJoin(PlayerLoginEvent event)
|
|
|
|
{
|
|
|
|
Player p = event.getPlayer();
|
|
|
|
if (Manager.GetServerConfig().PlayerServerWhitelist){
|
|
|
|
if (!getWhitelist().contains(p.getName())){
|
2015-07-29 15:22:49 +02:00
|
|
|
if (_host == p)
|
|
|
|
return;
|
2015-07-23 19:24:41 +02:00
|
|
|
Manager.GetPortal().sendToHub(p, "You aren't on the whitelist of this Mineplex Private Server.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 01:52:58 +01:00
|
|
|
@EventHandler
|
2014-12-16 18:42:06 +01:00
|
|
|
public void adminJoin(PlayerJoinEvent event)
|
2014-11-07 01:52:58 +01:00
|
|
|
{
|
2014-12-16 18:42:06 +01:00
|
|
|
if (!isPrivateServer())
|
2014-11-07 01:52:58 +01:00
|
|
|
return;
|
2014-12-16 18:42:06 +01:00
|
|
|
|
2014-11-07 01:52:58 +01:00
|
|
|
if (Manager.GetHost().equals(event.getPlayer().getName()))
|
|
|
|
{
|
|
|
|
_host = event.getPlayer();
|
2014-12-22 00:51:19 +01:00
|
|
|
_hostRank = Manager.GetClients().Get(_host).GetRank();
|
2014-12-16 18:42:06 +01:00
|
|
|
System.out.println("Game Host Joined.");
|
2015-03-16 04:10:58 +01:00
|
|
|
|
|
|
|
if (isEventServer())
|
|
|
|
worldeditPermissionSet(event.getPlayer(), true);
|
2014-12-16 18:42:06 +01:00
|
|
|
}
|
2014-12-22 06:31:13 +01:00
|
|
|
else if (isAdmin(event.getPlayer(), false))
|
2014-12-16 18:42:06 +01:00
|
|
|
{
|
|
|
|
System.out.println("Admin Joined.");
|
|
|
|
_onlineAdmins.add(event.getPlayer());
|
2015-03-16 04:10:58 +01:00
|
|
|
|
|
|
|
if (isEventServer())
|
|
|
|
worldeditPermissionSet(event.getPlayer(), true);
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2014-12-16 18:42:06 +01:00
|
|
|
public void adminQuit(PlayerQuitEvent event)
|
2014-11-07 01:52:58 +01:00
|
|
|
{
|
2014-12-16 18:42:06 +01:00
|
|
|
if (!isPrivateServer())
|
2014-11-07 01:52:58 +01:00
|
|
|
return;
|
|
|
|
|
2014-12-16 18:42:06 +01:00
|
|
|
if (isHost(event.getPlayer()))
|
2014-11-07 01:52:58 +01:00
|
|
|
{
|
|
|
|
System.out.println("Game Host Quit.");
|
|
|
|
_host = null;
|
2015-03-16 04:10:58 +01:00
|
|
|
|
|
|
|
if (isEventServer())
|
|
|
|
worldeditPermissionSet(event.getPlayer(), false);
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
2014-12-22 06:31:13 +01:00
|
|
|
else if (isAdmin(event.getPlayer(), false))
|
2014-12-16 18:42:06 +01:00
|
|
|
{
|
|
|
|
_onlineAdmins.remove(event.getPlayer());
|
2015-03-16 04:10:58 +01:00
|
|
|
|
|
|
|
if (isEventServer())
|
|
|
|
worldeditPermissionSet(event.getPlayer(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void worldeditPermissionSet(Player player, boolean hasPermission)
|
|
|
|
{
|
|
|
|
if (!_permissionMap.containsKey(player) || _permissionMap.get(player) != hasPermission)
|
|
|
|
{
|
|
|
|
for (Plugin plugin : Bukkit.getPluginManager().getPlugins())
|
|
|
|
{
|
|
|
|
player.addAttachment(plugin, "worldedit.*", hasPermission);
|
|
|
|
}
|
|
|
|
|
|
|
|
_permissionMap.put(player, hasPermission);
|
|
|
|
|
|
|
|
UtilPlayer.message(player, "World Edit Permissions: " + F.tf(hasPermission));
|
2014-12-16 18:42:06 +01:00
|
|
|
}
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-23 13:17:21 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void updateHostExpired(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (!isPrivateServer())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.getType() != UpdateType.FAST)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Manager.GetGame() != null && Manager.GetGame().GetState() != GameState.Recruit)
|
|
|
|
return;
|
|
|
|
|
2014-12-23 13:18:29 +01:00
|
|
|
if (_hostExpired)
|
|
|
|
return;
|
|
|
|
|
2014-12-23 13:17:21 +01:00
|
|
|
if (UtilTime.elapsed(_lastOnline, _expireTime))
|
|
|
|
setHostExpired(true, Manager.GetServerConfig().HostName + " has abandoned the server. Thanks for playing!");
|
|
|
|
|
|
|
|
else if (UtilTime.elapsed(_serverStartTime, _serverExpireTime))
|
|
|
|
setHostExpired(true, "This server has expired! Thank you for playing!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-07 01:52:58 +01:00
|
|
|
public boolean isHostExpired()
|
|
|
|
{
|
2014-12-23 13:17:21 +01:00
|
|
|
if (!isPrivateServer())
|
2014-11-07 01:52:58 +01:00
|
|
|
return false;
|
|
|
|
|
2014-12-23 13:17:21 +01:00
|
|
|
return _hostExpired;
|
2014-12-23 00:37:02 +01:00
|
|
|
}
|
|
|
|
|
2014-12-23 13:17:21 +01:00
|
|
|
public void setHostExpired(boolean expired, String string)
|
2014-12-23 00:37:02 +01:00
|
|
|
{
|
2014-12-23 13:17:21 +01:00
|
|
|
for (Player other : UtilServer.getPlayers())
|
|
|
|
{
|
|
|
|
UtilPlayer.message(other, C.cGold + C.Bold + string);
|
|
|
|
other.playSound(other.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
|
2015-01-11 09:42:31 +01:00
|
|
|
Manager.GetPortal().sendPlayerToServer(other, "Lobby");
|
2014-12-23 13:17:21 +01:00
|
|
|
}
|
|
|
|
|
2014-12-23 00:37:02 +01:00
|
|
|
_hostExpired = expired;
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-16 18:42:06 +01:00
|
|
|
private void giveAdminItem(Player player)
|
2014-11-07 01:52:58 +01:00
|
|
|
{
|
2014-11-07 02:14:33 +01:00
|
|
|
if (Manager.GetGame() == null)
|
|
|
|
return;
|
2014-12-16 18:42:06 +01:00
|
|
|
|
2015-03-06 09:43:17 +01:00
|
|
|
if (UtilGear.isMat(player.getInventory().getItem(8), Material.SPECKLED_MELON))
|
2015-01-26 01:20:02 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (player.getOpenInventory().getType() != InventoryType.CRAFTING &&
|
|
|
|
player.getOpenInventory().getType() != InventoryType.CREATIVE)
|
2014-11-07 02:14:33 +01:00
|
|
|
return;
|
|
|
|
|
2015-03-06 09:43:17 +01:00
|
|
|
player.getInventory().setItem(8, ItemStackFactory.Instance.CreateStack(Material.SPECKLED_MELON, (byte)0, 1, C.cGreen + C.Bold + "/menu"));
|
2014-11-07 02:14:33 +01:00
|
|
|
}
|
2014-12-23 00:37:02 +01:00
|
|
|
|
|
|
|
private void removeAdminItem(Player player)
|
|
|
|
{
|
2015-03-16 03:39:33 +01:00
|
|
|
if (player.getInventory().getItem(8) != null && player.getInventory().getItem(8).getType() == Material.SPECKLED_MELON)
|
2014-12-23 00:37:02 +01:00
|
|
|
{
|
2015-03-06 09:43:17 +01:00
|
|
|
player.getInventory().setItem(8, null);
|
2014-12-23 00:37:02 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-07 02:14:33 +01:00
|
|
|
|
|
|
|
public HashSet<String> getWhitelist()
|
|
|
|
{
|
|
|
|
return _whitelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HashSet<String> getBlacklist()
|
|
|
|
{
|
|
|
|
return _blacklist;
|
|
|
|
}
|
2014-12-16 18:42:06 +01:00
|
|
|
|
|
|
|
public HashSet<String> getAdminList()
|
|
|
|
{
|
|
|
|
return _adminList;
|
|
|
|
}
|
2015-07-24 21:24:21 +02:00
|
|
|
|
2015-07-27 19:18:37 +02:00
|
|
|
@EventHandler
|
|
|
|
public void broadcastCommand(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/bc"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!isPrivateServer())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!isAdmin(event.getPlayer(), true))
|
|
|
|
{
|
|
|
|
event.getPlayer().sendMessage(F.main("Broadcast", "Only MPS admins can use this command."));
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
|
|
|
if (event.getMessage().split(" ").length < 2)
|
|
|
|
{
|
|
|
|
event.getPlayer().sendMessage(F.main("Broadcast", "/bc <message>"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg = "";
|
|
|
|
for (int i = 1; i < event.getMessage().split(" ").length; i++)
|
|
|
|
{
|
|
|
|
msg += event.getMessage().split(" ")[i] + " ";
|
|
|
|
}
|
|
|
|
msg = msg.trim();
|
|
|
|
|
|
|
|
Bukkit.broadcastMessage("§6§l" + event.getPlayer().getName() + " §e" + msg);
|
|
|
|
}
|
|
|
|
|
2015-07-24 21:24:21 +02:00
|
|
|
@EventHandler
|
|
|
|
public void voteCommand(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/vote"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!isPrivateServer())
|
|
|
|
{
|
|
|
|
UtilPlayer.message(event.getPlayer(), F.main("Vote", "This command is only available on private servers."));
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-25 18:35:43 +02:00
|
|
|
if (!_voteInProgress)
|
|
|
|
{
|
|
|
|
UtilPlayer.message(event.getPlayer(), F.main("Vote", "There is no vote in progress."));
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-24 21:24:21 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
_shop.openPageForPlayer(event.getPlayer(), new GameVotingPage(Manager, _shop, event.getPlayer()));
|
|
|
|
return;
|
|
|
|
}
|
2014-11-07 02:14:33 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void menuCommand(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
2015-07-24 21:24:21 +02:00
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/menu"))
|
|
|
|
return;
|
|
|
|
|
2014-12-23 09:04:10 +01:00
|
|
|
if (!isPrivateServer())
|
|
|
|
return;
|
|
|
|
|
2014-12-22 06:31:13 +01:00
|
|
|
if (!isAdmin(event.getPlayer(), true))
|
2014-11-07 02:14:33 +01:00
|
|
|
return;
|
|
|
|
|
2015-07-20 20:27:10 +02:00
|
|
|
event.setCancelled(true);
|
2014-12-16 18:42:06 +01:00
|
|
|
openMenu(event.getPlayer());
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-07 02:14:33 +01:00
|
|
|
@EventHandler
|
|
|
|
public void menuInteract(PlayerInteractEvent event)
|
|
|
|
{
|
2014-12-23 09:04:10 +01:00
|
|
|
if (!isPrivateServer())
|
|
|
|
return;
|
|
|
|
|
2014-12-22 06:31:13 +01:00
|
|
|
if (!isAdmin(event.getPlayer(), true))
|
2014-11-07 02:14:33 +01:00
|
|
|
return;
|
|
|
|
|
2014-12-23 07:06:04 +01:00
|
|
|
if (!UtilGear.isMat(event.getPlayer().getItemInHand(), Material.SPECKLED_MELON))
|
2014-11-07 02:14:33 +01:00
|
|
|
return;
|
|
|
|
|
2014-12-16 18:42:06 +01:00
|
|
|
openMenu(event.getPlayer());
|
|
|
|
event.setCancelled(true);
|
2014-11-07 02:14:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-16 18:42:06 +01:00
|
|
|
private void openMenu(Player player)
|
2014-11-07 02:14:33 +01:00
|
|
|
{
|
2014-12-17 03:37:14 +01:00
|
|
|
_shop.attemptShopOpen(player);
|
2014-12-16 18:42:06 +01:00
|
|
|
}
|
|
|
|
|
2014-12-22 06:31:13 +01:00
|
|
|
public boolean isAdmin(Player player, boolean includeStaff)
|
2014-12-16 18:42:06 +01:00
|
|
|
{
|
2014-12-23 03:01:44 +01:00
|
|
|
return player.equals(_host) || _adminList.contains(player.getName()) || (includeStaff && Manager.GetClients().Get(player).GetRank().Has(Rank.ADMIN));
|
2014-12-16 18:42:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isHost(Player player)
|
|
|
|
{
|
2014-12-22 03:19:45 +01:00
|
|
|
return player.getName().equals(Manager.GetHost());
|
2014-12-16 18:42:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPrivateServer()
|
|
|
|
{
|
2014-12-23 12:46:05 +01:00
|
|
|
return Manager.GetHost() != null && Manager.GetHost().length() > 0;
|
2014-11-07 02:14:33 +01:00
|
|
|
}
|
|
|
|
|
2014-11-07 01:52:58 +01:00
|
|
|
@EventHandler
|
|
|
|
public void whitelistCommand(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (_host == null || !event.getPlayer().equals(_host))
|
|
|
|
return;
|
|
|
|
|
2015-07-27 23:18:41 +02:00
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/whitelist"))
|
2014-11-07 01:52:58 +01:00
|
|
|
return;
|
2015-07-27 19:18:37 +02:00
|
|
|
|
|
|
|
if (!isPrivateServer())
|
2014-11-07 01:52:58 +01:00
|
|
|
return;
|
2015-07-27 19:18:37 +02:00
|
|
|
|
|
|
|
event.setCancelled(true);
|
2014-11-07 01:52:58 +01:00
|
|
|
|
|
|
|
String[] args = event.getMessage().split(" ");
|
|
|
|
|
|
|
|
for (int i=1 ; i<args.length ; i++)
|
|
|
|
{
|
|
|
|
String name = args[i].toLowerCase();
|
|
|
|
|
|
|
|
if (_whitelist.add(name))
|
|
|
|
{
|
2015-07-27 19:18:37 +02:00
|
|
|
UtilPlayer.message(event.getPlayer(), F.main("Host", "Added " + F.elem(args[i]) + " to the whitelist."));
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-07 02:14:33 +01:00
|
|
|
|
|
|
|
public void setGame(GameType type)
|
|
|
|
{
|
|
|
|
if (_host == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Manager.GetGameCreationManager().SetNextGameType(type);
|
|
|
|
|
|
|
|
//End Current
|
|
|
|
if (Manager.GetGame().GetState() == GameState.Recruit)
|
|
|
|
{
|
|
|
|
Manager.GetGame().SetState(GameState.Dead);
|
|
|
|
|
|
|
|
Bukkit.broadcastMessage(C.cGreen + C.Bold + _host.getName() + " has changed game to " + type.GetName() + ".");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Bukkit.broadcastMessage(C.cGreen + C.Bold + _host.getName() + " set next game to " + type.GetName() + ".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startGame()
|
|
|
|
{
|
|
|
|
if (_host == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Manager.GetGameManager().StateCountdown(Manager.GetGame(), 10, true);
|
|
|
|
|
|
|
|
Manager.GetGame().Announce(C.cGreen + C.Bold + _host.getName() + " has started the game.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stopGame()
|
|
|
|
{
|
|
|
|
if (_host == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Manager.GetGame() == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HandlerList.unregisterAll(Manager.GetGame());
|
|
|
|
|
|
|
|
if (Manager.GetGame().GetState() == GameState.End || Manager.GetGame().GetState() == GameState.End)
|
|
|
|
{
|
|
|
|
_host.sendMessage("Game is already ending...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (Manager.GetGame().GetState() == GameState.Recruit)
|
|
|
|
{
|
|
|
|
Manager.GetGame().SetState(GameState.Dead);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Manager.GetGame().SetState(GameState.End);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Manager.GetGame().Announce(C.cGreen + C.Bold + _host.getName() + " has stopped the game.");
|
|
|
|
}
|
2014-12-16 20:43:01 +01:00
|
|
|
|
2014-12-22 00:51:19 +01:00
|
|
|
public boolean hasRank(Rank rank)
|
2014-12-17 03:37:14 +01:00
|
|
|
{
|
2014-12-22 00:51:19 +01:00
|
|
|
if (_hostRank == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _hostRank.Has(rank);
|
2014-12-17 03:37:14 +01:00
|
|
|
}
|
|
|
|
|
2014-12-22 06:31:13 +01:00
|
|
|
public ArrayList<GameType> getAvailableGames(Player player)
|
2014-12-17 03:37:14 +01:00
|
|
|
{
|
2014-12-22 06:31:13 +01:00
|
|
|
ArrayList<GameType> games = new ArrayList<GameType>();
|
2014-12-17 03:37:14 +01:00
|
|
|
|
2014-12-22 00:51:19 +01:00
|
|
|
if (hasRank(Rank.ULTRA))
|
2014-12-17 03:37:14 +01:00
|
|
|
games.addAll(ultraGames);
|
2014-12-22 00:51:19 +01:00
|
|
|
if (hasRank(Rank.HERO))
|
2014-12-17 03:37:14 +01:00
|
|
|
games.addAll(heroGames);
|
2014-12-22 00:51:19 +01:00
|
|
|
if (hasRank(Rank.LEGEND))
|
2014-12-17 03:37:14 +01:00
|
|
|
games.addAll(legendGames);
|
|
|
|
|
|
|
|
return games;
|
|
|
|
}
|
|
|
|
|
2015-07-27 19:18:37 +02:00
|
|
|
public HashMap<GameCategory, ArrayList<GameType>> getGames(Player p)
|
|
|
|
{
|
|
|
|
HashMap<GameCategory, ArrayList<GameType>> games = new HashMap<GameCategory, ArrayList<GameType>>();
|
|
|
|
for (GameCategory cat : GameCategory.values())
|
|
|
|
{
|
|
|
|
ArrayList<GameType> types = new ArrayList<>();
|
|
|
|
for (GameType type : getAvailableGames(p))
|
|
|
|
{
|
|
|
|
if (type.getGameCategory().equals(cat))
|
|
|
|
{
|
|
|
|
types.add(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
games.put(cat, types);
|
|
|
|
}
|
|
|
|
return games;
|
|
|
|
}
|
|
|
|
|
2014-12-16 20:43:01 +01:00
|
|
|
public void ban(Player player)
|
|
|
|
{
|
|
|
|
_blacklist.add(player.getName());
|
2014-12-22 03:19:45 +01:00
|
|
|
|
2015-03-07 01:53:18 +01:00
|
|
|
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Private Server.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void kickBlacklist(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.SEC)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
|
|
{
|
|
|
|
if (_blacklist.contains(player.getName()))
|
|
|
|
{
|
|
|
|
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Private Server.");
|
|
|
|
}
|
|
|
|
}
|
2014-12-16 20:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void giveAdmin(Player player)
|
|
|
|
{
|
|
|
|
_adminList.add(player.getName());
|
2014-12-17 03:37:14 +01:00
|
|
|
_onlineAdmins.add(player);
|
2014-12-22 00:51:19 +01:00
|
|
|
UtilPlayer.message(player, F.main("Server", "You were given admin privileges."));
|
2015-03-16 04:10:58 +01:00
|
|
|
|
|
|
|
if (isEventServer())
|
|
|
|
worldeditPermissionSet(player, true);
|
2014-12-16 20:43:01 +01:00
|
|
|
}
|
2014-12-23 00:37:02 +01:00
|
|
|
|
|
|
|
public void removeAdmin(String playerName)
|
|
|
|
{
|
|
|
|
_adminList.remove(playerName);
|
|
|
|
Player player = UtilPlayer.searchExact(playerName);
|
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
_onlineAdmins.remove(player);
|
|
|
|
removeAdminItem(player);
|
|
|
|
if (_shop.isPlayerInShop(player))
|
|
|
|
{
|
|
|
|
player.closeInventory();
|
|
|
|
}
|
|
|
|
UtilPlayer.message(player, F.main("Server", "Your admin privileges were removed."));
|
2015-03-12 02:14:49 +01:00
|
|
|
|
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
2015-03-16 04:10:58 +01:00
|
|
|
|
|
|
|
if (isEventServer())
|
|
|
|
worldeditPermissionSet(player, false);
|
2014-12-23 00:37:02 +01:00
|
|
|
}
|
|
|
|
}
|
2014-12-18 03:06:57 +01:00
|
|
|
|
|
|
|
public boolean isAdminOnline()
|
|
|
|
{
|
|
|
|
return _onlineAdmins.isEmpty();
|
|
|
|
}
|
2014-12-22 06:31:13 +01:00
|
|
|
|
|
|
|
public void setDefaultConfig()
|
|
|
|
{
|
|
|
|
Manager.GetServerConfig().HotbarInventory = false;
|
|
|
|
|
|
|
|
Manager.GetServerConfig().RewardAchievements = false;
|
|
|
|
Manager.GetServerConfig().RewardGems = false;
|
|
|
|
Manager.GetServerConfig().RewardItems = false;
|
|
|
|
Manager.GetServerConfig().RewardStats = false;
|
|
|
|
|
|
|
|
Manager.GetServerConfig().GameAutoStart = true;
|
|
|
|
Manager.GetServerConfig().GameTimeout = true;
|
|
|
|
Manager.GetServerConfig().PlayerKickIdle = true;
|
|
|
|
Manager.GetServerConfig().TeamForceBalance = true;
|
|
|
|
}
|
2014-12-23 06:20:20 +01:00
|
|
|
|
|
|
|
public int getMaxPlayerCap()
|
|
|
|
{
|
2015-05-12 02:55:26 +02:00
|
|
|
if (hasRank(Rank.SNR_MODERATOR) || _hostRank == Rank.YOUTUBE || _hostRank == Rank.TWITCH)
|
2015-02-24 20:47:10 +01:00
|
|
|
return 100;
|
|
|
|
else if (hasRank(Rank.LEGEND))
|
2014-12-23 06:20:20 +01:00
|
|
|
return 40;
|
|
|
|
else if (hasRank(Rank.HERO))
|
|
|
|
return 12;
|
|
|
|
else
|
|
|
|
return 4;
|
|
|
|
}
|
2014-12-22 06:31:13 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void setHostDebug(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (!event.getPlayer().isOp())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/sethost "))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Manager.GetServerConfig().HostName = event.getMessage().split(" ")[1];
|
|
|
|
|
|
|
|
event.getPlayer().sendMessage("Set host to: " + event.getMessage().split(" ")[1]);
|
|
|
|
|
|
|
|
_host = Bukkit.getPlayerExact(Manager.GetServerConfig().HostName);
|
|
|
|
if (_host != null)
|
|
|
|
_hostRank = Manager.GetClients().Get(_host).GetRank();
|
|
|
|
|
|
|
|
setDefaultConfig();
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-03-12 02:14:49 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void setEventGame(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (!isEventServer() || Manager.GetGame() == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!isAdmin(event.getPlayer(), false))
|
|
|
|
return;
|
|
|
|
|
2015-03-16 03:39:33 +01:00
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/e set ") && !event.getMessage().toLowerCase().equals("/e set"))
|
2015-03-12 02:14:49 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
String[] args = event.getMessage().split(" ");
|
2015-03-16 03:39:33 +01:00
|
|
|
|
|
|
|
//Parse Game
|
2015-03-12 02:14:49 +01:00
|
|
|
if (args.length >= 3)
|
|
|
|
{
|
2015-03-16 03:39:33 +01:00
|
|
|
ArrayList<GameType> matches = new ArrayList<GameType>();
|
|
|
|
for (GameType type : GameType.values())
|
|
|
|
{
|
|
|
|
if (type.toString().toLowerCase().equals(args[2]))
|
|
|
|
{
|
|
|
|
matches.clear();
|
|
|
|
matches.add(type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.toString().toLowerCase().contains(args[2]))
|
|
|
|
{
|
|
|
|
matches.add(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matches.size() == 0)
|
|
|
|
{
|
|
|
|
event.getPlayer().sendMessage("No results for: " + args[2]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matches.size() > 1)
|
|
|
|
{
|
|
|
|
event.getPlayer().sendMessage("Matched multiple games;");
|
|
|
|
for (GameType cur : matches)
|
|
|
|
event.getPlayer().sendMessage(cur.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameType type = matches.get(0);
|
|
|
|
Manager.GetGame().setGame(type, event.getPlayer(), true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Manager.GetGame().setGame(GameType.Event, event.getPlayer(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Map Pref
|
|
|
|
if (args.length >= 4)
|
|
|
|
{
|
|
|
|
Manager.GetGameCreationManager().MapPref = args[3];
|
2015-03-12 02:14:49 +01:00
|
|
|
UtilPlayer.message(event.getPlayer(), C.cAqua + C.Bold + "Map Preference: " + ChatColor.RESET + args[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2014-12-23 06:20:20 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void playerJoin(PlayerJoinEvent event)
|
|
|
|
{
|
2014-12-23 09:04:10 +01:00
|
|
|
if (!isPrivateServer())
|
|
|
|
return;
|
2015-02-24 20:38:12 +01:00
|
|
|
|
|
|
|
if (_blacklist.contains(event.getPlayer().getName()))
|
|
|
|
{
|
|
|
|
Manager.GetPortal().sendToHub(event.getPlayer(), "You were kicked from this Mineplex Private Server.");
|
|
|
|
return;
|
|
|
|
}
|
2014-12-23 09:04:10 +01:00
|
|
|
|
2015-02-26 06:07:07 +01:00
|
|
|
String serverName = Manager.getPlugin().getConfig().getString("serverstatus.name");
|
2014-12-23 06:20:20 +01:00
|
|
|
UtilPlayer.message(event.getPlayer(), ChatColor.BOLD + "Welcome to Mineplex Private Servers!");
|
|
|
|
UtilPlayer.message(event.getPlayer(), C.Bold + "Friends can connect with " + C.cGreen + C.Bold + "/server " + serverName);
|
|
|
|
}
|
2015-03-12 02:14:49 +01:00
|
|
|
|
|
|
|
public boolean isEventServer()
|
|
|
|
{
|
|
|
|
return _isEventServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEventServer(boolean var)
|
|
|
|
{
|
|
|
|
_isEventServer = var;
|
|
|
|
}
|
2015-07-24 21:24:21 +02:00
|
|
|
|
|
|
|
public HashMap<String, GameType> getVotes()
|
|
|
|
{
|
|
|
|
return _votes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVoteInProgress(boolean voteInProgress)
|
|
|
|
{
|
|
|
|
_voteInProgress = voteInProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isVoteInProgress()
|
|
|
|
{
|
|
|
|
return _voteInProgress;
|
|
|
|
}
|
2014-11-07 01:52:58 +01:00
|
|
|
}
|