9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-21 16:09:34 +00:00

1.3.0-beta-7

This commit is contained in:
Xiao-MoMi
2023-03-14 21:09:39 +08:00
parent 62a0a5015a
commit cc9e59a576
41 changed files with 589 additions and 370 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '1.3.0-beta-5'
version = '1.3.0-beta-7'
repositories {
mavenCentral()
@@ -22,6 +22,7 @@ repositories {
dependencies {
compileOnly fileTree(dir:'libs',includes:['*.jar'])
implementation fileTree(dir:'libs',includes:['BiomeAPI.jar'])
compileOnly('com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT')
compileOnly('io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT')
compileOnly('com.github.angeschossen:LandsAPI:6.26.18')
compileOnly('com.zaxxer:HikariCP:5.0.1')

Binary file not shown.

Binary file not shown.

View File

@@ -1 +0,0 @@
https://polymart.org/resource/customcrops.2625

Binary file not shown.

Binary file not shown.

View File

@@ -64,6 +64,7 @@ public final class CustomFishing extends JavaPlugin {
this.versionHelper = new VersionHelper(this);
this.fishingManager = new FishingManager(this);
this.dataManager = new DataManager(this);
this.statisticsManager = new StatisticsManager(this);
this.integrationManager = new IntegrationManager(this);
this.competitionManager = new CompetitionManager(this);
this.effectManager = new EffectManager(this);
@@ -73,7 +74,6 @@ public final class CustomFishing extends JavaPlugin {
this.sellManager = new SellManager(this);
this.bagDataManager = new BagDataManager(this);
this.offsetManager = new OffsetManager(this);
this.statisticsManager = new StatisticsManager(this);
this.reload();
this.registerCommands();
this.registerQuests();

View File

@@ -23,13 +23,13 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
public class FishHookEvent extends PlayerEvent implements Cancellable {
public class MiniGameStartEvent extends PlayerEvent implements Cancellable {
private boolean cancelled;
private int difficulty;
private static final HandlerList handlerList = new HandlerList();
public FishHookEvent(@NotNull Player who, int difficulty) {
public MiniGameStartEvent(@NotNull Player who, int difficulty) {
super(who);
this.cancelled = false;
this.difficulty = difficulty;

View File

@@ -41,6 +41,10 @@ public class RodCastEvent extends PlayerEvent implements Cancellable {
return this.isCancelled;
}
/**
* If cancelled, PlayerFishEvent would also be cancelled
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.isCancelled = cancel;

View File

@@ -32,7 +32,6 @@ public class TotemActivationEvent extends PlayerEvent implements Cancellable {
private final Location location;
private static final HandlerList handlerList = new HandlerList();
public TotemActivationEvent(@NotNull Player who, Location location, TotemConfig totem) {
super(who);
this.cancelled = false;

View File

@@ -74,7 +74,7 @@ public class BaitCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", args.get(1)));
return true;
}
if (!CustomFishing.getInstance().getEffectManager().getBaitItems().containsKey(args.get(1))) {
if (!CustomFishing.getInstance().getEffectManager().getBaitItems().containsKey(args.get(2))) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}

View File

@@ -52,11 +52,11 @@ public class LootCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
if (args.size() == 2){
if (args.size() == 2) {
ItemStackUtil.givePlayerLoot(player, args.get(1), 1);
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.getItem.replace("{Amount}", "1").replace("{Item}", args.get(1)));
} else {
if (Integer.parseInt(args.get(2)) < 1){
if (Integer.parseInt(args.get(2)) < 1) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount);
return true;
}

View File

@@ -79,11 +79,11 @@ public class RodCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
if (args.size() == 3){
if (args.size() == 3) {
ItemStackUtil.givePlayerRod(player, args.get(2), 1);
super.giveItemMsg(sender, args.get(1), args.get(2), 1);
} else {
if (Integer.parseInt(args.get(3)) < 1){
if (Integer.parseInt(args.get(3)) < 1) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount);
return true;
}

View File

@@ -32,27 +32,33 @@ import java.util.stream.Collectors;
public class PlayerStatisticsData {
private final ConcurrentHashMap<String, Integer> amountMap;
private final LootManager lootManager;
private int total_catch_amount;
public PlayerStatisticsData() {
this.amountMap = new ConcurrentHashMap<>();
this.lootManager = CustomFishing.getInstance().getLootManager();
this.total_catch_amount = 0;
}
public PlayerStatisticsData(ConfigurationSection section) {
this.lootManager = CustomFishing.getInstance().getLootManager();
this.amountMap = new ConcurrentHashMap<>();
this.total_catch_amount = 0;
for (String key : section.getKeys(false)) {
amountMap.put(key, section.getInt(key));
int amount = section.getInt(key);
total_catch_amount += amount;
amountMap.put(key, amount);
}
}
public PlayerStatisticsData(String longText) {
this.lootManager = CustomFishing.getInstance().getLootManager();
this.total_catch_amount = 0;
this.amountMap = (ConcurrentHashMap<String, Integer>) Arrays.stream(longText.split(";"))
.map(element -> element.split(":"))
.filter(pair -> pair.length == 2)
.collect(Collectors.toConcurrentMap(pair -> pair[0], pair -> Integer.parseInt(pair[1])));
.collect(Collectors.toConcurrentMap(pair -> pair[0], pair -> {
int amount = Integer.parseInt(pair[1]);
total_catch_amount += amount;
return amount;
}));
}
public String getLongText() {
@@ -63,14 +69,19 @@ public class PlayerStatisticsData {
return joiner.toString();
}
public void addFishAmount(Loot loot, int amount, UUID uuid) {
public void addFishAmount(Loot loot, UUID uuid, int amount) {
Integer previous = amountMap.get(loot.getKey());
if (previous == null) previous = 0;
int after = previous + amount;
amountMap.put(loot.getKey(), after);
total_catch_amount += amount;
Player player = Bukkit.getPlayer(uuid);
if (player == null) return;
HashMap<Integer, Action[]> actionMap = loot.getSuccessTimesActions();
doSuccessTimesAction(previous, after, player, loot);
}
private void doSuccessTimesAction(Integer previous, int after, Player player, Loot vanilla) {
HashMap<Integer, Action[]> actionMap = vanilla.getSuccessTimesActions();
if (actionMap != null) {
for (Map.Entry<Integer, Action[]> entry : actionMap.entrySet()) {
if (entry.getKey() > previous && entry.getKey() <= after) {
@@ -97,7 +108,7 @@ public class PlayerStatisticsData {
* @return percent
*/
public double getCategoryUnlockProgress(String category) {
List<String> categories = lootManager.getCategories(category);
List<String> categories = CustomFishing.getInstance().getLootManager().getCategories(category);
if (categories == null) return -1d;
double total = categories.size();
double unlocked = 0;
@@ -110,7 +121,7 @@ public class PlayerStatisticsData {
}
public int getCategoryTotalFishAmount(String category) {
List<String> categories = lootManager.getCategories(category);
List<String> categories = CustomFishing.getInstance().getLootManager().getCategories(category);
if (categories == null) return -1;
int total = 0;
for (String value : categories) {
@@ -130,4 +141,8 @@ public class PlayerStatisticsData {
public void setData(String key, int value) {
amountMap.put(key, value);
}
public int getTotalCatchAmount() {
return total_catch_amount;
}
}

View File

@@ -29,6 +29,10 @@ public class ModeThreeBar extends FishingBar {
private final int fish_offset;
private final int fish_start_position;
private final int success_position;
private final double ultimate_strain;
private final double normal_increase;
private final double struggling_increase;
private final double strain_loss;
public ModeThreeBar(ConfigurationSection section) {
super(section);
@@ -40,6 +44,10 @@ public class ModeThreeBar extends FishingBar {
this.fish_offset = section.getInt("arguments.fish-offset");
this.fish_start_position = section.getInt("arguments.fish-start-position");
this.success_position = section.getInt("arguments.success-position");
this.ultimate_strain = section.getDouble("arguments.ultimate-strain", 50);
this.normal_increase = section.getDouble("arguments.normal-pull-strain-increase", 1);
this.struggling_increase = section.getDouble("arguments.struggling-strain-increase", 2);
this.strain_loss = section.getDouble("arguments.loosening-strain-loss", 2);
}
public String getFish_image() {
@@ -73,4 +81,20 @@ public class ModeThreeBar extends FishingBar {
public String[] getStruggling_fish_image() {
return struggling_fish_image;
}
public double getUltimate_strain() {
return ultimate_strain;
}
public double getNormal_increase() {
return normal_increase;
}
public double getStruggling_increase() {
return struggling_increase;
}
public double getStrain_loss() {
return strain_loss;
}
}

View File

@@ -32,6 +32,9 @@ public class ModeTwoBar extends FishingBar {
private final int fish_icon_width;
private final String[] progress;
private final double punishment;
private final double water_resistance;
private final double pulling_strength;
private final double loosening_loss;
public ModeTwoBar(ConfigurationSection section) {
super(section);
@@ -44,6 +47,9 @@ public class ModeTwoBar extends FishingBar {
this.fish_icon_width = section.getInt("arguments.fish-icon-width");
this.punishment = section.getDouble("arguments.punishment");
this.progress = section.getStringList("progress").toArray(new String[0]);
this.water_resistance = section.getDouble("arguments.water-resistance", 0.15);
this.pulling_strength = section.getDouble("arguments.pulling-strength", 0.45);
this.loosening_loss = section.getDouble("arguments.loosening-strength-loss", 0.3);
}
public int getRandomTimeRequirement() {
@@ -81,4 +87,16 @@ public class ModeTwoBar extends FishingBar {
public double getPunishment() {
return punishment;
}
public double getWater_resistance() {
return water_resistance;
}
public double getPulling_strength() {
return pulling_strength;
}
public double getLoosening_loss() {
return loosening_loss;
}
}

View File

@@ -31,7 +31,7 @@ import java.util.Objects;
public class Item {
private final String key;
private int amount;
private final int amount;
private final Material material;
private String name;
private List<String> lore;
@@ -42,6 +42,8 @@ public class Item {
private List<LeveledEnchantment> enchantment;
private Map<String, Object> nbt;
private String totem;
private boolean headStackable;
private String[] cfTag;
public Item(Material material, String key) {
this.material = material;
@@ -80,6 +82,7 @@ public class Item {
}
if (section.contains("head64")) {
this.setHead64(section.getString("head64"));
this.setHeadStackable(section.getBoolean("head-stackable", false));
}
if (section.contains("totem")) {
this.setTotem(section.getString("totem"));
@@ -170,6 +173,22 @@ public class Item {
this.totem = totem;
}
public boolean isHeadStackable() {
return headStackable;
}
public void setHeadStackable(boolean headStackable) {
this.headStackable = headStackable;
}
public String[] getCfTag() {
return cfTag;
}
public void setCfTag(String[] cfTag) {
this.cfTag = cfTag;
}
public Item cloneWithPrice(double price){
Item newItem = new Item(this.material, this.key);
if (this.lore != null){

View File

@@ -59,17 +59,17 @@ public class ModeThreeGame extends FishingGame {
}
if (player.isSneaking()) {
if (struggling_time > 0) {
strain += (2 + ((double) difficulty / 5));
strain += (modeThreeBar.getStruggling_increase() + ((double) difficulty / 5));
fish_position -= 1;
}
else {
strain += 1;
strain += modeThreeBar.getNormal_increase();
fish_position -= 2;
}
}
else {
fish_position++;
strain -= 2;
strain -= modeThreeBar.getStrain_loss();
}
if (fish_position < modeThreeBar.getSuccess_position() - modeThreeBar.getFish_icon_width() - 1) {
cancel();
@@ -82,7 +82,7 @@ public class ModeThreeGame extends FishingGame {
fishingManager.removeFishingPlayer(player);
return;
}
if (fish_position + modeThreeBar.getFish_icon_width() > modeThreeBar.getBar_effective_width() || strain > 50) {
if (fish_position + modeThreeBar.getFish_icon_width() > modeThreeBar.getBar_effective_width() || strain > modeThreeBar.getUltimate_strain()) {
cancel();
FishHook fishHook = fishingManager.getBobber(player);
if (fishHook != null) {
@@ -102,10 +102,9 @@ public class ModeThreeGame extends FishingGame {
+ (struggling_time > 0 ? modeThreeBar.getStruggling_fish_image()[timer] : modeThreeBar.getFish_image())
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars(modeThreeBar.getBar_effective_width() - fish_position - modeThreeBar.getFish_icon_width()) + "</font>"
+ "</font>";
if (strain > 50) strain = 50;
if (strain < 0) strain = 0;
strain = Math.max(0, Math.min(strain, modeThreeBar.getUltimate_strain()));
AdventureUtil.playerTitle(player,
title.replace("{strain}", modeThreeBar.getStrain()[(int) ((strain / 50) * modeThreeBar.getStrain().length)])
title.replace("{strain}", modeThreeBar.getStrain()[(int) ((strain / modeThreeBar.getUltimate_strain()) * modeThreeBar.getStrain().length)])
, bar,0,500,0
);
}

View File

@@ -95,8 +95,7 @@ public class ModeTwoGame extends FishingGame {
+ modeTwoBar.getFish_image()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - fish_position - modeTwoBar.getFish_icon_width() + 1)) + "</font>"
+ "</font>";
if (hold_time > time_requirement) hold_time = time_requirement;
if (hold_time < 0) hold_time = 0;
hold_time = Math.max(0, Math.min(hold_time, time_requirement));
AdventureUtil.playerTitle(player,
title.replace("{progress}", modeTwoBar.getProgress()[(int) ((hold_time / time_requirement) * modeTwoBar.getProgress().length)])
, bar,0,500,0
@@ -114,21 +113,21 @@ public class ModeTwoGame extends FishingGame {
private void fraction() {
if (judgement_velocity > 0) {
judgement_velocity -= 0.15;
judgement_velocity -= modeTwoBar.getWater_resistance();
if (judgement_velocity < 0) judgement_velocity = 0;
}
else {
judgement_velocity += 0.15;
judgement_velocity += modeTwoBar.getWater_resistance();
if (judgement_velocity > 0) judgement_velocity = 0;
}
}
private void reduceV() {
fish_velocity -= 0.3;
fish_velocity -= modeTwoBar.getLoosening_loss();
}
private void addV() {
fish_velocity += 0.45;
fish_velocity += modeTwoBar.getPulling_strength();
}
private void calibrate() {

View File

@@ -85,15 +85,15 @@ public class CustomPapi implements RequirementInterface {
private List<PapiRequirement> getRequirements(Map<String, Object> map) {
List<PapiRequirement> papiRequirements = new ArrayList<>();
map.keySet().forEach(key -> {
if (key.startsWith("&&")){
if (key.startsWith("&&")) {
if (map.get(key) instanceof MemorySection map2){
addAndRequirements(papiRequirements, map2.getValues(false));
}
}else if (key.startsWith("||")){
} else if (key.startsWith("||")) {
if (map.get(key) instanceof MemorySection map2){
addOrRequirements(papiRequirements, map2.getValues(false));
}
}else {
} else {
if (map.get(key) instanceof MemorySection map2){
String type = map2.getString("type");
if (type == null) return;

View File

@@ -20,6 +20,6 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.fishing.FishingCondition;
public interface RequirementInterface {
boolean isConditionMet(FishingCondition fishingCondition);
boolean isConditionMet(FishingCondition fishingCondition);
}

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.integration.enchantment;
import net.advancedplugins.ae.api.AEAPI;

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.integration.enchantment;
import net.momirealms.customfishing.integration.EnchantmentInterface;

View File

@@ -21,6 +21,8 @@ import com.willfp.eco.core.items.CustomItem;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.loot.Item;
import net.momirealms.customfishing.util.ItemStackUtil;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
@@ -30,7 +32,7 @@ public class EcoItemRegister {
public static void registerItems() {
// Rods
for (Map.Entry<String, ItemStack> entry : CustomFishing.getInstance().getEffectManager().getRodItems().entrySet()) {
for (Map.Entry<String, Item> entry : CustomFishing.getInstance().getEffectManager().getRodItems().entrySet()) {
new CustomItem(
new NamespacedKey(CustomFishing.getInstance(), "rod_" + entry.getKey()),
itemStack -> {
@@ -44,11 +46,11 @@ public class EcoItemRegister {
return false;
}
},
entry.getValue()
ItemStackUtil.getFromItem(entry.getValue())
).register();
}
// Baits
for (Map.Entry<String, ItemStack> entry : CustomFishing.getInstance().getEffectManager().getBaitItems().entrySet()) {
for (Map.Entry<String, Item> entry : CustomFishing.getInstance().getEffectManager().getBaitItems().entrySet()) {
new CustomItem(
new NamespacedKey(CustomFishing.getInstance(), "bait_" + entry.getKey()),
itemStack -> {
@@ -62,11 +64,11 @@ public class EcoItemRegister {
return false;
}
},
entry.getValue()
ItemStackUtil.getFromItem(entry.getValue())
).register();
}
// Utils
for (Map.Entry<String, ItemStack> entry : CustomFishing.getInstance().getEffectManager().getUtilItems().entrySet()) {
for (Map.Entry<String, Item> entry : CustomFishing.getInstance().getEffectManager().getUtilItems().entrySet()) {
new CustomItem(
new NamespacedKey(CustomFishing.getInstance(), "util_" + entry.getKey()),
itemStack -> {
@@ -80,7 +82,7 @@ public class EcoItemRegister {
return false;
}
},
entry.getValue()
ItemStackUtil.getFromItem(entry.getValue())
).register();
}
}

View File

@@ -35,7 +35,7 @@ public class MMOItemsItemImpl implements ItemInterface {
if (!material.startsWith("MMOItems:")) return null;
material = material.substring(9);
String[] split = StringUtils.split(material, ":");
MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1]);
MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1].toUpperCase());
return mmoItem == null ? null : mmoItem.newBuilder().build();
}

View File

@@ -1,5 +1,23 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.integration.job;
import com.willfp.ecojobs.EcoJobsPlugin;
import com.willfp.ecojobs.api.EcoJobsAPI;
import com.willfp.ecojobs.jobs.Job;
import com.willfp.ecojobs.jobs.Jobs;
@@ -8,18 +26,12 @@ import org.bukkit.entity.Player;
public class EcoJobsImpl implements JobInterface {
private final EcoJobsAPI api;
public EcoJobsImpl() {
this.api = EcoJobsAPI.getInstance();
}
@Override
public void addXp(Player player, double amount) {
Job job = api.getActiveJob(player);
Job job = EcoJobsAPI.getInstance().getActiveJob(player);
if (job == null) return;
if (job.getId().equals("fisherman")) {
api.giveJobExperience(player, job, amount);
EcoJobsAPI.getInstance().giveJobExperience(player, job, amount);
}
}
@@ -27,6 +39,6 @@ public class EcoJobsImpl implements JobInterface {
public int getLevel(Player player) {
Job job = Jobs.getByID("fisherman");
if (job == null) return 0;
return api.getJobLevel(player, job);
return EcoJobsAPI.getInstance().getJobLevel(player, job);
}
}

View File

@@ -0,0 +1,13 @@
package net.momirealms.customfishing.integration.mob;
import net.momirealms.customfishing.fishing.loot.Mob;
import net.momirealms.customfishing.integration.MobInterface;
import org.bukkit.Location;
public class EliteMobsMobImpl implements MobInterface {
@Override
public void summon(Location playerLoc, Location summonLoc, Mob mob) {
}
}

View File

@@ -2,16 +2,17 @@ package net.momirealms.customfishing.integration.papi;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.manager.StatisticsManager;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class StatisticsPapi extends PlaceholderExpansion {
private final CustomFishing plugin;
private final StatisticsManager statisticsManager;
public StatisticsPapi(CustomFishing plugin) {
this.plugin = plugin;
this.statisticsManager = plugin.getStatisticsManager();
}
@Override
@@ -26,7 +27,7 @@ public class StatisticsPapi extends PlaceholderExpansion {
@Override
public @NotNull String getVersion() {
return "1.0";
return "1.1";
}
@Override
@@ -38,23 +39,26 @@ public class StatisticsPapi extends PlaceholderExpansion {
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
String[] args = params.split("_", 2);
switch (args[0]) {
case "total" -> {
return String.valueOf(statisticsManager.getTotalFishAmount(player.getUniqueId()));
}
case "amount" -> {
if (args[1].equals("")) return "lack args";
return String.valueOf(plugin.getStatisticsManager().getFishAmount(player.getUniqueId(), args[1]));
return String.valueOf(statisticsManager.getFishAmount(player.getUniqueId(), args[1]));
}
case "hascaught" -> {
if (args[1].equals("")) return "lack args";
return String.valueOf(plugin.getStatisticsManager().hasFished(player.getUniqueId(), args[1]));
return String.valueOf(statisticsManager.hasFished(player.getUniqueId(), args[1]));
}
case "category" -> {
String[] moreArgs = args[1].split("_", 2);
if (moreArgs[1].equals("")) return "lack args";
switch (moreArgs[0]) {
case "total" -> {
return String.valueOf(plugin.getStatisticsManager().getCategoryTotalFishAmount(player.getUniqueId(), moreArgs[1]));
return String.valueOf(statisticsManager.getCategoryTotalFishAmount(player.getUniqueId(), moreArgs[1]));
}
case "progress" -> {
String progress = String.format("%.1f", plugin.getStatisticsManager().getCategoryUnlockProgress(player.getUniqueId(), moreArgs[1]));
String progress = String.format("%.1f", statisticsManager.getCategoryUnlockProgress(player.getUniqueId(), moreArgs[1]));
return progress.equals("100.0") ? "100" : progress;
}
}

View File

@@ -46,7 +46,6 @@ public class ConfigManager {
public static boolean convertMMOItems;
public static boolean preventPickUp;
public static boolean enableFishingBag;
public static boolean otherLootHasFishingBar;
public static boolean allRodsFishInLava;
public static boolean enableSuccessTitle;
public static String[] successTitle;
@@ -101,7 +100,6 @@ public class ConfigManager {
private static void loadMechanics(YamlConfiguration config) {
disableBar = config.getBoolean("mechanics.disable-bar-mechanic", false);
instantBar = config.getBoolean("mechanics.instant-bar", false);
otherLootHasFishingBar = config.getBoolean("mechanics.other-loots.fishing-bar", true);
enableVanillaLoot = config.getBoolean("mechanics.other-loots.vanilla.enable", true);
vanillaLootRatio = config.getDouble("mechanics.other-loots.vanilla.ratio", 0.4);
enableMcMMOLoot = config.getBoolean("mechanics.other-loots.mcMMO.enable", false);

View File

@@ -26,6 +26,7 @@ import net.momirealms.customfishing.util.ItemStackUtil;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@@ -36,12 +37,13 @@ import java.util.Set;
public class EffectManager extends Function {
private final CustomFishing plugin;
private final HashMap<String, ItemStack> baitItems;
private final HashMap<String, Item> baitItems;
private final HashMap<String, Effect> baitEffects;
private final HashMap<String, ItemStack> rodItems;
private final HashMap<String, Item> rodItems;
private final HashMap<String, Effect> rodEffects;
private final HashMap<String, Item> utilItems;
private final HashMap<String, Effect> utilEffects;
private final HashMap<String, Effect> enchantEffects;
private final HashMap<String, ItemStack> utilItems;
public EffectManager(CustomFishing plugin) {
this.plugin = plugin;
@@ -51,6 +53,7 @@ public class EffectManager extends Function {
this.rodItems = new HashMap<>();
this.utilItems = new HashMap<>();
this.enchantEffects = new HashMap<>();
this.utilEffects = new HashMap<>();
}
@Override
@@ -67,7 +70,9 @@ public class EffectManager extends Function {
this.baitItems.clear();
this.rodEffects.clear();
this.rodItems.clear();
this.utilItems.clear();
this.enchantEffects.clear();
this.utilEffects.clear();
}
private void loadUtil() {
@@ -77,6 +82,7 @@ public class EffectManager extends Function {
plugin.saveResource("utils" + File.separator + "fish_finder.yml", false);
plugin.saveResource("utils" + File.separator + "totem_items.yml", false);
plugin.saveResource("utils" + File.separator + "splash_items.yml", false);
plugin.saveResource("utils" + File.separator + "fisherman_talismans.yml", false);
}
File[] files = util_file.listFiles();
if (files == null) return;
@@ -85,10 +91,14 @@ public class EffectManager extends Function {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
Set<String> keys = config.getKeys(false);
for (String key : keys) {
ConfigurationSection itemSection = config.getConfigurationSection(key);
if (itemSection == null) continue;
Item item = new Item(itemSection, key);
utilItems.put(key, ItemStackUtil.addIdentifier(ItemStackUtil.getFromItem(item), "util", key));
ConfigurationSection utilSection = config.getConfigurationSection(key);
if (utilSection == null) continue;
Item item = new Item(utilSection, key);
item.setCfTag(new String[] {"util", key});
utilItems.put(key, item);
if (utilSection.contains("effect")) {
utilEffects.put(key, getEffect(utilSection.getConfigurationSection("effect")));
}
}
}
AdventureUtil.consoleMessage("[CustomFishing] Loaded <green>" + utilItems.size() + " <gray>util(s)");
@@ -134,7 +144,8 @@ public class EffectManager extends Function {
ConfigurationSection baitSection = config.getConfigurationSection(key);
if (baitSection == null) continue;
Item item = new Item(baitSection, key);
baitItems.put(key, ItemStackUtil.addIdentifier(ItemStackUtil.getFromItem(item), "bait", key));
item.setCfTag(new String[] {"bait", key});
baitItems.put(key, item);
if (baitSection.contains("effect")) {
baitEffects.put(key, getEffect(baitSection.getConfigurationSection("effect")));
}
@@ -160,7 +171,8 @@ public class EffectManager extends Function {
if (rodSection == null) continue;
rodSection.set("material", "fishing_rod");
Item item = new Item(rodSection, key);
rodItems.put(key, ItemStackUtil.addIdentifier(ItemStackUtil.getFromItem(item), "rod", key));
item.setCfTag(new String[] {"rod", key});
rodItems.put(key, item);
if (rodSection.contains("effect")) {
rodEffects.put(key, getEffect(rodSection.getConfigurationSection("effect")));
}
@@ -196,11 +208,12 @@ public class EffectManager extends Function {
}
@Nullable
public ItemStack getBaitItem(String key) {
public Item getBaitItem(String key) {
return baitItems.get(key);
}
public HashMap<String, ItemStack> getBaitItems() {
@NotNull
public HashMap<String, Item> getBaitItems() {
return baitItems;
}
@@ -209,16 +222,18 @@ public class EffectManager extends Function {
return baitEffects.get(key);
}
@NotNull
public HashMap<String, Effect> getBaitEffects() {
return baitEffects;
}
@Nullable
public ItemStack getRodItem(String key) {
public Item getRodItem(String key) {
return rodItems.get(key);
}
public HashMap<String, ItemStack> getRodItems() {
@NotNull
public HashMap<String, Item> getRodItems() {
return rodItems;
}
@@ -227,6 +242,7 @@ public class EffectManager extends Function {
return rodEffects.get(key);
}
@NotNull
public HashMap<String, Effect> getRodEffects() {
return rodEffects;
}
@@ -236,16 +252,28 @@ public class EffectManager extends Function {
return enchantEffects.get(key);
}
@NotNull
public HashMap<String, Effect> getEnchantEffects() {
return enchantEffects;
}
@Nullable
public ItemStack getUtilItem(String key) {
public Item getUtilItem(String key) {
return utilItems.get(key);
}
public HashMap<String, ItemStack> getUtilItems() {
@NotNull
public HashMap<String, Item> getUtilItems() {
return utilItems;
}
@NotNull
public HashMap<String, Effect> getUtilEffects() {
return utilEffects;
}
@Nullable
public Effect getUtilEffect(String key) {
return utilEffects.get(key);
}
}

View File

@@ -162,142 +162,160 @@ public class FishingManager extends Function {
hooks.put(player, fishHook);
if (isCoolDown(player, 500)) return;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
PlayerInventory inventory = player.getInventory();
PlayerInventory inventory = player.getInventory();
boolean noSpecialRod = true;
boolean noRod = true;
boolean noBait = true;
int lureLevel = 0;
ItemStack baitItem = null;
boolean noSpecialRod = true;
boolean noRod = true;
boolean noBait = true;
int lureLevel = 0;
ItemStack baitItem = null;
Effect initialEffect = new Effect();
initialEffect.setDifficulty(0);
initialEffect.setDoubleLootChance(0);
initialEffect.setTimeModifier(1);
initialEffect.setScoreMultiplier(1);
initialEffect.setSizeMultiplier(1);
initialEffect.setWeightMD(new HashMap<>());
initialEffect.setWeightAS(new HashMap<>());
Effect initialEffect = new Effect();
initialEffect.setDifficulty(0);
initialEffect.setDoubleLootChance(0);
initialEffect.setTimeModifier(1);
initialEffect.setScoreMultiplier(1);
initialEffect.setSizeMultiplier(1);
initialEffect.setWeightMD(new HashMap<>());
initialEffect.setWeightAS(new HashMap<>());
ItemStack mainHandItem = inventory.getItemInMainHand();
Material mainHandItemType = mainHandItem.getType();
if (mainHandItemType != Material.AIR) {
if (mainHandItemType == Material.FISHING_ROD) {
noRod = false;
addEnchantEffect(initialEffect, mainHandItem);
lureLevel = mainHandItem.getEnchantmentLevel(Enchantment.LURE);
}
NBTItem mainHandNBTItem = new NBTItem(mainHandItem);
NBTCompound nbtCompound = mainHandNBTItem.getCompound("CustomFishing");
if (nbtCompound != null) {
if (nbtCompound.getString("type").equals("rod")) {
Effect rodEffect = plugin.getEffectManager().getRodEffect(nbtCompound.getString("id"));
if (rodEffect != null){
initialEffect.addEffect(rodEffect);
noSpecialRod = false;
}
ItemStack mainHandItem = inventory.getItemInMainHand();
Material mainHandItemType = mainHandItem.getType();
if (mainHandItemType != Material.AIR) {
if (mainHandItemType == Material.FISHING_ROD) {
noRod = false;
addEnchantEffect(initialEffect, mainHandItem);
lureLevel = mainHandItem.getEnchantmentLevel(Enchantment.LURE);
}
NBTItem mainHandNBTItem = new NBTItem(mainHandItem);
NBTCompound nbtCompound = mainHandNBTItem.getCompound("CustomFishing");
if (nbtCompound != null) {
String type = nbtCompound.getString("type");
String id = nbtCompound.getString("id");
if (type.equals("rod")) {
Effect rodEffect = plugin.getEffectManager().getRodEffect(id);
if (rodEffect != null){
initialEffect.addEffect(rodEffect);
noSpecialRod = false;
}
else if (nbtCompound.getString("type").equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(nbtCompound.getString("id"));
if (baitEffect != null) {
initialEffect.addEffect(baitEffect);
baitItem = mainHandItem.clone();
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
}
else if (type.equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(id);
if (baitEffect != null) {
initialEffect.addEffect(baitEffect);
baitItem = mainHandItem.clone();
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
noBait = false;
}
}
}
}
ItemStack offHandItem = inventory.getItemInOffHand();
Material offHandItemType = offHandItem.getType();
if (offHandItemType != Material.AIR){
if (noRod && offHandItemType == Material.FISHING_ROD) {
addEnchantEffect(initialEffect, offHandItem);
lureLevel = offHandItem.getEnchantmentLevel(Enchantment.LURE);
}
NBTItem offHandNBTItem = new NBTItem(offHandItem);
NBTCompound nbtCompound = offHandNBTItem.getCompound("CustomFishing");
if (nbtCompound != null) {
String type = nbtCompound.getString("type");
String id = nbtCompound.getString("id");
if (noBait && type.equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(id);
if (baitEffect != null){
initialEffect.addEffect(baitEffect);
baitItem = offHandItem.clone();
offHandItem.setAmount(offHandItem.getAmount() - 1);
noBait = false;
}
}
else if (noSpecialRod && type.equals("rod")) {
Effect rodEffect = plugin.getEffectManager().getRodEffect(id);
if (rodEffect != null) {
initialEffect.addEffect(rodEffect);
noSpecialRod = false;
}
}
}
}
for (ActivatedTotem activatedTotem : activeTotemMap.values()) {
if (activatedTotem.getNearbyPlayerSet().contains(player)) {
initialEffect.addEffect(activatedTotem.getTotem().getBonus());
break;
}
}
if (ConfigManager.enableFishingBag) {
Inventory fishingBag = plugin.getBagDataManager().getPlayerBagData(player.getUniqueId());
HashSet<String> uniqueUtils = new HashSet<>(4);
if (fishingBag != null) {
for (int i = 0; i < fishingBag.getSize(); i++) {
ItemStack itemStack = fishingBag.getItem(i);
if (itemStack == null || itemStack.getType() == Material.AIR) continue;
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound cfCompound = nbtItem.getCompound("CustomFishing");
if (cfCompound == null) continue;
String type = cfCompound.getString("type");
String id = cfCompound.getString("id");
if (noBait && type.equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(id);
if (baitEffect != null && itemStack.getAmount() > 0) {
noBait = false;
}
}
}
}
ItemStack offHandItem = inventory.getItemInOffHand();
Material offHandItemType = offHandItem.getType();
if (offHandItemType != Material.AIR){
if (noRod && offHandItemType == Material.FISHING_ROD) {
addEnchantEffect(initialEffect, offHandItem);
lureLevel = offHandItem.getEnchantmentLevel(Enchantment.LURE);
}
NBTItem offHandNBTItem = new NBTItem(offHandItem);
NBTCompound nbtCompound = offHandNBTItem.getCompound("CustomFishing");
if (nbtCompound != null) {
if (noBait && nbtCompound.getString("type").equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(nbtCompound.getString("id"));
if (baitEffect != null){
initialEffect.addEffect(baitEffect);
offHandItem.setAmount(offHandItem.getAmount() - 1);
baitItem = offHandItem.clone();
noBait = false;
}
}
else if (noSpecialRod && nbtCompound.getString("type").equals("rod")) {
Effect rodEffect = plugin.getEffectManager().getRodEffect(nbtCompound.getString("id"));
if (rodEffect != null) {
initialEffect.addEffect(rodEffect);
noSpecialRod = false;
}
}
}
}
for (ActivatedTotem activatedTotem : activeTotemMap.values()) {
if (activatedTotem.getNearbyPlayerSet().contains(player)) {
initialEffect.addEffect(activatedTotem.getTotem().getBonus());
break;
}
}
if (ConfigManager.enableFishingBag && noBait) {
Inventory baitInv = plugin.getBagDataManager().getPlayerBagData(player.getUniqueId());
if (baitInv != null) {
for (int i = 0; i < baitInv.getSize(); i++) {
ItemStack itemStack = baitInv.getItem(i);
if (itemStack == null || itemStack.getType() == Material.AIR) continue;
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound cfCompound = nbtItem.getCompound("CustomFishing");
if (cfCompound == null) continue;
if (!cfCompound.getString("type").equals("bait")) continue;
Effect baitEffect = plugin.getEffectManager().getBaitEffect(cfCompound.getString("id"));
if (baitEffect != null) {
initialEffect.addEffect(baitEffect);
baitItem = itemStack.clone();
itemStack.setAmount(itemStack.getAmount() - 1);
break;
}
}
else if (type.equals("util")) {
Effect utilEffect = plugin.getEffectManager().getUtilEffect(id);
if (utilEffect != null && !uniqueUtils.contains(id)) {
initialEffect.addEffect(utilEffect);
uniqueUtils.add(id);
}
}
}
}
}
RodCastEvent rodCastEvent = new RodCastEvent(player, initialEffect);
if (rodCastEvent.isCancelled()) {
event.setCancelled(true);
return;
}
RodCastEvent rodCastEvent = new RodCastEvent(player, initialEffect);
Bukkit.getPluginManager().callEvent(rodCastEvent);
if (rodCastEvent.isCancelled()) {
event.setCancelled(true);
return;
}
fishHook.setMaxWaitTime((int) (fishHook.getMaxWaitTime() * initialEffect.getTimeModifier()));
fishHook.setMinWaitTime((int) (fishHook.getMinWaitTime() * initialEffect.getTimeModifier()));
fishHook.setMaxWaitTime((int) (fishHook.getMaxWaitTime() * initialEffect.getTimeModifier()));
fishHook.setMinWaitTime((int) (fishHook.getMinWaitTime() * initialEffect.getTimeModifier()));
nextEffect.put(player, initialEffect);
nextEffect.put(player, initialEffect);
if (ConfigManager.needRodToFish && noSpecialRod) {
nextLoot.put(player, Loot.EMPTY);
return;
}
if (ConfigManager.needRodToFish && noSpecialRod) {
nextLoot.put(player, Loot.EMPTY);
return;
}
initialEffect.setHasSpecialRod(!noSpecialRod);
initialEffect.setHasSpecialRod(!noSpecialRod);
int entityID = 0;
if (baitItem != null) {
baitItem.setAmount(1);
entityID = new Random().nextInt(Integer.MAX_VALUE);
CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getSpawnPacket(entityID, fishHook.getLocation()));
CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getMetaPacket(entityID, baitItem));
}
int entityID = 0;
if (baitItem != null) {
baitItem.setAmount(1);
entityID = new Random().nextInt(Integer.MAX_VALUE);
CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getSpawnPacket(entityID, fishHook.getLocation()));
CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getMetaPacket(entityID, baitItem));
}
BobberCheckTask bobberCheckTask = new BobberCheckTask(plugin, player, initialEffect, fishHook, this, lureLevel, entityID);
bobberCheckTask.runTaskTimer(plugin, 1, 1);
hookCheckTaskMap.put(player, bobberCheckTask);
});
BobberCheckTask bobberCheckTask = new BobberCheckTask(plugin, player, initialEffect, fishHook, this, lureLevel, entityID);
bobberCheckTask.runTaskTimer(plugin, 1, 1);
hookCheckTaskMap.put(player, bobberCheckTask);
}
public void onBite(PlayerFishEvent event) {
if (ConfigManager.disableBar || !ConfigManager.instantBar) return;
showBar(event.getPlayer());
}
public void getNextLoot(Player player, Effect initialEffect, List<Loot> possibleLoots) {
@@ -364,8 +382,9 @@ public class FishingManager extends Function {
}
FishingGame fishingGame = fishingPlayerMap.remove(player);
// if the player is noy playing the game
if (fishingGame == null) {
// get his next loot
Loot loot = nextLoot.get(player);
if (loot == Loot.EMPTY) return;
@@ -378,19 +397,20 @@ public class FishingManager extends Function {
noBarWaterReelIn(event);
return;
}
showFishingBar(player, loot);
}
else {
vanillaLoot.put(player, new VanillaLoot(item.getItemStack(), event.getExpToDrop()));
showFishingBar(player, plugin.getLootManager().getVanilla_loot());
}
event.setCancelled(true);
showFishingBar(player, loot);
}
// Is vanilla loot
else {
if (ConfigManager.otherLootHasFishingBar) {
if (!plugin.getLootManager().getVanilla_loot().isDisableBar()) {
event.setCancelled(true);
vanillaLoot.put(player, new VanillaLoot(item.getItemStack(), event.getExpToDrop()));
showFishingBar(player, null);
showFishingBar(player, plugin.getLootManager().getVanilla_loot());
}
//else vanilla fishing mechanic
}
@@ -419,6 +439,51 @@ public class FishingManager extends Function {
}
}
public void onReelIn(PlayerFishEvent event) {
final Player player = event.getPlayer();
if (ConfigManager.disableBar) {
noBarLavaReelIn(event);
return;
}
//in fishing game
FishingGame fishingGame = fishingPlayerMap.remove(player);
if (fishingGame != null) {
proceedReelIn(event.getHook().getLocation(), player, fishingGame);
hookCheckTaskMap.remove(player);
return;
}
//not in fishing game
BobberCheckTask bobberCheckTask = hookCheckTaskMap.get(player);
if (bobberCheckTask != null && bobberCheckTask.isHooked()) {
Loot loot = nextLoot.get(player);
if (loot == Loot.EMPTY) return;
if (loot.isDisableBar()) {
noBarLavaReelIn(event);
return;
}
showFishingBar(player, loot);
event.setCancelled(true);
}
}
public void onCaughtEntity(PlayerFishEvent event) {
final Player player = event.getPlayer();
FishingGame fishingGame = fishingPlayerMap.remove(player);
if (fishingGame != null) {
Entity entity = event.getCaught();
if (entity != null && entity.getType() == EntityType.ARMOR_STAND) {
proceedReelIn(event.getHook().getLocation(), player, fishingGame);
}
else {
fishingGame.cancel();
nextEffect.remove(player);
nextLoot.remove(player);
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.hookOther);
}
}
}
private void noBarWaterReelIn(PlayerFishEvent event) {
Entity entity = event.getCaught();
if (!(entity instanceof Item item)) {
@@ -495,34 +560,6 @@ public class FishingManager extends Function {
}
}
public void onReelIn(PlayerFishEvent event) {
final Player player = event.getPlayer();
if (ConfigManager.disableBar) {
noBarLavaReelIn(event);
return;
}
//in fishing
FishingGame fishingGame = fishingPlayerMap.remove(player);
if (fishingGame != null) {
proceedReelIn(event.getHook().getLocation(), player, fishingGame);
hookCheckTaskMap.remove(player);
return;
}
//not in fishing
BobberCheckTask bobberCheckTask = hookCheckTaskMap.get(player);
if (bobberCheckTask != null && bobberCheckTask.isHooked()) {
Loot loot = nextLoot.get(player);
if (loot == Loot.EMPTY) return;
if (loot.isDisableBar()) {
noBarLavaReelIn(event);
return;
}
showFishingBar(player, loot);
event.setCancelled(true);
}
}
private void dropCustomFishingLoot(Player player, Location location, DroppedItem droppedItem, boolean isDouble, double scoreMultiplier, double sizeMultiplier) {
ItemStack drop = getCustomFishingLootItemStack(droppedItem, player, sizeMultiplier);
FishResultEvent fishResultEvent = new FishResultEvent(player, FishResult.CATCH_SPECIAL_ITEM, isDouble, drop, droppedItem.getKey());
@@ -558,16 +595,6 @@ public class FishingManager extends Function {
ItemStackUtil.addRandomDamage(drop);
if (ConfigManager.preventPickUp)
ItemStackUtil.addOwner(drop, player.getName());
if (ConfigManager.addTagToFish)
ItemStackUtil.addIdentifier(drop, "loot", droppedItem.getKey());
if (drop.getType() == Material.PLAYER_HEAD) {
NBTItem nbtItem = new NBTItem(drop);
NBTCompound nbtCompound = nbtItem.getCompound("SkullOwner");
if (nbtCompound != null && !nbtCompound.hasTag("Id")) {
nbtCompound.setUUID("Id", UUID.randomUUID());
drop.setItemMeta(nbtItem.getItem().getItemMeta());
}
}
ItemStackUtil.addExtraMeta(drop, droppedItem, sizeMultiplier);
}
return drop;
@@ -577,21 +604,53 @@ public class FishingManager extends Function {
ItemStack itemStack = McMMOTreasure.getTreasure(player);
if (itemStack == null) return false;
FishResultEvent fishResultEvent = new FishResultEvent(player, FishResult.CATCH_VANILLA_ITEM, isDouble, itemStack, "mcmmo");
FishResultEvent fishResultEvent = new FishResultEvent(player, FishResult.CATCH_VANILLA_ITEM, isDouble, itemStack, "vanilla");
Bukkit.getPluginManager().callEvent(fishResultEvent);
if (fishResultEvent.isCancelled()) {
return true;
}
doVanillaActions(player, location, itemStack, fishResultEvent.isDouble());
player.giveExp(new Random().nextInt(24), true);
return true;
}
private void dropVanillaLoot(Player player, VanillaLoot vanillaLoot, Location location, boolean isDouble) {
ItemStack itemStack = vanillaLoot.getItemStack();
if (ConfigManager.enableMcMMOLoot && Math.random() < ConfigManager.mcMMOLootChance){
ItemStack mcMMOItemStack = McMMOTreasure.getTreasure(player);
if (mcMMOItemStack != null){
itemStack = mcMMOItemStack;
}
}
FishResultEvent fishResultEvent = new FishResultEvent(player, FishResult.CATCH_VANILLA_ITEM, isDouble, itemStack, "vanilla");
Bukkit.getPluginManager().callEvent(fishResultEvent);
if (fishResultEvent.isCancelled()) {
return;
}
doVanillaActions(player, location, itemStack, fishResultEvent.isDouble());
player.giveExp(vanillaLoot.getXp(), true);
}
private void doVanillaActions(Player player, Location location, ItemStack itemStack, boolean isDouble) {
if (Competition.currentCompetition != null) {
Competition.currentCompetition.refreshData(player, 0, fishResultEvent.isDouble());
Competition.currentCompetition.refreshData(player, (float) plugin.getLootManager().getVanilla_loot().getScore(), isDouble);
Competition.currentCompetition.tryAddBossBarToPlayer(player);
}
player.giveExp(new Random().nextInt(24), true);
dropItem(player, location, fishResultEvent.isDouble(), itemStack);
Loot vanilla = plugin.getLootManager().getVanilla_loot();
addStats(player.getUniqueId(), vanilla, isDouble ? 2 : 1);
if (vanilla.getSuccessActions() != null) {
for (Action action : vanilla.getSuccessActions())
action.doOn(player, null);
}
AdventureUtil.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1);
dropItem(player, location, isDouble, itemStack);
sendSuccessTitle(player, itemStack);
return true;
}
private void dropItem(Player player, Location location, boolean isDouble, ItemStack itemStack) {
@@ -612,34 +671,6 @@ public class FishingManager extends Function {
plugin.getStatisticsManager().addFishAmount(uuid, loot, amount);
}
private void dropVanillaLoot(Player player, VanillaLoot vanillaLoot, Location location, boolean isDouble) {
ItemStack itemStack;
itemStack = vanillaLoot.getItemStack();
if (ConfigManager.enableMcMMOLoot && Math.random() < ConfigManager.mcMMOLootChance){
ItemStack mcMMOItemStack = McMMOTreasure.getTreasure(player);
if (mcMMOItemStack != null){
itemStack = mcMMOItemStack;
}
}
FishResultEvent fishResultEvent = new FishResultEvent(player, FishResult.CATCH_VANILLA_ITEM, isDouble, itemStack, "vanilla");
Bukkit.getPluginManager().callEvent(fishResultEvent);
if (fishResultEvent.isCancelled()) {
return;
}
if (Competition.currentCompetition != null){
Competition.currentCompetition.refreshData(player, 0, fishResultEvent.isDouble());
Competition.currentCompetition.tryAddBossBarToPlayer(player);
}
player.giveExp(vanillaLoot.getXp(), true);
AdventureUtil.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1);
dropItem(player, location, isDouble, itemStack);
sendSuccessTitle(player, itemStack);
}
private void summonMob(Player player, Loot loot, Location location, Mob mob, double scoreMultiplier) {
MobInterface mobInterface = plugin.getIntegrationManager().getMobInterface();
if (mobInterface == null) return;
@@ -681,20 +712,18 @@ public class FishingManager extends Function {
private void sendSuccessTitle(Player player, String loot) {
if (!ConfigManager.enableSuccessTitle) return;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
AdventureUtil.playerTitle(
player,
ConfigManager.successTitle[new Random().nextInt(ConfigManager.successTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successSubTitle[new Random().nextInt(ConfigManager.successSubTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successFadeIn,
ConfigManager.successFadeStay,
ConfigManager.successFadeOut
);
}, 8);
Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtil.playerTitle(
player,
ConfigManager.successTitle[new Random().nextInt(ConfigManager.successTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successSubTitle[new Random().nextInt(ConfigManager.successSubTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successFadeIn,
ConfigManager.successFadeStay,
ConfigManager.successFadeOut
), 8);
}
private void sendSuccessTitle(Player player, ItemStack itemStack) {
@@ -703,16 +732,14 @@ public class FishingManager extends Function {
Component titleComponent = getTitleComponent(itemStack, title);
String subTitle = ConfigManager.successSubTitle[new Random().nextInt(ConfigManager.successSubTitle.length)];
Component subtitleComponent = getTitleComponent(itemStack, subTitle);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
AdventureUtil.playerTitle(
player,
titleComponent,
subtitleComponent,
ConfigManager.successFadeIn,
ConfigManager.successFadeStay,
ConfigManager.successFadeOut
);
}, 8);
Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtil.playerTitle(
player,
titleComponent,
subtitleComponent,
ConfigManager.successFadeIn,
ConfigManager.successFadeStay,
ConfigManager.successFadeOut
), 8);
}
private void loseDurability(Player player) {
@@ -750,46 +777,20 @@ public class FishingManager extends Function {
}
if (!ConfigManager.enableFailureTitle) return;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
AdventureUtil.playerTitle(
player,
ConfigManager.failureTitle[new Random().nextInt(ConfigManager.failureTitle.length)],
ConfigManager.failureSubTitle[new Random().nextInt(ConfigManager.failureSubTitle.length)],
ConfigManager.failureFadeIn,
ConfigManager.failureFadeStay,
ConfigManager.failureFadeOut
);
}, 8);
}
public void onCaughtEntity(PlayerFishEvent event) {
final Player player = event.getPlayer();
FishingGame fishingGame = fishingPlayerMap.remove(player);
if (fishingGame != null) {
Entity entity = event.getCaught();
if (entity != null && entity.getType() == EntityType.ARMOR_STAND) {
proceedReelIn(event.getHook().getLocation(), player, fishingGame);
}
else {
fishingGame.cancel();
nextEffect.remove(player);
nextLoot.remove(player);
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.hookOther);
}
}
Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtil.playerTitle(
player,
ConfigManager.failureTitle[new Random().nextInt(ConfigManager.failureTitle.length)],
ConfigManager.failureSubTitle[new Random().nextInt(ConfigManager.failureSubTitle.length)],
ConfigManager.failureFadeIn,
ConfigManager.failureFadeStay,
ConfigManager.failureFadeOut
), 8);
}
public void onFailedAttempt(PlayerFishEvent event) {
//Empty
}
public void onBite(PlayerFishEvent event) {
if (ConfigManager.disableBar) return;
if (!ConfigManager.instantBar) return;
final Player player = event.getPlayer();
showBar(player);
}
public void showBar(Player player) {
if (fishingPlayerMap.get(player) != null) return;
Loot loot = nextLoot.get(player);
@@ -933,32 +934,33 @@ public class FishingManager extends Function {
AdventureUtil.playerMessage(player, stringBuilder.substring(0, stringBuilder.length() - MessageManager.splitChar.length()));
}
private void showFishingBar(Player player, @Nullable Loot loot){
MiniGameConfig game = (loot != null && loot.getFishingGames() != null)
private void showFishingBar(Player player, @NotNull Loot loot) {
MiniGameConfig game = loot.getFishingGames() != null
? loot.getFishingGames()[new Random().nextInt(loot.getFishingGames().length)]
: plugin.getBarMechanicManager().getRandomGame();
int difficult = game.getRandomDifficulty() + nextEffect.getOrDefault(player, new Effect()).getDifficulty();
FishHookEvent fishHookEvent = new FishHookEvent(player, Math.min(10, Math.max(1, difficult)));
Bukkit.getPluginManager().callEvent(fishHookEvent);
MiniGameStartEvent miniGameStartEvent = new MiniGameStartEvent(player, Math.min(10, Math.max(1, difficult)));
Bukkit.getPluginManager().callEvent(miniGameStartEvent);
if (miniGameStartEvent.isCancelled()) {
return;
}
FishingBar fishingBar = game.getRandomBar();
FishingGame fishingGame = null;
if (fishingBar instanceof ModeOneBar modeOneBar) {
fishingGame = new ModeOneGame(plugin, this, System.currentTimeMillis() + game.getTime() * 1000L, player, fishHookEvent.getDifficulty(), modeOneBar);
fishingGame = new ModeOneGame(plugin, this, System.currentTimeMillis() + game.getTime() * 1000L, player, miniGameStartEvent.getDifficulty(), modeOneBar);
}
else if (fishingBar instanceof ModeTwoBar modeTwoBar) {
fishingGame = new ModeTwoGame(plugin, this, System.currentTimeMillis() + game.getTime() * 1000L, player, fishHookEvent.getDifficulty(), modeTwoBar);
fishingGame = new ModeTwoGame(plugin, this, System.currentTimeMillis() + game.getTime() * 1000L, player, miniGameStartEvent.getDifficulty(), modeTwoBar);
}
else if (fishingBar instanceof ModeThreeBar modeThreeBar) {
fishingGame = new ModeThreeGame(plugin, this, System.currentTimeMillis() + game.getTime() * 1000L, player, fishHookEvent.getDifficulty(), modeThreeBar);
fishingGame = new ModeThreeGame(plugin, this, System.currentTimeMillis() + game.getTime() * 1000L, player, miniGameStartEvent.getDifficulty(), modeThreeBar);
}
if (fishingGame != null) {
fishingGame.runTaskTimer(plugin, 0, 1);
fishingPlayerMap.put(player, fishingGame);
}
if (vanillaLoot.get(player) == null && loot != null){
for (Action action : loot.getHookActions()) {
action.doOn(player, null);
}
for (Action action : loot.getHookActions()) {
action.doOn(player, null);
}
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, game.getTime() * 20,3));
}
@@ -974,11 +976,6 @@ public class FishingManager extends Function {
removeBobber(player);
}
@Nullable
public FishingGame getFishingPlayer(Player player) {
return fishingPlayerMap.get(player);
}
public void removeFishingPlayer(Player player) {
fishingPlayerMap.remove(player);
}

View File

@@ -36,6 +36,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@@ -46,8 +47,9 @@ public class LootManager extends Function {
private final CustomFishing plugin;
private final HashMap<String, Loot> waterLoots;
private final HashMap<String, Loot> lavaLoots;
private final HashMap<String, ItemStack> lootItems;
private final HashMap<String, Item> lootItems;
private final HashMap<String, List<String>> category;
private Loot vanilla_loot;
public LootManager(CustomFishing plugin) {
this.plugin = plugin;
@@ -59,12 +61,22 @@ public class LootManager extends Function {
@Nullable
public ItemStack build(String key) {
ItemStack itemStack = this.lootItems.get(key);
return itemStack == null ? null : itemStack.clone();
Item item = lootItems.get(key);
return item == null || item.getMaterial() == Material.AIR ? new ItemStack(Material.AIR) : ItemStackUtil.getFromItem(item);
}
@Override
public void load() {
this.vanilla_loot = new Loot(
"vanilla",
"vanilla",
null,
0,
false,
0,
false,
false
);
this.loadItems();
this.loadMobs();
this.loadCategories();
@@ -78,6 +90,7 @@ public class LootManager extends Function {
this.lavaLoots.clear();
this.lootItems.clear();
this.category.clear();
this.vanilla_loot = null;
}
@Nullable
@@ -183,7 +196,6 @@ public class LootManager extends Function {
if (lootSection == null) continue;
if (!lootSection.getBoolean("enable", true)) continue;
String material = lootSection.getString("material","COD");
DroppedItem loot = new DroppedItem(
key,
lootSection.contains("nick") ? lootSection.getString("nick") : AdventureUtil.replaceLegacy(lootSection.getString("display.name", key)),
@@ -226,15 +238,17 @@ public class LootManager extends Function {
setActions(lootSection, loot);
setRequirements(lootSection.getConfigurationSection("requirements"), loot);
if (key.equals("vanilla")) {
vanilla_loot = loot;
continue;
}
if (lootSection.getBoolean("in-lava", false)) lavaLoots.put(key, loot);
else waterLoots.put(key, loot);
//not a CustomFishing loot
if (material.contains(":")) continue;
Item item = new Item(lootSection, key);
if (item.getMaterial() == Material.AIR) lootItems.put(key, new ItemStack(Material.AIR));
else lootItems.put(key, ItemStackUtil.getFromItem(item));
if (ConfigManager.addTagToFish) item.setCfTag(new String[] {"loot", key});
lootItems.put(key, item);
}
}
}
@@ -353,4 +367,9 @@ public class LootManager extends Function {
public List<String> getCategories(String categoryID) {
return category.get(categoryID);
}
@NotNull
public Loot getVanilla_loot() {
return vanilla_loot;
}
}

View File

@@ -101,7 +101,7 @@ public class StatisticsManager extends DataFunction {
public void addFishAmount(UUID uuid, Loot loot, int amount) {
PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid);
if (statisticsData != null) {
statisticsData.addFishAmount(loot, amount, uuid);
statisticsData.addFishAmount(loot, uuid, amount);
}
}
@@ -113,6 +113,14 @@ public class StatisticsManager extends DataFunction {
return -1;
}
public int getTotalFishAmount(UUID uuid) {
PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid);
if (statisticsData != null) {
return statisticsData.getTotalCatchAmount();
}
return -1;
}
public boolean hasFished(UUID uuid, String key) {
PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid);
if (statisticsData != null) {

View File

@@ -24,6 +24,7 @@ import com.google.common.collect.Lists;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.loot.Item;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
@@ -116,13 +117,13 @@ public class ArmorStandUtil {
return equipPacket;
}
public static void sendAnimationToPlayer(Location location, Player player, String item, int time) {
public static void sendAnimationToPlayer(Location location, Player player, String key, int time) {
int id = new Random().nextInt(Integer.MAX_VALUE);
ItemStack itemStack = CustomFishing.getInstance().getEffectManager().getUtilItem(item);
if (itemStack == null) return;
Item item = CustomFishing.getInstance().getEffectManager().getUtilItem(key);
if (item == null) return;
CustomFishing.getProtocolManager().sendServerPacket(player, getSpawnPacket(id, location.clone().subtract(0,1,0)));
CustomFishing.getProtocolManager().sendServerPacket(player, getMetaPacket(id));
CustomFishing.getProtocolManager().sendServerPacket(player, getEquipPacket(id, itemStack));
CustomFishing.getProtocolManager().sendServerPacket(player, getEquipPacket(id, ItemStackUtil.getFromItem(item)));
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomFishing.getInstance(), () -> {
CustomFishing.getProtocolManager().sendServerPacket(player, getDestroyPacket(id));
}, time);

View File

@@ -27,6 +27,7 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.loot.DroppedItem;
import net.momirealms.customfishing.fishing.loot.Item;
import net.momirealms.customfishing.fishing.loot.Loot;
import net.momirealms.customfishing.manager.ConfigManager;
import net.momirealms.customfishing.object.LeveledEnchantment;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -88,8 +89,14 @@ public class ItemStackUtil {
lore.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<!i>" + line)));
});
}
if (item.getCfTag() != null) {
NBTCompound cfCompound = nbtItem.addCompound("CustomFishing");
cfCompound.setString("type", item.getCfTag()[0]);
cfCompound.setString("id", item.getCfTag()[1]);
}
if (item.getHead64() != null) {
NBTCompound nbtCompound = nbtItem.addCompound("SkullOwner");
nbtCompound.setUUID("Id", item.isHeadStackable() ? UUID.nameUUIDFromBytes(item.getKey().getBytes()) : UUID.randomUUID());
NBTListCompound texture = nbtCompound.addCompound("Properties").getCompoundList("textures").addCompound();
texture.setString("Value", item.getHead64());
}
@@ -170,23 +177,26 @@ public class ItemStackUtil {
}
public static void givePlayerRod(Player player, String rodKey, int amount){
ItemStack itemStack = CustomFishing.getInstance().getEffectManager().getRodItem(rodKey);
if (itemStack == null) return;
Item item = CustomFishing.getInstance().getEffectManager().getRodItem(rodKey);
if (item == null) return;
ItemStack itemStack = getFromItem(item);
for (int i = 0; i < amount; i++) {
player.getInventory().addItem(itemStack);
}
}
public static void givePlayerBait(Player player, String baitKey, int amount){
ItemStack itemStack = CustomFishing.getInstance().getEffectManager().getBaitItem(baitKey);
if (itemStack == null) return;
Item item = CustomFishing.getInstance().getEffectManager().getBaitItem(baitKey);
if (item == null) return;
ItemStack itemStack = getFromItem(item);
itemStack.setAmount(amount);
player.getInventory().addItem(itemStack);
}
public static void givePlayerUtil(Player player, String utilKey, int amount){
ItemStack itemStack = CustomFishing.getInstance().getEffectManager().getUtilItem(utilKey);
if (itemStack == null) return;
Item item = CustomFishing.getInstance().getEffectManager().getUtilItem(utilKey);
if (item == null) return;
ItemStack itemStack = getFromItem(item);
itemStack.setAmount(amount);
player.getInventory().addItem(itemStack);
}

View File

@@ -84,6 +84,6 @@ public class JedisUtil {
}
public static boolean isPoolEnabled() {
return jedisPool != null;
return !(jedisPool == null || jedisPool.isClosed());
}
}

View File

@@ -518,6 +518,9 @@ bar_10:
judgment-area-offset: -160
judgment-area-width: 33
fish-icon-width: 8
water-resistance: 0.15
pulling-strength: 0.45
loosening-strength-loss: 0.3
hold-time-requirements:
- 3
- 4
@@ -557,6 +560,10 @@ bar_11:
fish-start-position: 170
fish-icon-width: 8
success-position: 21
ultimate-strain: 50
normal-pull-strain-increase: 1
struggling-strain-increase: 2
loosening-strain-loss: 2
strain:
- '<font:customfishing:icons>뀑</font>'
- '<font:customfishing:icons>뀒</font>'

View File

@@ -1,5 +1,5 @@
# Don't change
config-version: '18'
config-version: '19'
# bStats
metrics: true
@@ -36,9 +36,6 @@ mechanics:
# other loots
# 其他战利品
other-loots:
# Should other loots have the same fishing mechanic CustomFishing provides
# 其他战利品是否有插件提供的钓鱼特性
fishing-bar: true
# 原版战利品
vanilla:
enable: true

View File

@@ -4,7 +4,6 @@ wooden_rod:
lore:
- '<gray>Its just an ordinary fishing rod'
- '<gray>But it''s quite friendly to a starter!'
# Click here to learn how modifier system works: https://www.yuque.com/docs/share/4842ac5f-b5ea-4568-acef-d510f8bc9064?# 《Modifier System》
effect:
difficulty: -1

View File

@@ -0,0 +1,13 @@
fisherman_talismans:
material: player_head
display:
name: '<blue>Fisherman Talismans'
lore:
- ''
- '<gray>Fishing would be easier when keeping'
- '<gray>the talismans in the fishing bag'
- ''
- '<gold>The effect cannot be stacked'
head64: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWQzZmVjNGI3M2E1ZThlMWY1Y2FiOTBjZDBhMzgzMDJmMzdiMDBjNzEzY2EwNmM4NDkzMDBmOGZkMTFlNWVjMiJ9fX0=
effect:
difficulty: -1