2013-02-15 16:36:14 +01:00
package com.gmail.nossr50.util ;
2013-03-08 21:46:05 +01:00
import java.util.ArrayList ;
import java.util.List ;
import org.bukkit.ChatColor ;
2013-03-14 22:13:23 +01:00
import org.bukkit.Location ;
2013-02-15 16:36:14 +01:00
import org.bukkit.Material ;
2013-03-14 22:13:23 +01:00
import org.bukkit.Sound ;
2013-02-15 16:36:14 +01:00
import org.bukkit.entity.Player ;
import org.bukkit.inventory.ItemStack ;
2013-03-08 21:46:05 +01:00
import org.bukkit.inventory.ShapelessRecipe ;
import org.bukkit.inventory.meta.ItemMeta ;
2013-03-14 22:13:23 +01:00
import org.bukkit.util.Vector ;
2013-02-15 16:36:14 +01:00
2013-03-22 00:38:15 +01:00
import com.gmail.nossr50.mcMMO ;
2013-02-15 16:36:14 +01:00
import com.gmail.nossr50.config.Config ;
2013-03-22 00:38:15 +01:00
import com.gmail.nossr50.datatypes.player.McMMOPlayer ;
2013-02-15 16:36:14 +01:00
import com.gmail.nossr50.locale.LocaleLoader ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.metrics.MetricsManager ;
2013-03-22 00:38:15 +01:00
import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.util.player.UserManager ;
2013-03-14 22:31:44 +01:00
import com.gmail.nossr50.util.skills.CombatUtils ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.util.skills.SkillUtils ;
2013-02-15 16:36:14 +01:00
public final class ChimaeraWing {
2013-03-22 00:38:15 +01:00
private static McMMOPlayer mcMMOPlayer ;
private static Location location ;
2013-02-15 16:36:14 +01:00
private ChimaeraWing ( ) { }
/ * *
* Check for item usage .
*
* @param player Player whose item usage to check
* /
public static void activationCheck ( Player player ) {
ItemStack inHand = player . getItemInHand ( ) ;
2013-03-08 21:46:05 +01:00
if ( ! Config . getInstance ( ) . getChimaeraEnabled ( ) | | ! ItemUtils . isChimaeraWing ( inHand ) ) {
2013-02-15 16:36:14 +01:00
return ;
}
2013-03-22 00:38:15 +01:00
mcMMOPlayer = UserManager . getPlayer ( player ) ;
location = player . getLocation ( ) ;
2013-02-15 16:36:14 +01:00
int amount = inHand . getAmount ( ) ;
2013-03-22 00:38:15 +01:00
long recentlyHurt = mcMMOPlayer . getRecentlyHurt ( ) ;
2013-04-10 17:08:27 +02:00
long lastTeleport = mcMMOPlayer . getLastTeleport ( ) ;
2013-03-08 21:46:05 +01:00
if ( Permissions . chimaeraWing ( player ) & & ItemUtils . isChimaeraWing ( inHand ) ) {
2013-04-10 16:05:10 +02:00
if ( mcMMOPlayer . getTeleportCommenceLocation ( ) ! = null ) {
2013-03-22 00:38:15 +01:00
return ;
}
2013-04-10 17:08:27 +02:00
if ( Config . getInstance ( ) . getChimaeraCooldown ( ) > 0 & & ! SkillUtils . cooldownOver ( lastTeleport * Misc . TIME_CONVERSION_FACTOR , Config . getInstance ( ) . getChimaeraCooldown ( ) , player ) ) {
player . sendMessage ( ChatColor . RED + " You need to wait before you can use this again! " + ChatColor . YELLOW + " ( " + SkillUtils . calculateTimeLeft ( lastTeleport * Misc . TIME_CONVERSION_FACTOR , Config . getInstance ( ) . getChimaeraCooldown ( ) , player ) + " ) " ) ; //TODO Locale!
2013-03-08 21:46:05 +01:00
return ;
}
2013-02-15 16:36:14 +01:00
2013-04-10 17:08:27 +02:00
int recentlyhurt_cooldown = Config . getInstance ( ) . getChimaeraRecentlyHurtCooldown ( ) ;
if ( ! SkillUtils . cooldownOver ( recentlyHurt * Misc . TIME_CONVERSION_FACTOR , recentlyhurt_cooldown , player ) ) {
player . sendMessage ( LocaleLoader . getString ( " Item.Injured.Wait " , SkillUtils . calculateTimeLeft ( recentlyHurt * Misc . TIME_CONVERSION_FACTOR , recentlyhurt_cooldown , player ) ) ) ;
2013-03-14 22:24:38 +01:00
return ;
}
2013-03-16 11:42:38 +01:00
if ( amount < Config . getInstance ( ) . getChimaeraUseCost ( ) ) {
2013-03-14 22:24:38 +01:00
player . sendMessage ( LocaleLoader . getString ( " Skills.NeedMore " , " Chimaera Wings " ) ) ; //TODO Locale!
return ;
}
if ( Config . getInstance ( ) . getChimaeraPreventUseUnderground ( ) ) {
if ( location . getY ( ) < player . getWorld ( ) . getHighestBlockYAt ( location ) ) {
2013-03-22 00:38:15 +01:00
player . setItemInHand ( new ItemStack ( getChimaeraWing ( amount - Config . getInstance ( ) . getChimaeraUseCost ( ) ) ) ) ;
2013-03-14 22:24:38 +01:00
player . sendMessage ( LocaleLoader . getString ( " Item.ChimaeraWing.Fail " ) ) ;
player . setVelocity ( new Vector ( 0 , 0 . 5D , 0 ) ) ;
2013-03-14 22:31:44 +01:00
CombatUtils . dealDamage ( player , Misc . getRandom ( ) . nextInt ( player . getHealth ( ) - 10 ) ) ;
2013-04-10 16:05:10 +02:00
mcMMOPlayer . actualizeLastTeleport ( ) ;
2013-03-14 22:24:38 +01:00
return ;
2013-02-15 16:36:14 +01:00
}
2013-03-14 22:24:38 +01:00
}
2013-04-04 15:59:10 +02:00
2013-04-10 16:05:10 +02:00
mcMMOPlayer . actualizeTeleportCommenceLocation ( player ) ;
2013-02-15 16:36:14 +01:00
2013-03-22 00:38:15 +01:00
long warmup = Config . getInstance ( ) . getChimaeraWarmup ( ) ;
2013-04-04 15:59:10 +02:00
if ( warmup > 0 ) {
player . sendMessage ( ChatColor . GRAY + " Commencing teleport in " + ChatColor . GOLD + " ( " + warmup + " ) " + ChatColor . GRAY + " seconds, please stand still... " ) ; //TODO Locale!
new ChimaeraWingWarmup ( mcMMOPlayer ) . runTaskLater ( mcMMO . p , 20 * warmup ) ;
}
else {
chimaeraExecuteTeleport ( ) ;
}
2013-03-22 00:38:15 +01:00
}
}
public static void chimaeraExecuteTeleport ( ) {
Player player = mcMMOPlayer . getPlayer ( ) ;
if ( player . getBedSpawnLocation ( ) ! = null ) {
player . teleport ( player . getBedSpawnLocation ( ) ) ;
}
else {
Location spawnLocation = player . getWorld ( ) . getSpawnLocation ( ) ;
if ( spawnLocation . getBlock ( ) . getType ( ) = = Material . AIR ) {
player . teleport ( spawnLocation ) ;
2013-03-14 22:24:38 +01:00
}
else {
2013-03-22 00:38:15 +01:00
player . teleport ( player . getWorld ( ) . getHighestBlockAt ( spawnLocation ) . getLocation ( ) ) ;
2013-02-15 16:36:14 +01:00
}
}
2013-03-22 00:38:15 +01:00
player . setItemInHand ( new ItemStack ( getChimaeraWing ( player . getItemInHand ( ) . getAmount ( ) - Config . getInstance ( ) . getChimaeraUseCost ( ) ) ) ) ;
2013-04-10 16:05:10 +02:00
UserManager . getPlayer ( player ) . actualizeLastTeleport ( ) ;
2013-04-04 15:48:48 +02:00
if ( Config . getInstance ( ) . getStatsTrackingEnabled ( ) ) {
MetricsManager . chimeraWingUsed ( ) ;
}
2013-03-22 00:38:15 +01:00
player . playSound ( location , Sound . BAT_TAKEOFF , Misc . BAT_VOLUME , Misc . BAT_PITCH ) ;
player . sendMessage ( LocaleLoader . getString ( " Item.ChimaeraWing.Pass " ) ) ;
2013-02-15 16:36:14 +01:00
}
2013-03-08 21:46:05 +01:00
public static ItemStack getChimaeraWing ( int amount ) {
2013-04-04 21:35:09 +02:00
Material ingredient = Material . getMaterial ( Config . getInstance ( ) . getChimaeraItemId ( ) ) ;
ItemStack itemStack = new ItemStack ( ingredient , amount ) ;
2013-03-08 21:46:05 +01:00
ItemMeta itemMeta = itemStack . getItemMeta ( ) ;
itemMeta . setDisplayName ( ChatColor . GOLD + " Chimaera Wing " ) ; //TODO Locale!
2013-04-04 21:35:09 +02:00
2013-03-08 21:46:05 +01:00
List < String > itemLore = new ArrayList < String > ( ) ;
itemLore . add ( " mcMMO Item " ) ;
itemLore . add ( ChatColor . GRAY + " Teleports you to your bed. " ) ; //TODO Locale!
itemMeta . setLore ( itemLore ) ;
2013-04-04 21:35:09 +02:00
2013-03-08 21:46:05 +01:00
itemStack . setItemMeta ( itemMeta ) ;
return itemStack ;
}
public static ShapelessRecipe getChimaeraWingRecipe ( ) {
Material ingredient = Material . getMaterial ( Config . getInstance ( ) . getChimaeraItemId ( ) ) ;
int amount = Config . getInstance ( ) . getChimaeraRecipeCost ( ) ;
if ( amount > 9 ) {
amount = 9 ;
}
ShapelessRecipe ChimaeraWing = new ShapelessRecipe ( getChimaeraWing ( 1 ) ) ;
ChimaeraWing . addIngredient ( amount , ingredient ) ;
return ChimaeraWing ;
}
2013-02-15 16:36:14 +01:00
}