mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-28 03:19:12 +00:00
1.2.19
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'net.momirealms'
|
||||
version = '1.2.18.2'
|
||||
version = '1.2.19'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -17,8 +17,53 @@
|
||||
|
||||
package net.momirealms.customfishing.api;
|
||||
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.competition.Competition;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CustomFishingAPI {
|
||||
|
||||
/**
|
||||
* return null if there's no competition
|
||||
* @return competition
|
||||
*/
|
||||
@Nullable
|
||||
public static Competition getCurrentCompetition() {
|
||||
return Competition.getCurrentCompetition();
|
||||
}
|
||||
|
||||
/**
|
||||
* get a fish's size
|
||||
* @return size
|
||||
*/
|
||||
public static float getFishSize(ItemStack fish) {
|
||||
return CustomFishing.plugin.getFishingManager().getSize(fish);
|
||||
}
|
||||
|
||||
/**
|
||||
* get plugin instance
|
||||
* @return plugin instance
|
||||
*/
|
||||
public static CustomFishing getInstance() {
|
||||
return CustomFishing.plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* get an item's price
|
||||
* @param itemStack item to sell
|
||||
* @return price
|
||||
*/
|
||||
public static double getItemPrice(ItemStack itemStack) {
|
||||
return CustomFishing.plugin.getSellManager().getSingleItemPrice(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* build an itemStack instance from key
|
||||
* @param id item_id
|
||||
* @return itemStack
|
||||
*/
|
||||
public static ItemStack buildItem(String id) {
|
||||
return CustomFishing.plugin.getIntegrationManager().build(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,14 +268,35 @@ public class Competition {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void refreshData(Player player, float score, boolean doubleScore) {
|
||||
if (this.goal == CompetitionGoal.CATCH_AMOUNT) {
|
||||
score = 1f;
|
||||
}
|
||||
if (doubleScore) {
|
||||
score *= 2;
|
||||
if (this.goal == CompetitionGoal.MAX_SIZE) {
|
||||
doubleScore = false;
|
||||
}
|
||||
ranking.refreshData(player.getName(), score);
|
||||
if (this.goal == CompetitionGoal.MAX_SIZE) {
|
||||
if (score > ranking.getPlayerScore(player.getName())) {
|
||||
ranking.setData(player.getName(), score);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ranking.refreshData(player.getName(), doubleScore ? 2 * score : score);
|
||||
}
|
||||
|
||||
public CompetitionGoal getGoal() {
|
||||
return goal;
|
||||
}
|
||||
|
||||
public RankingInterface getRanking() {
|
||||
return ranking;
|
||||
}
|
||||
|
||||
public static Competition getCurrentCompetition() {
|
||||
return currentCompetition;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ public enum CompetitionGoal {
|
||||
|
||||
CATCH_AMOUNT,
|
||||
TOTAL_SCORE,
|
||||
MAX_SIZE,
|
||||
TOTAL_SIZE,
|
||||
RANDOM
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ public class CompetitionPlayer implements Comparable<CompetitionPlayer>{
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setScore(float score){
|
||||
this.score = score;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public float getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class CompetitionSchedule extends Function {
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(CustomFishing.plugin, 60 - LocalTime.now().getSecond(), 200);
|
||||
}.runTaskTimer(CustomFishing.plugin, 60 - LocalTime.now().getSecond(), 100);
|
||||
}
|
||||
|
||||
public void stopCheck() {
|
||||
|
||||
@@ -76,6 +76,16 @@ public class LocalRankingImpl implements RankingInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPlayerScore(String player) {
|
||||
for (CompetitionPlayer competitionPlayer : competitionPlayers) {
|
||||
if (competitionPlayer.getPlayer().equals(player)) {
|
||||
return competitionPlayer.getScore();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitionPlayer[] getTop3Player() {
|
||||
CompetitionPlayer[] competitionPlayers = new CompetitionPlayer[3];
|
||||
@@ -132,6 +142,19 @@ public class LocalRankingImpl implements RankingInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(String player, float score) {
|
||||
CompetitionPlayer competitionPlayer = getCompetitionPlayer(player);
|
||||
if (competitionPlayer != null) {
|
||||
removePlayer(competitionPlayer);
|
||||
competitionPlayer.setScore(score);
|
||||
addPlayer(competitionPlayer);
|
||||
} else {
|
||||
competitionPlayer = new CompetitionPlayer(player, score);
|
||||
addPlayer(competitionPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFirstScore() {
|
||||
return getScoreAt(1);
|
||||
|
||||
@@ -28,8 +28,10 @@ public interface RankingInterface {
|
||||
Iterator<String> getIterator();
|
||||
int getSize();
|
||||
String getPlayerRank(String player);
|
||||
float getPlayerScore(String player);
|
||||
CompetitionPlayer[] getTop3Player();
|
||||
void refreshData(String player, float score);
|
||||
void setData(String player, float score);
|
||||
float getFirstScore();
|
||||
float getSecondScore();
|
||||
float getThirdScore();
|
||||
|
||||
@@ -83,6 +83,17 @@ public class RedisRankingImpl implements RankingInterface {
|
||||
return String.valueOf(rank + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPlayerScore(String player) {
|
||||
Jedis jedis = JedisUtil.getJedis();
|
||||
Double rank = jedis.zscore("cf_competition", player);
|
||||
jedis.close();
|
||||
if(rank == null) {
|
||||
return 0;
|
||||
}
|
||||
return rank.floatValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitionPlayer[] getTop3Player() {
|
||||
CompetitionPlayer[] competitionPlayers = new CompetitionPlayer[3];
|
||||
@@ -113,6 +124,13 @@ public class RedisRankingImpl implements RankingInterface {
|
||||
jedis.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(String player, float score) {
|
||||
Jedis jedis = JedisUtil.getJedis();
|
||||
jedis.zadd("cf_competition", score, player);
|
||||
jedis.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFirstScore() {
|
||||
Jedis jedis = JedisUtil.getJedis();
|
||||
|
||||
@@ -172,7 +172,7 @@ public class BonusManager extends Function {
|
||||
case "time" -> bonus.setTime(config.getDouble(key + ".modifier.time"));
|
||||
case "difficulty" -> bonus.setDifficulty(config.getInt(key + ".modifier.difficulty"));
|
||||
case "double-loot" -> bonus.setDoubleLoot(config.getDouble(key + ".modifier.double-loot"));
|
||||
case "score" -> bonus.setScore(config.getDouble(key + ".modifier.score"));
|
||||
case "score" -> bonus.setScore(config.getDouble(key + ".modifier.score") - 1);
|
||||
case "lava-fishing" -> bonus.setCanLavaFishing(config.getBoolean(key + ".modifier.lava-fishing", false));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.api.event.*;
|
||||
import net.momirealms.customfishing.competition.Competition;
|
||||
import net.momirealms.customfishing.competition.CompetitionGoal;
|
||||
import net.momirealms.customfishing.data.PlayerBagData;
|
||||
import net.momirealms.customfishing.integration.AntiGriefInterface;
|
||||
import net.momirealms.customfishing.integration.MobInterface;
|
||||
@@ -149,7 +150,7 @@ public class FishingManager extends Function {
|
||||
initialBonus.setDifficulty(0);
|
||||
initialBonus.setDoubleLoot(0);
|
||||
initialBonus.setTime(1);
|
||||
initialBonus.setScore(1);
|
||||
initialBonus.setScore(0);
|
||||
initialBonus.setWeightMD(new HashMap<>());
|
||||
initialBonus.setWeightAS(new HashMap<>());
|
||||
|
||||
@@ -400,7 +401,7 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
if (loot instanceof Mob mob) {
|
||||
summonMob(player, loot, item.getLocation(), mob, bonus.getScore());
|
||||
summonMob(player, loot, item.getLocation(), mob, bonus.getScoreBonus());
|
||||
return;
|
||||
}
|
||||
if (loot instanceof DroppedItem droppedItem){
|
||||
@@ -409,7 +410,7 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
}
|
||||
dropCustomFishingLoot(player, item.getLocation(), droppedItem, bonus.getDoubleLoot() > Math.random(), bonus.getScore());
|
||||
dropCustomFishingLoot(player, item.getLocation(), droppedItem, bonus.getDoubleLoot() > Math.random(), bonus.getScoreBonus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +426,7 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
if (loot instanceof Mob mob) {
|
||||
summonMob(player, loot, event.getHook().getLocation(), mob, bonus.getScore());
|
||||
summonMob(player, loot, event.getHook().getLocation(), mob, bonus.getScoreBonus());
|
||||
return;
|
||||
}
|
||||
if (loot instanceof DroppedItem droppedItem) {
|
||||
@@ -434,7 +435,7 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
}
|
||||
dropCustomFishingLoot(player, event.getHook().getLocation(), droppedItem, bonus.getDoubleLoot() > Math.random(), bonus.getScore());
|
||||
dropCustomFishingLoot(player, event.getHook().getLocation(), droppedItem, bonus.getDoubleLoot() > Math.random(), bonus.getScoreBonus());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,6 +444,7 @@ public class FishingManager extends Function {
|
||||
fishingPlayer.cancel();
|
||||
Loot loot = nextLoot.remove(player);
|
||||
VanillaLoot vanilla = vanillaLoot.remove(player);
|
||||
nextBonus.remove(player);
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
if (fishingPlayer.isSuccess()) {
|
||||
if (ConfigManager.rodLoseDurability) loseDurability(player);
|
||||
@@ -504,11 +506,15 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
|
||||
Bonus bonus = nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
float score = (float) (droppedItem.getScore() * scoreMultiplier);
|
||||
Competition.currentCompetition.refreshData(player, (float) (score * bonus.getScore()), isDouble);
|
||||
if (Competition.currentCompetition != null) {
|
||||
float score;
|
||||
if (Competition.currentCompetition.getGoal() == CompetitionGoal.MAX_SIZE || Competition.currentCompetition.getGoal() == CompetitionGoal.TOTAL_SIZE) {
|
||||
score = getSize(drop);
|
||||
}
|
||||
else {
|
||||
score = (float) ((float) droppedItem.getScore() * scoreMultiplier);
|
||||
}
|
||||
Competition.currentCompetition.refreshData(player, score, fishResultEvent.isDouble());
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
@@ -553,10 +559,8 @@ public class FishingManager extends Function {
|
||||
return true;
|
||||
}
|
||||
|
||||
nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
Competition.currentCompetition.refreshData(player, 0, isDouble);
|
||||
if (Competition.currentCompetition != null) {
|
||||
Competition.currentCompetition.refreshData(player, 0, fishResultEvent.isDouble());
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
@@ -596,10 +600,8 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
|
||||
nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
Competition.currentCompetition.refreshData(player, 0, isDouble);
|
||||
Competition.currentCompetition.refreshData(player, 0, fishResultEvent.isDouble());
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
@@ -618,11 +620,15 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
|
||||
Bonus bonus = nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null) {
|
||||
float score = (float) (loot.getScore() * scoreMultiplier);
|
||||
Competition.currentCompetition.refreshData(player, (float) (score * bonus.getScore()), false);
|
||||
float score;
|
||||
if (Competition.currentCompetition.getGoal() == CompetitionGoal.MAX_SIZE || Competition.currentCompetition.getGoal() == CompetitionGoal.TOTAL_SIZE) {
|
||||
score = 0;
|
||||
}
|
||||
else {
|
||||
score = (float) loot.getScore();
|
||||
}
|
||||
Competition.currentCompetition.refreshData(player, (float) (score * scoreMultiplier), false);
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
@@ -714,8 +720,6 @@ public class FishingManager extends Function {
|
||||
action.doOn(player, null);
|
||||
}
|
||||
|
||||
nextBonus.remove(player);
|
||||
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
ConfigManager.failureTitle[new Random().nextInt(ConfigManager.failureTitle.length)],
|
||||
@@ -927,11 +931,11 @@ public class FishingManager extends Function {
|
||||
|
||||
Bonus bonus = nextBonus.get(player);
|
||||
boolean isDouble = false;
|
||||
double scoreMultiplier = 0;
|
||||
double scoreMultiplier = 1;
|
||||
if (bonus != null) {
|
||||
speed += bonus.getDifficulty();
|
||||
isDouble = Math.random() < bonus.getDoubleLoot();
|
||||
scoreMultiplier = bonus.getScore() + 1;
|
||||
scoreMultiplier = bonus.getScoreBonus();
|
||||
}
|
||||
|
||||
if (speed < 1){
|
||||
@@ -1006,4 +1010,13 @@ public class FishingManager extends Function {
|
||||
public void removePlayerFromLavaFishing(Player player) {
|
||||
this.bobberTaskCache.remove(player);
|
||||
}
|
||||
|
||||
public float getSize(ItemStack itemStack) {
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
NBTCompound fishMeta = nbtItem.getCompound("FishMeta");
|
||||
if (fishMeta != null) {
|
||||
return fishMeta.getFloat("size");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +165,16 @@ public class SellManager extends Function {
|
||||
if (config.contains("decorative-icons." + key + ".display.lore")) item.setLore(config.getStringList("decorative-icons." + key + ".display.lore"));
|
||||
if (config.contains("decorative-icons." + key + ".custom-model-data")) item.setCustomModelData(config.getInt("decorative-icons." + key + ".custom-model-data"));
|
||||
ItemStack itemStack = ItemStackUtil.getFromItem(item);
|
||||
for (int slot : config.getIntegerList("decorative-icons." + key + ".slot")) {
|
||||
guiItems.put(slot - 1, itemStack);
|
||||
if (config.contains("decorative-icons." + key + ".slots")) {
|
||||
for (int slot : config.getIntegerList("decorative-icons." + key + ".slots")) {
|
||||
guiItems.put(slot - 1, itemStack);
|
||||
}
|
||||
}
|
||||
// for old version compatibility
|
||||
if (config.contains("decorative-icons." + key + ".slot")) {
|
||||
for (int slot : config.getIntegerList("decorative-icons." + key + ".slot")) {
|
||||
guiItems.put(slot - 1, itemStack);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -354,7 +362,7 @@ public class SellManager extends Function {
|
||||
return totalPrice;
|
||||
}
|
||||
|
||||
private float getSingleItemPrice(ItemStack itemStack) {
|
||||
public float getSingleItemPrice(ItemStack itemStack) {
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
NBTCompound fishMeta = nbtItem.getCompound("FishMeta");
|
||||
float price = 0;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class Bonus {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public double getScore() {
|
||||
private double getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -106,10 +106,14 @@ public class Bonus {
|
||||
if (anotherBonus.getTime() != 0) this.time += (anotherBonus.getTime() - 1);
|
||||
if (anotherBonus.getDoubleLoot() != 0) this.doubleLoot += anotherBonus.getDoubleLoot();
|
||||
if (anotherBonus.getDifficulty() != 0) this.difficulty += anotherBonus.getDifficulty();
|
||||
if (anotherBonus.getScore() != 0) this.score += (anotherBonus.getScore() - 1);
|
||||
if (anotherBonus.getScore() != 0) this.score += anotherBonus.getScore();
|
||||
if (anotherBonus.canLavaFishing()) this.canLavaFishing = true;
|
||||
}
|
||||
|
||||
public double getScoreBonus() {
|
||||
return score + 1;
|
||||
}
|
||||
|
||||
public boolean hasSpecialRod() {
|
||||
return hasSpecialRod;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ example:
|
||||
|
||||
# TOTAL_SCORE
|
||||
# CATCH_AMOUNT
|
||||
# MAX_SIZE
|
||||
# TOTAL_SIZE
|
||||
# RANDOM
|
||||
goal: CATCH_AMOUNT
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ decorative-icons:
|
||||
material: BLACK_STAINED_GLASS_PANE
|
||||
display:
|
||||
name: ' '
|
||||
slot:
|
||||
slots:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
|
||||
Reference in New Issue
Block a user