diff --git a/build.gradle b/build.gradle index b4b8b856..a89a98b1 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '1.3.0-beta-3' +version = '1.3.0-beta-4' repositories { mavenCentral() diff --git a/src/main/java/net/momirealms/customfishing/CustomFishing.java b/src/main/java/net/momirealms/customfishing/CustomFishing.java index 1666b27f..e070ed07 100644 --- a/src/main/java/net/momirealms/customfishing/CustomFishing.java +++ b/src/main/java/net/momirealms/customfishing/CustomFishing.java @@ -48,6 +48,7 @@ public final class CustomFishing extends JavaPlugin { private DataManager dataManager; private SellManager sellManager; private OffsetManager offsetManager; + private StatisticsManager statisticsManager; private VersionHelper versionHelper; @Override @@ -72,6 +73,7 @@ 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(); @@ -90,7 +92,8 @@ public final class CustomFishing extends JavaPlugin { this.bagDataManager.disable(); this.totemManager.unload(); this.sellManager.disable(); - this.dataManager.unload(); + this.dataManager.disable(); + this.statisticsManager.disable(); if (adventure != null) { adventure.close(); } @@ -174,6 +177,10 @@ public final class CustomFishing extends JavaPlugin { return barMechanicManager; } + public StatisticsManager getStatisticsManager() { + return statisticsManager; + } + public OffsetManager getOffsetManager() { return offsetManager; } @@ -203,6 +210,8 @@ public final class CustomFishing extends JavaPlugin { getCompetitionManager().load(); getBagDataManager().unload(); getBagDataManager().load(); + getStatisticsManager().unload(); + getStatisticsManager().load(); } public static BukkitAudiences getAdventure() { diff --git a/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java b/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java index 4e188a4a..7d51d710 100644 --- a/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; public abstract class AbstractSubCommand implements SubCommand { @@ -89,7 +90,7 @@ public abstract class AbstractSubCommand implements SubCommand { this.subCommandMap = subCommandMap; } - protected void giveItem(CommandSender sender, String name, String item, int amount){ + protected void giveItemMsg(CommandSender sender, String name, String item, int amount){ String string = MessageManager.prefix + MessageManager.giveItem.replace("{Amount}", String.valueOf(amount)).replace("{Player}",name).replace("{Item}",item); AdventureUtil.sendMessage(sender, string); } @@ -99,4 +100,8 @@ public abstract class AbstractSubCommand implements SubCommand { Bukkit.getOnlinePlayers().forEach((player -> online.add(player.getName()))); return online; } + + protected List filterStartingWith(List list, String prefix) { + return list.stream().filter(s -> s.startsWith(prefix)).collect(Collectors.toList()); + } } diff --git a/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java b/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java index d83e04d8..cee1a680 100644 --- a/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java @@ -17,17 +17,22 @@ package net.momirealms.customfishing.commands; -import net.momirealms.customfishing.commands.subcmd.OpenCommand; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.MessageManager; import net.momirealms.customfishing.util.AdventureUtil; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; public class FishingBagCommand implements TabExecutor { @@ -35,10 +40,6 @@ public class FishingBagCommand implements TabExecutor { public FishingBagCommand() { subCommandMap = new ConcurrentHashMap<>(); - regDefaultSubCommands(); - } - - private void regDefaultSubCommands() { regSubCommand(OpenCommand.INSTANCE); } @@ -48,6 +49,7 @@ public class FishingBagCommand implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!ConfigManager.enableFishingBag) return true; List argList = Arrays.asList(args); if (argList.size() < 1) { AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.nonArgs); @@ -80,4 +82,54 @@ public class FishingBagCommand implements TabExecutor { public Map getSubCommandMap() { return subCommandMap; } + + public static class OpenCommand extends AbstractSubCommand { + + public static final SubCommand INSTANCE = new OpenCommand(); + + private OpenCommand() { + super("open", null); + } + + @Override + public boolean onCommand(CommandSender sender, List args) { + if (!(sender instanceof Player player)) { + AdventureUtil.consoleMessage(MessageManager.prefix + MessageManager.noConsole); + return true; + } + if (args.size() == 0) { + if (!sender.hasPermission("fishingbag.open")) { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); + return true; + } + player.closeInventory(); + CustomFishing.getInstance().getBagDataManager().openFishingBag(player, player, false); + } + if (args.size() >= 1) { + if (!sender.hasPermission("customfishing.admin")) { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); + return true; + } + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(args.get(0)); + if (offlinePlayer == null) { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.playerNotExist); + return true; + } + player.closeInventory(); + CustomFishing.getInstance().getBagDataManager().openFishingBag(player, offlinePlayer, args.size() >= 2 && args.get(1).equals("--force")); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, List args) { + if (!ConfigManager.enableFishingBag || !sender.hasPermission("customfishing.admin")) return null; + if (args.size() == 1) { + return online_players().stream() + .filter(cmd -> cmd.startsWith(args.get(0))) + .collect(Collectors.toList()); + } + return null; + } + } } diff --git a/src/main/java/net/momirealms/customfishing/commands/MainCommand.java b/src/main/java/net/momirealms/customfishing/commands/MainCommand.java index 7e29bf37..748c5499 100644 --- a/src/main/java/net/momirealms/customfishing/commands/MainCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/MainCommand.java @@ -61,6 +61,7 @@ public class MainCommand implements TabExecutor { regSubCommand(ImportCommand.INSTANCE); regSubCommand(SellShopCommand.INSTANCE); regSubCommand(OpenBagCommand.INSTANCE); + regSubCommand(StatisticsCommand.INSTANCE); } public void regSubCommand(SubCommand executor) { diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/BaitCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/BaitCommand.java index 4b0d3f90..c6f99c8e 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/BaitCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/BaitCommand.java @@ -29,6 +29,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public class BaitCommand extends AbstractSubCommand { @@ -80,61 +81,38 @@ public class BaitCommand extends AbstractSubCommand { } if (args.size() == 3){ ItemStackUtil.givePlayerBait(player, args.get(2), 1); - super.giveItem(sender, args.get(1), args.get(2), 1); + super.giveItemMsg(sender, args.get(1), args.get(2), 1); } else { if (Integer.parseInt(args.get(3)) < 1){ AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } ItemStackUtil.givePlayerBait(player, args.get(2), Integer.parseInt(args.get(3))); - super.giveItem(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); + super.giveItemMsg(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); } } return true; } - @Override public List onTabComplete(CommandSender sender, List args) { if (args.size() == 1) { return List.of("get", "give"); - } - if (args.size() == 2) { + } else if (args.size() == 2) { if (args.get(0).equals("get")) { - List arrayList = new ArrayList<>(); - for (String cmd : baits()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; + return filterStartingWith(baits(), args.get(1)); + } else if (args.get(0).equals("give")) { + return filterStartingWith(online_players(), args.get(1)); } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : online_players()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; - } - } - if (args.size() == 3) { + } else if (args.size() == 3) { if (args.get(0).equals("get")) { - return List.of("1","2","4","8","16","32","64"); - } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : baits()) { - if (cmd.startsWith(args.get(2))) - arrayList.add(cmd); - } - return arrayList; + return List.of("1", "2", "4", "8", "16", "32", "64"); + } else if (args.get(0).equals("give")) { + return filterStartingWith(baits(), args.get(2)); } + } else if (args.size() == 4 && args.get(0).equals("give")) { + return List.of("1", "2", "4", "8", "16", "32", "64"); } - if (args.size() == 4) { - if (args.get(0).equals("give")) { - return List.of("1","2","4","8","16","32","64"); - } - } - return super.onTabComplete(sender, args); + return null; } private List baits() { diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java index 6daca7b6..61ffcd9c 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java @@ -21,6 +21,7 @@ import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.commands.SubCommand; import net.momirealms.customfishing.fishing.competition.CompetitionSchedule; +import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.MessageManager; import net.momirealms.customfishing.util.AdventureUtil; import org.bukkit.command.CommandSender; @@ -38,6 +39,7 @@ public class CompetitionCommand extends AbstractSubCommand { @Override public boolean onCommand(CommandSender sender, List args) { + if (!ConfigManager.enableCompetition) return true; if (args.size() < 1){ AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs); return true; @@ -65,18 +67,21 @@ public class CompetitionCommand extends AbstractSubCommand { @Override public List onTabComplete(CommandSender sender, List args) { + List completions = new ArrayList<>(); if (args.size() == 1) { - List arrayList = new ArrayList<>(); - for (String cmd : List.of("start","end","cancel")) { - if (cmd.startsWith(args.get(0))) - arrayList.add(cmd); + for (String cmd : List.of("start", "end", "cancel")) { + if (cmd.startsWith(args.get(0))) { + completions.add(cmd); + } + } + } else if (args.size() == 2 && args.get(0).equals("start")) { + for (String cmd : competitions()) { + if (cmd.startsWith(args.get(1))) { + completions.add(cmd); + } } - return arrayList; } - if (args.size() == 2 && args.get(0).equals("start")) { - return competitions(); - } - return super.onTabComplete(sender, args); + return completions.isEmpty() ? null : completions; } private List competitions() { diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/ImportCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/ImportCommand.java index 2d109760..c2456771 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/ImportCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/ImportCommand.java @@ -54,7 +54,7 @@ public class ImportCommand extends AbstractSubCommand { @Override public List onTabComplete(CommandSender sender, List args) { if (args.size() == 1) { - return Collections.singletonList("file_name"); + return Collections.singletonList(""); } return super.onTabComplete(sender, args); } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/LootCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/LootCommand.java index 3ebf49aa..e21ff22e 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/LootCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/LootCommand.java @@ -30,6 +30,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -83,14 +84,14 @@ public class LootCommand extends AbstractSubCommand { } if (args.size() == 3){ ItemStackUtil.givePlayerLoot(player, args.get(2), 1); - super.giveItem(sender, args.get(1), args.get(2), 1); + super.giveItemMsg(sender, args.get(1), args.get(2), 1); } else { if (Integer.parseInt(args.get(3)) < 1){ AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } ItemStackUtil.givePlayerLoot(player, args.get(2), Integer.parseInt(args.get(3))); - super.giveItem(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); + super.giveItemMsg(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); } } return true; @@ -101,43 +102,26 @@ public class LootCommand extends AbstractSubCommand { if (args.size() == 1) { return List.of("get", "give"); } - if (args.size() == 2) { - if (args.get(0).equals("get")) { - List arrayList = new ArrayList<>(); - for (String cmd : loots()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; + else if (args.size() == 2) { + if ("get".equals(args.get(0))) { + return filterStartingWith(loots(), args.get(1)); } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : online_players()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; + else if ("give".equals(args.get(0))) { + return filterStartingWith(online_players(), args.get(1)); } } - if (args.size() == 3) { - if (args.get(0).equals("get")) { - return List.of("1","2","4","8","16","32","64"); + else if (args.size() == 3) { + if ("get".equals(args.get(0))) { + return List.of("1", "2", "4", "8", "16", "32", "64"); } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : loots()) { - if (cmd.startsWith(args.get(2))) - arrayList.add(cmd); - } - return arrayList; + else if ("give".equals(args.get(0))) { + return filterStartingWith(loots(), args.get(2)); } } - if (args.size() == 4) { - if (args.get(0).equals("give")) { - return List.of("1","2","4","8","16","32","64"); - } + else if (args.size() == 4 && "give".equals(args.get(0))) { + return List.of("1", "2", "4", "8", "16", "32", "64"); } - return super.onTabComplete(sender, args); + return null; } private List loots() { 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 c5149e9d..397e384f 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenBagCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenBagCommand.java @@ -44,12 +44,7 @@ public class OpenBagCommand extends AbstractSubCommand { public List onTabComplete(CommandSender sender, List args) { if (!ConfigManager.enableFishingBag) return null; if (args.size() == 1) { - List arrayList = new ArrayList<>(); - for (String cmd : online_players()) { - if (cmd.startsWith(args.get(0))) - arrayList.add(cmd); - } - return arrayList; + return filterStartingWith(online_players(), args.get(0)); } return super.onTabComplete(sender, args); } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenCommand.java deleted file mode 100644 index b70fbc2d..00000000 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/OpenCommand.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.commands.SubCommand; -import net.momirealms.customfishing.manager.ConfigManager; -import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -public class OpenCommand extends AbstractSubCommand { - - public static final SubCommand INSTANCE = new OpenCommand(); - - private OpenCommand() { - super("open", null); - } - - @Override - public boolean onCommand(CommandSender sender, List args) { - if (!ConfigManager.enableFishingBag) return true; - if (!(sender instanceof Player player)) { - AdventureUtil.consoleMessage(MessageManager.prefix + MessageManager.noConsole); - return true; - } - if (args.size() == 0) { - if (!sender.hasPermission("fishingbag.open")) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); - return true; - } - player.closeInventory(); - CustomFishing.getInstance().getBagDataManager().openFishingBag(player, player, false); - } - if (args.size() >= 1) { - if (!sender.hasPermission("customfishing.admin")) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); - return true; - } - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(args.get(0)); - if (offlinePlayer == null) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.playerNotExist); - return true; - } - player.closeInventory(); - CustomFishing.getInstance().getBagDataManager().openFishingBag(player, offlinePlayer, args.size() >= 2 && args.get(1).equals("--force")); - } - return true; - } - - @Override - public List onTabComplete(CommandSender sender, List args) { - if (!ConfigManager.enableFishingBag) return null; - if (!sender.hasPermission("customfishing.admin")) return null; - if (args.size() == 1) { - List arrayList = new ArrayList<>(); - for (String cmd : online_players()) { - if (cmd.startsWith(args.get(0))) - arrayList.add(cmd); - } - return arrayList; - } - return super.onTabComplete(sender, args); - } -} diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/RodCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/RodCommand.java index 2b232c43..bf9a7308 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/RodCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/RodCommand.java @@ -81,14 +81,14 @@ public class RodCommand extends AbstractSubCommand { } if (args.size() == 3){ ItemStackUtil.givePlayerRod(player, args.get(2), 1); - super.giveItem(sender, args.get(1), args.get(2), 1); + super.giveItemMsg(sender, args.get(1), args.get(2), 1); } else { if (Integer.parseInt(args.get(3)) < 1){ AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } ItemStackUtil.givePlayerRod(player, args.get(2), Integer.parseInt(args.get(3))); - super.giveItem(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); + super.giveItemMsg(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); } } return true; @@ -98,44 +98,22 @@ public class RodCommand extends AbstractSubCommand { public List onTabComplete(CommandSender sender, List args) { if (args.size() == 1) { return List.of("get", "give"); - } - if (args.size() == 2) { + } else if (args.size() == 2) { if (args.get(0).equals("get")) { - List arrayList = new ArrayList<>(); - for (String cmd : rods()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; + return filterStartingWith(rods(), args.get(1)); + } else if (args.get(0).equals("give")) { + return filterStartingWith(online_players(), args.get(1)); } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : online_players()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; - } - } - if (args.size() == 3) { + } else if (args.size() == 3) { if (args.get(0).equals("get")) { return List.of("1","2","4","8","16","32","64"); + } else if (args.get(0).equals("give")) { + return filterStartingWith(rods(), args.get(2)); } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : rods()) { - if (cmd.startsWith(args.get(2))) - arrayList.add(cmd); - } - return arrayList; - } + } else if (args.size() == 4 && args.get(0).equals("give")) { + return List.of("1","2","4","8","16","32","64"); } - if (args.size() == 4) { - if (args.get(0).equals("give")) { - return List.of("1","2","4","8","16","32","64"); - } - } - return super.onTabComplete(sender, args); + return null; } private List rods() { diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java new file mode 100644 index 00000000..8b692106 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java @@ -0,0 +1,122 @@ +package net.momirealms.customfishing.commands.subcmd; + +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.commands.AbstractSubCommand; +import net.momirealms.customfishing.commands.SubCommand; +import net.momirealms.customfishing.fishing.loot.Loot; +import net.momirealms.customfishing.manager.ConfigManager; +import net.momirealms.customfishing.manager.MessageManager; +import net.momirealms.customfishing.util.AdventureUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class StatisticsCommand extends AbstractSubCommand { + + public static final SubCommand INSTANCE = new StatisticsCommand(); + + public StatisticsCommand() { + super("statistics", null); + regSubCommand(SetCommand.INSTANCE); + regSubCommand(ResetCommand.INSTANCE); + } + + public static class SetCommand extends AbstractSubCommand { + + public static final SubCommand INSTANCE = new SetCommand(); + + public SetCommand() { + super("set", null); + } + + @Override + public boolean onCommand(CommandSender sender, List args) { + if (!ConfigManager.enableStatistics) return true; + if (args.size() < 3) { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs); + return true; + } + int amount = Integer.parseInt(args.get(2)); + if (amount < 0) { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.negativeStatistics); + return true; + } + if (CustomFishing.getInstance().getLootManager().hasLoot(args.get(1))) { + Player player = Bukkit.getPlayer(args.get(0)); + if (player != null) { + CustomFishing.getInstance().getStatisticsManager().setData(player.getUniqueId(), args.get(1), amount); + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.setStatistics.replace("{Player}", args.get(0)).replace("{Amount}", args.get(2)).replace("{Loot}", args.get(1))); + } + else { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", args.get(0))); + } + } + else { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.statisticsNotExists); + } + return true; + } + @Override + public List onTabComplete(CommandSender sender, List args) { + if (args.size() == 1) { + return online_players().stream() + .filter(player_name -> player_name.startsWith(args.get(0))) + .collect(Collectors.toList()); + } + if (args.size() == 2) { + return CustomFishing.getInstance().getLootManager().getAllLoots().stream() + .filter(loot -> loot.getKey().startsWith(args.get(1)) && !loot.isDisableStats()) + .map(Loot::getKey) + .collect(Collectors.toList()); + } + if (args.size() == 3) { + return List.of("0","1","2","4","8","16","32","64"); + } + return super.onTabComplete(sender, args); + } + } + + public static class ResetCommand extends AbstractSubCommand { + + public static final SubCommand INSTANCE = new ResetCommand(); + + public ResetCommand() { + super("reset", null); + } + + @Override + public boolean onCommand(CommandSender sender, List args) { + if (!ConfigManager.enableStatistics) return true; + if (args.size() < 1) { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs); + return true; + } + Player player = Bukkit.getPlayer(args.get(0)); + if (player != null) { + if (CustomFishing.getInstance().getStatisticsManager().reset(player.getUniqueId())) { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.resetStatistics); + } + else { + AdventureUtil.sendMessage(sender, MessageManager.prefix + "Internal Error, player's data is not loaded"); + } + } + else { + AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", args.get(0))); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, List args) { + if (args.size() == 1) { + return online_players().stream() + .filter(player_name -> player_name.startsWith(args.get(0))) + .collect(Collectors.toList()); + } + return null; + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/UtilCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/UtilCommand.java index 66584b1b..caa50eb2 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/UtilCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/UtilCommand.java @@ -29,6 +29,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public class UtilCommand extends AbstractSubCommand { @@ -80,14 +81,14 @@ public class UtilCommand extends AbstractSubCommand { } if (args.size() == 3){ ItemStackUtil.givePlayerUtil(player, args.get(2), 1); - super.giveItem(sender, args.get(1), args.get(2), 1); + super.giveItemMsg(sender, args.get(1), args.get(2), 1); } else { if (Integer.parseInt(args.get(3)) < 1){ AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } ItemStackUtil.givePlayerUtil(player, args.get(2), Integer.parseInt(args.get(3))); - super.giveItem(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); + super.giveItemMsg(sender, args.get(1), args.get(2), Integer.parseInt(args.get(3))); } } return true; @@ -97,44 +98,22 @@ public class UtilCommand extends AbstractSubCommand { public List onTabComplete(CommandSender sender, List args) { if (args.size() == 1) { return List.of("get", "give"); - } - if (args.size() == 2) { + } else if (args.size() == 2) { if (args.get(0).equals("get")) { - List arrayList = new ArrayList<>(); - for (String cmd : utils()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; + return filterStartingWith(utils(), args.get(1)); + } else if (args.get(0).equals("give")) { + return filterStartingWith(online_players(), args.get(1)); } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : online_players()) { - if (cmd.startsWith(args.get(1))) - arrayList.add(cmd); - } - return arrayList; - } - } - if (args.size() == 3) { + } else if (args.size() == 3) { if (args.get(0).equals("get")) { return List.of("1","2","4","8","16","32","64"); + } else if (args.get(0).equals("give")) { + return filterStartingWith(utils(), args.get(2)); } - if (args.get(0).equals("give")) { - List arrayList = new ArrayList<>(); - for (String cmd : utils()) { - if (cmd.startsWith(args.get(2))) - arrayList.add(cmd); - } - return arrayList; - } + } else if (args.size() == 4 && args.get(0).equals("give")) { + return List.of("1","2","4","8","16","32","64"); } - if (args.size() == 4) { - if (args.get(0).equals("give")) { - return List.of("1","2","4","8","16","32","64"); - } - } - return super.onTabComplete(sender, args); + return null; } private List utils() { diff --git a/src/main/java/net/momirealms/customfishing/data/PlayerStatisticsData.java b/src/main/java/net/momirealms/customfishing/data/PlayerStatisticsData.java new file mode 100644 index 00000000..b6ae4a78 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/data/PlayerStatisticsData.java @@ -0,0 +1,116 @@ +package net.momirealms.customfishing.data; + +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.fishing.loot.Loot; +import net.momirealms.customfishing.manager.LootManager; +import net.momirealms.customfishing.object.action.Action; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +public class PlayerStatisticsData { + + private final ConcurrentHashMap amountMap; + private final LootManager lootManager; + + public PlayerStatisticsData() { + this.amountMap = new ConcurrentHashMap<>(); + this.lootManager = CustomFishing.getInstance().getLootManager(); + } + + public PlayerStatisticsData(ConfigurationSection section) { + this.lootManager = CustomFishing.getInstance().getLootManager(); + this.amountMap = new ConcurrentHashMap<>(); + for (String key : section.getKeys(false)) { + amountMap.put(key, section.getInt(key)); + } + } + + public PlayerStatisticsData(String longText) { + this.lootManager = CustomFishing.getInstance().getLootManager(); + this.amountMap = (ConcurrentHashMap) Arrays.stream(longText.split(";")) + .map(element -> element.split(":")) + .filter(pair -> pair.length == 2) + .collect(Collectors.toConcurrentMap(pair -> pair[0], pair -> Integer.parseInt(pair[1]))); + } + + public String getLongText() { + StringJoiner joiner = new StringJoiner(";"); + for (Map.Entry entry : amountMap.entrySet()) { + joiner.add(entry.getKey() + ":" + entry.getValue()); + } + return joiner.toString(); + } + + public void addFishAmount(Loot loot, int amount, UUID uuid) { + Integer previous = amountMap.get(loot.getKey()); + if (previous == null) previous = 0; + int after = previous + amount; + amountMap.put(loot.getKey(), after); + Player player = Bukkit.getPlayer(uuid); + if (player == null) return; + HashMap actionMap = loot.getSuccessTimesActions(); + if (actionMap != null) { + for (Map.Entry entry : actionMap.entrySet()) { + if (entry.getKey() > previous && entry.getKey() <= after) { + for (Action action : entry.getValue()) { + action.doOn(player, null); + } + } + } + } + } + + public int getFishAmount(String key) { + Integer amount = amountMap.get(key); + return amount == null ? 0 : amount; + } + + public boolean hasFished(String key) { + return amountMap.containsKey(key); + } + + /** + * Get a category's unlock progress + * @param category category name + * @return percent + */ + public double getCategoryUnlockProgress(String category) { + List categories = lootManager.getCategories(category); + if (categories == null) return -1d; + double total = categories.size(); + double unlocked = 0; + for (String value : categories) { + if (hasFished(value)) { + unlocked++; + } + } + return (unlocked / total) * 100d; + } + + public int getCategoryTotalFishAmount(String category) { + List categories = lootManager.getCategories(category); + if (categories == null) return -1; + int total = 0; + for (String value : categories) { + total += getFishAmount(value); + } + return total; + } + + public void reset() { + amountMap.clear(); + } + + public ConcurrentHashMap getAmountMap() { + return amountMap; + } + + public void setData(String key, int value) { + amountMap.put(key, value); + } +} diff --git a/src/main/java/net/momirealms/customfishing/data/storage/DataStorageInterface.java b/src/main/java/net/momirealms/customfishing/data/storage/DataStorageInterface.java index 1e539138..ac7e323e 100644 --- a/src/main/java/net/momirealms/customfishing/data/storage/DataStorageInterface.java +++ b/src/main/java/net/momirealms/customfishing/data/storage/DataStorageInterface.java @@ -18,6 +18,7 @@ package net.momirealms.customfishing.data.storage; import net.momirealms.customfishing.data.PlayerSellData; +import net.momirealms.customfishing.data.PlayerStatisticsData; import org.bukkit.inventory.Inventory; import java.util.UUID; @@ -31,4 +32,6 @@ public interface DataStorageInterface { PlayerSellData loadSellData(UUID uuid, boolean force); void saveSellData(UUID uuid, PlayerSellData playerSellData, boolean unlock); StorageType getStorageType(); + void saveStatistics(UUID uuid, PlayerStatisticsData statisticsData, boolean unlock); + PlayerStatisticsData loadStatistics(UUID uuid, boolean force); } diff --git a/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java b/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java index 9caea793..83f847ef 100644 --- a/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java +++ b/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java @@ -19,6 +19,7 @@ package net.momirealms.customfishing.data.storage; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.data.PlayerSellData; +import net.momirealms.customfishing.data.PlayerStatisticsData; import net.momirealms.customfishing.util.ConfigUtil; import net.momirealms.customfishing.util.InventoryUtil; import org.bukkit.Bukkit; @@ -29,6 +30,7 @@ import org.bukkit.inventory.ItemStack; import java.io.File; import java.io.IOException; +import java.util.Map; import java.util.UUID; public class FileStorageImpl implements DataStorageInterface { @@ -100,4 +102,24 @@ public class FileStorageImpl implements DataStorageInterface { public StorageType getStorageType() { return StorageType.YAML; } + + @Override + public void saveStatistics(UUID uuid, PlayerStatisticsData statisticsData, boolean unlock) { + YamlConfiguration data = new YamlConfiguration(); + for (Map.Entry entry : statisticsData.getAmountMap().entrySet()) { + data.set(entry.getKey(), entry.getValue()); + } + try { + data.save(new File(plugin.getDataFolder(), "statistics_data" + File.separator + uuid + ".yml")); + } + catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public PlayerStatisticsData loadStatistics(UUID uuid, boolean force) { + YamlConfiguration data = ConfigUtil.readData(new File(plugin.getDataFolder(), "statistics_data" + File.separator + uuid + ".yml")); + return new PlayerStatisticsData(data); + } } diff --git a/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java b/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java index 8d6ac5b6..2f85fdc9 100644 --- a/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java +++ b/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java @@ -19,6 +19,9 @@ package net.momirealms.customfishing.data.storage; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.data.PlayerSellData; +import net.momirealms.customfishing.data.PlayerStatisticsData; +import net.momirealms.customfishing.manager.ConfigManager; +import net.momirealms.customfishing.manager.SellManager; import net.momirealms.customfishing.util.AdventureUtil; import net.momirealms.customfishing.util.InventoryUtil; import org.bukkit.Bukkit; @@ -46,8 +49,9 @@ public class MySQLStorageImpl implements DataStorageInterface { @Override public void initialize() { sqlConnection.createNewHikariConfiguration(); - createTableIfNotExist(sqlConnection.getTablePrefix() + "_fishingbag", SqlConstants.SQL_CREATE_BAG_TABLE); - createTableIfNotExist(sqlConnection.getTablePrefix() + "_selldata", SqlConstants.SQL_CREATE_SELL_TABLE); + if (ConfigManager.enableFishingBag) createTableIfNotExist(sqlConnection.getTablePrefix() + "_" + "fishingbag", SqlConstants.SQL_CREATE_BAG_TABLE); + if (SellManager.sellLimitation) createTableIfNotExist(sqlConnection.getTablePrefix() + "_" + "selldata", SqlConstants.SQL_CREATE_SELL_TABLE); + if (ConfigManager.enableStatistics) createTableIfNotExist(sqlConnection.getTablePrefix() + "_" + "statistics", SqlConstants.SQL_CREATE_STATS_TABLE); } @Override @@ -55,10 +59,15 @@ public class MySQLStorageImpl implements DataStorageInterface { sqlConnection.close(); } + @Override + public StorageType getStorageType() { + return StorageType.SQL; + } + @Override public Inventory loadBagData(UUID uuid, boolean force) { Inventory inventory = null; - String sql = String.format(SqlConstants.SQL_SELECT_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_" + "fishingbag"); + String sql = String.format(SqlConstants.SQL_SELECT_BY_UUID, sqlConnection.getTablePrefix() + "_" + "fishingbag"); OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) { statement.setString(1, uuid.toString()); @@ -96,7 +105,7 @@ public class MySQLStorageImpl implements DataStorageInterface { @Override public PlayerSellData loadSellData(UUID uuid, boolean force) { PlayerSellData playerSellData = null; - String sql = String.format(SqlConstants.SQL_SELECT_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_" + "selldata"); + String sql = String.format(SqlConstants.SQL_SELECT_BY_UUID, sqlConnection.getTablePrefix() + "_" + "selldata"); try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) { statement.setString(1, uuid.toString()); ResultSet rs = statement.executeQuery(); @@ -129,8 +138,36 @@ public class MySQLStorageImpl implements DataStorageInterface { } @Override - public StorageType getStorageType() { - return StorageType.SQL; + public PlayerStatisticsData loadStatistics(UUID uuid, boolean force) { + PlayerStatisticsData playerStatisticsData = null; + String sql = String.format(SqlConstants.SQL_SELECT_BY_UUID, sqlConnection.getTablePrefix() + "_" + "statistics"); + try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) { + statement.setString(1, uuid.toString()); + ResultSet rs = statement.executeQuery(); + if (rs.next()) { + int version = rs.getInt(2); + if (!force && version != 0) { + statement.close(); + connection.close(); + return null; + } + String longText = rs.getString(3); + playerStatisticsData = new PlayerStatisticsData(longText); + lockData(uuid, "statistics"); + } + else { + playerStatisticsData = new PlayerStatisticsData(); + insertStatisticsData(uuid); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return playerStatisticsData; + } + + @Override + public void saveStatistics(UUID uuid, PlayerStatisticsData statisticsData, boolean unlock) { + updateStatisticsData(uuid, statisticsData.getLongText(), unlock); } private void createTableIfNotExist(String table, String sqlStat) { @@ -168,6 +205,18 @@ public class MySQLStorageImpl implements DataStorageInterface { } } + private void insertStatisticsData(UUID uuid) { + String sql = String.format(SqlConstants.SQL_INSERT_STATS, sqlConnection.getTablePrefix() + "_" + "statistics"); + try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) { + statement.setString(1, uuid.toString()); + statement.setInt(2, 1); + statement.setString(3, ""); + statement.executeUpdate(); + } catch (SQLException ex) { + AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid); + } + } + private void updateBagData(UUID uuid, int size, String contents, boolean unlock) { String sql = String.format(SqlConstants.SQL_UPDATE_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_" + "fishingbag"); try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) { @@ -194,6 +243,18 @@ public class MySQLStorageImpl implements DataStorageInterface { } } + private void updateStatisticsData(UUID uuid, String longText, boolean unlock) { + String sql = String.format(SqlConstants.SQL_UPDATE_STATS_BY_UUID, sqlConnection.getTablePrefix() + "_" + "statistics"); + try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) { + statement.setInt(1, unlock ? 0 : 1); + statement.setString(2, longText); + statement.setString(3, uuid.toString()); + statement.executeUpdate(); + } catch (SQLException ex) { + AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid); + } + } + public void migrate() { String sql_1 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_" + "fishingbag"); try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql_1)) { diff --git a/src/main/java/net/momirealms/customfishing/data/storage/SqlConstants.java b/src/main/java/net/momirealms/customfishing/data/storage/SqlConstants.java index 8f0963f0..c6ac6c29 100644 --- a/src/main/java/net/momirealms/customfishing/data/storage/SqlConstants.java +++ b/src/main/java/net/momirealms/customfishing/data/storage/SqlConstants.java @@ -21,12 +21,14 @@ public class SqlConstants { public static final String SQL_CREATE_BAG_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL, `version` INT NOT NULL, `size` INT NOT NULL, `contents` LONGTEXT NOT NULL, PRIMARY KEY (`uuid`) )"; public static final String SQL_CREATE_SELL_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL, `version` INT NOT NULL, `date` INT NOT NULL, `money` INT NOT NULL, PRIMARY KEY (`uuid`) )"; + public static final String SQL_CREATE_STATS_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL, `version` INT NOT NULL, `stats` LONGTEXT NOT NULL, PRIMARY KEY (`uuid`) )"; public static final String SQL_INSERT_BAG = "INSERT INTO `%s`(`uuid`, `version`, `size`, `contents`) VALUES (?, ?, ?, ?)"; public static final String SQL_INSERT_SELL = "INSERT INTO `%s`(`uuid`, `version`, `date`, `money`) VALUES (?, ?, ?, ?)"; + public static final String SQL_INSERT_STATS = "INSERT INTO `%s`(`uuid`, `version`, `stats`) VALUES (?, ?, ?)"; public static final String SQL_UPDATE_BAG_BY_UUID = "UPDATE `%s` SET `version` = ?, `size` = ?, `contents` = ? WHERE `uuid` = ?"; public static final String SQL_UPDATE_SELL_BY_UUID = "UPDATE `%s` SET `version` = ?, `date` = ?, `money` = ? WHERE `uuid` = ?"; - public static final String SQL_SELECT_BAG_BY_UUID = "SELECT * FROM `%s` WHERE `uuid` = ?"; - public static final String SQL_SELECT_SELL_BY_UUID = "SELECT * FROM `%s` WHERE `uuid` = ?"; + public static final String SQL_UPDATE_STATS_BY_UUID = "UPDATE `%s` SET `version` = ?, `stats` = ? WHERE `uuid` = ?"; + public static final String SQL_SELECT_BY_UUID = "SELECT * FROM `%s` WHERE `uuid` = ?"; public static final String SQL_LOCK_BY_UUID = "UPDATE `%s` SET `version` = 1 WHERE `uuid` = ?"; public static final String SQL_ALTER_TABLE = "ALTER TABLE `%s` ADD COLUMN `version` INT NOT NULL AFTER `uuid`"; public static final String SQL_DROP_TABLE = "DROP TABLE `%s`"; diff --git a/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java b/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java index f5e23b95..b65ca152 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java +++ b/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java @@ -25,7 +25,7 @@ import net.momirealms.customfishing.fishing.competition.ranking.RedisRankingImpl import net.momirealms.customfishing.integration.papi.PlaceholderManager; import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; import net.momirealms.customfishing.util.AdventureUtil; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -148,7 +148,7 @@ public class Competition { } public void givePrize(){ - HashMap rewardsMap = competitionConfig.getRewards(); + HashMap rewardsMap = competitionConfig.getRewards(); if (ranking.getSize() != 0 && rewardsMap != null) { Iterator iterator = ranking.getIterator(); int i = 1; @@ -157,19 +157,19 @@ public class Competition { String playerName = iterator.next(); Player player = Bukkit.getPlayer(playerName); if (player != null){ - for (ActionInterface action : rewardsMap.get(String.valueOf(i))) { + for (Action action : rewardsMap.get(String.valueOf(i))) { action.doOn(player, null); } } i++; } else { - ActionInterface[] actions = rewardsMap.get("participation"); + Action[] actions = rewardsMap.get("participation"); if (actions != null) { iterator.forEachRemaining(playerName -> { Player player = Bukkit.getPlayer(playerName); if (player != null){ - for (ActionInterface action : actions) { + for (Action action : actions) { action.doOn(player, null); } } diff --git a/src/main/java/net/momirealms/customfishing/fishing/competition/CompetitionConfig.java b/src/main/java/net/momirealms/customfishing/fishing/competition/CompetitionConfig.java index 2cabb962..b5db1f46 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/competition/CompetitionConfig.java +++ b/src/main/java/net/momirealms/customfishing/fishing/competition/CompetitionConfig.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.fishing.competition; import net.momirealms.customfishing.fishing.competition.bossbar.BossBarConfig; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; import java.util.Calendar; import java.util.HashMap; @@ -38,9 +38,9 @@ public class CompetitionConfig { private final CompetitionGoal goal; private final BossBarConfig bossBarConfig; private final boolean enableBossBar; - private final HashMap rewards; + private final HashMap rewards; - public CompetitionConfig(int duration, int minPlayers, List startMessage, List endMessage, List startCommand, List endCommand, List joinCommand, CompetitionGoal goal, BossBarConfig bossBarConfig, boolean enableBossBar, HashMap rewards) { + public CompetitionConfig(int duration, int minPlayers, List startMessage, List endMessage, List startCommand, List endCommand, List joinCommand, CompetitionGoal goal, BossBarConfig bossBarConfig, boolean enableBossBar, HashMap rewards) { this.duration = duration; this.minPlayers = minPlayers; this.startMessage = startMessage; @@ -94,7 +94,7 @@ public class CompetitionConfig { return enableBossBar; } - public HashMap getRewards() { + public HashMap getRewards() { return rewards; } diff --git a/src/main/java/net/momirealms/customfishing/fishing/loot/DroppedItem.java b/src/main/java/net/momirealms/customfishing/fishing/loot/DroppedItem.java index d6ec3492..f5fe834d 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/loot/DroppedItem.java +++ b/src/main/java/net/momirealms/customfishing/fishing/loot/DroppedItem.java @@ -30,8 +30,8 @@ public class DroppedItem extends Loot { private float basicPrice; private float sizeBonus; - public DroppedItem(String key, String nick, String material, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, boolean randomDurability, boolean disableBar) { - super(key, nick, fishingGames, weight, showInFinder, score, disableBar); + public DroppedItem(String key, String nick, String material, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, boolean randomDurability, boolean disableBar, boolean disableStats) { + super(key, nick, fishingGames, weight, showInFinder, score, disableBar, disableStats); this.material = material; this.randomDurability = randomDurability; } diff --git a/src/main/java/net/momirealms/customfishing/fishing/loot/Loot.java b/src/main/java/net/momirealms/customfishing/fishing/loot/Loot.java index 33c96217..27e9056a 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/loot/Loot.java +++ b/src/main/java/net/momirealms/customfishing/fishing/loot/Loot.java @@ -19,27 +19,31 @@ package net.momirealms.customfishing.fishing.loot; import net.momirealms.customfishing.fishing.MiniGameConfig; import net.momirealms.customfishing.fishing.requirements.RequirementInterface; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; + +import java.util.HashMap; public class Loot { - public static Loot EMPTY = new Loot("null", "null", new MiniGameConfig[0], 0, false, 0d, false); + public static Loot EMPTY = new Loot("null", "null", new MiniGameConfig[0], 0, false, 0d, false, true); protected final String key; protected final String nick; protected String group; + protected boolean disableStats; protected boolean disableBar; protected final boolean showInFinder; - protected ActionInterface[] successActions; - protected ActionInterface[] failureActions; - protected ActionInterface[] hookActions; - protected ActionInterface[] consumeActions; + protected Action[] successActions; + protected Action[] failureActions; + protected Action[] hookActions; + protected Action[] consumeActions; + protected HashMap successTimesActions; protected RequirementInterface[] requirements; protected final MiniGameConfig[] fishingGames; protected final int weight; protected final double score; - public Loot(String key, String nick, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, boolean disableBar) { + public Loot(String key, String nick, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, boolean disableBar, boolean disableStats) { this.key = key; this.nick = nick; this.weight = weight; @@ -47,6 +51,7 @@ public class Loot { this.score = score; this.fishingGames = fishingGames; this.disableBar = disableBar; + this.disableStats = disableStats; } public MiniGameConfig[] getFishingGames() { @@ -73,35 +78,35 @@ public class Loot { return showInFinder; } - public ActionInterface[] getSuccessActions() { + public Action[] getSuccessActions() { return successActions; } - public void setSuccessActions(ActionInterface[] successActions) { + public void setSuccessActions(Action[] successActions) { this.successActions = successActions; } - public ActionInterface[] getFailureActions() { + public Action[] getFailureActions() { return failureActions; } - public ActionInterface[] getConsumeActions() { + public Action[] getConsumeActions() { return consumeActions; } - public void setConsumeActions(ActionInterface[] consumeActions) { + public void setConsumeActions(Action[] consumeActions) { this.consumeActions = consumeActions; } - public void setFailureActions(ActionInterface[] failureActions) { + public void setFailureActions(Action[] failureActions) { this.failureActions = failureActions; } - public ActionInterface[] getHookActions() { + public Action[] getHookActions() { return hookActions; } - public void setHookActions(ActionInterface[] hookActions) { + public void setHookActions(Action[] hookActions) { this.hookActions = hookActions; } @@ -124,4 +129,16 @@ public class Loot { public boolean isDisableBar() { return disableBar; } + + public HashMap getSuccessTimesActions() { + return successTimesActions; + } + + public void setSuccessTimesActions(HashMap successTimesActions) { + this.successTimesActions = successTimesActions; + } + + public boolean isDisableStats() { + return disableStats; + } } diff --git a/src/main/java/net/momirealms/customfishing/fishing/loot/Mob.java b/src/main/java/net/momirealms/customfishing/fishing/loot/Mob.java index 37e26876..25860a85 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/loot/Mob.java +++ b/src/main/java/net/momirealms/customfishing/fishing/loot/Mob.java @@ -26,8 +26,8 @@ public class Mob extends Loot{ private final int mobLevel; private final MobVector mobVector; - public Mob(String key, String nick, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, String mobID, int mobLevel, MobVector mobVector, boolean disableBar) { - super(key, nick, fishingGames, weight, showInFinder, score, disableBar); + public Mob(String key, String nick, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, String mobID, int mobLevel, MobVector mobVector, boolean disableBar, boolean disableStats) { + super(key, nick, fishingGames, weight, showInFinder, score, disableBar, disableStats); this.mobID = mobID; this.mobLevel = mobLevel; this.mobVector = mobVector; diff --git a/src/main/java/net/momirealms/customfishing/fishing/totem/Totem.java b/src/main/java/net/momirealms/customfishing/fishing/totem/Totem.java index 44f3ebe7..9e940e53 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/totem/Totem.java +++ b/src/main/java/net/momirealms/customfishing/fishing/totem/Totem.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.fishing.totem; import net.momirealms.customfishing.fishing.Effect; import net.momirealms.customfishing.fishing.requirements.RequirementInterface; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; import org.bukkit.Particle; import org.bukkit.potion.PotionEffect; @@ -32,8 +32,8 @@ public class Totem { private final Particle particle; private final int duration; private final Effect effect; - private ActionInterface[] activatorActions; - private ActionInterface[] nearbyActions; + private Action[] activatorActions; + private Action[] nearbyActions; private double holoOffset; private String[] holoText; private PotionEffect[] potionEffects; @@ -84,19 +84,19 @@ public class Totem { return effect; } - public ActionInterface[] getActivatorActions() { + public Action[] getActivatorActions() { return activatorActions; } - public void setActivatorActions(ActionInterface[] activatorActions) { + public void setActivatorActions(Action[] activatorActions) { this.activatorActions = activatorActions; } - public ActionInterface[] getNearbyActions() { + public Action[] getNearbyActions() { return nearbyActions; } - public void setNearbyActions(ActionInterface[] nearbyActions) { + public void setNearbyActions(Action[] nearbyActions) { this.nearbyActions = nearbyActions; } diff --git a/src/main/java/net/momirealms/customfishing/fishing/totem/TotemConfig.java b/src/main/java/net/momirealms/customfishing/fishing/totem/TotemConfig.java index f2e71e80..9ece33e0 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/totem/TotemConfig.java +++ b/src/main/java/net/momirealms/customfishing/fishing/totem/TotemConfig.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.fishing.totem; import net.momirealms.customfishing.fishing.Effect; import net.momirealms.customfishing.fishing.requirements.RequirementInterface; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; import org.bukkit.Particle; import org.bukkit.potion.PotionEffect; @@ -32,8 +32,8 @@ public class TotemConfig { private final Particle particle; private final int duration; private final Effect effect; - private ActionInterface[] activatorActions; - private ActionInterface[] nearbyActions; + private Action[] activatorActions; + private Action[] nearbyActions; private double holoOffset; private String[] holoText; private PotionEffect[] potionEffects; @@ -84,19 +84,19 @@ public class TotemConfig { return effect; } - public ActionInterface[] getActivatorActions() { + public Action[] getActivatorActions() { return activatorActions; } - public void setActivatorActions(ActionInterface[] activatorActions) { + public void setActivatorActions(Action[] activatorActions) { this.activatorActions = activatorActions; } - public ActionInterface[] getNearbyActions() { + public Action[] getNearbyActions() { return nearbyActions; } - public void setNearbyActions(ActionInterface[] nearbyActions) { + public void setNearbyActions(Action[] nearbyActions) { this.nearbyActions = nearbyActions; } diff --git a/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java b/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java index 2155694b..d4df4394 100644 --- a/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java +++ b/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java @@ -17,9 +17,9 @@ package net.momirealms.customfishing.integration.block; +import io.th0rgal.oraxen.api.OraxenBlocks; import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic; import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory; -import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicListener; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.integration.BlockInterface; import net.momirealms.customfishing.util.AdventureUtil; @@ -58,7 +58,7 @@ public class OraxenBlockImpl implements BlockInterface { @Nullable @Override public String getID(Block block) { - NoteBlockMechanic mechanic = NoteBlockMechanicListener.getNoteBlockMechanic(block); + NoteBlockMechanic mechanic = OraxenBlocks.getNoteBlockMechanic(block); String id; if (mechanic == null) { id = block.getType().name(); diff --git a/src/main/java/net/momirealms/customfishing/integration/item/OraxenItemImpl.java b/src/main/java/net/momirealms/customfishing/integration/item/OraxenItemImpl.java index c5870432..b9ad615a 100644 --- a/src/main/java/net/momirealms/customfishing/integration/item/OraxenItemImpl.java +++ b/src/main/java/net/momirealms/customfishing/integration/item/OraxenItemImpl.java @@ -17,8 +17,8 @@ package net.momirealms.customfishing.integration.item; +import io.th0rgal.oraxen.api.OraxenItems; import io.th0rgal.oraxen.items.ItemBuilder; -import io.th0rgal.oraxen.items.OraxenItems; import net.momirealms.customfishing.integration.ItemInterface; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/net/momirealms/customfishing/integration/papi/PlaceholderManager.java b/src/main/java/net/momirealms/customfishing/integration/papi/PlaceholderManager.java index 77881acf..6f01e003 100644 --- a/src/main/java/net/momirealms/customfishing/integration/papi/PlaceholderManager.java +++ b/src/main/java/net/momirealms/customfishing/integration/papi/PlaceholderManager.java @@ -38,10 +38,11 @@ public class PlaceholderManager extends Function { private boolean hasPlaceholderAPI = false; public PlaceholderManager(CustomFishing plugin) { + this.plugin = plugin; if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { hasPlaceholderAPI = true; this.competitionPapi = new CompetitionPapi(); - //this.statisticsPapi = new StatisticsPapi(plugin); + this.statisticsPapi = new StatisticsPapi(plugin); } } @@ -55,13 +56,13 @@ public class PlaceholderManager extends Function { @Override public void load() { if (competitionPapi != null) competitionPapi.register(); - //if (statisticsPapi != null) statisticsPapi.register(); + if (statisticsPapi != null) statisticsPapi.register(); } @Override public void unload() { if (this.competitionPapi != null) competitionPapi.unregister(); - //if (this.statisticsPapi != null) statisticsPapi.unregister(); + if (this.statisticsPapi != null) statisticsPapi.unregister(); } public List detectBasicPlaceholders(String text){ diff --git a/src/main/java/net/momirealms/customfishing/integration/papi/StatisticsPapi.java b/src/main/java/net/momirealms/customfishing/integration/papi/StatisticsPapi.java index 48a340c6..582eb130 100644 --- a/src/main/java/net/momirealms/customfishing/integration/papi/StatisticsPapi.java +++ b/src/main/java/net/momirealms/customfishing/integration/papi/StatisticsPapi.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable; public class StatisticsPapi extends PlaceholderExpansion { - private CustomFishing plugin; + private final CustomFishing plugin; public StatisticsPapi(CustomFishing plugin) { this.plugin = plugin; @@ -36,6 +36,30 @@ public class StatisticsPapi extends PlaceholderExpansion { @Override public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) { + String[] args = params.split("_", 2); + switch (args[0]) { + case "amount" -> { + if (args[1].equals("")) return "lack args"; + return String.valueOf(plugin.getStatisticsManager().getFishAmount(player.getUniqueId(), args[1])); + } + case "hascaught" -> { + if (args[1].equals("")) return "lack args"; + return String.valueOf(plugin.getStatisticsManager().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])); + } + case "progress" -> { + String progress = String.format("%.1f", plugin.getStatisticsManager().getCategoryUnlockProgress(player.getUniqueId(), moreArgs[1])); + return progress.equals("100.0") ? "100" : progress; + } + } + } + } return "null"; } } diff --git a/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java b/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java index e8a9ac24..41cf1732 100644 --- a/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java @@ -28,7 +28,7 @@ import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.listener.InventoryListener; import net.momirealms.customfishing.listener.JoinQuitListener; import net.momirealms.customfishing.listener.WindowPacketListener; -import net.momirealms.customfishing.object.Function; +import net.momirealms.customfishing.object.DataFunction; import net.momirealms.customfishing.util.AdventureUtil; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -47,7 +47,7 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -public class BagDataManager extends Function { +public class BagDataManager extends DataFunction { private final ConcurrentHashMap dataMap; private final HashMap tempData; @@ -56,13 +56,12 @@ public class BagDataManager extends Function { private final JoinQuitListener joinQuitListener; private final BukkitTask timerSave; private final CustomFishing plugin; - private final HashMap triedTimes; public BagDataManager(CustomFishing plugin) { + super(); this.plugin = plugin; this.dataMap = new ConcurrentHashMap<>(); this.tempData = new HashMap<>(); - this.triedTimes = new HashMap<>(); this.inventoryListener = new InventoryListener(this); this.windowPacketListener = new WindowPacketListener(this); @@ -100,7 +99,7 @@ public class BagDataManager extends Function { for (HumanEntity humanEntity : entry.getValue().getViewers()) { humanEntity.closeInventory(); } - dataManager.getDataStorageInterface().saveBagData(entry.getKey(), entry.getValue(), false); + dataManager.getDataStorageInterface().saveBagData(entry.getKey(), entry.getValue(), true); } dataMap.clear(); tempData.clear(); @@ -265,20 +264,4 @@ public class BagDataManager extends Function { viewer.openInventory(inventory); } } - - private boolean checkTriedTimes(UUID uuid) { - Integer previous = triedTimes.get(uuid); - if (previous == null) { - triedTimes.put(uuid, 1); - return false; - } - else if (previous > 2) { - triedTimes.remove(uuid); - return true; - } - else { - triedTimes.put(uuid, previous + 1); - return false; - } - } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java b/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java index c85c5a52..98b4c812 100644 --- a/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java @@ -24,11 +24,10 @@ import net.momirealms.customfishing.fishing.competition.CompetitionSchedule; import net.momirealms.customfishing.fishing.competition.bossbar.BossBarConfig; import net.momirealms.customfishing.fishing.competition.bossbar.BossBarOverlay; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; import net.momirealms.customfishing.object.action.CommandActionImpl; import net.momirealms.customfishing.object.action.MessageActionImpl; import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; import org.bukkit.boss.BarColor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -94,14 +93,14 @@ public class CompetitionManager extends Function { competitionSection.getInt("bossbar.switch-interval", 200) ); - HashMap rewardsMap = new HashMap<>(); + HashMap rewardsMap = new HashMap<>(); Objects.requireNonNull(competitionSection.getConfigurationSection("prize")).getKeys(false).forEach(rank -> { - List rewards = new ArrayList<>(); + List rewards = new ArrayList<>(); if (competitionSection.contains("prize." + rank + ".messages")) rewards.add(new MessageActionImpl(competitionSection.getStringList("prize." + rank + ".messages").toArray(new String[0]), null)); if (competitionSection.contains("prize." + rank + ".commands")) rewards.add(new CommandActionImpl(competitionSection.getStringList("prize." + rank + ".commands").toArray(new String[0]), null)); - rewardsMap.put(rank, rewards.toArray(new ActionInterface[0])); + rewardsMap.put(rank, rewards.toArray(new Action[0])); }); CompetitionConfig competitionConfig = new CompetitionConfig( diff --git a/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java b/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java index 5d413988..abd98363 100644 --- a/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java @@ -123,6 +123,7 @@ public class ConfigManager { canStoreLoot = config.getBoolean("mechanics.fishing-bag.can-store-loot", false); addTagToFish = config.getBoolean("mechanics.add-custom-fishing-tags-to-loots", true); fishingBagTitle = config.getString("mechanics.fishing-bag.bag-title", "Fishing Bag"); + enableStatistics = config.getBoolean("mechanics.fishing-statistics.enable", true); bagWhiteListItems = new HashSet<>(); for (String material : config.getStringList("mechanics.fishing-bag.whitelist-items")) bagWhiteListItems.add(Material.valueOf(material.toUpperCase())); redisSettings(config); diff --git a/src/main/java/net/momirealms/customfishing/manager/DataManager.java b/src/main/java/net/momirealms/customfishing/manager/DataManager.java index 2a153f23..91b933cc 100644 --- a/src/main/java/net/momirealms/customfishing/manager/DataManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/DataManager.java @@ -70,4 +70,10 @@ public class DataManager extends Function { StorageType st = config.getString("data-storage-method","YAML").equalsIgnoreCase("YAML") ? StorageType.YAML : StorageType.SQL; if (this.dataStorageInterface != null && dataStorageInterface.getStorageType() != st) this.dataStorageInterface.disable(); } + + public void disable() { + if (this.dataStorageInterface != null) { + this.dataStorageInterface.disable(); + } + } } diff --git a/src/main/java/net/momirealms/customfishing/manager/FishingManager.java b/src/main/java/net/momirealms/customfishing/manager/FishingManager.java index cbda499f..3e4aee12 100644 --- a/src/main/java/net/momirealms/customfishing/manager/FishingManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/FishingManager.java @@ -47,7 +47,7 @@ import net.momirealms.customfishing.integration.item.McMMOTreasure; import net.momirealms.customfishing.listener.*; import net.momirealms.customfishing.object.Function; import net.momirealms.customfishing.object.SimpleLocation; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; import net.momirealms.customfishing.util.AdventureUtil; import net.momirealms.customfishing.util.FakeItemUtil; import net.momirealms.customfishing.util.ItemStackUtil; @@ -176,7 +176,8 @@ public class FishingManager extends Function { initialEffect.setDifficulty(0); initialEffect.setDoubleLootChance(0); initialEffect.setTimeModifier(1); - initialEffect.setScoreMultiplier(0); + initialEffect.setScoreMultiplier(1); + initialEffect.setSizeMultiplier(1); initialEffect.setWeightMD(new HashMap<>()); initialEffect.setWeightAS(new HashMap<>()); @@ -536,9 +537,11 @@ public class FishingManager extends Function { Competition.currentCompetition.tryAddBossBarToPlayer(player); } - dropItem(player, location, fishResultEvent.isDouble(), drop); - for (ActionInterface action : droppedItem.getSuccessActions()) + for (Action action : droppedItem.getSuccessActions()) action.doOn(player, null); + + dropItem(player, location, fishResultEvent.isDouble(), drop); + addStats(player.getUniqueId(), droppedItem, isDouble ? 2 : 1); sendSuccessTitle(player, droppedItem.getNick()); } @@ -603,6 +606,12 @@ public class FishingManager extends Function { } } + private void addStats(UUID uuid, Loot loot, int amount) { + if (!ConfigManager.enableStatistics) return; + if (loot.isDisableStats()) return; + plugin.getStatisticsManager().addFishAmount(uuid, loot, amount); + } + private void dropVanillaLoot(Player player, VanillaLoot vanillaLoot, Location location, boolean isDouble) { ItemStack itemStack; itemStack = vanillaLoot.getItemStack(); @@ -646,9 +655,11 @@ public class FishingManager extends Function { Competition.currentCompetition.tryAddBossBarToPlayer(player); } - mobInterface.summon(player.getLocation(), location, mob); - for (ActionInterface action : loot.getSuccessActions()) + for (Action action : loot.getSuccessActions()) action.doOn(player, null); + + mobInterface.summon(player.getLocation(), location, mob); + addStats(player.getUniqueId(), mob, 1); sendSuccessTitle(player, loot.getNick()); } @@ -734,7 +745,7 @@ public class FishingManager extends Function { } if (!isVanilla && loot != null) { - for (ActionInterface action : loot.getFailureActions()) + for (Action action : loot.getFailureActions()) action.doOn(player, null); } @@ -891,10 +902,10 @@ public class FishingManager extends Function { plugin.getTotemManager().removeModel(totem.getFinalModel(), coreLoc, direction); if (player.getGameMode() != GameMode.CREATIVE) itemStack.setAmount(itemStack.getAmount() - 1); - for (ActionInterface action : totem.getActivatorActions()) { + for (Action action : totem.getActivatorActions()) { action.doOn(player, null); } - for (ActionInterface action : totem.getNearbyActions()) { + for (Action action : totem.getNearbyActions()) { for (Player nearby : coreLoc.getNearbyPlayers(totem.getRadius())) { action.doOn(nearby, player); } @@ -947,7 +958,7 @@ public class FishingManager extends Function { fishingPlayerMap.put(player, fishingGame); } if (vanillaLoot.get(player) == null && loot != null){ - for (ActionInterface action : loot.getHookActions()) { + for (Action action : loot.getHookActions()) { action.doOn(player, null); } } @@ -1044,7 +1055,7 @@ public class FishingManager extends Function { if (!(loot instanceof DroppedItem droppedItem)) return; final Player player = event.getPlayer(); if (droppedItem.getConsumeActions() != null) - for (ActionInterface action : droppedItem.getConsumeActions()) + for (Action action : droppedItem.getConsumeActions()) action.doOn(player, null); } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/manager/LootManager.java b/src/main/java/net/momirealms/customfishing/manager/LootManager.java index 2647c8b9..2da901d0 100644 --- a/src/main/java/net/momirealms/customfishing/manager/LootManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/LootManager.java @@ -47,12 +47,14 @@ public class LootManager extends Function { private final HashMap waterLoots; private final HashMap lavaLoots; private final HashMap lootItems; + private final HashMap> category; public LootManager(CustomFishing plugin) { this.plugin = plugin; this.waterLoots = new HashMap<>(); this.lavaLoots = new HashMap<>(); this.lootItems = new HashMap<>(); + this.category = new HashMap<>(); } @Nullable @@ -65,7 +67,9 @@ public class LootManager extends Function { public void load() { this.loadItems(); this.loadMobs(); + this.loadCategories(); AdventureUtil.consoleMessage("[CustomFishing] Loaded " + (this.lavaLoots.size() + this.waterLoots.size()) + " loot(s)"); + AdventureUtil.consoleMessage("[CustomFishing] Loaded " + (this.category.size()) + " category(s)"); } @Override @@ -73,6 +77,7 @@ public class LootManager extends Function { this.waterLoots.clear(); this.lavaLoots.clear(); this.lootItems.clear(); + this.category.clear(); } @Nullable @@ -84,6 +89,39 @@ public class LootManager extends Function { return loot; } + public boolean hasLoot(String key) { + boolean has = this.waterLoots.containsKey(key); + if (!has) { + has = this.lavaLoots.containsKey(key); + } + return has; + } + + private void loadCategories() { + File category_file = new File(plugin.getDataFolder() + File.separator + "categories"); + if (!category_file.exists()) { + if (!category_file.mkdir()) return; + plugin.saveResource("categories" + File.separator + "default.yml", false); + } + File[] files = category_file.listFiles(); + if (files == null) return; + for (File file : files) { + if (!file.getName().endsWith(".yml")) continue; + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + outer: + for (String key : config.getKeys(false)) { + List fishIDs = config.getStringList(key); + for (String id : fishIDs) { + if (!waterLoots.containsKey(id) && !lavaLoots.containsKey(id)) { + AdventureUtil.consoleMessage("[CustomFishing] Fish ID " + id + " doesn't exist in category " + key); + continue outer; + } + } + category.put(key, fishIDs); + } + } + } + private void loadMobs() { if (Bukkit.getPluginManager().getPlugin("MythicMobs") == null) return; File mob_file = new File(plugin.getDataFolder() + File.separator + "mobs"); @@ -114,7 +152,8 @@ public class LootManager extends Function { mobSection.getDouble("vector.horizontal",1.1), mobSection.getDouble("vector.vertical",1.3) ), - mobSection.getBoolean("disable-bar-mechanic", false) + mobSection.getBoolean("disable-bar-mechanic", false), + mobSection.getBoolean("disable-stats", false) ); setActions(mobSection, loot); @@ -154,7 +193,8 @@ public class LootManager extends Function { lootSection.getBoolean("show-in-fishfinder", true), lootSection.getDouble("score"), lootSection.getBoolean("random-durability", false), - lootSection.getBoolean("disable-bar-mechanic", false) + lootSection.getBoolean("disable-bar-mechanic", false), + lootSection.getBoolean("disable-stats", false) ); if (lootSection.contains("size")) { @@ -189,7 +229,7 @@ public class LootManager extends Function { 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); @@ -204,14 +244,25 @@ public class LootManager extends Function { loot.setFailureActions(getActions(section.getConfigurationSection("action.failure"), loot.getNick())); loot.setHookActions(getActions(section.getConfigurationSection("action.hook"), loot.getNick())); loot.setConsumeActions(getActions(section.getConfigurationSection("action.consume"), loot.getNick())); + setSuccessAmountAction(section.getConfigurationSection("action.success-times"), loot); + } + + private void setSuccessAmountAction(ConfigurationSection section, Loot loot) { + if (section != null) { + HashMap actionMap = new HashMap<>(); + for (String amount : section.getKeys(false)) { + actionMap.put(Integer.parseInt(amount), getActions(section.getConfigurationSection(amount), loot.getNick())); + } + loot.setSuccessTimesActions(actionMap); + } } private void setRequirements(ConfigurationSection section, Loot loot) { loot.setRequirements(getRequirements(section)); } - public ActionInterface[] getActions(ConfigurationSection section, String nick) { - List actions = new ArrayList<>(); + public Action[] getActions(ConfigurationSection section, String nick) { + List actions = new ArrayList<>(); if (section != null) { for (String action : section.getKeys(false)) { switch (action) { @@ -242,7 +293,7 @@ public class LootManager extends Function { } } } - return actions.toArray(new ActionInterface[0]); + return actions.toArray(new Action[0]); } public RequirementInterface[] getRequirements(ConfigurationSection section) { @@ -295,4 +346,9 @@ public class LootManager extends Function { loots.addAll(getLavaLoots().values()); return loots; } + + @Nullable + public List getCategories(String categoryID) { + return category.get(categoryID); + } } diff --git a/src/main/java/net/momirealms/customfishing/manager/MessageManager.java b/src/main/java/net/momirealms/customfishing/manager/MessageManager.java index d45fc537..13336e0d 100644 --- a/src/main/java/net/momirealms/customfishing/manager/MessageManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/MessageManager.java @@ -55,6 +55,10 @@ public class MessageManager { public static String noRod; public static String hookOther; public static String reachSellLimit; + public static String setStatistics; + public static String resetStatistics; + public static String negativeStatistics; + public static String statisticsNotExists; public static void load() { YamlConfiguration config = ConfigUtil.getConfig("messages" + File.separator + "messages_" + ConfigManager.lang +".yml"); @@ -89,5 +93,9 @@ public class MessageManager { noRod = config.getString("messages.no-rod", "messages.no-rod is missing"); hookOther = config.getString("messages.hook-other-entity","messages.hook-other-entity is missing"); reachSellLimit = config.getString("messages.reach-sell-limit","messages.reach-sell-limit is missing"); + setStatistics = config.getString("messages.set-statistics","messages.set-statistics is missing"); + resetStatistics = config.getString("messages.reset-statistics","messages.reset-statistics is missing"); + negativeStatistics = config.getString("messages.negative-statistics","messages.negative-statistics is missing"); + statisticsNotExists = config.getString("messages.statistics-not-exist","messages.statistics-not-exist is missing"); } } diff --git a/src/main/java/net/momirealms/customfishing/manager/SellManager.java b/src/main/java/net/momirealms/customfishing/manager/SellManager.java index 48e8f157..60f22f28 100644 --- a/src/main/java/net/momirealms/customfishing/manager/SellManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/SellManager.java @@ -35,7 +35,7 @@ import net.momirealms.customfishing.integration.papi.PlaceholderManager; import net.momirealms.customfishing.listener.InventoryListener; import net.momirealms.customfishing.listener.JoinQuitListener; import net.momirealms.customfishing.listener.WindowPacketListener; -import net.momirealms.customfishing.object.Function; +import net.momirealms.customfishing.object.DataFunction; import net.momirealms.customfishing.util.AdventureUtil; import net.momirealms.customfishing.util.ConfigUtil; import net.momirealms.customfishing.util.ItemStackUtil; @@ -56,9 +56,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -public class SellManager extends Function { +public class SellManager extends DataFunction { private final WindowPacketListener windowPacketListener; private final InventoryListener inventoryListener; @@ -89,15 +88,14 @@ public class SellManager extends Function { public static int upperLimit; private final HashMap inventoryMap; private final HashMap sellDataMap; - private final HashMap triedTimes; public SellManager(CustomFishing plugin) { + super(); this.plugin = plugin; this.windowPacketListener = new WindowPacketListener(this); this.inventoryListener = new InventoryListener(this); this.joinQuitListener = new JoinQuitListener(this); this.sellDataMap = new HashMap<>(); - this.triedTimes = new HashMap<>(); this.inventoryMap = new HashMap<>(); } @@ -466,20 +464,4 @@ public class SellManager extends Function { ); } } - - public boolean checkTriedTimes(UUID uuid) { - Integer previous = triedTimes.get(uuid); - if (previous == null) { - triedTimes.put(uuid, 1); - return false; - } - else if (previous > 2) { - triedTimes.remove(uuid); - return true; - } - else { - triedTimes.put(uuid, previous + 1); - return false; - } - } } diff --git a/src/main/java/net/momirealms/customfishing/manager/StatisticsManager.java b/src/main/java/net/momirealms/customfishing/manager/StatisticsManager.java index 9ea6451b..55b55dac 100644 --- a/src/main/java/net/momirealms/customfishing/manager/StatisticsManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/StatisticsManager.java @@ -1,4 +1,138 @@ package net.momirealms.customfishing.manager; -public class StatisticsManager { +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.data.PlayerStatisticsData; +import net.momirealms.customfishing.fishing.loot.Loot; +import net.momirealms.customfishing.listener.JoinQuitListener; +import net.momirealms.customfishing.object.DataFunction; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; + +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +public class StatisticsManager extends DataFunction { + + private final ConcurrentHashMap statisticsDataMap; + private final JoinQuitListener joinQuitListener; + private final CustomFishing plugin; + + public StatisticsManager(CustomFishing plugin) { + super(); + this.statisticsDataMap = new ConcurrentHashMap<>(); + this.joinQuitListener = new JoinQuitListener(this); + this.plugin = plugin; + } + + @Override + public void load() { + if (!ConfigManager.enableStatistics) return; + Bukkit.getPluginManager().registerEvents(joinQuitListener, plugin); + } + + @Override + public void unload() { + HandlerList.unregisterAll(joinQuitListener); + } + + public void disable() { + unload(); + DataManager dataManager = plugin.getDataManager(); + for (Map.Entry entry : statisticsDataMap.entrySet()) { + dataManager.getDataStorageInterface().saveStatistics(entry.getKey(), entry.getValue(), true); + } + statisticsDataMap.clear(); + } + + @Override + public void onQuit(Player player) { + UUID uuid = player.getUniqueId(); + PlayerStatisticsData playerStatisticsData = statisticsDataMap.remove(uuid); + triedTimes.remove(player.getUniqueId()); + if (playerStatisticsData != null) { + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getDataManager().getDataStorageInterface().saveStatistics(uuid, playerStatisticsData, true); + }); + } + } + + @Override + public void onJoin(Player player) { + Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> { + joinReadData(player, false); + }, 10); + } + + public void joinReadData(Player player, boolean force) { + if (player == null || !player.isOnline()) return; + PlayerStatisticsData statisticsData = plugin.getDataManager().getDataStorageInterface().loadStatistics(player.getUniqueId(), force); + if (statisticsData != null) { + statisticsDataMap.put(player.getUniqueId(), statisticsData); + } + else if (!force) { + if (!checkTriedTimes(player.getUniqueId())) { + Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> joinReadData(player, false), 20); + } + else { + Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> joinReadData(player, true), 20); + } + } + } + + public void addFishAmount(UUID uuid, Loot loot, int amount) { + PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid); + if (statisticsData != null) { + statisticsData.addFishAmount(loot, amount, uuid); + } + } + + public int getFishAmount(UUID uuid, String key) { + PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid); + if (statisticsData != null) { + return statisticsData.getFishAmount(key); + } + return -1; + } + + public boolean hasFished(UUID uuid, String key) { + PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid); + if (statisticsData != null) { + return statisticsData.hasFished(key); + } + return false; + } + + public double getCategoryUnlockProgress(UUID uuid, String category) { + PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid); + if (statisticsData != null) { + return statisticsData.getCategoryUnlockProgress(category); + } + return -1d; + } + + public int getCategoryTotalFishAmount(UUID uuid, String category) { + PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid); + if (statisticsData != null) { + return statisticsData.getCategoryTotalFishAmount(category); + } + return -1; + } + + public boolean reset(UUID uuid) { + PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid); + if (statisticsData != null) { + statisticsData.reset(); + return true; + } + return false; + } + + public void setData(UUID uuid, String key, int amount) { + PlayerStatisticsData statisticsData = statisticsDataMap.get(uuid); + if (statisticsData != null) { + statisticsData.setData(key, amount); + } + } } diff --git a/src/main/java/net/momirealms/customfishing/manager/TotemManager.java b/src/main/java/net/momirealms/customfishing/manager/TotemManager.java index 830cc559..ef43b1ef 100644 --- a/src/main/java/net/momirealms/customfishing/manager/TotemManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/TotemManager.java @@ -24,7 +24,7 @@ import net.momirealms.customfishing.fishing.totem.OriginalModel; import net.momirealms.customfishing.fishing.totem.TotemConfig; import net.momirealms.customfishing.integration.BlockInterface; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.object.action.ActionInterface; +import net.momirealms.customfishing.object.action.Action; import net.momirealms.customfishing.object.action.CommandActionImpl; import net.momirealms.customfishing.object.action.MessageActionImpl; import net.momirealms.customfishing.util.AdventureUtil; @@ -183,8 +183,8 @@ public class TotemManager extends Function { EffectManager.getEffect(config.getConfigurationSection(key + ".effect")) ); - List actionList = new ArrayList<>(); - List nearActionList = new ArrayList<>(); + List actionList = new ArrayList<>(); + List nearActionList = new ArrayList<>(); if (config.contains(key + ".action")) { for (String action : Objects.requireNonNull(config.getConfigurationSection(key + ".action")).getKeys(false)) { switch (action) { @@ -196,8 +196,8 @@ public class TotemManager extends Function { } } - totem.setActivatorActions(actionList.toArray(new ActionInterface[0])); - totem.setNearbyActions(nearActionList.toArray(new ActionInterface[0])); + totem.setActivatorActions(actionList.toArray(new Action[0])); + totem.setNearbyActions(nearActionList.toArray(new Action[0])); totem.setRequirements(plugin.getLootManager().getRequirements(config.getConfigurationSection(key + ".requirements"))); if (config.getBoolean(key + ".hologram.enable", false)) { diff --git a/src/main/java/net/momirealms/customfishing/object/DataFunction.java b/src/main/java/net/momirealms/customfishing/object/DataFunction.java new file mode 100644 index 00000000..4515c8e6 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/DataFunction.java @@ -0,0 +1,29 @@ +package net.momirealms.customfishing.object; + +import java.util.HashMap; +import java.util.UUID; + +public abstract class DataFunction extends Function { + + protected final HashMap triedTimes; + + public DataFunction() { + this.triedTimes = new HashMap<>(); + } + + protected boolean checkTriedTimes(UUID uuid) { + Integer previous = triedTimes.get(uuid); + if (previous == null) { + triedTimes.put(uuid, 1); + return false; + } + else if (previous > 2) { + triedTimes.remove(uuid); + return true; + } + else { + triedTimes.put(uuid, previous + 1); + return false; + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/Function.java b/src/main/java/net/momirealms/customfishing/object/Function.java index 279666d9..8ebaea1c 100644 --- a/src/main/java/net/momirealms/customfishing/object/Function.java +++ b/src/main/java/net/momirealms/customfishing/object/Function.java @@ -27,7 +27,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; -public class Function { +public abstract class Function { public void load() { //empty diff --git a/src/main/java/net/momirealms/customfishing/object/action/ActionInterface.java b/src/main/java/net/momirealms/customfishing/object/action/Action.java similarity index 96% rename from src/main/java/net/momirealms/customfishing/object/action/ActionInterface.java rename to src/main/java/net/momirealms/customfishing/object/action/Action.java index 709715ff..cab14f25 100644 --- a/src/main/java/net/momirealms/customfishing/object/action/ActionInterface.java +++ b/src/main/java/net/momirealms/customfishing/object/action/Action.java @@ -20,7 +20,7 @@ package net.momirealms.customfishing.object.action; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; -public interface ActionInterface { +public interface Action { void doOn(Player player, @Nullable Player anotherPlayer); diff --git a/src/main/java/net/momirealms/customfishing/object/action/CommandActionImpl.java b/src/main/java/net/momirealms/customfishing/object/action/CommandActionImpl.java index 9f7c74ae..33078435 100644 --- a/src/main/java/net/momirealms/customfishing/object/action/CommandActionImpl.java +++ b/src/main/java/net/momirealms/customfishing/object/action/CommandActionImpl.java @@ -21,7 +21,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; -public record CommandActionImpl(String[] commands, String nick) implements ActionInterface { +public record CommandActionImpl(String[] commands, String nick) implements Action { public CommandActionImpl(String[] commands, @Nullable String nick) { this.commands = commands; diff --git a/src/main/java/net/momirealms/customfishing/object/action/MessageActionImpl.java b/src/main/java/net/momirealms/customfishing/object/action/MessageActionImpl.java index 689e5e22..cefb57ff 100644 --- a/src/main/java/net/momirealms/customfishing/object/action/MessageActionImpl.java +++ b/src/main/java/net/momirealms/customfishing/object/action/MessageActionImpl.java @@ -21,7 +21,7 @@ import net.momirealms.customfishing.util.AdventureUtil; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; -public record MessageActionImpl(String[] messages, String nick) implements ActionInterface { +public record MessageActionImpl(String[] messages, String nick) implements Action { public MessageActionImpl(String[] messages, String nick) { this.messages = messages; diff --git a/src/main/java/net/momirealms/customfishing/object/action/PotionEffectImpl.java b/src/main/java/net/momirealms/customfishing/object/action/PotionEffectImpl.java index 40ddf346..42248b93 100644 --- a/src/main/java/net/momirealms/customfishing/object/action/PotionEffectImpl.java +++ b/src/main/java/net/momirealms/customfishing/object/action/PotionEffectImpl.java @@ -21,7 +21,7 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.jetbrains.annotations.Nullable; -public record PotionEffectImpl(PotionEffect[] potionEffects) implements ActionInterface { +public record PotionEffectImpl(PotionEffect[] potionEffects) implements Action { @Override public void doOn(Player player, @Nullable Player anotherPlayer) { diff --git a/src/main/java/net/momirealms/customfishing/object/action/SkillXPImpl.java b/src/main/java/net/momirealms/customfishing/object/action/SkillXPImpl.java index c6e97279..bccba215 100644 --- a/src/main/java/net/momirealms/customfishing/object/action/SkillXPImpl.java +++ b/src/main/java/net/momirealms/customfishing/object/action/SkillXPImpl.java @@ -21,7 +21,7 @@ import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.integration.SkillInterface; import org.bukkit.entity.Player; -public record SkillXPImpl(double amount) implements ActionInterface { +public record SkillXPImpl(double amount) implements Action { @Override public void doOn(Player player, Player another) { diff --git a/src/main/java/net/momirealms/customfishing/object/action/SoundActionImpl.java b/src/main/java/net/momirealms/customfishing/object/action/SoundActionImpl.java index 95747af4..7d93db10 100644 --- a/src/main/java/net/momirealms/customfishing/object/action/SoundActionImpl.java +++ b/src/main/java/net/momirealms/customfishing/object/action/SoundActionImpl.java @@ -22,7 +22,7 @@ import net.kyori.adventure.sound.Sound; import net.momirealms.customfishing.util.AdventureUtil; import org.bukkit.entity.Player; -public record SoundActionImpl(String source, String sound, float volume, float pitch) implements ActionInterface { +public record SoundActionImpl(String source, String sound, float volume, float pitch) implements Action { @Override public void doOn(Player player, Player another) { diff --git a/src/main/java/net/momirealms/customfishing/object/action/VanillaXPImpl.java b/src/main/java/net/momirealms/customfishing/object/action/VanillaXPImpl.java index d83fe9f4..ce515d97 100644 --- a/src/main/java/net/momirealms/customfishing/object/action/VanillaXPImpl.java +++ b/src/main/java/net/momirealms/customfishing/object/action/VanillaXPImpl.java @@ -22,7 +22,7 @@ import net.kyori.adventure.sound.Sound; import net.momirealms.customfishing.util.AdventureUtil; import org.bukkit.entity.Player; -public record VanillaXPImpl(int amount, boolean mending) implements ActionInterface { +public record VanillaXPImpl(int amount, boolean mending) implements Action { @Override public void doOn(Player player, Player another) { diff --git a/src/main/resources/categories/default.yml b/src/main/resources/categories/default.yml new file mode 100644 index 00000000..f3c8a186 --- /dev/null +++ b/src/main/resources/categories/default.yml @@ -0,0 +1,55 @@ +# %fishingstats_amount_% get the number of a certain fish caught +# %fishingstats_hascaught_% return if a player has caught this fish +# %fishingstats_category_total_% get the total number of a certain category's fish caught +# %fishingstats_category_progress_% get the player's exploration of this category of fish +normal_fish: + - pufferfish + - cod + - salmon + - tropical_fish + - tuna_fish + - pike_fish + - gold_fish + - perch_fish + - mullet_fish + - sardine_fish + - carp_fish + - cat_fish + - octopus + - sunfish + - red_snapper_fish + - salmon_void_fish + - woodskip_fish + - sturgeon_fish + +sliver_star_fish: + - tuna_fish_silver_star + - pike_fish_silver_star + - gold_fish_silver_star + - perch_fish_silver_star + - mullet_fish_silver_star + - sardine_fish_silver_star + - carp_fish_silver_star + - cat_fish_silver_star + - octopus_silver_star + - sunfish_silver_star + - red_snapper_fish_silver_star + - salmon_void_fish_silver_star + - woodskip_fish_silver_star + - sturgeon_fish_silver_star + +golden_star_fish: + - tuna_fish_golden_star + - pike_fish_golden_star + - gold_fish_golden_star + - perch_fish_golden_star + - mullet_fish_golden_star + - sardine_fish_golden_star + - carp_fish_golden_star + - cat_fish_golden_star + - octopus_golden_star + - sunfish_golden_star + - red_snapper_fish_golden_star + - salmon_void_fish_golden_star + - woodskip_fish_golden_star + - sturgeon_fish_golden_star \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 411748af..0deb8486 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Don't change -config-version: '17' +config-version: '18' # bStats metrics: true @@ -109,6 +109,9 @@ mechanics: item: lava_effect # ticks time: 25 + # Record the statistics of player's fishing results + fishing-statistics: + enable: true titles: success: diff --git a/src/main/resources/loots/default.yml b/src/main/resources/loots/default.yml index 2153311a..d66bfb59 100644 --- a/src/main/resources/loots/default.yml +++ b/src/main/resources/loots/default.yml @@ -1,6 +1,8 @@ rubbish: material: cod show-in-fishfinder: false + disable-stats: true + disable-bar-mechanic: true display: name: 'Garbage' lore: @@ -14,6 +16,7 @@ obsidian: nick: '<#4B0082>Obsidian' material: obsidian in-lava: true + disable-stats: true action: success: mending: 15 @@ -21,6 +24,7 @@ wither_skeleton_skull: nick: 'Wither Skeleton Skull' material: wither_skeleton_skull in-lava: true + disable-stats: true weight: 1 action: success: diff --git a/src/main/resources/loots/example.yml b/src/main/resources/loots/example.yml index 691bf572..a0871559 100644 --- a/src/main/resources/loots/example.yml +++ b/src/main/resources/loots/example.yml @@ -5,6 +5,9 @@ rainbow_fish: # Disable bar mechanic for a certain loot # 为某个战利品关闭捕鱼条机制 disable-bar-mechanic: false + # Disable statistics for a certain loot + # 关闭此物品的数据记录 + disable-stats: true # Nick is what to show in fish finder and titles # 昵称将在标题和找鱼器信息中显示 nick: 'Example Fish' @@ -65,7 +68,7 @@ rainbow_fish: namespace: '(String) momirealms' id: '(String) rainbow_fish' - # Available events: consume/success/failure/hook + # Available events: consume/success/failure/hook/success-times # Available actions: message/command/exp/mending/skill-xp/sound/potion-effect action: consume: @@ -100,6 +103,13 @@ rainbow_fish: - 'The fish is hooked!' command: - 'say Hook command example' + success-times: + 1: + message: + - 'This is the first time you caught a rainbow fish!' + 100: + message: + - 'You have caught rainbow fish for 100 times!' # Enchantments on the item enchantments: diff --git a/src/main/resources/messages/messages_chinese.yml b/src/main/resources/messages/messages_chinese.yml index c9e0715e..b58e3733 100644 --- a/src/main/resources/messages/messages_chinese.yml +++ b/src/main/resources/messages/messages_chinese.yml @@ -30,3 +30,7 @@ messages: no-rod: '你必须使用特殊鱼竿才能获得战利品!' no-player: '虚位以待' no-score: '无分数' + set-statistics: '成功将玩家 {Player} 的 {Loot} 捕获次数设置为 {Amount}' + reset-statistics: '成功重置玩家 {Player} 的统计数据' + negative-statistics: '不能设置此数据为负数' + statistics-not-exist: '此统计数据不存在' diff --git a/src/main/resources/messages/messages_english.yml b/src/main/resources/messages/messages_english.yml index cc6c0f2f..46c43f64 100644 --- a/src/main/resources/messages/messages_english.yml +++ b/src/main/resources/messages/messages_english.yml @@ -29,4 +29,8 @@ messages: hook-other-entity: 'The bobber is hooked on another entity!' no-rod: 'You have to obtain a special rod to get loots!' no-player: 'No player' - no-score: 'No score' \ No newline at end of file + no-score: 'No score' + set-statistics: 'Successfully set {Player}''s {Loot} catch amount to {Amount}' + reset-statistics: 'Successfully reset {Player}''s statistics' + negative-statistics: 'Amount should be a value no lower than zero' + statistics-not-exist: 'That statistics does not exist' \ No newline at end of file diff --git a/src/main/resources/messages/messages_spanish.yml b/src/main/resources/messages/messages_spanish.yml index b7579105..f9f2e760 100644 --- a/src/main/resources/messages/messages_spanish.yml +++ b/src/main/resources/messages/messages_spanish.yml @@ -29,4 +29,8 @@ messages: hook-other-entity: '¡El bobber está enganchado a otra entidad!' no-rod: 'Hay que obtener una vara especial para conseguir botines' no-player: 'Ningún jugador' - no-score: 'Sin puntuación' \ No newline at end of file + no-score: 'Sin puntuación' + set-statistics: 'Successfully set {Player}''s {Loot} catch amount to {Amount}' + reset-statistics: 'Successfully reset {Player}''s statistics' + negative-statistics: 'Amount should be a value no lower than zero' + statistics-not-exist: 'That statistics does not exist' \ No newline at end of file