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:
bm01 2013-02-01 06:38:25 +01:00
parent d0c0b9a089
commit 7d83dd8283
56 changed files with 487 additions and 524 deletions

View File

@ -34,7 +34,7 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
*/
public static void addRawXP(Player player, SkillType skillType, int XP) {
Users.getPlayer(player).addXPOverride(skillType, XP);
Users.getPlayer(player).addXpOverride(skillType, XP);
checkXP(player, skillType);
}
@ -48,7 +48,7 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
*/
public static void addMultipliedXP(Player player, SkillType skillType, int XP) {
Users.getPlayer(player).addXPOverrideBonus(skillType, XP);
Users.getPlayer(player).addXpOverrideBonus(skillType, XP);
checkXP(player, skillType);
}
@ -62,7 +62,7 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
*/
public static void addXP(Player player, SkillType skillType, int XP) {
Users.getPlayer(player).addXP(skillType, XP);
Users.getPlayer(player).addXp(skillType, XP);
checkXP(player, skillType);
}
@ -158,7 +158,7 @@ public final class ExperienceAPI {
* @param newValue The value to set the XP to
*/
public static void setXP(Player player, SkillType skillType, int newValue) {
Users.getProfile(player).setSkillXPLevel(skillType, newValue);
Users.getProfile(player).setSkillXpLevel(skillType, newValue);
}
/**
@ -171,6 +171,6 @@ public final class ExperienceAPI {
* @param xp The amount of XP to remove
*/
public static void removeXP(Player player, SkillType skillType, int xp) {
Users.getProfile(player).removeXP(skillType, xp);
Users.getProfile(player).removeXp(skillType, xp);
}
}

View File

@ -44,7 +44,7 @@ public class AddxpCommand implements CommandExecutor {
PlayerProfile profile = Users.getProfile(modifiedPlayer);
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
mcMMOPlayer.addXPOverride(skill, xp);
mcMMOPlayer.addXpOverride(skill, xp);
if (skill.equals(SkillType.ALL)) {
modifiedPlayer.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", new Object[] {xp}));
@ -95,7 +95,7 @@ public class AddxpCommand implements CommandExecutor {
xp = Integer.valueOf(args[2]);
skill = SkillTools.getSkillType(args[1]);
mcMMOPlayer.addXPOverride(skill, xp);
mcMMOPlayer.addXpOverride(skill, xp);
if (skill.equals(SkillType.ALL)) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", new Object[] {playerName}));

View File

@ -11,14 +11,16 @@ import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomTool;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.spout.huds.SpoutHud;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class McMMOPlayer {
private Player player;
private PlayerProfile profile;
private Party party;
private Party invite;
@ -38,7 +40,10 @@ public class McMMOPlayer {
int powerLevel = 0;
for (SkillType type : SkillType.values()) {
if (type.isChildSkill()) continue;
if (type.isChildSkill()) {
continue;
}
if (type.getPermissions(player)) {
powerLevel += profile.getSkillLevel(type);
}
@ -48,12 +53,12 @@ public class McMMOPlayer {
}
/**
* Adds XP to the player, doesn't calculate for XP Rate
* Adds Xp to the player, doesn't calculate for Xp Rate
*
* @param skillType The skill to add XP to
* @param xp The amount of XP to add
* @param skillType The skill to add Xp to
* @param xp The amount of Xp to add
*/
public void addXPOverride(SkillType skillType, int xp) {
public void addXpOverride(SkillType skillType, int xp) {
if (skillType.equals(SkillType.ALL)) {
for (SkillType type : SkillType.values()) {
if (type.equals(SkillType.ALL) || type.isChildSkill()) {
@ -61,12 +66,12 @@ public class McMMOPlayer {
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, type, xp));
profile.setSkillXPLevel(type, profile.getSkillXpLevel(type) + xp);
profile.setSkillXpLevel(type, profile.getSkillXpLevel(type) + xp);
}
}
else {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
profile.setSkillXpLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
SpoutHud spoutHud = profile.getSpoutHud();
@ -77,33 +82,36 @@ public class McMMOPlayer {
}
/**
* Adds XP to the player, this ignores skill modifiers.
* Adds Xp to the player, this ignores skill modifiers.
*
* @param skillType The skill to add XP to
* @param xp The amount of XP to add
* @param skillType The skill to add Xp to
* @param xp The amount of Xp to add
*/
public void addXPOverrideBonus(SkillType skillType, int xp) {
public void addXpOverrideBonus(SkillType skillType, int xp) {
int modifiedXp = (int) Math.floor(xp * Config.getInstance().getExperienceGainsGlobalMultiplier());
addXPOverride(skillType, modifiedXp);
addXpOverride(skillType, modifiedXp);
}
/**
* Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
* Adds experience to the player, this is affected by skill modifiers, rate and permissions
*
* @param skillType The skill to add XP to
* @param xp The amount of XP to add
* @param skillType The skill to add Xp to
* @param xp The amount of Xp to add
*/
public void addXP(SkillType skillType, int xp) {
if (player == null)
return;
else if (player.getGameMode() == null)
return;
if (player.getGameMode().equals(GameMode.CREATIVE)) {
public void addXp(SkillType skillType, int xp) {
if ((skillType.getMaxLevel() < profile.getSkillLevel(skillType) + 1) || (Misc.getPowerLevelCap() < getPowerLevel() + 1)) {
return;
}
xp = (int)Math.floor((xp / skillType.getXpModifier()) * Config.getInstance().getExperienceGainsGlobalMultiplier());
if (player.getGameMode() == GameMode.CREATIVE) {
return;
}
if (party != null && !ShareHandler.isRunning()) {
ShareHandler.handleEqualXpShare(xp, player, party, skillType);
}
xp = (int) (xp / skillType.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier());
if (Config.getInstance().getToolModsEnabled()) {
ItemStack item = player.getItemInHand();
@ -114,30 +122,33 @@ public class McMMOPlayer {
}
}
// TODO: find a better way to do this, if possible
if (Permissions.xpQuadruple(player)) {
xp = xp * 4;
xp *= 4;
}
else if (Permissions.xpTriple(player)) {
xp = xp * 3;
xp *= 3;
}
else if (Permissions.xpDoubleAndOneHalf(player)) {
xp = (int) (xp * 2.5);
xp *= 2.5;
}
else if (Permissions.xpDouble(player)) {
xp = xp * 2;
xp *= 2;
}
else if (Permissions.xpOneAndOneHalf(player)) {
xp = (int) (xp * 1.5);
xp *= 1.5;
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
profile.setSkillXpLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
SpoutHud spoutHud = profile.getSpoutHud();
if (spoutHud != null) {
spoutHud.setLastGained(skillType);
}
SkillTools.xpCheckSkill(skillType, player, profile);
}
// Players & Profiles

View File

@ -26,20 +26,19 @@ public class PlayerProfile {
private String playerName;
/* HUD */
// HUD
private SpoutHud spoutHud;
private HudType hudType;
/* Party Stuff */
// Party Stuff
private Party party;
private Party invite;
private Player ptpRequest;
private boolean ptpEnabled = true;
private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
/* Toggles */
// Toggles
private boolean loaded;
private boolean placedAnvil;
private boolean placedSalvageAnvil;
private boolean partyChatMode, adminChatMode;
@ -51,17 +50,17 @@ public class PlayerProfile {
pickaxePreparationMode, axePreparationMode;
private boolean abilityUse = true;
/* Timestamps */
// Timestamps
private long recentlyHurt;
private int respawnATS;
private long lastSave = 0L;
private long ptpTimeout;
/* mySQL STUFF */
// mySQL STUFF
private int userId;
private HashMap<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); //Skills and Levels
HashMap<SkillType, Integer> skillsXp = new HashMap<SkillType, Integer>(); //Skills and XP
HashMap<SkillType, Integer> skillsXp = new HashMap<SkillType, Integer>(); //Skills and Xp
HashMap<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>();
HashMap<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
@ -316,7 +315,7 @@ public class PlayerProfile {
if (timestamp < (lastSave + ((long) Config.getInstance().getSaveInterval() * 60000)) && !override)
return;
// if we are using mysql save to database
// If we are using mysql save to database
if (Config.getInstance().getUseMySQL()) {
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
@ -362,7 +361,7 @@ public class PlayerProfile {
+ " WHERE user_id = " + userId);
}
else {
// otherwise save to flatfile
// Otherwise save to flatfile
try {
// Open the file
FileReader file = new FileReader(location);
@ -446,9 +445,9 @@ public class PlayerProfile {
out.append("0:"); // mining
out.append(":");
out.append(":");
out.append("0:"); //XP
out.append("0:"); // Xp
out.append("0:"); // woodcutting
out.append("0:"); //woodCuttingXP
out.append("0:"); // woodCuttingXp
out.append("0:"); // repair
out.append("0:"); // unarmed
out.append("0:"); // herbalism
@ -457,17 +456,17 @@ public class PlayerProfile {
out.append("0:"); // swords
out.append("0:"); // axes
out.append("0:"); // acrobatics
out.append("0:"); //repairXP
out.append("0:"); //unarmedXP
out.append("0:"); //herbalismXP
out.append("0:"); //excavationXP
out.append("0:"); //archeryXP
out.append("0:"); //swordsXP
out.append("0:"); //axesXP
out.append("0:"); //acrobaticsXP
out.append("0:"); // repairXp
out.append("0:"); // unarmedXp
out.append("0:"); // herbalismXp
out.append("0:"); // excavationXp
out.append("0:"); // archeryXp
out.append("0:"); // swordsXp
out.append("0:"); // axesXp
out.append("0:"); // acrobaticsXp
out.append(":");
out.append("0:"); // taming
out.append("0:"); //tamingXP
out.append("0:"); // tamingXp
out.append("0:"); // DATS
out.append("0:"); // DATS
out.append("0:"); // DATS
@ -477,7 +476,7 @@ public class PlayerProfile {
out.append("0:"); // DATS
out.append(hudType.toString()).append(":"); // HUD
out.append("0:"); // Fishing
out.append("0:"); //FishingXP
out.append("0:"); // FishingXp
out.append("0:"); // Blast Mining
// Add more in the same format as the line above
@ -918,7 +917,7 @@ public class PlayerProfile {
}
/*
* XP Functions
* Xp Functions
*/
public int getSkillLevel(SkillType skillType) {
@ -943,7 +942,7 @@ public class PlayerProfile {
return skillsXp.get(skillType);
}
public void setSkillXPLevel(SkillType skillType, int newValue) {
public void setSkillXpLevel(SkillType skillType, int newValue) {
skillsXp.put(skillType, newValue);
save(false);
}
@ -954,12 +953,12 @@ public class PlayerProfile {
}
// /**
// * Adds XP to the player, doesn't calculate for XP Rate
// * Adds Xp to the player, doesn't calculate for Xp Rate
// *
// * @param skillType The skill to add XP to
// * @param newValue The amount of XP to add
// * @param skillType The skill to add Xp to
// * @param newValue The amount of Xp to add
// */
// public void addXPOverride(SkillType skillType, int newValue) {
// public void addXpOverride(SkillType skillType, int newValue) {
// if (skillType.equals(SkillType.ALL)) {
// for (SkillType x : SkillType.values()) {
// if (x.equals(SkillType.ALL)) {
@ -978,23 +977,23 @@ public class PlayerProfile {
// }
// /**
// * Adds XP to the player, this ignores skill modifiers.
// * Adds Xp to the player, this ignores skill modifiers.
// *
// * @param skillType The skill to add XP to
// * @param newValue The amount of XP to add
// * @param skillType The skill to add Xp to
// * @param newValue The amount of Xp to add
// */
// public void addXPOverrideBonus(SkillType skillType, int newValue) {
// public void addXpOverrideBonus(SkillType skillType, int newValue) {
// int xp = newValue * Config.getInstance().xpGainMultiplier;
// addXPOverride(skillType, xp);
// addXpOverride(skillType, xp);
// }
// /**
// * Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
// * Adds Xp to the player, this is affected by skill modifiers and Xp Rate and Permissions
// *
// * @param skillType The skill to add XP to
// * @param newvalue The amount of XP to add
// * @param skillType The skill to add Xp to
// * @param newvalue The amount of Xp to add
// */
// public void addXP(SkillType skillType, int newValue) {
// public void addXp(SkillType skillType, int newValue) {
// if (player.getGameMode().equals(GameMode.CREATIVE)) {
// return;
// }
@ -1048,12 +1047,12 @@ public class PlayerProfile {
// }
/**
* Remove XP from a skill.
* Remove Xp from a skill.
*
* @param skillType Type of skill to modify
* @param xp Amount of xp to remove
*/
public void removeXP(SkillType skillType, int xp) {
public void removeXp(SkillType skillType, int xp) {
if (skillType.isChildSkill()) {
return;
}
@ -1130,10 +1129,10 @@ public class PlayerProfile {
}
/**
* Get the amount of XP remaining before the next level.
* Get the amount of Xp remaining before the next level.
*
* @param skillType Type of skill to check
* @return the XP remaining until next level
* @return the Xp remaining until next level
*/
public int getXpToLevel(SkillType skillType) {
return 1020 + (skills.get(skillType) * Config.getInstance().getFormulaMultiplierCurve());
@ -1157,7 +1156,7 @@ public class PlayerProfile {
// }
// /**
// * Calculate the party XP modifier.
// * Calculate the party Xp modifier.
// *
// * @param skillType Type of skill to check
// * @return the party bonus multiplier

View File

@ -22,6 +22,7 @@ import org.bukkit.metadata.FixedMetadataValue;
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.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
@ -137,9 +138,10 @@ public class BlockListener implements Listener {
}
Player player = event.getPlayer();
PlayerProfile profile = Users.getProfile(player);
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
if (Misc.isNPCPlayer(player, profile)) {
if (Misc.isNPCPlayer(player, mcMMOPlayer.getProfile())) {
return;
}
@ -158,10 +160,10 @@ public class BlockListener implements Listener {
* Instead, we check it inside the drops handler.
*/
if (Permissions.herbalism(player)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); //Double drops
Herbalism.herbalismProcCheck(block, mcMMOPlayer, event, plugin); //Double drops
if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); //Triple drops
Herbalism.herbalismProcCheck(block, mcMMOPlayer, event, plugin); //Triple drops
}
}
}
@ -170,12 +172,12 @@ public class BlockListener implements Listener {
else if (BlockChecks.canBeSuperBroken(block) && Permissions.mining(player) && !mcMMO.placeStore.isTrue(block)) {
if (Mining.requiresTool) {
if (ItemChecks.isPickaxe(heldItem)) {
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(mcMMOPlayer);
miningManager.miningBlockCheck(block);
}
}
else {
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(mcMMOPlayer);
miningManager.miningBlockCheck(block);
}
}
@ -183,16 +185,16 @@ public class BlockListener implements Listener {
/* WOOD CUTTING */
else if (BlockChecks.isLog(block) && Permissions.woodcutting(player) && !mcMMO.placeStore.isTrue(block)) {
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemChecks.isAxe(heldItem)) {
Woodcutting.beginTreeFeller(event);
Woodcutting.beginTreeFeller(mcMMOPlayer, block);
}
else {
if (Config.getInstance().getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(heldItem)) {
Woodcutting.beginWoodcutting(player, block);
Woodcutting.beginWoodcutting(mcMMOPlayer, block);
}
}
else {
Woodcutting.beginWoodcutting(player, block);
Woodcutting.beginWoodcutting(mcMMOPlayer, block);
}
}
}
@ -201,11 +203,11 @@ public class BlockListener implements Listener {
else if (BlockChecks.canBeGigaDrillBroken(block) && Permissions.excavation(player) && !mcMMO.placeStore.isTrue(block)) {
if (Excavation.requiresTool) {
if (ItemChecks.isShovel(heldItem)) {
Excavation.excavationProcCheck(block, player);
Excavation.excavationProcCheck(block, mcMMOPlayer);
}
}
else {
Excavation.excavationProcCheck(block, player);
Excavation.excavationProcCheck(block, mcMMOPlayer);
}
}
@ -239,7 +241,7 @@ public class BlockListener implements Listener {
Herbalism.hylianLuck(block, player, event);
}
else if (BlockChecks.canBeFluxMined(block) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(block)) {
SmeltingManager smeltingManager = new SmeltingManager(player);
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
smeltingManager.fluxMining(event);
}
}
@ -311,7 +313,8 @@ public class BlockListener implements Listener {
}
Player player = event.getPlayer();
PlayerProfile profile = Users.getProfile(player);
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
if (Misc.isNPCPlayer(player, profile)) {
return;
@ -332,12 +335,12 @@ public class BlockListener implements Listener {
if (Excavation.requiresTool) {
if (ItemChecks.isShovel(heldItem)) {
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
Excavation.gigaDrillBreaker(mcMMOPlayer, block);
}
}
else {
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
Excavation.gigaDrillBreaker(mcMMOPlayer, block);
}
}
else if (profile.getAbilityMode(AbilityType.BERSERK) && SkillTools.triggerCheck(player, block, AbilityType.BERSERK)) {
@ -351,7 +354,7 @@ public class BlockListener implements Listener {
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
}
else if (profile.getAbilityMode(AbilityType.SUPER_BREAKER) && SkillTools.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(mcMMOPlayer);
if (Mining.requiresTool) {
if (ItemChecks.isPickaxe(heldItem)) {

View File

@ -27,6 +27,7 @@ import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
@ -153,7 +154,8 @@ public class EntityListener implements Listener {
return;
}
PlayerProfile profile = Users.getProfile(player);
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
if (Misc.isNPCPlayer(player, profile)) {
return;
@ -167,11 +169,11 @@ public class EntityListener implements Listener {
if (!Misc.isInvincible(player, event)) {
if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) {
AcrobaticsManager acroManager = new AcrobaticsManager(player);
acroManager.rollCheck(event);
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(mcMMOPlayer);
acrobaticsManager.rollCheck(event);
}
else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.demolitionsExpertise(player)) {
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(mcMMOPlayer);
miningManager.demolitionsExpertise(event);
}
@ -185,7 +187,7 @@ public class EntityListener implements Listener {
AnimalTamer owner = pet.getOwner();
if ((!Misc.isInvincible(livingEntity, event)) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) {
TamingManager tamingManager = new TamingManager((Player) owner);
TamingManager tamingManager = new TamingManager(Users.getPlayer((Player) owner));
tamingManager.preventDamage(event);
}
}
@ -244,7 +246,7 @@ public class EntityListener implements Listener {
Player player = plugin.getTNTPlayer(id);
if (Permissions.biggerBombs(player)) {
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.biggerBombs(event);
}
}
@ -266,7 +268,7 @@ public class EntityListener implements Listener {
if (plugin.tntIsTracked(id)) {
Player player = plugin.getTNTPlayer(id);
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.blastMiningDropProcessing(event);
plugin.removeFromTNTTracker(id);
@ -347,7 +349,7 @@ public class EntityListener implements Listener {
return;
}
TamingManager tamingManager = new TamingManager(player);
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
tamingManager.awardTamingXP(event);
}
}

View File

@ -19,6 +19,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Users;
public class InventoryListener implements Listener{
private final mcMMO plugin;
@ -80,7 +81,7 @@ public class InventoryListener implements Listener{
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (player != null) {
SmeltingManager smeltingManager = new SmeltingManager(player);
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
smeltingManager.fuelEfficiency(event);
}
}
@ -100,7 +101,7 @@ public class InventoryListener implements Listener{
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (player != null) {
SmeltingManager smeltingManager = new SmeltingManager(player);
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
smeltingManager.smeltProcessing(event);
}
}
@ -117,7 +118,7 @@ public class InventoryListener implements Listener{
ItemStack result = inventory.getResult();
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemChecks.isSmelted(result)) {
SmeltingManager smeltingManager = new SmeltingManager(plugin.getFurnacePlayer(furnaceBlock));
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(plugin.getFurnacePlayer(furnaceBlock)));
smeltingManager.vanillaXPBoost(event);
}
}

View File

@ -91,7 +91,7 @@ public class PlayerListener implements Listener {
switch (event.getState()) {
case CAUGHT_FISH:
Fishing.beginFishing(player, skillLevel, event);
Fishing.beginFishing(Users.getPlayer(player), skillLevel, event);
break;
case CAUGHT_ENTITY:
@ -200,31 +200,28 @@ public class PlayerListener implements Listener {
/* REPAIR CHECKS */
if (blockID == Repair.anvilID && Permissions.repair(player) && mcMMO.repairManager.isRepairable(heldItem)) {
mcMMO.repairManager.handleRepair(player, heldItem);
mcMMO.repairManager.handleRepair(Users.getPlayer(player), heldItem);
event.setCancelled(true);
player.updateInventory();
}
/* SALVAGE CHECKS */
else if (blockID == Salvage.anvilID && Permissions.salvage(player) && Salvage.isSalvageable(heldItem)) {
Salvage.handleSalvage(player, block.getLocation(), heldItem);
event.setCancelled(true);
player.updateInventory();
}
/* BLAST MINING CHECK */
else if (player.isSneaking() && Permissions.blastMining(player) && heldItem.getTypeId() == BlastMining.detonatorID) {
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.detonate(event);
}
break;
case RIGHT_CLICK_AIR:
/* BLAST MINING CHECK */
if (player.isSneaking() && Permissions.blastMining(player) && heldItem.getTypeId() == BlastMining.detonatorID) {
MiningManager miningManager = new MiningManager(player);
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.detonate(event);
}
@ -305,11 +302,11 @@ public class PlayerListener implements Listener {
Material type = heldItem.getType();
if (type == Material.RAW_FISH) {
TamingManager tamingManager = new TamingManager(player);
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
tamingManager.summonOcelot();
}
else if (type == Material.BONE) {
TamingManager tamingManager = new TamingManager(player);
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
tamingManager.summonWolf();
}
}

View File

@ -13,7 +13,7 @@ public class Party {
private String name;
private String password;
private boolean locked;
private String expShareMode;
private ShareHandler.XpShareMode xpShareMode;
public List<String> getMembers() {
return members;
@ -64,11 +64,11 @@ public class Party {
this.locked = locked;
}
public void setExpShareMode(String expShareMode) {
this.expShareMode = expShareMode;
public void setXpShareMode(ShareHandler.XpShareMode xpShareMode) {
this.xpShareMode = xpShareMode;
}
public String getExpShareMode() {
return expShareMode;
public ShareHandler.XpShareMode getXpShareMode() {
return xpShareMode;
}
}

View File

@ -244,7 +244,7 @@ public final class PartyManager {
party.setName(partyName);
party.setLeader(playerName);
party.setExpShareMode("NO_SHARE");
party.setXpShareMode(ShareHandler.XpShareMode.NONE);
party.setLocked(true);//Parties are now invite-only by default, can be set to open with /party unlock
if (password != null) {
@ -459,7 +459,7 @@ public final class PartyManager {
party.setLeader(partiesFile.getString(partyName + ".Leader"));
party.setPassword(partiesFile.getString(partyName + ".Password"));
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
party.setExpShareMode(partiesFile.getString(partyName + ".ExpShareMode"));
party.setXpShareMode(ShareHandler.XpShareMode.getFromString(partiesFile.getString(partyName + ".ExpShareMode")));
party.getMembers().addAll(partiesFile.getStringList(partyName + ".Members"));
parties.add(party);
@ -484,7 +484,7 @@ public final class PartyManager {
partiesFile.set(partyName + ".Leader", party.getLeader());
partiesFile.set(partyName + ".Password", party.getPassword());
partiesFile.set(partyName + ".Locked", party.isLocked());
partiesFile.set(partyName + ".ExpShareMode", party.getExpShareMode());
partiesFile.set(partyName + ".ExpShareMode", party.getXpShareMode().toString());
partiesFile.set(partyName + ".Members", party.getMembers());
try {

View File

@ -9,68 +9,51 @@ import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Users;
public class ShareHandler {
public final class ShareHandler {
public enum XpShareMode {
NONE,
EQUAL;
public static boolean expShareEnabled = Config.getInstance().getExpShareEnabled();
public static boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
public static double partyShareRange = Config.getInstance().getPartyShareRange();
public static double partyShareBonus = Config.getInstance().getPartyShareBonus();
// protected enum PartyShareType {
// NO_SHARE,
// RANDOM,
// EQUAL,
// };
public static double checkXpSharing(int oldExp, Player player, Party party) {
int newExp = oldExp;
if (party.getExpShareMode() == null) {
party.setExpShareMode("NO_SHARE");
public static XpShareMode getFromString(String string) {
try {
return valueOf(string);
}
if (party.getExpShareMode().equals("NO_SHARE")) {
return newExp;
catch (IllegalArgumentException exception) {
return NONE;
}
else if (party.getExpShareMode().equals("EQUAL")) {
newExp = (int) calculateSharedExp(oldExp, player, party);
}
};
return newExp;
}
/**
* Calculate the party XP.
*
* @param oldExp XP without party sharing
* @return the party shared XP
*/
public static double calculateSharedExp(int oldExp, Player player, Party party) {
int newExp = oldExp;
List<Player> nearMembers = PartyManager.getNearMembers(player, party, partyShareRange);
if (nearMembers.size() > 0) {
newExp = (int) ((oldExp / (nearMembers.size() + 1)) * partyShareBonus);
}
return newExp;
}
private static boolean running; // Used to prevent permanent sharing, McMMOPlayer.addXp() uses it
private ShareHandler() {}
/**
* Distribute XP amongst party members.
*
* @param xp XP without party sharing
*/
public static void handleEqualExpShare(int xp, Player player, Party party, SkillType skillType) {
List<Player> nearMembers = PartyManager.getNearMembers(player, party, partyShareRange);
public static void handleEqualXpShare(int xp, Player player, Party party, SkillType skillType) {
running = true;
int newExp = xp;
if (party.getXpShareMode() == XpShareMode.EQUAL) {
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
if (nearMembers.size() > 0) {
newExp = (int) ((xp / (nearMembers.size() + 1)) * Config.getInstance().getPartyShareBonus());
}
for (Player member : nearMembers) {
if (nearMembers.size() > 0) {
Users.getPlayer(member).addXP(skillType, xp);
Users.getPlayer(member).addXp(skillType, newExp);
SkillTools.xpCheckSkill(skillType, member, Users.getProfile(member));
}
}
running = false;
}
public static boolean isRunning() {
return running;
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
@ -110,7 +111,7 @@ public class PartyCommand implements CommandExecutor {
String leader = party.getLeader();
StringBuilder tempList = new StringBuilder();
int membersNear = PartyManager.getNearMembers(player, party, ShareHandler.partyShareRange).size();
int membersNear = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()).size();
int membersOnline = party.getOnlineMembers().size() - 1;
String ItemShare = "";
@ -139,16 +140,22 @@ public class PartyCommand implements CommandExecutor {
player.sendMessage(LocaleLoader.getString("Commands.Party.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", new Object[] {party.getName(), status}));
if (ShareHandler.expShareEnabled) {
ExpShare = LocaleLoader.getString("Commands.Party.ExpShare", new Object[] { party.getExpShareMode() });
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
if (xpShareEnabled) {
ExpShare = LocaleLoader.getString("Commands.Party.ExpShare", new Object[] { party.getXpShareMode().toString() });
}
if (ShareHandler.itemShareEnabled) {
if (itemShareEnabled) {
ItemShare = LocaleLoader.getString("Commands.Party.ItemShare", new Object[] { itemShareMode });
}
if (ShareHandler.expShareEnabled && ShareHandler.itemShareEnabled) {
if (xpShareEnabled && itemShareEnabled) {
Split = ChatColor.DARK_GRAY + " || ";
}
if (ShareHandler.expShareEnabled || ShareHandler.itemShareEnabled) {
if (xpShareEnabled || itemShareEnabled) {
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + ExpShare + Split + ItemShare);
}
@ -350,8 +357,10 @@ public class PartyCommand implements CommandExecutor {
}
private boolean shareExp(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare"))
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare")) {
return true;
}
String playerName = player.getName();
PlayerProfile playerProfile = Users.getProfile(player);
Party party = playerProfile.getParty();
@ -362,18 +371,21 @@ public class PartyCommand implements CommandExecutor {
}
if (party.getLeader().equals(playerName)) {
if(args[1].equalsIgnoreCase("noshare") || args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("false")) {
party.setExpShareMode("NONE");
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("false")) {
party.setXpShareMode(ShareHandler.XpShareMode.getFromString("NONE"));
for (Player onlineMembers : party.getOnlineMembers()) {
onlineMembers.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", new Object[] {LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode.NoShare")}));
}
} else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
party.setExpShareMode("EQUAL");
party.setXpShareMode(ShareHandler.XpShareMode.getFromString("EQUAL"));
for (Player onlineMembers : party.getOnlineMembers()) {
onlineMembers.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", new Object[] {LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode.Equal")}));
}
}
}
return true;
}

View File

@ -1,32 +1,23 @@
package com.gmail.nossr50.skills;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
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 abstract class SkillManager {
protected Player player;
protected PlayerProfile profile;
protected McMMOPlayer mcMMOPlayer;
protected int skillLevel;
protected int activationChance;
public SkillManager(Player player, SkillType skill) {
this.player = player;
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(skill);
this.activationChance = Misc.calculateActivationChance(Permissions.lucky(player, skill));
public SkillManager(McMMOPlayer mcMMOPlayer, SkillType skill) {
this.mcMMOPlayer = mcMMOPlayer;
this.skillLevel = mcMMOPlayer.getProfile().getSkillLevel(skill);
this.activationChance = Misc.calculateActivationChance(Permissions.lucky(mcMMOPlayer.getPlayer(), skill));
}
public Player getPlayer() {
return player;
}
public PlayerProfile getProfile() {
return profile;
public McMMOPlayer getMcMMOPlayer() {
return mcMMOPlayer;
}
public int getSkillLevel() {

View File

@ -7,7 +7,6 @@ import com.gmail.nossr50.util.Misc;
public abstract class AcrobaticsEventHandler {
protected AcrobaticsManager manager;
protected Player player;
protected EntityDamageEvent event;
protected int damage;
@ -16,7 +15,6 @@ public abstract class AcrobaticsEventHandler {
protected AcrobaticsEventHandler(AcrobaticsManager manager, EntityDamageEvent event) {
this.manager = manager;
this.player = manager.getPlayer();
this.event = event;
this.damage = event.getDamage();
}
@ -42,9 +40,9 @@ public abstract class AcrobaticsEventHandler {
protected abstract void sendAbilityMessage();
/**
* Process XP gain from this event.
* Process Xp gain from this event.
*/
protected abstract void processXPGain(int xp);
protected abstract void processXpGain(int xp);
/**
* Check to ensure you're not gaining XP after you die.
@ -53,6 +51,8 @@ public abstract class AcrobaticsEventHandler {
* @return true if the damage is fatal, false otherwise
*/
protected boolean isFatal(int damage) {
Player player = manager.getMcMMOPlayer().getPlayer();
if (Misc.isNPCPlayer(player) || player.getHealth() - damage < 1) {
return true;
}

View File

@ -1,15 +1,15 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
public class AcrobaticsManager extends SkillManager {
public AcrobaticsManager (Player player) {
super(player, SkillType.ACROBATICS);
public AcrobaticsManager (McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.ACROBATICS);
}
/**
@ -32,10 +32,10 @@ public class AcrobaticsManager extends SkillManager {
if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXPGain(eventHandler.damage * Acrobatics.rollXpModifier);
eventHandler.processXpGain(eventHandler.damage * Acrobatics.rollXpModifier);
}
else if (!eventHandler.isFatal(event.getDamage())) {
eventHandler.processXPGain(eventHandler.damage * Acrobatics.fallXpModifier);
eventHandler.processXpGain(eventHandler.damage * Acrobatics.fallXpModifier);
}
}
@ -52,7 +52,7 @@ public class AcrobaticsManager extends SkillManager {
if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXPGain(eventHandler.damage * Acrobatics.dodgeXpModifier);
eventHandler.processXpGain(eventHandler.damage * Acrobatics.dodgeXpModifier);
}
}
}

View File

@ -2,9 +2,8 @@ package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
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;
@ -39,15 +38,15 @@ public class DodgeEventHandler extends AcrobaticsEventHandler {
@Override
protected void sendAbilityMessage() {
player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
}
@Override
protected void processXPGain(int xp) {
PlayerProfile profile = manager.getProfile();
protected void processXpGain(int xp) {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
if (System.currentTimeMillis() >= profile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) {
SkillTools.xpProcessing(player, profile, SkillType.ACROBATICS, xp);
if (System.currentTimeMillis() >= mcMMOPlayer.getProfile().getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) {
manager.getMcMMOPlayer().addXp(SkillType.ACROBATICS, xp);
}
}
}

View File

@ -1,9 +1,9 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
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;
@ -56,6 +56,8 @@ public class RollEventHandler extends AcrobaticsEventHandler {
@Override
protected void sendAbilityMessage() {
Player player = manager.getMcMMOPlayer().getPlayer();
if (isGraceful) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
}
@ -66,14 +68,16 @@ public class RollEventHandler extends AcrobaticsEventHandler {
@Override
protected void processXPGain(int xpGain) {
SkillTools.xpProcessing(player, manager.getProfile(), SkillType.ACROBATICS, xpGain);
protected void processXpGain(int xp) {
manager.getMcMMOPlayer().addXp(SkillType.ACROBATICS, xp);
}
/**
* Check if this is a graceful roll.
*/
private void isGracefulRoll() {
Player player = manager.getMcMMOPlayer().getPlayer();
if (Permissions.gracefulRoll(player)) {
this.isGraceful = player.isSneaking();
}

View File

@ -5,24 +5,25 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
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;
public class ArcheryManager extends SkillManager {
public ArcheryManager (Player player) {
super(player, SkillType.ARCHERY);
public ArcheryManager (McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.ARCHERY);
}
public void distanceXpBonus(LivingEntity target) {
Player player = mcMMOPlayer.getPlayer();
Location shooterLocation = player.getEyeLocation();
Location targetLocation = target.getLocation();
double squaredDistance = shooterLocation.distanceSquared(targetLocation);
int bonusXp = (int) (squaredDistance * Archery.distanceXpModifer);
SkillTools.xpProcessing(player, profile, SkillType.ARCHERY, bonusXp);
mcMMOPlayer.addXp(SkillType.ARCHERY, bonusXp);
}
/**
@ -63,7 +64,7 @@ public class ArcheryManager extends SkillManager {
* @param event The event to modify.
*/
public void skillShot(EntityDamageEvent event) {
if (skillLevel >= Archery.skillShotIncreaseLevel && Permissions.archeryBonus(player)) {
if (skillLevel >= Archery.skillShotIncreaseLevel && Permissions.archeryBonus(mcMMOPlayer.getPlayer())) {
SkillShotEventHandler eventHandler = new SkillShotEventHandler(this, event);
eventHandler.calculateDamageBonus();

View File

@ -44,6 +44,6 @@ public class DazeEventHandler {
protected void sendAbilityMessages() {
defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy"));
manager.getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
}
}

View File

@ -1,16 +1,16 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
public class AxeManager extends SkillManager {
public AxeManager(Player player) {
super(player, SkillType.AXES);
public AxeManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.AXES);
}
/**
@ -64,7 +64,7 @@ public class AxeManager extends SkillManager {
* @param damage The base damage to deal
*/
public void skullSplitter(LivingEntity target, int damage) {
SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(player, damage, target);
SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(mcMMOPlayer.getPlayer(), damage, target);
eventHandler.applyAbilityEffects();
}
}

View File

@ -34,7 +34,7 @@ public class CriticalHitEventHandler {
}
protected void sendAbilityMessages() {
manager.getPlayer().sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
if (defender instanceof Player) {
((Player) defender).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));

View File

@ -18,12 +18,11 @@ public class ImpactEventHandler {
private short durabilityDamage = 1;
private EntityEquipment equipment;
private ItemStack[] armorContents;
protected LivingEntity defender;
public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
this.manager = manager;
this.player = manager.getPlayer();
this.player = manager.getMcMMOPlayer().getPlayer();
this.event = event;
this.defender = defender;
this.equipment = defender.getEquipment();
@ -31,7 +30,7 @@ public class ImpactEventHandler {
}
protected void damageArmor() {
/* Every 50 Skill Levels you gain 1 durability damage (default values) */
// Every 50 Skill Levels you gain 1 durability damage (default values)
durabilityDamage += (short) (manager.getSkillLevel() / Axes.impactIncreaseLevel);
for (ItemStack armor : armorContents) {

View File

@ -8,12 +8,11 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.mods.ModChecks;
@ -21,7 +20,6 @@ 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 Excavation {
public static boolean requiresTool = Config.getInstance().getExcavationRequiresTool();
@ -30,21 +28,13 @@ public class Excavation {
* Check to see if treasures were found.
*
* @param block The block to check
* @param player The player who broke the block
* @param mcMMOPlayer The player who broke the block
*/
public static void excavationProcCheck(Block block, Player player) {
Material type = block.getType();
Location location = block.getLocation();
PlayerProfile profile = Users.getProfile(player);
int skillLevel = profile.getSkillLevel(SkillType.EXCAVATION);
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
public static void excavationProcCheck(Block block, McMMOPlayer mcMMOPlayer) {
Material material = block.getType();
int xp;
switch (type) {
switch (material) {
case CLAY:
xp = Config.getInstance().getExcavationClayXP();
break;
@ -78,8 +68,11 @@ public class Excavation {
break;
}
Player player = mcMMOPlayer.getPlayer();
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
if (Permissions.excavationTreasures(player)) {
switch (type) {
switch (material) {
case DIRT:
treasures = TreasuresConfig.getInstance().excavationFromDirt;
break;
@ -112,43 +105,40 @@ public class Excavation {
break;
}
Location location = block.getLocation();
for (ExcavationTreasure treasure : treasures) {
if (skillLevel >= treasure.getDropLevel()) {
if (mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION) >= treasure.getDropLevel()) {
int activationChance = Misc.calculateActivationChance(Permissions.luckyExcavation(player));
if (Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
xp += treasure.getXp();
is.add(treasure.getDrop());
Misc.dropItem(location, treasure.getDrop());
}
}
}
}
//Drop items
for (ItemStack x : is) {
if (x != null) {
Misc.dropItem(location, x);
}
}
}
SkillTools.xpProcessing(player, profile, SkillType.EXCAVATION, xp);
mcMMOPlayer.addXp(SkillType.EXCAVATION, xp);
}
/**
* Handle triple drops from Giga Drill Breaker.
*
* @param player The player using the ability
* @param mcMMOPlayer The player using the ability
* @param block The block to check
*/
public static void gigaDrillBreaker(Player player, Block block) {
public static void gigaDrillBreaker(McMMOPlayer mcMMOplayer, Block block) {
Player player = mcMMOplayer.getPlayer();
SkillTools.abilityDurabilityLoss(player.getItemInHand(), Misc.toolDurabilityLoss);
if (!mcMMO.placeStore.isTrue(block) && Misc.blockBreakSimulate(block, player, true)) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
Excavation.excavationProcCheck(block, player);
Excavation.excavationProcCheck(block, player);
Excavation.excavationProcCheck(block, mcMMOplayer);
Excavation.excavationProcCheck(block, mcMMOplayer);
}
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);

View File

@ -15,6 +15,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
@ -22,7 +23,6 @@ import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public final class Fishing {
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
@ -103,12 +103,13 @@ public final class Fishing {
/**
* Begins Fishing
*
* @param player Player fishing
* @param mcMMOPlayer Player fishing
* @param skillLevel Fishing level of the player
* @param event Event to process
*/
public static void beginFishing(Player player, int skillLevel, PlayerFishEvent event) {
public static void beginFishing(McMMOPlayer mcMMOPlayer, int skillLevel, PlayerFishEvent event) {
int treasureXp = 0;
Player player = mcMMOPlayer.getPlayer();
FishingTreasure treasure = checkForTreasure(player, skillLevel);
if (treasure != null) {
@ -127,7 +128,7 @@ public final class Fishing {
caught.setItemStack(treasureDrop);
}
SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.FISHING, Config.getInstance().getFishingBaseXP() + treasureXp);
mcMMOPlayer.addXp(SkillType.FISHING, Config.getInstance().getFishingBaseXP() + treasureXp);
event.setExpToDrop(event.getExpToDrop() * getVanillaXpMultiplier(skillLevel));
}

View File

@ -18,6 +18,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
@ -141,11 +142,13 @@ public class Herbalism {
* Check for extra Herbalism drops.
*
* @param block The block to check for extra drops
* @param player The player getting extra drops
* @param mcMMOPlayer The player getting extra drops
* @param event The event to use for Green Thumb
* @param plugin mcMMO plugin instance
*/
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
public static void herbalismProcCheck(final Block block, McMMOPlayer mcMMOPlayer, BlockBreakEvent event, mcMMO plugin) {
Player player = mcMMOPlayer.getPlayer();
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
return;
}
@ -209,7 +212,7 @@ public class Herbalism {
}
}
SkillTools.xpProcessing(player, profile, SkillType.HERBALISM, xp);
mcMMOPlayer.addXp(SkillType.HERBALISM, xp);
}
/**

View File

@ -10,21 +10,19 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc;
public class BlastMiningDropEventHandler {
private MiningManager manager;
private int skillLevel;
private EntityExplodeEvent event;
private float yield;
private List<Block> blocks;
private List<Block> ores = new ArrayList<Block>();
private List<Block> debris = new ArrayList<Block>();
private List<Block> droppedOres = new ArrayList<Block>();
private float oreBonus;
private float debrisReduction;
private int dropMultiplier;
@ -36,7 +34,6 @@ public class BlastMiningDropEventHandler {
this.event = event;
this.yield = event.getYield();
this.blocks = event.blockList();
}
protected void sortExplosionBlocks() {
@ -51,9 +48,11 @@ public class BlastMiningDropEventHandler {
}
protected void processXPGain() {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
for (Block block : droppedOres) {
if (!mcMMO.placeStore.isTrue(block)) {
Mining.miningXP(manager.getPlayer(), manager.getProfile(), block, block.getType());
Mining.miningXP(mcMMOPlayer, block, block.getType());
}
}
}

View File

@ -4,7 +4,6 @@ import org.bukkit.event.entity.EntityDamageEvent;
public class DemoltionsExpertiseEventHandler {
private int skillLevel;
private EntityDamageEvent event;
private int damage;
private double damageModifier;

View File

@ -5,16 +5,14 @@ import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
@ -35,10 +33,10 @@ public class Mining {
/**
* Award XP for Mining blocks.
*
* @param player The player to award XP to
* @param mcMMOPlayer The player to award XP to
* @param block The block to award XP for
*/
protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) {
protected static void miningXP(McMMOPlayer mcMMOPlayer, Block block, Material type) {
int xp = 0;
switch (type) {
@ -106,7 +104,7 @@ public class Mining {
break;
}
SkillTools.xpProcessing(player, profile, SkillType.MINING, xp);
mcMMOPlayer.addXp(SkillType.MINING, xp);
}
/**

View File

@ -4,24 +4,18 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import com.gmail.nossr50.util.Misc;
public class MiningBlockEventHandler {
private MiningManager manager;
private Player player;
private Block block;
private Location blockLocation;
private Material blockType;
protected int skillModifier;
protected MiningBlockEventHandler(MiningManager manager, Block block) {
this.manager = manager;
this.player = manager.getPlayer();
this.block = block;
this.blockLocation = block.getLocation();
this.blockType = block.getType();
@ -37,7 +31,7 @@ public class MiningBlockEventHandler {
* Process Mining block drops.
*/
protected void processDrops() {
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
if (manager.getMcMMOPlayer().getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
Mining.silkTouchDrops(block, blockLocation, blockType);
}
else {
@ -46,6 +40,6 @@ public class MiningBlockEventHandler {
}
protected void processXPGain() {
Mining.miningXP(player, manager.getProfile(), block, blockType);
Mining.miningXP(manager.getMcMMOPlayer(), block, blockType);
}
}

View File

@ -2,21 +2,21 @@ package com.gmail.nossr50.skills.mining;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class MiningManager extends SkillManager{
public MiningManager (Player player) {
super(player, SkillType.MINING);
public MiningManager (McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.MINING);
}
/**
@ -33,11 +33,11 @@ public class MiningManager extends SkillManager{
eventHandler.targetTNT();
if (eventHandler.block.getType() != Material.TNT) {
if (eventHandler.getBlock().getType() != Material.TNT) {
return;
}
if (!Misc.blockBreakSimulate(eventHandler.block, player, true)) {
if (!Misc.blockBreakSimulate(eventHandler.getBlock(), mcMMOPlayer.getPlayer(), true)) {
return;
}
@ -56,7 +56,7 @@ public class MiningManager extends SkillManager{
* @param event Event whose explosion is being processed
*/
public void blastMiningDropProcessing(EntityExplodeEvent event) {
if (Misc.isNPCPlayer(player)) {
if (Misc.isNPCPlayer(mcMMOPlayer.getPlayer())) {
return;
}
@ -93,7 +93,7 @@ public class MiningManager extends SkillManager{
* @param event Event whose explosion radius is being changed
*/
public void biggerBombs(ExplosionPrimeEvent event) {
if (Misc.isNPCPlayer(player)) {
if (Misc.isNPCPlayer(mcMMOPlayer.getPlayer())) {
return;
}
@ -112,7 +112,7 @@ public class MiningManager extends SkillManager{
MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block);
eventHandler.processXPGain();
if (!Permissions.miningDoubleDrops(player)) {
if (!Permissions.miningDoubleDrops(mcMMOPlayer.getPlayer())) {
return;
}
@ -129,7 +129,7 @@ public class MiningManager extends SkillManager{
* @param block The block being affected
*/
public void superBreakerBlockCheck(Block block) {
if (mcMMO.placeStore.isTrue(block) || !Misc.blockBreakSimulate(block, player, true)) {
if (mcMMO.placeStore.isTrue(block) || !Misc.blockBreakSimulate(block, mcMMOPlayer.getPlayer(), true)) {
return;
}

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.player.PlayerInteractEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.AbilityType;
@ -16,18 +17,13 @@ import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.util.Misc;
public class RemoteDetonationEventHandler {
private Player player;
private PlayerProfile profile;
private MiningManager manager;
private PlayerInteractEvent event;
protected Block block;
private Block block;
private HashSet<Byte> transparentBlocks = new HashSet<Byte>();
public RemoteDetonationEventHandler(MiningManager manager, PlayerInteractEvent event) {
this.player = manager.getPlayer();
this.profile = manager.getProfile();
this.manager = manager;
this.event = event;
this.block = event.getClickedBlock();
}
@ -35,7 +31,7 @@ public class RemoteDetonationEventHandler {
protected void targetTNT() {
if (block == null || block.getType() != Material.TNT) {
generateTransparentBlockList();
block = player.getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
block = manager.getMcMMOPlayer().getPlayer().getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
}
else {
event.setCancelled(true); // This is the only way I know to avoid the original TNT to be triggered (in case the player is close to it)
@ -43,6 +39,10 @@ public class RemoteDetonationEventHandler {
}
protected boolean cooldownOver() {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
Player player = mcMMOPlayer.getPlayer();
PlayerProfile profile = mcMMOPlayer.getProfile();
if (!SkillTools.cooldownOver(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { SkillTools.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player) }));
@ -53,19 +53,24 @@ public class RemoteDetonationEventHandler {
}
protected void sendMessages() {
Player player = manager.getMcMMOPlayer().getPlayer();
Misc.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
}
protected void handleDetonation() {
Player player = manager.getMcMMOPlayer().getPlayer();
TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
mcMMO.p.addToTNTTracker(tnt.getEntityId(), player.getName());
tnt.setFuseTicks(0);
block.setType(Material.AIR);
}
protected void setProfileData() {
PlayerProfile profile = manager.getMcMMOPlayer().getProfile();
profile.setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
profile.setAbilityInformed(AbilityType.BLAST_MINING, false);
}
@ -77,4 +82,8 @@ public class RemoteDetonationEventHandler {
}
}
}
protected Block getBlock() {
return block;
}
}

View File

@ -14,29 +14,22 @@ import com.gmail.nossr50.util.Misc;
public class SuperBreakerEventHandler {
private MiningManager manager;
private Player player;
private Block block;
private Material blockType;
private boolean customBlock;
private ItemStack heldItem;
private int tier;
private int durabilityLoss;
private FakePlayerAnimationEvent armswing;
protected SuperBreakerEventHandler (MiningManager manager, Block block) {
this.manager = manager;
this.player = manager.getPlayer();
this.block = block;
this.blockType = block.getType();
this.customBlock = ModChecks.isCustomMiningBlock(block);
Player player = manager.getMcMMOPlayer().getPlayer();
this.heldItem = player.getItemInHand();
this.tier = Misc.getTier(heldItem);
this.armswing = new FakePlayerAnimationEvent(player);
calculateDurabilityLoss();
@ -55,7 +48,7 @@ public class SuperBreakerEventHandler {
}
protected void playSound() {
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
manager.getMcMMOPlayer().getPlayer().playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}

View File

@ -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);

View File

@ -1,23 +1,19 @@
package com.gmail.nossr50.skills.runnables;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillType;
public class GainXp implements Runnable {
private Player player;
private PlayerProfile profile;
public class CombatXpGiver implements Runnable {
private McMMOPlayer mcMMOPlayer;
private double baseXp;
private SkillType skillType;
private LivingEntity target;
private int baseHealth;
public GainXp(Player player, PlayerProfile profile, SkillType skillType, double baseXp, LivingEntity target) {
this.player = player;
this.profile = profile;
public CombatXpGiver(McMMOPlayer mcMMOPlayer, SkillType skillType, double baseXp, LivingEntity target) {
this.mcMMOPlayer = mcMMOPlayer;
this.skillType = skillType;
this.baseXp = baseXp;
this.target = target;
@ -39,6 +35,6 @@ public class GainXp implements Runnable {
damage += health;
}
SkillTools.xpProcessing(player, profile, skillType, (int) (damage * baseXp));
mcMMOPlayer.addXp(skillType, (int) (damage * baseXp));
}
}

View File

@ -3,10 +3,10 @@ package com.gmail.nossr50.skills.smelting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.utilities.SkillType;
@ -15,13 +15,11 @@ import com.gmail.nossr50.util.Permissions;
public class FluxMiningEventHandler {
private SmeltingManager manager;
private Player player;
private BlockBreakEvent event;
private Block block;
protected FluxMiningEventHandler(SmeltingManager manager, BlockBreakEvent event) {
this.manager = manager;
this.player = manager.getPlayer();
this.event = event;
this.block = event.getBlock();
}
@ -47,10 +45,13 @@ public class FluxMiningEventHandler {
}
Location location = block.getLocation();
Misc.dropItem(location, item);
if (Permissions.secondSmelt(player)) {
int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (Misc.skillCheck(manager.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel)));
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
if (Permissions.secondSmelt(mcMMOPlayer.getPlayer())) {
int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (Misc.skillCheck(mcMMOPlayer.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel)));
Misc.randomDropItem(location, item, chance);
}
}
@ -61,6 +62,6 @@ public class FluxMiningEventHandler {
}
protected void sendAbilityMessage() {
player.sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
}
}

View File

@ -6,8 +6,7 @@ import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
@ -28,8 +27,6 @@ public class SmeltResourceEventHandler {
}
protected void handleXPGain() {
Player player = manager.getPlayer();
PlayerProfile profile = manager.getProfile();
Material sourceType = event.getSource().getType();
int xp = 0;
@ -67,12 +64,15 @@ public class SmeltResourceEventHandler {
break;
}
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
Player player = mcMMOPlayer.getPlayer();
if (Permissions.mining(player)) {
SkillTools.xpProcessing(player, profile, SkillType.MINING, xp / 2);
mcMMOPlayer.addXp(SkillType.MINING, xp / 2);
}
if (Permissions.repair(player)) {
SkillTools.xpProcessing(player, profile, SkillType.REPAIR, xp / 2);
mcMMOPlayer.addXp(SkillType.REPAIR, xp / 2);
}
}

View File

@ -6,6 +6,7 @@ import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
@ -13,8 +14,8 @@ import com.gmail.nossr50.util.Permissions;
public class SmeltingManager extends SkillManager {
public SmeltingManager(Player player) {
super(player, SkillType.SMELTING);
public SmeltingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.SMELTING);
}
/**
@ -23,6 +24,8 @@ public class SmeltingManager extends SkillManager {
* @param event The {@link FurnaceBurnEvent} to modify.
*/
public void fuelEfficiency(FurnaceBurnEvent event) {
Player player = mcMMOPlayer.getPlayer();
if (Misc.isNPCPlayer(player) || !Permissions.fuelEfficiency(player)) {
return;
}
@ -33,6 +36,8 @@ public class SmeltingManager extends SkillManager {
}
public void smeltProcessing(FurnaceSmeltEvent event) {
Player player = mcMMOPlayer.getPlayer();
if (Misc.isNPCPlayer(player)) {
return;
}
@ -69,7 +74,7 @@ public class SmeltingManager extends SkillManager {
}
public void vanillaXPBoost(FurnaceExtractEvent event) {
if (skillLevel < Smelting.vanillaXPBoostRank1Level || !Permissions.smeltingVanillaXPBoost(player)) {
if (skillLevel < Smelting.vanillaXPBoostRank1Level || !Permissions.smeltingVanillaXPBoost(mcMMOPlayer.getPlayer())) {
return;
}

View File

@ -11,7 +11,6 @@ public class BleedEventHandler {
private SwordsManager manager;
private int skillLevel;
private LivingEntity defender;
protected int skillModifier;
protected BleedEventHandler(SwordsManager manager, LivingEntity defender) {
@ -40,7 +39,7 @@ public class BleedEventHandler {
}
protected void sendAbilityMessages() {
manager.getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding"));
if (defender instanceof Player) {
((Player) defender).sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Started"));

View File

@ -9,15 +9,12 @@ import com.gmail.nossr50.util.Misc;
public class CounterAttackEventHandler {
private SwordsManager manager;
private Player player;
private LivingEntity attacker;
private int damage;
protected int skillModifier;
protected CounterAttackEventHandler(SwordsManager manager, LivingEntity attacker, int damage) {
this.manager = manager;
this.player = manager.getPlayer();
this.attacker = attacker;
this.damage = damage;
}
@ -31,10 +28,7 @@ public class CounterAttackEventHandler {
}
protected void sendAbilityMessages() {
if (player == null)
return;
player.sendMessage(LocaleLoader.getString("Swords.Combat.Countered"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Countered"));
if (attacker instanceof Player) {
((Player) attacker).sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Hit"));

View File

@ -1,25 +1,24 @@
package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillType;
public class SerratedStrikesEventHandler {
private Player player;
private SwordsManager manager;
private LivingEntity target;
private int damage;
protected SerratedStrikesEventHandler(SwordsManager manager, LivingEntity target, int damage) {
this.player = manager.getPlayer();
this.manager = manager;
this.target = target;
this.damage = damage;
}
protected void applyAbilityEffects() {
CombatTools.applyAbilityAoE(player, target, damage / Swords.serratedStrikesModifier, SkillType.SWORDS);
CombatTools.applyAbilityAoE(manager.getMcMMOPlayer().getPlayer(), target, damage / Swords.serratedStrikesModifier, SkillType.SWORDS);
BleedTimer.add(target, Swords.serratedStrikesBleedTicks);
}
}

View File

@ -1,15 +1,15 @@
package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
public class SwordsManager extends SkillManager {
public SwordsManager (Player player) {
super(player, SkillType.SWORDS);
public SwordsManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.SWORDS);
}
/**

View File

@ -12,7 +12,7 @@ public class EnvironmentallyAwareEventHandler {
private Wolf wolf;
protected EnvironmentallyAwareEventHandler(TamingManager manager, EntityDamageEvent event) {
this.player = manager.getPlayer();
this.player = manager.getMcMMOPlayer().getPlayer();
this.event = event;
this.wolf = (Wolf) event.getEntity();
}

View File

@ -35,7 +35,7 @@ public class GoreEventHandler {
((Player) entity).sendMessage(LocaleLoader.getString("Combat.StruckByGore"));
}
manager.getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));
}
protected void applyBleed() {

View File

@ -23,8 +23,8 @@ public class Taming {
public static int thickFurUnlockLevel = AdvancedConfig.getInstance().getThickFurUnlock();
public static int thickFurModifier = AdvancedConfig.getInstance().getThickFurModifier();
public static int wolfXP = Config.getInstance().getTamingXPWolf();
public static int ocelotXP = Config.getInstance().getTamingXPOcelot();
public static int wolfXp = Config.getInstance().getTamingXPWolf();
public static int ocelotXp = Config.getInstance().getTamingXPOcelot();
public static boolean pvpEnabled = Config.getInstance().getTamingPVP();
public static boolean pveEnabled = Config.getInstance().getTamingPVE();

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.taming;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -11,18 +10,15 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
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;
public class TamingManager extends SkillManager {
private Config configInstance;
public TamingManager (Player player) {
super(player, SkillType.TAMING);
this.configInstance = Config.getInstance();
public TamingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.TAMING);
}
/**
@ -37,11 +33,11 @@ public class TamingManager extends SkillManager {
switch (event.getEntityType()) {
case WOLF:
SkillTools.xpProcessing(player, profile, SkillType.TAMING, Taming.wolfXP);
mcMMOPlayer.addXp(SkillType.TAMING, Taming.wolfXp);
break;
case OCELOT:
SkillTools.xpProcessing(player, profile, SkillType.TAMING, Taming.ocelotXP);
mcMMOPlayer.addXp(SkillType.TAMING, Taming.ocelotXp);
break;
default:
@ -128,14 +124,14 @@ public class TamingManager extends SkillManager {
* Summon an ocelot to your side.
*/
public void summonOcelot() {
callOfTheWild(EntityType.OCELOT, configInstance.getTamingCOTWOcelotCost());
callOfTheWild(EntityType.OCELOT, Config.getInstance().getTamingCOTWOcelotCost());
}
/**
* Summon a wolf to your side.
*/
public void summonWolf() {
callOfTheWild(EntityType.WOLF, configInstance.getTamingCOTWWolfCost());
callOfTheWild(EntityType.WOLF, Config.getInstance().getTamingCOTWWolfCost());
}
/**
@ -144,7 +140,7 @@ public class TamingManager extends SkillManager {
* @param livingEntity The entity to examine
*/
public void beastLore(LivingEntity livingEntity) {
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity);
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(mcMMOPlayer.getPlayer(), livingEntity);
eventHandler.sendInspectMessage();
}
@ -155,11 +151,11 @@ public class TamingManager extends SkillManager {
* @param summonAmount The amount of material needed to summon the entity
*/
private void callOfTheWild(EntityType type, int summonAmount) {
if (!Permissions.callOfTheWild(player)) {
if (!Permissions.callOfTheWild(mcMMOPlayer.getPlayer())) {
return;
}
CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(player, type, summonAmount);
CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(mcMMOPlayer.getPlayer(), type, summonAmount);
ItemStack inHand = eventHandler.inHand;
int inHandAmount = inHand.getAmount();
@ -186,7 +182,7 @@ public class TamingManager extends SkillManager {
* @param cause The damage cause of the event
*/
private void environmentallyAware(EntityDamageEvent event, DamageCause cause) {
if (skillLevel >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(player)) {
if (skillLevel >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(mcMMOPlayer.getPlayer())) {
EnvironmentallyAwareEventHandler eventHandler = new EnvironmentallyAwareEventHandler(this, event);
switch (cause) {
@ -214,7 +210,7 @@ public class TamingManager extends SkillManager {
* @param cause The damage cause of the event
*/
private void thickFur(EntityDamageEvent event, DamageCause cause) {
if (skillLevel >= Taming.thickFurUnlockLevel && Permissions.thickFur(player)) {
if (skillLevel >= Taming.thickFurUnlockLevel && Permissions.thickFur(mcMMOPlayer.getPlayer())) {
ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause);
eventHandler.modifyEventDamage();
}
@ -226,7 +222,7 @@ public class TamingManager extends SkillManager {
* @param event The event to modify
*/
private void shockProof(EntityDamageEvent event) {
if (skillLevel >= Taming.shockProofUnlockLevel && Permissions.shockProof(player)) {
if (skillLevel >= Taming.shockProofUnlockLevel && Permissions.shockProof(mcMMOPlayer.getPlayer())) {
ShockProofEventHandler eventHandler = new ShockProofEventHandler(event);
eventHandler.modifyEventDamage();
}

View File

@ -22,7 +22,7 @@ public class DeflectEventHandler {
}
protected void sendAbilityMessage() {
manager.getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
}
protected void cancelEvent() {

View File

@ -25,6 +25,6 @@ public class IronGripEventHandler {
protected void sendAbilityMessages() {
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
manager.getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
}
}

View File

@ -4,14 +4,15 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class UnarmedManager extends SkillManager {
public UnarmedManager (Player player) {
super(player, SkillType.UNARMED);
public UnarmedManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.UNARMED);
}
/**

View File

@ -21,6 +21,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
@ -33,7 +34,7 @@ import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxeManager;
import com.gmail.nossr50.skills.axes.Axes;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.runnables.GainXp;
import com.gmail.nossr50.skills.runnables.CombatXpGiver;
import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.Taming;
@ -80,8 +81,9 @@ public final class CombatTools {
}
if (Permissions.swords(player)) {
SwordsManager swordsManager = new SwordsManager(player);
PlayerProfile profile = swordsManager.getProfile();
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
SwordsManager swordsManager = new SwordsManager(mcMMOPlayer);
boolean canSerratedStrike = Permissions.serratedStrikes(player); //So we don't have to check the same permission twice
if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
@ -96,7 +98,7 @@ public final class CombatTools {
swordsManager.serratedStrikes(target, event.getDamage());
}
startGainXp(player, profile, target, SkillType.SWORDS);
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
}
}
else if (ItemChecks.isAxe(heldItem)) {
@ -110,8 +112,9 @@ public final class CombatTools {
}
if (Permissions.axes(player)) {
AxeManager axeManager = new AxeManager(player);
PlayerProfile profile = axeManager.getProfile();
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
AxeManager axeManager = new AxeManager(mcMMOPlayer);
boolean canSkullSplit = Permissions.skullSplitter(player); //So we don't have to check the same permission twice
if (profile.getToolPreparationMode(ToolType.AXE) && canSkullSplit) {
SkillTools.abilityCheck(player, SkillType.AXES);
@ -133,7 +136,7 @@ public final class CombatTools {
axeManager.skullSplitter(target, event.getDamage());
}
startGainXp(player, profile, target, SkillType.AXES);
startGainXp(mcMMOPlayer, target, SkillType.AXES);
}
}
else if (heldItemType == Material.AIR) {
@ -147,8 +150,9 @@ public final class CombatTools {
}
if (Permissions.unarmed(player)) {
UnarmedManager unarmedManager = new UnarmedManager(player);
PlayerProfile profile = unarmedManager.getProfile();
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
UnarmedManager unarmedManager = new UnarmedManager(mcMMOPlayer);
boolean canBerserk = Permissions.berserk(player); //So we don't have to check the same permission twice
if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
@ -167,11 +171,11 @@ public final class CombatTools {
unarmedManager.disarmCheck(target);
}
startGainXp(player, unarmedManager.getProfile(), target, SkillType.UNARMED);
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
}
}
else if (heldItemType == Material.BONE && target instanceof Tameable && Permissions.beastLore(player)) {
TamingManager tamingManager = new TamingManager(player);
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
tamingManager.beastLore(target);
event.setCancelled(true);
}
@ -200,7 +204,8 @@ public final class CombatTools {
}
if (Permissions.taming(master)) {
TamingManager tamingManager = new TamingManager(master);
McMMOPlayer mcMMOPlayer = Users.getPlayer(master);
TamingManager tamingManager = new TamingManager(mcMMOPlayer);
int skillLevel = tamingManager.getSkillLevel();
if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(master)) {
@ -216,7 +221,7 @@ public final class CombatTools {
}
if (target != master) {
startGainXp(master, tamingManager.getProfile(), target, SkillType.TAMING);
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
}
}
}
@ -258,28 +263,28 @@ public final class CombatTools {
if (damager instanceof Player) {
if (Swords.pvpEnabled && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
SwordsManager swordsManager = new SwordsManager(player);
SwordsManager swordsManager = new SwordsManager(Users.getPlayer(player));
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
}
if (Acrobatics.pvpEnabled && Permissions.dodge(player)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(Users.getPlayer(player));
acrobaticsManager.dodgeCheck(event);
}
if (Unarmed.pvpEnabled && heldItem.getType() == Material.AIR && Permissions.deflect(player)) {
UnarmedManager unarmedManager = new UnarmedManager(player);
UnarmedManager unarmedManager = new UnarmedManager(Users.getPlayer(player));
unarmedManager.deflectCheck(event);
}
}
else {
if (Swords.pveEnabled && damager instanceof LivingEntity && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
SwordsManager swordsManager = new SwordsManager(player);
SwordsManager swordsManager = new SwordsManager(Users.getPlayer(player));
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
}
if (Acrobatics.pveEnabled && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) && Permissions.dodge(player)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(Users.getPlayer(player));
acrobaticsManager.dodgeCheck(event);
}
}
@ -299,7 +304,8 @@ public final class CombatTools {
}
if (Permissions.archery(shooter)) {
ArcheryManager archeryManager = new ArcheryManager(shooter);
McMMOPlayer mcMMOPlayer = Users.getPlayer(shooter);
ArcheryManager archeryManager = new ArcheryManager(mcMMOPlayer);
archeryManager.skillShot(event);
if (target instanceof Player && Permissions.daze(shooter)) {
@ -312,7 +318,7 @@ public final class CombatTools {
if (target != shooter) {
archeryManager.distanceXpBonus(target);
startGainXp(shooter, archeryManager.getProfile(), target, SkillType.ARCHERY);
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY);
}
}
}
@ -430,12 +436,11 @@ public final class CombatTools {
/**
* Start the task that gives combat XP.
*
* @param attacker The attacking player
* @param profile The player's PlayerProfile
* @param mcMMOPlayer The attacking player
* @param target The defending entity
* @param skillType The skill being used
*/
public static void startGainXp(Player attacker, PlayerProfile profile, LivingEntity target, SkillType skillType) {
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType) {
double baseXP = 0;
if (target instanceof Player) {
@ -546,7 +551,7 @@ public final class CombatTools {
}
if (baseXP != 0) {
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GainXp(attacker, profile, skillType, baseXP, target), 0);
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new CombatXpGiver(mcMMOPlayer, skillType, baseXP, target), 0);
}
}

View File

@ -15,7 +15,6 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.SpoutTools;
import com.gmail.nossr50.util.Misc;
@ -230,7 +229,7 @@ public class SkillTools {
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
profile.removeXP(skillType, profile.getXpToLevel(skillType));
profile.removeXp(skillType, profile.getXpToLevel(skillType));
skillups++;
profile.skillUp(skillType, 1);
@ -510,26 +509,4 @@ public class SkillTools {
return activate;
}
/**
* Handle the processing of XP gain from individual skills.
*
* @param player The player that gained XP
* @param profile The profile of the player gaining XP
* @param type The type of skill to gain XP from
* @param xp the amount of XP to gain
*/
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
if ((type.getMaxLevel() < profile.getSkillLevel(type) + 1) || (Misc.getPowerLevelCap() < Users.getPlayer(player).getPowerLevel() + 1)) {
return;
}
if (profile.inParty()) {
xp = (int) ShareHandler.checkXpSharing(xp, player, profile.getParty());
ShareHandler.handleEqualExpShare(xp, player, profile.getParty(), type);
}
Users.getPlayer(player).addXP(type, xp);
xpCheckSkill(type, player, profile);
}
}

View File

@ -12,16 +12,15 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public final class TreeFeller {
private static boolean treeFellerReachedThreshold = false;
@ -31,10 +30,10 @@ public final class TreeFeller {
/**
* Begins Tree Feller
*
* @param player Player using Tree Feller
* @param mcMMOPlayer Player using Tree Feller
* @param block Block being broken
*/
public static void process(Player player, Block block) {
public static void process(McMMOPlayer mcMMOPlayer, Block block) {
List<Block> treeFellerBlocks = new ArrayList<Block>();
processRecursively(block, treeFellerBlocks);
@ -43,13 +42,15 @@ public final class TreeFeller {
if (treeFellerReachedThreshold) {
treeFellerReachedThreshold = false;
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
return;
}
Player player = mcMMOPlayer.getPlayer();
// If the tool can't sustain the durability loss
if (!handleDurabilityLoss(treeFellerBlocks, player)) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
if (!handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
int health = player.getHealth();
@ -60,7 +61,7 @@ public final class TreeFeller {
return;
}
dropBlocks(treeFellerBlocks, player);
dropBlocks(treeFellerBlocks, mcMMOPlayer);
}
/**
@ -129,11 +130,10 @@ public final class TreeFeller {
* Handles the durability loss
*
* @param treeFellerBlocks List of blocks to be removed
* @param player Player using the ability
* @param inHand tool being used
* @return True if the tool can sustain the durability loss
*/
private static boolean handleDurabilityLoss(List<Block> treeFellerBlocks, Player player) {
ItemStack inHand = player.getItemInHand();
private static boolean handleDurabilityLoss(List<Block> treeFellerBlocks, ItemStack inHand) {
Material inHandMaterial = inHand.getType();
if (inHandMaterial != Material.AIR) {
@ -164,19 +164,19 @@ public final class TreeFeller {
* Handles the dropping of blocks
*
* @param treeFellerBlocks List of blocks to be dropped
* @param player Player using the ability
* @param mcMMOPlayer Player using the ability
*/
private static void dropBlocks(List<Block> treeFellerBlocks, Player player) {
private static void dropBlocks(List<Block> treeFellerBlocks, McMMOPlayer mcMMOPlayer) {
int xp = 0;
for (Block block : treeFellerBlocks) {
if (!Misc.blockBreakSimulate(block, player, true)) {
if (!Misc.blockBreakSimulate(block, mcMMOPlayer.getPlayer(), true)) {
break; // TODO: Shouldn't we use continue instead?
}
switch (block.getType()) {
case LOG:
Woodcutting.checkForDoubleDrop(player, block);
Woodcutting.checkForDoubleDrop(mcMMOPlayer, block);
try {
xp += Woodcutting.getExperienceFromLog(block, ExperienceGainMethod.TREE_FELLER);
@ -192,7 +192,7 @@ public final class TreeFeller {
break;
default:
if (ModChecks.isCustomLogBlock(block)) {
Woodcutting.checkForDoubleDrop(player, block);
Woodcutting.checkForDoubleDrop(mcMMOPlayer, block);
CustomBlock customBlock = ModChecks.getCustomBlock(block);
xp = customBlock.getXpGain();
@ -220,6 +220,6 @@ public final class TreeFeller {
block.setType(Material.AIR);
}
SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.WOODCUTTING, xp);
mcMMOPlayer.addXp(SkillType.WOODCUTTING, xp);
}
}

View File

@ -6,16 +6,15 @@ import org.bukkit.Sound;
import org.bukkit.TreeSpecies;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
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.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
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;
@ -35,10 +34,11 @@ public final class Woodcutting {
/**
* Begins the Tree Feller ability
*
* @param event Event to process
* @param mcMMOPlayer Player using the ability
* @param block Block being broken
*/
public static void beginTreeFeller(BlockBreakEvent event) {
TreeFeller.process(event.getPlayer(), event.getBlock());
public static void beginTreeFeller(McMMOPlayer mcMMOPlayer, Block block) {
TreeFeller.process(mcMMOPlayer, block);
}
/**
@ -56,10 +56,10 @@ public final class Woodcutting {
/**
* Begins Woodcutting
*
* @param player Player breaking the block
* @param mcMMOPlayer Player breaking the block
* @param block Block being broken
*/
public static void beginWoodcutting(Player player, Block block) {
public static void beginWoodcutting(McMMOPlayer mcMMOPlayer, Block block) {
int xp = 0;
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
@ -74,11 +74,13 @@ public final class Woodcutting {
}
}
Player player = mcMMOPlayer.getPlayer();
if (Permissions.woodcuttingDoubleDrops(player)) {
checkForDoubleDrop(player, block);
checkForDoubleDrop(mcMMOPlayer, block);
}
SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.WOODCUTTING, xp);
mcMMOPlayer.addXp(SkillType.WOODCUTTING, xp);
}
/**
@ -122,13 +124,13 @@ public final class Woodcutting {
/**
* Checks for double drops
*
* @param player Player breaking the block
* @param mcMMOPlayer Player breaking the block
* @param block Block being broken
*/
protected static void checkForDoubleDrop(Player player, Block block) {
protected static void checkForDoubleDrop(McMMOPlayer mcMMOPlayer, Block block) {
Player player = mcMMOPlayer.getPlayer();
double configDoubleDropChance = ADVANCED_CONFIG.getWoodcuttingDoubleDropChance();
int configDoubleDropMaxLevel = ADVANCED_CONFIG.getWoodcuttingDoubleDropMaxLevel();
int probability = (int) ((configDoubleDropChance / configDoubleDropMaxLevel) * Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING));
int activationChance = Misc.calculateActivationChance(Permissions.luckyWoodcutting(player));

View File

@ -87,6 +87,7 @@ public final class Users {
* @param player The player whose profile to retrieve
* @return the player's profile
*/
@Deprecated
public static PlayerProfile getProfile(OfflinePlayer player) {
return getProfile(player.getName());
}
@ -97,6 +98,7 @@ public final class Users {
* @param playerName The name of the player whose profile to retrieve
* @return the player's profile
*/
@Deprecated
public static PlayerProfile getProfile(String playerName) {
McMMOPlayer mcmmoPlayer = players.get(playerName);