mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Move Salvage checks into our RepairManager
This commit is contained in:
parent
5f4e269efa
commit
08960a2dbc
@ -35,8 +35,6 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||
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.RepairManager;
|
||||
import com.gmail.nossr50.skills.repair.Salvage;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.skills.unarmed.Unarmed;
|
||||
import com.gmail.nossr50.skills.woodcutting.Woodcutting;
|
||||
@ -117,15 +115,7 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
if (Repair.anvilMessagesEnabled) {
|
||||
RepairManager repairManager = UserManager.getPlayer(player).getRepairManager();
|
||||
int blockID = blockState.getTypeId();
|
||||
|
||||
if (blockID == Repair.anvilID) {
|
||||
repairManager.placedAnvilCheck(blockID);
|
||||
}
|
||||
else if (blockID == Salvage.anvilID) {
|
||||
Salvage.placedAnvilCheck(player, blockID);
|
||||
}
|
||||
UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockState.getTypeId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
/* SALVAGE CHECKS */
|
||||
else if (blockID == Salvage.anvilID && Permissions.salvage(player) && Salvage.isSalvageable(heldItem)) {
|
||||
Salvage.handleSalvage(player, block.getLocation(), heldItem);
|
||||
UserManager.getPlayer(player).getRepairManager().handleSalvage(block.getLocation(), heldItem);
|
||||
event.setCancelled(true);
|
||||
player.updateInventory();
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.gmail.nossr50.skills.repair;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -13,6 +15,7 @@ import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
|
||||
@ -29,12 +32,21 @@ public class RepairManager extends SkillManager {
|
||||
super(mcMMOPlayer, SkillType.REPAIR);
|
||||
}
|
||||
|
||||
public void placedAnvilCheck(int anvilId) {
|
||||
if (anvilId == Repair.anvilID) {
|
||||
repairAnvilCheck(anvilId);
|
||||
}
|
||||
else if (anvilId == Salvage.anvilID) {
|
||||
salvageAnvilCheck(anvilId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles notifications for placing an anvil.
|
||||
*
|
||||
* @param anvilID The item ID of the anvil block
|
||||
*/
|
||||
public void placedAnvilCheck(int anvilID) {
|
||||
public void repairAnvilCheck(int anvilID) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (mcMMOPlayer.getPlacedAnvil()) {
|
||||
@ -56,6 +68,32 @@ public class RepairManager extends SkillManager {
|
||||
mcMMOPlayer.togglePlacedAnvil();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles notifications for placing an anvil.
|
||||
*
|
||||
* @param player The player placing the anvil
|
||||
* @param anvilID The item ID of the anvil block
|
||||
*/
|
||||
public void salvageAnvilCheck(int anvilID) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (!mcMMOPlayer.getPlacedSalvageAnvil()) {
|
||||
if (mcMMO.spoutEnabled) {
|
||||
final SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
||||
spoutPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to salvage!", Material.getMaterial(anvilID));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil2"));
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
mcMMOPlayer.togglePlacedSalvageAnvil();
|
||||
}
|
||||
}
|
||||
|
||||
public void handleRepair(ItemStack item) {
|
||||
Player player = getPlayer();
|
||||
int itemId = item.getTypeId();
|
||||
@ -166,6 +204,32 @@ public class RepairManager extends SkillManager {
|
||||
item.setDurability(newDurability);
|
||||
}
|
||||
|
||||
public void handleSalvage(Location location, ItemStack item) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (!Config.getInstance().getSalvageEnabled() || player.getGameMode() != GameMode.SURVIVAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getSkillLevel() < Salvage.salvageUnlockLevel) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptSalvage"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.getDurability() == 0) {
|
||||
player.setItemInHand(new ItemStack(Material.AIR));
|
||||
location.setY(location.getY() + 1);
|
||||
|
||||
Misc.dropItems(location, new ItemStack(Salvage.getSalvagedItem(item)), Salvage.getSalvagedAmount(item));
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.SalvageSuccess"));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.NotFullDurability"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Arcane Forging rank
|
||||
*
|
||||
|
@ -1,83 +1,15 @@
|
||||
package com.gmail.nossr50.skills.repair;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
public class Salvage {
|
||||
public static int salvageUnlockLevel = Config.getInstance().getSalvageUnlockLevel();
|
||||
public static int anvilID = Config.getInstance().getSalvageAnvilId();
|
||||
|
||||
public static void handleSalvage(final Player player, final Location location, final ItemStack item) {
|
||||
if (!Config.getInstance().getSalvageEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode() == GameMode.SURVIVAL) {
|
||||
final int skillLevel = UserManager.getPlayer(player).getProfile().getSkillLevel(SkillType.REPAIR);
|
||||
|
||||
if (skillLevel < salvageUnlockLevel) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptSalvage"));
|
||||
return;
|
||||
}
|
||||
|
||||
final float currentDurability = item.getDurability();
|
||||
|
||||
if (currentDurability == 0) {
|
||||
player.setItemInHand(new ItemStack(Material.AIR));
|
||||
location.setY(location.getY() + 1);
|
||||
|
||||
Misc.dropItems(location, new ItemStack(getSalvagedItem(item)), getSalvagedAmount(item));
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.SalvageSuccess"));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.NotFullDurability"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles notifications for placing an anvil.
|
||||
*
|
||||
* @param player The player placing the anvil
|
||||
* @param anvilID The item ID of the anvil block
|
||||
*/
|
||||
public static void placedAnvilCheck(final Player player, final int anvilID) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (!mcMMOPlayer.getPlacedSalvageAnvil()) {
|
||||
if (mcMMO.spoutEnabled) {
|
||||
final SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
||||
spoutPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to salvage!", Material.getMaterial(anvilID));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil2"));
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
mcMMOPlayer.togglePlacedSalvageAnvil();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the item is salvageable.
|
||||
*
|
||||
@ -96,7 +28,7 @@ public class Salvage {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Material getSalvagedItem(final ItemStack inHand) {
|
||||
protected static Material getSalvagedItem(final ItemStack inHand) {
|
||||
if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) {
|
||||
return Material.DIAMOND;
|
||||
}
|
||||
@ -123,7 +55,7 @@ public class Salvage {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getSalvagedAmount(final ItemStack inHand) {
|
||||
protected static int getSalvagedAmount(final ItemStack inHand) {
|
||||
if (ItemUtils.isPickaxe(inHand) || ItemUtils.isAxe(inHand) || inHand.getType() == Material.BOW || inHand.getType() == Material.BUCKET) {
|
||||
return 3;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user