2013-02-15 16:36:14 +01:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (!Config.getInstance().getChimaeraEnabled() || inHand.getTypeId() != Config.getInstance().getChimaeraItemId()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = player.getLocation().getBlock();
|
|
|
|
int amount = inHand.getAmount();
|
2013-03-03 17:06:05 +01:00
|
|
|
long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt() * Misc.TIME_CONVERSION_FACTOR;
|
2013-02-15 16:36:14 +01:00
|
|
|
|
|
|
|
if (Permissions.chimaeraWing(player) && inHand.getTypeId() == Config.getInstance().getChimaeraItemId()) {
|
2013-03-01 06:52:01 +01:00
|
|
|
if (SkillUtils.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
|
2013-02-15 16:36:14 +01:00
|
|
|
player.setItemInHand(new ItemStack(Config.getInstance().getChimaeraItemId(), amount - Config.getInstance().getChimaeraCost()));
|
|
|
|
|
|
|
|
for (int y = 1; block.getY() + y < player.getWorld().getMaxHeight(); y++) {
|
|
|
|
if (!(block.getRelative(0, y, 0).getType() == Material.AIR)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
|
|
|
|
player.teleport(block.getRelative(0, y - 1, 0).getLocation());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-03 17:03:16 +01:00
|
|
|
if (player.getBedSpawnLocation() != null) {
|
2013-02-15 16:36:14 +01:00
|
|
|
player.teleport(player.getBedSpawnLocation());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.teleport(player.getWorld().getSpawnLocation());
|
|
|
|
}
|
|
|
|
|
2013-02-16 02:59:38 +01:00
|
|
|
MetricsManager.chimeraWingUsed();
|
2013-02-15 16:36:14 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass"));
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
else if (!SkillUtils.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt, 60, player)));
|
2013-02-15 16:36:14 +01:00
|
|
|
}
|
|
|
|
else if (amount <= Config.getInstance().getChimaeraCost()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Config.getInstance().getChimaeraItemId())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|