mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Remove more code duplication.
This commit is contained in:
parent
b15f1dde28
commit
db637f0bc9
@ -1,7 +1,5 @@
|
|||||||
package com.gmail.nossr50.listeners;
|
package com.gmail.nossr50.listeners;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Furnace;
|
import org.bukkit.block.Furnace;
|
||||||
@ -19,7 +17,6 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
@ -77,20 +74,13 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
|
||||||
|
|
||||||
if (metadata.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
||||||
|
|
||||||
if (smelting == null || !ItemUtils.isSmeltable(smelting)) {
|
if (smelting == null || !ItemUtils.isSmeltable(smelting)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||||
Player player = plugin.getServer().getPlayer(metadata.get(0).asString());
|
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
|
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
|
||||||
return;
|
return;
|
||||||
@ -108,20 +98,13 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
|
||||||
|
|
||||||
if (metadata.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
||||||
|
|
||||||
if (smelting == null || !ItemUtils.isSmeltable(smelting)) {
|
if (smelting == null || !ItemUtils.isSmeltable(smelting)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||||
Player player = plugin.getServer().getPlayer(metadata.get(0).asString());
|
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
|
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
|
||||||
return;
|
return;
|
||||||
@ -139,20 +122,13 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
|
||||||
|
|
||||||
if (metadata.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack result = ((Furnace) furnaceState).getInventory().getResult();
|
ItemStack result = ((Furnace) furnaceState).getInventory().getResult();
|
||||||
|
|
||||||
if (result == null || !ItemUtils.isSmelted(result)) {
|
if (result == null || !ItemUtils.isSmelted(result)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||||
Player player = plugin.getServer().getPlayer(metadata.get(0).asString());
|
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player)) {
|
if (Misc.isNPCEntity(player)) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.gmail.nossr50.util;
|
package com.gmail.nossr50.util;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -15,6 +16,7 @@ import org.bukkit.event.inventory.InventoryEvent;
|
|||||||
import org.bukkit.inventory.FurnaceInventory;
|
import org.bukkit.inventory.FurnaceInventory;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
@ -225,6 +227,12 @@ public final class Misc {
|
|||||||
return furnace.getBlock();
|
return furnace.getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
public static Random getRandom() {
|
public static Random getRandom() {
|
||||||
return random;
|
return random;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user