9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-28 19:39:06 +00:00

1.3.0-beta-4

This commit is contained in:
Xiao-MoMi
2023-03-09 17:32:46 +08:00
parent 6d9a89e50f
commit bb811513b1
56 changed files with 946 additions and 386 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '1.3.0-beta-3'
version = '1.3.0-beta-4'
repositories {
mavenCentral()

View File

@@ -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() {

View File

@@ -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<String> filterStartingWith(List<String> list, String prefix) {
return list.stream().filter(s -> s.startsWith(prefix)).collect(Collectors.toList());
}
}

View File

@@ -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<String> 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<String, SubCommand> 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<String> 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<String> onTabComplete(CommandSender sender, List<String> 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;
}
}
}

View File

@@ -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) {

View File

@@ -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<String> onTabComplete(CommandSender sender, List<String> 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<String> 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<String> 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<String> 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<String> baits() {

View File

@@ -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<String> 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<String> onTabComplete(CommandSender sender, List<String> args) {
List<String> completions = new ArrayList<>();
if (args.size() == 1) {
List<String> 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<String> competitions() {

View File

@@ -54,7 +54,7 @@ public class ImportCommand extends AbstractSubCommand {
@Override
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (args.size() == 1) {
return Collections.singletonList("file_name");
return Collections.singletonList("<file_name>");
}
return super.onTabComplete(sender, args);
}

View File

@@ -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<String> 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<String> 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<String> 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<String> loots() {

View File

@@ -44,12 +44,7 @@ public class OpenBagCommand extends AbstractSubCommand {
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (!ConfigManager.enableFishingBag) return null;
if (args.size() == 1) {
List<String> 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);
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.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<String> 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<String> onTabComplete(CommandSender sender, List<String> args) {
if (!ConfigManager.enableFishingBag) return null;
if (!sender.hasPermission("customfishing.admin")) return null;
if (args.size() == 1) {
List<String> arrayList = new ArrayList<>();
for (String cmd : online_players()) {
if (cmd.startsWith(args.get(0)))
arrayList.add(cmd);
}
return arrayList;
}
return super.onTabComplete(sender, args);
}
}

View File

@@ -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<String> onTabComplete(CommandSender sender, List<String> 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<String> 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<String> 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<String> 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<String> rods() {

View File

@@ -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<String> 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<String> onTabComplete(CommandSender sender, List<String> 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<String> 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<String> onTabComplete(CommandSender sender, List<String> args) {
if (args.size() == 1) {
return online_players().stream()
.filter(player_name -> player_name.startsWith(args.get(0)))
.collect(Collectors.toList());
}
return null;
}
}
}

View File

@@ -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<String> onTabComplete(CommandSender sender, List<String> 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<String> 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<String> 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<String> 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<String> utils() {

View File

@@ -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<String, Integer> 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<String, Integer>) Arrays.stream(longText.split(";"))
.map(element -> element.split(":"))
.filter(pair -> pair.length == 2)
.collect(Collectors.toConcurrentMap(pair -> pair[0], pair -> Integer.parseInt(pair[1])));
}
public String getLongText() {
StringJoiner joiner = new StringJoiner(";");
for (Map.Entry<String, Integer> 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<Integer, Action[]> actionMap = loot.getSuccessTimesActions();
if (actionMap != null) {
for (Map.Entry<Integer, Action[]> 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<String> 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<String> 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<String, Integer> getAmountMap() {
return amountMap;
}
public void setData(String key, int value) {
amountMap.put(key, value);
}
}

View File

@@ -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);
}

View File

@@ -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<String, Integer> 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);
}
}

View File

@@ -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)) {

View File

@@ -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`";

View File

@@ -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<String, ActionInterface[]> rewardsMap = competitionConfig.getRewards();
HashMap<String, Action[]> rewardsMap = competitionConfig.getRewards();
if (ranking.getSize() != 0 && rewardsMap != null) {
Iterator<String> 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);
}
}

View File

@@ -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<String, ActionInterface[]> rewards;
private final HashMap<String, Action[]> rewards;
public CompetitionConfig(int duration, int minPlayers, List<String> startMessage, List<String> endMessage, List<String> startCommand, List<String> endCommand, List<String> joinCommand, CompetitionGoal goal, BossBarConfig bossBarConfig, boolean enableBossBar, HashMap<String, ActionInterface[]> rewards) {
public CompetitionConfig(int duration, int minPlayers, List<String> startMessage, List<String> endMessage, List<String> startCommand, List<String> endCommand, List<String> joinCommand, CompetitionGoal goal, BossBarConfig bossBarConfig, boolean enableBossBar, HashMap<String, Action[]> rewards) {
this.duration = duration;
this.minPlayers = minPlayers;
this.startMessage = startMessage;
@@ -94,7 +94,7 @@ public class CompetitionConfig {
return enableBossBar;
}
public HashMap<String, ActionInterface[]> getRewards() {
public HashMap<String, Action[]> getRewards() {
return rewards;
}

View File

@@ -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;
}

View File

@@ -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<Integer, Action[]> 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<Integer, Action[]> getSuccessTimesActions() {
return successTimesActions;
}
public void setSuccessTimesActions(HashMap<Integer, Action[]> successTimesActions) {
this.successTimesActions = successTimesActions;
}
public boolean isDisableStats() {
return disableStats;
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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<String> detectBasicPlaceholders(String text){

View File

@@ -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";
}
}

View File

@@ -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<UUID, Inventory> dataMap;
private final HashMap<UUID, Inventory> 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<UUID, Integer> 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;
}
}
}

View File

@@ -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<String, ActionInterface[]> rewardsMap = new HashMap<>();
HashMap<String, Action[]> rewardsMap = new HashMap<>();
Objects.requireNonNull(competitionSection.getConfigurationSection("prize")).getKeys(false).forEach(rank -> {
List<ActionInterface> rewards = new ArrayList<>();
List<Action> 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(

View File

@@ -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);

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -47,12 +47,14 @@ public class LootManager extends Function {
private final HashMap<String, Loot> waterLoots;
private final HashMap<String, Loot> lavaLoots;
private final HashMap<String, ItemStack> lootItems;
private final HashMap<String, List<String>> 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 <green>" + (this.lavaLoots.size() + this.waterLoots.size()) + " <gray>loot(s)");
AdventureUtil.consoleMessage("[CustomFishing] Loaded <green>" + (this.category.size()) + " <gray>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<String> fishIDs = config.getStringList(key);
for (String id : fishIDs) {
if (!waterLoots.containsKey(id) && !lavaLoots.containsKey(id)) {
AdventureUtil.consoleMessage("<red>[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<Integer, Action[]> 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<ActionInterface> actions = new ArrayList<>();
public Action[] getActions(ConfigurationSection section, String nick) {
List<Action> 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<String> getCategories(String categoryID) {
return category.get(categoryID);
}
}

View File

@@ -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");
}
}

View File

@@ -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<Player, Inventory> inventoryMap;
private final HashMap<UUID, PlayerSellData> sellDataMap;
private final HashMap<UUID, Integer> 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;
}
}
}

View File

@@ -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<UUID, PlayerStatisticsData> 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<UUID, PlayerStatisticsData> 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);
}
}
}

View File

@@ -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<ActionInterface> actionList = new ArrayList<>();
List<ActionInterface> nearActionList = new ArrayList<>();
List<Action> actionList = new ArrayList<>();
List<Action> 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)) {

View File

@@ -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<UUID, Integer> 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;
}
}
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -0,0 +1,55 @@
# %fishingstats_amount_<id>% get the number of a certain fish caught
# %fishingstats_hascaught_<id>% return if a player has caught this fish
# %fishingstats_category_total_<id>% get the total number of a certain category's fish caught
# %fishingstats_category_progress_<id>% 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

View File

@@ -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:

View File

@@ -1,6 +1,8 @@
rubbish:
material: cod
show-in-fishfinder: false
disable-stats: true
disable-bar-mechanic: true
display:
name: '<gray>Garbage</gray>'
lore:
@@ -14,6 +16,7 @@ obsidian:
nick: '<#4B0082>Obsidian</#4B0082>'
material: obsidian
in-lava: true
disable-stats: true
action:
success:
mending: 15
@@ -21,6 +24,7 @@ wither_skeleton_skull:
nick: '<black>Wither Skeleton Skull</black>'
material: wither_skeleton_skull
in-lava: true
disable-stats: true
weight: 1
action:
success:

View File

@@ -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:

View File

@@ -30,3 +30,7 @@ messages:
no-rod: '你必须使用特殊鱼竿才能获得战利品!'
no-player: '虚位以待'
no-score: '无分数'
set-statistics: '成功将玩家 {Player} 的 {Loot} 捕获次数设置为 {Amount}'
reset-statistics: '成功重置玩家 {Player} 的统计数据'
negative-statistics: '不能设置此数据为负数'
statistics-not-exist: '此统计数据不存在'

View File

@@ -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-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'

View File

@@ -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-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'