mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-01 05:04:43 +02:00
Put McMMOPlayer to use where it made sense
It's basically a wrapper for anything related to players, as a consequence Users.getProfile() is now depreciated. Also removed SkillTools.xpProcessing() because of some redundancy with McMMOPlayer.addXp(). + some cleanup for consistency sake.
This commit is contained in:
@ -14,20 +14,19 @@ import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Repair {
|
||||
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
private static final AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
|
||||
public static final double REPAIR_MASTERY_CHANCE_MAX = advancedConfig.getRepairMasteryMaxBonus();
|
||||
public static final int REPAIR_MASTERY_MAX_BONUS_LEVEL = advancedConfig.getRepairMasteryMaxLevel();
|
||||
|
||||
public static final double SUPER_REPAIR_CHANCE_MAX = advancedConfig.getSuperRepairChanceMax();
|
||||
public static final int SUPER_REPAIR_MAX_BONUS_LEVEL = advancedConfig.getSuperRepairMaxLevel();
|
||||
|
||||
@ -38,22 +37,18 @@ public class Repair {
|
||||
public static int anvilID = Config.getInstance().getRepairAnvilId();
|
||||
|
||||
/**
|
||||
* Handle the XP gain for repair events.
|
||||
* Handle the Xp gain for repair events.
|
||||
*
|
||||
* @param player Player repairing the item
|
||||
* @param profile PlayerProfile of the repairing player
|
||||
* @param mcMMOPlayer Player repairing the item
|
||||
* @param durabilityBefore Durability of the item before repair
|
||||
* @param modify Amount to modify the durability by
|
||||
*/
|
||||
protected static void xpHandler(Player player, PlayerProfile profile, short durabilityBefore, short durabilityAfter, double modify) {
|
||||
short dif = (short) (durabilityBefore - durabilityAfter);
|
||||
protected static void xpHandler(McMMOPlayer mcMMOPlayer, short durabilityBefore, short durabilityAfter, double modify) {
|
||||
short dif = (short) ((durabilityBefore - durabilityAfter) * modify);
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
dif = (short) (dif * modify);
|
||||
|
||||
SkillTools.xpProcessing(player, profile, SkillType.REPAIR, dif * 10);
|
||||
|
||||
//CLANG CLANG
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
mcMMOPlayer.addXp(SkillType.REPAIR, dif * 10);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,9 +2,10 @@ package com.gmail.nossr50.skills.repair;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
|
||||
public interface RepairManager {
|
||||
/**
|
||||
* Register a repairable with the RepairManager
|
||||
@ -47,8 +48,8 @@ public interface RepairManager {
|
||||
/**
|
||||
* Handle the repairing of this object
|
||||
*
|
||||
* @param player Player that is repairing an item
|
||||
* @param mcMMOPlayer Player that is repairing an item
|
||||
* @param item ItemStack that is being repaired
|
||||
*/
|
||||
public void handleRepair(Player player, ItemStack item);
|
||||
public void handleRepair(McMMOPlayer mcMMOPlayer, ItemStack item);
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class SimpleRepairManager implements RepairManager {
|
||||
private HashMap<Integer, Repairable> repairables;
|
||||
@ -57,12 +57,8 @@ public class SimpleRepairManager implements RepairManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRepair(Player player, ItemStack item) {
|
||||
// Load some variables for use
|
||||
PlayerProfile profile = Users.getProfile(player);
|
||||
short startDurability = item.getDurability();
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
int skillLevel = profile.getSkillLevel(SkillType.REPAIR);
|
||||
public void handleRepair(McMMOPlayer mcMMOPlayer, ItemStack item) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
Repairable repairable = repairables.get(item.getTypeId());
|
||||
|
||||
// Permissions checks on material and item types
|
||||
@ -76,12 +72,16 @@ public class SimpleRepairManager implements RepairManager {
|
||||
return;
|
||||
}
|
||||
|
||||
int skillLevel = mcMMOPlayer.getProfile().getSkillLevel(SkillType.REPAIR);
|
||||
|
||||
// Level check
|
||||
if (skillLevel < repairable.getMinimumLevel()) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.Adept", new Object[] { String.valueOf(repairable.getMinimumLevel()), Misc.prettyItemString(item.getTypeId()) } ));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
// Check if they have the proper material to repair with
|
||||
if (!inventory.contains(repairable.getRepairMaterialId())) {
|
||||
String message = LocaleLoader.getString("Skills.NeedMore", new Object[] { Misc.prettyItemString(repairable.getRepairMaterialId()) });
|
||||
@ -95,6 +95,8 @@ public class SimpleRepairManager implements RepairManager {
|
||||
return;
|
||||
}
|
||||
|
||||
short startDurability = item.getDurability();
|
||||
|
||||
// Do not repair if at full durability
|
||||
if (startDurability <= 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.FullDurability"));
|
||||
@ -137,7 +139,7 @@ public class SimpleRepairManager implements RepairManager {
|
||||
}
|
||||
|
||||
// Handle the enchants
|
||||
if (Repair.advancedConfig.getArcaneForgingEnchantLossEnabled() && !Permissions.arcaneBypass(player)) {
|
||||
if (AdvancedConfig.getInstance().getArcaneForgingEnchantLossEnabled() && !Permissions.arcaneBypass(player)) {
|
||||
// Generalize away enchantment work
|
||||
Repair.addEnchants(player, item);
|
||||
}
|
||||
@ -146,7 +148,7 @@ public class SimpleRepairManager implements RepairManager {
|
||||
removeOneFrom(inventory, repairItemLocation);
|
||||
|
||||
// Give out XP like candy
|
||||
Repair.xpHandler(player, profile, startDurability, newDurability, repairable.getXpMultiplier());
|
||||
Repair.xpHandler(mcMMOPlayer, startDurability, newDurability, repairable.getXpMultiplier());
|
||||
|
||||
// Repair the item!
|
||||
item.setDurability(newDurability);
|
||||
|
Reference in New Issue
Block a user