Minor Fishing "cleanup"

This commit is contained in:
bm01 2013-01-30 22:51:11 +01:00
parent a1d4a4b3f8
commit 13a65e875f
2 changed files with 12 additions and 19 deletions

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.listeners;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -91,8 +92,8 @@ public class PlayerListener implements Listener {
switch (event.getState()) { switch (event.getState()) {
case CAUGHT_FISH: case CAUGHT_FISH:
Fishing.beginFishing(player, skillLevel, event); Fishing.beginFishing(player, skillLevel, (Item) event.getCaught());
Fishing.awardAdditionalVanillaXP(skillLevel, event); event.setExpToDrop(event.getExpToDrop() * Fishing.getVanillaXpMultiplier(skillLevel));
break; break;
case CAUGHT_ENTITY: case CAUGHT_ENTITY:

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
@ -27,7 +26,7 @@ import com.gmail.nossr50.util.Users;
public final class Fishing { public final class Fishing {
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance(); static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
// The order of the values is extremely important, Fishing.getLootTier() and ShakeMob.getShakeChance() depend on it to work properly // The order of the values is extremely important, a few methods depend on it to work properly
protected enum Tier { protected enum Tier {
FIVE(5) { FIVE(5) {
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier5();} @Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier5();}
@ -105,17 +104,16 @@ public final class Fishing {
* *
* @param player Player fishing * @param player Player fishing
* @param skillLevel Fishing level of the player * @param skillLevel Fishing level of the player
* @param event Event to process * @param caught Item reeled
*/ */
public static void beginFishing(Player player, int skillLevel, PlayerFishEvent event) { public static void beginFishing(Player player, int skillLevel, Item caught) {
// TODO: Find a way to not pass the event directly int treasureXp = 0;
int xp = 0;
FishingTreasure treasure = checkForTreasure(player, skillLevel); FishingTreasure treasure = checkForTreasure(player, skillLevel);
if (treasure != null) { if (treasure != null) {
player.sendMessage(LocaleLoader.getString("Fishing.ItemFound")); player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
xp += treasure.getXp(); treasureXp = treasure.getXp();
ItemStack treasureDrop = treasure.getDrop(); ItemStack treasureDrop = treasure.getDrop();
if (Permissions.fishingMagic(player) && beginMagicHunter(player, skillLevel, treasureDrop, player.getWorld().hasStorm())) { if (Permissions.fishingMagic(player) && beginMagicHunter(player, skillLevel, treasureDrop, player.getWorld().hasStorm())) {
@ -123,17 +121,11 @@ public final class Fishing {
} }
// Drop the original catch at the feet of the player and set the treasure as the real catch // Drop the original catch at the feet of the player and set the treasure as the real catch
Item caught = (Item) event.getCaught();
Misc.dropItem(player.getEyeLocation(), caught.getItemStack()); Misc.dropItem(player.getEyeLocation(), caught.getItemStack());
caught.setItemStack(treasureDrop); caught.setItemStack(treasureDrop);
} }
SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.FISHING, Config.getInstance().getFishingBaseXP() + xp); SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.FISHING, Config.getInstance().getFishingBaseXP() + treasureXp);
}
public static void awardAdditionalVanillaXP(int skillLevel, PlayerFishEvent event) {
int xp = event.getExpToDrop();
event.setExpToDrop(xp * getVanillaXPMultiplier(skillLevel));
} }
/** /**
@ -256,12 +248,12 @@ public final class Fishing {
} }
/** /**
* Gets the Shake Mob probability for a given skill level * Gets the vanilla xp multiplier for a given skill level
* *
* @param skillLevel Fishing skill level * @param skillLevel Fishing skill level
* @return Shake Mob probability * @return Shake Mob probability
*/ */
public static int getVanillaXPMultiplier(int skillLevel) { public static int getVanillaXpMultiplier(int skillLevel) {
for (Tier tier : Tier.values()) { for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) { if (skillLevel >= tier.getLevel()) {
return tier.getVanillaXPBoostModifier(); return tier.getVanillaXPBoostModifier();