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
import com.gmail.nossr50.config.Config ;
import com.gmail.nossr50.locale.LocaleLoader ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.metrics.MetricsManager ;
import com.gmail.nossr50.util.player.UserManager ;
import com.gmail.nossr50.util.skills.SkillUtils ;
2013-02-15 16:36:14 +01:00
public final class ChimaeraWing {
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-14 22:13:23 +01:00
Location location = player . getLocation ( ) ;
2013-02-15 16:36:14 +01:00
int amount = inHand . getAmount ( ) ;
2013-03-08 21:46:05 +01:00
long recentlyHurt = UserManager . getPlayer ( player ) . getRecentlyHurt ( ) ;
long lastChimaeraWing = ( UserManager . getPlayer ( player ) . getLastChimaeraTeleport ( ) ) ;
if ( Permissions . chimaeraWing ( player ) & & ItemUtils . isChimaeraWing ( inHand ) ) {
if ( ! SkillUtils . cooldownOver ( lastChimaeraWing * 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 ( lastChimaeraWing * Misc . TIME_CONVERSION_FACTOR , Config . getInstance ( ) . getChimaeraCooldown ( ) , player ) + " ) " ) ; //TODO Locale!
return ;
}
2013-02-15 16:36:14 +01:00
2013-03-14 22:24:38 +01:00
if ( ! SkillUtils . cooldownOver ( recentlyHurt * Misc . TIME_CONVERSION_FACTOR , 60 , player ) ) {
player . sendMessage ( LocaleLoader . getString ( " Item.Injured.Wait " , SkillUtils . calculateTimeLeft ( recentlyHurt * Misc . TIME_CONVERSION_FACTOR , 60 , player ) ) ) ;
return ;
}
if ( amount < = Config . getInstance ( ) . getChimaeraUseCost ( ) ) {
player . sendMessage ( LocaleLoader . getString ( " Skills.NeedMore " , " Chimaera Wings " ) ) ; //TODO Locale!
return ;
}
player . setItemInHand ( new ItemStack ( getChimaeraWing ( amount - Config . getInstance ( ) . getChimaeraUseCost ( ) ) ) ) ;
2013-02-15 16:36:14 +01:00
2013-03-14 22:24:38 +01:00
if ( Config . getInstance ( ) . getChimaeraPreventUseUnderground ( ) ) {
2013-03-14 22:13:23 +01:00
2013-03-14 22:24:38 +01:00
if ( location . getY ( ) < player . getWorld ( ) . getHighestBlockYAt ( location ) ) {
player . sendMessage ( LocaleLoader . getString ( " Item.ChimaeraWing.Fail " ) ) ;
player . setVelocity ( new Vector ( 0 , 0 . 5D , 0 ) ) ;
UserManager . getPlayer ( player ) . actualizeLastChimaeraTeleport ( ) ;
return ;
2013-02-15 16:36:14 +01:00
}
2013-03-14 22:24:38 +01:00
}
2013-02-15 16:36:14 +01:00
2013-03-14 22:24:38 +01:00
if ( player . getBedSpawnLocation ( ) ! = null ) {
player . teleport ( player . getBedSpawnLocation ( ) ) ;
}
else {
Location spawnLocation = player . getWorld ( ) . getSpawnLocation ( ) ;
if ( spawnLocation . getBlock ( ) . getType ( ) = = Material . AIR ) {
player . teleport ( spawnLocation ) ;
2013-02-15 16:36:14 +01:00
}
else {
2013-03-14 22:24:38 +01:00
player . teleport ( player . getWorld ( ) . getHighestBlockAt ( spawnLocation ) . getLocation ( ) ) ;
2013-02-15 16:36:14 +01:00
}
}
2013-03-14 22:24:38 +01:00
UserManager . getPlayer ( player ) . actualizeLastChimaeraTeleport ( ) ;
MetricsManager . chimeraWingUsed ( ) ;
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 ) {
ItemStack itemStack = new ItemStack ( Material . FEATHER , amount ) ;
ItemMeta itemMeta = itemStack . getItemMeta ( ) ;
itemMeta . setDisplayName ( ChatColor . GOLD + " Chimaera Wing " ) ; //TODO Locale!
List < String > itemLore = new ArrayList < String > ( ) ;
itemLore . add ( " mcMMO Item " ) ;
itemLore . add ( ChatColor . GRAY + " Teleports you to your bed. " ) ; //TODO Locale!
itemMeta . setLore ( itemLore ) ;
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
}