mcMMO/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java

133 lines
4.5 KiB
Java
Raw Normal View History

2013-01-23 22:34:01 +01:00
package com.gmail.nossr50.skills.smelting;
2013-02-28 00:28:20 +01:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
2013-01-23 22:34:01 +01:00
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.FurnaceBurnEvent;
2013-02-28 00:28:20 +01:00
import org.bukkit.inventory.ItemStack;
2013-01-23 22:34:01 +01:00
2013-02-28 00:28:20 +01:00
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
2013-02-28 00:28:20 +01:00
import com.gmail.nossr50.locale.LocaleLoader;
2013-01-23 22:34:01 +01:00
import com.gmail.nossr50.skills.SkillManager;
2013-02-28 00:28:20 +01:00
import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.smelting.Smelting.Tier;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
2013-02-28 00:28:20 +01:00
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.ItemChecks;
2013-01-23 22:34:01 +01:00
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class SmeltingManager extends SkillManager {
public SmeltingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.SMELTING);
2013-01-23 22:34:01 +01:00
}
2013-02-28 00:28:20 +01:00
public boolean canUseFluxMining(BlockState blockState) {
Player player = getPlayer();
ItemStack heldItem = player.getItemInHand();
return BlockChecks.affectedByFluxMining(blockState) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(blockState);
}
public boolean canUseVanillaXpBoost() {
Player player = getPlayer();
return SkillTools.unlockLevelReached(player, skill, Smelting.Tier.ONE.getLevel()) && Permissions.vanillaXpBoost(player, skill);
}
2013-01-23 22:34:01 +01:00
/**
2013-02-28 00:28:20 +01:00
* Process the Flux Mining ability.
2013-01-23 22:34:01 +01:00
*
2013-02-28 00:28:20 +01:00
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
2013-01-23 22:34:01 +01:00
*/
2013-02-28 00:28:20 +01:00
public boolean processFluxMining(BlockState blockState) {
Player player = getPlayer();
2013-02-28 00:28:20 +01:00
if (SkillTools.unlockLevelReached(player, skill, Smelting.fluxMiningUnlockLevel) && SkillTools.activationSuccessful(player, skill, Smelting.fluxMiningChance)) {
ItemStack item = null;
2013-01-23 22:34:01 +01:00
2013-02-28 00:28:20 +01:00
switch (blockState.getType()) {
case IRON_ORE:
item = new ItemStack(Material.IRON_INGOT);
break;
2013-01-23 22:34:01 +01:00
2013-02-28 00:28:20 +01:00
case GOLD_ORE:
item = new ItemStack(Material.GOLD_INGOT);
break;
2013-02-28 00:28:20 +01:00
default:
break;
}
2013-01-23 22:34:01 +01:00
2013-02-28 00:28:20 +01:00
if (item == null) {
return false;
}
2013-01-23 22:34:01 +01:00
2013-02-28 00:28:20 +01:00
Location location = blockState.getLocation();
2013-01-23 22:34:01 +01:00
2013-02-28 00:28:20 +01:00
Misc.dropItem(location, item);
if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Mining.doubleDropsMaxChance, Mining.doubleDropsMaxLevel)) {
Misc.dropItem(location, item);
}
blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR);
player.sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
return true;
2013-01-23 22:34:01 +01:00
}
2013-02-28 00:28:20 +01:00
return false;
}
/**
* Increases burn time for furnace fuel.
*
* @param burnTime The initial burn time from the {@link FurnaceBurnEvent}
*/
public int fuelEfficiency(int burnTime) {
double burnModifier = 1 + (((double) getSkillLevel() / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier);
return (int) (burnTime * burnModifier);
}
2013-02-28 23:32:36 +01:00
public ItemStack smeltProcessing(Material resourceType, ItemStack result) {
2013-02-28 00:28:20 +01:00
Player player = getPlayer();
2013-01-23 22:34:01 +01:00
2013-02-28 00:28:20 +01:00
applyXpGain(Smelting.getResourceXp(resourceType));
if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Smelting.secondSmeltMaxChance, Smelting.secondSmeltMaxLevel)) {
2013-02-28 23:32:36 +01:00
ItemStack newResult = new ItemStack(result.getType(), result.getAmount() + 1);
return newResult;
2013-01-23 22:34:01 +01:00
}
2013-02-28 23:32:36 +01:00
return result;
2013-01-23 22:34:01 +01:00
}
2013-02-28 00:28:20 +01:00
public int vanillaXPBoost(int experience) {
return experience * getVanillaXpMultiplier();
}
/**
* Gets the vanilla XP multiplier
*
* @return the vanilla XP multiplier
*/
protected int getVanillaXpMultiplier() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getVanillaXPBoostModifier();
}
2013-01-23 22:34:01 +01:00
}
2013-02-28 00:28:20 +01:00
return 0;
2013-01-23 22:34:01 +01:00
}
}