|
@@ -4,15 +4,13 @@ import com.gmail.nossr50.api.ItemSpawnReason;
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
|
-import com.gmail.nossr50.config.treasure.TreasureConfig;
|
|
|
|
|
|
+import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
|
|
|
+import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
|
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
|
|
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
|
-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.datatypes.treasure.*;
|
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
|
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
@@ -39,10 +37,12 @@ import org.bukkit.entity.*;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
+import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
|
import org.bukkit.util.BoundingBox;
|
|
import org.bukkit.util.BoundingBox;
|
|
import org.bukkit.util.Vector;
|
|
import org.bukkit.util.Vector;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@@ -369,9 +369,7 @@ public class FishingManager extends SkillManager {
|
|
return AdvancedConfig.getInstance().getFishingBoatReductionMaxWaitTicks();
|
|
return AdvancedConfig.getInstance().getFishingBoatReductionMaxWaitTicks();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public boolean isMagicHunterEnabled()
|
|
|
|
- {
|
|
|
|
|
|
+ public boolean isMagicHunterEnabled() {
|
|
return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.FISHING_MAGIC_HUNTER)
|
|
return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.FISHING_MAGIC_HUNTER)
|
|
&& RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.FISHING_TREASURE_HUNTER)
|
|
&& RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.FISHING_TREASURE_HUNTER)
|
|
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.FISHING_TREASURE_HUNTER);
|
|
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.FISHING_TREASURE_HUNTER);
|
|
@@ -382,12 +380,14 @@ public class FishingManager extends SkillManager {
|
|
*
|
|
*
|
|
* @param fishingCatch The {@link Item} initially caught
|
|
* @param fishingCatch The {@link Item} initially caught
|
|
*/
|
|
*/
|
|
- public void handleFishing(Item fishingCatch) {
|
|
|
|
|
|
+ public void processFishing(@NotNull Item fishingCatch) {
|
|
this.fishingCatch = fishingCatch;
|
|
this.fishingCatch = fishingCatch;
|
|
int fishXp = ExperienceConfig.getInstance().getXp(PrimarySkillType.FISHING, fishingCatch.getItemStack().getType());
|
|
int fishXp = ExperienceConfig.getInstance().getXp(PrimarySkillType.FISHING, fishingCatch.getItemStack().getType());
|
|
int treasureXp = 0;
|
|
int treasureXp = 0;
|
|
|
|
+ ItemStack treasureDrop = null;
|
|
Player player = getPlayer();
|
|
Player player = getPlayer();
|
|
FishingTreasure treasure = null;
|
|
FishingTreasure treasure = null;
|
|
|
|
+ boolean fishingSucceeds = false;
|
|
|
|
|
|
if (Config.getInstance().getFishingDropsEnabled() && Permissions.isSubSkillEnabled(player, SubSkillType.FISHING_TREASURE_HUNTER)) {
|
|
if (Config.getInstance().getFishingDropsEnabled() && Permissions.isSubSkillEnabled(player, SubSkillType.FISHING_TREASURE_HUNTER)) {
|
|
treasure = getFishingTreasure();
|
|
treasure = getFishingTreasure();
|
|
@@ -395,49 +395,92 @@ public class FishingManager extends SkillManager {
|
|
}
|
|
}
|
|
|
|
|
|
if (treasure != null) {
|
|
if (treasure != null) {
|
|
- ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
|
|
|
|
- Map<Enchantment, Integer> enchants = new HashMap<>();
|
|
|
|
|
|
+ if(treasure instanceof FishingTreasureBook) {
|
|
|
|
+ treasureDrop = createEnchantBook((FishingTreasureBook) treasure);
|
|
|
|
+ } else {
|
|
|
|
+ treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
|
|
|
|
|
|
- if (isMagicHunterEnabled()
|
|
|
|
- && ItemUtils.isEnchantable(treasureDrop)) {
|
|
|
|
- enchants = handleMagicHunter(treasureDrop);
|
|
|
|
}
|
|
}
|
|
|
|
+ Map<Enchantment, Integer> enchants = new HashMap<>();
|
|
|
|
+ McMMOPlayerFishingTreasureEvent event;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Books get some special treatment
|
|
|
|
+ */
|
|
|
|
+ if(treasure instanceof FishingTreasureBook) {
|
|
|
|
+ //Skip the magic hunter stuff
|
|
|
|
+ if(treasureDrop.getItemMeta() != null) {
|
|
|
|
+ enchants.putAll(treasureDrop.getItemMeta().getEnchants());
|
|
|
|
+ }
|
|
|
|
|
|
- McMMOPlayerFishingTreasureEvent event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
|
|
|
|
|
|
+ event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
|
|
|
|
+ } else {
|
|
|
|
+ if (isMagicHunterEnabled() && ItemUtils.isEnchantable(treasureDrop)) {
|
|
|
|
+ enchants = processMagicHunter(treasureDrop);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
|
|
|
|
+ }
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
if (!event.isCancelled()) {
|
|
treasureDrop = event.getTreasure();
|
|
treasureDrop = event.getTreasure();
|
|
treasureXp = event.getXp();
|
|
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;
|
|
|
|
|
|
+ // Drop the original catch at the feet of the player and set the treasure as the real catch
|
|
|
|
+ if (treasureDrop != null) {
|
|
|
|
+ fishingSucceeds = true;
|
|
|
|
+ boolean enchanted = false;
|
|
|
|
|
|
- if (!enchants.isEmpty()) {
|
|
|
|
- treasureDrop.addUnsafeEnchantments(enchants);
|
|
|
|
- enchanted = true;
|
|
|
|
- }
|
|
|
|
|
|
+ if(treasure instanceof FishingTreasureBook) {
|
|
|
|
+ enchanted = true;
|
|
|
|
+ } else if (!enchants.isEmpty()) {
|
|
|
|
+ treasureDrop.addUnsafeEnchantments(enchants);
|
|
|
|
+ enchanted = true;
|
|
|
|
+ }
|
|
|
|
|
|
- if (enchanted) {
|
|
|
|
- NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Fishing.Ability.TH.MagicFound");
|
|
|
|
- }
|
|
|
|
|
|
+ if (enchanted) {
|
|
|
|
+ NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Fishing.Ability.TH.MagicFound");
|
|
|
|
+ }
|
|
|
|
|
|
- if (Config.getInstance().getFishingExtraFish()) {
|
|
|
|
- Misc.spawnItem(player.getEyeLocation(), fishingCatch.getItemStack(), ItemSpawnReason.FISHING_EXTRA_FISH);
|
|
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ treasureDrop = null;
|
|
|
|
+ treasureXp = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- fishingCatch.setItemStack(treasureDrop);
|
|
|
|
|
|
+ if(fishingSucceeds) {
|
|
|
|
+ fishingCatch.setItemStack(treasureDrop);
|
|
|
|
+
|
|
|
|
+ if (Config.getInstance().getFishingExtraFish()) {
|
|
|
|
+ Misc.spawnItem(player.getEyeLocation(), fishingCatch.getItemStack(), ItemSpawnReason.FISHING_EXTRA_FISH);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
applyXpGain(fishXp + treasureXp, XPGainReason.PVE);
|
|
applyXpGain(fishXp + treasureXp, XPGainReason.PVE);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private @NotNull ItemStack createEnchantBook(@NotNull FishingTreasureBook fishingTreasureBook) {
|
|
|
|
+ ItemStack itemStack = fishingTreasureBook.getDrop().clone();
|
|
|
|
+ EnchantmentWrapper enchantmentWrapper = getRandomEnchantment(fishingTreasureBook.getLegalEnchantments());
|
|
|
|
+ ItemMeta itemMeta = itemStack.getItemMeta();
|
|
|
|
+
|
|
|
|
+ if(itemMeta == null)
|
|
|
|
+ return itemStack;
|
|
|
|
+
|
|
|
|
+ itemMeta.addEnchant(enchantmentWrapper.getEnchantment(), enchantmentWrapper.getEnchantmentLevel(), ExperienceConfig.getInstance().allowUnsafeEnchantments());
|
|
|
|
+ itemStack.setItemMeta(itemMeta);
|
|
|
|
+ return itemStack;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private @NotNull EnchantmentWrapper getRandomEnchantment(@NotNull List<EnchantmentWrapper> enchantmentWrappers) {
|
|
|
|
+ Collections.shuffle(enchantmentWrappers, Misc.getRandom());
|
|
|
|
+
|
|
|
|
+ int randomIndex = Misc.getRandom().nextInt(enchantmentWrappers.size());
|
|
|
|
+ return enchantmentWrappers.get(randomIndex);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Handle the vanilla XP boost for Fishing
|
|
* Handle the vanilla XP boost for Fishing
|
|
*
|
|
*
|
|
@@ -487,7 +530,7 @@ public class FishingManager extends SkillManager {
|
|
break;
|
|
break;
|
|
|
|
|
|
case BEDROCK:
|
|
case BEDROCK:
|
|
- if (TreasureConfig.getInstance().getInventoryStealEnabled()) {
|
|
|
|
|
|
+ if (FishingTreasureConfig.getInstance().getInventoryStealEnabled()) {
|
|
PlayerInventory inventory = targetPlayer.getInventory();
|
|
PlayerInventory inventory = targetPlayer.getInventory();
|
|
int length = inventory.getContents().length;
|
|
int length = inventory.getContents().length;
|
|
int slot = Misc.getRandom().nextInt(length);
|
|
int slot = Misc.getRandom().nextInt(length);
|
|
@@ -497,7 +540,7 @@ public class FishingManager extends SkillManager {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- if (TreasureConfig.getInstance().getInventoryStealStacks()) {
|
|
|
|
|
|
+ if (FishingTreasureConfig.getInstance().getInventoryStealStacks()) {
|
|
inventory.setItem(slot, null);
|
|
inventory.setItem(slot, null);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -547,7 +590,7 @@ public class FishingManager extends SkillManager {
|
|
*
|
|
*
|
|
* @return The {@link FishingTreasure} found, or null if no treasure was found.
|
|
* @return The {@link FishingTreasure} found, or null if no treasure was found.
|
|
*/
|
|
*/
|
|
- private FishingTreasure getFishingTreasure() {
|
|
|
|
|
|
+ private @Nullable FishingTreasure getFishingTreasure() {
|
|
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
|
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
|
int luck;
|
|
int luck;
|
|
|
|
|
|
@@ -565,15 +608,11 @@ public class FishingManager extends SkillManager {
|
|
FishingTreasure treasure = null;
|
|
FishingTreasure treasure = null;
|
|
|
|
|
|
for (Rarity rarity : Rarity.values()) {
|
|
for (Rarity rarity : Rarity.values()) {
|
|
- double dropRate = TreasureConfig.getInstance().getItemDropRate(getLootTier(), rarity);
|
|
|
|
|
|
+ double dropRate = FishingTreasureConfig.getInstance().getItemDropRate(getLootTier(), rarity);
|
|
|
|
|
|
if (diceRoll <= dropRate) {
|
|
if (diceRoll <= dropRate) {
|
|
- /*if (rarity == Rarity.TRAP) {
|
|
|
|
- handleTraps();
|
|
|
|
- break;
|
|
|
|
- }*/
|
|
|
|
|
|
|
|
- List<FishingTreasure> fishingTreasures = TreasureConfig.getInstance().fishingRewards.get(rarity);
|
|
|
|
|
|
+ List<FishingTreasure> fishingTreasures = FishingTreasureConfig.getInstance().fishingRewards.get(rarity);
|
|
|
|
|
|
if (fishingTreasures.isEmpty()) {
|
|
if (fishingTreasures.isEmpty()) {
|
|
return null;
|
|
return null;
|
|
@@ -611,21 +650,16 @@ public class FishingManager extends SkillManager {
|
|
* Process the Magic Hunter ability
|
|
* Process the Magic Hunter ability
|
|
*
|
|
*
|
|
* @param treasureDrop The {@link ItemStack} to enchant
|
|
* @param treasureDrop The {@link ItemStack} to enchant
|
|
- *
|
|
|
|
- * @return true if the item has been enchanted
|
|
|
|
*/
|
|
*/
|
|
- private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) {
|
|
|
|
|
|
+ private Map<Enchantment, Integer> processMagicHunter(@NotNull ItemStack treasureDrop) {
|
|
Map<Enchantment, Integer> enchants = new HashMap<>();
|
|
Map<Enchantment, Integer> enchants = new HashMap<>();
|
|
List<EnchantmentTreasure> fishingEnchantments = null;
|
|
List<EnchantmentTreasure> fishingEnchantments = null;
|
|
|
|
|
|
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
|
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
|
|
|
|
|
for (Rarity rarity : Rarity.values()) {
|
|
for (Rarity rarity : Rarity.values()) {
|
|
- if (rarity == Rarity.RECORD) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- double dropRate = TreasureConfig.getInstance().getEnchantmentDropRate(getLootTier(), rarity);
|
|
|
|
|
|
+ double dropRate = FishingTreasureConfig.getInstance().getEnchantmentDropRate(getLootTier(), rarity);
|
|
|
|
|
|
if (diceRoll <= dropRate) {
|
|
if (diceRoll <= dropRate) {
|
|
// Make sure enchanted books always get some kind of enchantment. --hoorigan
|
|
// Make sure enchanted books always get some kind of enchantment. --hoorigan
|
|
@@ -633,7 +667,8 @@ public class FishingManager extends SkillManager {
|
|
diceRoll = dropRate + 1;
|
|
diceRoll = dropRate + 1;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- fishingEnchantments = TreasureConfig.getInstance().fishingEnchantments.get(rarity);
|
|
|
|
|
|
+
|
|
|
|
+ fishingEnchantments = FishingTreasureConfig.getInstance().fishingEnchantments.get(rarity);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|