Merge pull request #3 from TfT-02/master

Salvage ability for Repair
This commit is contained in:
Glitchfinder 2012-11-13 13:37:04 -08:00
commit 506efec858
14 changed files with 188 additions and 6 deletions

3
.gitignore vendored
View File

@ -40,3 +40,6 @@
# Atlassian Stuff
/atlassian-ide-plugin.xml
src/.DS_Store
src/main/.DS_Store

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>1.3.11</version>
<version>1.3.12</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<issueManagement>

View File

@ -16,6 +16,7 @@ public class RepairCommand extends SkillCommand {
private boolean canSuperRepair;
private boolean canMasterRepair;
private boolean canArcaneForge;
private boolean canSalvage;
private boolean canRepairStone;
private boolean canRepairIron;
private boolean canRepairGold;
@ -24,6 +25,7 @@ public class RepairCommand extends SkillCommand {
private boolean canRepairLeather;
private boolean canRepairWood;
private int salvageLevel;
private int diamondLevel;
private int goldLevel;
private int ironLevel;
@ -46,6 +48,8 @@ public class RepairCommand extends SkillCommand {
ironLevel = (ironRepairable == null) ? 0 : ironRepairable.getMinimumLevel();
stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel();
salvageLevel = Config.getInstance().getSalvageUnlockLevel();
repairMasteryBonus = percent.format(skillValue / 500);
if (skillValue >= 1000) {
@ -63,6 +67,7 @@ public class RepairCommand extends SkillCommand {
canSuperRepair = permInstance.repairBonus(player);
canMasterRepair = permInstance.repairMastery(player);
canArcaneForge = permInstance.arcaneForging(player);
canSalvage = permInstance.salvage(player);
canRepairDiamond = permInstance.diamondRepair(player);
canRepairGold = permInstance.goldRepair(player);
canRepairIron = permInstance.ironRepair(player);
@ -74,7 +79,7 @@ public class RepairCommand extends SkillCommand {
@Override
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
@ -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") }));
}
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) {
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 */
public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); }
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 */
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 placedAnvil;
private boolean placedSalvageAnvil;
private boolean partyChatMode, adminChatMode;
private boolean godMode;
private boolean greenTerraMode, treeFellerMode, superBreakerMode, gigaDrillBreakerMode, serratedStrikesMode, skullSplitterMode, berserkMode;
@ -491,7 +492,7 @@ public class PlayerProfile {
}
/*
* Anvil Placement
* Repair Anvil Placement
*/
public void togglePlacedAnvil() {
@ -501,6 +502,16 @@ public class PlayerProfile {
public Boolean getPlacedAnvil() {
return placedAnvil;
}
/*
* Salvage Anvil Placement
*/
public void togglePlacedSalvageAnvil() {
placedSalvageAnvil = !placedSalvageAnvil;
}
public Boolean getPlacedSalvageAnvil() {
return placedSalvageAnvil;
}
/*
* 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.WoodCutting;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.ItemChecks;
@ -154,6 +155,9 @@ public class BlockListener implements Listener {
if (id == configInstance.getRepairAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) {
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;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
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.Fishing;
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.util.BlockChecks;
import com.gmail.nossr50.util.Item;
@ -322,6 +324,15 @@ public class PlayerListener implements Listener {
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 */
if (Config.getInstance().getAbilitiesEnabled() && BlockChecks.abilityBlockCheck(block)) {

View File

@ -146,6 +146,11 @@ public class mcMMO extends JavaPlugin {
repairManager = RepairManagerFactory.getRepairManager(repairables.size());
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()) {
Users.loadUsers();
}

View File

@ -0,0 +1,115 @@
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"));
}
}
/**
* 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();
}
}
public static int getSalvagedItemID(final ItemStack inHand) {
int salvagedItem = 0;
if (ItemChecks.isDiamondTool(inHand) || ItemChecks.isDiamondArmor(inHand)) { salvagedItem = 264; }
else if (ItemChecks.isGoldTool(inHand) || ItemChecks.isGoldArmor(inHand)) { salvagedItem = 266; }
else if (ItemChecks.isIronTool(inHand) || ItemChecks.isIronArmor(inHand)){ salvagedItem = 265; }
else if (ItemChecks.isStoneTool(inHand)){ salvagedItem = 4; }
else if (ItemChecks.isWoodTool(inHand)){ salvagedItem = 5; }
else if ( ItemChecks.isLeatherArmor(inHand)){ salvagedItem = 334; }
return salvagedItem;
}
public static int getSalvagedAmount(final ItemStack inHand) {
int salvagedAmount = 0;
if (ItemChecks.isPickaxe(inHand) || ItemChecks.isAxe(inHand)) { salvagedAmount = 3; }
else if (ItemChecks.isShovel(inHand)) { salvagedAmount = 1; }
else if (ItemChecks.isSword(inHand) || ItemChecks.isHoe(inHand)) { salvagedAmount = 2; }
else if (ItemChecks.isHelmet(inHand)) { salvagedAmount = 5; }
else if (ItemChecks.isChestplate(inHand)) { salvagedAmount = 8; }
else if (ItemChecks.isPants(inHand)) { salvagedAmount = 7; }
else if (ItemChecks.isBoots(inHand)) { salvagedAmount = 4; }
return salvagedAmount;
}
/**
* 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;
default:
if (block.getTypeId() == Config.getInstance().getRepairAnvilId()) {
if (block.getTypeId() == Config.getInstance().getRepairAnvilId() || block.getTypeId() == Config.getInstance().getSalvageAnvilId()) {
return false;
}
else {

View File

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

View File

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

View File

@ -208,9 +208,13 @@ Repair.Effect.6=Diamond Repair ({0}+ SKILL)
Repair.Effect.7=Repair Diamond Tools & Armor
Repair.Effect.8=Arcane Forging
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.Anvil2=[[DARK_RED]]You have placed a Salvage anvil, use this to Salvage tools and armor.
Repair.Listener=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.AdeptGold=[[DARK_RED]]You're not skilled enough to repair Gold.
Repair.Skills.AdeptIron=[[DARK_RED]]You're not skilled enough to repair Iron.
@ -218,6 +222,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.FeltEasy=[[GRAY]]That felt easy.
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.StackedItems=[[DARK_RED]]You can't repair stacked items.
Repair.Skills.Super.Chance=[[RED]]Super Repair Chance: [[YELLOW]]{0}

View File

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