Treasure code removed pending rewrite

This commit is contained in:
nossr50 2019-09-23 19:20:09 -07:00
parent 3aead73d07
commit 815131a013
20 changed files with 485 additions and 504 deletions

View File

@ -1,16 +1,11 @@
package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.fishing.FishingManager;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -54,34 +49,34 @@ public class FishingCommand extends SkillCommand {
lootTier = fishingManager.getLootTier();
// Item drop rates
commonTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.COMMON) / 100.0);
uncommonTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.UNCOMMON) / 100.0);
rareTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE) / 100.0);
epicTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC) / 100.0);
legendaryTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY) / 100.0);
recordTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RECORD) / 100.0);
// commonTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.COMMON) / 100.0);
// uncommonTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.UNCOMMON) / 100.0);
// rareTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE) / 100.0);
// epicTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC) / 100.0);
// legendaryTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY) / 100.0);
// recordTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RECORD) / 100.0);
//
// // Magic hunter drop rates
// double totalEnchantChance = 0;
//
// for (Rarity rarity : Rarity.values()) {
// if (rarity != Rarity.RECORD) {
// totalEnchantChance += FishingTreasureConfig.getInstance().getEnchantmentDropRate(lootTier, rarity);
// }
// }
// Magic hunter drop rates
double totalEnchantChance = 0;
for (Rarity rarity : Rarity.values()) {
if (rarity != Rarity.RECORD) {
totalEnchantChance += FishingTreasureConfig.getInstance().getEnchantmentDropRate(lootTier, rarity);
}
}
if (totalEnchantChance >= 1)
magicChance = percent.format(totalEnchantChance / 100.0);
else
magicChance = percent.format(0);
// if (totalEnchantChance >= 1)
// magicChance = percent.format(totalEnchantChance / 100.0);
// else
// magicChance = percent.format(0);
}
// FISHING_SHAKE
if (canShake) {
String[] shakeStrings = pluginRef.getRandomChanceTools().calculateAbilityDisplayValuesStatic(player, PrimarySkillType.FISHING, fishingManager.getShakeChance());
shakeChance = shakeStrings[0];
shakeChanceLucky = shakeStrings[1];
}
// if (canShake) {
// String[] shakeStrings = pluginRef.getRandomChanceTools().calculateAbilityDisplayValuesStatic(player, PrimarySkillType.FISHING, fishingManager.getShakeChance());
// shakeChance = shakeStrings[0];
// shakeChanceLucky = shakeStrings[1];
// }
// FISHERMAN'S DIET
if (canFishermansDiet) {
@ -98,13 +93,13 @@ public class FishingCommand extends SkillCommand {
location = player.getLocation();
}
if (Fishing.getInstance().getMasterAnglerBiomes().contains(location.getBlock().getBiome())) {
rawBiteChance = rawBiteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier();
}
// if (Fishing.getInstance().getMasterAnglerBiomes().contains(location.getBlock().getBiome())) {
// rawBiteChance = rawBiteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier();
// }
if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) {
rawBiteChance = rawBiteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier();
}
// if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) {
// rawBiteChance = rawBiteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier();
// }
double luckyModifier = pluginRef.getPermissionTools().lucky(player, PrimarySkillType.FISHING) ? 1.333D : 1.0D;
@ -135,9 +130,9 @@ public class FishingCommand extends SkillCommand {
messages.add(getStatMessage(false, true, SubSkillType.FISHING_FISHERMANS_DIET, String.valueOf(fishermansDietRank)));
}
if (canIceFish) {
messages.add(getStatMessage(SubSkillType.FISHING_ICE_FISHING, SubSkillType.FISHING_ICE_FISHING.getLocaleStatDescription()));
}
// if (canIceFish) {
// messages.add(getStatMessage(SubSkillType.FISHING_ICE_FISHING, SubSkillType.FISHING_ICE_FISHING.getLocaleStatDescription()));
// }
if (canMagicHunt) {
messages.add(getStatMessage(SubSkillType.FISHING_MAGIC_HUNTER, magicChance));

View File

@ -1,14 +1,8 @@
package com.gmail.nossr50.datatypes.skills.behaviours;
import com.gmail.nossr50.config.treasure.ExcavationTreasureConfig;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils;
import org.bukkit.block.BlockState;
import java.util.ArrayList;
import java.util.List;
/**
* These behaviour classes are a band-aid fix for a larger problem
* Until the new skill system for mcMMO is finished/implemented, there is no good place to store the hardcoded behaviours for each skill
@ -24,18 +18,18 @@ public class ExcavationBehaviour {
this.pluginRef = pluginRef;
}
/**
* Get the list of possible {@link ExcavationTreasure|ExcavationTreasures} obtained from a given block.
*
* @param blockState The {@link BlockState} of the block to check.
* @return the list of treasures that could be found
*/
public List<ExcavationTreasure> getTreasures(BlockState blockState) {
String friendly = StringUtils.getFriendlyConfigBlockDataString(blockState.getBlockData());
if (ExcavationTreasureConfig.getInstance().excavationMap.containsKey(friendly))
return ExcavationTreasureConfig.getInstance().excavationMap.get(friendly);
return new ArrayList<>();
}
// /**
// * Get the list of possible {@link ExcavationTreasure|ExcavationTreasures} obtained from a given block.
// *
// * @param blockState The {@link BlockState} of the block to check.
// * @return the list of treasures that could be found
// */
// public List<ExcavationTreasure> getTreasures(BlockState blockState) {
// String friendly = StringUtils.getFriendlyConfigBlockDataString(blockState.getBlockData());
// if (ExcavationTreasureConfig.getInstance().excavationMap.containsKey(friendly))
// return ExcavationTreasureConfig.getInstance().excavationMap.get(friendly);
// return new ArrayList<>();
// }
public int getBlockXP(BlockState blockState) {
int xp = pluginRef.getDynamicSettingsManager().getExperienceManager().getExcavationXp(blockState.getType());

View File

@ -1,14 +1,10 @@
package com.gmail.nossr50.datatypes.skills.behaviours;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.adapter.BiomeAdapter;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.List;
@ -61,39 +57,39 @@ public class FishingBehaviour {
}
}
/**
* Finds the possible drops of an entity
*
* @param target Targeted entity
* @return possibleDrops List of ItemStack that can be dropped
*/
public List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
if (FishingTreasureConfig.getInstance().shakeMap.containsKey(target.getType()))
return FishingTreasureConfig.getInstance().shakeMap.get(target.getType());
// /**
// * Finds the possible drops of an entity
// *
// * @param target Targeted entity
// * @return possibleDrops List of ItemStack that can be dropped
// */
// public List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
// if (FishingTreasureConfig.getInstance().shakeMap.containsKey(target.getType()))
// return FishingTreasureConfig.getInstance().shakeMap.get(target.getType());
//
// return null;
// }
return null;
}
/**
* Randomly chooses a drop among the list
*
* @param possibleDrops List of ItemStack that can be dropped
* @return Chosen ItemStack
*/
public ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
int dropProbability = Misc.getRandom().nextInt(100);
double cumulatedProbability = 0;
for (ShakeTreasure treasure : possibleDrops) {
cumulatedProbability += treasure.getDropChance();
if (dropProbability < cumulatedProbability) {
return treasure.getDrop().clone();
}
}
return null;
}
// /**
// * Randomly chooses a drop among the list
// *
// * @param possibleDrops List of ItemStack that can be dropped
// * @return Chosen ItemStack
// */
// public ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
// int dropProbability = Misc.getRandom().nextInt(100);
// double cumulatedProbability = 0;
//
// for (ShakeTreasure treasure : possibleDrops) {
// cumulatedProbability += treasure.getDropChance();
//
// if (dropProbability < cumulatedProbability) {
// return treasure.getDrop().clone();
// }
// }
//
// return null;
// }
public HashMap<Material, List<Enchantment>> getEnchantableCache() {
return enchantableCache;

View File

@ -1,29 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.enchantments.Enchantment;
public class EnchantmentTreasure {
private Enchantment enchantment;
private int level;
public EnchantmentTreasure(Enchantment enchantment, int level) {
this.setEnchantment(enchantment);
this.setLevel(level);
}
public Enchantment getEnchantment() {
return enchantment;
}
public void setEnchantment(Enchantment enchantment) {
this.enchantment = enchantment;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}

View File

@ -1,9 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public class ExcavationTreasure extends Treasure {
public ExcavationTreasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
super(drop, xp, dropChance, dropLevel);
}
}

View File

@ -1,10 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public class FishingTreasure extends Treasure {
public FishingTreasure(ItemStack drop, int xp) {
super(drop, xp, 0, 0);
}
}

View File

@ -1,9 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public class HylianTreasure extends Treasure {
public HylianTreasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
super(drop, xp, dropChance, dropLevel);
}
}

View File

@ -1,18 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
public enum Rarity {
RECORD,
LEGENDARY,
EPIC,
RARE,
UNCOMMON,
COMMON;
public static Rarity getRarity(String string) {
try {
return valueOf(string);
} catch (IllegalArgumentException ex) {
return COMMON;
}
}
}

View File

@ -1,9 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public class ShakeTreasure extends Treasure {
public ShakeTreasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
super(drop, xp, dropChance, dropLevel);
}
}

View File

@ -1,53 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public abstract class Treasure {
private int xp;
private double dropChance;
private int dropLevel;
private ItemStack drop;
public Treasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
this.drop = drop;
this.xp = xp;
this.dropChance = dropChance;
this.dropLevel = dropLevel;
}
public ItemStack getDrop() {
return drop;
}
public void setDrop(ItemStack drop) {
this.drop = drop;
}
public int getXp() {
return xp;
}
public void setXp(int xp) {
this.xp = xp;
}
public double getDropChance() {
return dropChance;
}
public void setDropChance(Double dropChance) {
this.dropChance = dropChance;
}
public int getDropLevel() {
//If they are in retro mode all requirements are scaled up by 10
if (pluginRef.isRetroModeEnabled())
return dropLevel * 10;
return dropLevel;
}
public void setDropLevel(int dropLevel) {
this.dropLevel = dropLevel;
}
}

View File

@ -0,0 +1,29 @@
//package com.gmail.nossr50.datatypes.treasure;
//
//import org.bukkit.enchantments.Enchantment;
//
//public class EnchantmentTreasure {
// private Enchantment enchantment;
// private int level;
//
// public EnchantmentTreasure(Enchantment enchantment, int level) {
// this.setEnchantment(enchantment);
// this.setLevel(level);
// }
//
// public Enchantment getEnchantment() {
// return enchantment;
// }
//
// public void setEnchantment(Enchantment enchantment) {
// this.enchantment = enchantment;
// }
//
// public int getLevel() {
// return level;
// }
//
// public void setLevel(int level) {
// this.level = level;
// }
//}

View File

@ -0,0 +1,9 @@
//package com.gmail.nossr50.datatypes.treasure;
//
//import org.bukkit.inventory.ItemStack;
//
//public class ExcavationTreasure extends Treasure {
// public ExcavationTreasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
// super(drop, xp, dropChance, dropLevel);
// }
//}

View File

@ -0,0 +1,10 @@
//package com.gmail.nossr50.datatypes.treasure;
//
//import org.bukkit.inventory.ItemStack;
//
//public class FishingTreasure extends Treasure {
//
// public FishingTreasure(ItemStack drop, int xp) {
// super(drop, xp, 0, 0);
// }
//}

View File

@ -5,7 +5,7 @@
//import com.gmail.nossr50.config.UnsafeValueValidation;
//import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
//import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
//import com.gmail.nossr50.datatypes.treasure.Rarity;
//import com.gmail.nossr50.dumpster.Rarity;
//import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
//import com.gmail.nossr50.mcMMO;
//import com.gmail.nossr50.util.EnchantmentUtils;

View File

@ -0,0 +1,9 @@
//package com.gmail.nossr50.datatypes.treasure;
//
//import org.bukkit.inventory.ItemStack;
//
//public class HylianTreasure extends Treasure {
// public HylianTreasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
// super(drop, xp, dropChance, dropLevel);
// }
//}

View File

@ -0,0 +1,18 @@
//package com.gmail.nossr50.dumpster;
//
//public enum Rarity {
// RECORD,
// LEGENDARY,
// EPIC,
// RARE,
// UNCOMMON,
// COMMON;
//
// public static Rarity getRarity(String string) {
// try {
// return valueOf(string);
// } catch (IllegalArgumentException ex) {
// return COMMON;
// }
// }
//}

View File

@ -0,0 +1,9 @@
//package com.gmail.nossr50.datatypes.treasure;
//
//import org.bukkit.inventory.ItemStack;
//
//public class ShakeTreasure extends Treasure {
// public ShakeTreasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
// super(drop, xp, dropChance, dropLevel);
// }
//}

View File

@ -0,0 +1,53 @@
//package com.gmail.nossr50.datatypes.treasure;
//
//import org.bukkit.inventory.ItemStack;
//
//public abstract class Treasure {
// private int xp;
// private double dropChance;
// private int dropLevel;
// private ItemStack drop;
//
// public Treasure(ItemStack drop, int xp, double dropChance, int dropLevel) {
// this.drop = drop;
// this.xp = xp;
// this.dropChance = dropChance;
// this.dropLevel = dropLevel;
// }
//
// public ItemStack getDrop() {
// return drop;
// }
//
// public void setDrop(ItemStack drop) {
// this.drop = drop;
// }
//
// public int getXp() {
// return xp;
// }
//
// public void setXp(int xp) {
// this.xp = xp;
// }
//
// public double getDropChance() {
// return dropChance;
// }
//
// public void setDropChance(Double dropChance) {
// this.dropChance = dropChance;
// }
//
// public int getDropLevel() {
// //If they are in retro mode all requirements are scaled up by 10
// if (pluginRef.isRetroModeEnabled())
// return dropLevel * 10;
//
// return dropLevel;
// }
//
// public void setDropLevel(int dropLevel) {
// this.dropLevel = dropLevel;
// }
//}

View File

@ -387,7 +387,15 @@ public class PlayerListener implements Listener {
return;
case CAUGHT_ENTITY:
if (fishingManager.canShake(caught)) {
fishingManager.shakeCheck((LivingEntity) caught);
//TODO: SHAKE REWRITE
//TODO: SHAKE REWRITE
//TODO: SHAKE REWRITE
//TODO: SHAKE REWRITE
//TODO: SHAKE REWRITE
//TODO: SHAKE REWRITE
//TODO: SHAKE REWRITE
//TODO: SHAKE REWRITE
// fishingManager.shakeCheck((LivingEntity) caught);
fishingManager.setFishingTarget();
}
return;

View File

@ -1,23 +1,13 @@
package com.gmail.nossr50.skills.fishing;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.core.MetadataConstants;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.behaviours.FishingBehaviour;
import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.random.RandomChanceSkillStatic;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.Bukkit;
@ -27,14 +17,12 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
public class FishingManager extends SkillManager {
@ -194,12 +182,12 @@ public class FishingManager extends SkillManager {
return pluginRef.getRankTools().getRank(getPlayer(), SubSkillType.FISHING_TREASURE_HUNTER);
}
public double getShakeChance() {
return AdvancedConfig.getInstance().getShakeChance(getLootTier());
}
public double getShakeChance() {
return pluginRef.getConfigManager().getFishingTreasureConfig().getShakeChance(getLootTier());
}
// public double getShakeChance() {
// return AdvancedConfig.getInstance().getShakeChance(getLootTier());
// }
// public double getShakeChance() {
// return pluginRef.getConfigManager().getFishingTreasureConfig().getShakeChance(getLootTier());
// }
public int getInnerPeaceMultiplier() {
return pluginRef.getConfigManager().getConfigFishing().getVanillaXPMultInnerPeace(pluginRef.getRankTools().getRank(getPlayer(), SubSkillType.FISHING_INNER_PEACE));
@ -210,9 +198,9 @@ public class FishingManager extends SkillManager {
*
* @return Shake Mob probability
*/
public double getShakeProbability() {
return getShakeChance();
}
// public double getShakeProbability() {
// return getShakeChance();
// }
/**
* Handle the Fisherman's Diet ability
@ -249,13 +237,13 @@ public class FishingManager extends SkillManager {
hookLocation = location;
if (fishingBehaviour.getMasterAnglerBiomes().contains(location.getBlock().getBiome())) {
biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier();
}
if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) {
biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier();
}
// if (fishingBehaviour.getMasterAnglerBiomes().contains(location.getBlock().getBiome())) {
// biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier();
// }
//
// if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) {
// biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier();
// }
hook.setBiteChance(Math.min(biteChance, 1.0));
}
@ -275,53 +263,53 @@ public class FishingManager extends SkillManager {
int fishXp = fishingBehaviour.getFishXPValue(fishingCatch.getItemStack().getType());
int treasureXp = 0;
Player player = getPlayer();
FishingTreasure treasure = null;
// FishingTreasure treasure = null;
if (pluginRef.getConfigManager().getConfigFishing().isAllowCustomDrops()
&& pluginRef.getPermissionTools().isSubSkillEnabled(player, SubSkillType.FISHING_TREASURE_HUNTER)) {
treasure = getFishingTreasure();
// treasure = getFishingTreasure();
}
if (treasure != null) {
ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
Map<Enchantment, Integer> enchants = new HashMap<>();
if (isMagicHunterEnabled()
&& pluginRef.getItemTools().isEnchantable(treasureDrop)) {
enchants = handleMagicHunter(treasureDrop);
}
McMMOPlayerFishingTreasureEvent event = pluginRef.getEventManager().callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
if (!event.isCancelled()) {
treasureDrop = event.getTreasure();
treasureXp = event.getXp();
} else {
treasureDrop = null;
treasureXp = 0;
}
// Drop the original catch at the feet of the player and set the treasure as the real catch
if (treasureDrop != null) {
boolean enchanted = false;
if (!enchants.isEmpty()) {
treasureDrop.addUnsafeEnchantments(enchants);
enchanted = true;
}
if (enchanted) {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Fishing.Ability.TH.MagicFound");
}
if (pluginRef.getConfigManager().getConfigFishing().isAlwaysCatchFish()) {
/*Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());*/
Misc.dropItem(fishingCatch.getLocation(), fishingCatch.getItemStack()).setVelocity(fishingCatch.getVelocity());
}
fishingCatch.setItemStack(treasureDrop);
}
}
// if (treasure != null) {
// ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
// Map<Enchantment, Integer> enchants = new HashMap<>();
//
// if (isMagicHunterEnabled()
// && pluginRef.getItemTools().isEnchantable(treasureDrop)) {
// enchants = handleMagicHunter(treasureDrop);
// }
//
// McMMOPlayerFishingTreasureEvent event = pluginRef.getEventManager().callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
//
// if (!event.isCancelled()) {
// treasureDrop = event.getTreasure();
// treasureXp = event.getXp();
// } else {
// treasureDrop = null;
// treasureXp = 0;
// }
//
// // Drop the original catch at the feet of the player and set the treasure as the real catch
// if (treasureDrop != null) {
// boolean enchanted = false;
//
// if (!enchants.isEmpty()) {
// treasureDrop.addUnsafeEnchantments(enchants);
// enchanted = true;
// }
//
// if (enchanted) {
// pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Fishing.Ability.TH.MagicFound");
// }
//
// if (pluginRef.getConfigManager().getConfigFishing().isAlwaysCatchFish()) {
// /*Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());*/
// Misc.dropItem(fishingCatch.getLocation(), fishingCatch.getItemStack()).setVelocity(fishingCatch.getVelocity());
// }
//
// fishingCatch.setItemStack(treasureDrop);
// }
// }
applyXpGain(fishXp + treasureXp, XPGainReason.PVE);
}
@ -345,151 +333,151 @@ public class FishingManager extends SkillManager {
*
* @param target The {@link LivingEntity} affected by the ability
*/
public void shakeCheck(LivingEntity target) {
if (pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getShakeChance(), getPlayer(), SubSkillType.FISHING_SHAKE))) {
List<ShakeTreasure> possibleDrops = fishingBehaviour.findPossibleDrops(target);
if (possibleDrops == null || possibleDrops.isEmpty()) {
return;
}
ItemStack drop = fishingBehaviour.chooseDrop(possibleDrops);
// It's possible that chooseDrop returns null if the sum of probability in possibleDrops is inferior than 100
if (drop == null) {
return;
}
// Extra processing depending on the mob and drop type
switch (target.getType()) {
case PLAYER:
Player targetPlayer = (Player) target;
switch (drop.getType()) {
case PLAYER_HEAD:
drop.setDurability((short) 3);
SkullMeta skullMeta = (SkullMeta) drop.getItemMeta();
skullMeta.setOwningPlayer(targetPlayer);
drop.setItemMeta(skullMeta);
break;
case BEDROCK:
if (FishingTreasureConfig.getInstance().getInventoryStealEnabled()) {
PlayerInventory inventory = targetPlayer.getInventory();
int length = inventory.getContents().length;
int slot = Misc.getRandom().nextInt(length);
drop = inventory.getItem(slot);
if (drop == null) {
break;
}
if (FishingTreasureConfig.getInstance().getInventoryStealStacks()) {
inventory.setItem(slot, null);
} else {
inventory.setItem(slot, (drop.getAmount() > 1) ? new ItemStack(drop.getType(), drop.getAmount() - 1) : null);
drop.setAmount(1);
}
targetPlayer.updateInventory();
}
break;
default:
break;
}
break;
case SHEEP:
Sheep sheep = (Sheep) target;
if (drop.getType().name().endsWith("WOOL")) {
if (sheep.isSheared()) {
return;
}
sheep.setSheared(true);
}
break;
default:
break;
}
McMMOPlayerShakeEvent shakeEvent = new McMMOPlayerShakeEvent(getPlayer(), drop);
drop = shakeEvent.getDrop();
if (shakeEvent.isCancelled() || drop == null) {
return;
}
Misc.dropItem(target.getLocation(), drop);
pluginRef.getCombatTools().dealDamage(target, Math.min(Math.max(target.getMaxHealth() / 4, 1), 10), EntityDamageEvent.DamageCause.CUSTOM, getPlayer()); // Make it so you can shake a mob no more than 4 times.
applyXpGain(pluginRef.getConfigManager().getConfigExperience().getShakeXP(), XPGainReason.PVE);
}
}
// public void shakeCheck(LivingEntity target) {
// if (pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getShakeChance(), getPlayer(), SubSkillType.FISHING_SHAKE))) {
// List<ShakeTreasure> possibleDrops = fishingBehaviour.findPossibleDrops(target);
//
// if (possibleDrops == null || possibleDrops.isEmpty()) {
// return;
// }
//
// ItemStack drop = fishingBehaviour.chooseDrop(possibleDrops);
//
// // It's possible that chooseDrop returns null if the sum of probability in possibleDrops is inferior than 100
// if (drop == null) {
// return;
// }
//
// // Extra processing depending on the mob and drop type
// switch (target.getType()) {
// case PLAYER:
// Player targetPlayer = (Player) target;
//
// switch (drop.getType()) {
// case PLAYER_HEAD:
// drop.setDurability((short) 3);
// SkullMeta skullMeta = (SkullMeta) drop.getItemMeta();
// skullMeta.setOwningPlayer(targetPlayer);
// drop.setItemMeta(skullMeta);
// break;
//
// case BEDROCK:
// if (FishingTreasureConfig.getInstance().getInventoryStealEnabled()) {
// PlayerInventory inventory = targetPlayer.getInventory();
// int length = inventory.getContents().length;
// int slot = Misc.getRandom().nextInt(length);
// drop = inventory.getItem(slot);
//
// if (drop == null) {
// break;
// }
//
// if (FishingTreasureConfig.getInstance().getInventoryStealStacks()) {
// inventory.setItem(slot, null);
// } else {
// inventory.setItem(slot, (drop.getAmount() > 1) ? new ItemStack(drop.getType(), drop.getAmount() - 1) : null);
// drop.setAmount(1);
// }
//
// targetPlayer.updateInventory();
// }
// break;
//
// default:
// break;
// }
// break;
//
// case SHEEP:
// Sheep sheep = (Sheep) target;
//
// if (drop.getType().name().endsWith("WOOL")) {
// if (sheep.isSheared()) {
// return;
// }
// sheep.setSheared(true);
// }
// break;
// default:
// break;
// }
//
// McMMOPlayerShakeEvent shakeEvent = new McMMOPlayerShakeEvent(getPlayer(), drop);
//
// drop = shakeEvent.getDrop();
//
// if (shakeEvent.isCancelled() || drop == null) {
// return;
// }
//
// Misc.dropItem(target.getLocation(), drop);
// pluginRef.getCombatTools().dealDamage(target, Math.min(Math.max(target.getMaxHealth() / 4, 1), 10), EntityDamageEvent.DamageCause.CUSTOM, getPlayer()); // Make it so you can shake a mob no more than 4 times.
// applyXpGain(pluginRef.getConfigManager().getConfigExperience().getShakeXP(), XPGainReason.PVE);
// }
// }
/**
* Process the Treasure Hunter ability for Fishing
*
* @return The {@link FishingTreasure} found, or null if no treasure was found.
*/
private FishingTreasure getFishingTreasure() {
double diceRoll = Misc.getRandom().nextDouble() * 100;
int luck;
if (getPlayer().getInventory().getItemInMainHand().getType() == Material.FISHING_ROD) {
luck = getPlayer().getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK);
} else {
// We know something was caught, so if the rod wasn't in the main hand it must be in the offhand
luck = getPlayer().getInventory().getItemInOffHand().getEnchantmentLevel(Enchantment.LUCK);
}
// Rather than subtracting luck (and causing a minimum 3% chance for every drop), scale by luck.
diceRoll *= (1.0 - luck * pluginRef.getConfigManager().getConfigFishing().getLureLuckModifier() / 100);
FishingTreasure treasure = null;
for (Rarity rarity : Rarity.values()) {
double dropRate = FishingTreasureConfig.getInstance().getItemDropRate(getLootTier(), rarity);
if (diceRoll <= dropRate) {
/*if (rarity == Rarity.TRAP) {
handleTraps();
break;
}*/
List<FishingTreasure> fishingTreasures = FishingTreasureConfig.getInstance().fishingRewards.get(rarity);
if (fishingTreasures.isEmpty()) {
return null;
}
treasure = fishingTreasures.get(Misc.getRandom().nextInt(fishingTreasures.size()));
break;
}
diceRoll -= dropRate;
}
if (treasure == null) {
return null;
}
ItemStack treasureDrop = treasure.getDrop().clone();
short maxDurability = treasureDrop.getType().getMaxDurability();
if (maxDurability > 0) {
treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability)));
}
if (treasureDrop.getAmount() > 1) {
treasureDrop.setAmount(Misc.getRandom().nextInt(treasureDrop.getAmount()) + 1);
}
treasure.setDrop(treasureDrop);
return treasure;
}
// private FishingTreasure getFishingTreasure() {
// double diceRoll = Misc.getRandom().nextDouble() * 100;
// int luck;
//
// if (getPlayer().getInventory().getItemInMainHand().getType() == Material.FISHING_ROD) {
// luck = getPlayer().getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK);
// } else {
// // We know something was caught, so if the rod wasn't in the main hand it must be in the offhand
// luck = getPlayer().getInventory().getItemInOffHand().getEnchantmentLevel(Enchantment.LUCK);
// }
//
// // Rather than subtracting luck (and causing a minimum 3% chance for every drop), scale by luck.
// diceRoll *= (1.0 - luck * pluginRef.getConfigManager().getConfigFishing().getLureLuckModifier() / 100);
//
// FishingTreasure treasure = null;
//
// for (Rarity rarity : Rarity.values()) {
// double dropRate = FishingTreasureConfig.getInstance().getItemDropRate(getLootTier(), rarity);
//
// if (diceRoll <= dropRate) {
// /*if (rarity == Rarity.TRAP) {
// handleTraps();
// break;
// }*/
//
// List<FishingTreasure> fishingTreasures = FishingTreasureConfig.getInstance().fishingRewards.get(rarity);
//
// if (fishingTreasures.isEmpty()) {
// return null;
// }
//
// treasure = fishingTreasures.get(Misc.getRandom().nextInt(fishingTreasures.size()));
// break;
// }
//
// diceRoll -= dropRate;
// }
//
// if (treasure == null) {
// return null;
// }
//
// ItemStack treasureDrop = treasure.getDrop().clone();
// short maxDurability = treasureDrop.getType().getMaxDurability();
//
// if (maxDurability > 0) {
// treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability)));
// }
//
// if (treasureDrop.getAmount() > 1) {
// treasureDrop.setAmount(Misc.getRandom().nextInt(treasureDrop.getAmount()) + 1);
// }
//
// treasure.setDrop(treasureDrop);
//
// return treasure;
// }
/**
* Process the Magic Hunter ability
@ -497,68 +485,68 @@ public class FishingManager extends SkillManager {
* @param treasureDrop The {@link ItemStack} to enchant
* @return true if the item has been enchanted
*/
private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) {
Map<Enchantment, Integer> enchants = new HashMap<>();
List<EnchantmentTreasure> fishingEnchantments = null;
double diceRoll = Misc.getRandom().nextDouble() * 100;
for (Rarity rarity : Rarity.values()) {
if (rarity == Rarity.RECORD) {
continue;
}
double dropRate = FishingTreasureConfig.getInstance().getEnchantmentDropRate(getLootTier(), rarity);
if (diceRoll <= dropRate) {
// Make sure enchanted books always get some kind of enchantment. --hoorigan
if (treasureDrop.getType() == Material.ENCHANTED_BOOK) {
diceRoll = dropRate + 1;
continue;
}
fishingEnchantments = FishingTreasureConfig.getInstance().fishingEnchantments.get(rarity);
break;
}
diceRoll -= dropRate;
}
if (fishingEnchantments == null) {
return enchants;
}
List<Enchantment> validEnchantments = getPossibleEnchantments(treasureDrop);
List<EnchantmentTreasure> possibleEnchants = new ArrayList<>();
for (EnchantmentTreasure enchantmentTreasure : fishingEnchantments) {
if (validEnchantments.contains(enchantmentTreasure.getEnchantment())) {
possibleEnchants.add(enchantmentTreasure);
}
}
if (possibleEnchants.isEmpty()) {
return enchants;
}
// This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
Collections.shuffle(possibleEnchants, Misc.getRandom());
int specificChance = 1;
for (EnchantmentTreasure enchantmentTreasure : possibleEnchants) {
Enchantment possibleEnchantment = enchantmentTreasure.getEnchantment();
if (treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) || Misc.getRandom().nextInt(specificChance) != 0) {
continue;
}
enchants.put(possibleEnchantment, enchantmentTreasure.getLevel());
specificChance *= 2;
}
return enchants;
}
// private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) {
// Map<Enchantment, Integer> enchants = new HashMap<>();
// List<EnchantmentTreasure> fishingEnchantments = null;
//
// double diceRoll = Misc.getRandom().nextDouble() * 100;
//
// for (Rarity rarity : Rarity.values()) {
// if (rarity == Rarity.RECORD) {
// continue;
// }
//
// double dropRate = FishingTreasureConfig.getInstance().getEnchantmentDropRate(getLootTier(), rarity);
//
// if (diceRoll <= dropRate) {
// // Make sure enchanted books always get some kind of enchantment. --hoorigan
// if (treasureDrop.getType() == Material.ENCHANTED_BOOK) {
// diceRoll = dropRate + 1;
// continue;
// }
// fishingEnchantments = FishingTreasureConfig.getInstance().fishingEnchantments.get(rarity);
// break;
// }
//
// diceRoll -= dropRate;
// }
//
// if (fishingEnchantments == null) {
// return enchants;
// }
//
// List<Enchantment> validEnchantments = getPossibleEnchantments(treasureDrop);
// List<EnchantmentTreasure> possibleEnchants = new ArrayList<>();
//
// for (EnchantmentTreasure enchantmentTreasure : fishingEnchantments) {
// if (validEnchantments.contains(enchantmentTreasure.getEnchantment())) {
// possibleEnchants.add(enchantmentTreasure);
// }
// }
//
// if (possibleEnchants.isEmpty()) {
// return enchants;
// }
//
// // This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
// Collections.shuffle(possibleEnchants, Misc.getRandom());
//
// int specificChance = 1;
//
// for (EnchantmentTreasure enchantmentTreasure : possibleEnchants) {
// Enchantment possibleEnchantment = enchantmentTreasure.getEnchantment();
//
// if (treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) || Misc.getRandom().nextInt(specificChance) != 0) {
// continue;
// }
//
// enchants.put(possibleEnchantment, enchantmentTreasure.getLevel());
//
// specificChance *= 2;
// }
//
// return enchants;
// }
private List<Enchantment> getPossibleEnchantments(ItemStack treasureDrop) {
Material dropType = treasureDrop.getType();