diff --git a/src/main/java/net/momirealms/customfishing/ConfigReader.java b/src/main/java/net/momirealms/customfishing/ConfigReader.java index 663c631f..e0ba5fd4 100644 --- a/src/main/java/net/momirealms/customfishing/ConfigReader.java +++ b/src/main/java/net/momirealms/customfishing/ConfigReader.java @@ -1,7 +1,32 @@ +/* + * 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; -import net.momirealms.customfishing.bar.Difficulty; -import net.momirealms.customfishing.bar.Layout; +import net.kyori.adventure.bossbar.BossBar; +import net.momirealms.customfishing.competition.CompetitionConfig; +import net.momirealms.customfishing.competition.Goal; +import net.momirealms.customfishing.competition.bossbar.BossBarConfig; +import net.momirealms.customfishing.titlebar.Difficulty; +import net.momirealms.customfishing.titlebar.Layout; +import net.momirealms.customfishing.hook.skill.Aurelium; +import net.momirealms.customfishing.hook.skill.MMOCore; +import net.momirealms.customfishing.hook.skill.SkillXP; +import net.momirealms.customfishing.hook.skill.mcMMO; import net.momirealms.customfishing.item.Bait; import net.momirealms.customfishing.item.Loot; import net.momirealms.customfishing.item.Rod; @@ -10,6 +35,7 @@ import net.momirealms.customfishing.requirements.*; import net.momirealms.customfishing.utils.*; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -30,6 +56,8 @@ public class ConfigReader{ public static HashMap BAIT = new HashMap<>(); public static HashMap BAITITEM = new HashMap<>(); public static HashMap LAYOUT = new HashMap<>(); + public static HashMap Competitions = new HashMap<>(); + public static HashMap CompetitionsCommand = new HashMap<>(); private static YamlConfiguration getConfig(String configName) { File file = new File(CustomFishing.instance.getDataFolder(), configName); @@ -47,6 +75,7 @@ public class ConfigReader{ loadUtil(); loadRod(); loadBait(); + loadCompetitions(); } public static class Config { @@ -58,10 +87,12 @@ public class ConfigReader{ public static boolean vanillaDrop; public static boolean needOpenWater; public static boolean needSpecialRod; + public static boolean competition; public static String season_papi; public static String lang; public static int fishFinderCoolDown; public static double timeMultiply; + public static SkillXP skillXP; public static void loadConfig() { @@ -96,6 +127,34 @@ public class ConfigReader{ AdventureManager.consoleMessage("[CustomFishing] PlaceholderAPI Hooked!"); } } + skillXP = null; + + if(config.getBoolean("config.integrations.mcMMO",false)){ + if(Bukkit.getPluginManager().getPlugin("mcMMO") == null){ + CustomFishing.instance.getLogger().warning("Failed to initialize mcMMO!"); + }else { + skillXP = new mcMMO(); + AdventureManager.consoleMessage("[CustomCrops] mcMMO Hooked!"); + } + } + if(config.getBoolean("config.integrations.AureliumSkills",false)){ + if(Bukkit.getPluginManager().getPlugin("AureliumSkills") == null){ + CustomFishing.instance.getLogger().warning("Failed to initialize AureliumSkills!"); + }else { + skillXP = new Aurelium(); + AdventureManager.consoleMessage("[CustomCrops] AureliumSkills Hooked!"); + } + } + if(config.getBoolean("config.integrations.MMOCore",false)){ + if(Bukkit.getPluginManager().getPlugin("MMOCore") == null){ + CustomFishing.instance.getLogger().warning("Failed to initialize MMOCore!"); + }else { + skillXP = new MMOCore(); + AdventureManager.consoleMessage("[CustomCrops] MMOCore Hooked!"); + } + } + + season = config.getBoolean("config.season.enable"); if (!papi && season) { season = false; @@ -113,6 +172,7 @@ public class ConfigReader{ fishFinderCoolDown = config.getInt("config.fishfinder-cooldown"); timeMultiply = config.getDouble("config.time-multiply"); lang = config.getString("config.lang","cn"); + competition = config.getBoolean("config.fishing-competition",true); /* 计算获取布局 @@ -157,6 +217,15 @@ public class ConfigReader{ public static String splitChar; public static String noLoot; public static String notOpenWater; + public static String competitionOn; + public static String notEnoughPlayers; + public static String noRank; + public static String forceSuccess; + public static String forceFailure; + public static String forceEnd; + public static String forceCancel; + public static String noPlayer; + public static String noScore; public static void loadMessage() { YamlConfiguration config = getConfig("messages/messages_" + Config.lang +".yml"); prefix = config.getString("messages.prefix"); @@ -175,6 +244,15 @@ public class ConfigReader{ splitChar = config.getString("messages.split-char"); noLoot = config.getString("messages.no-loot"); notOpenWater = config.getString("messages.not-open-water"); + competitionOn = config.getString("messages.competition-ongoing"); + notEnoughPlayers = config.getString("messages.players-not-enough"); + noRank = config.getString("messages.no-rank"); + forceSuccess = config.getString("messages.force-competition-success"); + forceFailure = config.getString("messages.force-competition-failure"); + forceEnd = config.getString("messages.force-competition-end"); + forceCancel = config.getString("messages.force-competition-cancel"); + noPlayer = config.getString("messages.no-player"); + noScore = config.getString("messages.no-score"); } } @@ -288,6 +366,7 @@ public class ConfigReader{ loot.setNick(loot.getName()); } loot.setUnbreakable(config.getBoolean("items." + key + ".unbreakable",false)); + loot.setPoint((float) config.getDouble("items." + key + ".score")); if (config.contains("items." + key + ".action.message")) loot.setMsg(config.getString("items." + key + ".action.message")); @@ -297,6 +376,8 @@ public class ConfigReader{ loot.setExp(config.getInt("items." + key + ".action.exp")); if (config.contains("items." + key + ".layout")) loot.setLayout(config.getString("items." + key + ".layout")); + if (config.contains("items." + key + ".skill-xp")) + loot.setSkillXP(config.getDouble("items." + key + ".skill-xp")); if (config.contains("items." + key + ".group")) loot.setGroup(config.getString("items." + key + ".group")); if (config.contains("items." + key + ".show-in-fishfinder")){ @@ -336,7 +417,11 @@ public class ConfigReader{ loot.setRequirements(requirements); } LOOT.put(key, loot); - LOOTITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(loot), "loot", key)); + if (loot.getMaterial().equalsIgnoreCase("AIR")){ + LOOTITEM.put(key, new ItemStack(Material.AIR)); + }else { + LOOTITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(loot), "loot", key)); + } }); if (config.contains("mobs") && Config.mm){ @@ -409,6 +494,8 @@ public class ConfigReader{ loot.setCommands(config.getStringList("mobs." + key + ".action.command")); if (config.contains("mobs." + key + ".action.exp")) loot.setExp(config.getInt("mobs." + key + ".action.exp")); + if (config.contains("mobs." + key + ".skill-xp")) + loot.setSkillXP(config.getDouble("mobs." + key + ".skill-xp")); if (config.contains("mobs." + key + ".layout")) loot.setLayout(config.getString("mobs." + key + "layout")); if (config.contains("mobs." + key + ".group")) @@ -418,6 +505,7 @@ public class ConfigReader{ }else { loot.setShowInFinder(true); } + loot.setPoint((float) config.getDouble("mobs." + key + ".score")); /* 设置捕获条件 */ @@ -675,4 +763,38 @@ public class ConfigReader{ AdventureManager.consoleMessage("[CustomFishing] " + keys.size() + " baits loaded!"); } } + + public static void loadCompetitions(){ + Competitions.clear(); + CompetitionsCommand.clear(); + YamlConfiguration config = getConfig("competition.yml"); + Set keys = config.getConfigurationSection("").getKeys(false); + keys.forEach(key -> { + CompetitionConfig competitionConfig; + if (config.getBoolean(key + ".bossbar.enable", true)){ + competitionConfig = new CompetitionConfig(true); + BossBarConfig bossBarConfig = new BossBarConfig( + config.getString(key + ".bossbar.text"), + BossBar.Overlay.valueOf(config.getString(key + ".bossbar.overlay")), + BossBar.Color.valueOf(config.getString(key + ".bossbar.color")), + config.getInt(key + ".bossbar.refresh-rate") + ); + competitionConfig.setBossBarConfig(bossBarConfig); + }else { + competitionConfig = new CompetitionConfig(false); + } + competitionConfig.setDuration(config.getInt(key + ".duration",600)); + competitionConfig.setGoal(Goal.valueOf(config.getString(key + ".goal", "RANDOM"))); + if (config.contains(key + ".broadcast.start")){ + competitionConfig.setStartMessage(config.getStringList(key + ".broadcast.start")); + } + if (config.contains(key + ".broadcast.end")){ + competitionConfig.setEndMessage(config.getStringList(key + ".broadcast.end")); + } + config.getStringList(key + ".start-time").forEach(time -> { + Competitions.put(time, competitionConfig); + }); + CompetitionsCommand.put(key, competitionConfig); + }); + } } diff --git a/src/main/java/net/momirealms/customfishing/CustomFishing.java b/src/main/java/net/momirealms/customfishing/CustomFishing.java index a2644761..58bfe512 100644 --- a/src/main/java/net/momirealms/customfishing/CustomFishing.java +++ b/src/main/java/net/momirealms/customfishing/CustomFishing.java @@ -1,11 +1,32 @@ +/* + * 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; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.momirealms.customfishing.command.Execute; import net.momirealms.customfishing.command.TabComplete; +import net.momirealms.customfishing.competition.CompetitionSchedule; +import net.momirealms.customfishing.competition.bossbar.BossBarManager; import net.momirealms.customfishing.listener.PlayerListener; +import net.momirealms.customfishing.utils.AdventureManager; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import org.checkerframework.checker.units.qual.C; import java.util.Objects; @@ -13,6 +34,7 @@ public final class CustomFishing extends JavaPlugin { public static JavaPlugin instance; public static BukkitAudiences adventure; + private CompetitionSchedule competitionSchedule; @Override public void onEnable() { @@ -23,14 +45,26 @@ public final class CustomFishing extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new PlayerListener(),this); AdventureManager.consoleMessage("[CustomFishing] Running on " + Bukkit.getVersion()); ConfigReader.Reload(); + if (ConfigReader.Config.competition){ + competitionSchedule = new CompetitionSchedule(); + competitionSchedule.checkTime(); + Bukkit.getPluginManager().registerEvents(new BossBarManager(), this); + } AdventureManager.consoleMessage("[CustomFishing] Plugin Enabled!"); } @Override public void onDisable() { - if(adventure != null) { + if (competitionSchedule != null){ + competitionSchedule.stopCheck(); + competitionSchedule = null; + } + if (adventure != null) { adventure.close(); adventure = null; } + if (instance != null){ + instance = null; + } } } diff --git a/src/main/java/net/momirealms/customfishing/api/PlayerFishSuccessEvent.java b/src/main/java/net/momirealms/customfishing/api/PlayerFishSuccessEvent.java new file mode 100644 index 00000000..58217695 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/api/PlayerFishSuccessEvent.java @@ -0,0 +1,4 @@ +package net.momirealms.customfishing.api; + +public class PlayerFishSuccessEvent { +} diff --git a/src/main/java/net/momirealms/customfishing/bar/Difficulty.java b/src/main/java/net/momirealms/customfishing/bar/Difficulty.java index 3b8d9d7e..34b7e79f 100644 --- a/src/main/java/net/momirealms/customfishing/bar/Difficulty.java +++ b/src/main/java/net/momirealms/customfishing/bar/Difficulty.java @@ -1,4 +1,4 @@ -package net.momirealms.customfishing.bar; +package net.momirealms.customfishing.titlebar; public record Difficulty(int timer, int speed) { diff --git a/src/main/java/net/momirealms/customfishing/bar/FishingPlayer.java b/src/main/java/net/momirealms/customfishing/bar/FishingPlayer.java index 49275bf9..d4184af0 100644 --- a/src/main/java/net/momirealms/customfishing/bar/FishingPlayer.java +++ b/src/main/java/net/momirealms/customfishing/bar/FishingPlayer.java @@ -1,4 +1,4 @@ -package net.momirealms.customfishing.bar; +package net.momirealms.customfishing.titlebar; import net.momirealms.customfishing.timer.Timer; diff --git a/src/main/java/net/momirealms/customfishing/bar/Layout.java b/src/main/java/net/momirealms/customfishing/bar/Layout.java index e6ce4b5f..066dee52 100644 --- a/src/main/java/net/momirealms/customfishing/bar/Layout.java +++ b/src/main/java/net/momirealms/customfishing/bar/Layout.java @@ -1,4 +1,4 @@ -package net.momirealms.customfishing.bar; +package net.momirealms.customfishing.titlebar; public class Layout { diff --git a/src/main/java/net/momirealms/customfishing/command/Execute.java b/src/main/java/net/momirealms/customfishing/command/Execute.java index 1fda2bca..7e15bf62 100644 --- a/src/main/java/net/momirealms/customfishing/command/Execute.java +++ b/src/main/java/net/momirealms/customfishing/command/Execute.java @@ -1,11 +1,9 @@ package net.momirealms.customfishing.command; -import net.momirealms.customfishing.AdventureManager; +import net.momirealms.customfishing.competition.CompetitionSchedule; +import net.momirealms.customfishing.item.*; +import net.momirealms.customfishing.utils.AdventureManager; import net.momirealms.customfishing.ConfigReader; -import net.momirealms.customfishing.item.Bait; -import net.momirealms.customfishing.item.Loot; -import net.momirealms.customfishing.item.Rod; -import net.momirealms.customfishing.item.Util; import net.momirealms.customfishing.utils.SaveItem; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -51,6 +49,32 @@ public class Execute implements CommandExecutor { return true; } + if (args[0].equalsIgnoreCase("competition")) { + //检验参数长度 [0]competition [1]start/end [2]key + if (args.length < 2){ + lackArgs(sender); + return true; + } + if (args[1].equalsIgnoreCase("start")){ + if (args.length < 3){ + lackArgs(sender); + return true; + } + if (CompetitionSchedule.startCompetition(args[2])){ + forceSuccess(sender); + }else { + forceFailure(sender); + } + }else if (args[1].equalsIgnoreCase("end")){ + CompetitionSchedule.endCompetition(); + forceEnd(sender); + }else if (args[1].equalsIgnoreCase("cancel")){ + CompetitionSchedule.cancelCompetition(); + forceCancel(sender); + } + return true; + } + if (args[0].equalsIgnoreCase("items")) { if (args.length < 4){ lackArgs(sender); @@ -66,14 +90,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 4){ - Loot.givePlayerLoot(player, args[3], 1); + ItemGive.givePlayerLoot(player, args[3], 1); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - Loot.givePlayerLoot(player, args[3], Integer.parseInt(args[4])); + ItemGive.givePlayerLoot(player, args[3], Integer.parseInt(args[4])); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { @@ -99,14 +123,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 5){ - Loot.givePlayerLoot(player, args[4], 1); + ItemGive.givePlayerLoot(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - Loot.givePlayerLoot(player, args[4], Integer.parseInt(args[5])); + ItemGive.givePlayerLoot(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -125,14 +149,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 4){ - Util.givePlayerUtil(player, args[3], 1); + ItemGive.givePlayerUtil(player, args[3], 1); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - Util.givePlayerUtil(player, args[3], Integer.parseInt(args[4])); + ItemGive.givePlayerUtil(player, args[3], Integer.parseInt(args[4])); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { @@ -158,14 +182,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 5){ - Util.givePlayerUtil(player, args[4], 1); + ItemGive.givePlayerUtil(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - Util.givePlayerUtil(player, args[4], Integer.parseInt(args[5])); + ItemGive.givePlayerUtil(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -181,14 +205,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 4){ - Rod.givePlayerRod(player, args[3], 1); + ItemGive.givePlayerRod(player, args[3], 1); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - Rod.givePlayerRod(player, args[3], Integer.parseInt(args[4])); + ItemGive.givePlayerRod(player, args[3], Integer.parseInt(args[4])); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { @@ -214,14 +238,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 5){ - Rod.givePlayerRod(player, args[4], 1); + ItemGive.givePlayerRod(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - Rod.givePlayerRod(player, args[4], Integer.parseInt(args[5])); + ItemGive.givePlayerRod(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -237,14 +261,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 4){ - Bait.givePlayerBait(player, args[3], 1); + ItemGive.givePlayerBait(player, args[3], 1); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - Bait.givePlayerBait(player, args[3], Integer.parseInt(args[4])); + ItemGive.givePlayerBait(player, args[3], Integer.parseInt(args[4])); AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { @@ -270,14 +294,14 @@ public class Execute implements CommandExecutor { return true; } if (args.length == 5){ - Bait.givePlayerBait(player, args[4], 1); + ItemGive.givePlayerBait(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - Bait.givePlayerBait(player, args[4], Integer.parseInt(args[5])); + ItemGive.givePlayerBait(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -328,4 +352,36 @@ public class Execute implements CommandExecutor { AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount); } } + + private void forceSuccess(CommandSender sender){ + if (sender instanceof Player){ + AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess); + }else { + AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess); + } + } + + private void forceFailure(CommandSender sender){ + if (sender instanceof Player){ + AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceFailure); + }else { + AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceFailure); + } + } + + private void forceEnd(CommandSender sender){ + if (sender instanceof Player){ + AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceEnd); + }else { + AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceEnd); + } + } + + private void forceCancel(CommandSender sender){ + if (sender instanceof Player){ + AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceCancel); + }else { + AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceCancel); + } + } } diff --git a/src/main/java/net/momirealms/customfishing/command/TabComplete.java b/src/main/java/net/momirealms/customfishing/command/TabComplete.java index 7cb77ad3..1ea225b8 100644 --- a/src/main/java/net/momirealms/customfishing/command/TabComplete.java +++ b/src/main/java/net/momirealms/customfishing/command/TabComplete.java @@ -20,7 +20,7 @@ public class TabComplete implements TabCompleter { return null; } if (args.length == 1){ - return Arrays.asList("reload","items","export"); + return Arrays.asList("competition","reload","items","export"); } if (args.length == 2){ if (args[0].equalsIgnoreCase("items")){ @@ -29,6 +29,9 @@ public class TabComplete implements TabCompleter { if (args[0].equalsIgnoreCase("export")){ return List.of("FileName"); } + if (args[0].equalsIgnoreCase("competition")){ + return List.of("start","end","cancel"); + } } if (args.length == 3){ if (args[0].equalsIgnoreCase("items")){ @@ -36,6 +39,11 @@ public class TabComplete implements TabCompleter { return Arrays.asList("get","give"); } } + if (args[0].equalsIgnoreCase("competition")){ + if (args[1].equalsIgnoreCase("start")){ + return competitions(); + } + } } if (args.length == 4){ if (args[0].equalsIgnoreCase("items")){ @@ -113,4 +121,7 @@ public class TabComplete implements TabCompleter { private List baits() { return new ArrayList<>(ConfigReader.BAIT.keySet()); } + private List competitions() { + return new ArrayList<>(ConfigReader.CompetitionsCommand.keySet()); + } } diff --git a/src/main/java/net/momirealms/customfishing/competition/Competition.java b/src/main/java/net/momirealms/customfishing/competition/Competition.java new file mode 100644 index 00000000..fd671eaf --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/Competition.java @@ -0,0 +1,175 @@ +/* + * 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.competition; + +import net.momirealms.customfishing.ConfigReader; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.competition.bossbar.BossBarConfig; +import net.momirealms.customfishing.competition.bossbar.BossBarManager; +import net.momirealms.customfishing.item.Loot; +import net.momirealms.customfishing.utils.AdventureManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import java.time.Instant; +import java.util.*; + +public class Competition { + + private Goal goal; + private final long duration; + private long startTime; + private final int minPlayers; + private boolean status; + private BukkitTask timerTask; + private Ranking ranking; + private final BossBarConfig bossBarConfig; + private final List startMessage; + private final List endMessage; + + public static long remainingTime; + public static float progress; + public static CompetitionPlayer emptyPlayer = new CompetitionPlayer("XiaoMoMi",0); + + public Competition(CompetitionConfig competitionConfig) { + this.duration = competitionConfig.getDuration(); + this.goal = competitionConfig.getGoal(); + this.minPlayers = competitionConfig.getMinPlayers(); + this.bossBarConfig = competitionConfig.getBossBarConfig(); + this.startMessage = competitionConfig.getStartMessage(); + this.endMessage = competitionConfig.getEndMessage(); + } + + public void begin(boolean forceStart) { + + if (goal == Goal.RANDOM) { + goal = getRandomGoal(); + } + + remainingTime = this.duration; + this.startTime = Instant.now().getEpochSecond(); + + Collection playerCollections = Bukkit.getOnlinePlayers(); + if (playerCollections.size() >= minPlayers || forceStart) { + status = true; + ranking = new Ranking(); + startTimer(); + if (startMessage != null){ + playerCollections.forEach(player -> { + startMessage.forEach(message -> { + AdventureManager.playerMessage(player, message); + }); + }); + } + } + else { + playerCollections.forEach(player -> { + AdventureManager.playerMessage(player, ConfigReader.Message.notEnoughPlayers); + }); + } + } + + private void startTimer() { + this.timerTask = new BukkitRunnable() { + @Override + public void run() { + if (decreaseTime()){ + end(); + } + } + }.runTaskTimer(CustomFishing.instance, 0, 20); + } + + private boolean decreaseTime() { + + long tVac; + long current = Instant.now().getEpochSecond(); + + progress = (float) remainingTime / duration; + + remainingTime = duration - (current - startTime); + if ((tVac = (current - startTime) + 1) != duration - remainingTime) { + for (long i = duration - remainingTime; i < tVac; i++) { + if (remainingTime <= 0) return true; + remainingTime--; + } + } + return false; + } + + public void end() { + BossBarManager.stopAllTimer(); + this.timerTask.cancel(); + status = false; + if (endMessage != null){ + List newMessage = new ArrayList<>(); + endMessage.forEach(message -> { + float first = ranking.getScoreAt(1); + float second = ranking.getScoreAt(2); + float third = ranking.getScoreAt(3); + newMessage.add(message + .replace("{1st}", Optional.ofNullable(ranking.getPlayerAt(1)).orElse(ConfigReader.Message.noPlayer)) + .replace("{2nd}", Optional.ofNullable(ranking.getPlayerAt(2)).orElse(ConfigReader.Message.noPlayer)) + .replace("{3rd}", Optional.ofNullable(ranking.getPlayerAt(3)).orElse(ConfigReader.Message.noPlayer)) + .replace("{1st_points}", first < 0 ? ConfigReader.Message.noScore : String.format("%.1f",(first))) + .replace("{2nd_points}", second < 0 ? ConfigReader.Message.noScore : String.format("%.1f",(second))) + .replace("{3rd_points}", third < 0 ? ConfigReader.Message.noScore : String.format("%.1f",(third)))); + }); + Bukkit.getOnlinePlayers().forEach(player -> { + newMessage.forEach(message -> { + AdventureManager.playerMessage(player, message); + }); + }); + } + ranking.clear(); + } + + public void cancel() { + ranking.clear(); + BossBarManager.stopAllTimer(); + this.timerTask.cancel(); + status = false; + } + + public void refreshRanking(String player, Loot loot) { + CompetitionPlayer competitionPlayer = ranking.getCompetitionPlayer(player); + float score; + if (this.goal == Goal.TOTAL_POINTS) score = loot.getPoint(); + else score = 1.0f; + if (competitionPlayer != null) { + ranking.removePlayer(competitionPlayer); + competitionPlayer.addScore(score); + ranking.addPlayer(competitionPlayer); + } else { + ranking.addPlayer(player, score); + } + } + + private Goal getRandomGoal() { + int goal = new Random().nextInt(Goal.values().length-1); + return Goal.values()[goal]; + } + + public long getDuration() {return duration;} + public long getRemainingTime() {return remainingTime;} + public boolean isGoingOn() {return status;} + public BossBarConfig getBossBarConfig() {return bossBarConfig;} + public Ranking getRanking() {return ranking;} +} diff --git a/src/main/java/net/momirealms/customfishing/competition/CompetitionConfig.java b/src/main/java/net/momirealms/customfishing/competition/CompetitionConfig.java new file mode 100644 index 00000000..a7d424da --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/CompetitionConfig.java @@ -0,0 +1,49 @@ +/* + * 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.competition; + +import net.momirealms.customfishing.competition.bossbar.BossBarConfig; + +import java.util.List; + +public class CompetitionConfig { + + private int duration; + private int minPlayers; + private List startMessage; + private List endMessage; + private Goal goal; + private BossBarConfig bossBarConfig; + private final boolean enableBossBar; + + public CompetitionConfig(boolean enableBossBar){this.enableBossBar = enableBossBar;} + + public void setDuration(int duration) {this.duration = duration;} + public void setBossBarConfig(BossBarConfig bossBarConfig) {this.bossBarConfig = bossBarConfig;} + public void setGoal(Goal goal) {this.goal = goal;} + public void setEndMessage(List endMessage) {this.endMessage = endMessage;} + public void setStartMessage(List startMessage) {this.startMessage = startMessage;} + + public Goal getGoal() {return goal;} + public int getMinPlayers() {return minPlayers;} + public int getDuration() {return duration;} + public BossBarConfig getBossBarConfig() {return bossBarConfig;} + public boolean isEnableBossBar() {return enableBossBar;} + public List getEndMessage() {return endMessage;} + public List getStartMessage() {return startMessage;} +} diff --git a/src/main/java/net/momirealms/customfishing/competition/CompetitionPlayer.java b/src/main/java/net/momirealms/customfishing/competition/CompetitionPlayer.java new file mode 100644 index 00000000..ee611f5b --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/CompetitionPlayer.java @@ -0,0 +1,60 @@ +/* + * 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.competition; + +import org.jetbrains.annotations.NotNull; + +public class CompetitionPlayer implements Comparable{ + + private long time; + private final String player; + private float score; + + public CompetitionPlayer(String player, float score) { + this.player = player; + this.score = score; + this.time = System.currentTimeMillis(); + } + + public void addScore(float score){ + this.score += score; + this.time = System.currentTimeMillis(); + } + + public float getScore() { + return this.score; + } + + public String getPlayer(){ + return this.player; + } + + @Override + public int compareTo(@NotNull CompetitionPlayer competitionPlayer) { + if (competitionPlayer.getScore() != this.score) { + return (competitionPlayer.getScore() > this.score) ? 1 : -1; + } else { + return (competitionPlayer.getScore() > this.time) ? 1 : -1; + } + } + + @Override + public String toString() { + return "CompetitionPlayer[player=" + this.player + ", score=" + this.score + ", catch-time=" + this.time + "]"; + } +} diff --git a/src/main/java/net/momirealms/customfishing/competition/CompetitionSchedule.java b/src/main/java/net/momirealms/customfishing/competition/CompetitionSchedule.java new file mode 100644 index 00000000..557341bb --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/CompetitionSchedule.java @@ -0,0 +1,103 @@ +/* + * 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.competition; + +import net.momirealms.customfishing.ConfigReader; +import net.momirealms.customfishing.CustomFishing; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import java.time.LocalTime; + +public class CompetitionSchedule { + + public static Competition competition; + public static boolean hasBossBar; + private int doubleCheckTime; + private int checkTaskID; + + public CompetitionSchedule(){ + hasBossBar = false; + } + + public static boolean startCompetition(String competitionName){ + CompetitionConfig competitionConfig = ConfigReader.CompetitionsCommand.get(competitionName); + if (competitionConfig == null) return false; + if (competition != null){ + competition.end(); + } + competition = new Competition(competitionConfig); + competition.begin(true); + hasBossBar = competitionConfig.isEnableBossBar(); + return true; + } + + public static void endCompetition(){ + if (competition != null){ + competition.end(); + } + } + + public static void cancelCompetition(){ + if (competition != null){ + competition.cancel(); + } + } + + public void startCompetition(CompetitionConfig competitionConfig){ + if (competition != null){ + competition.end(); + } + competition = new Competition(competitionConfig); + competition.begin(false); + hasBossBar = competitionConfig.isEnableBossBar(); + } + + public void checkTime() { + BukkitTask checkTimeTask = new BukkitRunnable(){ + public void run(){ + if (isANewMinute()){ + CompetitionConfig competitionConfig = ConfigReader.Competitions.get(getCurrentTime()); + if (competitionConfig != null){ + startCompetition(competitionConfig); + } + } + } + }.runTaskTimer(CustomFishing.instance, (60- LocalTime.now().getSecond())*20, 1200); + checkTaskID = checkTimeTask.getTaskId(); + } + + public void stopCheck(){ + Bukkit.getScheduler().cancelTask(checkTaskID); + } + + public String getCurrentTime() { + return LocalTime.now().getHour() + ":" + String.format("%02d", LocalTime.now().getMinute()); + } + + private boolean isANewMinute() { + int minute = LocalTime.now().getMinute(); + if (doubleCheckTime != minute) { + doubleCheckTime = minute; + return true; + }else { + return false; + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/competition/Goal.java b/src/main/java/net/momirealms/customfishing/competition/Goal.java new file mode 100644 index 00000000..ae52de4f --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/Goal.java @@ -0,0 +1,26 @@ +/* + * 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.competition; + +public enum Goal { + + TOTAL_POINTS, + CATCH_AMOUNT, + RANDOM + +} diff --git a/src/main/java/net/momirealms/customfishing/competition/Ranking.java b/src/main/java/net/momirealms/customfishing/competition/Ranking.java new file mode 100644 index 00000000..b0c84a25 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/Ranking.java @@ -0,0 +1,93 @@ +/* + * 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.competition; + +import java.util.TreeSet; + +public class Ranking { + + private final TreeSet competitionPlayers = new TreeSet<>(); + + public void addPlayer(String player, float score) { + CompetitionPlayer competitionPlayer = new CompetitionPlayer(player, score); + competitionPlayers.add(competitionPlayer); + } + + public void addPlayer(CompetitionPlayer competitionPlayer) { + competitionPlayers.add(competitionPlayer); + } + + public void removePlayer(CompetitionPlayer competitionPlayer) { + competitionPlayers.removeIf(e -> e == competitionPlayer); + } + + public void clear() { + competitionPlayers.clear(); + } + + public boolean contains(CompetitionPlayer competitionPlayer) { + return competitionPlayers.contains(competitionPlayer); + } + + public CompetitionPlayer getCompetitionPlayer(String player) { + for (CompetitionPlayer competitionPlayer : competitionPlayers) { + if (competitionPlayer.getPlayer().equals(player)) { + return competitionPlayer; + } + } + return null; + } + + public String getPlayerRank(String player) { + int index = 1; + for (CompetitionPlayer competitionPlayer : competitionPlayers) { + if (competitionPlayer.getPlayer().equals(player)) { + return String.valueOf(index); + }else { + index++; + } + } + return null; + } + + public CompetitionPlayer getFirst() { + return competitionPlayers.first(); + } + + public String getPlayerAt(int i) { + int count = 1; + for (CompetitionPlayer competitionPlayer : competitionPlayers) { + if (count == i) { + return competitionPlayer.getPlayer(); + } + count++; + } + return null; + } + + public float getScoreAt(int i) { + int count = 1; + for (CompetitionPlayer competitionPlayer : competitionPlayers) { + if (count == i) { + return competitionPlayer.getScore(); + } + count++; + } + return -1.0f; + } +} diff --git a/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarConfig.java b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarConfig.java new file mode 100644 index 00000000..c2e2442e --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarConfig.java @@ -0,0 +1,29 @@ +/* + * 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.competition.bossbar; + +import net.kyori.adventure.bossbar.BossBar; + +public record BossBarConfig(String text, BossBar.Overlay overlay, + BossBar.Color color, int rate) { + + public BossBar.Color getColor() {return color;} + public int getRate() {return rate;} + public BossBar.Overlay getOverlay() {return overlay;} + public String getText() {return text;} +} diff --git a/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarManager.java b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarManager.java new file mode 100644 index 00000000..645aa9ef --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarManager.java @@ -0,0 +1,71 @@ +/* + * 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.competition.bossbar; + +import net.momirealms.customfishing.ConfigReader; +import net.momirealms.customfishing.competition.CompetitionSchedule; +import net.momirealms.customfishing.utils.AdventureManager; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; + +public class BossBarManager implements Listener { + + public static HashMap cache = new HashMap<>(); + + @EventHandler + public void onJoin(PlayerJoinEvent event){ + Player player = event.getPlayer(); + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()){ + if (CompetitionSchedule.competition.getRanking().getCompetitionPlayer(player.getName()) != null && cache.get(player) == null){ + BossBarTimer timerTask = new BossBarTimer(player, CompetitionSchedule.competition.getBossBarConfig()); + cache.put(player, timerTask); + }else { + AdventureManager.playerMessage(player, ConfigReader.Message.competitionOn); + } + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent event){ + Player player = event.getPlayer(); + BossBarTimer timerTask = cache.get(player); + if (timerTask != null){ + timerTask.stopTimer(); + cache.remove(player); + } + } + + public static void stopAllTimer(){ + cache.forEach(((player, timerTask) -> { + timerTask.stopTimer(); + })); + cache.clear(); + } + + public static void joinCompetition(Player player){ + if (cache.get(player) == null){ + BossBarTimer timerTask = new BossBarTimer(player, CompetitionSchedule.competition.getBossBarConfig()); + cache.put(player, timerTask); + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarSender.java b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarSender.java new file mode 100644 index 00000000..b8d95df2 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarSender.java @@ -0,0 +1,96 @@ +/* + * 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.competition.bossbar; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.momirealms.customfishing.ConfigReader; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.competition.Competition; +import net.momirealms.customfishing.competition.CompetitionSchedule; +import net.momirealms.customfishing.hook.PapiHook; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.Optional; + +public class BossBarSender extends BukkitRunnable { + + private final Player player; + private final Audience audience; + private BossBar bossBar; + private int timer; + private final BossBarConfig bossbarConfig; + private final BossBar.Color color; + private final BossBar.Overlay overlay; + + public BossBarSender(Player player, BossBarConfig bossbarConfig){ + this.player = player; + this.bossbarConfig = bossbarConfig; + this.audience = CustomFishing.adventure.player(player); + this.timer = 0; + this.color = bossbarConfig.getColor(); + this.overlay = bossbarConfig.getOverlay(); + } + + public void hideBossbar(){ + audience.hideBossBar(bossBar); + } + + public void showBossbar(){ + String text; + if (ConfigReader.Config.papi){ + text = PapiHook.parse(player, bossbarConfig.getText()); + }else { + text = bossbarConfig.getText(); + } + bossBar = BossBar.bossBar( + MiniMessage.miniMessage().deserialize(text.replace("{time}", String.valueOf(Competition.remainingTime)) + .replace("{rank}", Optional.ofNullable(CompetitionSchedule.competition.getRanking().getPlayerRank(player.getName())).orElse(ConfigReader.Message.noRank)) + .replace("{minute}", String.format("%02d",Competition.remainingTime/60)) + .replace("{second}",String.format("%02d",Competition.remainingTime%60)) + .replace("{point}", String.format("%.1f",Optional.ofNullable(CompetitionSchedule.competition.getRanking().getCompetitionPlayer(player.getName())).orElse(Competition.emptyPlayer).getScore()))), + Competition.progress, + color, + overlay); + audience.showBossBar(bossBar); + } + + @Override + public void run() { + if (timer < bossbarConfig.getRate()){ + timer++; + }else { + String text; + if (ConfigReader.Config.papi){ + text = PapiHook.parse(player, bossbarConfig.getText()); + }else { + text = bossbarConfig.getText(); + } + bossBar.name( + MiniMessage.miniMessage().deserialize(text.replace("{time}", String.valueOf(Competition.remainingTime)) + .replace("{rank}", Optional.ofNullable(CompetitionSchedule.competition.getRanking().getPlayerRank(player.getName())).orElse(ConfigReader.Message.noRank)) + .replace("{minute}", String.format("%02d",Competition.remainingTime/60)) + .replace("{second}",String.format("%02d",Competition.remainingTime%60)) + .replace("{point}", String.format("%.1f",Optional.ofNullable(CompetitionSchedule.competition.getRanking().getCompetitionPlayer(player.getName())).orElse(Competition.emptyPlayer).getScore())))); + bossBar.progress(Competition.progress); + timer = 0; + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarTimer.java b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarTimer.java new file mode 100644 index 00000000..361f16a4 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarTimer.java @@ -0,0 +1,47 @@ +/* + * 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.competition.bossbar; + +import net.momirealms.customfishing.CustomFishing; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashMap; + +public class BossBarTimer { + + public HashMap bossbarCache = new HashMap<>(); + + public BossBarTimer(Player player, BossBarConfig bossBarConfig){ + + BossBarSender bossbar = new BossBarSender(player, bossBarConfig); + bossbar.showBossbar(); + BukkitTask task = bossbar.runTaskTimerAsynchronously(CustomFishing.instance, 0,1); + bossbarCache.put(task.getTaskId(), bossbar); + + } + + public void stopTimer(){ + bossbarCache.forEach((key,value)-> { + value.hideBossbar(); + Bukkit.getScheduler().cancelTask(key); + }); + bossbarCache = null; + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/competition/reward/Command.java b/src/main/java/net/momirealms/customfishing/competition/reward/Command.java new file mode 100644 index 00000000..dd2a9c40 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/reward/Command.java @@ -0,0 +1,39 @@ +/* + * 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.competition.reward; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; + +public class Command implements Reward{ + + private final List commands; + + public Command(List commands){ + this.commands = commands; + } + + @Override + public void giveReward(Player player) { + commands.forEach(command -> { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName())); + }); + } +} diff --git a/src/main/java/net/momirealms/customfishing/competition/reward/Message.java b/src/main/java/net/momirealms/customfishing/competition/reward/Message.java new file mode 100644 index 00000000..d771ad0b --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/reward/Message.java @@ -0,0 +1,40 @@ +/* + * 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.competition.reward; + +import net.momirealms.customfishing.utils.AdventureManager; +import org.bukkit.entity.Player; + +import java.util.List; + +public class Message implements Reward{ + + private final List messages; + + public Message(List messages){ + this.messages = messages; + } + + @Override + public void giveReward(Player player) { + if (!player.isOnline()) return; + messages.forEach(message -> { + AdventureManager.playerMessage(player, message); + }); + } +} diff --git a/src/main/java/net/momirealms/customfishing/competition/reward/Reward.java b/src/main/java/net/momirealms/customfishing/competition/reward/Reward.java new file mode 100644 index 00000000..836b725b --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/competition/reward/Reward.java @@ -0,0 +1,24 @@ +/* + * 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.competition.reward; + +import org.bukkit.entity.Player; + +public interface Reward { + void giveReward(Player player); +} diff --git a/src/main/java/net/momirealms/customfishing/hook/MythicMobsUtils.java b/src/main/java/net/momirealms/customfishing/hook/MythicMobsUtils.java new file mode 100644 index 00000000..d4165a3e --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/MythicMobsUtils.java @@ -0,0 +1,53 @@ +/* + * 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.hook; + +import io.lumine.mythic.api.adapters.AbstractLocation; +import io.lumine.mythic.api.adapters.AbstractVector; +import io.lumine.mythic.api.mobs.MobManager; +import io.lumine.mythic.api.mobs.MythicMob; +import io.lumine.mythic.bukkit.MythicBukkit; +import io.lumine.mythic.bukkit.utils.serialize.Position; +import io.lumine.mythic.core.mobs.ActiveMob; +import net.momirealms.customfishing.item.Loot; +import net.momirealms.customfishing.utils.VectorUtil; +import org.bukkit.Location; +import org.bukkit.util.Vector; + +import java.util.Optional; + +public class MythicMobsUtils { + + public static void summonMM(Location pLocation, Location bLocation, Loot loot){ + MobManager mobManager = MythicBukkit.inst().getMobManager(); + Optional mythicMob = mobManager.getMythicMob(loot.getMm()); + if (mythicMob.isPresent()) { + //获取MM怪实例 + MythicMob theMob = mythicMob.get(); + //生成MM怪 + Position position = Position.of(bLocation); + AbstractLocation abstractLocation = new AbstractLocation(position); + ActiveMob activeMob = theMob.spawn(abstractLocation, loot.getMmLevel()); + + VectorUtil vectorUtil = loot.getVectorUtil(); + Vector vector = pLocation.subtract(bLocation).toVector().multiply((vectorUtil.getHorizontal())-1); + vector = vector.setY((vector.getY()+0.2)*vectorUtil.getVertical()); + activeMob.getEntity().setVelocity(new AbstractVector(vector.getX(),vector.getY(),vector.getZ())); + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/PapiHook.java b/src/main/java/net/momirealms/customfishing/hook/PapiHook.java new file mode 100644 index 00000000..85cdcab1 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/PapiHook.java @@ -0,0 +1,10 @@ +package net.momirealms.customfishing.hook; + +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.entity.Player; + +public class PapiHook { + public static String parse(Player player, String text){ + return PlaceholderAPI.setPlaceholders(player, text); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/Placeholders.java b/src/main/java/net/momirealms/customfishing/hook/Placeholders.java new file mode 100644 index 00000000..eb69d9e2 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/Placeholders.java @@ -0,0 +1,21 @@ +/* + * 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.hook; + +public class Placeholders { +} diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/Aurelium.java b/src/main/java/net/momirealms/customfishing/hook/skill/Aurelium.java new file mode 100644 index 00000000..d05156e2 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/skill/Aurelium.java @@ -0,0 +1,17 @@ +package net.momirealms.customfishing.hook.skill; + +import com.archyx.aureliumskills.api.AureliumAPI; +import com.archyx.aureliumskills.leveler.Leveler; +import com.archyx.aureliumskills.skills.Skill; +import org.bukkit.entity.Player; + +public class Aurelium implements SkillXP{ + + private static final Leveler leveler = AureliumAPI.getPlugin().getLeveler(); + private static final Skill skill = AureliumAPI.getPlugin().getSkillRegistry().getSkill("fishing"); + + @Override + public void addXp(Player player, double amount) { + leveler.addXp(player, skill, amount); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/MMOCore.java b/src/main/java/net/momirealms/customfishing/hook/skill/MMOCore.java new file mode 100644 index 00000000..c70e8361 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/skill/MMOCore.java @@ -0,0 +1,14 @@ +package net.momirealms.customfishing.hook.skill; + +import net.Indyuce.mmocore.experience.EXPSource; +import net.Indyuce.mmocore.experience.Profession; +import org.bukkit.entity.Player; + +public class MMOCore implements SkillXP{ + + @Override + public void addXp(Player player, double amount) { + Profession profession = net.Indyuce.mmocore.MMOCore.plugin.professionManager.get("fishing"); + profession.giveExperience(net.Indyuce.mmocore.MMOCore.plugin.dataProvider.getDataManager().get(player), amount, null , EXPSource.OTHER); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/SkillXP.java b/src/main/java/net/momirealms/customfishing/hook/skill/SkillXP.java new file mode 100644 index 00000000..2449628f --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/skill/SkillXP.java @@ -0,0 +1,7 @@ +package net.momirealms.customfishing.hook.skill; + +import org.bukkit.entity.Player; + +public interface SkillXP { + void addXp(Player player, double amount); +} diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/mcMMO.java b/src/main/java/net/momirealms/customfishing/hook/skill/mcMMO.java new file mode 100644 index 00000000..26cc2349 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/skill/mcMMO.java @@ -0,0 +1,12 @@ +package net.momirealms.customfishing.hook.skill; + +import com.gmail.nossr50.api.ExperienceAPI; +import org.bukkit.entity.Player; + +public class mcMMO implements SkillXP{ + + @Override + public void addXp(Player player, double amount) { + ExperienceAPI.addXP(player, "Fishing", (int) amount, "UNKNOWN"); + } +} diff --git a/src/main/java/net/momirealms/customfishing/item/Bait.java b/src/main/java/net/momirealms/customfishing/item/Bait.java index d730950e..cb639fab 100644 --- a/src/main/java/net/momirealms/customfishing/item/Bait.java +++ b/src/main/java/net/momirealms/customfishing/item/Bait.java @@ -1,9 +1,23 @@ +/* + * 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.item; -import net.momirealms.customfishing.ConfigReader; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.List; @@ -29,12 +43,6 @@ public class Bait implements Item{ this.material = material; } - public static void givePlayerBait(Player player, String baitKey, int amount){ - ItemStack itemStack = ConfigReader.BAITITEM.get(baitKey); - if (itemStack == null) return; - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } public void setName(String name) {this.name = name;} public void setItemFlags(List itemFlags) {this.itemFlags = itemFlags;} diff --git a/src/main/java/net/momirealms/customfishing/item/Item.java b/src/main/java/net/momirealms/customfishing/item/Item.java index 5076a471..1d03c5ba 100644 --- a/src/main/java/net/momirealms/customfishing/item/Item.java +++ b/src/main/java/net/momirealms/customfishing/item/Item.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.item; import net.momirealms.customfishing.utils.Enchantment; diff --git a/src/main/java/net/momirealms/customfishing/item/ItemGive.java b/src/main/java/net/momirealms/customfishing/item/ItemGive.java new file mode 100644 index 00000000..d9e57f8e --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/item/ItemGive.java @@ -0,0 +1,52 @@ +/* + * 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.item; + +import net.momirealms.customfishing.ConfigReader; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class ItemGive { + + public static void givePlayerLoot(Player player, String lootKey, int amount){ + ItemStack itemStack = ConfigReader.LOOTITEM.get(lootKey); + if (itemStack == null) return; + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static void givePlayerRod(Player player, String rodKey, int amount){ + ItemStack itemStack = ConfigReader.RODITEM.get(rodKey); + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static void givePlayerBait(Player player, String baitKey, int amount){ + ItemStack itemStack = ConfigReader.BAITITEM.get(baitKey); + if (itemStack == null) return; + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static void givePlayerUtil(Player player, String utilKey, int amount){ + ItemStack itemStack = ConfigReader.UTILITEM.get(utilKey); + if (itemStack == null) return; + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } +} diff --git a/src/main/java/net/momirealms/customfishing/item/Loot.java b/src/main/java/net/momirealms/customfishing/item/Loot.java index 75ad730b..a9c20e4d 100644 --- a/src/main/java/net/momirealms/customfishing/item/Loot.java +++ b/src/main/java/net/momirealms/customfishing/item/Loot.java @@ -1,12 +1,26 @@ +/* + * 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.item; -import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.requirements.Requirement; -import net.momirealms.customfishing.bar.Difficulty; +import net.momirealms.customfishing.titlebar.Difficulty; import net.momirealms.customfishing.utils.VectorUtil; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; import java.util.*; @@ -35,6 +49,8 @@ public class Loot implements Item { private boolean showInFinder; private int custommodeldata; private boolean unbreakable; + private double skillXP; + private float point; public Loot(String key, Difficulty difficulty, int weight, int time){ this.key = key; @@ -58,6 +74,8 @@ public class Loot implements Item { public VectorUtil getVectorUtil(){ return this.vectorUtil; } public String getGroup() {return group;} public int getExp() {return exp;} + public double getSkillXP() {return skillXP;} + public float getPoint() {return point;} @Override public List getLore(){return this.lore;} @@ -95,11 +113,6 @@ public class Loot implements Item { public void setEnchantment(List enchantment) {this.enchantment = enchantment;} public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;} public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;} - - public static void givePlayerLoot(Player player, String lootKey, int amount){ - ItemStack itemStack = ConfigReader.LOOTITEM.get(lootKey); - if (itemStack == null) return; - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } + public void setSkillXP(double skillXP) {this.skillXP = skillXP;} + public void setPoint(float point) {this.point = point;} } diff --git a/src/main/java/net/momirealms/customfishing/item/Rod.java b/src/main/java/net/momirealms/customfishing/item/Rod.java index 53667325..a47c293e 100644 --- a/src/main/java/net/momirealms/customfishing/item/Rod.java +++ b/src/main/java/net/momirealms/customfishing/item/Rod.java @@ -1,10 +1,24 @@ +/* + * 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.item; -import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.utils.Enchantment; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.List; @@ -25,12 +39,6 @@ public class Rod implements Item{ private int custommodeldata; private boolean unbreakable; - public static void givePlayerRod(Player player, String rodKey, int amount){ - ItemStack itemStack = ConfigReader.RODITEM.get(rodKey); - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } - public void setDifficulty(int difficulty) {this.difficulty = difficulty;} public void setDoubleLoot(double doubleLoot) {this.doubleLoot = doubleLoot;} public void setNbt(Map nbt) {this.nbt = nbt;} diff --git a/src/main/java/net/momirealms/customfishing/item/Util.java b/src/main/java/net/momirealms/customfishing/item/Util.java index b1de9aab..cbe0ebde 100644 --- a/src/main/java/net/momirealms/customfishing/item/Util.java +++ b/src/main/java/net/momirealms/customfishing/item/Util.java @@ -1,10 +1,24 @@ +/* + * 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.item; -import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.utils.Enchantment; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; import java.util.List; import java.util.Map; @@ -24,13 +38,6 @@ public class Util implements Item{ this.material = material; } - public static void givePlayerUtil(Player player, String utilKey, int amount){ - ItemStack itemStack = ConfigReader.UTILITEM.get(utilKey); - if (itemStack == null) return; - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } - public void setLore(List lore){this.lore = lore;} public void setNbt(Map nbt){this.nbt = nbt;} public void setEnchantment(List enchantment) {this.enchantment = enchantment;} diff --git a/src/main/java/net/momirealms/customfishing/listener/PlayerListener.java b/src/main/java/net/momirealms/customfishing/listener/PlayerListener.java index e7631ffa..189ebf5c 100644 --- a/src/main/java/net/momirealms/customfishing/listener/PlayerListener.java +++ b/src/main/java/net/momirealms/customfishing/listener/PlayerListener.java @@ -1,20 +1,40 @@ +/* + * 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.listener; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; -import net.momirealms.customfishing.AdventureManager; +import net.momirealms.customfishing.competition.Competition; +import net.momirealms.customfishing.competition.CompetitionSchedule; +import net.momirealms.customfishing.competition.bossbar.BossBarManager; +import net.momirealms.customfishing.hook.MythicMobsUtils; +import net.momirealms.customfishing.utils.AdventureManager; import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.bar.Difficulty; -import net.momirealms.customfishing.bar.FishingPlayer; -import net.momirealms.customfishing.bar.Layout; +import net.momirealms.customfishing.titlebar.Difficulty; +import net.momirealms.customfishing.titlebar.FishingPlayer; +import net.momirealms.customfishing.titlebar.Layout; import net.momirealms.customfishing.item.Bait; import net.momirealms.customfishing.item.Loot; import net.momirealms.customfishing.item.Rod; import net.momirealms.customfishing.requirements.FishingCondition; import net.momirealms.customfishing.requirements.Requirement; -import net.momirealms.customfishing.timer.Timer; -import net.momirealms.customfishing.utils.*; +import net.momirealms.customfishing.titlebar.Timer; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -56,7 +76,7 @@ public class PlayerListener implements Listener { //设置冷却时间 long time = System.currentTimeMillis(); - if (time - (coolDown.getOrDefault(player, time - 1000)) < 1000) { + if (time - (coolDown.getOrDefault(player, time - 2000)) < 2000) { return; } coolDown.put(player, time); @@ -274,7 +294,7 @@ public class PlayerListener implements Listener { int last = (fishingPlayers.get(player).getTimer().getTimerTask().getProgress() + 1)/layout.getRange(); fishingPlayers.remove(player); player.removePotionEffect(PotionEffectType.SLOW); - if (!event.getHook().isInOpenWater()){ + if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){ AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater); return; } @@ -283,15 +303,18 @@ public class PlayerListener implements Listener { Location location = event.getHook().getLocation(); //钓上来的是MM怪吗 if (lootInstance.getMm() != null){ - MMUtil.summonMM(player.getLocation(), location, lootInstance); + MythicMobsUtils.summonMM(player.getLocation(), location, lootInstance); }else { - Entity item = location.getWorld().dropItem(location, ConfigReader.LOOTITEM.get(lootInstance.getKey())); - Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1); - vector = vector.setY((vector.getY()+0.2)*1.2); - item.setVelocity(vector); - if (willDouble.contains(player)){ - Entity item2 = location.getWorld().dropItem(location, ConfigReader.LOOTITEM.get(lootInstance.getKey())); - item2.setVelocity(vector); + ItemStack itemStack = ConfigReader.LOOTITEM.get(lootInstance.getKey()); + if (itemStack.getType() != Material.AIR) { + Entity item = location.getWorld().dropItem(location, itemStack); + Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1); + vector = vector.setY((vector.getY()+0.2)*1.2); + item.setVelocity(vector); + if (willDouble.contains(player)){ + Entity item2 = location.getWorld().dropItem(location, itemStack); + item2.setVelocity(vector); + } } } if (lootInstance.getMsg() != null){ @@ -315,6 +338,13 @@ public class PlayerListener implements Listener { player.giveExp(lootInstance.getExp(),true); player.getWorld().playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1); } + if (lootInstance.getSkillXP() != 0){ + ConfigReader.Config.skillXP.addXp(player, lootInstance.getSkillXP()); + } + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()){ + CompetitionSchedule.competition.refreshRanking(player.getName(), lootInstance); + BossBarManager.joinCompetition(player); + } //发送Title AdventureManager.playerTitle(player, ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_in, ConfigReader.Title.success_stay, ConfigReader.Title.success_out); }else { diff --git a/src/main/java/net/momirealms/customfishing/requirements/Biome.java b/src/main/java/net/momirealms/customfishing/requirements/Biome.java index a0244c43..252e9498 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Biome.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Biome.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; import java.util.List; diff --git a/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java b/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java index c9777f12..57686e32 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java +++ b/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; import org.bukkit.Location; diff --git a/src/main/java/net/momirealms/customfishing/requirements/Permission.java b/src/main/java/net/momirealms/customfishing/requirements/Permission.java index 7c55df17..8f31dd06 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Permission.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Permission.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; public record Permission(String permission) implements Requirement { diff --git a/src/main/java/net/momirealms/customfishing/requirements/Region.java b/src/main/java/net/momirealms/customfishing/requirements/Region.java index b350b742..76dc518a 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Region.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Region.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; import com.sk89q.worldedit.bukkit.BukkitAdapter; diff --git a/src/main/java/net/momirealms/customfishing/requirements/Requirement.java b/src/main/java/net/momirealms/customfishing/requirements/Requirement.java index bedda4f0..5d74eb63 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Requirement.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Requirement.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; public interface Requirement { diff --git a/src/main/java/net/momirealms/customfishing/requirements/Season.java b/src/main/java/net/momirealms/customfishing/requirements/Season.java index 5c5d6f29..270cf143 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Season.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Season.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; import me.clip.placeholderapi.PlaceholderAPI; diff --git a/src/main/java/net/momirealms/customfishing/requirements/Time.java b/src/main/java/net/momirealms/customfishing/requirements/Time.java index 5a7222d5..3d8d1a3a 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Time.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Time.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/net/momirealms/customfishing/requirements/Weather.java b/src/main/java/net/momirealms/customfishing/requirements/Weather.java index 9adaa148..cda9e0bc 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Weather.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Weather.java @@ -1,6 +1,23 @@ +/* + * 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.requirements; -import net.momirealms.customfishing.AdventureManager; +import net.momirealms.customfishing.utils.AdventureManager; import org.bukkit.World; import java.util.List; diff --git a/src/main/java/net/momirealms/customfishing/requirements/World.java b/src/main/java/net/momirealms/customfishing/requirements/World.java index 08a39e1a..3319b0b8 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/World.java +++ b/src/main/java/net/momirealms/customfishing/requirements/World.java @@ -1,6 +1,23 @@ +/* + * 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.requirements; -import net.momirealms.customfishing.AdventureManager; +import net.momirealms.customfishing.utils.AdventureManager; import java.util.List; diff --git a/src/main/java/net/momirealms/customfishing/requirements/YPos.java b/src/main/java/net/momirealms/customfishing/requirements/YPos.java index d7e6afe1..2747e02b 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/YPos.java +++ b/src/main/java/net/momirealms/customfishing/requirements/YPos.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.requirements; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/net/momirealms/customfishing/timer/Timer.java b/src/main/java/net/momirealms/customfishing/timer/Timer.java index 3585f68a..3dfaad22 100644 --- a/src/main/java/net/momirealms/customfishing/timer/Timer.java +++ b/src/main/java/net/momirealms/customfishing/timer/Timer.java @@ -1,7 +1,7 @@ package net.momirealms.customfishing.timer; import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.bar.Difficulty; +import net.momirealms.customfishing.titlebar.Difficulty; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; diff --git a/src/main/java/net/momirealms/customfishing/timer/TimerTask.java b/src/main/java/net/momirealms/customfishing/timer/TimerTask.java index e1fc8038..0f28d195 100644 --- a/src/main/java/net/momirealms/customfishing/timer/TimerTask.java +++ b/src/main/java/net/momirealms/customfishing/timer/TimerTask.java @@ -3,8 +3,8 @@ package net.momirealms.customfishing.timer; import net.momirealms.customfishing.AdventureManager; import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.bar.Difficulty; -import net.momirealms.customfishing.bar.Layout; +import net.momirealms.customfishing.titlebar.Difficulty; +import net.momirealms.customfishing.titlebar.Layout; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/src/main/java/net/momirealms/customfishing/titlebar/Difficulty.java b/src/main/java/net/momirealms/customfishing/titlebar/Difficulty.java new file mode 100644 index 00000000..67d1b9e1 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/titlebar/Difficulty.java @@ -0,0 +1,23 @@ +/* + * 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.titlebar; + +public record Difficulty(int timer, int speed) { + public int getTimer() {return this.timer;} + public int getSpeed() {return this.speed;} +} diff --git a/src/main/java/net/momirealms/customfishing/titlebar/FishingPlayer.java b/src/main/java/net/momirealms/customfishing/titlebar/FishingPlayer.java new file mode 100644 index 00000000..1e7bc93a --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/titlebar/FishingPlayer.java @@ -0,0 +1,23 @@ +/* + * 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.titlebar; + +public record FishingPlayer(Long fishingTime, Timer timer) { + public Long getFishingTime() {return this.fishingTime;} + public Timer getTimer() {return this.timer;} +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/titlebar/Layout.java b/src/main/java/net/momirealms/customfishing/titlebar/Layout.java new file mode 100644 index 00000000..0fb2eece --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/titlebar/Layout.java @@ -0,0 +1,60 @@ +/* + * 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.titlebar; + +public class Layout { + + private final String key; + private final int range; + private final double[] successRate; + private final int size; + + private String start; + private String bar; + private String pointer; + private String offset; + private String end; + private String pointerOffset; + private String title; + + public Layout(String key, int range, double[] successRate, int size){ + this.key = key; + this.range = range; + this.successRate = successRate; + this.size = size; + } + + public void setBar(String bar) {this.bar = bar;} + public void setEnd(String end) {this.end = end;} + public void setOffset(String offset) {this.offset = offset;} + public void setPointer(String pointer) {this.pointer = pointer;} + public void setPointerOffset(String pointerOffset) {this.pointerOffset = pointerOffset;} + public void setStart(String start) {this.start = start;} + public void setTitle(String title) {this.title = title;} + + public int getRange(){return this.range;} + public double[] getSuccessRate(){return this.successRate;} + public int getSize(){return this.size;} + public String getBar() {return bar;} + public String getEnd() {return end;} + public String getOffset() {return offset;} + public String getPointer() {return pointer;} + public String getPointerOffset() {return pointerOffset;} + public String getStart() {return start;} + public String getTitle() {return title;} +} diff --git a/src/main/java/net/momirealms/customfishing/titlebar/Timer.java b/src/main/java/net/momirealms/customfishing/titlebar/Timer.java new file mode 100644 index 00000000..a0b70a4e --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/titlebar/Timer.java @@ -0,0 +1,40 @@ +/* + * 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.titlebar; + +import net.momirealms.customfishing.CustomFishing; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; + +public class Timer { + + private final TimerTask timerTask; + private final BukkitTask task; + private final String layout; + + public Timer(Player player, Difficulty difficulty, String layout) { + this.layout = layout; + this.timerTask = new TimerTask(player, difficulty, layout); + this.task = timerTask.runTaskTimerAsynchronously(CustomFishing.instance, 0,1); + timerTask.setTaskID(task.getTaskId()); + } + + public TimerTask getTimerTask(){ return this.timerTask; } + public int getTaskID (){ return this.task.getTaskId(); } + public String getLayout(){return this.layout;} +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/titlebar/TimerTask.java b/src/main/java/net/momirealms/customfishing/titlebar/TimerTask.java new file mode 100644 index 00000000..1c86efb3 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/titlebar/TimerTask.java @@ -0,0 +1,132 @@ +/* + * 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.titlebar; + +import net.momirealms.customfishing.utils.AdventureManager; +import net.momirealms.customfishing.ConfigReader; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.titlebar.Difficulty; +import net.momirealms.customfishing.titlebar.Layout; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitScheduler; + +import static net.momirealms.customfishing.listener.PlayerListener.fishingPlayers; + +public class TimerTask extends BukkitRunnable { + + private final Player player; + private final Difficulty difficulty; + private int taskID; + private int progress; + private int internalTimer; + private final int size; + private boolean face; + private BukkitScheduler bukkitScheduler; + + private final String start; + private final String bar; + private final String pointer; + private final String offset; + private final String end; + private final String pointerOffset; + private final String title; + + public TimerTask(Player player, Difficulty difficulty, String layout){ + this.player = player; + this.difficulty = difficulty; + this.progress = 0; + this.internalTimer = 0; + this.face = true; + this.bukkitScheduler = Bukkit.getScheduler(); + Layout layoutUtil = ConfigReader.LAYOUT.get(layout); + this.start = layoutUtil.getStart(); + this.bar = layoutUtil.getBar(); + this.pointer = layoutUtil.getPointer(); + this.offset = layoutUtil.getOffset(); + this.end = layoutUtil.getEnd(); + this.pointerOffset = layoutUtil.getPointerOffset(); + this.title = layoutUtil.getTitle(); + this.size = layoutUtil.getSize(); + } + + public int getProgress() { return this.progress; } + public void setTaskID(int taskID){ + this.taskID = taskID; + } + + @Override + public void run() { + //移除提前收杆玩家 + if (fishingPlayers.get(player) == null){ + bukkitScheduler.cancelTask(taskID); + return; + } + //移除超时玩家 + if (System.currentTimeMillis() > fishingPlayers.get(player).getFishingTime()){ + fishingPlayers.remove(player); + bukkitScheduler.cancelTask(taskID); + return; + } + int timer = difficulty.getTimer() - 1; + int speed = difficulty.getSpeed(); + //设置指针方向 + if (progress <= speed - 1){ + face = true; + }else if(progress >= size - speed + 1){ + face = false; + } + //内部计时器操控 + if (internalTimer < timer){ + internalTimer++; + return; + }else { + if (face){ + internalTimer -= timer; + progress += speed; + }else { + internalTimer -= timer; + progress -= speed; + } + } + //发送title + StringBuilder stringBuilder = new StringBuilder(start + bar + pointerOffset); + for (int index = 0; index <= size; index++){ + if (index == progress){ + stringBuilder.append(pointer); + }else { + stringBuilder.append(offset); + } + } + stringBuilder.append(end); + AdventureManager.playerTitle(player, title, stringBuilder.toString(),0,300,0); + //移除切换物品的玩家 + PlayerInventory playerInventory = player.getInventory(); + if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD){ + fishingPlayers.remove(player); + bukkitScheduler.cancelTask(taskID); + bukkitScheduler.runTask(CustomFishing.instance, ()-> { + player.removePotionEffect(PotionEffectType.SLOW); + }); + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/utils/AdventureManager.java b/src/main/java/net/momirealms/customfishing/utils/AdventureManager.java new file mode 100644 index 00000000..3abba1b1 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/utils/AdventureManager.java @@ -0,0 +1,67 @@ +/* + * 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.utils; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.title.Title; +import net.momirealms.customfishing.CustomFishing; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.time.Duration; + +public class AdventureManager { + + public static void consoleMessage(String s) { + Audience au = CustomFishing.adventure.sender(Bukkit.getConsoleSender()); + MiniMessage mm = MiniMessage.miniMessage(); + Component parsed = mm.deserialize(s); + au.sendMessage(parsed); + } + + public static void playerMessage(Player player, String s) { + Audience au = CustomFishing.adventure.player(player); + MiniMessage mm = MiniMessage.miniMessage(); + Component parsed = mm.deserialize(s); + au.sendMessage(parsed); + } + + public static void playerTitle(Player player, String s1, String s2, int in, int duration, int out) { + Audience au = CustomFishing.adventure.player(player); + MiniMessage mm = MiniMessage.miniMessage(); + Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out)); + Title title = Title.title(mm.deserialize(s1), mm.deserialize(s2), times); + au.showTitle(title); + } + + public static void playerActionbar(Player player, String s) { + Audience au = CustomFishing.adventure.player(player); + MiniMessage mm = MiniMessage.miniMessage(); + au.sendActionBar(mm.deserialize(s)); + } + + public static void playerSound(Player player, Sound.Source source, Key key) { + Sound sound = Sound.sound(key, source, 1, 1); + Audience au = CustomFishing.adventure.player(player); + au.playSound(sound); + } +} diff --git a/src/main/java/net/momirealms/customfishing/utils/Enchantment.java b/src/main/java/net/momirealms/customfishing/utils/Enchantment.java index 5e973b08..e97a720e 100644 --- a/src/main/java/net/momirealms/customfishing/utils/Enchantment.java +++ b/src/main/java/net/momirealms/customfishing/utils/Enchantment.java @@ -1,14 +1,25 @@ +/* + * 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.utils; import org.bukkit.NamespacedKey; public record Enchantment(NamespacedKey key, int level) { - - public int getLevel() { - return level; - } - - public NamespacedKey getKey() { - return key; - } + public int getLevel() {return level;} + public NamespacedKey getKey() {return key;} } diff --git a/src/main/java/net/momirealms/customfishing/utils/ItemStackGenerator.java b/src/main/java/net/momirealms/customfishing/utils/ItemStackGenerator.java index 27e16168..7cf0d3f5 100644 --- a/src/main/java/net/momirealms/customfishing/utils/ItemStackGenerator.java +++ b/src/main/java/net/momirealms/customfishing/utils/ItemStackGenerator.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.utils; import de.tr7zw.changeme.nbtapi.NBTCompound; diff --git a/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java b/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java index f8fb6adc..af7253b4 100644 --- a/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java +++ b/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java @@ -1,11 +1,26 @@ +/* + * 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.utils; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; -import org.apache.commons.lang.StringUtils; import org.bukkit.inventory.ItemStack; -import java.nio.charset.StandardCharsets; import java.util.*; public class NBTUtil { @@ -31,7 +46,7 @@ public class NBTUtil { return this.nbtItem; } - private NBTCompound setTags(Map map, NBTCompound nbtCompound){ + private void setTags(Map map, NBTCompound nbtCompound){ map.keySet().forEach(key -> { if (map.get(key) instanceof Map map2){ nbtCompound.addCompound(key); @@ -54,7 +69,7 @@ public class NBTUtil { nbtCompound.getIntegerList(key).add(Integer.valueOf(s.substring(6))); } else if (s.startsWith("(IntArray) ")){ String[] split = s.substring(11).replace("[","").replace("]","").replaceAll("\\s", "").split(","); - int[] array = Arrays.asList(split).stream().mapToInt(Integer::parseInt).toArray(); + int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); nbtCompound.getIntArrayList(key).add(array); } } else if (o instanceof Map map1) { @@ -91,12 +106,11 @@ public class NBTUtil { nbtCompound.setByteArray(key, bytes); }else if (string.startsWith("(IntArray) ")){ String[] split = string.substring(11).replace("[","").replace("]","").replaceAll("\\s", "").split(","); - int[] array = Arrays.asList(split).stream().mapToInt(Integer::parseInt).toArray(); + int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); nbtCompound.setIntArray(key, array); } } } }); - return nbtCompound; } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/utils/SaveItem.java b/src/main/java/net/momirealms/customfishing/utils/SaveItem.java index 147b4972..24400e7b 100644 --- a/src/main/java/net/momirealms/customfishing/utils/SaveItem.java +++ b/src/main/java/net/momirealms/customfishing/utils/SaveItem.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customfishing.utils; import de.tr7zw.changeme.nbtapi.NBTCompound; diff --git a/src/main/java/net/momirealms/customfishing/utils/VectorUtil.java b/src/main/java/net/momirealms/customfishing/utils/VectorUtil.java index 53cbefd5..96b4c73a 100644 --- a/src/main/java/net/momirealms/customfishing/utils/VectorUtil.java +++ b/src/main/java/net/momirealms/customfishing/utils/VectorUtil.java @@ -1,12 +1,23 @@ +/* + * 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.utils; public record VectorUtil(double horizontal, double vertical) { - - public double getHorizontal() { - return this.horizontal; - } - - public double getVertical() { - return this.vertical; - } + public double getHorizontal() {return this.horizontal;} + public double getVertical() {return this.vertical;} } diff --git a/src/main/resources/competition.yml b/src/main/resources/competition.yml new file mode 100644 index 00000000..a56eb847 --- /dev/null +++ b/src/main/resources/competition.yml @@ -0,0 +1,43 @@ +example: + + #TOTAL_POINTS + #CATCH_AMOUNT + goal: TOTAL_POINTS + + start-time: + - '5:30' + - '17:30' + + duration: 300 #seconds + + bossbar: + enable: true + color: YELLOW + overlay: PROGRESS + text: 'Time Left:{time}s Rank:{rank} Time Left:{minute}m{second}s Points:{point}' + refresh-rate: 10 + + broadcast: + start: + - 'The competition has started. Start Fishing to join!' + end: + - 'The competition has ended!' + - ' ① {1st} {1st_points}points' + - ' ② {2nd} {2nd_points}points' + - ' ③ {3rd} {3rd_points}points' + + prize: + 1: + commands: + - 'say {player} got the 1st place' + messages: + - 'You got the first prize lol!' + 2: + commands: + - 'money give {player} 100' + 3: + commands: + - 'money give {player} 50' + participation: + commands: + - 'money give {player} 10' \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d7d8e56f..2f7841ff 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,6 +6,9 @@ config: WorldGuard: false MythicMobs: false PlaceholderAPI: true + mcMMO: false + MMOCore: false + AureliumSkills: false #季节特性 season: @@ -25,6 +28,16 @@ config: #是否只有本插件的鱼竿能钓到鱼 need-special-rod: false + #使用找鱼器的冷却时间(ms) + fishfinder-cooldown: 3000 + + #修改捕鱼所需的时间 + #在paper.yml中可以修改默认最少最长上钩时间 + time-multiply: 2 + + #是否启用钓鱼比赛(修改此项需要重启) + fishing-competition: true + #成功率 #你可以自定义区域数量,这为自定义UI提供了可能 success-rate: @@ -86,10 +99,3 @@ config: 20: 0 21: 0 22: 0 - - #使用找鱼器的冷却时间(ms) - fishfinder-cooldown: 3000 - - #修改捕鱼所需的时间 - #在paper.yml中可以修改默认最少最长上钩时间 - time-multiply: 2 \ No newline at end of file diff --git a/src/main/resources/loots.yml b/src/main/resources/loots.yml index 39309cb0..540cc518 100644 --- a/src/main/resources/loots.yml +++ b/src/main/resources/loots.yml @@ -10,6 +10,7 @@ items: time: 100000 show-in-fishfinder: false difficulty: 1-1 + score: 10.5 #物品内部ID rainbow_fish: diff --git a/src/main/resources/messages/messages_cn.yml b/src/main/resources/messages/messages_cn.yml index 62613b74..52f19ec0 100644 --- a/src/main/resources/messages/messages_cn.yml +++ b/src/main/resources/messages/messages_cn.yml @@ -16,4 +16,13 @@ messages: possible-loots: '此处可能钓到: ' split-char: ',' no-loot: '这个地方什么鱼都没有!' - not-open-water: '这里不是开放水域,你将无法获得任何奖励!' \ No newline at end of file + not-open-water: '这里不是开放水域,你将无法获得任何奖励!' + competition-ongoing: '当前有一场钓鱼比赛进行中! 开始钓鱼以加入比赛获取奖励!' + players-not-enough: '玩家数量不足,钓鱼比赛无法如期举行!' + no-rank: '未上榜' + force-competition-success: '成功强制进行钓鱼比赛!' + force-competition-failure: '此比赛不存在!' + force-competition-end: '已强制结束当前正在进行的比赛!' + force-competition-cancel: '已强制取消当前正在进行的比赛!' + no-player: '无玩家' + no-score: '无分数' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b8b4f09d..96e7b60a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,6 +7,9 @@ softdepend: - MythicMobs - PlaceholderAPI - WorldGuard + - mcMMO + - AureliumSkills + - MMOCore commands: customfishing: usage: /customfishing