mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
SmeltingManager cleaning.
This commit is contained in:
parent
c3eaec513b
commit
499411f6a2
@ -1,5 +1,7 @@
|
||||
package com.gmail.nossr50.datatypes;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -12,6 +14,7 @@ import com.gmail.nossr50.mods.datatypes.CustomTool;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.party.ShareHandler;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.skills.utilities.PerksUtils;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
@ -67,10 +70,22 @@ public class McMMOPlayer {
|
||||
* @param xp Experience amount to process
|
||||
*/
|
||||
public void beginXpGain(SkillType skillType, int xp) {
|
||||
if (xp == 0) {
|
||||
if (xp == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (skillType.isChildSkill()) {
|
||||
Set<SkillType> parentSkills = FamilyTree.getParents(skillType);
|
||||
|
||||
for (SkillType parentSkill : parentSkills) {
|
||||
if (Permissions.skillEnabled(player, parentSkill)) {
|
||||
beginXpGain(parentSkill, xp / parentSkills.size());
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Return if the experience has been shared
|
||||
if (party != null && ShareHandler.handleXpShare(xp, this, skillType)) {
|
||||
return;
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -35,7 +34,6 @@ import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.skills.repair.Salvage;
|
||||
import com.gmail.nossr50.skills.smelting.Smelting;
|
||||
import com.gmail.nossr50.skills.unarmed.Unarmed;
|
||||
import com.gmail.nossr50.skills.utilities.AbilityType;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
@ -239,7 +237,6 @@ public class BlockListener implements Listener {
|
||||
|
||||
String playerName = player.getName();
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
if (SkillManagerStore.getInstance().getHerbalismManager(playerName).canUseHylianLuck()) {
|
||||
if (SkillManagerStore.getInstance().getHerbalismManager(playerName).processHylianLuck(blockState)) {
|
||||
@ -247,8 +244,8 @@ public class BlockListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
else if (BlockChecks.affectedByFluxMining(blockState) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(blockState)) {
|
||||
if (Smelting.processFluxMining(blockState, player)) {
|
||||
else if (SkillManagerStore.getInstance().getSmeltingManager(playerName).canUseFluxMining(blockState)) {
|
||||
if (SkillManagerStore.getInstance().getSmeltingManager(playerName).processFluxMining(blockState)) {
|
||||
blockState.update(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.gmail.nossr50.listeners;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -13,15 +13,18 @@ import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.FurnaceInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.skills.SkillManagerStore;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.ItemChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class InventoryListener implements Listener{
|
||||
@ -33,37 +36,47 @@ public class InventoryListener implements Listener{
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
InventoryType inventoryType = event.getInventory().getType();
|
||||
HumanEntity player = event.getPlayer();
|
||||
|
||||
if (inventoryType == InventoryType.FURNACE) {
|
||||
FurnaceInventory inventory = (FurnaceInventory) event.getInventory();
|
||||
Furnace furnace = inventory.getHolder();
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if (inventory instanceof FurnaceInventory) {
|
||||
Furnace furnace = (Furnace) inventory.getHolder();
|
||||
|
||||
if (furnace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block furnaceBlock = furnace.getBlock();
|
||||
BlockState furnaceBlock = furnace.getBlock().getState();
|
||||
|
||||
if (furnace.getBurnTime() == 0 && !plugin.furnaceIsTracked(furnaceBlock)) {
|
||||
plugin.addToOpenFurnaceTracker(furnaceBlock, event.getPlayer().getName());
|
||||
plugin.addToOpenFurnaceTracker(furnaceBlock, player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
InventoryType inventoryType = event.getInventory().getType();
|
||||
HumanEntity player = event.getPlayer();
|
||||
|
||||
if (inventoryType == InventoryType.FURNACE) {
|
||||
FurnaceInventory inventory = (FurnaceInventory) event.getInventory();
|
||||
Furnace furnace = inventory.getHolder();
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if (inventory instanceof FurnaceInventory) {
|
||||
Furnace furnace = (Furnace) inventory.getHolder();
|
||||
|
||||
if (furnace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block furnaceBlock = furnace.getBlock();
|
||||
BlockState furnaceBlock = furnace.getBlock().getState();
|
||||
|
||||
if (furnace.getBurnTime() == 0 && plugin.furnaceIsTracked(furnaceBlock)) {
|
||||
plugin.removeFromFurnaceTracker(furnaceBlock);
|
||||
@ -73,18 +86,20 @@ public class InventoryListener implements Listener{
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
BlockState blockState = furnaceBlock.getState();
|
||||
BlockState furnaceBlock = event.getBlock().getState();
|
||||
|
||||
if (furnaceBlock instanceof Furnace) {
|
||||
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting();
|
||||
|
||||
if (blockState instanceof Furnace) {
|
||||
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
|
||||
ItemStack smelting = inventory.getSmelting();
|
||||
|
||||
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
|
||||
Player player = plugin.getFurnacePlayer(furnaceBlock);
|
||||
|
||||
if (player != null) {
|
||||
SkillManagerStore.getInstance().getSmeltingManager(player.getName()).fuelEfficiency(event);
|
||||
|
||||
if (!Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.fuelEfficiency(player)) {
|
||||
event.setBurnTime(SkillManagerStore.getInstance().getSmeltingManager(player.getName()).fuelEfficiency(event.getBurnTime()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,18 +107,20 @@ public class InventoryListener implements Listener{
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
BlockState blockState = furnaceBlock.getState();
|
||||
BlockState furnaceBlock = event.getBlock().getState();
|
||||
|
||||
if (blockState instanceof Furnace) {
|
||||
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
|
||||
ItemStack smelting = inventory.getSmelting();
|
||||
if (furnaceBlock instanceof Furnace) {
|
||||
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting();
|
||||
|
||||
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
|
||||
Player player = plugin.getFurnacePlayer(furnaceBlock);
|
||||
|
||||
if (player != null) {
|
||||
SkillManagerStore.getInstance().getSmeltingManager(player.getName()).smeltProcessing(event);
|
||||
if (!Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(player, SkillType.SMELTING)) {
|
||||
SkillManagerStore.getInstance().getSmeltingManager(player.getName()).smeltProcessing(event.getSource().getType(), event.getResult());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,18 +128,16 @@ public class InventoryListener implements Listener{
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
BlockState blockState = furnaceBlock.getState();
|
||||
BlockState furnaceBlock = event.getBlock().getState();
|
||||
|
||||
if (blockState instanceof Furnace) {
|
||||
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
|
||||
ItemStack result = inventory.getResult();
|
||||
if (furnaceBlock instanceof Furnace) {
|
||||
ItemStack result = ((Furnace) furnaceBlock).getInventory().getResult();
|
||||
|
||||
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemChecks.isSmelted(result)) {
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(event.getPlayer());
|
||||
|
||||
if (mcMMOPlayer.getPlayer().equals(plugin.getFurnacePlayer(furnaceBlock))) {
|
||||
SkillManagerStore.getInstance().getSmeltingManager(event.getPlayer().getName()).vanillaXPBoost(event);
|
||||
SkillManagerStore.getInstance().getSmeltingManager(event.getPlayer().getName()).vanillaXPBoost(event.getExpToDrop());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import net.shatteredlands.shatt.backup.ZipLibrary;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
@ -66,7 +66,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private final WorldListener worldListener = new WorldListener();
|
||||
|
||||
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
|
||||
private HashMap<Block, String> furnaceTracker = new HashMap<Block, String>();
|
||||
private HashMap<BlockState, String> furnaceTracker = new HashMap<BlockState, String>();
|
||||
|
||||
public static mcMMO p;
|
||||
|
||||
@ -442,19 +442,19 @@ public class mcMMO extends JavaPlugin {
|
||||
tntTracker.remove(tntID);
|
||||
}
|
||||
|
||||
public void addToOpenFurnaceTracker(Block furnace, String playerName) {
|
||||
public void addToOpenFurnaceTracker(BlockState furnace, String playerName) {
|
||||
furnaceTracker.put(furnace, playerName);
|
||||
}
|
||||
|
||||
public boolean furnaceIsTracked(Block furnace) {
|
||||
public boolean furnaceIsTracked(BlockState furnace) {
|
||||
return furnaceTracker.containsKey(furnace);
|
||||
}
|
||||
|
||||
public void removeFromFurnaceTracker(Block furnace) {
|
||||
public void removeFromFurnaceTracker(BlockState furnace) {
|
||||
furnaceTracker.remove(furnace);
|
||||
}
|
||||
|
||||
public Player getFurnacePlayer(Block furnace) {
|
||||
public Player getFurnacePlayer(BlockState furnace) {
|
||||
return getServer().getPlayer(furnaceTracker.get(furnace));
|
||||
}
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import org.bukkit.event.inventory.FurnaceBurnEvent;
|
||||
|
||||
public class FuelEfficiencyEventHandler {
|
||||
private SmeltingManager manager;
|
||||
private FurnaceBurnEvent event;
|
||||
private double burnModifier;
|
||||
|
||||
protected FuelEfficiencyEventHandler(SmeltingManager manager, FurnaceBurnEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
protected void calculateBurnModifier() {
|
||||
this.burnModifier = 1 + (((double) manager.getSkillLevel() / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier);
|
||||
}
|
||||
|
||||
protected void modifyBurnTime() {
|
||||
int burnTime = event.getBurnTime();
|
||||
event.setBurnTime((int)(burnTime * burnModifier));
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public class SmeltResourceEventHandler {
|
||||
private SmeltingManager manager;
|
||||
private FurnaceSmeltEvent event;
|
||||
|
||||
protected int skillModifier;
|
||||
|
||||
protected SmeltResourceEventHandler(SmeltingManager manager, FurnaceSmeltEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
protected void calculateSkillModifier() {
|
||||
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Smelting.secondSmeltMaxLevel);
|
||||
}
|
||||
|
||||
protected void handleXPGain() {
|
||||
Material sourceType = event.getSource().getType();
|
||||
int xp = Config.getInstance().getXp(SkillType.SMELTING, sourceType);
|
||||
|
||||
if (sourceType == Material.GLOWING_REDSTONE_ORE) {
|
||||
xp = Config.getInstance().getXp(SkillType.SMELTING, Material.REDSTONE_ORE);
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
Set<SkillType> parentSkills = FamilyTree.getParents(SkillType.SMELTING);
|
||||
for (SkillType parentSkill : parentSkills) {
|
||||
if (Permissions.skillEnabled(player, parentSkill)) {
|
||||
mcMMOPlayer.beginXpGain(parentSkill, xp / parentSkills.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleBonusSmelts() {
|
||||
ItemStack result = event.getResult();
|
||||
|
||||
result.setAmount(result.getAmount() + 1);
|
||||
event.setResult(result);
|
||||
}
|
||||
}
|
@ -1,20 +1,44 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.mining.Mining;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public class Smelting {
|
||||
// The order of the values is extremely important, a few methods depend on it to work properly
|
||||
protected enum Tier {
|
||||
FIVE(5) {
|
||||
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Level();}
|
||||
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Multiplier();}},
|
||||
FOUR(4) {
|
||||
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Level();}
|
||||
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Multiplier();}},
|
||||
THREE(3) {
|
||||
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Level();}
|
||||
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Multiplier();}},
|
||||
TWO(2) {
|
||||
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Level();}
|
||||
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Multiplier();}},
|
||||
ONE(1) {
|
||||
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();}
|
||||
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Multiplier();}};
|
||||
|
||||
int numerical;
|
||||
|
||||
private Tier(int numerical) {
|
||||
this.numerical = numerical;
|
||||
}
|
||||
|
||||
public int toNumerical() {
|
||||
return numerical;
|
||||
}
|
||||
|
||||
abstract protected int getLevel();
|
||||
abstract protected int getVanillaXPBoostModifier();
|
||||
}
|
||||
|
||||
public static int burnModifierMaxLevel = AdvancedConfig.getInstance().getBurnModifierMaxLevel();
|
||||
public static double burnTimeMultiplier = AdvancedConfig.getInstance().getBurnTimeMultiplier();
|
||||
|
||||
@ -24,60 +48,13 @@ public class Smelting {
|
||||
public static int fluxMiningUnlockLevel = AdvancedConfig.getInstance().getFluxMiningUnlockLevel();
|
||||
public static double fluxMiningChance = AdvancedConfig.getInstance().getFluxMiningChance();
|
||||
|
||||
public static int vanillaXPBoostRank1Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();
|
||||
public static int vanillaXPBoostRank2Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Level();
|
||||
public static int vanillaXPBoostRank3Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Level();
|
||||
public static int vanillaXPBoostRank4Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Level();
|
||||
public static int vanillaXPBoostRank5Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Level();
|
||||
protected static int getResourceXp(Material resourceType) {
|
||||
int xp = Config.getInstance().getXp(SkillType.SMELTING, resourceType);
|
||||
|
||||
public static int vanillaXPBoostRank1Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Multiplier();
|
||||
public static int vanillaXPBoostRank2Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Multiplier();
|
||||
public static int vanillaXPBoostRank3Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Multiplier();
|
||||
public static int vanillaXPBoostRank4Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Multiplier();
|
||||
public static int vanillaXPBoostRank5Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Multiplier();
|
||||
|
||||
/**
|
||||
* Process the Flux Mining ability.
|
||||
*
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @param player The {@link Player} using this ability
|
||||
* @return true if the ability was successful, false otherwise
|
||||
*/
|
||||
public static boolean processFluxMining(BlockState blockState, Player player) {
|
||||
if (SkillTools.unlockLevelReached(player, SkillType.SMELTING, fluxMiningUnlockLevel) && SkillTools.activationSuccessful(player, SkillType.SMELTING, fluxMiningChance)) {
|
||||
ItemStack item = null;
|
||||
|
||||
switch (blockState.getType()) {
|
||||
case IRON_ORE:
|
||||
item = new ItemStack(Material.IRON_INGOT);
|
||||
break;
|
||||
|
||||
case GOLD_ORE:
|
||||
item = new ItemStack(Material.GOLD_INGOT);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Location location = blockState.getLocation();
|
||||
|
||||
Misc.dropItem(location, item);
|
||||
|
||||
if (Permissions.doubleDrops(player, SkillType.SMELTING) && SkillTools.activationSuccessful(player, SkillType.SMELTING, 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;
|
||||
if (resourceType == Material.GLOWING_REDSTONE_ORE) {
|
||||
xp = Config.getInstance().getXp(SkillType.SMELTING, Material.REDSTONE_ORE);
|
||||
}
|
||||
|
||||
return false;
|
||||
return xp;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillCommand;
|
||||
import com.gmail.nossr50.skills.SkillManagerStore;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
@ -11,7 +13,7 @@ public class SmeltingCommand extends SkillCommand {
|
||||
private String secondSmeltChanceLucky;
|
||||
private String fluxMiningChance;
|
||||
private String fluxMiningChanceLucky;
|
||||
private String vanillaXPModifier;
|
||||
private int vanillaXPModifier;
|
||||
|
||||
private boolean canFuelEfficiency;
|
||||
private boolean canSecondSmelt;
|
||||
@ -38,21 +40,7 @@ public class SmeltingCommand extends SkillCommand {
|
||||
fluxMiningChanceLucky = fluxMiningStrings[1];
|
||||
|
||||
//VANILLA XP BOOST
|
||||
if (skillValue >= Smelting.vanillaXPBoostRank5Level) {
|
||||
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank5Multiplier);
|
||||
}
|
||||
else if (skillValue >= Smelting.vanillaXPBoostRank4Level) {
|
||||
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank4Multiplier);
|
||||
}
|
||||
else if (skillValue >= Smelting.vanillaXPBoostRank3Level) {
|
||||
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank3Multiplier);
|
||||
}
|
||||
else if (skillValue >= Smelting.vanillaXPBoostRank2Level) {
|
||||
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank2Multiplier);
|
||||
}
|
||||
else {
|
||||
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank1Multiplier);
|
||||
}
|
||||
vanillaXPModifier = SkillManagerStore.getInstance().getSmeltingManager(player.getName()).getVanillaXpMultiplier();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,8 +98,8 @@ public class SmeltingCommand extends SkillCommand {
|
||||
}
|
||||
|
||||
if (canVanillaXPBoost) {
|
||||
if (skillValue < Smelting.vanillaXPBoostRank1Level) {
|
||||
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", Smelting.vanillaXPBoostRank1Level)));
|
||||
if (skillValue < AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level()) {
|
||||
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level())));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", vanillaXPModifier));
|
||||
|
@ -1,71 +1,129 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.FurnaceBurnEvent;
|
||||
import org.bukkit.event.inventory.FurnaceExtractEvent;
|
||||
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
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;
|
||||
import com.gmail.nossr50.util.BlockChecks;
|
||||
import com.gmail.nossr50.util.ItemChecks;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the Flux Mining ability.
|
||||
*
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @return true if the ability was successful, false otherwise
|
||||
*/
|
||||
public boolean processFluxMining(BlockState blockState) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (SkillTools.unlockLevelReached(player, skill, Smelting.fluxMiningUnlockLevel) && SkillTools.activationSuccessful(player, skill, Smelting.fluxMiningChance)) {
|
||||
ItemStack item = null;
|
||||
|
||||
switch (blockState.getType()) {
|
||||
case IRON_ORE:
|
||||
item = new ItemStack(Material.IRON_INGOT);
|
||||
break;
|
||||
|
||||
case GOLD_ORE:
|
||||
item = new ItemStack(Material.GOLD_INGOT);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Location location = blockState.getLocation();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases burn time for furnace fuel.
|
||||
*
|
||||
* @param event The {@link FurnaceBurnEvent} to modify.
|
||||
* @param burnTime The initial burn time from the {@link FurnaceBurnEvent}
|
||||
*/
|
||||
public void fuelEfficiency(FurnaceBurnEvent event) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
public int fuelEfficiency(int burnTime) {
|
||||
double burnModifier = 1 + (((double) getSkillLevel() / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier);
|
||||
|
||||
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
FuelEfficiencyEventHandler eventHandler = new FuelEfficiencyEventHandler(this, event);
|
||||
eventHandler.calculateBurnModifier();
|
||||
eventHandler.modifyBurnTime();
|
||||
return (int) (burnTime * burnModifier);
|
||||
}
|
||||
|
||||
public void smeltProcessing(FurnaceSmeltEvent event) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
public void smeltProcessing(Material resourceType, ItemStack result) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
applyXpGain(Smelting.getResourceXp(resourceType));
|
||||
|
||||
SmeltResourceEventHandler eventHandler = new SmeltResourceEventHandler(this, event);
|
||||
|
||||
if (Permissions.skillEnabled(player, skill)) {
|
||||
eventHandler.handleXPGain();
|
||||
}
|
||||
|
||||
if (!Permissions.doubleDrops(player, skill)) {
|
||||
return;
|
||||
}
|
||||
|
||||
eventHandler.calculateSkillModifier();
|
||||
|
||||
double chance = (Smelting.secondSmeltMaxChance / Smelting.secondSmeltMaxLevel) * eventHandler.skillModifier;
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
eventHandler.handleBonusSmelts();
|
||||
if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Smelting.secondSmeltMaxChance, Smelting.secondSmeltMaxLevel)) {
|
||||
result.setAmount(result.getAmount() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void vanillaXPBoost(FurnaceExtractEvent event) {
|
||||
if (getSkillLevel() < Smelting.vanillaXPBoostRank1Level || !Permissions.vanillaXpBoost(mcMMOPlayer.getPlayer(), skill)) {
|
||||
return;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
SmeltingVanillaXPEventHandler eventHandler = new SmeltingVanillaXPEventHandler(this, event);
|
||||
eventHandler.calculateModifier();
|
||||
eventHandler.modifyVanillaXP();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import org.bukkit.event.inventory.FurnaceExtractEvent;
|
||||
|
||||
public class SmeltingVanillaXPEventHandler {
|
||||
private SmeltingManager manager;
|
||||
private FurnaceExtractEvent event;
|
||||
private int xpBoostModifier;
|
||||
|
||||
protected SmeltingVanillaXPEventHandler(SmeltingManager manager, FurnaceExtractEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
protected void calculateModifier() {
|
||||
int skillLevel = manager.getSkillLevel();
|
||||
|
||||
if (skillLevel >= Smelting.vanillaXPBoostRank5Level) {
|
||||
xpBoostModifier = Smelting.vanillaXPBoostRank5Multiplier;
|
||||
}
|
||||
else if (skillLevel >= Smelting.vanillaXPBoostRank4Level) {
|
||||
xpBoostModifier = Smelting.vanillaXPBoostRank4Multiplier;
|
||||
}
|
||||
else if (skillLevel >= Smelting.vanillaXPBoostRank3Level) {
|
||||
xpBoostModifier = Smelting.vanillaXPBoostRank3Multiplier;
|
||||
}
|
||||
else if (skillLevel >= Smelting.vanillaXPBoostRank2Level) {
|
||||
xpBoostModifier = Smelting.vanillaXPBoostRank2Multiplier;
|
||||
}
|
||||
else {
|
||||
xpBoostModifier = Smelting.vanillaXPBoostRank1Multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
protected void modifyVanillaXP() {
|
||||
int xp = event.getExpToDrop();
|
||||
event.setExpToDrop(xp * xpBoostModifier);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user