2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.managers ;
2014-03-13 08:18:22 +01:00
import java.util.ArrayList ;
2013-08-27 17:14:08 +02:00
import java.util.Iterator ;
2015-08-12 08:36:21 +02:00
import mineplex.core.bonuses.event.CarlSpinnerEvent ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.C ;
import mineplex.core.common.util.F ;
2014-10-25 02:03:45 +02:00
import mineplex.core.common.util.UtilFirework ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.UtilInv ;
import mineplex.core.common.util.UtilPlayer ;
import mineplex.core.common.util.UtilServer ;
2014-10-25 04:56:23 +02:00
import mineplex.core.common.util.UtilTextBottom ;
2014-10-25 04:40:34 +02:00
import mineplex.core.common.util.UtilTextTop ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.UtilTime ;
2015-11-12 23:51:13 +01:00
import mineplex.core.disguise.disguises.DisguiseBase ;
import mineplex.core.disguise.disguises.DisguiseLiving ;
import mineplex.core.disguise.disguises.DisguiseWither ;
2014-12-16 06:18:09 +01:00
import mineplex.core.gadget.gadgets.MorphWither ;
import mineplex.core.gadget.types.Gadget ;
import mineplex.core.gadget.types.GadgetType ;
2014-08-22 20:30:41 +02:00
import mineplex.minecraft.game.core.condition.Condition.ConditionType ;
2014-08-11 19:26:56 +02:00
import mineplex.core.mount.Mount ;
2014-08-22 20:30:41 +02:00
import mineplex.core.mount.types.MountDragon ;
2013-08-27 17:14:08 +02:00
import mineplex.core.updater.UpdateType ;
2013-09-02 10:09:28 +02:00
import mineplex.core.updater.event.RestartServerEvent ;
2013-08-27 17:14:08 +02:00
import mineplex.core.updater.event.UpdateEvent ;
import nautilus.game.arcade.ArcadeManager ;
2014-04-05 07:52:23 +02:00
import nautilus.game.arcade.events.GamePrepareCountdownCommence ;
2013-08-27 17:14:08 +02:00
import nautilus.game.arcade.events.GameStateChangeEvent ;
2014-03-14 10:17:06 +01:00
import nautilus.game.arcade.events.PlayerPrepareTeleportEvent ;
2013-08-27 17:14:08 +02:00
import nautilus.game.arcade.events.PlayerStateChangeEvent ;
import nautilus.game.arcade.game.Game ;
import nautilus.game.arcade.game.GameTeam ;
import nautilus.game.arcade.game.Game.GameState ;
2014-11-08 00:30:32 +01:00
import nautilus.game.arcade.game.games.uhc.UHC ;
2013-08-27 17:14:08 +02:00
import org.bukkit.ChatColor ;
import org.bukkit.Color ;
2014-10-25 02:03:45 +02:00
import org.bukkit.Location ;
2013-08-27 17:14:08 +02:00
import org.bukkit.Sound ;
import org.bukkit.FireworkEffect.Type ;
2014-12-17 06:31:51 +01:00
import org.bukkit.entity.Creature ;
2013-08-27 17:14:08 +02:00
import org.bukkit.entity.Player ;
2014-12-17 06:31:51 +01:00
import org.bukkit.entity.Wither ;
2013-08-27 17:14:08 +02:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
import org.bukkit.event.Listener ;
public class GameManager implements Listener
{
ArcadeManager Manager ;
2013-10-26 10:01:26 +02:00
private int _colorId = 0 ;
2015-12-07 10:07:20 +01:00
private int _animationIndex = 0 ;
2013-08-27 17:14:08 +02:00
public GameManager ( ArcadeManager manager )
{
Manager = manager ;
2015-02-26 06:07:07 +01:00
Manager . getPluginManager ( ) . registerEvents ( this , Manager . getPlugin ( ) ) ;
2013-08-27 17:14:08 +02:00
}
2013-10-26 10:01:26 +02:00
@EventHandler
public void DisplayIP ( UpdateEvent event )
{
2015-12-07 10:07:20 +01:00
if ( event . getType ( ) ! = UpdateType . FASTEST )
2013-10-26 10:01:26 +02:00
return ;
2014-10-25 04:56:23 +02:00
if ( Manager . GetGame ( ) ! = null & & ! Manager . GetGame ( ) . InProgress ( ) )
2013-10-26 10:01:26 +02:00
{
ChatColor col = ChatColor . RED ;
if ( _colorId = = 1 ) col = ChatColor . YELLOW ;
else if ( _colorId = = 2 ) col = ChatColor . GREEN ;
else if ( _colorId = = 3 ) col = ChatColor . AQUA ;
_colorId = ( _colorId + 1 ) % 4 ;
String text = col + C . Bold + " US.MINEPLEX.COM EU.MINEPLEX.COM " ;
2015-12-07 10:07:20 +01:00
//Christmas
2015-12-07 10:20:49 +01:00
_animationIndex = ( _animationIndex + 1 ) % 40 ;
if ( _animationIndex = = 0 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 5 " + C . cWhiteB + " 0% OFF ALL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 1 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50 " + C . cWhiteB + " % OFF ALL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 2 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% " + C . cWhiteB + " OFF ALL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 3 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% O " + C . cWhiteB + " FF ALL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 4 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OF " + C . cWhiteB + " F ALL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 5 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF " + C . cWhiteB + " ALL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 6 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF A " + C . cWhiteB + " LL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 7 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF AL " + C . cWhiteB + " L RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 8 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL " + C . cWhiteB + " RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 9 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL R " + C . cWhiteB + " ANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 10 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RA " + C . cWhiteB + " NKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 11 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RAN " + C . cWhiteB + " KS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 12 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANK " + C . cWhiteB + " S " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 13 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 14 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 15 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cWhiteB + " 50% OFF ALL RANKS " + C . cGreenB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 16 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 17 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cWhiteB + " 50% OFF ALL RANKS " + C . cGreenB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 18 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 19 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cWhiteB + " 50% OFF ALL RANKS " + C . cGreenB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 20 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 21 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cWhiteB + " 50% OFF ALL RANKS " + C . cGreenB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 22 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 23 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cWhiteB + " 50% OFF ALL RANKS " + C . cGreenB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 24 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 25 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cWhiteB + " 50% OFF ALL RANKS " + C . cGreenB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex = = 26 ) text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " 50% OFF ALL RANKS " + C . cWhiteB + " " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
if ( _animationIndex > = 27 )
text = C . cWhite + " ❄ " + C . cRed + " Massive Winter Sale " + C . cGreenB + " " + C . cWhiteB + " 50% OFF ALL RANKS " + C . cYellow + " www.mineplex.com/shop " + C . cWhite + " ❄ " ;
2015-12-07 10:07:20 +01:00
2013-10-26 10:01:26 +02:00
double health = 1 ;
2014-10-25 04:56:23 +02:00
if ( Manager . GetGame ( ) . GetState ( ) = = GameState . Recruit )
2013-10-26 10:01:26 +02:00
{
2014-10-25 04:56:23 +02:00
if ( Manager . GetGame ( ) . GetCountdown ( ) > = 0 & & Manager . GetGame ( ) . GetCountdown ( ) < = 10 )
health = 1 - Manager . GetGame ( ) . GetCountdown ( ) / 10d ;
2013-10-26 10:01:26 +02:00
}
2014-10-25 04:56:23 +02:00
2014-10-25 04:40:34 +02:00
//Display IP
2014-10-25 04:56:23 +02:00
UtilTextTop . displayProgress ( text , health , UtilServer . getPlayers ( ) ) ;
2014-08-11 19:26:56 +02:00
2014-12-17 06:31:51 +01:00
for ( Creature pet : Manager . getCosmeticManager ( ) . getPetManager ( ) . getPets ( ) )
2015-11-12 23:51:13 +01:00
{
DisguiseBase disguise = Manager . GetDisguise ( ) . getDisguise ( pet ) ;
if ( disguise instanceof DisguiseWither )
{
( ( DisguiseWither ) disguise ) . setName ( text ) ;
( ( DisguiseLiving ) disguise ) . setHealth ( ( float ) Math . max ( 0 . 1 ,
300 * health ) ) ;
disguise . resendMetadata ( ) ;
}
}
2014-12-17 06:31:51 +01:00
2014-10-25 04:56:23 +02:00
//Name Dragons Appropriately
2014-08-11 19:26:56 +02:00
for ( Mount mount : Manager . getCosmeticManager ( ) . getMountManager ( ) . getMounts ( ) )
{
2014-08-22 20:30:41 +02:00
if ( mount instanceof MountDragon )
2014-08-11 19:26:56 +02:00
{
2014-08-22 20:30:41 +02:00
( ( MountDragon ) mount ) . SetName ( text ) ;
( ( MountDragon ) mount ) . setHealthPercent ( health ) ;
2014-08-11 19:26:56 +02:00
}
}
2014-12-16 06:18:09 +01:00
for ( Gadget gadget : Manager . getCosmeticManager ( ) . getGadgetManager ( ) . getGadgets ( GadgetType . Morph ) )
{
if ( gadget instanceof MorphWither )
{
( ( MorphWither ) gadget ) . setWitherData ( text , health ) ;
}
}
2013-10-26 10:01:26 +02:00
}
}
2014-10-25 04:56:23 +02:00
@EventHandler
public void DisplayPrepareTime ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . TICK )
return ;
if ( Manager . GetGame ( ) = = null | | Manager . GetGame ( ) . GetState ( ) ! = GameState . Prepare )
return ;
2015-03-17 11:52:58 +01:00
Game game = Manager . GetGame ( ) ;
double percentage = ( double ) ( System . currentTimeMillis ( ) - game . GetStateTime ( ) ) / game . PrepareTime ;
2014-10-25 04:56:23 +02:00
for ( Player player : UtilServer . getPlayers ( ) )
2015-03-17 11:52:58 +01:00
UtilTextBottom . displayProgress ( " Game Start " , percentage ,
UtilTime . MakeStr ( Math . max ( 0 , game . PrepareTime - ( System . currentTimeMillis ( ) - game . GetStateTime ( ) ) ) ) , player ) ;
2014-10-25 04:56:23 +02:00
}
2013-08-27 17:14:08 +02:00
@EventHandler
public void StateUpdate ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . SEC )
return ;
Game game = Manager . GetGame ( ) ;
if ( game = = null ) return ;
if ( game . GetState ( ) = = GameState . Loading )
{
if ( UtilTime . elapsed ( game . GetStateTime ( ) , 30000 ) )
{
System . out . println ( " Game Load Expired. " ) ;
game . SetState ( GameState . Dead ) ;
}
2014-09-01 13:37:39 +02:00
}
2013-08-27 17:14:08 +02:00
else if ( game . GetState ( ) = = GameState . Recruit )
{
//Stop Countdown!
if ( game . GetCountdown ( ) ! = - 1 & &
UtilServer . getPlayers ( ) . length < Manager . GetPlayerMin ( ) & &
2013-11-24 11:58:55 +01:00
! game . GetCountdownForce ( ) )
2013-08-27 17:14:08 +02:00
{
game . SetCountdown ( - 1 ) ;
Manager . GetLobby ( ) . DisplayWaiting ( ) ;
}
2014-10-03 02:49:26 +02:00
if ( Manager . IsGameAutoStart ( ) )
2013-09-09 10:06:44 +02:00
{
if ( UtilServer . getPlayers ( ) . length > = Manager . GetPlayerFull ( ) )
StateCountdown ( game , 20 , false ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
else if ( UtilServer . getPlayers ( ) . length > = Manager . GetPlayerMin ( ) )
StateCountdown ( game , 60 , false ) ;
2014-10-10 06:26:04 +02:00
else if ( game . GetCountdown ( ) ! = - 1 )
StateCountdown ( game , - 1 , false ) ;
2013-09-09 10:06:44 +02:00
}
2014-10-03 02:49:26 +02:00
else if ( game . GetCountdown ( ) ! = - 1 )
{
StateCountdown ( game , - 1 , false ) ;
}
2013-08-27 17:14:08 +02:00
}
else if ( game . GetState ( ) = = GameState . Prepare )
{
2014-03-13 08:18:22 +01:00
if ( game . CanStartPrepareCountdown ( ) )
2013-08-27 17:14:08 +02:00
{
2015-03-17 11:52:58 +01:00
if ( UtilTime . elapsed ( game . GetStateTime ( ) , game . PrepareTime ) )
2013-08-27 17:14:08 +02:00
{
2015-03-17 11:52:58 +01:00
int players = game . GetPlayers ( true ) . size ( ) ;
if ( players < 2 | | game . PlaySoundGameStart )
{
for ( Player player : UtilServer . getPlayers ( ) )
player . playSound ( player . getLocation ( ) , Sound . NOTE_PLING , 2f , 2f ) ;
}
2014-03-13 08:18:22 +01:00
2015-03-17 11:52:58 +01:00
if ( players < 2 )
2014-03-13 08:18:22 +01:00
{
game . Announce ( C . cWhite + C . Bold + game . GetName ( ) + " ended, not enough players! " ) ;
game . SetState ( GameState . Dead ) ;
}
else
{
game . SetState ( GameState . Live ) ;
}
2013-08-27 17:14:08 +02:00
}
else
{
2014-03-13 08:18:22 +01:00
for ( Player player : UtilServer . getPlayers ( ) )
player . playSound ( player . getLocation ( ) , Sound . NOTE_STICKS , 1f , 1f ) ;
2013-08-27 17:14:08 +02:00
}
}
}
2014-07-26 08:38:21 +02:00
else if ( game . GetState ( ) = = GameState . Live )
2013-08-27 17:14:08 +02:00
{
2015-03-06 09:43:17 +01:00
if ( game . GameTimeout ! = - 1 & & UtilTime . elapsed ( game . GetStateTime ( ) , game . GameTimeout ) & & Manager . IsGameTimeout ( ) )
2013-08-27 17:14:08 +02:00
{
2014-07-26 09:40:17 +02:00
game . HandleTimeout ( ) ;
2013-08-27 17:14:08 +02:00
}
}
else if ( game . GetState ( ) = = GameState . End )
{
if ( UtilTime . elapsed ( game . GetStateTime ( ) , 10000 ) )
{
game . SetState ( GameState . Dead ) ;
}
}
}
public void StateCountdown ( Game game , int timer , boolean force )
{
2015-05-11 20:25:05 +02:00
if ( game instanceof UHC & & ! ( ( UHC ) game ) . isMapLoaded ( ) )
return ;
2015-07-24 21:24:21 +02:00
if ( Manager . GetGameHostManager ( ) . isPrivateServer ( ) & & Manager . GetGameHostManager ( ) . isVoteInProgress ( ) )
return ;
2014-08-11 03:55:00 +02:00
//Disabling Cosmetics
2015-03-06 09:11:26 +01:00
if ( game . GetCountdown ( ) < = 5 & & game . GetCountdown ( ) > = 0 & & game . GadgetsDisabled )
2014-08-11 03:55:00 +02:00
{
if ( Manager . getCosmeticManager ( ) . isShowingInterface ( ) )
{
2014-08-11 07:33:45 +02:00
Manager . getCosmeticManager ( ) . setActive ( false ) ;
2014-08-11 03:55:00 +02:00
Manager . getCosmeticManager ( ) . disableItemsForGame ( ) ;
}
}
2013-08-27 17:14:08 +02:00
if ( force )
game . SetCountdownForce ( true ) ;
2015-05-12 21:46:21 +02:00
2013-08-27 17:14:08 +02:00
//Team Preference
TeamPreferenceJoin ( game ) ;
//Team Swap
TeamPreferenceSwap ( game ) ;
//Team Default
TeamDefaultJoin ( game ) ;
//Team Inform STILL Queued
if ( game . GetCountdown ( ) = = - 1 )
{
game . InformQueuePositions ( ) ;
2013-09-01 00:34:53 +02:00
//game.AnnounceGame();
2013-08-27 17:14:08 +02:00
}
//Initialise Countdown
if ( force )
game . SetCountdownForce ( true ) ;
//Start Timer
if ( game . GetCountdown ( ) = = - 1 )
game . SetCountdown ( timer + 1 ) ;
//Decrease Timer
if ( game . GetCountdown ( ) > timer + 1 & & timer ! = - 1 )
game . SetCountdown ( timer + 1 ) ;
//Countdown--
if ( game . GetCountdown ( ) > 0 )
game . SetCountdown ( game . GetCountdown ( ) - 1 ) ;
//Inform Countdown
if ( game . GetCountdown ( ) > 0 )
{
Manager . GetLobby ( ) . WriteGameLine ( " starting in " + game . GetCountdown ( ) + " ... " , 3 , 159 , ( byte ) 13 ) ;
}
else
{
Manager . GetLobby ( ) . WriteGameLine ( " game in progress " , 3 , 159 , ( byte ) 13 ) ;
}
if ( game . GetCountdown ( ) > 0 & & game . GetCountdown ( ) < = 10 )
for ( Player player : UtilServer . getPlayers ( ) )
player . playSound ( player . getLocation ( ) , Sound . NOTE_PLING , 1f , 1f ) ;
//Countdown Ended
if ( game . GetCountdown ( ) = = 0 )
game . SetState ( GameState . Prepare ) ;
}
2013-09-02 10:09:28 +02:00
@EventHandler
public void restartServerCheck ( RestartServerEvent event )
{
if ( Manager . GetGame ( ) ! = null & & Manager . GetGame ( ) . GetState ( ) ! = GameState . Recruit )
event . setCancelled ( true ) ;
}
2014-09-18 07:44:48 +02:00
2013-08-27 17:14:08 +02:00
@EventHandler
public void KitRegister ( GameStateChangeEvent event )
{
2013-09-23 08:00:35 +02:00
if ( event . GetState ( ) ! = event . GetGame ( ) . KitRegisterState )
2013-08-27 17:14:08 +02:00
return ;
event . GetGame ( ) . RegisterKits ( ) ;
}
2015-07-07 02:30:20 +02:00
@EventHandler ( priority = EventPriority . HIGH )
2013-08-27 17:14:08 +02:00
public void KitDeregister ( GameStateChangeEvent event )
{
if ( event . GetState ( ) ! = GameState . Dead )
return ;
event . GetGame ( ) . DeregisterKits ( ) ;
2014-09-06 12:39:20 +02:00
event . GetGame ( ) . deRegisterStats ( ) ;
2013-08-27 17:14:08 +02:00
}
2014-08-08 09:05:11 +02:00
2014-08-14 03:23:48 +02:00
2014-09-21 01:26:34 +02:00
2014-08-14 03:23:48 +02:00
@EventHandler
public void ScoreboardTitle ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . FASTEST )
return ;
Game game = Manager . GetGame ( ) ;
if ( game = = null ) return ;
game . GetScoreboard ( ) . UpdateTitle ( ) ;
}
2013-08-27 17:14:08 +02:00
@EventHandler ( priority = EventPriority . LOWEST ) //BEFORE PARSE DATA
public void TeamGeneration ( GameStateChangeEvent event )
{
if ( event . GetState ( ) ! = GameState . Recruit )
return ;
Game game = event . GetGame ( ) ;
2014-10-10 09:54:38 +02:00
int count = 1 ;
2013-08-27 17:14:08 +02:00
for ( String team : game . WorldData . SpawnLocs . keySet ( ) )
{
ChatColor color ;
if ( team . equalsIgnoreCase ( " RED " ) ) color = ChatColor . RED ;
else if ( team . equalsIgnoreCase ( " YELLOW " ) ) color = ChatColor . YELLOW ;
else if ( team . equalsIgnoreCase ( " GREEN " ) ) color = ChatColor . GREEN ;
else if ( team . equalsIgnoreCase ( " BLUE " ) ) color = ChatColor . AQUA ;
else
{
color = ChatColor . DARK_GREEN ;
2014-09-11 09:44:57 +02:00
if ( game . GetTeamList ( ) . size ( ) % 14 = = 0 ) if ( game . WorldData . SpawnLocs . size ( ) > 1 ) color = ChatColor . RED ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 1 ) color = ChatColor . YELLOW ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 2 ) color = ChatColor . GREEN ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 3 ) color = ChatColor . AQUA ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 4 ) color = ChatColor . GOLD ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 5 ) color = ChatColor . LIGHT_PURPLE ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 6 ) color = ChatColor . DARK_BLUE ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 7 ) color = ChatColor . WHITE ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 8 ) color = ChatColor . BLUE ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 9 ) color = ChatColor . DARK_GREEN ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 10 ) color = ChatColor . DARK_PURPLE ;
2014-10-10 09:54:38 +02:00
if ( game . GetTeamList ( ) . size ( ) % 14 = = 11 ) color = ChatColor . DARK_RED ;
if ( game . GetTeamList ( ) . size ( ) % 14 = = 12 ) color = ChatColor . DARK_AQUA ;
}
//Random Names
String teamName = team ;
if ( game . WorldData . SpawnLocs . size ( ) > 12 )
{
teamName = " " + count ;
count + + ;
2013-08-27 17:14:08 +02:00
}
2014-10-10 09:54:38 +02:00
GameTeam newTeam = new GameTeam ( game , teamName , color , game . WorldData . SpawnLocs . get ( team ) ) ;
2013-08-27 17:14:08 +02:00
game . AddTeam ( newTeam ) ;
}
//Restrict Kits
game . RestrictKits ( ) ;
//Parse Data
game . ParseData ( ) ;
}
@EventHandler ( priority = EventPriority . MONITOR )
public void TeamScoreboardCreation ( GameStateChangeEvent event )
{
if ( event . GetState ( ) ! = GameState . Recruit )
return ;
2014-06-10 04:51:47 +02:00
event . GetGame ( ) . GetScoreboard ( ) . CreateTeams ( ) ;
2013-08-27 17:14:08 +02:00
}
public void TeamPreferenceJoin ( Game game )
{
//Preferred Team No Longer Full
for ( GameTeam team : game . GetTeamPreferences ( ) . keySet ( ) )
{
Iterator < Player > queueIterator = game . GetTeamPreferences ( ) . get ( team ) . iterator ( ) ;
while ( queueIterator . hasNext ( ) )
{
Player player = queueIterator . next ( ) ;
if ( ! game . CanJoinTeam ( team ) )
2014-11-15 09:31:56 +01:00
{
2013-08-27 17:14:08 +02:00
break ;
2014-11-15 09:31:56 +01:00
}
2013-08-27 17:14:08 +02:00
queueIterator . remove ( ) ;
if ( ! game . IsPlaying ( player ) )
{
PlayerAdd ( game , player , team ) ;
}
else
{
2014-08-29 10:21:08 +02:00
game . SetPlayerTeam ( player , team , true ) ;
2013-08-27 17:14:08 +02:00
}
}
}
}
public void TeamPreferenceSwap ( Game game )
{
//Preferred Team No Longer Full
for ( GameTeam team : game . GetTeamPreferences ( ) . keySet ( ) )
{
Iterator < Player > queueIterator = game . GetTeamPreferences ( ) . get ( team ) . iterator ( ) ;
while ( queueIterator . hasNext ( ) )
{
Player player = queueIterator . next ( ) ;
GameTeam currentTeam = game . GetTeam ( player ) ;
//Not on team, cannot swap
if ( currentTeam = = null )
continue ;
// Other without concurrent (order doesn't matter as first case will fire
if ( team = = currentTeam )
{
queueIterator . remove ( ) ;
continue ;
}
for ( Player other : team . GetPlayers ( false ) )
{
if ( other . equals ( player ) )
continue ;
GameTeam otherPref = game . GetTeamPreference ( other ) ;
if ( otherPref = = null )
continue ;
if ( otherPref . equals ( currentTeam ) )
{
UtilPlayer . message ( player , F . main ( " Team " , " You swapped team with " + F . elem ( team . GetColor ( ) + other . getName ( ) ) + " . " ) ) ;
UtilPlayer . message ( other , F . main ( " Team " , " You swapped team with " + F . elem ( currentTeam . GetColor ( ) + player . getName ( ) ) + " . " ) ) ;
//Player Swap
queueIterator . remove ( ) ;
2014-08-29 10:21:08 +02:00
game . SetPlayerTeam ( player , team , true ) ;
2013-08-27 17:14:08 +02:00
//Other Swap
2014-08-29 10:21:08 +02:00
game . SetPlayerTeam ( other , currentTeam , true ) ;
2014-06-16 01:25:32 +02:00
break ;
2013-08-27 17:14:08 +02:00
}
}
}
}
}
public void TeamDefaultJoin ( Game game )
{
//Team Default
for ( Player player : UtilServer . getPlayers ( ) )
{
if ( player . isDead ( ) )
{
2014-03-15 05:49:01 +01:00
player . sendMessage ( F . main ( " Afk Monitor " , " You are being sent to the Lobby for being AFK. " ) ) ;
2015-01-11 09:42:31 +01:00
Manager . GetPortal ( ) . sendPlayerToServer ( player , " Lobby " ) ;
2014-05-03 03:23:10 +02:00
}
else if ( Manager . IsObserver ( player ) )
{
2013-08-27 17:14:08 +02:00
}
2014-08-30 08:33:56 +02:00
else if ( ! game . IsPlaying ( player ) & & Manager . IsTeamAutoJoin ( ) )
2013-08-27 17:14:08 +02:00
{
PlayerAdd ( game , player , null ) ;
}
}
}
@EventHandler
public void TeamQueueSizeUpdate ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . TICK )
return ;
Game game = Manager . GetGame ( ) ;
if ( game = = null ) return ;
for ( GameTeam team : game . GetTeamList ( ) )
{
int amount = 0 ;
if ( game . GetTeamPreferences ( ) . containsKey ( team ) )
{
amount = game . GetTeamPreferences ( ) . get ( team ) . size ( ) ;
}
2013-09-09 10:06:44 +02:00
if ( team . GetTeamEntity ( ) = = null )
continue ;
2013-08-27 17:14:08 +02:00
if ( game . GetCountdown ( ) = = - 1 )
{
team . GetTeamEntity ( ) . setCustomName ( team . GetFormattedName ( ) + " Team " + ChatColor . RESET + " " + amount + " Queued " ) ;
}
else
{
team . GetTeamEntity ( ) . setCustomName ( team . GetPlayers ( false ) . size ( ) + " Players " + team . GetFormattedName ( ) + " Team " + ChatColor . RESET + " " + amount + " Queued " ) ;
}
}
2014-08-23 09:55:28 +02:00
}
2013-08-27 17:14:08 +02:00
public boolean PlayerAdd ( Game game , Player player , GameTeam team )
{
if ( team = = null )
team = game . ChooseTeam ( player ) ;
if ( team = = null )
return false ;
2014-08-29 10:21:08 +02:00
game . SetPlayerTeam ( player , team , true ) ;
2013-08-27 17:14:08 +02:00
return true ;
}
2014-08-09 15:25:13 +02:00
@EventHandler ( priority = EventPriority . LOW )
2013-08-27 17:14:08 +02:00
public void PlayerPrepare ( GameStateChangeEvent event )
{
2014-03-13 08:18:22 +01:00
final Game game = event . GetGame ( ) ;
2013-08-27 17:14:08 +02:00
if ( event . GetState ( ) ! = GameState . Prepare )
return ;
2014-03-13 08:18:22 +01:00
final ArrayList < Player > players = game . GetPlayers ( true ) ;
2013-08-27 17:14:08 +02:00
//Prepare Players
2014-03-13 08:18:22 +01:00
for ( int i = 0 ; i < players . size ( ) ; i + + )
2013-08-27 17:14:08 +02:00
{
2014-03-13 08:18:22 +01:00
final Player player = players . get ( i ) ;
final GameTeam team = game . GetTeam ( player ) ;
2015-02-26 06:07:07 +01:00
UtilServer . getServer ( ) . getScheduler ( ) . runTaskLater ( Manager . getPlugin ( ) , new Runnable ( )
2014-03-13 08:18:22 +01:00
{
public void run ( )
{
//Teleport
2014-03-14 10:17:06 +01:00
team . SpawnTeleport ( player ) ;
2014-03-13 08:18:22 +01:00
Manager . Clear ( player ) ;
UtilInv . Clear ( player ) ;
2013-08-27 17:14:08 +02:00
2014-03-13 08:18:22 +01:00
game . ValidateKit ( player , game . GetTeam ( player ) ) ;
2013-08-27 17:14:08 +02:00
2014-03-13 08:18:22 +01:00
if ( game . GetKit ( player ) ! = null )
game . GetKit ( player ) . ApplyKit ( player ) ;
2014-03-14 10:17:06 +01:00
//Event
PlayerPrepareTeleportEvent playerStateEvent = new PlayerPrepareTeleportEvent ( game , player ) ;
UtilServer . getServer ( ) . getPluginManager ( ) . callEvent ( playerStateEvent ) ;
2014-03-13 08:18:22 +01:00
}
2014-10-12 09:26:18 +02:00
} , i * game . TickPerTeleport ) ;
2013-08-27 17:14:08 +02:00
}
2014-03-13 08:18:22 +01:00
//Announce Game after every player is TP'd in
2015-02-26 06:07:07 +01:00
UtilServer . getServer ( ) . getScheduler ( ) . runTaskLater ( Manager . getPlugin ( ) , new Runnable ( )
2014-03-13 08:18:22 +01:00
{
public void run ( )
{
game . AnnounceGame ( ) ;
game . StartPrepareCountdown ( ) ;
2014-04-05 07:52:23 +02:00
//Event
GamePrepareCountdownCommence event = new GamePrepareCountdownCommence ( game ) ;
UtilServer . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
2014-03-13 08:18:22 +01:00
}
2014-10-12 09:26:18 +02:00
} , players . size ( ) * game . TickPerTeleport ) ;
2014-05-03 03:23:10 +02:00
//Spectators Move
for ( Player player : UtilServer . getPlayers ( ) )
{
if ( Manager . GetGame ( ) . IsAlive ( player ) )
continue ;
2015-03-12 05:31:40 +01:00
Manager . addSpectator ( player , true ) ;
2014-05-03 03:23:10 +02:00
}
2013-08-27 17:14:08 +02:00
}
@EventHandler
2014-03-22 00:44:31 +01:00
public void PlayerTeleportOut ( GameStateChangeEvent event )
2013-08-27 17:14:08 +02:00
{
if ( event . GetState ( ) ! = GameState . Dead )
return ;
2014-03-22 00:44:31 +01:00
final Player [ ] players = UtilServer . getPlayers ( ) ;
//Prepare Players
for ( int i = 0 ; i < players . length ; i + + )
2013-08-27 17:14:08 +02:00
{
2014-03-22 00:44:31 +01:00
final Player player = players [ i ] ;
2015-02-26 06:07:07 +01:00
UtilServer . getServer ( ) . getScheduler ( ) . runTaskLater ( Manager . getPlugin ( ) , new Runnable ( )
2014-03-22 00:44:31 +01:00
{
public void run ( )
{
Manager . Clear ( player ) ;
UtilInv . Clear ( player ) ;
Manager . GetCondition ( ) . EndCondition ( player , ConditionType . CLOAK , " Spectator " ) ;
player . eject ( ) ;
player . leaveVehicle ( ) ;
player . teleport ( Manager . GetLobby ( ) . GetSpawn ( ) ) ;
}
2014-08-21 09:07:54 +02:00
} , i ) ;
2013-08-27 17:14:08 +02:00
}
}
2014-03-22 00:44:31 +01:00
2014-01-03 07:37:39 +01:00
@EventHandler
public void disguiseClean ( GameStateChangeEvent event )
{
if ( event . GetState ( ) ! = GameState . Dead )
return ;
Manager . GetDisguise ( ) . clearDisguises ( ) ;
}
2013-08-27 17:14:08 +02:00
2014-01-18 02:56:00 +01:00
2013-08-27 17:14:08 +02:00
@EventHandler
public void WorldFireworksUpdate ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . FASTEST )
return ;
Game game = Manager . GetGame ( ) ;
if ( game = = null ) return ;
if ( game . GetState ( ) ! = GameState . End )
return ;
Color color = Color . GREEN ;
if ( game . WinnerTeam ! = null )
{
if ( game . WinnerTeam . GetColor ( ) = = ChatColor . RED ) color = Color . RED ;
else if ( game . WinnerTeam . GetColor ( ) = = ChatColor . AQUA ) color = Color . BLUE ;
else if ( game . WinnerTeam . GetColor ( ) = = ChatColor . YELLOW ) color = Color . YELLOW ;
else color = Color . LIME ;
}
2014-10-25 02:03:45 +02:00
Location loc = game . GetSpectatorLocation ( ) . clone ( ) . add ( Math . random ( ) * 160 - 80 , 10 + Math . random ( ) * 20 , Math . random ( ) * 160 - 80 ) ;
2013-08-27 17:14:08 +02:00
2014-10-25 02:03:45 +02:00
UtilFirework . playFirework ( loc , Type . BALL_LARGE , color , false , false ) ;
2013-08-27 17:14:08 +02:00
}
@EventHandler ( priority = EventPriority . MONITOR )
public void EndUpdate ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . SEC )
return ;
Game game = Manager . GetGame ( ) ;
if ( game = = null ) return ;
game . EndCheck ( ) ;
}
@EventHandler ( priority = EventPriority . MONITOR )
public void EndStateChange ( PlayerStateChangeEvent event )
{
event . GetGame ( ) . EndCheck ( ) ;
}
2015-08-12 08:36:21 +02:00
@EventHandler
public void carlSpinnerCancel ( CarlSpinnerEvent event )
{
Game game = Manager . GetGame ( ) ;
if ( game = = null ) return ;
2015-08-12 08:58:46 +02:00
if ( game . GetCountdown ( ) > 0 | | game . GetState ( ) ! = GameState . Recruit )
{
UtilPlayer . message ( event . getPlayer ( ) , F . main ( " Carl " , " You can't use my spinner at the moment! " ) ) ;
2015-08-12 08:36:21 +02:00
event . setCancelled ( true ) ;
2015-08-12 08:58:46 +02:00
}
2015-08-12 08:36:21 +02:00
}
2013-08-27 17:14:08 +02:00
}