9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-09 17:42:32 +08:00
parent b460259ffb
commit 3b9d45c315
24 changed files with 577 additions and 58 deletions

View File

@@ -21,6 +21,9 @@ 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.competition.reward.CommandImpl;
import net.momirealms.customfishing.competition.reward.MessageImpl;
import net.momirealms.customfishing.competition.reward.Reward;
import net.momirealms.customfishing.titlebar.Difficulty;
import net.momirealms.customfishing.titlebar.Layout;
import net.momirealms.customfishing.hook.skill.Aurelium;
@@ -59,7 +62,7 @@ public class ConfigReader{
public static HashMap<String, CompetitionConfig> Competitions = new HashMap<>();
public static HashMap<String, CompetitionConfig> CompetitionsCommand = new HashMap<>();
private static YamlConfiguration getConfig(String configName) {
public static YamlConfiguration getConfig(String configName) {
File file = new File(CustomFishing.instance.getDataFolder(), configName);
if (!file.exists()) {
CustomFishing.instance.saveResource(configName, false);
@@ -366,7 +369,7 @@ public class ConfigReader{
loot.setNick(loot.getName());
}
loot.setUnbreakable(config.getBoolean("items." + key + ".unbreakable",false));
loot.setPoint((float) config.getDouble("items." + key + ".score"));
loot.setScore((float) config.getDouble("items." + key + ".score",0));
if (config.contains("items." + key + ".action.message"))
loot.setMsg(config.getString("items." + key + ".action.message"));
@@ -505,7 +508,7 @@ public class ConfigReader{
}else {
loot.setShowInFinder(true);
}
loot.setPoint((float) config.getDouble("mobs." + key + ".score"));
loot.setScore((float) config.getDouble("mobs." + key + ".score",0));
/*
设置捕获条件
*/
@@ -673,6 +676,7 @@ public class ConfigReader{
case "time" -> rodInstance.setTime(config.getDouble("rods." + key + ".modifier.time"));
case "difficulty" -> rodInstance.setDifficulty(config.getInt("rods." + key + ".modifier.difficulty"));
case "double-loot" -> rodInstance.setDoubleLoot(config.getDouble("rods." + key + ".modifier.double-loot"));
case "score" -> rodInstance.setScoreModifier(config.getDouble("rods." + key + ".modifier.score"));
}
});
}
@@ -750,6 +754,7 @@ public class ConfigReader{
case "time" -> baitInstance.setTime(config.getDouble("baits." + key + ".modifier.time"));
case "difficulty" -> baitInstance.setDifficulty(config.getInt("baits." + key + ".modifier.difficulty"));
case "double-loot" -> baitInstance.setDoubleLoot(config.getDouble("baits." + key + ".modifier.double-loot"));
case "score" -> baitInstance.setScoreModifier(config.getDouble("baits." + key + ".modifier.score"));
}
});
}
@@ -791,10 +796,34 @@ public class ConfigReader{
if (config.contains(key + ".broadcast.end")){
competitionConfig.setEndMessage(config.getStringList(key + ".broadcast.end"));
}
if (config.contains(key + ".prize")){
HashMap<String, List<Reward>> rewardsMap = new HashMap<>();
config.getConfigurationSection(key + ".prize").getKeys(false).forEach(rank -> {
List<Reward> rewards = new ArrayList<>();
if (config.contains(key + ".prize." + rank + ".messages")){
rewards.add(new MessageImpl(config.getStringList(key + ".prize." + rank + ".messages")));
}
if (config.contains(key + ".prize." + rank + ".commands")){
rewards.add(new CommandImpl(config.getStringList(key + ".prize." + rank + ".commands")));
}
rewardsMap.put(rank, rewards);
});
competitionConfig.setRewards(rewardsMap);
}
config.getStringList(key + ".start-time").forEach(time -> {
Competitions.put(time, competitionConfig);
});
CompetitionsCommand.put(key, competitionConfig);
});
}
public static void tryEnableJedis(){
YamlConfiguration configuration = ConfigReader.getConfig("redis.yml");
if (configuration.getBoolean("redis.enable")){
JedisUtil.initializeRedis(configuration);
JedisUtil.useRedis = true;
}else {
JedisUtil.useRedis = false;
}
}
}

View File

@@ -22,11 +22,11 @@ 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.helper.LibraryLoader;
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;
@@ -37,8 +37,14 @@ public final class CustomFishing extends JavaPlugin {
private CompetitionSchedule competitionSchedule;
@Override
public void onEnable() {
public void onLoad(){
instance = this;
LibraryLoader.load("redis.clients","jedis","4.2.3","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("org.apache.commons","commons-pool2","2.11.1","https://repo.maven.apache.org/maven2/");
}
@Override
public void onEnable() {
adventure = BukkitAudiences.create(this);
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setExecutor(new Execute());
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setTabCompleter(new TabComplete());
@@ -50,6 +56,7 @@ public final class CustomFishing extends JavaPlugin {
competitionSchedule.checkTime();
Bukkit.getPluginManager().registerEvents(new BossBarManager(), this);
}
ConfigReader.tryEnableJedis();
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Plugin Enabled!");
}

View File

@@ -21,8 +21,12 @@ 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.competition.ranking.Ranking;
import net.momirealms.customfishing.competition.ranking.RankingImpl;
import net.momirealms.customfishing.competition.ranking.RedisRankingImpl;
import net.momirealms.customfishing.competition.reward.Reward;
import net.momirealms.customfishing.utils.AdventureManager;
import net.momirealms.customfishing.utils.JedisUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@@ -43,6 +47,7 @@ public class Competition {
private final BossBarConfig bossBarConfig;
private final List<String> startMessage;
private final List<String> endMessage;
private final HashMap<String, List<Reward>> rewardsMap;
public static long remainingTime;
public static float progress;
@@ -55,21 +60,24 @@ public class Competition {
this.bossBarConfig = competitionConfig.getBossBarConfig();
this.startMessage = competitionConfig.getStartMessage();
this.endMessage = competitionConfig.getEndMessage();
this.rewardsMap = competitionConfig.getRewards();
}
public void begin(boolean forceStart) {
if (goal == Goal.RANDOM) {
goal = getRandomGoal();
}
remainingTime = this.duration;
this.startTime = Instant.now().getEpochSecond();
Collection<? extends Player> playerCollections = Bukkit.getOnlinePlayers();
if (playerCollections.size() >= minPlayers || forceStart) {
status = true;
ranking = new Ranking();
if (JedisUtil.useRedis){
ranking = new RedisRankingImpl();
}else {
ranking = new RankingImpl();
}
startTimer();
if (startMessage != null){
playerCollections.forEach(player -> {
@@ -118,16 +126,18 @@ public class Competition {
BossBarManager.stopAllTimer();
this.timerTask.cancel();
status = false;
givePrize();
if (endMessage != null){
List<String> newMessage = new ArrayList<>();
endMessage.forEach(message -> {
float first = ranking.getScoreAt(1);
float second = ranking.getScoreAt(2);
float third = ranking.getScoreAt(3);
CompetitionPlayer[] competitionPlayers = ranking.getTop3Player();
float first = Optional.ofNullable(competitionPlayers[0]).orElse(CompetitionPlayer.emptyPlayer).getScore();
float second = Optional.ofNullable(competitionPlayers[1]).orElse(CompetitionPlayer.emptyPlayer).getScore();
float third = Optional.ofNullable(competitionPlayers[2]).orElse(CompetitionPlayer.emptyPlayer).getScore();
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}", Optional.ofNullable(Optional.ofNullable(competitionPlayers[0]).orElse(CompetitionPlayer.emptyPlayer).getPlayer()).orElse(ConfigReader.Message.noPlayer))
.replace("{2nd}", Optional.ofNullable(Optional.ofNullable(competitionPlayers[1]).orElse(CompetitionPlayer.emptyPlayer).getPlayer()).orElse(ConfigReader.Message.noPlayer))
.replace("{3rd}", Optional.ofNullable(Optional.ofNullable(competitionPlayers[2]).orElse(CompetitionPlayer.emptyPlayer).getPlayer()).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))));
@@ -138,7 +148,44 @@ public class Competition {
});
});
}
ranking.clear();
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomFishing.instance, ()-> {
ranking.clear();
}, 300);
}
public void givePrize(){
if (ranking.getSize() != 0 && rewardsMap != null) {
Iterator<String> iterator = ranking.getIterator();
int i = 1;
while (iterator.hasNext()) {
if (i < rewardsMap.size()) {
String playerName = iterator.next();
Player player = Bukkit.getPlayer(playerName);
if (player != null){
for (Reward reward : rewardsMap.get(String.valueOf(i))) {
reward.giveReward(player);
}
}
i++;
}
else {
List<Reward> rewards = rewardsMap.get("participation");
if (rewards != null) {
iterator.forEachRemaining(playerName -> {
Player player = Bukkit.getPlayer(playerName);
if (player != null){
for (Reward reward : rewards) {
reward.giveReward(player);
}
}
});
}
else {
break;
}
}
}
}
}
public void cancel() {
@@ -148,18 +195,10 @@ public class Competition {
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);
}
public void refreshRanking(String player, float score) {
if (this.goal != Goal.TOTAL_SCORE) score = 1.0f;
if (score == 0) return;
ranking.refreshData(player, score);
}
private Goal getRandomGoal() {

View File

@@ -18,7 +18,9 @@
package net.momirealms.customfishing.competition;
import net.momirealms.customfishing.competition.bossbar.BossBarConfig;
import net.momirealms.customfishing.competition.reward.Reward;
import java.util.HashMap;
import java.util.List;
public class CompetitionConfig {
@@ -30,6 +32,7 @@ public class CompetitionConfig {
private Goal goal;
private BossBarConfig bossBarConfig;
private final boolean enableBossBar;
private HashMap<String, List<Reward>> rewards;
public CompetitionConfig(boolean enableBossBar){this.enableBossBar = enableBossBar;}
@@ -38,6 +41,7 @@ public class CompetitionConfig {
public void setGoal(Goal goal) {this.goal = goal;}
public void setEndMessage(List<String> endMessage) {this.endMessage = endMessage;}
public void setStartMessage(List<String> startMessage) {this.startMessage = startMessage;}
public HashMap<String, List<Reward>> getRewards() {return rewards;}
public Goal getGoal() {return goal;}
public int getMinPlayers() {return minPlayers;}
@@ -46,4 +50,5 @@ public class CompetitionConfig {
public boolean isEnableBossBar() {return enableBossBar;}
public List<String> getEndMessage() {return endMessage;}
public List<String> getStartMessage() {return startMessage;}
public void setRewards(HashMap<String, List<Reward>> rewards) {this.rewards = rewards;}
}

View File

@@ -25,6 +25,8 @@ public class CompetitionPlayer implements Comparable<CompetitionPlayer>{
private final String player;
private float score;
public static CompetitionPlayer emptyPlayer = new CompetitionPlayer(null, 0);
public CompetitionPlayer(String player, float score) {
this.player = player;
this.score = score;

View File

@@ -39,7 +39,7 @@ public class CompetitionSchedule {
public static boolean startCompetition(String competitionName){
CompetitionConfig competitionConfig = ConfigReader.CompetitionsCommand.get(competitionName);
if (competitionConfig == null) return false;
if (competition != null){
if (competition != null && competition.isGoingOn()){
competition.end();
}
competition = new Competition(competitionConfig);
@@ -61,7 +61,7 @@ public class CompetitionSchedule {
}
public void startCompetition(CompetitionConfig competitionConfig){
if (competition != null){
if (competition != null && competition.isGoingOn()){
competition.end();
}
competition = new Competition(competitionConfig);

View File

@@ -19,7 +19,7 @@ package net.momirealms.customfishing.competition;
public enum Goal {
TOTAL_POINTS,
TOTAL_SCORE,
CATCH_AMOUNT,
RANDOM

View File

@@ -63,7 +63,7 @@ public class BossBarManager implements Listener {
}
public static void joinCompetition(Player player){
if (cache.get(player) == null){
if (cache.get(player) == null) {
BossBarTimer timerTask = new BossBarTimer(player, CompetitionSchedule.competition.getBossBarConfig());
cache.put(player, timerTask);
}

View File

@@ -0,0 +1,15 @@
package net.momirealms.customfishing.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;
import java.util.Iterator;
public interface Ranking {
void clear();
CompetitionPlayer getCompetitionPlayer(String player);
Iterator<String> getIterator();
int getSize();
String getPlayerRank(String player);
CompetitionPlayer[] getTop3Player();
void refreshData(String player, float score);
}

View File

@@ -0,0 +1,134 @@
/*
* 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.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;
import java.util.*;
public class RankingImpl implements Ranking{
private final Set<CompetitionPlayer> competitionPlayers = Collections.synchronizedSet(new TreeSet<>());
public void addPlayer(CompetitionPlayer competitionPlayer) {
competitionPlayers.add(competitionPlayer);
}
public void removePlayer(CompetitionPlayer competitionPlayer) {
competitionPlayers.removeIf(e -> e == competitionPlayer);
}
@Override
public void clear() {
competitionPlayers.clear();
}
@Override
public CompetitionPlayer getCompetitionPlayer(String player) {
for (CompetitionPlayer competitionPlayer : competitionPlayers) {
if (competitionPlayer.getPlayer().equals(player)) {
return competitionPlayer;
}
}
return null;
}
@Override
public Iterator<String> getIterator() {
List<String> players = new ArrayList<>();
for (CompetitionPlayer competitionPlayer: competitionPlayers){
players.add(competitionPlayer.getPlayer());
}
return players.iterator();
}
@Override
public int getSize() {
return competitionPlayers.size();
}
@Override
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;
}
@Override
public CompetitionPlayer[] getTop3Player() {
CompetitionPlayer[] competitionPlayers = new CompetitionPlayer[3];
int index = 1;
for (CompetitionPlayer competitionPlayer : this.competitionPlayers) {
if (index == 1) {
competitionPlayers[0] = competitionPlayer;
}
if (index == 2) {
competitionPlayers[1] = competitionPlayer;
}
if (index == 3) {
competitionPlayers[2] = competitionPlayer;
return competitionPlayers;
}
index++;
}
return competitionPlayers;
}
public String getPlayerAt(int i) {
int index = 1;
for (CompetitionPlayer competitionPlayer : competitionPlayers) {
if (index == i) {
return competitionPlayer.getPlayer();
}
index++;
}
return null;
}
public float getScoreAt(int i) {
int index = 1;
for (CompetitionPlayer competitionPlayer : competitionPlayers) {
if (index == i) {
return competitionPlayer.getScore();
}
index++;
}
return -1.0f;
}
@Override
public void refreshData(String player, float score) {
CompetitionPlayer competitionPlayer = getCompetitionPlayer(player);
if (competitionPlayer != null) {
removePlayer(competitionPlayer);
competitionPlayer.addScore(score);
addPlayer(competitionPlayer);
} else {
competitionPlayer = new CompetitionPlayer(player, score);
addPlayer(competitionPlayer);
}
}
}

View File

@@ -0,0 +1,97 @@
package net.momirealms.customfishing.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;
import net.momirealms.customfishing.utils.JedisUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.resps.Tuple;
import java.util.Iterator;
import java.util.List;
public class RedisRankingImpl implements Ranking{
public void addPlayer(CompetitionPlayer competitionPlayer) {
Jedis jedis = JedisUtil.getJedis();
jedis.zadd("cf_competition", competitionPlayer.getScore(), competitionPlayer.getPlayer());
jedis.close();
}
public void removePlayer(CompetitionPlayer competitionPlayer) {
Jedis jedis = JedisUtil.getJedis();
jedis.zrem("cf_competition", competitionPlayer.getPlayer());
jedis.close();
}
@Override
public void clear() {
Jedis jedis = JedisUtil.getJedis();
jedis.zremrangeByRank("cf_competition",0,-1);
jedis.close();
}
@Override
public CompetitionPlayer getCompetitionPlayer(String player) {
Jedis jedis = JedisUtil.getJedis();
Double score = jedis.zscore("cf_competition", player);
jedis.close();
if (score == 0) return null;
return new CompetitionPlayer(player, Float.parseFloat(score.toString()));
}
@Override
public Iterator<String> getIterator() {
Jedis jedis = JedisUtil.getJedis();
List<String> players = jedis.zrevrange("cf_competition", 0, -1);
jedis.close();
return players.iterator();
}
@Override
public int getSize() {
Jedis jedis = JedisUtil.getJedis();
long size = jedis.zcard("cf_competition");
jedis.close();
return (int) size;
}
@Override
public String getPlayerRank(String player) {
Jedis jedis = JedisUtil.getJedis();
Long rank = jedis.zrevrank("cf_competition", player);
jedis.close();
if(rank == null){
return null;
}
return String.valueOf(rank + 1);
}
@Override
public CompetitionPlayer[] getTop3Player() {
CompetitionPlayer[] competitionPlayers = new CompetitionPlayer[3];
Jedis jedis = JedisUtil.getJedis();
List<Tuple> players = jedis.zrevrangeWithScores("cf_competition", 0, -1);
jedis.close();
int index = 1;
for (Tuple tuple : players){
if (index == 1){
competitionPlayers[0] = new CompetitionPlayer(tuple.getElement(), (float) tuple.getScore());
}
if (index == 2){
competitionPlayers[1] = new CompetitionPlayer(tuple.getElement(), (float) tuple.getScore());
}
if (index == 3){
competitionPlayers[2] = new CompetitionPlayer(tuple.getElement(), (float) tuple.getScore());
return competitionPlayers;
}
index++;
}
return competitionPlayers;
}
@Override
public void refreshData(String player, float score) {
Jedis jedis = JedisUtil.getJedis();
jedis.zincrby("cf_competition", score, player);
jedis.close();
}
}

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.competition.reward;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandImpl implements Reward{
private final List<String> commands;
public CommandImpl(List<String> commands){
this.commands = commands;
}
@Override
public void giveReward(Player player) {
commands.forEach(command -> {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName()));
});
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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.competition.reward;
import net.momirealms.customfishing.utils.AdventureManager;
import org.bukkit.entity.Player;
import java.util.List;
public class MessageImpl implements Reward{
private final List<String> messages;
public MessageImpl(List<String> messages){
this.messages = messages;
}
@Override
public void giveReward(Player player) {
if (!player.isOnline()) return;
messages.forEach(message -> {
AdventureManager.playerMessage(player, message);
});
}
}

View File

@@ -31,6 +31,7 @@ public class Bait implements Item{
private HashMap<String, Double> weightMQ;
private HashMap<String, Integer> weightPM;
private double time;
private double scoreModifier;
private double doubleLoot;
private int difficulty;
private final String material;
@@ -43,7 +44,6 @@ public class Bait implements Item{
this.material = material;
}
public void setName(String name) {this.name = name;}
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
public void setDifficulty(int difficulty) {this.difficulty = difficulty;}
@@ -56,12 +56,14 @@ public class Bait implements Item{
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;}
public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;}
public void setScoreModifier(double scoreModifier) {this.scoreModifier = scoreModifier;}
public double getDoubleLoot() {return this.doubleLoot;}
public int getDifficulty() {return difficulty;}
public double getTime() {return time;}
public HashMap<String, Double> getWeightMQ() {return weightMQ;}
public HashMap<String, Integer> getWeightPM() {return weightPM;}
public double getScoreModifier() {return scoreModifier;}
@Override
public boolean isUnbreakable() {return this.unbreakable;}

View File

@@ -50,7 +50,7 @@ public class Loot implements Item {
private int custommodeldata;
private boolean unbreakable;
private double skillXP;
private float point;
private float score;
public Loot(String key, Difficulty difficulty, int weight, int time){
this.key = key;
@@ -75,7 +75,7 @@ public class Loot implements Item {
public String getGroup() {return group;}
public int getExp() {return exp;}
public double getSkillXP() {return skillXP;}
public float getPoint() {return point;}
public float getScore() {return score;}
@Override
public List<String> getLore(){return this.lore;}
@@ -114,5 +114,5 @@ public class Loot implements Item {
public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;}
public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;}
public void setSkillXP(double skillXP) {this.skillXP = skillXP;}
public void setPoint(float point) {this.point = point;}
public void setScore(float score) {this.score = score;}
}

View File

@@ -32,6 +32,7 @@ public class Rod implements Item{
private HashMap<String, Double> weightMQ;
private HashMap<String, Integer> weightPM;
private double time;
private double scoreModifier;
private int difficulty;
private double doubleLoot;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
@@ -51,12 +52,14 @@ public class Rod implements Item{
public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;}
public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;}
public void setName(String name) {this.name = name;}
public void setScoreModifier(double scoreModifier) {this.scoreModifier = scoreModifier;}
public double getTime() {return time;}
public HashMap<String, Double> getWeightMQ() {return weightMQ;}
public HashMap<String, Integer> getWeightPM() {return weightPM;}
public int getDifficulty() {return difficulty;}
public double getDoubleLoot() {return this.doubleLoot;}
public double getScoreModifier() {return scoreModifier;}
@Override
public boolean isUnbreakable() {return this.unbreakable;}

View File

@@ -19,7 +19,6 @@ package net.momirealms.customfishing.listener;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
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;
@@ -35,6 +34,7 @@ import net.momirealms.customfishing.item.Rod;
import net.momirealms.customfishing.requirements.FishingCondition;
import net.momirealms.customfishing.requirements.Requirement;
import net.momirealms.customfishing.titlebar.Timer;
import net.momirealms.customfishing.utils.Modifier;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -61,8 +61,7 @@ public class PlayerListener implements Listener {
private final HashMap<Player, Long> coolDown = new HashMap<>();
private final HashMap<Player, Loot> nextLoot = new HashMap<>();
private final HashMap<Player, Integer> modifier = new HashMap<>();
private final HashSet<Player> willDouble = new HashSet<>();
private final HashMap<Player, Modifier> modifiers = new HashMap<>();
public static ConcurrentHashMap<Player, FishingPlayer> fishingPlayers = new ConcurrentHashMap<>();
@EventHandler
@@ -88,6 +87,7 @@ public class PlayerListener implements Listener {
boolean noRod = true;
double timeModifier = 1;
double doubleLoot = 0;
double scoreModifier = 1;
int difficultyModifier = 0;
HashMap<String, Integer> pm1 = new HashMap<>();
@@ -107,6 +107,7 @@ public class PlayerListener implements Listener {
if (rod.getTime() != 0) timeModifier *= rod.getTime();
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
if (rod.getScoreModifier() != 0) scoreModifier *= rod.getScoreModifier();
noRod = false;
}
}
@@ -119,6 +120,7 @@ public class PlayerListener implements Listener {
if (bait.getTime() != 0) timeModifier *= bait.getTime();
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
if (bait.getScoreModifier() != 0) scoreModifier *= bait.getScoreModifier();
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
}
}
@@ -142,6 +144,7 @@ public class PlayerListener implements Listener {
if (bait.getTime() != 0) timeModifier *= bait.getTime();
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
if (bait.getScoreModifier() != 0) scoreModifier *= bait.getScoreModifier();
offHandItem.setAmount(offHandItem.getAmount() - 1);
}
}else if (noRod && offHandCompound.getString("type").equals("rod")){
@@ -153,6 +156,7 @@ public class PlayerListener implements Listener {
if (rod.getTime() != 0) timeModifier *= rod.getTime();
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
if (rod.getScoreModifier() != 0) scoreModifier *= rod.getScoreModifier();
noRod = false;
}
}
@@ -179,15 +183,12 @@ public class PlayerListener implements Listener {
return;
}
//双倍掉落
if (doubleLoot > Math.random()) {
willDouble.add(player);
}else {
willDouble.remove(player);
}
//难度修改
modifier.put(player, difficultyModifier);
Modifier modifier = new Modifier();
modifier.setDifficultyModifier(difficultyModifier);
modifier.setScoreModifier(scoreModifier);
modifier.setWillDouble(doubleLoot > Math.random());
//修改
modifiers.put(player, modifier);
double[] weights = new double[possibleLoots.size()];
int index = 0;
@@ -262,7 +263,7 @@ public class PlayerListener implements Listener {
});
int difficulty = lootInstance.getDifficulty().getSpeed();
difficulty += modifier.get(player);
difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficultyModifier(), 0);;
if (difficulty < 1){
difficulty = 1;
}
@@ -311,7 +312,7 @@ public class PlayerListener implements Listener {
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)){
if (modifiers.get(player).willDouble()){
Entity item2 = location.getWorld().dropItem(location, itemStack);
item2.setVelocity(vector);
}
@@ -342,7 +343,8 @@ public class PlayerListener implements Listener {
ConfigReader.Config.skillXP.addXp(player, lootInstance.getSkillXP());
}
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()){
CompetitionSchedule.competition.refreshRanking(player.getName(), lootInstance);
float score = (float) (lootInstance.getScore() * modifiers.get(player).getScoreModifier());
CompetitionSchedule.competition.refreshRanking(player.getName(), score);
BossBarManager.joinCompetition(player);
}
//发送Title
@@ -373,8 +375,7 @@ public class PlayerListener implements Listener {
player.removePotionEffect(PotionEffectType.SLOW);
coolDown.remove(player);
nextLoot.remove(player);
modifier.remove(player);
willDouble.remove(player);
modifiers.remove(player);
fishingPlayers.remove(player);
}

View File

@@ -0,0 +1,59 @@
package net.momirealms.customfishing.utils;
import net.momirealms.customfishing.helper.Log;
import org.bukkit.configuration.file.YamlConfiguration;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import java.util.ArrayList;
import java.util.List;
public class JedisUtil {
private static JedisPool jedisPool;
public static boolean useRedis;
public static Jedis getJedis(){
return jedisPool.getResource();
}
public static void initializeRedis(YamlConfiguration configuration){
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setTestWhileIdle(true);
jedisPoolConfig.setTimeBetweenEvictionRunsMillis(30000);
jedisPoolConfig.setNumTestsPerEvictionRun(-1);
jedisPoolConfig.setMinEvictableIdleTimeMillis(configuration.getInt("redis.MinEvictableIdleTimeMillis",1800000));
jedisPoolConfig.setMaxTotal(configuration.getInt("redis.MaxTotal",8));
jedisPoolConfig.setMaxIdle(configuration.getInt("redis.MaxIdle",8));
jedisPoolConfig.setMinIdle(configuration.getInt("redis.MinIdle",1));
jedisPoolConfig.setMaxWaitMillis(configuration.getInt("redis.MaxWaitMillis",30000));
jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("redis.host","localhost"), configuration.getInt("redis.port",6379));
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] <color:#E1FFFF>Redis Enabled!");
List<Jedis> minIdleJedisList = new ArrayList<>(jedisPoolConfig.getMinIdle());
for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) {
Jedis jedis;
try {
jedis = jedisPool.getResource();
minIdleJedisList.add(jedis);
jedis.ping();
} catch (Exception e) {
Log.warn(e.getMessage());
}
}
for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) {
Jedis jedis;
try {
jedis = minIdleJedisList.get(i);
jedis.close();
} catch (Exception e) {
Log.warn(e.getMessage());
}
}
}
}

View File

@@ -0,0 +1,32 @@
package net.momirealms.customfishing.utils;
public class Modifier {
private int difficulty;
private double score;
private boolean willDouble;
public int getDifficultyModifier() {
return difficulty;
}
public void setDifficultyModifier(int difficulty) {
this.difficulty = difficulty;
}
public double getScoreModifier() {
return score;
}
public void setScoreModifier(double score) {
this.score = score;
}
public boolean willDouble() {
return willDouble;
}
public void setWillDouble(boolean willDouble) {
this.willDouble = willDouble;
}
}

View File

@@ -24,3 +24,5 @@ baits:
difficulty: 3
#双倍掉落概率
double-loot: 0.05
#比赛分数加成
score: 1.2

View File

@@ -1,8 +1,8 @@
example:
#TOTAL_POINTS
#TOTAL_SCORE
#CATCH_AMOUNT
goal: TOTAL_POINTS
goal: TOTAL_SCORE
start-time:
- '5:30'

View File

@@ -15,3 +15,5 @@ commands:
usage: /customfishing
description: main command
permission: customfishing.admin
aliases:
- cfishing

View File

@@ -0,0 +1,9 @@
redis:
enable: false
host: localhost
port: 6379
MaxTotal: 10
MaxIdle: 10
MinIdle: 1
MaxWaitMillis: 30000
MinEvictableIdleTimeMillis: 1800000

View File

@@ -22,3 +22,5 @@ rods:
difficulty: -1
#双倍掉落概率
double-loot: 0.05
#比赛分数加成
score: 1.2