9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2026-01-04 15:41:35 +00:00
This commit is contained in:
XiaoMoMi
2023-07-27 00:57:59 +08:00
parent c7f8eecb21
commit 99c6da4c80
20 changed files with 126 additions and 36 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '1.3.2.3'
version = '1.3.2.4'
repositories {
maven {name = "aliyun-repo"; url = "https://maven.aliyun.com/repository/public/"}
@@ -27,6 +27,7 @@ repositories {
dependencies {
compileOnly fileTree(dir:'libs',includes:['*.jar'])
implementation fileTree(dir:'libs',includes:['BiomeAPI.jar'])
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly('dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT')
compileOnly('com.zaxxer:HikariCP:5.0.1')
compileOnly('commons-io:commons-io:2.11.0')

View File

@@ -137,7 +137,7 @@ public final class CustomFishing extends JavaPlugin {
TimeZone timeZone = TimeZone.getDefault();
String libRepo = timeZone.getID().startsWith("Asia") ? "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/";
LibraryLoader.load("org.apache.commons","commons-pool2","2.11.1", libRepo);
LibraryLoader.load("redis.clients","jedis","4.4.3", "https://repo.maven.apache.org/maven2/");
LibraryLoader.load("redis.clients","jedis","4.4.2", libRepo);
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3.1", libRepo);
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1", libRepo);
LibraryLoader.load("net.objecthunter","exp4j","0.4.8", libRepo);

View File

@@ -45,8 +45,11 @@ public class CompetitionCommand extends AbstractSubCommand {
AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs);
return true;
}
if (CompetitionSchedule.startCompetition(args.get(1))) AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceSuccess);
else AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceFailure);
if (CompetitionSchedule.startCompetition(args.get(1))) {
AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceSuccess);
} else {
AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceFailure);
}
}
case "end" -> {
CompetitionSchedule.endCompetition();

View File

@@ -5,6 +5,7 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.api.CustomFishingAPI;
import net.momirealms.customfishing.commands.AbstractSubCommand;
import net.momirealms.customfishing.fishing.Effect;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.loot.LootImpl;
import net.momirealms.customfishing.integration.SeasonInterface;
import net.momirealms.customfishing.util.AdventureUtils;
@@ -45,7 +46,7 @@ public class DebugCommand extends AbstractSubCommand {
}
case "loot-chance" -> {
Effect initial = CustomFishing.getInstance().getFishingManager().getInitialEffect(player);
List<String> lootProbability = getLootProbability(initial, CustomFishingAPI.getLootsAt(player.getLocation(), player));
List<String> lootProbability = getLootProbability(initial, CustomFishing.getInstance().getFishingManager().getPossibleLootList(new FishingCondition(player.getLocation(), player, "fish_finder", "fish_finder"), false, CustomFishing.getInstance().getLootManager().getAllLoots()));
for (String msg : lootProbability) {
AdventureUtils.playerMessage(player, msg);
}

View File

@@ -48,6 +48,20 @@ public class FishingCondition{
}
}
public FishingCondition(Location location, Player player) {
this.location = location;
this.player = player;
this.rodID = null;
this.baitID = null;
this.papiMap = new HashMap<>();
if (player != null) {
PlaceholderManager placeholderManager = CustomFishing.getInstance().getIntegrationManager().getPlaceholderManager();
for (String papi : CustomPapi.allPapi) {
this.papiMap.put(papi, placeholderManager.parse(player, papi));
}
}
}
public HashMap<String, String> getPapiMap() {
return papiMap;
}

View File

@@ -28,6 +28,7 @@ import net.momirealms.customfishing.integration.papi.PlaceholderManager;
import net.momirealms.customfishing.manager.ConfigManager;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.util.AdventureUtils;
import net.momirealms.customfishing.util.JedisUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -59,9 +60,11 @@ public class Competition {
this.goal = competitionConfig.getGoal() == CompetitionGoal.RANDOM ? getRandomGoal() : competitionConfig.getGoal();
this.remainingTime = this.competitionConfig.getDuration();
this.startTime = Instant.now().getEpochSecond();
if (ConfigManager.useRedis) this.ranking = new RedisRankingImpl();
else this.ranking = new LocalRankingImpl();
if (ConfigManager.useRedis) {
this.ranking = new RedisRankingImpl();
} else {
this.ranking = new LocalRankingImpl();
}
this.ranking.clear();
startTimer();

View File

@@ -26,6 +26,7 @@ import java.util.List;
public class CompetitionConfig {
private String key;
private final int duration;
private final int minPlayers;
private final List<String> startMessage;
@@ -40,7 +41,21 @@ public class CompetitionConfig {
private final boolean enableBossBar;
private final HashMap<String, Action[]> rewards;
public CompetitionConfig(int duration, int minPlayers, List<String> startMessage, List<String> endMessage, List<String> startCommand, List<String> endCommand, List<String> joinCommand, CompetitionGoal goal, BossBarConfig bossBarConfig, boolean enableBossBar, HashMap<String, Action[]> rewards) {
public CompetitionConfig(
String key,
int duration,
int minPlayers,
List<String> startMessage,
List<String> endMessage,
List<String> startCommand,
List<String> endCommand,
List<String> joinCommand,
CompetitionGoal goal,
BossBarConfig bossBarConfig,
boolean enableBossBar,
HashMap<String, Action[]> rewards
) {
this.key = key;
this.duration = duration;
this.minPlayers = minPlayers;
this.startMessage = startMessage;
@@ -106,6 +121,10 @@ public class CompetitionConfig {
this.weekday = weekday;
}
public String getKey() {
return key;
}
public boolean canStart() {
if (date != null && date.size() != 0) {
Calendar calendar = Calendar.getInstance();

View File

@@ -17,19 +17,27 @@
package net.momirealms.customfishing.fishing.competition;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.object.Function;
import net.momirealms.customfishing.util.AdventureUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.time.LocalTime;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class CompetitionSchedule extends Function {
@Override
public void load() {
checkTime();
}
private static CompetitionSchedule instance;
private ScheduledFuture<?> checkTimeTask;
private int doubleCheckTime;
@Override
public void unload() {
@@ -37,8 +45,10 @@ public class CompetitionSchedule extends Function {
cancelCompetition();
}
private ScheduledFuture<?> checkTimeTask;
private int doubleCheckTime;
public void load() {
instance = this;
checkTime();
}
public static boolean startCompetition(String competitionName) {
CompetitionConfig competitionConfig = CustomFishing.getInstance().getCompetitionManager().getCompetitionsC().get(competitionName);
@@ -63,6 +73,7 @@ public class CompetitionSchedule extends Function {
}
}
public void startCompetition(CompetitionConfig competitionConfig) {
if (Competition.currentCompetition != null) {
Competition.currentCompetition.end();
@@ -101,4 +112,8 @@ public class CompetitionSchedule extends Function {
return false;
}
}
public static CompetitionSchedule getInstance() {
return instance;
}
}

View File

@@ -21,7 +21,6 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.bar.ModeThreeBar;
import net.momirealms.customfishing.manager.FishingManager;
import net.momirealms.customfishing.util.AdventureUtils;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import java.util.concurrent.TimeUnit;

View File

@@ -21,11 +21,8 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.bar.ModeTwoBar;
import net.momirealms.customfishing.manager.FishingManager;
import net.momirealms.customfishing.util.AdventureUtils;
import net.momirealms.customfishing.util.LocationUtils;
import org.bukkit.Location;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerFishEvent;
import java.util.concurrent.TimeUnit;

View File

@@ -19,7 +19,7 @@ public class BaitImpl extends Requirement implements RequirementInterface {
public boolean isConditionMet(FishingCondition fishingCondition) {
Player player = fishingCondition.getPlayer();
String bait = fishingCondition.getBaitID();
if (bait == null || baits.contains(bait)) {
if (bait != null && (baits.contains(bait) || bait.equals("fish_finder"))) {
return true;
}
notMetMessage(player);

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.competition.Competition;
import org.jetbrains.annotations.Nullable;
public class CompetitionImpl extends Requirement implements RequirementInterface {
private final boolean state;
public CompetitionImpl(@Nullable String[] msg, boolean state) {
super(msg);
this.state = state;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
if (Competition.hasCompetitionOn() == state) return true;
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -19,7 +19,7 @@ public class RodImpl extends Requirement implements RequirementInterface {
public boolean isConditionMet(FishingCondition fishingCondition) {
Player player = fishingCondition.getPlayer();
String rod = fishingCondition.getRodID();
if (rod == null || rods.contains(rod)) {
if (rod != null && (rods.contains(rod) || rod.equals("fish_finder"))) {
return true;
}
notMetMessage(player);

View File

@@ -69,7 +69,7 @@ public class CompetitionManager extends Function {
}
private void loadCompetitions() {
File competition_file = new File(plugin.getDataFolder() + File.separator + "contents" + File.separator + "competitions");
File competition_file = new File(plugin.getDataFolder(), "contents" + File.separator + "competitions");
if (!competition_file.exists()) {
if (!competition_file.mkdir()) return;
plugin.saveResource("contents" + File.separator + "competitions" + File.separator + "default.yml", false);
@@ -105,6 +105,7 @@ public class CompetitionManager extends Function {
});
CompetitionConfig competitionConfig = new CompetitionConfig(
key,
competitionSection.getInt("duration",600),
competitionSection.getInt("min-players",1),
competitionSection.getStringList("broadcast.start"),

View File

@@ -182,12 +182,10 @@ public class ConfigManager {
private static void redisSettings(ConfigurationSection config) {
if (enableCompetition && config.getBoolean("fishing-competition.redis", false)) {
if (!JedisUtils.isPoolEnabled()) {
YamlConfiguration configuration = ConfigUtils.getConfig("database.yml");
JedisUtils.initializeRedis(configuration);
JedisUtils.initializeRedis(ConfigUtils.getConfig("database.yml"));
}
useRedis = true;
}
else if (useRedis && JedisUtils.isPoolEnabled()) {
} else if (useRedis && JedisUtils.isPoolEnabled()) {
JedisUtils.closePool();
useRedis = false;
}

View File

@@ -60,6 +60,7 @@ import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerFishEvent;
@@ -831,7 +832,7 @@ public class FishingManager extends Function {
List<TotemConfig> totemList = plugin.getTotemManager().getTotemsByCoreID(blockID);
if (totemList == null || !totemList.contains(totem)) return;
FishingCondition fishingCondition = new FishingCondition(block.getLocation(), player, null, null);
FishingCondition fishingCondition = new FishingCondition(block.getLocation(), player);
if (totem.getRequirements() != null)
for (RequirementInterface requirement : totem.getRequirements()) {
if (!requirement.isConditionMet(fishingCondition)) {
@@ -875,7 +876,7 @@ public class FishingManager extends Function {
return;
}
FishingCondition fishingCondition = new FishingCondition(player.getLocation(), player, null, null);
FishingCondition fishingCondition = new FishingCondition(player.getLocation(), player, "fish_finder", "fish_finder");
List<LootImpl> possibleLoots = getPossibleLootList(fishingCondition, true, plugin.getLootManager().getAllLoots());
FishFinderEvent fishFinderEvent = new FishFinderEvent(player, possibleLoots);
@@ -992,11 +993,7 @@ public class FishingManager extends Function {
public void removeHook(UUID uuid) {
FishHook fishHook = removeHookCache(uuid);
if (fishHook != null) {
if (plugin.getVersionHelper().isFolia()) {
plugin.getScheduler().runTask(fishHook::remove, fishHook.getLocation());
} else {
fishHook.remove();
}
plugin.getScheduler().runTask(fishHook::remove, fishHook.getLocation());
}
}

View File

@@ -200,8 +200,7 @@ public class AdventureUtils {
} else {
stringBuilder.append(chars[i]);
}
}
else {
} else {
stringBuilder.append(chars[i]);
}
}

View File

@@ -112,6 +112,7 @@ public class ConfigUtils {
case "date" -> requirements.add(new DateImpl(null, new HashSet<>(section.getStringList(type))));
case "rod" -> requirements.add(new RodImpl(null, new HashSet<>(section.getStringList(type))));
case "bait" -> requirements.add(new BaitImpl(null, new HashSet<>(section.getStringList(type))));
case "competition" -> requirements.add(new CompetitionImpl(null, section.getBoolean(type)));
case "papi-condition" -> requirements.add(new CustomPapi(null, Objects.requireNonNull(section.getConfigurationSection(type)).getValues(false)));
}
}
@@ -142,6 +143,7 @@ public class ConfigUtils {
case "date" -> requirements.add(new DateImpl(msg, new HashSet<>(innerSec.getStringList("value"))));
case "rod" -> requirements.add(new RodImpl(msg, new HashSet<>(innerSec.getStringList("value"))));
case "bait" -> requirements.add(new BaitImpl(msg, new HashSet<>(innerSec.getStringList("value"))));
case "competition" -> requirements.add(new CompetitionImpl(msg, innerSec.getBoolean("value")));
case "papi-condition" -> requirements.add(new CustomPapi(msg, Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false)));
}
}

View File

@@ -82,7 +82,6 @@ public class JedisUtils {
jedisPool = null;
}
}
public static boolean isPoolEnabled() {
return jedisPool != null && !jedisPool.isClosed();
}

View File

@@ -229,6 +229,9 @@ rainbow_fish:
# Requires job plugin
job-level: 10
# Only occurs when there's a competition
competition: true
# Requires Season Plugin
season:
- Spring