2013-08-27 17:14:08 +02:00
package mineplex.hub.server ;
import java.io.BufferedReader ;
import java.io.File ;
import java.io.FileInputStream ;
import java.io.IOException ;
import java.io.InputStreamReader ;
2013-09-27 21:40:09 +02:00
import java.util.ArrayList ;
2013-09-11 22:53:24 +02:00
import java.util.Collection ;
2013-09-27 21:40:09 +02:00
import java.util.Collections ;
2013-09-11 22:53:24 +02:00
import java.util.HashSet ;
2013-09-18 00:50:23 +02:00
import java.util.List ;
2013-08-27 17:14:08 +02:00
import java.util.Set ;
import org.bukkit.ChatColor ;
2013-09-14 00:25:01 +02:00
import org.bukkit.Material ;
2014-05-28 20:18:30 +02:00
import org.bukkit.Sound ;
2014-06-15 04:35:09 +02:00
import org.bukkit.entity.LivingEntity ;
2013-08-27 17:14:08 +02:00
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
2013-09-14 00:25:01 +02:00
import org.bukkit.event.EventPriority ;
2013-09-27 21:40:09 +02:00
import org.bukkit.event.entity.EntityPortalEnterEvent ;
import org.bukkit.event.entity.EntityPortalEvent ;
2013-09-14 00:25:01 +02:00
import org.bukkit.event.player.PlayerInteractEvent ;
import org.bukkit.event.player.PlayerJoinEvent ;
2013-09-27 21:40:09 +02:00
import org.bukkit.event.player.PlayerPortalEvent ;
2014-07-31 22:36:00 +02:00
import org.bukkit.event.player.PlayerQuitEvent ;
2013-08-27 17:14:08 +02:00
import org.bukkit.plugin.java.JavaPlugin ;
2013-09-27 21:40:09 +02:00
import org.bukkit.util.Vector ;
2013-08-27 17:14:08 +02:00
import mineplex.core.MiniPlugin ;
import mineplex.core.account.CoreClientManager ;
import mineplex.core.common.Rank ;
import mineplex.core.common.util.C ;
2013-09-18 00:50:23 +02:00
import mineplex.core.common.util.Callback ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.F ;
import mineplex.core.common.util.NautHashMap ;
2013-09-27 21:40:09 +02:00
import mineplex.core.common.util.UtilAction ;
import mineplex.core.common.util.UtilAlg ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.UtilPlayer ;
import mineplex.core.common.util.UtilTime ;
import mineplex.core.common.util.UtilTime.TimeUnit ;
import mineplex.core.donation.DonationManager ;
2013-09-14 00:25:01 +02:00
import mineplex.core.itemstack.ItemStackFactory ;
2014-04-30 09:31:22 +02:00
import mineplex.core.logger.Logger ;
2013-08-27 17:14:08 +02:00
import mineplex.core.portal.Portal ;
2013-09-27 21:40:09 +02:00
import mineplex.core.recharge.Recharge ;
2014-05-27 11:10:29 +02:00
import mineplex.core.shop.ShopBase ;
2013-09-18 00:50:23 +02:00
import mineplex.core.status.ServerStatusManager ;
2013-08-27 17:14:08 +02:00
import mineplex.core.updater.UpdateType ;
import mineplex.core.updater.event.UpdateEvent ;
2013-09-27 21:40:09 +02:00
import mineplex.hub.HubManager ;
import mineplex.hub.modules.StackerManager ;
2013-09-09 10:28:35 +02:00
import mineplex.hub.party.Party ;
import mineplex.hub.party.PartyManager ;
2014-05-27 11:10:29 +02:00
import mineplex.hub.queue.QueueManager ;
import mineplex.hub.queue.ui.QueueShop ;
2013-10-03 07:23:01 +02:00
import mineplex.hub.server.ui.LobbyShop ;
2013-09-28 08:06:53 +02:00
import mineplex.hub.server.ui.QuickShop ;
2013-08-27 17:14:08 +02:00
import mineplex.hub.server.ui.ServerNpcShop ;
2014-08-01 23:56:29 +02:00
import mineplex.serverdata.MinecraftServer ;
2013-08-27 17:14:08 +02:00
2013-09-19 07:11:49 +02:00
public class ServerManager extends MiniPlugin
2013-08-27 17:14:08 +02:00
{
2014-08-01 09:09:35 +02:00
private static final Long FREE_PORTAL_TIMER = 60000L ;
2014-08-01 07:38:26 +02:00
2013-08-27 17:14:08 +02:00
private CoreClientManager _clientManager ;
private DonationManager _donationManager ;
private Portal _portal ;
2013-09-09 10:28:35 +02:00
private PartyManager _partyManager ;
2013-09-18 00:50:23 +02:00
private ServerStatusManager _statusManager ;
2013-09-27 21:40:09 +02:00
private HubManager _hubManager ;
private StackerManager _stackerManager ;
2014-05-27 11:10:29 +02:00
private QueueManager _queueManager ;
2013-08-27 17:14:08 +02:00
2013-10-03 07:23:01 +02:00
private NautHashMap < String , HashSet < ServerInfo > > _serverKeyInfoMap = new NautHashMap < String , HashSet < ServerInfo > > ( ) ;
private NautHashMap < String , String > _serverKeyTagMap = new NautHashMap < String , String > ( ) ;
2013-08-27 17:14:08 +02:00
private NautHashMap < String , ServerNpcShop > _serverNpcShopMap = new NautHashMap < String , ServerNpcShop > ( ) ;
private NautHashMap < String , ServerInfo > _serverInfoMap = new NautHashMap < String , ServerInfo > ( ) ;
private NautHashMap < String , Long > _serverUpdate = new NautHashMap < String , Long > ( ) ;
2013-09-27 21:40:09 +02:00
private NautHashMap < Vector , String > _serverPortalLocations = new NautHashMap < Vector , String > ( ) ;
2013-08-27 17:14:08 +02:00
2014-07-31 22:36:00 +02:00
// Join Time for Free Players Timer
private NautHashMap < String , Long > _freeJoinTime = new NautHashMap < String , Long > ( ) ;
2014-05-27 11:10:29 +02:00
private QueueShop _domShop ;
2013-09-28 08:06:53 +02:00
private QuickShop _quickShop ;
2013-10-03 07:23:01 +02:00
private LobbyShop _lobbyShop ;
2013-09-14 00:25:01 +02:00
2013-09-18 00:50:23 +02:00
private boolean _alternateUpdateFire = false ;
private boolean _retrieving = false ;
2013-10-26 23:36:48 +02:00
private long _lastRetrieve = 0 ;
2013-08-27 17:14:08 +02:00
2014-05-27 11:10:29 +02:00
public ServerManager ( JavaPlugin plugin , CoreClientManager clientManager , DonationManager donationManager , Portal portal , PartyManager partyManager , ServerStatusManager statusManager , HubManager hubManager , StackerManager stackerManager , QueueManager queueManager )
2013-08-27 17:14:08 +02:00
{
super ( " Server Manager " , plugin ) ;
_clientManager = clientManager ;
_donationManager = donationManager ;
_portal = portal ;
2013-09-09 10:28:35 +02:00
_partyManager = partyManager ;
2013-09-18 00:50:23 +02:00
_statusManager = statusManager ;
2013-09-27 21:40:09 +02:00
_hubManager = hubManager ;
_stackerManager = stackerManager ;
2014-05-27 11:10:29 +02:00
_queueManager = queueManager ;
2013-08-27 17:14:08 +02:00
plugin . getServer ( ) . getMessenger ( ) . registerOutgoingPluginChannel ( plugin , " BungeeCord " ) ;
LoadServers ( ) ;
2013-09-11 22:53:24 +02:00
2013-09-28 08:06:53 +02:00
_quickShop = new QuickShop ( this , clientManager , donationManager , " Quick Menu " ) ;
2013-10-03 07:23:01 +02:00
_lobbyShop = new LobbyShop ( this , clientManager , donationManager , " Lobby Menu " ) ;
2014-06-10 09:00:53 +02:00
//_domShop = new new QueueShop(_queueManager, clientManager, donationManager, "Dominate");
2013-08-27 17:14:08 +02:00
}
2013-09-14 00:25:01 +02:00
@EventHandler ( priority = EventPriority . LOW )
2013-09-27 21:40:09 +02:00
public void playerPortalEvent ( PlayerPortalEvent event )
2013-09-14 00:25:01 +02:00
{
2013-09-27 21:40:09 +02:00
event . setCancelled ( true ) ;
2013-09-14 00:25:01 +02:00
}
2013-09-27 21:40:09 +02:00
@EventHandler ( priority = EventPriority . LOW )
public void entityPortalEvent ( EntityPortalEvent event )
2013-09-14 00:25:01 +02:00
{
2013-09-27 21:40:09 +02:00
event . setCancelled ( true ) ;
2013-09-14 00:25:01 +02:00
}
2013-09-27 21:40:09 +02:00
@EventHandler ( priority = EventPriority . LOW )
public void playerCheckPortalEvent ( EntityPortalEnterEvent event )
2013-08-27 17:14:08 +02:00
{
2013-09-27 21:40:09 +02:00
if ( ! ( event . getEntity ( ) instanceof Player ) )
{
2014-06-15 04:35:09 +02:00
if ( event . getEntity ( ) instanceof LivingEntity )
UtilAction . velocity ( event . getEntity ( ) , UtilAlg . getTrajectory ( event . getEntity ( ) . getLocation ( ) , _hubManager . GetSpawn ( ) ) , 1 , true , 0 . 8 , 0 , 1 , true ) ;
2013-09-27 21:40:09 +02:00
return ;
}
2014-08-01 08:22:01 +02:00
final Player player = ( Player ) event . getEntity ( ) ;
2014-07-31 22:36:00 +02:00
2014-04-03 06:48:58 +02:00
if ( ! Recharge . Instance . use ( player , " Portal Server " , 1000 , false , false ) )
2013-09-27 21:40:09 +02:00
return ;
2014-08-01 08:22:01 +02:00
long timeUntilPortal = getMillisecondsUntilPortal ( player ) ;
if ( ! _hubManager . CanPortal ( player ) | | timeUntilPortal > 0 )
2013-08-27 17:14:08 +02:00
{
2014-08-01 08:22:01 +02:00
if ( timeUntilPortal > 0 )
{
player . playSound ( player . getEyeLocation ( ) , Sound . CHICKEN_EGG_POP , 2 , 2 ) ;
2014-08-01 08:43:50 +02:00
UtilPlayer . message ( player , F . main ( " Server Portal " , " You cannot join a server for " + C . cGreen + UtilTime . convertString ( timeUntilPortal , 0 , TimeUnit . SECONDS ) ) ) ;
2014-08-01 08:22:01 +02:00
}
UtilAction . velocity ( player , UtilAlg . getTrajectory ( player . getLocation ( ) , _hubManager . GetSpawn ( ) ) , 1 . 5 , true , 0 . 8 , 0 , 1 . 0 , true ) ;
// Need to set their velocity again a tick later
// Setting Y-Velocity while in a portal doesn't seem to do anything... Science!
_plugin . getServer ( ) . getScheduler ( ) . runTask ( _plugin , new Runnable ( )
{
@Override
public void run ( )
{
if ( player ! = null & & player . isOnline ( ) )
{
UtilAction . velocity ( player , UtilAlg . getTrajectory ( player . getLocation ( ) , _hubManager . GetSpawn ( ) ) , 1 , true , 0 . 5 , 0 , 1 . 0 , true ) ;
}
}
} ) ;
2013-09-27 21:40:09 +02:00
return ;
2013-08-27 17:14:08 +02:00
}
2013-09-27 21:40:09 +02:00
String serverName = _serverPortalLocations . get ( player . getLocation ( ) . getBlock ( ) . getLocation ( ) . toVector ( ) ) ;
if ( serverName ! = null )
{
List < ServerInfo > serverList = new ArrayList < ServerInfo > ( GetServerList ( serverName ) ) ;
int slots = 1 ;
if ( serverList . size ( ) > 0 )
{
slots = GetRequiredSlots ( player , serverList . get ( 0 ) . ServerType ) ;
}
try
{
Collections . sort ( serverList , new ServerSorter ( slots ) ) ;
2014-08-01 06:56:51 +02:00
boolean hasUltra = _clientManager . Get ( player ) . GetRank ( ) . Has ( Rank . ULTRA ) ;
2013-09-27 21:40:09 +02:00
for ( ServerInfo serverInfo : serverList )
{
if ( ( serverInfo . MOTD . contains ( " Starting " ) | | serverInfo . MOTD . contains ( " Recruiting " ) | | serverInfo . MOTD . contains ( " Waiting " ) | | serverInfo . MOTD . contains ( " Cup " ) ) & & ( serverInfo . MaxPlayers - serverInfo . CurrentPlayers ) > = slots )
{
2014-08-01 06:56:51 +02:00
// Make sure ultra players get put on premium servers, non premium gets placed on free servers
if ( hasUltra = = serverInfo . isFree ( ) )
continue ;
2013-09-27 21:40:09 +02:00
SelectServer ( player , serverInfo ) ;
return ;
}
}
}
catch ( Exception exception )
{
2014-04-30 09:31:22 +02:00
Logger . Instance . log ( exception ) ;
2013-09-27 21:40:09 +02:00
exception . printStackTrace ( ) ;
}
2014-08-01 08:43:50 +02:00
UtilPlayer . message ( player , F . main ( " Server Portal " , " There are currently no joinable servers! " ) ) ;
2013-09-27 21:40:09 +02:00
}
}
2014-05-27 11:10:29 +02:00
@EventHandler
public void checkQueuePrompts ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . SEC )
return ;
2014-06-10 09:00:53 +02:00
/ *
2014-05-28 20:18:30 +02:00
for ( final Player player : _queueManager . findPlayersNeedingPrompt ( ) )
2014-05-27 11:10:29 +02:00
{
2014-05-28 20:18:30 +02:00
player . playSound ( player . getLocation ( ) , Sound . ENDERDRAGON_GROWL , 5f , 1f ) ;
Bukkit . getScheduler ( ) . runTaskLater ( GetPlugin ( ) , new Runnable ( )
{
public void run ( )
{
if ( player . isOnline ( ) )
{
_domShop . attemptShopOpen ( player ) ;
}
}
} , 20 ) ;
2014-05-27 11:10:29 +02:00
}
2014-06-10 09:00:53 +02:00
* /
2014-05-27 11:10:29 +02:00
}
2013-09-27 21:40:09 +02:00
@EventHandler ( priority = EventPriority . LOW )
public void playerJoin ( PlayerJoinEvent event )
{
event . getPlayer ( ) . getInventory ( ) . addItem ( ItemStackFactory . Instance . CreateStack ( Material . COMPASS . getId ( ) , ( byte ) 0 , 1 , ChatColor . GREEN + " Game Menu " ) ) ;
2013-10-05 09:59:45 +02:00
event . getPlayer ( ) . getInventory ( ) . addItem ( ItemStackFactory . Instance . CreateStack ( Material . WATCH . getId ( ) , ( byte ) 0 , 1 , ChatColor . GREEN + " Lobby Menu " ) ) ;
2014-07-31 22:36:00 +02:00
if ( _clientManager . Get ( event . getPlayer ( ) ) . GetRank ( ) = = Rank . ALL )
{
_freeJoinTime . put ( event . getPlayer ( ) . getName ( ) , System . currentTimeMillis ( ) ) ;
}
}
@EventHandler
public void playerQuit ( PlayerQuitEvent event )
{
_freeJoinTime . remove ( event . getPlayer ( ) . getName ( ) ) ;
2013-09-27 21:40:09 +02:00
}
@EventHandler ( priority = EventPriority . LOWEST )
public void playerInteract ( PlayerInteractEvent event )
{
if ( event . getItem ( ) ! = null & & event . getItem ( ) . getType ( ) = = Material . COMPASS )
{
2013-09-28 08:06:53 +02:00
_quickShop . attemptShopOpen ( event . getPlayer ( ) ) ;
2013-09-27 21:40:09 +02:00
}
2013-10-03 07:23:01 +02:00
else if ( event . getItem ( ) ! = null & & event . getItem ( ) . getType ( ) = = Material . WATCH )
{
_lobbyShop . attemptShopOpen ( event . getPlayer ( ) ) ;
}
2013-08-27 17:14:08 +02:00
}
2014-07-31 22:36:00 +02:00
public Long getMillisecondsUntilPortal ( Player player )
{
2014-08-01 07:38:26 +02:00
// Party party = _partyManager.GetParty(player);
2014-07-31 22:36:00 +02:00
long timeLeft = 0 ;
if ( _freeJoinTime . containsKey ( player . getName ( ) ) )
{
2014-08-01 07:38:26 +02:00
timeLeft = ( _freeJoinTime . get ( player . getName ( ) ) - System . currentTimeMillis ( ) ) + FREE_PORTAL_TIMER ;
2014-07-31 22:36:00 +02:00
if ( timeLeft < = 0 )
{
_freeJoinTime . remove ( player . getName ( ) ) ;
timeLeft = 0 ;
}
}
2014-08-01 07:38:26 +02:00
// if (party != null)
// {
// if (player.getName().equals(party.GetLeader()))
// {
// for (Player partyPlayer : party.GetPlayersOnline())
// {
// if (!partyPlayer.equals(player))
// timeLeft = Math.max(timeLeft, getMillisecondsUntilPortal(partyPlayer));
// }
// }
// }
2014-07-31 22:36:00 +02:00
return timeLeft ;
}
2013-08-27 17:14:08 +02:00
public void RemoveServer ( String serverName )
{
2013-10-03 07:23:01 +02:00
for ( String key : _serverKeyInfoMap . keySet ( ) )
2013-08-27 17:14:08 +02:00
{
2013-10-03 07:23:01 +02:00
_serverKeyInfoMap . get ( key ) . remove ( serverName ) ;
2013-08-27 17:14:08 +02:00
}
_serverInfoMap . remove ( serverName ) ;
}
2013-10-03 07:23:01 +02:00
public void addServerGroup ( String serverKey , String serverTag )
2013-08-27 17:14:08 +02:00
{
2013-10-03 07:23:01 +02:00
_serverKeyInfoMap . put ( serverKey , new HashSet < ServerInfo > ( ) ) ;
_serverKeyTagMap . put ( serverTag , serverKey ) ;
}
public void AddServerNpc ( String serverNpcName , String serverTag )
{
addServerGroup ( serverNpcName , serverTag ) ;
2013-08-27 17:14:08 +02:00
_serverNpcShopMap . put ( serverNpcName , new ServerNpcShop ( this , _clientManager , _donationManager , serverNpcName ) ) ;
}
public void RemoveServerNpc ( String serverNpcName )
{
2013-10-03 07:23:01 +02:00
Set < ServerInfo > mappedServers = _serverKeyInfoMap . remove ( serverNpcName ) ;
2013-08-27 17:14:08 +02:00
_serverNpcShopMap . remove ( serverNpcName ) ;
if ( mappedServers ! = null )
{
for ( ServerInfo mappedServer : mappedServers )
{
boolean isMappedElseWhere = false ;
2013-10-03 07:23:01 +02:00
for ( String key : _serverKeyInfoMap . keySet ( ) )
2013-08-27 17:14:08 +02:00
{
2013-10-03 07:23:01 +02:00
for ( ServerInfo value : _serverKeyInfoMap . get ( key ) )
2013-08-27 17:14:08 +02:00
{
if ( value . Name . equalsIgnoreCase ( mappedServer . Name ) )
{
isMappedElseWhere = true ;
break ;
}
}
if ( isMappedElseWhere )
break ;
}
if ( ! isMappedElseWhere )
_serverInfoMap . remove ( mappedServer . Name ) ;
}
}
}
2013-09-11 22:53:24 +02:00
public Collection < ServerInfo > GetServerList ( String serverNpcName )
2013-08-27 17:14:08 +02:00
{
2013-10-03 07:23:01 +02:00
return _serverKeyInfoMap . get ( serverNpcName ) ;
2013-08-27 17:14:08 +02:00
}
public Set < String > GetAllServers ( )
{
return _serverInfoMap . keySet ( ) ;
}
public ServerInfo GetServerInfo ( String serverName )
{
return _serverInfoMap . get ( serverName ) ;
}
public boolean HasServerNpc ( String serverNpcName )
{
2013-10-03 07:23:01 +02:00
return _serverKeyInfoMap . containsKey ( serverNpcName ) ;
2013-08-27 17:14:08 +02:00
}
@EventHandler
2013-09-14 00:25:01 +02:00
public void updatePages ( UpdateEvent event )
2013-08-27 17:14:08 +02:00
{
2013-09-14 00:25:01 +02:00
if ( event . getType ( ) ! = UpdateType . FAST )
2013-08-27 17:14:08 +02:00
return ;
2013-09-19 07:11:49 +02:00
_quickShop . UpdatePages ( ) ;
2013-08-27 17:14:08 +02:00
2013-09-14 00:25:01 +02:00
for ( ServerNpcShop shop : _serverNpcShopMap . values ( ) )
2013-08-27 17:14:08 +02:00
{
2013-09-14 00:25:01 +02:00
shop . UpdatePages ( ) ;
2013-08-27 17:14:08 +02:00
}
2013-09-14 00:25:01 +02:00
}
@EventHandler
public void updateServers ( UpdateEvent event )
{
2013-10-26 23:36:48 +02:00
if ( event . getType ( ) ! = UpdateType . SEC | | ( _retrieving & & System . currentTimeMillis ( ) - _lastRetrieve < = 5000 ) )
2013-09-14 00:25:01 +02:00
return ;
2013-08-27 17:14:08 +02:00
2013-09-18 00:50:23 +02:00
_alternateUpdateFire = ! _alternateUpdateFire ;
if ( ! _alternateUpdateFire )
return ;
_retrieving = true ;
2013-10-26 23:36:48 +02:00
2014-08-01 23:56:29 +02:00
_statusManager . retrieveServerStatuses ( new Callback < Collection < MinecraftServer > > ( )
2013-08-27 17:14:08 +02:00
{
2014-08-01 23:56:29 +02:00
public void run ( Collection < MinecraftServer > serverStatusList )
2013-09-18 00:50:23 +02:00
{
2014-08-01 23:56:29 +02:00
for ( MinecraftServer serverStatus : serverStatusList )
2013-08-27 17:14:08 +02:00
{
2014-08-01 23:56:29 +02:00
if ( ! _serverInfoMap . containsKey ( serverStatus . getName ( ) ) )
2013-09-27 21:40:09 +02:00
{
ServerInfo newServerInfo = new ServerInfo ( ) ;
2014-08-01 23:56:29 +02:00
newServerInfo . Name = serverStatus . getName ( ) ;
_serverInfoMap . put ( serverStatus . getName ( ) , newServerInfo ) ;
2013-09-18 00:50:23 +02:00
}
2013-09-27 21:40:09 +02:00
2014-08-01 23:56:29 +02:00
String [ ] args = serverStatus . getMotd ( ) . split ( " \\ | " ) ;
String tag = ( serverStatus . getName ( ) ! = null & & serverStatus . getName ( ) . contains ( " - " ) ) ? serverStatus . getName ( ) . split ( " - " ) [ 0 ] : " N/A " ;
2013-09-27 21:40:09 +02:00
2014-08-01 23:56:29 +02:00
ServerInfo serverInfo = _serverInfoMap . get ( serverStatus . getName ( ) ) ;
serverInfo . MOTD = args . length > 0 ? args [ 0 ] : serverStatus . getMotd ( ) ;
serverInfo . CurrentPlayers = serverStatus . getPlayerCount ( ) ;
serverInfo . MaxPlayers = serverStatus . getMaxPlayerCount ( ) ;
2013-09-27 21:40:09 +02:00
if ( args . length > 1 )
serverInfo . ServerType = args [ 1 ] ;
if ( args . length > 2 )
serverInfo . Game = args [ 2 ] ;
if ( args . length > 3 )
serverInfo . Map = args [ 3 ] ;
2014-08-01 23:56:29 +02:00
_serverUpdate . put ( serverStatus . getName ( ) , System . currentTimeMillis ( ) ) ;
2013-08-27 17:14:08 +02:00
2013-10-03 07:23:01 +02:00
if ( _serverKeyTagMap . containsKey ( tag ) )
2013-09-18 00:50:23 +02:00
{
2013-10-03 07:23:01 +02:00
_serverKeyInfoMap . get ( _serverKeyTagMap . get ( tag ) ) . add ( serverInfo ) ;
2013-09-27 21:40:09 +02:00
}
}
for ( String name : _serverUpdate . keySet ( ) )
{
if ( _serverUpdate . get ( name ) ! = - 1L & & System . currentTimeMillis ( ) - _serverUpdate . get ( name ) > 5000 )
{
ServerInfo serverInfo = _serverInfoMap . get ( name ) ;
serverInfo . MOTD = ChatColor . DARK_RED + " OFFLINE " ;
serverInfo . CurrentPlayers = 0 ;
serverInfo . MaxPlayers = 0 ;
_serverUpdate . put ( name , - 1L ) ;
2013-09-18 00:50:23 +02:00
}
2013-08-27 17:14:08 +02:00
}
2013-09-18 00:50:23 +02:00
// Reset
_retrieving = false ;
2013-10-26 23:36:48 +02:00
_lastRetrieve = System . currentTimeMillis ( ) ;
2013-08-27 17:14:08 +02:00
}
2013-09-18 00:50:23 +02:00
} ) ;
2013-08-27 17:14:08 +02:00
}
public void Help ( Player caller , String message )
{
UtilPlayer . message ( caller , F . main ( _moduleName , " Commands List: " ) ) ;
UtilPlayer . message ( caller , F . help ( " /servernpc create <name> " , " <name> is name of npc. " , Rank . OWNER ) ) ;
UtilPlayer . message ( caller , F . help ( " /servernpc delete <name> " , " <name> is name of npc. " , Rank . OWNER ) ) ;
UtilPlayer . message ( caller , F . help ( " /servernpc addserver <servernpc> | <name> " , " Adds server. " , Rank . OWNER ) ) ;
UtilPlayer . message ( caller , F . help ( " /servernpc removeserver <name> " , " Removes server. " , Rank . OWNER ) ) ;
UtilPlayer . message ( caller , F . help ( " /servernpc listnpcs " , " Lists all server npcs. " , Rank . OWNER ) ) ;
UtilPlayer . message ( caller , F . help ( " /servernpc listservers <servernpc> " , " Lists all servers. " , Rank . OWNER ) ) ;
UtilPlayer . message ( caller , F . help ( " /servernpc listoffline " , " Shows all servers offline. " , Rank . OWNER ) ) ;
if ( message ! = null )
UtilPlayer . message ( caller , F . main ( _moduleName , ChatColor . RED + message ) ) ;
}
public void Help ( Player caller )
{
Help ( caller , null ) ;
}
2013-09-09 10:28:35 +02:00
public PartyManager getPartyManager ( )
2013-08-27 17:14:08 +02:00
{
2013-09-09 10:28:35 +02:00
return _partyManager ;
}
public void SelectServer ( org . bukkit . entity . Player player , ServerInfo serverInfo )
{
Party party = _partyManager . GetParty ( player ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:28:35 +02:00
if ( party ! = null )
{
if ( player . getName ( ) . equals ( party . GetLeader ( ) ) )
{
for ( String name : party . GetPlayers ( ) )
{
Player partyPlayer = UtilPlayer . searchExact ( name ) ;
if ( partyPlayer = = null )
continue ;
2014-03-05 09:34:20 +01:00
if ( serverInfo . Name . contains ( " BETA " ) )
2014-03-03 21:47:57 +01:00
{
2014-03-05 09:34:20 +01:00
if ( ! _clientManager . Get ( partyPlayer ) . GetRank ( ) . Has ( Rank . ULTRA ) )
continue ;
2014-03-03 21:47:57 +01:00
}
2014-03-05 09:34:20 +01:00
if ( ! _clientManager . Get ( partyPlayer ) . GetRank ( ) . Has ( Rank . MODERATOR ) & & serverInfo . CurrentPlayers > = serverInfo . MaxPlayers * 1 . 5 )
continue ;
2013-09-09 10:28:35 +02:00
if ( _clientManager . Get ( partyPlayer ) . GetRank ( ) . Has ( Rank . ULTRA ) | | _donationManager . Get ( partyPlayer . getName ( ) ) . OwnsUnknownPackage ( serverInfo . ServerType + " ULTRA " ) )
continue ;
partyPlayer . leaveVehicle ( ) ;
partyPlayer . eject ( ) ;
_portal . SendPlayerToServer ( partyPlayer , serverInfo . Name ) ;
}
for ( String name : party . GetPlayers ( ) )
{
Player partyPlayer = UtilPlayer . searchExact ( name ) ;
if ( partyPlayer = = null )
continue ;
2014-03-05 09:34:20 +01:00
if ( serverInfo . Name . contains ( " BETA " ) )
2014-03-03 21:47:57 +01:00
{
2014-03-05 09:34:20 +01:00
if ( ! _clientManager . Get ( partyPlayer ) . GetRank ( ) . Has ( Rank . ULTRA ) )
continue ;
2014-03-03 21:47:57 +01:00
}
2014-03-05 09:34:20 +01:00
if ( ! _clientManager . Get ( partyPlayer ) . GetRank ( ) . Has ( Rank . MODERATOR ) & & serverInfo . CurrentPlayers > = serverInfo . MaxPlayers * 1 . 5 )
continue ;
2013-09-09 10:28:35 +02:00
if ( _clientManager . Get ( partyPlayer ) . GetRank ( ) . Has ( Rank . ULTRA ) | | _donationManager . Get ( partyPlayer . getName ( ) ) . OwnsUnknownPackage ( serverInfo . ServerType + " ULTRA " ) )
{
partyPlayer . leaveVehicle ( ) ;
partyPlayer . eject ( ) ;
_portal . SendPlayerToServer ( partyPlayer , serverInfo . Name ) ;
}
}
}
}
else
{
player . leaveVehicle ( ) ;
player . eject ( ) ;
_portal . SendPlayerToServer ( player , serverInfo . Name ) ;
}
2013-08-27 17:14:08 +02:00
}
public void ListServerNpcs ( Player caller )
{
UtilPlayer . message ( caller , F . main ( GetName ( ) , " Listing Server Npcs: " ) ) ;
2013-10-03 07:23:01 +02:00
for ( String serverNpc : _serverKeyInfoMap . keySet ( ) )
2013-08-27 17:14:08 +02:00
{
UtilPlayer . message ( caller , F . main ( GetName ( ) , C . cYellow + serverNpc ) ) ;
}
}
public void ListServers ( Player caller , String serverNpcName )
{
UtilPlayer . message ( caller , F . main ( GetName ( ) , " Listing Servers for ' " + serverNpcName + " ': " ) ) ;
2013-10-03 07:23:01 +02:00
for ( ServerInfo serverNpc : _serverKeyInfoMap . get ( serverNpcName ) )
2013-08-27 17:14:08 +02:00
{
UtilPlayer . message ( caller , F . main ( GetName ( ) , C . cYellow + serverNpc . Name + C . cWhite + " - " + serverNpc . MOTD + " " + serverNpc . CurrentPlayers + " / " + serverNpc . MaxPlayers ) ) ;
}
}
public void ListOfflineServers ( Player caller )
{
UtilPlayer . message ( caller , F . main ( GetName ( ) , " Listing Offline Servers: " ) ) ;
for ( ServerInfo serverNpc : _serverInfoMap . values ( ) )
{
if ( serverNpc . MOTD . equalsIgnoreCase ( ChatColor . DARK_RED + " OFFLINE " ) )
{
UtilPlayer . message ( caller , F . main ( GetName ( ) , C . cYellow + serverNpc . Name + C . cWhite + " - " + F . time ( UtilTime . convertString ( System . currentTimeMillis ( ) - _serverUpdate . get ( serverNpc . Name ) , 0 , TimeUnit . FIT ) ) ) ) ;
}
}
}
public void LoadServers ( )
{
2013-09-11 22:53:24 +02:00
_serverInfoMap . clear ( ) ;
_serverUpdate . clear ( ) ;
2013-10-03 07:23:01 +02:00
for ( String npcName : _serverKeyInfoMap . keySet ( ) )
2013-09-11 22:53:24 +02:00
{
2013-10-03 07:23:01 +02:00
_serverKeyInfoMap . get ( npcName ) . clear ( ) ;
2013-09-11 22:53:24 +02:00
}
2013-10-03 07:23:01 +02:00
_serverKeyTagMap . clear ( ) ;
2013-09-27 21:40:09 +02:00
2013-08-27 17:14:08 +02:00
FileInputStream fstream = null ;
BufferedReader br = null ;
2013-09-11 22:53:24 +02:00
HashSet < String > npcNames = new HashSet < String > ( ) ;
2013-08-27 17:14:08 +02:00
try
{
File npcFile = new File ( " ServerManager.dat " ) ;
if ( npcFile . exists ( ) )
{
fstream = new FileInputStream ( npcFile ) ;
br = new BufferedReader ( new InputStreamReader ( fstream ) ) ;
String line = br . readLine ( ) ;
while ( line ! = null )
{
String serverNpcName = line . substring ( 0 , line . indexOf ( '|' ) ) . trim ( ) ;
2013-09-27 21:40:09 +02:00
String serverTag = line . substring ( line . indexOf ( '|' ) + 1 , line . indexOf ( '|' , line . indexOf ( '|' ) + 1 ) ) . trim ( ) ;
String [ ] locations = line . substring ( line . indexOf ( '|' , line . indexOf ( '|' ) + 1 ) + 1 ) . trim ( ) . split ( " , " ) ;
for ( String location : locations )
{
_serverPortalLocations . put ( ParseVector ( location ) , serverNpcName ) ;
}
2013-08-27 17:14:08 +02:00
if ( ! HasServerNpc ( serverNpcName ) )
{
2013-10-03 07:23:01 +02:00
AddServerNpc ( serverNpcName , serverTag ) ;
2013-08-27 17:14:08 +02:00
}
2013-09-11 22:53:24 +02:00
npcNames . add ( serverNpcName ) ;
2013-08-27 17:14:08 +02:00
line = br . readLine ( ) ;
}
}
}
catch ( Exception e )
{
2014-04-30 09:31:22 +02:00
Logger . Instance . log ( e ) ;
2013-08-27 17:14:08 +02:00
System . out . println ( " ServerManager - Error parsing servers file : " + e . getMessage ( ) ) ;
}
finally
{
if ( br ! = null )
{
try
{
br . close ( ) ;
}
catch ( IOException e )
{
e . printStackTrace ( ) ;
}
}
if ( fstream ! = null )
{
try
{
fstream . close ( ) ;
}
catch ( IOException e )
{
e . printStackTrace ( ) ;
}
}
}
2013-09-11 22:53:24 +02:00
for ( String npcName : npcNames )
{
if ( ! _serverNpcShopMap . containsKey ( npcName ) )
_serverNpcShopMap . remove ( npcName ) ;
2013-10-03 07:23:01 +02:00
if ( ! _serverKeyInfoMap . containsKey ( npcName ) )
_serverKeyInfoMap . remove ( npcName ) ;
2013-09-11 22:53:24 +02:00
}
2013-08-27 17:14:08 +02:00
}
2013-09-09 10:28:35 +02:00
public int GetRequiredSlots ( Player player , String serverType )
{
int slots = 0 ;
Party party = _partyManager . GetParty ( player ) ;
if ( party ! = null )
{
if ( player . getName ( ) . equals ( party . GetLeader ( ) ) )
{
for ( String name : party . GetPlayers ( ) )
{
Player partyPlayer = UtilPlayer . searchExact ( name ) ;
if ( partyPlayer = = null )
continue ;
if ( _clientManager . Get ( partyPlayer ) . GetRank ( ) . Has ( Rank . ULTRA ) | | _donationManager . Get ( partyPlayer . getName ( ) ) . OwnsUnknownPackage ( serverType + " ULTRA " ) )
continue ;
slots + + ;
}
}
}
else
{
if ( ! _clientManager . Get ( player ) . GetRank ( ) . Has ( Rank . ULTRA ) & & ! _donationManager . Get ( player . getName ( ) ) . OwnsUnknownPackage ( serverType + " ULTRA " ) )
slots + + ;
}
return slots ;
}
2013-09-19 07:11:49 +02:00
public ServerNpcShop getMixedArcadeShop ( )
{
2013-09-27 21:40:09 +02:00
return _serverNpcShopMap . get ( " Mixed Arcade " ) ;
2013-09-19 07:11:49 +02:00
}
public ServerNpcShop getSuperSmashMobsShop ( )
{
return _serverNpcShopMap . get ( " Super Smash Mobs " ) ;
}
2014-05-27 11:10:29 +02:00
@SuppressWarnings ( " rawtypes " )
public ShopBase getDominateShop ( )
2013-09-19 07:11:49 +02:00
{
2014-06-10 09:00:53 +02:00
return _serverNpcShopMap . get ( " Dominate " ) ;
2013-09-19 07:11:49 +02:00
}
public ServerNpcShop getBridgesShop ( )
{
return _serverNpcShopMap . get ( " The Bridges " ) ;
}
2013-09-27 21:40:09 +02:00
2013-11-23 11:04:22 +01:00
public ServerNpcShop getSurvivalGamesShop ( )
{
2013-12-18 11:22:40 +01:00
return _serverNpcShopMap . get ( " Survival Games " ) ;
2013-11-23 11:04:22 +01:00
}
public ServerNpcShop getBlockHuntShop ( )
{
return _serverNpcShopMap . get ( " Block Hunt " ) ;
}
2013-09-27 21:40:09 +02:00
private Vector ParseVector ( String vectorString )
{
Vector vector = new Vector ( ) ;
String [ ] parts = vectorString . trim ( ) . split ( " " ) ;
vector . setX ( Double . parseDouble ( parts [ 0 ] ) ) ;
vector . setY ( Double . parseDouble ( parts [ 1 ] ) ) ;
vector . setZ ( Double . parseDouble ( parts [ 2 ] ) ) ;
return vector ;
2013-09-19 07:11:49 +02:00
}
2013-10-03 07:23:01 +02:00
public ServerStatusManager getStatusManager ( )
{
return _statusManager ;
}
2014-06-15 06:27:21 +02:00
public ShopBase < ServerManager > getCastleSiegeShop ( )
{
return _serverNpcShopMap . get ( " Castle Siege " ) ;
}
2013-08-27 17:14:08 +02:00
}