mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
More code duplication removal.
This commit is contained in:
parent
db637f0bc9
commit
3a78e1b487
@ -1,8 +1,6 @@
|
||||
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;
|
||||
@ -21,7 +19,6 @@ import org.bukkit.metadata.FixedMetadataValue;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.runnables.PlayerUpdateInventoryTask;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -68,15 +65,9 @@ public class InventoryListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
ItemStack smelting = Misc.getSmeltingFromFurnace(furnaceBlock);
|
||||
|
||||
if (!(furnaceState instanceof Furnace)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
||||
|
||||
if (smelting == null || !ItemUtils.isSmeltable(smelting)) {
|
||||
if (!ItemUtils.isSmeltable(smelting)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -92,15 +83,9 @@ public class InventoryListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
ItemStack smelting = Misc.getSmeltingFromFurnace(furnaceBlock);
|
||||
|
||||
if (!(furnaceState instanceof Furnace)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
||||
|
||||
if (smelting == null || !ItemUtils.isSmeltable(smelting)) {
|
||||
if (!ItemUtils.isSmeltable(smelting)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -116,29 +101,19 @@ public class InventoryListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
ItemStack result = Misc.getResultFromFurnace(furnaceBlock);
|
||||
|
||||
if (!(furnaceState instanceof Furnace)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack result = ((Furnace) furnaceState).getInventory().getResult();
|
||||
|
||||
if (result == null || !ItemUtils.isSmelted(result)) {
|
||||
if (!ItemUtils.isSmelted(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
if (Misc.isNPCEntity(player) || !Permissions.vanillaXpBoost(player, SkillType.SMELTING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmeltingManager smeltingManager = UserManager.getPlayer(player).getSmeltingManager();
|
||||
|
||||
if (smeltingManager.canUseVanillaXpBoost()) {
|
||||
event.setExpToDrop(smeltingManager.vanillaXPBoost(event.getExpToDrop()));
|
||||
}
|
||||
event.setExpToDrop(UserManager.getPlayer(player).getSmeltingManager().vanillaXPBoost(event.getExpToDrop()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
|
@ -28,10 +28,6 @@ public class SmeltingManager extends SkillManager {
|
||||
return getSkillLevel() >= Smelting.fluxMiningUnlockLevel && BlockUtils.affectedByFluxMining(blockState) && Permissions.fluxMining(getPlayer()) && !mcMMO.getPlaceStore().isTrue(blockState);
|
||||
}
|
||||
|
||||
public boolean canUseVanillaXpBoost() {
|
||||
return getSkillLevel() >= Smelting.Tier.ONE.getLevel() && Permissions.vanillaXpBoost(getPlayer(), skill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the Flux Mining ability.
|
||||
*
|
||||
@ -122,6 +118,6 @@ public class SmeltingManager extends SkillManager {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -461,6 +461,10 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static boolean isSmeltable(ItemStack item) {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case COAL_ORE:
|
||||
case DIAMOND_ORE:
|
||||
@ -479,6 +483,10 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static boolean isSmelted(ItemStack item) {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case COAL:
|
||||
case DIAMOND:
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@ -230,7 +231,31 @@ public final class Misc {
|
||||
public static Player getPlayerFromFurnace(Block furnaceBlock) {
|
||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
||||
|
||||
return metadata.isEmpty() ? null : mcMMO.p.getServer().getPlayerExact(metadata.get(0).asString());
|
||||
if (metadata.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mcMMO.p.getServer().getPlayerExact(metadata.get(0).asString());
|
||||
}
|
||||
|
||||
public static ItemStack getSmeltingFromFurnace(Block furnaceBlock) {
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
|
||||
if (!(furnaceState instanceof Furnace)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ((Furnace) furnaceState).getInventory().getSmelting();
|
||||
}
|
||||
|
||||
public static ItemStack getResultFromFurnace(Block furnaceBlock) {
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
|
||||
if (!(furnaceState instanceof Furnace)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ((Furnace) furnaceState).getInventory().getResult();
|
||||
}
|
||||
|
||||
public static Random getRandom() {
|
||||
|
Loading…
Reference in New Issue
Block a user