From 71b60ac0e2ca0bf00dcc9a1a85a1ae49304a718d Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Fri, 24 Mar 2023 01:37:26 +0800 Subject: [PATCH] 1.3.0.4 --- .../customfishing/api/CustomFishingAPI.java | 212 ++++++++++++++---- .../commands/AbstractMainCommand.java | 17 ++ .../customfishing/commands/MainCommand.java | 1 + .../commands/subcmd/AboutCommand.java | 44 ++++ .../commands/subcmd/HelpCommand.java | 52 +++-- .../commands/subcmd/OpenBagCommand.java | 17 ++ .../commands/subcmd/SellShopCommand.java | 17 ++ .../commands/subcmd/StatisticsCommand.java | 17 ++ .../fishing/FishingCondition.java | 4 + .../fishing/mode/ModeOneGame.java | 4 +- .../fishing/requirements/CustomPapi.java | 1 + .../fishing/requirements/JobLevelImpl.java | 2 +- .../fishing/requirements/PermissionImpl.java | 2 +- .../fishing/requirements/Requirement.java | 2 +- .../fishing/requirements/SkillLevelImpl.java | 2 +- .../customfishing/helper/VersionHelper.java | 16 +- .../customfishing/manager/SellManager.java | 12 + .../customfishing/util/ItemStackUtil.java | 1 + 18 files changed, 352 insertions(+), 71 deletions(-) create mode 100644 src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java diff --git a/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java b/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java index 33cd56ea..c27247e6 100644 --- a/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java +++ b/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java @@ -17,21 +17,47 @@ package net.momirealms.customfishing.api; +import de.tr7zw.changeme.nbtapi.NBTCompound; +import de.tr7zw.changeme.nbtapi.NBTItem; import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.fishing.FishingCondition; import net.momirealms.customfishing.fishing.competition.Competition; 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.util.ItemStackUtil; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.UUID; public class CustomFishingAPI { /** + * get plugin instance + * @return plugin instance + */ + public static CustomFishing getPluginInstance() { + return CustomFishing.getInstance(); + } + + /** + * Is there a competition ongoing + * @return is or not + */ + public static boolean isCompetitionGoingOn() { + return Competition.getCurrentCompetition() != null; + } + + /** + * Get the current competition * return null if there's no competition * @return competition */ @@ -48,14 +74,6 @@ public class CustomFishingAPI { return CustomFishing.getInstance().getFishingManager().getSize(fish); } - /** - * get plugin instance - * @return plugin instance - */ - public static CustomFishing getPluginInstance() { - return CustomFishing.getInstance(); - } - /** * get an item's price * @param itemStack item to sell @@ -65,42 +83,6 @@ public class CustomFishingAPI { return CustomFishing.getInstance().getSellManager().getSingleItemPrice(itemStack); } - /** - * get items directly from item library - * return AIR if the loot does not exist - * @param id item_id - * @return itemStack - */ - @NotNull - public static ItemStack getLootByID(String id) { - return CustomFishing.getInstance().getIntegrationManager().build(id); - } - - /** - * get items obtained by fishing - * return AIR if the loot does not exist - * @param id item_id - * @param player player - * @return itemStack - */ - @NotNull - public static ItemStack getLootByID(String id, @Nullable Player player) { - Loot loot = CustomFishing.getInstance().getLootManager().getLoot(id); - if (!(loot instanceof DroppedItem droppedItem)) return new ItemStack(Material.AIR); - return CustomFishing.getInstance().getFishingManager().getCustomFishingLootItemStack(droppedItem, player); - } - - /** - * get the catch amount of a certain loot - * return -1 if player's data is not loaded - * @param id loot id - * @param uuid uuid - * @return amount - */ - public static int getCertainLootCatchAmount(String id, UUID uuid) { - return CustomFishing.getInstance().getStatisticsManager().getFishAmount(uuid, id); - } - /** * If an item exists in item library * @param type type @@ -116,4 +98,146 @@ public class CustomFishingAPI { default -> false; }; } + + /** + * If a world allow new fishing + * @param world world + * @return allow or not + */ + public static boolean isFishingWorld(World world) { + return ConfigManager.getWorldsList().contains(world.getName()); + } + + /** + * Get all the possible loots for a certain player at a certain location + * @param location location + * @param player player + * @return loots + */ + public static List getLootsAt(Location location, Player player) { + return CustomFishing.getInstance().getFishingManager().getPossibleLootList(new FishingCondition(location, player), false, CustomFishing.getInstance().getLootManager().getAllLoots()); + } + + /** + * Get all the possible loots at a certain location + * @param location location + * @return loots + */ + public static List getLootsAt(Location location) { + return CustomFishing.getInstance().getFishingManager().getPossibleLootList(new FishingCondition(location, null), false, CustomFishing.getInstance().getLootManager().getAllLoots()); + } + + /** + * Get a loot from Loot Manager + * @param id id + * @return loot + */ + public static Loot getLootByID(String id) { + return CustomFishing.getInstance().getLootManager().getLoot(id); + } + + /** + * get items directly from item library + * return AIR if the loot does not exist + * @param id item_id + * @return itemStack + */ + @NotNull + public static ItemStack getLootItemByID(String id) { + return CustomFishing.getInstance().getIntegrationManager().build(id); + } + + /** + * get items obtained by fishing + * return AIR if the loot does not exist + * @param id item_id + * @param player player + * @return itemStack + */ + @NotNull + public static ItemStack getLootItemByID(String id, @Nullable Player player) { + Loot loot = CustomFishing.getInstance().getLootManager().getLoot(id); + if (!(loot instanceof DroppedItem droppedItem)) return new ItemStack(Material.AIR); + return CustomFishing.getInstance().getFishingManager().getCustomFishingLootItemStack(droppedItem, player); + } + + /** + * get rods directly from item library + * return null if the rod does not exist + * @param id rod_id + * @return itemStack + */ + public static ItemStack getRodItemByID(String id) { + Item item = CustomFishing.getInstance().getEffectManager().getRodItem(id); + return item == null ? null : ItemStackUtil.getFromItem(item); + } + + /** + * get baits directly from item library + * return null if the bait does not exist + * @param id bait_id + * @return itemStack + */ + public static ItemStack getBaitItemByID(String id) { + Item item = CustomFishing.getInstance().getEffectManager().getBaitItem(id); + return item == null ? null : ItemStackUtil.getFromItem(item); + } + + /** + * get utils directly from item library + * return null if the util does not exist + * @param id util_id + * @return itemStack + */ + public static ItemStack getUtilItemByID(String id) { + Item item = CustomFishing.getInstance().getEffectManager().getUtilItem(id); + return item == null ? null : ItemStackUtil.getFromItem(item); + } + + /** + * get the catch amount of a certain loot + * return -1 if player's data is not loaded + * @param id loot id + * @param uuid uuid + * @return amount + */ + public static int getCertainLootCatchAmount(String id, UUID uuid) { + return CustomFishing.getInstance().getStatisticsManager().getFishAmount(uuid, id); + } + + /** + * If the item is CustomFishing item + * @param itemStack itemStack + * @return is or not + */ + public static boolean isCustomFishingItem(ItemStack itemStack) { + if (itemStack == null || itemStack.getType() == Material.AIR) return false; + NBTItem nbtItem = new NBTItem(itemStack); + NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing"); + return nbtCompound != null; + } + + /** + * Add CustomFishing tag to an item + * @param itemStack itemStack + * @param type type + * @param id id + */ + public static void addCustomFishingTagToItem(ItemStack itemStack, String type, String id) { + if (itemStack == null || itemStack.getType() == Material.AIR) return; + NBTItem nbtItem = new NBTItem(itemStack); + NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing"); + nbtCompound.setString("type", type); + nbtCompound.setString("id", id); + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + } + + /** + * Get a player's earnings + * @param player player + * @return earnings + */ + public static double getTodayEarning(Player player) { + return CustomFishing.getInstance().getSellManager().getTodayEarning(player); + } } diff --git a/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java b/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java index 0ba3472f..9d309152 100644 --- a/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customfishing.commands; import net.momirealms.customfishing.manager.MessageManager; diff --git a/src/main/java/net/momirealms/customfishing/commands/MainCommand.java b/src/main/java/net/momirealms/customfishing/commands/MainCommand.java index 2c8e22d3..93d9ad50 100644 --- a/src/main/java/net/momirealms/customfishing/commands/MainCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/MainCommand.java @@ -31,5 +31,6 @@ public class MainCommand extends AbstractMainCommand { regSubCommand(OpenBagCommand.INSTANCE); regSubCommand(StatisticsCommand.INSTANCE); regSubCommand(HelpCommand.INSTANCE); + regSubCommand(AboutCommand.INSTANCE); } } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java new file mode 100644 index 00000000..891a3b14 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customfishing.commands.subcmd; + +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.commands.AbstractSubCommand; +import net.momirealms.customfishing.util.AdventureUtil; +import org.bukkit.command.CommandSender; + +import java.util.List; + +public class AboutCommand extends AbstractSubCommand { + + public static final AboutCommand INSTANCE = new AboutCommand(); + + public AboutCommand() { + super("about"); + } + + @Override + public boolean onCommand(CommandSender sender, List args) { + AdventureUtil.sendMessage(sender, "<#00BFFF>\uD83C\uDFA3 CustomFishing - <#87CEEB>" + CustomFishing.getInstance().getVersionHelper().getPluginVersion()); + AdventureUtil.sendMessage(sender, "<#B0C4DE>A fishing plugin that provides innovative mechanics and powerful loot system"); + AdventureUtil.sendMessage(sender, "<#DA70D6>\uD83E\uDDEA Author: <#FFC0CB>XiaoMoMi"); + AdventureUtil.sendMessage(sender, "<#FF7F50>\uD83D\uDD25 Contributors: <#FFA07A>0ft3n, <#FFA07A>Peng_Lx, <#FFA07A>Masaki"); + AdventureUtil.sendMessage(sender, "<#FFD700>⭐ Document <#A9A9A9>| <#FAFAD2>⛏ Github <#A9A9A9>| <#48D1CC>\uD83D\uDD14 Polymart"); + return true; + } +} diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java index 281aa49e..91a15602 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customfishing.commands.subcmd; import net.momirealms.customfishing.commands.AbstractSubCommand; @@ -16,33 +33,38 @@ public class HelpCommand extends AbstractSubCommand { @Override public boolean onCommand(CommandSender sender, List args) { + AdventureUtil.sendMessage(sender, "<#4169E1>Command usage:"); + AdventureUtil.sendMessage(sender, " ├─<#FFFACD> "); + AdventureUtil.sendMessage(sender, " └─<#FFFACD><#E1FFFF>[Optional Augument]"); AdventureUtil.sendMessage(sender, "<#4169E1>/customfishing"); + AdventureUtil.sendMessage(sender, " ├─help"); + AdventureUtil.sendMessage(sender, " ├─about"); AdventureUtil.sendMessage(sender, " ├─reload <#87CEFA>Reload the plugin"); - AdventureUtil.sendMessage(sender, " ├─forceopenbag <#87CEFA>Force a player to open his fishing bag"); - AdventureUtil.sendMessage(sender, " ├─sellshop <#87CEFA>Force a player to open sell shop"); + AdventureUtil.sendMessage(sender, " ├─forceopenbag <#FFFACD> <#87CEFA>Force a player to open his fishing bag"); + AdventureUtil.sendMessage(sender, " ├─sellshop <#FFFACD> <#87CEFA>Force a player to open sell shop"); AdventureUtil.sendMessage(sender, " ├─competition"); - AdventureUtil.sendMessage(sender, " │ ├─start <#87CEFA>Start a competition"); + AdventureUtil.sendMessage(sender, " │ ├─start <#FFFACD> <#87CEFA>Start a competition"); AdventureUtil.sendMessage(sender, " │ ├─end <#87CEFA>End the ongoing competition"); AdventureUtil.sendMessage(sender, " │ └─cancel <#87CEFA>Cancel the ongoing competition"); AdventureUtil.sendMessage(sender, " ├─items"); AdventureUtil.sendMessage(sender, " │ ├─loot"); - AdventureUtil.sendMessage(sender, " │ │ ├─get [amount]"); - AdventureUtil.sendMessage(sender, " │ │ ├─give [amount]"); - AdventureUtil.sendMessage(sender, " │ │ └─import <#87CEFA>Import the item in hand"); + AdventureUtil.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtil.sendMessage(sender, " │ │ ├─give <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtil.sendMessage(sender, " │ │ └─import <#FFFACD> <#87CEFA>Import the item in hand"); AdventureUtil.sendMessage(sender, " │ ├─rod"); - AdventureUtil.sendMessage(sender, " │ │ ├─get [amount]"); - AdventureUtil.sendMessage(sender, " │ │ └─give [amount]"); + AdventureUtil.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtil.sendMessage(sender, " │ │ └─give <#FFFACD> <#E1FFFF>[amount]"); AdventureUtil.sendMessage(sender, " │ ├─bait"); - AdventureUtil.sendMessage(sender, " │ │ ├─get [amount]"); - AdventureUtil.sendMessage(sender, " │ │ └─give [amount]"); + AdventureUtil.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtil.sendMessage(sender, " │ │ └─give <#FFFACD> <#E1FFFF>[amount]"); AdventureUtil.sendMessage(sender, " │ └─util"); - AdventureUtil.sendMessage(sender, " │ ├─et [amount]"); - AdventureUtil.sendMessage(sender, " │ └─give [amount]"); + AdventureUtil.sendMessage(sender, " │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtil.sendMessage(sender, " │ └─give <#FFFACD> <#E1FFFF>[amount]"); AdventureUtil.sendMessage(sender, " └─statistics"); - AdventureUtil.sendMessage(sender, " ├─reset <#87CEFA>Reset a player's statistics"); - AdventureUtil.sendMessage(sender, " └─set <#87CEFA>Set certain statistics' value"); + AdventureUtil.sendMessage(sender, " ├─reset <#FFFACD> <#87CEFA>Reset a player's statistics"); + AdventureUtil.sendMessage(sender, " └─set <#FFFACD> <#87CEFA>Set certain statistics' value"); AdventureUtil.sendMessage(sender, "<#4169E1>/fishingbag"); - AdventureUtil.sendMessage(sender, " └─open [player] <#87CEFA>Open the fishing bag"); + AdventureUtil.sendMessage(sender, " └─open <#E1FFFF>[player] <#87CEFA>Open the fishing bag"); AdventureUtil.sendMessage(sender, "<#4169E1>/sellshop <#87CEFA>Open the sell shop"); return true; } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenBagCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenBagCommand.java index 936a27b7..5c2be29a 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenBagCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenBagCommand.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customfishing.commands.subcmd; import net.momirealms.customfishing.CustomFishing; diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/SellShopCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/SellShopCommand.java index 59dad37e..de3f1f2b 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/SellShopCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/SellShopCommand.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customfishing.commands.subcmd; import net.momirealms.customfishing.CustomFishing; diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java index 6ca0b94d..31f06d28 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customfishing.commands.subcmd; import net.momirealms.customfishing.CustomFishing; diff --git a/src/main/java/net/momirealms/customfishing/fishing/FishingCondition.java b/src/main/java/net/momirealms/customfishing/fishing/FishingCondition.java index 9cfa26e5..de328b2d 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/FishingCondition.java +++ b/src/main/java/net/momirealms/customfishing/fishing/FishingCondition.java @@ -34,6 +34,10 @@ public class FishingCondition{ public FishingCondition(Location location, Player player) { this.location = location; this.player = player; + if (player == null) { + papiMap = new HashMap<>(); + return; + } PlaceholderManager placeholderManager = CustomFishing.getInstance().getIntegrationManager().getPlaceholderManager(); this.papiMap = new HashMap<>(); for (String papi : CustomPapi.allPapi) { diff --git a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java index 47485b1c..aee93e4c 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java +++ b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java @@ -53,12 +53,10 @@ public class ModeOneGame extends FishingGame { @Override public void showBar() { - String bar = - "" + modeOneBar.getBarImage() + String bar = "" + modeOneBar.getBarImage() + "" + offsetManager.getOffsetChars(modeOneBar.getPointerOffset() + progress) + "" + modeOneBar.getPointerImage() + "" + offsetManager.getOffsetChars(modeOneBar.getTotalWidth() - progress - modeOneBar.getPointerWidth()) + ""; - AdventureUtil.playerTitle(player, title, bar,0,500,0); } diff --git a/src/main/java/net/momirealms/customfishing/fishing/requirements/CustomPapi.java b/src/main/java/net/momirealms/customfishing/fishing/requirements/CustomPapi.java index 4e7b1ac3..c2df732c 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/requirements/CustomPapi.java +++ b/src/main/java/net/momirealms/customfishing/fishing/requirements/CustomPapi.java @@ -72,6 +72,7 @@ public class CustomPapi extends Requirement implements RequirementInterface { @Override public boolean isConditionMet(FishingCondition fishingCondition) { + if (fishingCondition.getPlayer() == null) return true; return papiRequirement.isMet(fishingCondition.getPapiMap(), fishingCondition.getPlayer()); } diff --git a/src/main/java/net/momirealms/customfishing/fishing/requirements/JobLevelImpl.java b/src/main/java/net/momirealms/customfishing/fishing/requirements/JobLevelImpl.java index ad318b71..1e948b99 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/requirements/JobLevelImpl.java +++ b/src/main/java/net/momirealms/customfishing/fishing/requirements/JobLevelImpl.java @@ -17,7 +17,7 @@ public class JobLevelImpl extends Requirement implements RequirementInterface { @Override public boolean isConditionMet(FishingCondition fishingCondition) { JobInterface jobInterface = CustomFishing.getInstance().getIntegrationManager().getJobInterface(); - if (jobInterface == null) return true; + if (jobInterface == null || fishingCondition.getPlayer() == null) return true; if (jobInterface.getLevel(fishingCondition.getPlayer()) >= level) { return true; } diff --git a/src/main/java/net/momirealms/customfishing/fishing/requirements/PermissionImpl.java b/src/main/java/net/momirealms/customfishing/fishing/requirements/PermissionImpl.java index 59564f7a..620ed990 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/requirements/PermissionImpl.java +++ b/src/main/java/net/momirealms/customfishing/fishing/requirements/PermissionImpl.java @@ -35,7 +35,7 @@ public class PermissionImpl extends Requirement implements RequirementInterface @Override public boolean isConditionMet(FishingCondition fishingCondition) { - if (fishingCondition.getPlayer().hasPermission(permission)) { + if (fishingCondition.getPlayer() == null || fishingCondition.getPlayer().hasPermission(permission)) { return true; } notMetMessage(fishingCondition.getPlayer()); diff --git a/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java b/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java index 4e52999b..4777ef98 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java +++ b/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java @@ -30,7 +30,7 @@ public abstract class Requirement { } public void notMetMessage(Player player) { - if (msg != null) { + if (msg != null && player != null) { for (String str : msg) { AdventureUtil.playerMessage(player, str); } diff --git a/src/main/java/net/momirealms/customfishing/fishing/requirements/SkillLevelImpl.java b/src/main/java/net/momirealms/customfishing/fishing/requirements/SkillLevelImpl.java index 7022e2e6..4db23cdc 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/requirements/SkillLevelImpl.java +++ b/src/main/java/net/momirealms/customfishing/fishing/requirements/SkillLevelImpl.java @@ -17,7 +17,7 @@ public class SkillLevelImpl extends Requirement implements RequirementInterface @Override public boolean isConditionMet(FishingCondition fishingCondition) { SkillInterface skillInterface = CustomFishing.getInstance().getIntegrationManager().getSkillInterface(); - if (skillInterface == null) return true; + if (skillInterface == null || fishingCondition.getPlayer() == null) return true; if (skillInterface.getLevel(fishingCondition.getPlayer()) >= level) { return true; } diff --git a/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java b/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java index ceece630..f7ed90ad 100644 --- a/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java +++ b/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java @@ -34,21 +34,23 @@ import java.net.URLConnection; public class VersionHelper { private boolean isNewerThan1_19_R2; - private String version; + private String serverVersion; private final CustomFishing plugin; private final boolean isSpigot; + private final String pluginVersion; public VersionHelper(CustomFishing plugin) { this.plugin = plugin; isVersionNewerThan1_19_R2(); disableUseLessInfo(); isSpigot = plugin.getServer().getName().equals("CraftBukkit"); + pluginVersion = plugin.getDescription().getVersion(); } public boolean isVersionNewerThan1_19_R2() { - if (version == null) { - version = plugin.getServer().getClass().getPackage().getName().split("\\.")[3]; - String[] split = version.split("_"); + if (serverVersion == null) { + serverVersion = plugin.getServer().getClass().getPackage().getName().split("\\.")[3]; + String[] split = serverVersion.split("_"); int main_ver = Integer.parseInt(split[1]); if (main_ver >= 20) isNewerThan1_19_R2 = true; else if (main_ver == 19) isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2; @@ -66,7 +68,7 @@ public class VersionHelper { field.setAccessible(true); MinecraftVersion minecraftVersion; try { - minecraftVersion = MinecraftVersion.valueOf(version.replace("v", "MC")); + minecraftVersion = MinecraftVersion.valueOf(serverVersion.replace("v", "MC")); } catch (IllegalArgumentException ex) { minecraftVersion = MinecraftVersion.UNKNOWN; } @@ -174,4 +176,8 @@ public class VersionHelper { public boolean isSpigot() { return isSpigot; } + + public String getPluginVersion() { + return pluginVersion; + } } diff --git a/src/main/java/net/momirealms/customfishing/manager/SellManager.java b/src/main/java/net/momirealms/customfishing/manager/SellManager.java index 0281f6e2..adfd0449 100644 --- a/src/main/java/net/momirealms/customfishing/manager/SellManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/SellManager.java @@ -441,6 +441,18 @@ public class SellManager extends DataFunction { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd.replace("{player}", player.getName()).replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited")); } + public double getTodayEarning(Player player) { + PlayerSellData playerSellData = sellDataMap.get(player.getUniqueId()); + if (playerSellData == null) return 0d; + Calendar calendar = Calendar.getInstance(); + int currentDate = (calendar.get(Calendar.MONTH) + 1) * 100 + calendar.get(Calendar.DATE); + if (currentDate != playerSellData.getDate()) { + playerSellData.setDate(currentDate); + playerSellData.setMoney(0); + } + return playerSellData.getMoney(); + } + @Override public void onWindowTitlePacketSend(PacketContainer packet, Player player) { StructureModifier wrappedChatComponentStructureModifier = packet.getChatComponents(); diff --git a/src/main/java/net/momirealms/customfishing/util/ItemStackUtil.java b/src/main/java/net/momirealms/customfishing/util/ItemStackUtil.java index f32ebc87..280db3c5 100644 --- a/src/main/java/net/momirealms/customfishing/util/ItemStackUtil.java +++ b/src/main/java/net/momirealms/customfishing/util/ItemStackUtil.java @@ -205,6 +205,7 @@ public class ItemStackUtil { File file = new File(CustomFishing.getInstance().getDataFolder(), File.separator + "loots" + File.separator + "imported.yml"); YamlConfiguration data = ConfigUtil.readData(file); data.set(key + ".material", itemStack.getType().toString()); + data.set(key + ".amount", itemStack.getAmount()); NBTItem nbtItem = new NBTItem(itemStack); Map map0 = compoundToMap(nbtItem); if (map0.size() != 0) {