mcMMO/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java

63 lines
2.7 KiB
Java
Raw Normal View History

2012-04-27 11:47:11 +02: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.datatypes.PlayerProfile;
2012-06-05 16:13:10 +02:00
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
2012-04-27 11:47:11 +02:00
2013-01-26 23:01:55 +01:00
public final class ChimaeraWing {
private ChimaeraWing() {}
2012-04-27 11:47:11 +02:00
/**
* Check for item usage.
*
* @param player Player whose item usage to check
*/
2013-01-26 23:01:55 +01:00
public static void activationCheck(Player player) {
ItemStack inHand = player.getItemInHand();
2012-04-27 11:47:11 +02:00
2013-01-26 23:01:55 +01:00
if (!Config.getInstance().getChimaeraEnabled() || inHand.getTypeId() != Config.getInstance().getChimaeraItemId()) {
return;
2012-04-27 11:47:11 +02:00
}
PlayerProfile profile = Users.getPlayer(player).getProfile();
2012-04-27 11:47:11 +02:00
Block block = player.getLocation().getBlock();
int amount = inHand.getAmount();
2013-01-16 15:08:45 +01:00
long recentlyHurt = profile.getRecentlyHurt();
2012-04-27 11:47:11 +02:00
2013-01-07 02:52:31 +01:00
if (Permissions.chimaeraWing(player) && inHand.getTypeId() == Config.getInstance().getChimaeraItemId()) {
2013-01-26 23:01:55 +01:00
if (SkillTools.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
2012-04-27 11:47:11 +02:00
player.setItemInHand(new ItemStack(Config.getInstance().getChimaeraItemId(), amount - Config.getInstance().getChimaeraCost()));
for (int y = 1; block.getY() + y < player.getWorld().getMaxHeight(); y++) {
2012-04-27 11:47:11 +02:00
if (!block.getRelative(0, y, 0).getType().equals(Material.AIR)) {
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
player.teleport(block.getRelative(0, y - 1, 0).getLocation());
return;
}
}
if (player.getBedSpawnLocation() != null && player.getBedSpawnLocation().getBlock().getType().equals(Material.BED_BLOCK)) {
player.teleport(player.getBedSpawnLocation());
}
else {
player.teleport(player.getWorld().getSpawnLocation());
}
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass"));
}
2013-01-26 23:01:55 +01:00
else if (!SkillTools.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillTools.calculateTimeLeft(recentlyHurt, 60, player)));
2012-04-27 11:47:11 +02:00
}
else if (amount <= Config.getInstance().getChimaeraCost()) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", Misc.prettyItemString(Config.getInstance().getChimaeraItemId())));
2012-04-27 11:47:11 +02:00
}
}
}
}