New Salvage ability for Repair!

Added a fully working ability to Repair. With this ability you can
salvage items and get bars in return.

- Added new permission node for Salvage ability
- Added new config options for Salvage
- Added new locale strings for Salvage
- Added a check to make sure that Repair Anvil != Salvage Anvil
This commit is contained in:
TfT_02 2012-11-13 16:50:00 +01:00
parent b0681c10b9
commit f8b44cd8ce
12 changed files with 286 additions and 3 deletions

View File

@ -16,6 +16,7 @@ public class RepairCommand extends SkillCommand {
private boolean canSuperRepair; private boolean canSuperRepair;
private boolean canMasterRepair; private boolean canMasterRepair;
private boolean canArcaneForge; private boolean canArcaneForge;
private boolean canSalvage;
private boolean canRepairStone; private boolean canRepairStone;
private boolean canRepairIron; private boolean canRepairIron;
private boolean canRepairGold; private boolean canRepairGold;
@ -24,6 +25,7 @@ public class RepairCommand extends SkillCommand {
private boolean canRepairLeather; private boolean canRepairLeather;
private boolean canRepairWood; private boolean canRepairWood;
private int salvageLevel;
private int diamondLevel; private int diamondLevel;
private int goldLevel; private int goldLevel;
private int ironLevel; private int ironLevel;
@ -46,6 +48,8 @@ public class RepairCommand extends SkillCommand {
ironLevel = (ironRepairable == null) ? 0 : ironRepairable.getMinimumLevel(); ironLevel = (ironRepairable == null) ? 0 : ironRepairable.getMinimumLevel();
stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel(); stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel();
salvageLevel = Config.getInstance().getSalvageUnlockLevel();
repairMasteryBonus = percent.format(skillValue / 500); repairMasteryBonus = percent.format(skillValue / 500);
if (skillValue >= 1000) { if (skillValue >= 1000) {
@ -63,6 +67,7 @@ public class RepairCommand extends SkillCommand {
canSuperRepair = permInstance.repairBonus(player); canSuperRepair = permInstance.repairBonus(player);
canMasterRepair = permInstance.repairMastery(player); canMasterRepair = permInstance.repairMastery(player);
canArcaneForge = permInstance.arcaneForging(player); canArcaneForge = permInstance.arcaneForging(player);
canSalvage = permInstance.salvage(player);
canRepairDiamond = permInstance.diamondRepair(player); canRepairDiamond = permInstance.diamondRepair(player);
canRepairGold = permInstance.goldRepair(player); canRepairGold = permInstance.goldRepair(player);
canRepairIron = permInstance.ironRepair(player); canRepairIron = permInstance.ironRepair(player);
@ -74,7 +79,7 @@ public class RepairCommand extends SkillCommand {
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canArcaneForge || canRepairDiamond || canRepairGold || canRepairIron || canMasterRepair || canRepairStone || canSuperRepair || canRepairString || canRepairWood || canRepairLeather; return canArcaneForge || canSalvage || canRepairDiamond || canRepairGold || canRepairIron || canMasterRepair || canRepairStone || canSuperRepair || canRepairString || canRepairWood || canRepairLeather;
} }
@Override @Override
@ -107,6 +112,10 @@ public class RepairCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Repair.Effect.6", new Object[] { diamondLevel }), LocaleLoader.getString("Repair.Effect.7") })); player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Repair.Effect.6", new Object[] { diamondLevel }), LocaleLoader.getString("Repair.Effect.7") }));
} }
if (canSalvage && salvageLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Repair.Effect.16", new Object[] { salvageLevel }), LocaleLoader.getString("Repair.Effect.17") }));
}
if (canArcaneForge) { if (canArcaneForge) {
player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Repair.Effect.8"), LocaleLoader.getString("Repair.Effect.9") })); player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Repair.Effect.8"), LocaleLoader.getString("Repair.Effect.9") }));
} }

View File

@ -270,6 +270,11 @@ public class Config extends ConfigLoader {
/* Repair */ /* Repair */
public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); } public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); }
public int getRepairAnvilId() { return config.getInt("Skills.Repair.Anvil_ID", 42); } public int getRepairAnvilId() { return config.getInt("Skills.Repair.Anvil_ID", 42); }
public boolean getSalvageEnabled() { return config.getBoolean("Skills.Repair.Salvage_enabled", true); }
public int getSalvageAnvilId() { return config.getInt("Skills.Repair.Salvage_Anvil_ID", 41); }
public int getSalvageUnlockLevel() { return config.getInt("Skills.Repair.Salvage_UnlockLevel", 600); }
public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", true); }
public boolean getSalvageArmor() { return config.getBoolean("Skills.Repair.Salvage_armor", true); }
/* Taming */ /* Taming */
public int getTamingXPWolf() { return config.getInt("Experience.Taming.Animal_Taming.Wolf", 250); } public int getTamingXPWolf() { return config.getInt("Experience.Taming.Animal_Taming.Wolf", 250); }

View File

@ -31,6 +31,7 @@ public class PlayerProfile {
private boolean loaded; private boolean loaded;
private boolean placedAnvil; private boolean placedAnvil;
private boolean placedSalvageAnvil;
private boolean partyChatMode, adminChatMode; private boolean partyChatMode, adminChatMode;
private boolean godMode; private boolean godMode;
private boolean greenTerraMode, treeFellerMode, superBreakerMode, gigaDrillBreakerMode, serratedStrikesMode, skullSplitterMode, berserkMode; private boolean greenTerraMode, treeFellerMode, superBreakerMode, gigaDrillBreakerMode, serratedStrikesMode, skullSplitterMode, berserkMode;
@ -491,7 +492,7 @@ public class PlayerProfile {
} }
/* /*
* Anvil Placement * Repair Anvil Placement
*/ */
public void togglePlacedAnvil() { public void togglePlacedAnvil() {
@ -501,6 +502,16 @@ public class PlayerProfile {
public Boolean getPlacedAnvil() { public Boolean getPlacedAnvil() {
return placedAnvil; return placedAnvil;
} }
/*
* Salvage Anvil Placement
*/
public void togglePlacedSalvageAnvil() {
placedSalvageAnvil = !placedSalvageAnvil;
}
public Boolean getPlacedSalvageAnvil() {
return placedSalvageAnvil;
}
/* /*
* HUD Stuff * HUD Stuff

View File

@ -34,6 +34,7 @@ import com.gmail.nossr50.skills.gathering.Herbalism;
import com.gmail.nossr50.skills.gathering.Mining; import com.gmail.nossr50.skills.gathering.Mining;
import com.gmail.nossr50.skills.gathering.WoodCutting; import com.gmail.nossr50.skills.gathering.WoodCutting;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.ItemChecks;
@ -154,6 +155,9 @@ public class BlockListener implements Listener {
if (id == configInstance.getRepairAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) { if (id == configInstance.getRepairAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) {
Repair.placedAnvilCheck(player, id); Repair.placedAnvilCheck(player, id);
} }
if (id == configInstance.getSalvageAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) {
Salvage.placedAnvilCheck(player, id);
}
} }
/** /**

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -36,6 +37,7 @@ import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.skills.gathering.BlastMining; import com.gmail.nossr50.skills.gathering.BlastMining;
import com.gmail.nossr50.skills.gathering.Fishing; import com.gmail.nossr50.skills.gathering.Fishing;
import com.gmail.nossr50.skills.gathering.Herbalism; import com.gmail.nossr50.skills.gathering.Herbalism;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Item; import com.gmail.nossr50.util.Item;
@ -259,6 +261,15 @@ public class PlayerListener implements Listener {
player.updateInventory(); player.updateInventory();
} }
} }
/* SALVAGE CHECKS */
if (Permissions.getInstance().salvage(player) && block.getTypeId() == Config.getInstance().getSalvageAnvilId()) {
if (Salvage.isSalvageable(inHand)) {
final Location location = block.getLocation();
Salvage.handleSalvage(player, location, inHand);
event.setCancelled(true);
player.updateInventory();
}
}
/* ACTIVATION CHECKS */ /* ACTIVATION CHECKS */
if (Config.getInstance().getAbilitiesEnabled() && BlockChecks.abilityBlockCheck(block)) { if (Config.getInstance().getAbilitiesEnabled() && BlockChecks.abilityBlockCheck(block)) {

View File

@ -146,6 +146,11 @@ public class mcMMO extends JavaPlugin {
repairManager = RepairManagerFactory.getRepairManager(repairables.size()); repairManager = RepairManagerFactory.getRepairManager(repairables.size());
repairManager.registerRepairables(repairables); repairManager.registerRepairables(repairables);
//Check if Repair Anvil and Salvage Anvil have different itemID's
if (configInstance.getSalvageAnvilId() == configInstance.getRepairAnvilId()){
System.out.println("[WARNING!] Can't use the same itemID for Repair/Salvage Anvils!" );
}
if (!configInstance.getUseMySQL()) { if (!configInstance.getUseMySQL()) {
Users.loadUsers(); Users.loadUsers();
} }

View File

@ -0,0 +1,219 @@
package com.gmail.nossr50.skills.repair;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
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.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class Salvage {
private static Config configInstance = Config.getInstance();
private static Permissions permInstance = Permissions.getInstance();
public static void handleSalvage(final Player player, final Location location, final ItemStack inHand) {
if (!permInstance.salvage(player) || !configInstance.getSalvageEnabled()) {
return;
}
final PlayerProfile profile = Users.getProfile(player);
final int skillLevel = profile.getSkillLevel(SkillType.REPAIR);
final int unlockLevel = configInstance.getSalvageUnlockLevel();
if (skillLevel >= unlockLevel) {
final World world = player.getWorld();
final float currentdura = inHand.getDurability();
if (currentdura == 0) {
final int salvagedAmount = getSalvagedAmount(inHand);
final int itemID = getSalvagedItemID(inHand);
player.setItemInHand(new ItemStack(0));
location.setY(location.getY() + 1);
world.dropItem(location, new ItemStack(itemID, salvagedAmount));
player.sendMessage(LocaleLoader.getString("Repair.Skills.SalvageSuccess"));
} else {
player.sendMessage(LocaleLoader.getString("Repair.Skills.NotFullDurability"));
}
} else {
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptSalvage"));
}
}
public static int getSalvagedItemID(final ItemStack inHand) {
int salvagedItem = 0;
switch (inHand.getType()) {
case DIAMOND_PICKAXE:
case DIAMOND_SPADE:
case DIAMOND_AXE:
case DIAMOND_SWORD:
case DIAMOND_HOE:
case DIAMOND_HELMET:
case DIAMOND_CHESTPLATE:
case DIAMOND_LEGGINGS:
case DIAMOND_BOOTS:
salvagedItem = 264;
break;
case GOLD_PICKAXE:
case GOLD_SPADE:
case GOLD_AXE:
case GOLD_SWORD:
case GOLD_HOE:
case GOLD_HELMET:
case GOLD_CHESTPLATE:
case GOLD_LEGGINGS:
case GOLD_BOOTS:
salvagedItem = 266;
break;
case IRON_PICKAXE:
case IRON_SPADE:
case IRON_AXE:
case IRON_SWORD:
case IRON_HOE:
case IRON_HELMET:
case IRON_CHESTPLATE:
case IRON_LEGGINGS:
case IRON_BOOTS:
salvagedItem = 265;
break;
case STONE_PICKAXE:
case STONE_SPADE:
case STONE_AXE:
case STONE_SWORD:
case STONE_HOE:
salvagedItem = 4;
break;
case WOOD_PICKAXE:
case WOOD_SPADE:
case WOOD_AXE:
case WOOD_SWORD:
case WOOD_HOE:
salvagedItem = 5;
break;
case LEATHER_HELMET:
case LEATHER_CHESTPLATE:
case LEATHER_LEGGINGS:
case LEATHER_BOOTS:
salvagedItem = 334;
break;
default:
break;
}
return salvagedItem;
}
public static int getSalvagedAmount(final ItemStack inHand) {
int salvagedAmount = 0;
switch (inHand.getType()) {
case DIAMOND_PICKAXE:
case GOLD_PICKAXE:
case IRON_PICKAXE:
case STONE_PICKAXE:
case WOOD_PICKAXE:
case DIAMOND_AXE:
case GOLD_AXE:
case IRON_AXE:
case STONE_AXE:
case WOOD_AXE:
salvagedAmount = 3;
break;
case DIAMOND_SPADE:
case GOLD_SPADE:
case IRON_SPADE:
case STONE_SPADE:
case WOOD_SPADE:
salvagedAmount = 1;
break;
case DIAMOND_SWORD:
case GOLD_SWORD:
case IRON_SWORD:
case STONE_SWORD:
case WOOD_SWORD:
case DIAMOND_HOE:
case GOLD_HOE:
case IRON_HOE:
case STONE_HOE:
case WOOD_HOE:
salvagedAmount = 2;
break;
case DIAMOND_HELMET:
case GOLD_HELMET:
case IRON_HELMET:
case LEATHER_HELMET:
salvagedAmount = 5;
break;
case DIAMOND_CHESTPLATE:
case GOLD_CHESTPLATE:
case IRON_CHESTPLATE:
case LEATHER_CHESTPLATE:
salvagedAmount = 8;
break;
case DIAMOND_LEGGINGS:
case GOLD_LEGGINGS:
case IRON_LEGGINGS:
case LEATHER_LEGGINGS:
salvagedAmount = 7;
break;
case DIAMOND_BOOTS:
case GOLD_BOOTS:
case IRON_BOOTS:
case LEATHER_BOOTS:
salvagedAmount = 4;
break;
default:
break;
}
return salvagedAmount;
}
/**
* 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) {
final PlayerProfile profile = Users.getProfile(player);
if (!profile.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"));
}
profile.togglePlacedSalvageAnvil();
}
}
/**
* Checks if the item is salvageable.
*
* @param is Item to check
* @return true if the item is salvageable, false otherwise
*/
public static boolean isSalvageable(final ItemStack is) {
if (configInstance.getSalvageTools() && ItemChecks.isTool(is)) {
return true;
}
if (configInstance.getSalvageArmor() && ItemChecks.isArmor(is)) {
return true;
}
return false;
}
}

View File

@ -105,7 +105,7 @@ public class BlockChecks {
return false; return false;
default: default:
if (block.getTypeId() == Config.getInstance().getRepairAnvilId()) { if (block.getTypeId() == Config.getInstance().getRepairAnvilId() | block.getTypeId() == Config.getInstance().getSalvageAnvilId()) {
return false; return false;
} }
else { else {

View File

@ -208,6 +208,11 @@ public class Permissions {
return player.hasPermission("mcmmo.ability.repair.stringrepair"); return player.hasPermission("mcmmo.ability.repair.stringrepair");
} }
public boolean salvage(Player player) {
return player.hasPermission("mcmmo.ability.repair.salvage");
}
/* /*
* MCMMO.ABILITY.UNARMED.* * MCMMO.ABILITY.UNARMED.*
*/ */

View File

@ -172,6 +172,11 @@ Skills:
Level_Cap: 0 Level_Cap: 0
Anvil_Messages: true Anvil_Messages: true
Anvil_ID: 42 Anvil_ID: 42
Salvage_enabled: true
Salvage_Anvil_ID: 41
Salvage_UnlockLevel: 600
Salvage_tools: true
Salvage_armor: true
Swords: Swords:
Enabled_For_PVP: true Enabled_For_PVP: true
Enabled_For_PVE: true Enabled_For_PVE: true

View File

@ -205,9 +205,13 @@ Repair.Effect.6=Diamond Repair ({0}+ SKILL)
Repair.Effect.7=Repair Diamond Tools & Armor Repair.Effect.7=Repair Diamond Tools & Armor
Repair.Effect.8=Arcane Forging Repair.Effect.8=Arcane Forging
Repair.Effect.9=Repair magic items Repair.Effect.9=Repair magic items
Repair.Effect.16=Salvage ({0}+ SKILL)
Repair.Effect.17=Salvage Tools & Armor
Repair.Listener.Anvil=[[DARK_RED]]You have placed an anvil, anvils can repair tools and armor. Repair.Listener.Anvil=[[DARK_RED]]You have placed an anvil, anvils can repair tools and armor.
Repair.Listener.Anvil2=[[DARK_RED]]You have placed a Salvage anvil, use this to Salvage tools and armor.
Repair.Listener=Repair: Repair.Listener=Repair:
Repair.SkillName=REPAIR Repair.SkillName=REPAIR
Repair.Skills.AdeptSalvage=[[DARK_RED]]You're not skilled enough to Salvage items.
Repair.Skills.AdeptDiamond=[[DARK_RED]]You're not skilled enough to repair Diamond. Repair.Skills.AdeptDiamond=[[DARK_RED]]You're not skilled enough to repair Diamond.
Repair.Skills.AdeptGold=[[DARK_RED]]You're not skilled enough to repair Gold. Repair.Skills.AdeptGold=[[DARK_RED]]You're not skilled enough to repair Gold.
Repair.Skills.AdeptIron=[[DARK_RED]]You're not skilled enough to repair Iron. Repair.Skills.AdeptIron=[[DARK_RED]]You're not skilled enough to repair Iron.
@ -215,6 +219,8 @@ Repair.Skills.AdeptStone=[[DARK_RED]]You're not skilled enough to repair Stone.
Repair.Skills.Adept=[[RED]]You must be level [[YELLOW]]{0}[[RED]] to repair [[YELLOW]]{1} Repair.Skills.Adept=[[RED]]You must be level [[YELLOW]]{0}[[RED]] to repair [[YELLOW]]{1}
Repair.Skills.FeltEasy=[[GRAY]]That felt easy. Repair.Skills.FeltEasy=[[GRAY]]That felt easy.
Repair.Skills.FullDurability=[[GRAY]]That is at full durability. Repair.Skills.FullDurability=[[GRAY]]That is at full durability.
Repair.Skills.SalvageSuccess=[[GRAY]]Item salvaged!
Repair.Skills.NotFullDurability=[[DARK_RED]]You can't salvage damaged items.
Repair.Skills.Mastery=[[RED]]Repair Mastery: [[YELLOW]]Extra {0} durability restored Repair.Skills.Mastery=[[RED]]Repair Mastery: [[YELLOW]]Extra {0} durability restored
Repair.Skills.StackedItems=[[DARK_RED]]You can't repair stacked items. Repair.Skills.StackedItems=[[DARK_RED]]You can't repair stacked items.
Repair.Skills.Super.Chance=[[RED]]Super Repair Chance: [[YELLOW]]{0} Repair.Skills.Super.Chance=[[RED]]Super Repair Chance: [[YELLOW]]{0}

View File

@ -366,6 +366,7 @@ permissions:
mcmmo.ability.repair.repairbonus: true mcmmo.ability.repair.repairbonus: true
mcmmo.ability.repair.repairmastery: true mcmmo.ability.repair.repairmastery: true
mcmmo.ability.repair.arcaneforging: true mcmmo.ability.repair.arcaneforging: true
mcmmo.ability.repair.salvage: true
mcmmo.ability.repair.woodrepair: true mcmmo.ability.repair.woodrepair: true
mcmmo.ability.repair.stonerepair: true mcmmo.ability.repair.stonerepair: true
mcmmo.ability.repair.leatherrepair: true mcmmo.ability.repair.leatherrepair: true
@ -383,6 +384,8 @@ permissions:
description: Allows access to Repair Mastery description: Allows access to Repair Mastery
mcmmo.ability.repair.arcaneforging: mcmmo.ability.repair.arcaneforging:
description: Allows access to the Arcane Forging ability description: Allows access to the Arcane Forging ability
mcmmo.ability.repair.salvage:
description: Allows access to the Salvage ability
mcmmo.ability.repair.woodrepair: mcmmo.ability.repair.woodrepair:
description: Allows ability to repair Wood tools description: Allows ability to repair Wood tools
mcmmo.ability.repair.stonerepair: mcmmo.ability.repair.stonerepair: