2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.managers ;
import java.util.ArrayList ;
2014-08-04 05:44:01 +02:00
import mineplex.core.common.CurrencyType ;
import mineplex.core.common.Rank ;
import mineplex.core.common.util.C ;
import mineplex.core.common.util.F ;
import mineplex.core.common.util.UtilPlayer ;
2015-08-30 23:13:08 +02:00
import mineplex.core.common.util.UtilServer ;
2014-10-09 01:35:54 +02:00
import mineplex.core.common.util.UtilTabTitle ;
2014-08-04 05:44:01 +02:00
import mineplex.core.donation.Donor ;
2014-09-21 01:26:34 +02:00
import mineplex.core.recharge.Recharge ;
2014-08-04 05:44:01 +02:00
import mineplex.core.shop.page.ConfirmationPage ;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent ;
import mineplex.minecraft.game.core.damage.CustomDamageEvent ;
import nautilus.game.arcade.ArcadeManager ;
2015-03-16 05:01:35 +01:00
import nautilus.game.arcade.GameType ;
2015-08-30 23:13:08 +02:00
import nautilus.game.arcade.events.PlayerKitApplyEvent ;
2014-09-21 01:26:34 +02:00
import nautilus.game.arcade.events.PlayerStateChangeEvent ;
2014-08-04 05:44:01 +02:00
import nautilus.game.arcade.game.Game ;
import nautilus.game.arcade.game.Game.GameState ;
import nautilus.game.arcade.game.GameTeam ;
import nautilus.game.arcade.kit.Kit ;
import nautilus.game.arcade.kit.KitAvailability ;
import nautilus.game.arcade.shop.ArcadeShop ;
import nautilus.game.arcade.shop.KitPackage ;
2015-10-13 08:49:15 +02:00
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata ;
2014-08-04 05:44:01 +02:00
2015-08-25 02:40:34 +02:00
import org.bukkit.ChatColor ;
import org.bukkit.Location ;
import org.bukkit.Sound ;
2015-10-13 08:49:15 +02:00
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity ;
2015-08-25 02:40:34 +02:00
import org.bukkit.entity.Entity ;
import org.bukkit.entity.LivingEntity ;
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
import org.bukkit.event.Listener ;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause ;
import org.bukkit.event.inventory.InventoryClickEvent ;
import org.bukkit.event.inventory.InventoryType ;
import org.bukkit.event.player.PlayerCommandPreprocessEvent ;
import org.bukkit.event.player.PlayerInteractEntityEvent ;
import org.bukkit.event.player.PlayerJoinEvent ;
import org.bukkit.event.player.PlayerRespawnEvent ;
2013-08-27 17:14:08 +02:00
public class GamePlayerManager implements Listener
{
ArcadeManager Manager ;
2014-05-03 03:23:10 +02:00
2013-08-27 17:14:08 +02:00
public GamePlayerManager ( ArcadeManager manager )
{
Manager = manager ;
2014-05-03 03:23:10 +02:00
2015-02-26 06:07:07 +01:00
Manager . getPluginManager ( ) . registerEvents ( this , Manager . getPlugin ( ) ) ;
2013-08-27 17:14:08 +02:00
}
2014-05-03 03:23:10 +02:00
2013-08-27 17:14:08 +02:00
@EventHandler ( priority = EventPriority . HIGH )
public void PlayerDeath ( CombatDeathEvent event )
{
//Don't actually die
2015-08-25 02:40:34 +02:00
event . GetEvent ( ) . getEntity ( ) . setHealth ( event . GetEvent ( ) . getEntity ( ) . getMaxHealth ( ) ) ;
2013-08-27 17:14:08 +02:00
//Dont display message
2013-09-09 10:06:44 +02:00
if ( Manager . GetGame ( ) ! = null )
event . SetBroadcastType ( Manager . GetGame ( ) . GetDeathMessageType ( ) ) ;
2014-05-03 03:23:10 +02:00
2013-08-27 17:14:08 +02:00
//Colors
if ( event . GetLog ( ) . GetKiller ( ) ! = null )
{
Player player = UtilPlayer . searchExact ( event . GetLog ( ) . GetKiller ( ) . GetName ( ) ) ;
if ( player ! = null )
event . GetLog ( ) . SetKillerColor ( Manager . GetColor ( player ) + " " ) ;
}
if ( event . GetEvent ( ) . getEntity ( ) instanceof Player )
{
Player player = ( Player ) event . GetEvent ( ) . getEntity ( ) ;
if ( player ! = null )
event . GetLog ( ) . SetKilledColor ( Manager . GetColor ( player ) + " " ) ;
}
}
@EventHandler
public void PlayerJoin ( PlayerJoinEvent event )
{
final Player player = event . getPlayer ( ) ;
2014-05-03 03:23:10 +02:00
2014-10-09 01:35:54 +02:00
//Player List
UtilTabTitle . setHeaderAndFooter ( player ,
Manager . GetGame ( ) ! = null ? C . cGold + C . Bold + Manager . GetGame ( ) . GetType ( ) . GetName ( ) : " " ,
" Visit " + C . cGreen + " www.mineplex.com " + ChatColor . RESET + " for News, Forums and Shop " ) ;
2013-08-27 17:14:08 +02:00
//Lobby Name
Manager . GetLobby ( ) . AddPlayerToScoreboards ( player , null ) ;
//Lobby Spawn
if ( Manager . GetGame ( ) = = null | | ! Manager . GetGame ( ) . InProgress ( ) )
{
2013-09-09 10:06:44 +02:00
Manager . Clear ( player ) ;
2013-08-27 17:14:08 +02:00
player . teleport ( Manager . GetLobby ( ) . GetSpawn ( ) ) ;
return ;
}
//Game Spawn
if ( Manager . GetGame ( ) . IsAlive ( player ) )
{
2013-09-09 10:06:44 +02:00
Location loc = Manager . GetGame ( ) . GetLocationStore ( ) . remove ( player . getName ( ) ) ;
if ( loc ! = null & & ! loc . getWorld ( ) . getName ( ) . equalsIgnoreCase ( " world " ) )
{
player . teleport ( loc ) ;
}
else
{
Manager . Clear ( player ) ;
player . teleport ( Manager . GetGame ( ) . GetTeam ( player ) . GetSpawn ( ) ) ;
}
2013-08-27 17:14:08 +02:00
}
else
{
2013-09-09 10:06:44 +02:00
Manager . Clear ( player ) ;
2015-03-12 05:31:40 +01:00
Manager . addSpectator ( player , true ) ;
2013-08-27 17:14:08 +02:00
UtilPlayer . message ( player , F . main ( " Game " , Manager . GetGame ( ) . GetName ( ) + " is in progress, please wait for next game! " ) ) ;
}
2014-06-10 04:51:47 +02:00
player . setScoreboard ( Manager . GetGame ( ) . GetScoreboard ( ) . GetScoreboard ( ) ) ;
2013-08-27 17:14:08 +02:00
}
@EventHandler
public void PlayerRespawn ( PlayerRespawnEvent event )
{
if ( Manager . GetGame ( ) = = null | | ! Manager . GetGame ( ) . InProgress ( ) )
{
event . setRespawnLocation ( Manager . GetLobby ( ) . GetSpawn ( ) ) ;
return ;
}
Player player = event . getPlayer ( ) ;
if ( Manager . GetGame ( ) . IsAlive ( player ) )
{
event . setRespawnLocation ( Manager . GetGame ( ) . GetTeam ( player ) . GetSpawn ( ) ) ;
}
else
{
2015-03-12 05:31:40 +01:00
Manager . addSpectator ( player , true ) ;
2013-08-27 17:14:08 +02:00
event . setRespawnLocation ( Manager . GetGame ( ) . GetSpectatorLocation ( ) ) ;
}
}
2014-07-26 09:03:03 +02:00
2014-09-21 01:26:34 +02:00
@EventHandler
public void PlayerStateChange ( PlayerStateChangeEvent event )
{
Recharge . Instance . useForce ( event . GetPlayer ( ) , " Return to Hub " , 4000 ) ;
}
2014-07-26 09:03:03 +02:00
@EventHandler
2014-11-15 12:40:56 +01:00
public void DisallowCreativeClick ( InventoryClickEvent event )
2014-07-26 09:03:03 +02:00
{
2015-05-01 01:20:35 +02:00
if ( Manager . GetGame ( ) = = null | | ! Manager . GetGame ( ) . InProgress ( ) | | Manager . GetGameHostManager ( ) . isEventServer ( ) | | Manager . GetGame ( ) . GetType ( ) = = GameType . Build )
2014-07-26 09:03:03 +02:00
return ;
2014-11-15 12:40:56 +01:00
if ( ( event . getInventory ( ) . getType ( ) = = InventoryType . CREATIVE | | event . getInventory ( ) . getType ( ) = = InventoryType . PLAYER ) & & ! event . getWhoClicked ( ) . isOp ( ) )
2014-07-26 09:03:03 +02:00
{
event . setCancelled ( true ) ;
2014-11-15 12:29:53 +01:00
event . getWhoClicked ( ) . closeInventory ( ) ;
2014-07-26 09:03:03 +02:00
}
}
2014-05-03 03:23:10 +02:00
2013-08-27 17:14:08 +02:00
@EventHandler ( priority = EventPriority . HIGH )
public void TeamInteract ( PlayerInteractEntityEvent event )
{
if ( event . getRightClicked ( ) = = null )
return ;
Player player = event . getPlayer ( ) ;
2015-07-23 05:31:07 +02:00
GameTeam team = Manager . GetLobby ( ) . GetClickedTeam ( event . getRightClicked ( ) ) ;
if ( team = = null )
return ;
2014-05-03 03:23:10 +02:00
//Observer
if ( Manager . IsObserver ( player ) )
{
UtilPlayer . message ( player , F . main ( " Game " , " Spectators cannot partake in games. " ) ) ;
return ;
}
2015-07-23 05:31:07 +02:00
2013-08-27 17:14:08 +02:00
TeamClick ( player , team ) ;
}
@EventHandler
public void TeamDamage ( CustomDamageEvent event )
{
Player player = event . GetDamagerPlayer ( false ) ;
if ( player = = null ) return ;
LivingEntity target = event . GetDamageeEntity ( ) ;
GameTeam team = Manager . GetLobby ( ) . GetClickedTeam ( target ) ;
if ( team = = null )
return ;
2015-07-23 05:31:07 +02:00
//Observer
if ( Manager . IsObserver ( player ) )
{
UtilPlayer . message ( player , F . main ( " Game " , " Spectators cannot partake in games. " ) ) ;
return ;
}
2013-08-27 17:14:08 +02:00
TeamClick ( player , team ) ;
}
public void TeamClick ( final Player player , final GameTeam team )
{
if ( Manager . GetGame ( ) = = null )
return ;
if ( Manager . GetGame ( ) . GetState ( ) ! = GameState . Recruit )
return ;
if ( ! Manager . GetGame ( ) . HasTeam ( team ) )
return ;
AddTeamPreference ( Manager . GetGame ( ) , player , team ) ;
}
2014-05-03 03:23:10 +02:00
2013-08-27 17:14:08 +02:00
public void AddTeamPreference ( Game game , Player player , GameTeam team )
{
GameTeam past = game . GetTeamPreference ( player ) ;
GameTeam current = game . GetTeam ( player ) ;
if ( current ! = null & & current . equals ( team ) )
{
game . RemoveTeamPreference ( player ) ;
UtilPlayer . message ( player , F . main ( " Team " , " You are already on " + F . elem ( team . GetFormattedName ( ) ) + " . " ) ) ;
return ;
}
if ( past = = null | | ! past . equals ( team ) )
{
if ( past ! = null )
2013-09-14 12:03:24 +02:00
{
2013-08-27 17:14:08 +02:00
game . RemoveTeamPreference ( player ) ;
2013-09-14 12:03:24 +02:00
}
2013-08-27 17:14:08 +02:00
if ( ! game . GetTeamPreferences ( ) . containsKey ( team ) )
game . GetTeamPreferences ( ) . put ( team , new ArrayList < Player > ( ) ) ;
game . GetTeamPreferences ( ) . get ( team ) . add ( player ) ;
}
2014-06-27 03:38:11 +02:00
UtilPlayer . message ( player , F . main ( " Team " , " You are " + F . elem ( game . GetTeamQueuePosition ( player ) ) + " in queue for " + F . elem ( team . GetFormattedName ( ) + " Team " ) + " . " ) ) ;
2013-08-27 17:14:08 +02:00
}
2014-04-21 02:48:04 +02:00
@EventHandler ( priority = EventPriority . LOWEST )
2013-08-27 17:14:08 +02:00
public void KitInteract ( PlayerInteractEntityEvent event )
{
if ( event . getRightClicked ( ) = = null )
return ;
Player player = event . getPlayer ( ) ;
2014-05-03 03:23:10 +02:00
2015-07-23 05:31:07 +02:00
Kit kit = Manager . GetLobby ( ) . GetClickedKit ( event . getRightClicked ( ) ) ;
if ( kit = = null )
return ;
2014-05-03 03:23:10 +02:00
//Observer
2015-03-12 05:31:40 +01:00
if ( Manager . IsObserver ( player ) | | Manager . isSpectator ( player ) )
2014-05-03 03:23:10 +02:00
{
UtilPlayer . message ( player , F . main ( " Game " , " Spectators cannot partake in games. " ) ) ;
return ;
}
2013-08-27 17:14:08 +02:00
KitClick ( player , kit , event . getRightClicked ( ) ) ;
2014-05-03 03:23:10 +02:00
2014-04-21 02:48:04 +02:00
event . setCancelled ( true ) ;
2013-08-27 17:14:08 +02:00
}
@EventHandler
public void KitDamage ( CustomDamageEvent event )
{
2014-04-19 06:50:14 +02:00
if ( Manager . GetGame ( ) ! = null & & Manager . GetGame ( ) . InProgress ( ) )
return ;
2014-05-03 03:23:10 +02:00
2014-04-08 02:53:41 +02:00
if ( event . GetCause ( ) ! = DamageCause . ENTITY_ATTACK )
return ;
2014-05-03 03:23:10 +02:00
2013-08-27 17:14:08 +02:00
Player player = event . GetDamagerPlayer ( false ) ;
if ( player = = null ) return ;
2014-05-03 03:23:10 +02:00
2015-07-23 05:31:07 +02:00
2014-05-03 03:23:10 +02:00
2013-08-27 17:14:08 +02:00
LivingEntity target = event . GetDamageeEntity ( ) ;
Kit kit = Manager . GetLobby ( ) . GetClickedKit ( target ) ;
if ( kit = = null )
return ;
2015-07-23 05:31:07 +02:00
//Observer
if ( Manager . IsObserver ( player ) | | Manager . isSpectator ( player ) )
{
UtilPlayer . message ( player , F . main ( " Game " , " Spectators cannot partake in games. " ) ) ;
return ;
}
2013-08-27 17:14:08 +02:00
KitClick ( player , kit , target ) ;
}
public void KitClick ( final Player player , final Kit kit , final Entity entity )
{
2015-08-30 23:13:08 +02:00
PlayerKitApplyEvent kitEvent = new PlayerKitApplyEvent ( Manager . GetGame ( ) , kit , player ) ;
UtilServer . getServer ( ) . getPluginManager ( ) . callEvent ( kitEvent ) ;
if ( ! kitEvent . isCancelled ( ) )
{
kit . DisplayDesc ( player ) ;
2014-11-15 09:31:56 +01:00
2015-08-30 23:13:08 +02:00
if ( Manager . GetGame ( ) = = null )
return ;
2014-11-15 09:31:56 +01:00
2015-08-30 23:13:08 +02:00
if ( ! Manager . GetGame ( ) . HasKit ( kit ) )
return ;
2014-11-15 09:31:56 +01:00
2015-08-30 23:13:08 +02:00
Donor donor = Manager . GetDonation ( ) . Get ( player . getName ( ) ) ;
2014-11-15 09:31:56 +01:00
2015-08-30 23:13:08 +02:00
if ( kit . GetAvailability ( ) = = KitAvailability . Free | | //Free
2015-11-07 00:43:11 +01:00
Manager . hasKitsUnlocked ( player ) | | //YouTube
2014-11-15 09:31:56 +01:00
2015-11-07 00:43:11 +01:00
( kit . GetAvailability ( ) = = KitAvailability . Achievement & & //Achievement
Manager . GetAchievement ( ) . hasCategory ( player , kit . getAchievementRequirement ( ) ) ) | |
2015-08-30 23:13:08 +02:00
2015-11-07 00:43:11 +01:00
donor . OwnsUnknownPackage ( Manager . GetGame ( ) . GetType ( ) . GetKitGameName ( ) + " " + kit . GetName ( ) ) | | //Green
2015-08-30 23:13:08 +02:00
2015-11-07 00:43:11 +01:00
Manager . GetClients ( ) . Get ( player ) . GetRank ( ) . has ( Rank . MAPDEV ) | | //STAFF
2014-11-15 09:31:56 +01:00
2015-11-07 00:43:11 +01:00
donor . OwnsUnknownPackage ( Manager . GetServerConfig ( ) . ServerType + " ULTRA " ) | | //Single Ultra (Old)
Manager . GetServerConfig ( ) . Tournament ) //Tournament
2015-02-26 06:07:07 +01:00
{
2015-08-30 23:13:08 +02:00
Manager . GetGame ( ) . SetKit ( player , kit , true ) ;
}
else if ( kit . GetAvailability ( ) = = KitAvailability . Gem & & donor . GetBalance ( CurrencyType . Gems ) > = kit . GetCost ( ) )
{
Manager . GetShop ( ) . openPageForPlayer ( player , new ConfirmationPage < ArcadeManager , ArcadeShop > (
2015-11-07 00:43:11 +01:00
Manager , Manager . GetShop ( ) , Manager . GetClients ( ) , Manager . GetDonation ( ) , new Runnable ( )
2015-08-30 23:13:08 +02:00
{
2015-11-07 00:43:11 +01:00
public void run ( )
2015-08-30 23:13:08 +02:00
{
2015-11-07 00:43:11 +01:00
if ( player . isOnline ( ) )
{
Manager . GetGame ( ) . SetKit ( player , kit , true ) ;
UtilPlayer . sendPacket ( player , new PacketPlayOutEntityMetadata ( entity . getEntityId ( ) , ( ( CraftEntity ) entity ) . getHandle ( ) . getDataWatcher ( ) , true ) ) ;
}
2015-08-30 23:13:08 +02:00
}
2015-11-07 00:43:11 +01:00
} , null , new KitPackage ( Manager . GetGame ( ) . GetType ( ) . GetKitGameName ( ) , kit ) , CurrencyType . Gems , player ) ) ;
2015-08-30 23:13:08 +02:00
}
else if ( kit . GetAvailability ( ) = = KitAvailability . Achievement )
{
UtilPlayer . message ( player , F . main ( " Kit " , " You have not unlocked all " + F . elem ( C . cPurple + Manager . GetGame ( ) . GetName ( ) + " Achievements " ) + " . " ) ) ;
}
else
{
player . playSound ( player . getLocation ( ) , Sound . NOTE_BASS , 2f , 0 . 5f ) ;
UtilPlayer . message ( player , F . main ( " Kit " , " You do not have enough " + F . elem ( C . cGreen + " Gems " ) + " . " ) ) ;
}
2014-10-24 10:05:57 +02:00
}
2013-08-27 17:14:08 +02:00
else
2015-08-30 23:13:08 +02:00
UtilPlayer . message ( player , F . main ( " Game " , kitEvent . getCancelMessage ( ) ) ) ;
2013-08-27 17:14:08 +02:00
}
2014-07-02 22:09:47 +02:00
2014-11-28 00:00:31 +01:00
@EventHandler ( priority = EventPriority . HIGHEST )
2014-07-02 22:09:47 +02:00
public void TeleportCommand ( PlayerCommandPreprocessEvent event )
{
Game game = Manager . GetGame ( ) ;
if ( game = = null )
return ;
Player player = event . getPlayer ( ) ;
2015-08-28 22:22:04 +02:00
if ( Manager . GetClients ( ) . Get ( player ) . GetRank ( ) . has ( Rank . MODERATOR ) )
2014-07-05 08:04:46 +02:00
return ;
2014-11-28 00:00:31 +01:00
if ( event . getMessage ( ) . toLowerCase ( ) . startsWith ( " /tp " ) )
2014-07-02 22:09:47 +02:00
{
2014-11-28 00:00:31 +01:00
UtilPlayer . message ( player , F . main ( " Game " , " Spectate Teleport changed to " + F . elem ( " /spec <name> " ) + " . " ) ) ;
2014-07-02 22:09:47 +02:00
event . setCancelled ( true ) ;
return ;
}
2014-11-28 00:00:31 +01:00
if ( ! event . getMessage ( ) . toLowerCase ( ) . startsWith ( " /spec " ) )
return ;
event . setCancelled ( true ) ;
2015-03-12 05:31:40 +01:00
if ( game . IsAlive ( player ) | | ! Manager . isSpectator ( player ) )
2014-11-28 00:00:31 +01:00
{
UtilPlayer . message ( player , F . main ( " Game " , " Only Spectators can use this command. " ) ) ;
return ;
}
2014-07-02 22:09:47 +02:00
String [ ] tokens = event . getMessage ( ) . split ( " " ) ;
if ( tokens . length ! = 2 )
{
2014-11-28 00:00:31 +01:00
UtilPlayer . message ( player , F . main ( " Game " , " Invalid Input. " + F . elem ( " /spec <Name> " ) + " . " ) ) ;
2014-07-02 22:09:47 +02:00
return ;
}
Player target = UtilPlayer . searchOnline ( player , tokens [ 1 ] , true ) ;
if ( target ! = null )
{
UtilPlayer . message ( player , F . main ( " Game " , " You teleported to " + F . name ( target . getName ( ) ) + " . " ) ) ;
player . teleport ( target ) ;
}
}
2015-11-07 00:43:11 +01:00
}