2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.managers ;
import java.util.ArrayList ;
import java.util.Collection ;
2014-08-04 06:31:55 +02:00
import java.util.Collections ;
2013-08-27 17:14:08 +02:00
import java.util.HashMap ;
import java.util.List ;
import java.util.Map.Entry ;
import org.bukkit.Bukkit ;
import org.bukkit.ChatColor ;
import org.bukkit.Color ;
import org.bukkit.DyeColor ;
import org.bukkit.FireworkEffect ;
2014-08-04 05:44:01 +02:00
import org.bukkit.FireworkEffect.Type ;
2013-08-27 17:14:08 +02:00
import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.World ;
import org.bukkit.block.Block ;
import org.bukkit.block.BlockFace ;
import org.bukkit.entity.Creature ;
import org.bukkit.entity.Entity ;
import org.bukkit.entity.EntityType ;
import org.bukkit.entity.Player ;
import org.bukkit.entity.Sheep ;
2013-08-31 01:37:21 +02:00
import org.bukkit.entity.Slime ;
2013-08-27 17:14:08 +02:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
import org.bukkit.event.Listener ;
import org.bukkit.event.entity.EntityCombustEvent ;
2014-08-09 14:59:54 +02:00
import org.bukkit.event.entity.EntityExplodeEvent ;
2014-08-09 05:10:02 +02:00
import org.bukkit.event.inventory.InventoryClickEvent ;
2014-08-09 11:55:05 +02:00
import org.bukkit.event.inventory.InventoryType ;
2013-08-27 17:14:08 +02:00
import org.bukkit.event.player.PlayerQuitEvent ;
2014-08-11 03:55:00 +02:00
import org.bukkit.event.player.PlayerVelocityEvent ;
2013-08-27 17:14:08 +02:00
import org.bukkit.scoreboard.DisplaySlot ;
import org.bukkit.scoreboard.Objective ;
import org.bukkit.scoreboard.Scoreboard ;
import mineplex.core.account.CoreClient ;
import mineplex.core.common.Rank ;
import mineplex.core.common.util.C ;
2014-08-26 09:33:48 +02:00
import mineplex.core.common.util.F ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.MapUtil ;
import mineplex.core.common.util.NautHashMap ;
import mineplex.core.common.util.UtilEnt ;
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 ;
2014-10-25 02:36:22 +02:00
import mineplex.core.common.util.UtilPlayer ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.UtilServer ;
2014-10-25 04:40:34 +02:00
import mineplex.core.common.util.UtilBlockText ;
import mineplex.core.common.util.UtilBlockText.TextAlign ;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.UtilTime ;
import mineplex.core.common.util.UtilWorld ;
2014-08-26 09:33:48 +02:00
import mineplex.core.cosmetic.event.ActivateGemBoosterEvent ;
2013-08-27 17:14:08 +02:00
import mineplex.core.donation.Donor ;
2014-10-25 02:36:22 +02:00
import mineplex.core.event.CustomTagEvent ;
2014-09-12 22:03:33 +02:00
import mineplex.core.packethandler.IPacketHandler ;
import mineplex.core.packethandler.PacketHandler ;
2014-03-21 18:57:31 +01:00
import mineplex.core.packethandler.PacketVerifier ;
2014-09-12 22:03:33 +02:00
import mineplex.core.packethandler.PacketInfo ;
2013-08-27 17:14:08 +02:00
import mineplex.core.updater.UpdateType ;
import mineplex.core.updater.event.UpdateEvent ;
2014-04-19 06:50:14 +02:00
import mineplex.minecraft.game.core.damage.CustomDamageEvent ;
2013-08-27 17:14:08 +02:00
import nautilus.game.arcade.ArcadeManager ;
2013-09-11 04:22:55 +02:00
import nautilus.game.arcade.GameType ;
2013-08-27 17:14:08 +02:00
import nautilus.game.arcade.events.GameStateChangeEvent ;
import nautilus.game.arcade.game.Game ;
import nautilus.game.arcade.game.Game.GameState ;
2014-08-04 05:44:01 +02:00
import nautilus.game.arcade.game.GameTeam ;
2013-08-27 17:14:08 +02:00
import nautilus.game.arcade.kit.Kit ;
import nautilus.game.arcade.kit.KitAvailability ;
2014-08-04 07:31:46 +02:00
import nautilus.game.arcade.kit.KitSorter ;
2014-08-14 01:57:37 +02:00
import net.minecraft.server.v1_7_R4.Packet ;
2014-10-25 02:36:22 +02:00
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata ;
2014-10-19 04:15:53 +02:00
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving ;
2014-10-25 02:36:22 +02:00
import net.minecraft.server.v1_7_R4.WatchableObject ;
2013-08-27 17:14:08 +02:00
2014-09-12 22:03:33 +02:00
public class GameLobbyManager implements Listener , IPacketHandler
2013-08-27 17:14:08 +02:00
{
public ArcadeManager Manager ;
private Location _gameText ;
private Location _advText ;
private Location _kitText ;
private Location _teamText ;
private Location _kitDisplay ;
2013-11-07 00:18:36 +01:00
private Location _teamDisplay ;
2013-08-27 17:14:08 +02:00
private Location spawn ;
2013-08-31 01:37:21 +02:00
private NautHashMap < Entity , LobbyEnt > _kits = new NautHashMap < Entity , LobbyEnt > ( ) ;
private NautHashMap < Block , Material > _kitBlocks = new NautHashMap < Block , Material > ( ) ;
2013-08-27 17:14:08 +02:00
2013-08-31 01:37:21 +02:00
private NautHashMap < Entity , LobbyEnt > _teams = new NautHashMap < Entity , LobbyEnt > ( ) ;
private NautHashMap < Block , Material > _teamBlocks = new NautHashMap < Block , Material > ( ) ;
2013-08-27 17:14:08 +02:00
private long _fireworkStart ;
private Color _fireworkColor ;
private int _advertiseStage = 0 ;
2013-11-07 00:18:36 +01:00
2013-08-27 17:14:08 +02:00
//Scoreboard
private NautHashMap < Player , Scoreboard > _scoreboardMap = new NautHashMap < Player , Scoreboard > ( ) ;
private NautHashMap < Player , Integer > _gemMap = new NautHashMap < Player , Integer > ( ) ;
2014-05-05 07:40:44 +02:00
private NautHashMap < Player , Integer > _eloMap = new NautHashMap < Player , Integer > ( ) ;
2013-08-27 17:14:08 +02:00
private NautHashMap < Player , String > _kitMap = new NautHashMap < Player , String > ( ) ;
private int _oldPlayerCount = 0 ;
2014-12-23 07:06:30 +01:00
private int _oldMaxPlayerCount = 0 ; // Used for scoreboard when max player count changes
2014-09-05 13:36:01 +02:00
private boolean _handlingPacket = false ;
2013-08-27 17:14:08 +02:00
2014-09-12 22:03:33 +02:00
public GameLobbyManager ( ArcadeManager manager , PacketHandler packetHandler )
2013-08-27 17:14:08 +02:00
{
Manager = manager ;
2014-09-12 22:03:33 +02:00
packetHandler . addPacketHandler ( this ) ;
2013-08-27 17:14:08 +02:00
World world = UtilWorld . getWorld ( " world " ) ;
spawn = new Location ( world , 0 , 104 , 0 ) ;
_gameText = new Location ( world , 0 , 130 , 50 ) ;
_kitText = new Location ( world , - 40 , 120 , 0 ) ;
_teamText = new Location ( world , 40 , 120 , 0 ) ;
_advText = new Location ( world , 0 , 140 , - 60 ) ;
_kitDisplay = new Location ( world , - 17 , 101 , 0 ) ;
_teamDisplay = new Location ( world , 18 , 101 , 0 ) ;
Manager . GetPluginManager ( ) . registerEvents ( this , Manager . GetPlugin ( ) ) ;
}
private boolean HasScoreboard ( Player player )
{
return _scoreboardMap . containsKey ( player ) ;
}
public void CreateScoreboards ( )
{
for ( Player player : UtilServer . getPlayers ( ) )
2014-06-19 09:48:04 +02:00
{
CreateScoreboard ( player , false ) ;
}
for ( Player otherPlayer : UtilServer . getPlayers ( ) )
{
AddPlayerToScoreboards ( otherPlayer , null ) ;
}
2013-08-27 17:14:08 +02:00
}
2014-06-19 09:48:04 +02:00
private void CreateScoreboard ( Player player , boolean resendToAll )
2013-08-27 17:14:08 +02:00
{
_scoreboardMap . put ( player , Bukkit . getScoreboardManager ( ) . getNewScoreboard ( ) ) ;
Scoreboard scoreboard = _scoreboardMap . get ( player ) ;
2014-05-26 01:42:39 +02:00
Objective objective = scoreboard . registerNewObjective ( " §l " + " Lobby " , " dummy " ) ;
2013-08-27 17:14:08 +02:00
objective . setDisplaySlot ( DisplaySlot . SIDEBAR ) ;
for ( Rank rank : Rank . values ( ) )
{
if ( rank = = Rank . ALL )
{
scoreboard . registerNewTeam ( rank . Name ) . setPrefix ( " " ) ;
}
else
{
2013-11-07 00:18:36 +01:00
scoreboard . registerNewTeam ( rank . Name ) . setPrefix ( rank . GetTag ( true , true ) + ChatColor . RESET + " " + ChatColor . WHITE ) ;
2013-08-27 17:14:08 +02:00
}
if ( Manager . GetGame ( ) ! = null & & ! Manager . GetGame ( ) . GetTeamList ( ) . isEmpty ( ) )
{
for ( GameTeam team : Manager . GetGame ( ) . GetTeamList ( ) )
{
if ( rank = = Rank . ALL )
{
scoreboard . registerNewTeam ( rank . Name + team . GetName ( ) . toUpperCase ( ) ) . setPrefix ( team . GetColor ( ) + " " ) ;
}
else
{
2013-11-07 00:18:36 +01:00
scoreboard . registerNewTeam ( rank . Name + team . GetName ( ) . toUpperCase ( ) ) . setPrefix ( rank . GetTag ( true , true ) + ChatColor . RESET + " " + team . GetColor ( ) ) ;
2013-08-27 17:14:08 +02:00
}
}
2013-09-07 02:43:45 +02:00
}
2013-08-27 17:14:08 +02:00
}
2014-08-08 01:44:27 +02:00
2014-06-19 09:48:04 +02:00
if ( resendToAll )
2013-08-27 17:14:08 +02:00
{
2014-06-19 09:48:04 +02:00
for ( Player otherPlayer : UtilServer . getPlayers ( ) )
{
2014-08-08 01:44:27 +02:00
String teamName = null ;
if ( Manager . GetGame ( ) ! = null & & Manager . GetGame ( ) . GetTeam ( otherPlayer ) ! = null )
teamName = Manager . GetGame ( ) . GetTeam ( otherPlayer ) . GetName ( ) . toUpperCase ( ) ;
AddPlayerToScoreboards ( otherPlayer , teamName ) ;
2014-06-19 09:48:04 +02:00
}
2013-08-27 17:14:08 +02:00
}
}
public Collection < Scoreboard > GetScoreboards ( )
{
return _scoreboardMap . values ( ) ;
}
public void WriteLine ( Player player , int x , int y , int z , BlockFace face , int line , String text )
{
Location loc = player . getLocation ( ) ;
loc . setX ( x ) ;
loc . setY ( y ) ;
loc . setZ ( z ) ;
int id = 159 ;
byte data = 15 ;
if ( player . getItemInHand ( ) ! = null & & player . getItemInHand ( ) . getType ( ) . isBlock ( ) & & player . getItemInHand ( ) . getType ( ) ! = Material . AIR )
{
id = player . getItemInHand ( ) . getTypeId ( ) ;
data = UtilInv . GetData ( player . getItemInHand ( ) ) ;
}
if ( line > 0 )
loc . add ( 0 , line * - 6 , 0 ) ;
2014-10-25 04:40:34 +02:00
UtilBlockText . MakeText ( text , loc , face , id , data , TextAlign . CENTER ) ;
2013-08-27 17:14:08 +02:00
player . sendMessage ( " Writing: " + text + " @ " + UtilWorld . locToStrClean ( loc ) ) ;
}
public void WriteGameLine ( String text , int line , int id , byte data )
{
2014-05-04 21:52:04 +02:00
Location loc = new Location ( _gameText . getWorld ( ) , _gameText . getX ( ) , _gameText . getY ( ) , _gameText . getZ ( ) ) ;
2013-08-27 17:14:08 +02:00
if ( line > 0 )
loc . add ( 0 , line * - 6 , 0 ) ;
BlockFace face = BlockFace . WEST ;
2014-10-25 04:40:34 +02:00
UtilBlockText . MakeText ( text , loc , face , id , data , TextAlign . CENTER ) ;
2013-08-27 17:14:08 +02:00
}
public void WriteAdvertiseLine ( String text , int line , int id , byte data )
{
2014-05-04 21:52:04 +02:00
Location loc = new Location ( _advText . getWorld ( ) , _advText . getX ( ) , _advText . getY ( ) , _advText . getZ ( ) ) ;
2013-08-27 17:14:08 +02:00
if ( line > 0 )
loc . add ( 0 , line * - 6 , 0 ) ;
BlockFace face = BlockFace . EAST ;
2014-10-25 04:40:34 +02:00
UtilBlockText . MakeText ( text , loc , face , id , data , TextAlign . CENTER ) ;
2013-08-27 17:14:08 +02:00
}
public void WriteKitLine ( String text , int line , int id , byte data )
{
2014-05-04 21:52:04 +02:00
Location loc = new Location ( _kitText . getWorld ( ) , _kitText . getX ( ) , _kitText . getY ( ) , _kitText . getZ ( ) ) ;
2013-08-27 17:14:08 +02:00
if ( line > 0 )
loc . add ( 0 , line * - 6 , 0 ) ;
BlockFace face = BlockFace . NORTH ;
2014-10-25 04:40:34 +02:00
UtilBlockText . MakeText ( text , loc , face , id , data , TextAlign . CENTER ) ;
2013-08-27 17:14:08 +02:00
}
public void WriteTeamLine ( String text , int line , int id , byte data )
{
2014-05-04 21:52:04 +02:00
Location loc = new Location ( _teamText . getWorld ( ) , _teamText . getX ( ) , _teamText . getY ( ) , _teamText . getZ ( ) ) ;
2013-08-27 17:14:08 +02:00
if ( line > 0 )
loc . add ( 0 , line * - 6 , 0 ) ;
BlockFace face = BlockFace . SOUTH ;
2014-10-25 04:40:34 +02:00
UtilBlockText . MakeText ( text , loc , face , id , data , TextAlign . CENTER ) ;
2013-08-27 17:14:08 +02:00
}
public Location GetSpawn ( )
{
return spawn . clone ( ) . add ( 4 - Math . random ( ) * 8 , 0 , 4 - Math . random ( ) * 8 ) ;
}
@EventHandler ( priority = EventPriority . MONITOR )
public void TeamGeneration ( GameStateChangeEvent event )
{
if ( event . GetState ( ) ! = GameState . Recruit )
return ;
2014-04-11 07:33:31 +02:00
if ( event . GetGame ( ) . GetMode ( ) = = null )
WriteGameLine ( event . GetGame ( ) . WorldData . MapName , 1 , 159 , ( byte ) 4 ) ;
else
WriteGameLine ( event . GetGame ( ) . WorldData . MapName , 2 , 159 , ( byte ) 4 ) ;
2013-10-08 08:56:57 +02:00
2013-08-27 17:14:08 +02:00
CreateTeams ( event . GetGame ( ) ) ;
}
public void CreateTeams ( Game game )
{
//Text
WriteTeamLine ( " Select " , 0 , 159 , ( byte ) 15 ) ;
WriteTeamLine ( " Team " , 1 , 159 , ( byte ) 4 ) ;
//Remove Old Ents
for ( Entity ent : _teams . keySet ( ) )
ent . remove ( ) ;
_teams . clear ( ) ;
//Remove Blocks
for ( Block block : _teamBlocks . keySet ( ) )
block . setType ( _teamBlocks . get ( block ) ) ;
_teamBlocks . clear ( ) ;
2013-09-09 10:06:44 +02:00
2013-09-14 01:34:05 +02:00
//Smash
2014-04-23 02:21:01 +02:00
if ( game . GetType ( ) = = GameType . Smash | | game . GetType ( ) = = GameType . SurvivalGames )
2013-09-14 01:34:05 +02:00
{
//Text
2014-08-14 02:56:47 +02:00
WriteTeamLine ( " Select " , 0 , 159 , ( byte ) 15 ) ;
WriteTeamLine ( " Kit " , 1 , 159 , ( byte ) 4 ) ;
2013-10-04 23:49:05 +02:00
CreateScoreboards ( ) ;
return ;
}
2014-09-11 09:44:57 +02:00
//UHC
if ( game . GetType ( ) = = GameType . UHC )
{
if ( game . GetTeamList ( ) . size ( ) > 1 )
{
//Text
WriteTeamLine ( " " , 0 , 159 , ( byte ) 15 ) ;
WriteTeamLine ( " " , 1 , 159 , ( byte ) 4 ) ;
for ( int i = 0 ; i < game . GetTeamList ( ) . size ( ) ; i + + )
{
GameTeam team = game . GetTeamList ( ) . get ( i ) ;
//Circle Math
double lead = i * ( ( 2d * Math . PI ) / game . GetTeamList ( ) . size ( ) ) ;
double sizeMod = 32 ;
double oX = - Math . sin ( lead ) * sizeMod ;
double oZ = Math . cos ( lead ) * sizeMod ;
//Location
Location entLoc = spawn . clone ( ) . add ( oX , 0 , oZ ) ;
entLoc . setY ( _teamDisplay . getY ( ) ) ;
//Blocks
SetKitTeamBlocks ( entLoc . clone ( ) , 35 , team . GetColorData ( ) , _teamBlocks ) ;
entLoc . add ( 0 , 1 . 5 , 0 ) ;
entLoc . getChunk ( ) . load ( ) ;
//NPC
Sheep ent = ( Sheep ) Manager . GetCreature ( ) . SpawnEntity ( entLoc , EntityType . SHEEP ) ;
ent . setRemoveWhenFarAway ( false ) ;
ent . setCustomNameVisible ( false ) ;
ent . setColor ( DyeColor . getByWoolData ( team . GetColorData ( ) ) ) ;
UtilEnt . Vegetate ( ent ) ;
team . SetTeamEntity ( ent ) ;
_teams . put ( ent , new LobbyEnt ( ent , entLoc , team ) ) ;
}
return ;
}
}
2014-06-27 03:38:11 +02:00
2013-09-09 10:06:44 +02:00
//Standard
2014-06-27 03:38:11 +02:00
if ( game . GetKits ( ) . length > 1 | | game . GetTeamList ( ) . size ( ) < 6 )
2013-09-09 10:06:44 +02:00
{
//Display
2013-09-13 04:24:33 +02:00
ArrayList < GameTeam > teams = new ArrayList < GameTeam > ( ) ;
for ( GameTeam team : game . GetTeamList ( ) )
if ( team . GetVisible ( ) )
teams . add ( team ) ;
2013-09-09 10:06:44 +02:00
//Positions
double space = 6 ;
double offset = ( teams . size ( ) - 1 ) * space / 2d ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
for ( int i = 0 ; i < teams . size ( ) ; i + + )
{
Location entLoc = _teamDisplay . clone ( ) . subtract ( 0 , 0 , i * space - offset ) ;
SetKitTeamBlocks ( entLoc . clone ( ) , 35 , teams . get ( i ) . GetColorData ( ) , _teamBlocks ) ;
entLoc . add ( 0 , 1 . 5 , 0 ) ;
entLoc . getChunk ( ) . load ( ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
Sheep ent = ( Sheep ) Manager . GetCreature ( ) . SpawnEntity ( entLoc , EntityType . SHEEP ) ;
ent . setRemoveWhenFarAway ( false ) ;
ent . setCustomNameVisible ( true ) ;
ent . setColor ( DyeColor . getByWoolData ( teams . get ( i ) . GetColorData ( ) ) ) ;
UtilEnt . Vegetate ( ent ) ;
teams . get ( i ) . SetTeamEntity ( ent ) ;
_teams . put ( ent , new LobbyEnt ( ent , entLoc , teams . get ( i ) ) ) ;
}
}
//Double
else
2013-08-27 17:14:08 +02:00
{
2013-09-09 10:06:44 +02:00
//Text
WriteKitLine ( " Select " , 0 , 159 , ( byte ) 15 ) ;
WriteKitLine ( " Team " , 1 , 159 , ( byte ) 4 ) ;
//Display
ArrayList < GameTeam > teamsA = new ArrayList < GameTeam > ( ) ;
ArrayList < GameTeam > teamsB = new ArrayList < GameTeam > ( ) ;
for ( int i = 0 ; i < game . GetTeamList ( ) . size ( ) ; i + + )
{
if ( i < game . GetTeamList ( ) . size ( ) / 2 )
teamsA . add ( game . GetTeamList ( ) . get ( i ) ) ;
else
teamsB . add ( game . GetTeamList ( ) . get ( i ) ) ;
}
//A
{
//Positions
double space = 6 ;
double offset = ( teamsA . size ( ) - 1 ) * space / 2d ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
for ( int i = 0 ; i < teamsA . size ( ) ; i + + )
{
Location entLoc = _teamDisplay . clone ( ) . subtract ( 0 , 0 , i * space - offset ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
SetKitTeamBlocks ( entLoc . clone ( ) , 35 , teamsA . get ( i ) . GetColorData ( ) , _teamBlocks ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
entLoc . add ( 0 , 1 . 5 , 0 ) ;
entLoc . getChunk ( ) . load ( ) ;
Sheep ent = ( Sheep ) Manager . GetCreature ( ) . SpawnEntity ( entLoc , EntityType . SHEEP ) ;
ent . setRemoveWhenFarAway ( false ) ;
ent . setCustomNameVisible ( true ) ;
ent . setColor ( DyeColor . getByWoolData ( teamsA . get ( i ) . GetColorData ( ) ) ) ;
UtilEnt . Vegetate ( ent ) ;
teamsA . get ( i ) . SetTeamEntity ( ent ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
_teams . put ( ent , new LobbyEnt ( ent , entLoc , teamsA . get ( i ) ) ) ;
}
}
//B
{
//Positions
double space = 6 ;
double offset = ( teamsB . size ( ) - 1 ) * space / 2d ;
for ( int i = 0 ; i < teamsB . size ( ) ; i + + )
{
Location entLoc = _kitDisplay . clone ( ) . subtract ( 0 , 0 , i * space - offset ) ;
SetKitTeamBlocks ( entLoc . clone ( ) , 35 , teamsB . get ( i ) . GetColorData ( ) , _teamBlocks ) ;
entLoc . add ( 0 , 1 . 5 , 0 ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
entLoc . getChunk ( ) . load ( ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
Sheep ent = ( Sheep ) Manager . GetCreature ( ) . SpawnEntity ( entLoc , EntityType . SHEEP ) ;
ent . setRemoveWhenFarAway ( false ) ;
ent . setCustomNameVisible ( true ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
ent . setColor ( DyeColor . getByWoolData ( teamsB . get ( i ) . GetColorData ( ) ) ) ;
2013-08-27 17:14:08 +02:00
2013-09-09 10:06:44 +02:00
UtilEnt . Vegetate ( ent ) ;
teamsB . get ( i ) . SetTeamEntity ( ent ) ;
_teams . put ( ent , new LobbyEnt ( ent , entLoc , teamsB . get ( i ) ) ) ;
}
}
2013-08-27 17:14:08 +02:00
}
CreateScoreboards ( ) ;
}
public void CreateKits ( Game game )
{
//Text
WriteKitLine ( " Select " , 0 , 159 , ( byte ) 15 ) ;
WriteKitLine ( " Kit " , 1 , 159 , ( byte ) 4 ) ;
//Remove Old Ents
for ( Entity ent : _kits . keySet ( ) )
ent . remove ( ) ;
_kits . clear ( ) ;
//Remove Blocks
for ( Block block : _kitBlocks . keySet ( ) )
block . setType ( _kitBlocks . get ( block ) ) ;
_kitBlocks . clear ( ) ;
2014-08-14 02:45:38 +02:00
2013-09-11 04:22:55 +02:00
if ( game . GetKits ( ) . length < = 1 & & game . GetType ( ) = = GameType . UHC )
2013-09-09 10:06:44 +02:00
{
WriteKitLine ( " " , 0 , 159 , ( byte ) 15 ) ;
WriteKitLine ( " " , 1 , 159 , ( byte ) 4 ) ;
return ;
}
2013-08-27 17:14:08 +02:00
//Display
ArrayList < Kit > kits = new ArrayList < Kit > ( ) ;
for ( Kit kit : game . GetKits ( ) )
{
if ( kit . GetAvailability ( ) ! = KitAvailability . Hide )
kits . add ( kit ) ;
}
2014-08-04 07:31:46 +02:00
2014-08-14 02:45:38 +02:00
// Break up the kits into chunks with respect to Null Kits
ArrayList < List < Kit > > kitChunks = new ArrayList < List < Kit > > ( ) ;
int lastBreak = 0 ;
for ( int i = 0 ; i < kits . size ( ) ; i + + )
{
if ( i = = kits . size ( ) - 1 | | kits . get ( i ) . GetAvailability ( ) = = KitAvailability . Null )
{
kitChunks . add ( kits . subList ( lastBreak , i + 1 ) ) ;
lastBreak = i + 1 ;
}
}
// Sort each kit chunk
for ( List < Kit > kitList : kitChunks )
Collections . sort ( kitList , new KitSorter ( ) ) ;
// Create the new sorted list
kits = new ArrayList < Kit > ( ) ;
for ( List < Kit > kitList : kitChunks )
{
kits . addAll ( kitList ) ;
}
2013-09-16 03:52:27 +02:00
//Smash
2014-04-23 02:21:01 +02:00
if ( game . GetType ( ) = = GameType . Smash | | game . GetType ( ) = = GameType . SurvivalGames )
2013-09-14 01:34:05 +02:00
{
2014-08-14 02:56:47 +02:00
// WriteKitLine("Free", 0, 159, (byte)15);
// WriteKitLine("Kits", 1, 159, (byte)4);
2013-09-14 01:34:05 +02:00
ArrayList < Kit > kitsA = new ArrayList < Kit > ( ) ;
ArrayList < Kit > kitsB = new ArrayList < Kit > ( ) ;
for ( int i = 0 ; i < kits . size ( ) ; i + + )
{
2014-08-04 07:31:46 +02:00
if ( kits . get ( i ) . GetCost ( ) < 5000 ) kitsA . add ( kits . get ( i ) ) ;
else kitsB . add ( kits . get ( i ) ) ;
2013-09-14 01:34:05 +02:00
}
{
//Positions
double space = 4 ;
double offset = ( kitsA . size ( ) - 1 ) * space / 2d ;
for ( int i = 0 ; i < kitsA . size ( ) ; i + + )
{
Kit kit = kitsA . get ( i ) ;
if ( kit . GetAvailability ( ) = = KitAvailability . Null )
continue ;
Location entLoc = _kitDisplay . clone ( ) . subtract ( 0 , 0 , i * space - offset ) ;
byte data = 4 ;
2014-10-24 10:05:57 +02:00
if ( kit . GetAvailability ( ) = = KitAvailability . Gem ) data = 5 ;
else if ( kit . GetAvailability ( ) = = KitAvailability . Achievement ) data = 2 ;
2013-09-14 01:34:05 +02:00
SetKitTeamBlocks ( entLoc . clone ( ) , 35 , data , _kitBlocks ) ;
entLoc . add ( 0 , 1 . 5 , 0 ) ;
entLoc . getChunk ( ) . load ( ) ;
Entity ent = kit . SpawnEntity ( entLoc ) ;
if ( ent = = null )
continue ;
_kits . put ( ent , new LobbyEnt ( ent , entLoc , kit ) ) ;
}
}
{
//Positions
double space = 4 ;
double offset = ( kitsB . size ( ) - 1 ) * space / 2d ;
for ( int i = 0 ; i < kitsB . size ( ) ; i + + )
{
Kit kit = kitsB . get ( i ) ;
if ( kit . GetAvailability ( ) = = KitAvailability . Null )
continue ;
Location entLoc = _teamDisplay . clone ( ) . subtract ( 0 , 0 , i * space - offset ) ;
byte data = 4 ;
2014-10-24 10:05:57 +02:00
if ( kit . GetAvailability ( ) = = KitAvailability . Gem ) data = 5 ;
else if ( kit . GetAvailability ( ) = = KitAvailability . Achievement ) data = 2 ;
2013-09-14 01:34:05 +02:00
SetKitTeamBlocks ( entLoc . clone ( ) , 35 , data , _kitBlocks ) ;
entLoc . add ( 0 , 1 . 5 , 0 ) ;
entLoc . getChunk ( ) . load ( ) ;
Entity ent = kit . SpawnEntity ( entLoc ) ;
if ( ent = = null )
continue ;
_kits . put ( ent , new LobbyEnt ( ent , entLoc , kit ) ) ;
}
}
return ;
}
2013-08-27 17:14:08 +02:00
//Positions
double space = 4 ;
double offset = ( kits . size ( ) - 1 ) * space / 2d ;
for ( int i = 0 ; i < kits . size ( ) ; i + + )
{
Kit kit = kits . get ( i ) ;
if ( kit . GetAvailability ( ) = = KitAvailability . Null )
continue ;
Location entLoc = _kitDisplay . clone ( ) . subtract ( 0 , 0 , i * space - offset ) ;
byte data = 4 ;
2014-10-24 10:05:57 +02:00
if ( kit . GetAvailability ( ) = = KitAvailability . Gem ) data = 5 ;
else if ( kit . GetAvailability ( ) = = KitAvailability . Achievement ) data = 2 ;
2013-08-27 17:14:08 +02:00
SetKitTeamBlocks ( entLoc . clone ( ) , 35 , data , _kitBlocks ) ;
entLoc . add ( 0 , 1 . 5 , 0 ) ;
entLoc . getChunk ( ) . load ( ) ;
2013-08-31 01:37:21 +02:00
Entity ent = kit . SpawnEntity ( entLoc ) ;
2013-08-27 17:14:08 +02:00
if ( ent = = null )
continue ;
_kits . put ( ent , new LobbyEnt ( ent , entLoc , kit ) ) ;
}
}
2013-08-31 01:37:21 +02:00
public void SetKitTeamBlocks ( Location loc , int id , byte data , NautHashMap < Block , Material > blockMap )
2013-08-27 17:14:08 +02:00
{
//Coloring
Block block = loc . clone ( ) . add ( 0 . 5 , 0 , 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , id , data ) ;
block = loc . clone ( ) . add ( - 0 . 5 , 0 , 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , id , data ) ;
block = loc . clone ( ) . add ( 0 . 5 , 0 , - 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , id , data ) ;
block = loc . clone ( ) . add ( - 0 . 5 , 0 , - 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , id , data ) ;
//Top
block = loc . clone ( ) . add ( 0 . 5 , 1 , 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , 44 , ( byte ) 5 ) ;
block = loc . clone ( ) . add ( - 0 . 5 , 1 , 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , 44 , ( byte ) 5 ) ;
block = loc . clone ( ) . add ( 0 . 5 , 1 , - 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , 44 , ( byte ) 5 ) ;
block = loc . clone ( ) . add ( - 0 . 5 , 1 , - 0 . 5 ) . getBlock ( ) ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , 44 , ( byte ) 5 ) ;
//Floor
for ( int x = - 2 ; x < 2 ; x + + )
{
for ( int z = - 2 ; z < 2 ; z + + )
{
2013-09-14 01:34:05 +02:00
block = loc . clone ( ) . add ( x + 0 . 5 , - 1 , z + 0 . 5 ) . getBlock ( ) ;
2013-08-27 17:14:08 +02:00
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , id , data ) ;
}
}
//Outline
for ( int x = - 3 ; x < 3 ; x + + )
{
for ( int z = - 3 ; z < 3 ; z + + )
{
2013-09-14 01:34:05 +02:00
block = loc . clone ( ) . add ( x + 0 . 5 , - 1 , z + 0 . 5 ) . getBlock ( ) ;
2013-08-27 17:14:08 +02:00
if ( blockMap . containsKey ( block ) )
continue ;
blockMap . put ( block , block . getType ( ) ) ;
MapUtil . QuickChangeBlockAt ( block . getLocation ( ) , 35 , ( byte ) 15 ) ;
}
}
}
2013-11-08 23:48:40 +01:00
public void AddKitLocation ( Entity ent , Kit kit , Location loc )
{
_kits . put ( ent , new LobbyEnt ( ent , loc , kit ) ) ;
}
2013-08-27 17:14:08 +02:00
@EventHandler
public void PlayerQuit ( PlayerQuitEvent event )
{
_scoreboardMap . remove ( event . getPlayer ( ) ) ;
_gemMap . remove ( event . getPlayer ( ) ) ;
_kitMap . remove ( event . getPlayer ( ) ) ;
}
2014-04-19 06:50:14 +02:00
@EventHandler ( priority = EventPriority . LOWEST )
public void DamageCancel ( CustomDamageEvent event )
{
if ( _kits . containsKey ( event . GetDamageeEntity ( ) ) )
event . SetCancelled ( " Kit Cancel " ) ;
}
2013-08-27 17:14:08 +02:00
@EventHandler
public void Update ( UpdateEvent event )
{
if ( event . getType ( ) = = UpdateType . FAST )
{
spawn . getWorld ( ) . setTime ( 6000 ) ;
spawn . getWorld ( ) . setStorm ( false ) ;
spawn . getWorld ( ) . setThundering ( false ) ;
}
if ( event . getType ( ) = = UpdateType . TICK )
UpdateEnts ( ) ;
if ( event . getType ( ) = = UpdateType . FASTEST )
UpdateFirework ( ) ;
if ( event . getType ( ) = = UpdateType . SLOW )
UpdateAdvertise ( ) ;
ScoreboardDisplay ( event ) ;
ScoreboardSet ( event ) ;
}
2014-08-09 11:55:05 +02:00
@EventHandler
private void RemoveInvalidEnts ( GameStateChangeEvent event )
2013-08-27 17:14:08 +02:00
{
2014-08-09 11:55:05 +02:00
if ( event . GetState ( ) ! = GameState . Recruit )
return ;
2013-08-27 17:14:08 +02:00
for ( Entity ent : UtilWorld . getWorld ( " world " ) . getEntities ( ) )
{
2013-08-31 01:37:21 +02:00
if ( ent instanceof Creature | | ent instanceof Slime )
2013-08-27 17:14:08 +02:00
{
if ( _kits . containsKey ( ent ) )
continue ;
if ( _teams . containsKey ( ent ) )
continue ;
2013-09-04 03:55:19 +02:00
if ( ent . getPassenger ( ) ! = null )
continue ;
2013-08-27 17:14:08 +02:00
ent . remove ( ) ;
}
}
}
private void UpdateAdvertise ( )
{
2014-05-05 03:29:19 +02:00
if ( Manager . GetGame ( ) = = null | | Manager . GetGame ( ) . GetState ( ) ! = GameState . Recruit )
2013-08-27 17:14:08 +02:00
return ;
2013-09-09 10:06:44 +02:00
_advertiseStage = ( _advertiseStage + 1 ) % 2 ;
if ( Manager . GetGame ( ) . AdvertiseText ( this , _advertiseStage ) )
{
return ;
}
2013-08-27 17:14:08 +02:00
if ( _advertiseStage = = 0 )
{
2014-08-08 08:51:11 +02:00
WriteAdvertiseLine ( " GET MINEPLEX ULTRA " , 0 , 159 , ( byte ) 4 ) ;
WriteAdvertiseLine ( " FOR AMAZING " , 1 , 159 , ( byte ) 15 ) ;
WriteAdvertiseLine ( " FUN TIMES " , 2 , 159 , ( byte ) 15 ) ;
2013-08-27 17:14:08 +02:00
WriteAdvertiseLine ( " www.mineplex.com " , 4 , 159 , ( byte ) 15 ) ;
}
else if ( _advertiseStage = = 1 )
{
2014-04-06 04:45:52 +02:00
WriteAdvertiseLine ( " KEEP CALM " , 0 , 159 , ( byte ) 4 ) ;
WriteAdvertiseLine ( " AND " , 1 , 159 , ( byte ) 15 ) ;
2014-04-11 07:33:31 +02:00
WriteAdvertiseLine ( " PLAY MINEPLEX " , 2 , 159 , ( byte ) 4 ) ;
2013-08-27 17:14:08 +02:00
WriteAdvertiseLine ( " www.mineplex.com " , 4 , 159 , ( byte ) 15 ) ;
}
}
public void UpdateEnts ( )
{
for ( Entity ent : _kits . keySet ( ) )
ent . teleport ( _kits . get ( ent ) . GetLocation ( ) ) ;
for ( Entity ent : _teams . keySet ( ) )
ent . teleport ( _teams . get ( ent ) . GetLocation ( ) ) ;
}
public Kit GetClickedKit ( Entity clicked )
{
for ( LobbyEnt ent : _kits . values ( ) )
if ( clicked . equals ( ent . GetEnt ( ) ) )
return ent . GetKit ( ) ;
return null ;
}
public GameTeam GetClickedTeam ( Entity clicked )
{
for ( LobbyEnt ent : _teams . values ( ) )
if ( clicked . equals ( ent . GetEnt ( ) ) )
return ent . GetTeam ( ) ;
return null ;
}
2014-05-04 21:52:04 +02:00
public void RegisterFireworks ( GameTeam winnerTeam )
2013-08-27 17:14:08 +02:00
{
if ( winnerTeam ! = null )
{
_fireworkColor = Color . GREEN ;
if ( winnerTeam . GetColor ( ) = = ChatColor . RED ) _fireworkColor = Color . RED ;
if ( winnerTeam . GetColor ( ) = = ChatColor . AQUA ) _fireworkColor = Color . BLUE ;
if ( winnerTeam . GetColor ( ) = = ChatColor . YELLOW ) _fireworkColor = Color . YELLOW ;
_fireworkStart = System . currentTimeMillis ( ) ;
}
}
public void UpdateFirework ( )
{
if ( UtilTime . elapsed ( _fireworkStart , 10000 ) )
return ;
2014-10-25 02:03:45 +02:00
UtilFirework . playFirework ( spawn . clone ( ) . add ( Math . random ( ) * 160 - 80 , 30 + Math . random ( ) * 10 , Math . random ( ) * 160 - 80 ) ,
Type . BALL_LARGE , _fireworkColor , false , false ) ;
2013-08-27 17:14:08 +02:00
}
@EventHandler
public void Combust ( EntityCombustEvent event )
{
for ( LobbyEnt ent : _kits . values ( ) )
if ( event . getEntity ( ) . equals ( ent . GetEnt ( ) ) )
{
event . setCancelled ( true ) ;
return ;
}
}
public void DisplayLast ( Game game )
{
//Start Fireworks
RegisterFireworks ( game . WinnerTeam ) ;
}
public void DisplayNext ( Game game , HashMap < String , ChatColor > pastTeams )
{
2014-04-11 07:33:31 +02:00
WriteGameLine ( game . GetType ( ) . GetLobbyName ( ) , 0 , 159 , ( byte ) 14 ) ;
if ( game . GetMode ( ) = = null )
WriteGameLine ( " " , 1 , 159 , ( byte ) 14 ) ;
else
2014-06-19 09:48:04 +02:00
WriteGameLine ( game . GetMode ( ) , 1 , 159 , ( byte ) 14 ) ;
2013-10-08 08:56:57 +02:00
2013-08-27 17:14:08 +02:00
DisplayWaiting ( ) ;
CreateKits ( game ) ;
CreateTeams ( game ) ;
}
public void DisplayWaiting ( )
{
WriteGameLine ( " waiting for players " , 3 , 159 , ( byte ) 13 ) ;
}
@EventHandler
public void ScoreboardDisplay ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . FAST )
return ;
if ( Manager . GetGame ( ) ! = null & &
( Manager . GetGame ( ) . GetState ( ) ! = GameState . Loading & &
Manager . GetGame ( ) . GetState ( ) ! = GameState . Recruit ) )
2013-09-09 10:06:44 +02:00
{
2013-08-27 17:14:08 +02:00
for ( Player player : UtilServer . getPlayers ( ) )
2014-06-10 04:51:47 +02:00
player . setScoreboard ( Manager . GetGame ( ) . GetScoreboard ( ) . GetScoreboard ( ) ) ;
2013-09-09 10:06:44 +02:00
}
2013-08-27 17:14:08 +02:00
else
{
for ( Player player : UtilServer . getPlayers ( ) )
{
if ( ! HasScoreboard ( player ) )
{
2014-06-19 09:48:04 +02:00
CreateScoreboard ( player , true ) ;
2013-08-27 17:14:08 +02:00
}
else
{
player . setScoreboard ( _scoreboardMap . get ( player ) ) ;
}
}
}
}
@EventHandler
public void ScoreboardSet ( UpdateEvent event )
{
if ( event . getType ( ) ! = UpdateType . FAST )
return ;
2013-09-09 10:06:44 +02:00
if ( Manager . GetGame ( ) ! = null & & ! Manager . GetGame ( ) . DisplayLobbySide )
2013-08-27 17:14:08 +02:00
{
2013-09-09 10:06:44 +02:00
return ;
}
for ( Entry < Player , Scoreboard > entry : _scoreboardMap . entrySet ( ) )
{
2014-05-26 01:42:39 +02:00
Objective objective = entry . getValue ( ) . getObjective ( " §l " + " Lobby " ) ;
2013-08-27 17:14:08 +02:00
if ( Manager . GetGame ( ) ! = null & & Manager . GetGame ( ) . GetCountdown ( ) > = 0 )
{
if ( Manager . GetGame ( ) . GetCountdown ( ) > 0 )
2014-05-26 01:42:39 +02:00
objective . setDisplayName ( C . Bold + " §lStarting in " + C . cGreen + " §l " + Manager . GetGame ( ) . GetCountdown ( ) + ( Manager . GetGame ( ) . GetCountdown ( ) = = 1 ? " Second " : " Seconds " ) ) ;
2013-08-27 17:14:08 +02:00
else if ( Manager . GetGame ( ) . GetCountdown ( ) = = 0 )
2014-05-26 01:42:39 +02:00
objective . setDisplayName ( ChatColor . WHITE + " §lIn Progress... " ) ;
2013-08-27 17:14:08 +02:00
}
else
{
2014-05-26 01:42:39 +02:00
objective . setDisplayName ( ChatColor . GREEN + " §l " + " Waiting for Players " ) ;
2013-08-27 17:14:08 +02:00
}
2014-07-02 22:09:47 +02:00
int line = 15 ;
2013-08-27 17:14:08 +02:00
2014-07-02 21:50:04 +02:00
objective . getScore ( " " ) . setScore ( line - - ) ;
2014-12-29 22:50:37 +01:00
objective . getScore ( C . cYellow + C . Bold + " Players " ) . setScore ( line - - ) ;
2013-08-27 17:14:08 +02:00
2014-12-23 06:54:51 +01:00
// Remove Old
2014-12-23 07:06:30 +01:00
entry . getValue ( ) . resetScores ( _oldPlayerCount + " / " + _oldMaxPlayerCount ) ;
2013-08-27 17:14:08 +02:00
// Set new
2014-05-06 18:06:39 +02:00
objective . getScore ( UtilServer . getPlayers ( ) . length + " / " + Manager . GetPlayerFull ( ) ) . setScore ( line - - ) ;
2013-08-27 17:14:08 +02:00
if ( Manager . GetGame ( ) ! = null )
{
ChatColor teamColor = ChatColor . GRAY ;
String kitName = " None " ;
if ( Manager . GetGame ( ) . GetTeam ( entry . getKey ( ) ) ! = null )
{
teamColor = Manager . GetGame ( ) . GetTeam ( entry . getKey ( ) ) . GetColor ( ) ;
}
if ( Manager . GetGame ( ) . GetKit ( entry . getKey ( ) ) ! = null )
{
kitName = Manager . GetGame ( ) . GetKit ( entry . getKey ( ) ) . GetName ( ) + " " ;
}
if ( teamColor = = null )
//Shorten Kit Name
if ( kitName . length ( ) > 16 )
kitName = kitName . substring ( 0 , 16 ) ;
// Remove old
2014-04-25 09:44:14 +02:00
entry . getValue ( ) . resetScores ( C . cGray + C . Bold + " Kit " ) ;
entry . getValue ( ) . resetScores ( _kitMap . get ( entry . getKey ( ) ) + " " ) ;
2013-08-27 17:14:08 +02:00
// Set new
2014-04-25 09:44:14 +02:00
objective . getScore ( " " ) . setScore ( line - - ) ;
objective . getScore ( teamColor + C . Bold + " Kit " ) . setScore ( line - - ) ;
objective . getScore ( kitName + " " ) . setScore ( line - - ) ;
2013-08-27 17:14:08 +02:00
_kitMap . put ( entry . getKey ( ) , kitName + " " ) ;
}
2014-04-25 09:44:14 +02:00
objective . getScore ( " " ) . setScore ( line - - ) ;
objective . getScore ( C . cGreen + C . Bold + " Gems " ) . setScore ( line - - ) ;
2013-08-27 17:14:08 +02:00
// Remove old
2014-04-25 09:44:14 +02:00
entry . getValue ( ) . resetScores ( _gemMap . get ( entry . getKey ( ) ) + " " ) ;
2013-08-27 17:14:08 +02:00
// Set new
2014-04-25 09:44:14 +02:00
objective . getScore ( Manager . GetDonation ( ) . Get ( entry . getKey ( ) . getName ( ) ) . GetGems ( ) + " " ) . setScore ( line - - ) ;
2013-08-27 17:14:08 +02:00
_gemMap . put ( entry . getKey ( ) , Manager . GetDonation ( ) . Get ( entry . getKey ( ) . getName ( ) ) . GetGems ( ) ) ;
2014-05-05 07:40:44 +02:00
2014-12-29 22:50:37 +01:00
//Server
objective . getScore ( " " ) . setScore ( line - - ) ;
objective . getScore ( C . cAqua + C . Bold + " Server " ) . setScore ( line - - ) ;
objective . getScore ( Manager . GetPlugin ( ) . getConfig ( ) . getString ( " serverstatus.name " ) ) . setScore ( line - - ) ;
//ELO
2014-05-06 18:06:39 +02:00
if ( Manager . GetGame ( ) ! = null & & Manager . GetGame ( ) . EloRanking )
{
objective . getScore ( " " ) . setScore ( line - - ) ;
2014-12-29 22:50:37 +01:00
objective . getScore ( C . cPurple + C . Bold + " Elo " ) . setScore ( line - - ) ;
2014-05-06 18:06:39 +02:00
// Remove old
entry . getValue ( ) . resetScores ( _eloMap . get ( entry . getKey ( ) ) + " " ) ;
// Set new
objective . getScore ( Manager . getEloManager ( ) . getElo ( entry . getKey ( ) . getUniqueId ( ) , Manager . GetGame ( ) . GetName ( ) ) + " " ) . setScore ( line - - ) ;
}
2013-08-27 17:14:08 +02:00
}
_oldPlayerCount = UtilServer . getPlayers ( ) . length ;
2014-12-23 07:06:30 +01:00
_oldMaxPlayerCount = Manager . GetPlayerFull ( ) ;
2013-08-27 17:14:08 +02:00
}
private String GetKitCustomName ( Player player , Game game , LobbyEnt ent )
{
CoreClient client = Manager . GetClients ( ) . Get ( player ) ;
Donor donor = Manager . GetDonation ( ) . Get ( player . getName ( ) ) ;
String entityName = ent . GetKit ( ) . GetName ( ) ;
2013-10-10 18:01:48 +02:00
if ( ! player . isOnline ( ) | | client = = null | | donor = = null )
return entityName ;
if ( client . GetRank ( ) = = null )
{
System . out . println ( " client rank is null " ) ;
}
if ( game = = null )
{
System . out . println ( " game is null " ) ;
}
if ( Manager = = null )
{
System . out . println ( " Manager is null " ) ;
}
if ( Manager . GetServerConfig ( ) = = null )
{
System . out . println ( " Manager.GetServerConfig() is null " ) ;
}
2014-08-01 06:05:53 +02:00
if ( ent . GetKit ( ) . GetAvailability ( ) = = KitAvailability . Free | | //Free
2014-10-24 10:05:57 +02:00
Manager . isYoutuber ( player ) | | //YouTube
( ent . GetKit ( ) . GetAvailability ( ) = = KitAvailability . Achievement & &
Manager . GetAchievement ( ) . hasCategory ( player , ent . GetKit ( ) . getAchievementRequirement ( ) ) ) | | //Achievement
2014-08-09 15:10:40 +02:00
donor . OwnsUnknownPackage ( Manager . GetGame ( ) . GetName ( ) + " " + ent . GetKit ( ) . GetName ( ) ) | | //Green
2014-12-18 02:45:45 +01:00
Manager . GetClients ( ) . Get ( player ) . GetRank ( ) . Has ( Rank . MAPDEV ) | | //STAFF
2014-11-07 13:10:33 +01:00
donor . OwnsUnknownPackage ( Manager . GetServerConfig ( ) . ServerType + " ULTRA " ) | | //Single Ultra (Old)
2014-08-21 05:35:31 +02:00
Manager . GetServerConfig ( ) . Tournament ) //Tournament
2013-08-27 17:14:08 +02:00
{
2013-11-15 08:52:46 +01:00
entityName = ent . GetKit ( ) . GetAvailability ( ) . GetColor ( ) + entityName ;
2013-08-27 17:14:08 +02:00
}
2014-10-24 10:05:57 +02:00
else if ( ent . GetKit ( ) . GetAvailability ( ) = = KitAvailability . Achievement )
{
entityName = ChatColor . RED + C . Bold + entityName ;
entityName + = ChatColor . RESET + " ( " + C . cPurple + " Achievement Kit " + ChatColor . RESET + " ) " ;
}
2013-08-27 17:14:08 +02:00
else
{
2013-11-15 08:52:46 +01:00
entityName = ChatColor . RED + C . Bold + entityName ;
2014-08-04 06:31:55 +02:00
entityName + = ChatColor . RESET + " ( " + C . cGreen + ent . GetKit ( ) . GetCost ( ) + " Gems " + ChatColor . RESET + " ) " ;
2013-08-27 17:14:08 +02:00
}
return entityName ;
}
2014-10-25 02:36:22 +02:00
@EventHandler
public void customEntityName ( CustomTagEvent event )
{
// TODO: This needs to be changed when removing CustomTagFix
if ( Manager . GetGame ( ) ! = null )
{
String customName = null ;
for ( LobbyEnt ent : _kits . values ( ) )
{
if ( ent . GetEnt ( ) . getEntityId ( ) = = event . getEntityId ( ) )
{
customName = GetKitCustomName ( event . getPlayer ( ) , Manager . GetGame ( ) , ent ) ;
break ;
}
}
if ( customName ! = null )
{
event . setCustomName ( customName ) ;
}
}
}
2013-08-27 17:14:08 +02:00
@SuppressWarnings ( " unchecked " )
2014-09-12 22:03:33 +02:00
public void handle ( PacketInfo packetInfo )
2013-08-27 17:14:08 +02:00
{
2014-10-25 02:36:22 +02:00
// This only applies to 1.7 clients currently, 1.8 custom names are handled by customEntityName(CustomTagEvent event)
if ( _handlingPacket | | UtilPlayer . is1_8 ( packetInfo . getPlayer ( ) ) )
2014-09-05 13:36:01 +02:00
return ;
2014-10-19 04:15:53 +02:00
2014-09-12 22:03:33 +02:00
Packet packet = packetInfo . getPacket ( ) ;
Player owner = packetInfo . getPlayer ( ) ;
PacketVerifier packetVerifier = packetInfo . getVerifier ( ) ;
2014-10-25 02:36:22 +02:00
2013-08-27 17:14:08 +02:00
int entityId = - 1 ;
2014-10-25 02:36:22 +02:00
if ( packet instanceof PacketPlayOutEntityMetadata )
2013-08-27 17:14:08 +02:00
{
2014-10-25 02:36:22 +02:00
entityId = ( ( PacketPlayOutEntityMetadata ) packet ) . a ;
2013-08-27 17:14:08 +02:00
}
if ( entityId ! = - 1 )
{
String customName = null ;
// Order important (_next and _prev overlap if games are same and will throw NPE on _game.GetName())
for ( LobbyEnt ent : _kits . values ( ) )
{
if ( ent . GetEnt ( ) . getEntityId ( ) = = entityId & & Manager . GetGame ( ) ! = null )
{
customName = GetKitCustomName ( owner , Manager . GetGame ( ) , ent ) ;
break ;
}
}
if ( customName ! = null )
{
try
{
2014-10-25 02:36:22 +02:00
if ( packet instanceof PacketPlayOutEntityMetadata )
2013-08-27 17:14:08 +02:00
{
2014-10-25 02:36:22 +02:00
List < WatchableObject > watchables = new ArrayList < WatchableObject > ( ) ;
for ( WatchableObject watchableObject : ( List < WatchableObject > ) ( ( PacketPlayOutEntityMetadata ) packet ) . b )
{
WatchableObject newWatch = new WatchableObject ( watchableObject . c ( ) , watchableObject . a ( ) , watchableObject . b ( ) ) ;
if ( newWatch . a ( ) = = 10 )
{
newWatch . a ( customName ) ;
}
watchables . add ( newWatch ) ;
}
PacketPlayOutEntityMetadata newPacket = new PacketPlayOutEntityMetadata ( ) ;
newPacket . a = entityId ;
newPacket . b = watchables ;
_handlingPacket = true ;
packetVerifier . process ( newPacket ) ;
_handlingPacket = false ;
packetInfo . setCancelled ( true ) ;
2013-08-27 17:14:08 +02:00
}
2014-10-19 04:15:53 +02:00
}
2013-08-27 17:14:08 +02:00
catch ( IllegalArgumentException e )
{
e . printStackTrace ( ) ;
2014-10-25 02:36:22 +02:00
}
2013-08-27 17:14:08 +02:00
}
}
}
public void AddPlayerToScoreboards ( Player player , String teamName )
2014-06-19 09:48:04 +02:00
{
2013-08-27 17:14:08 +02:00
if ( teamName = = null )
teamName = " " ;
2014-06-19 09:48:04 +02:00
String rankName = Manager . GetClients ( ) . Get ( player ) . GetRank ( ) . Name ;
boolean rankIsUltra = ! Manager . GetClients ( ) . Get ( player ) . GetRank ( ) . Has ( Rank . ULTRA ) & & Manager . GetDonation ( ) . Get ( player . getName ( ) ) . OwnsUnknownPackage ( Manager . GetServerConfig ( ) . ServerType + " ULTRA " ) ;
if ( rankIsUltra )
{
rankName = Rank . ULTRA . Name ;
}
teamName = rankName + teamName ;
2014-08-08 01:44:27 +02:00
2013-08-27 17:14:08 +02:00
for ( Scoreboard scoreboard : GetScoreboards ( ) )
{
2013-09-21 05:34:14 +02:00
try
{
2014-06-19 09:48:04 +02:00
scoreboard . getTeam ( teamName ) . addPlayer ( player ) ;
2013-09-21 05:34:14 +02:00
}
catch ( Exception e )
{
System . out . println ( " GameLobbyManager AddPlayerToScoreboard Error " ) ;
System . out . println ( " [ " + rankName + teamName + " ] adding [ " + player . getName ( ) + " ] " ) ;
System . out . println ( " Team is Null [ " + ( scoreboard . getTeam ( rankName + teamName ) = = null ) + " ] " ) ;
}
2013-08-27 17:14:08 +02:00
}
}
2014-08-08 09:05:11 +02:00
2014-08-09 05:10:02 +02:00
@EventHandler
2014-08-09 11:55:05 +02:00
public void disallowInventoryClick ( InventoryClickEvent event )
2014-08-09 05:10:02 +02:00
{
if ( Manager . GetGame ( ) = = null )
return ;
if ( Manager . GetGame ( ) . GetState ( ) ! = GameState . Recruit )
return ;
2014-08-09 11:55:05 +02:00
if ( event . getInventory ( ) . getType ( ) = = InventoryType . CRAFTING )
{
event . setCancelled ( true ) ;
event . getWhoClicked ( ) . closeInventory ( ) ;
}
2014-08-09 05:10:02 +02:00
}
2014-08-08 09:05:11 +02:00
@EventHandler
2014-08-09 11:55:05 +02:00
public void InventoryUpdate ( UpdateEvent event )
2014-08-08 09:05:11 +02:00
{
2014-08-30 08:33:56 +02:00
if ( ! Manager . IsHotbarInventory ( ) )
2014-08-08 09:05:11 +02:00
return ;
2014-08-11 03:55:00 +02:00
if ( event . getType ( ) ! = UpdateType . FAST )
2014-08-10 02:50:31 +02:00
return ;
2014-08-08 09:05:11 +02:00
if ( Manager . GetGame ( ) = = null )
return ;
2014-08-10 02:50:31 +02:00
2014-08-08 09:05:11 +02:00
if ( Manager . GetGame ( ) . GetState ( ) ! = GameState . Recruit )
return ;
for ( Player player : UtilServer . getPlayers ( ) )
{
2014-08-10 02:50:31 +02:00
if ( player . getOpenInventory ( ) . getType ( ) ! = InventoryType . CRAFTING )
continue ;
2014-08-09 11:55:05 +02:00
//Cosmetic Menu
Manager . getCosmeticManager ( ) . giveInterfaceItem ( player ) ;
2014-08-08 09:05:11 +02:00
}
}
@EventHandler ( priority = EventPriority . LOWEST )
2014-08-26 09:33:48 +02:00
public void GemBoosterInteract ( ActivateGemBoosterEvent event )
2014-08-08 09:05:11 +02:00
{
2014-08-30 08:33:56 +02:00
if ( ! Manager . IsHotbarInventory ( ) | | Manager . GetGame ( ) = = null | | Manager . GetGame ( ) . GetState ( ) ! = GameState . Recruit )
2014-08-26 09:33:48 +02:00
{
event . setCancelled ( true ) ;
event . getPlayer ( ) . sendMessage ( F . main ( " Arcade " , " You can't use Gem Boosters right now. " ) ) ;
2014-08-09 05:10:02 +02:00
return ;
2014-08-26 09:33:48 +02:00
}
2014-08-09 05:10:02 +02:00
2014-08-26 09:33:48 +02:00
Manager . GetGame ( ) . AddGemBooster ( event . getPlayer ( ) ) ;
2014-08-08 09:05:11 +02:00
}
2014-08-09 14:59:54 +02:00
@EventHandler ( priority = EventPriority . LOWEST )
2014-08-10 03:07:05 +02:00
public void explodeBlockBreakFix ( EntityExplodeEvent event )
2014-08-09 14:59:54 +02:00
{
if ( Manager . GetGame ( ) = = null )
return ;
2014-08-10 03:07:05 +02:00
if ( Manager . GetGame ( ) . GetState ( ) = = GameState . Live )
2014-08-09 14:59:54 +02:00
return ;
event . blockList ( ) . clear ( ) ;
}
2014-08-11 03:55:00 +02:00
@EventHandler ( priority = EventPriority . LOWEST )
public void velocityEventCancel ( PlayerVelocityEvent event )
{
if ( Manager . GetGame ( ) = = null )
return ;
if ( Manager . GetGame ( ) . GetState ( ) = = GameState . Live )
return ;
event . setCancelled ( true ) ;
}
2013-08-27 17:14:08 +02:00
}