9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-20 15:39:36 +00:00
This commit is contained in:
XiaoMoMi
2023-07-19 02:42:01 +08:00
parent 76a0930084
commit c7f8eecb21
24 changed files with 299 additions and 203 deletions

View File

@@ -4,7 +4,7 @@ plugins {
} }
group = 'net.momirealms' group = 'net.momirealms'
version = '1.3.2.2' version = '1.3.2.3'
repositories { repositories {
maven {name = "aliyun-repo"; url = "https://maven.aliyun.com/repository/public/"} maven {name = "aliyun-repo"; url = "https://maven.aliyun.com/repository/public/"}
@@ -35,7 +35,7 @@ dependencies {
compileOnly('me.clip:placeholderapi:2.11.3') compileOnly('me.clip:placeholderapi:2.11.3')
compileOnly("com.github.oraxen:oraxen:1.158.0") compileOnly("com.github.oraxen:oraxen:1.158.0")
compileOnly('io.lumine:Mythic-Dist:5.2.1') compileOnly('io.lumine:Mythic-Dist:5.2.1')
compileOnly('dev.dejvokep:boosted-yaml:1.3') compileOnly('dev.dejvokep:boosted-yaml:1.3.1')
compileOnly('com.github.LoneDev6:api-itemsadder:3.4.1-r4') compileOnly('com.github.LoneDev6:api-itemsadder:3.4.1-r4')
compileOnly('net.objecthunter:exp4j:0.4.8') compileOnly('net.objecthunter:exp4j:0.4.8')
compileOnly('org.mariadb.jdbc:mariadb-java-client:3.1.4') compileOnly('org.mariadb.jdbc:mariadb-java-client:3.1.4')

View File

@@ -138,7 +138,7 @@ public final class CustomFishing extends JavaPlugin {
String libRepo = timeZone.getID().startsWith("Asia") ? "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/"; 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("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.3", "https://repo.maven.apache.org/maven2/");
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3", libRepo); LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3.1", libRepo);
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1", libRepo); LibraryLoader.load("com.zaxxer","HikariCP","5.0.1", libRepo);
LibraryLoader.load("net.objecthunter","exp4j","0.4.8", libRepo); LibraryLoader.load("net.objecthunter","exp4j","0.4.8", libRepo);
LibraryLoader.load("org.mariadb.jdbc","mariadb-java-client","3.1.4", libRepo); LibraryLoader.load("org.mariadb.jdbc","mariadb-java-client","3.1.4", libRepo);

View File

@@ -19,7 +19,6 @@ package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.fishing.FishResult; import net.momirealms.customfishing.fishing.FishResult;
import net.momirealms.customfishing.fishing.loot.Loot; import net.momirealms.customfishing.fishing.loot.Loot;
import net.momirealms.customfishing.fishing.loot.LootImpl;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;

View File

@@ -18,7 +18,6 @@
package net.momirealms.customfishing.api.event; package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.fishing.Effect; import net.momirealms.customfishing.fishing.Effect;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;

View File

@@ -26,8 +26,10 @@ public abstract class FishingBar {
protected String[] titles; protected String[] titles;
protected String font; protected String font;
protected String barImage; protected String barImage;
protected String tip;
public FishingBar(ConfigurationSection section) { public FishingBar(ConfigurationSection section) {
this.tip = section.getString("tip");
this.titles = section.getStringList("title").size() == 0 ? new String[]{section.getString("title")} : section.getStringList("title").toArray(new String[0]); this.titles = section.getStringList("title").size() == 0 ? new String[]{section.getString("title")} : section.getStringList("title").toArray(new String[0]);
this.font = section.getString("subtitle.font", "customfishing:bar"); this.font = section.getString("subtitle.font", "customfishing:bar");
this.barImage = section.getString("subtitle.bar",""); this.barImage = section.getString("subtitle.bar","");
@@ -44,4 +46,8 @@ public abstract class FishingBar {
public String getFont() { public String getFont() {
return font; return font;
} }
public String getTip() {
return tip;
}
} }

View File

@@ -28,7 +28,6 @@ public class ModeOneBar extends FishingBar {
private final double[] successRate; private final double[] successRate;
private final int totalWidth; private final int totalWidth;
private final int pointerWidth; private final int pointerWidth;
private final String pointerImage; private final String pointerImage;
private final int pointerOffset; private final int pointerOffset;

View File

@@ -21,80 +21,80 @@ import org.bukkit.configuration.ConfigurationSection;
public class ModeThreeBar extends FishingBar { public class ModeThreeBar extends FishingBar {
private final String fish_image; private final String fishImage;
private final int fish_icon_width; private final int fishIconWidth;
private final String[] strain; private final String[] strain;
private final String[] struggling_fish_image; private final String[] strugglingFishImage;
private final int bar_effective_width; private final int barEffectiveWidth;
private final int fish_offset; private final int fishOffset;
private final int fish_start_position; private final int fishStartPosition;
private final int success_position; private final int successPosition;
private final double ultimate_strain; private final double ultimateStrain;
private final double normal_increase; private final double normalIncrease;
private final double struggling_increase; private final double strugglingIncrease;
private final double strain_loss; private final double strainLoss;
public ModeThreeBar(ConfigurationSection section) { public ModeThreeBar(ConfigurationSection section) {
super(section); super(section);
this.fish_icon_width = section.getInt("arguments.fish-icon-width"); this.fishIconWidth = section.getInt("arguments.fish-icon-width");
this.fish_image = section.getString("subtitle.fish"); this.fishImage = section.getString("subtitle.fish");
this.strain = section.getStringList("strain").toArray(new String[0]); this.strain = section.getStringList("strain").toArray(new String[0]);
this.struggling_fish_image = section.getStringList("subtitle.struggling-fish").toArray(new String[0]); this.strugglingFishImage = section.getStringList("subtitle.struggling-fish").toArray(new String[0]);
this.bar_effective_width = section.getInt("arguments.bar-effective-area-width"); this.barEffectiveWidth = section.getInt("arguments.bar-effective-area-width");
this.fish_offset = section.getInt("arguments.fish-offset"); this.fishOffset = section.getInt("arguments.fish-offset");
this.fish_start_position = section.getInt("arguments.fish-start-position"); this.fishStartPosition = section.getInt("arguments.fish-start-position");
this.success_position = section.getInt("arguments.success-position"); this.successPosition = section.getInt("arguments.success-position");
this.ultimate_strain = section.getDouble("arguments.ultimate-strain", 50); this.ultimateStrain = section.getDouble("arguments.ultimate-strain", 50);
this.normal_increase = section.getDouble("arguments.normal-pull-strain-increase", 1); this.normalIncrease = section.getDouble("arguments.normal-pull-strain-increase", 1);
this.struggling_increase = section.getDouble("arguments.struggling-strain-increase", 2); this.strugglingIncrease = section.getDouble("arguments.struggling-strain-increase", 2);
this.strain_loss = section.getDouble("arguments.loosening-strain-loss", 2); this.strainLoss = section.getDouble("arguments.loosening-strain-loss", 2);
} }
public String getFish_image() { public String getFishImage() {
return fish_image; return fishImage;
} }
public int getFish_icon_width() { public int getFishIconWidth() {
return fish_icon_width; return fishIconWidth;
} }
public String[] getStrain() { public String[] getStrain() {
return strain; return strain;
} }
public int getBar_effective_width() { public int getBarEffectiveWidth() {
return bar_effective_width; return barEffectiveWidth;
} }
public int getFish_offset() { public int getFishOffset() {
return fish_offset; return fishOffset;
} }
public int getFish_start_position() { public int getFishStartPosition() {
return fish_start_position; return fishStartPosition;
} }
public int getSuccess_position() { public int getSuccessPosition() {
return success_position; return successPosition;
} }
public String[] getStruggling_fish_image() { public String[] getStrugglingFishImage() {
return struggling_fish_image; return strugglingFishImage;
} }
public double getUltimate_strain() { public double getUltimateStrain() {
return ultimate_strain; return ultimateStrain;
} }
public double getNormal_increase() { public double getNormalIncrease() {
return normal_increase; return normalIncrease;
} }
public double getStruggling_increase() { public double getStrugglingIncrease() {
return struggling_increase; return strugglingIncrease;
} }
public double getStrain_loss() { public double getStrainLoss() {
return strain_loss; return strainLoss;
} }
} }

View File

@@ -23,63 +23,61 @@ import java.util.Random;
public class ModeTwoBar extends FishingBar { public class ModeTwoBar extends FishingBar {
private final int[] time_requirements; private final int[] timeRequirements;
private final String judgement_area_image; private final String judgementAreaImage;
private final String fish_image; private final String fishImage;
private final int bar_effective_width; private final int barEffectiveWidth;
private final int judgement_area_offset; private final int judgementAreaOffset;
private final int judgement_area_width; private final int judgementAreaWidth;
private final int fish_icon_width; private final int fishIconWidth;
private final String[] progress; private final String[] progress;
private final double punishment; private final double punishment;
private final double water_resistance; private final double waterResistance;
private final double pulling_strength; private final double pullingStrength;
private final double loosening_loss; private final double looseningLoss;
private final boolean sneakMode;
public ModeTwoBar(ConfigurationSection section) { public ModeTwoBar(ConfigurationSection section) {
super(section); super(section);
this.time_requirements = section.getIntegerList("hold-time-requirements").stream().mapToInt(Integer::intValue).toArray(); this.timeRequirements = section.getIntegerList("hold-time-requirements").stream().mapToInt(Integer::intValue).toArray();
this.judgement_area_image = section.getString("subtitle.judgment-area"); this.judgementAreaImage = section.getString("subtitle.judgment-area");
this.fish_image = section.getString("subtitle.fish"); this.fishImage = section.getString("subtitle.fish");
this.bar_effective_width = section.getInt("arguments.bar-effective-area-width"); this.barEffectiveWidth = section.getInt("arguments.bar-effective-area-width");
this.judgement_area_offset = section.getInt("arguments.judgment-area-offset"); this.judgementAreaOffset = section.getInt("arguments.judgment-area-offset");
this.judgement_area_width = section.getInt("arguments.judgment-area-width"); this.judgementAreaWidth = section.getInt("arguments.judgment-area-width");
this.fish_icon_width = section.getInt("arguments.fish-icon-width"); this.fishIconWidth = section.getInt("arguments.fish-icon-width");
this.punishment = section.getDouble("arguments.punishment"); this.punishment = section.getDouble("arguments.punishment");
this.progress = section.getStringList("progress").toArray(new String[0]); this.progress = section.getStringList("progress").toArray(new String[0]);
this.water_resistance = section.getDouble("arguments.water-resistance", 0.15); this.waterResistance = section.getDouble("arguments.water-resistance", 0.15);
this.pulling_strength = section.getDouble("arguments.pulling-strength", 0.45); this.pullingStrength = section.getDouble("arguments.pulling-strength", 0.45);
this.loosening_loss = section.getDouble("arguments.loosening-strength-loss", 0.3); this.looseningLoss = section.getDouble("arguments.loosening-strength-loss", 0.3);
this.sneakMode = section.getString("arguments.pull-method", "sneak").equalsIgnoreCase("sneak");
} }
public int getRandomTimeRequirement() { public int getRandomTimeRequirement() {
return time_requirements[new Random().nextInt(time_requirements.length)] * 20; return timeRequirements[new Random().nextInt(timeRequirements.length)] * 20;
} }
public String getJudgement_area_image() { public String getJudgementAreaImage() {
return judgement_area_image; return judgementAreaImage;
} }
public String getFish_image() { public String getFishImage() {
return fish_image; return fishImage;
} }
public int getBar_effective_width() { public int getBarEffectiveWidth() {
return bar_effective_width; return barEffectiveWidth;
} }
public int getJudgement_area_offset() { public int getJudgementAreaOffset() {
return judgement_area_offset; return judgementAreaOffset;
} }
public int getJudgement_area_width() { public int getJudgementAreaWidth() {
return judgement_area_width; return judgementAreaWidth;
} }
public int getFish_icon_width() { public int getFishIconWidth() {
return fish_icon_width; return fishIconWidth;
} }
public String[] getProgress() { public String[] getProgress() {
@@ -90,19 +88,15 @@ public class ModeTwoBar extends FishingBar {
return punishment; return punishment;
} }
public double getWater_resistance() { public double getWaterResistance() {
return water_resistance; return waterResistance;
} }
public double getPulling_strength() { public double getPullingStrength() {
return pulling_strength; return pullingStrength;
} }
public double getLoosening_loss() { public double getLooseningLoss() {
return loosening_loss; return looseningLoss;
}
public boolean isSneakMode() {
return sneakMode;
} }
} }

View File

@@ -29,6 +29,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import java.time.LocalTime;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
public abstract class FishingGame implements Runnable { public abstract class FishingGame implements Runnable {
@@ -42,8 +43,18 @@ public abstract class FishingGame implements Runnable {
protected String title; protected String title;
protected FishHook fishHook; protected FishHook fishHook;
protected ScheduledFuture<?> gameTask; protected ScheduledFuture<?> gameTask;
protected boolean success;
private int doubleCheckTime;
public FishingGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, FishingBar fishingBar) { public FishingGame(
CustomFishing plugin,
FishingManager fishingManager,
long deadline,
Player player,
int difficulty,
FishingBar fishingBar
) {
this.plugin = plugin;
this.offsetManager = plugin.getOffsetManager(); this.offsetManager = plugin.getOffsetManager();
this.fishingManager = fishingManager; this.fishingManager = fishingManager;
this.player = player; this.player = player;
@@ -51,6 +62,7 @@ public abstract class FishingGame implements Runnable {
this.difficulty = difficulty; this.difficulty = difficulty;
this.title = fishingBar.getRandomTitle(); this.title = fishingBar.getRandomTitle();
this.fishHook = fishingManager.getHook(player.getUniqueId()); this.fishHook = fishingManager.getHook(player.getUniqueId());
this.success = false;
} }
@Override @Override
@@ -79,6 +91,7 @@ public abstract class FishingGame implements Runnable {
} }
protected void switchItemCheck() { protected void switchItemCheck() {
if (!isANewSecond()) return;
PlayerInventory playerInventory = player.getInventory(); PlayerInventory playerInventory = player.getInventory();
if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD) { if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD) {
cancel(); cancel();
@@ -100,4 +113,37 @@ public abstract class FishingGame implements Runnable {
this.gameTask.cancel(false); this.gameTask.cancel(false);
} }
} }
public void success() {
success = true;
proceedTheResult();
cancel();
}
public void fail() {
success = false;
proceedTheResult();
cancel();
}
public void proceedTheResult() {
plugin.getScheduler().runTask(() -> {
FishHook fishHook = fishingManager.getHook(player.getUniqueId());
if (fishHook != null) {
fishingManager.proceedReelIn(fishHook.getLocation(), player, this);
fishingManager.removeHook(player.getUniqueId());
fishingManager.removeFishingPlayer(player);
}
}, fishHook.getLocation());
}
private boolean isANewSecond() {
int minute = LocalTime.now().getSecond();
if (doubleCheckTime != minute) {
doubleCheckTime = minute;
return true;
} else {
return false;
}
}
} }

View File

@@ -31,11 +31,18 @@ public class ModeOneGame extends FishingGame {
private boolean face; private boolean face;
private final ModeOneBar modeOneBar; private final ModeOneBar modeOneBar;
public ModeOneGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, ModeOneBar modeOneBar) { public ModeOneGame(
CustomFishing plugin,
FishingManager fishingManager,
long deadline,
Player player,
int difficulty,
ModeOneBar modeOneBar
) {
super(plugin, fishingManager, deadline, player, difficulty, modeOneBar); super(plugin, fishingManager, deadline, player, difficulty, modeOneBar);
this.face = true; this.face = true;
this.modeOneBar = modeOneBar; this.modeOneBar = modeOneBar;
this.gameTask = plugin.getScheduler().runTaskTimer(this, 50, 54 - difficulty * 4L, TimeUnit.MILLISECONDS); this.gameTask = plugin.getScheduler().runTaskTimerAsync(this, 50, Math.max(55 - difficulty * 5L, 5), TimeUnit.MILLISECONDS);
this.progress = -1; this.progress = -1;
} }

View File

@@ -30,19 +30,27 @@ public class ModeThreeGame extends FishingGame {
private final ModeThreeBar modeThreeBar; private final ModeThreeBar modeThreeBar;
private int fish_position; private int fish_position;
private boolean success;
private int timer; private int timer;
private final int timer_max; private final int timer_max;
private double strain; private double strain;
private int struggling_time; private int struggling_time;
private boolean played;
public ModeThreeGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, ModeThreeBar modeThreeBar) { public ModeThreeGame(
CustomFishing plugin,
FishingManager fishingManager,
long deadline,
Player player,
int difficulty,
ModeThreeBar modeThreeBar
) {
super(plugin, fishingManager, deadline, player, difficulty, modeThreeBar); super(plugin, fishingManager, deadline, player, difficulty, modeThreeBar);
this.fish_position = modeThreeBar.getFish_start_position(); this.fish_position = modeThreeBar.getFishStartPosition();
this.success = false; this.success = false;
this.modeThreeBar = modeThreeBar; this.modeThreeBar = modeThreeBar;
this.timer_max = modeThreeBar.getStruggling_fish_image().length; this.timer_max = modeThreeBar.getStrugglingFishImage().length;
this.gameTask = plugin.getScheduler().runTaskTimer(this, 50, 40, TimeUnit.MILLISECONDS); this.gameTask = plugin.getScheduler().runTaskTimerAsync(this, 50, 40, TimeUnit.MILLISECONDS);
this.played = false;
} }
@Override @Override
@@ -53,65 +61,57 @@ public class ModeThreeGame extends FishingGame {
timer = 0; timer = 0;
} }
if (struggling_time <= 0) { if (struggling_time <= 0) {
if (Math.random() < ((double) difficulty / 200)) { if (Math.random() < ((double) difficulty / 300)) {
struggling_time = (int) (20 + Math.random() * difficulty * 3); struggling_time = (int) (15 + Math.random() * difficulty * 3);
} }
} } else {
else {
struggling_time--; struggling_time--;
} }
if (player.isSneaking()) pull(); if (player.isSneaking()) pull();
else loosen(); else loosen();
if (fish_position < modeThreeBar.getSuccess_position() - modeThreeBar.getFish_icon_width() - 1) { if (fish_position < modeThreeBar.getSuccessPosition() - modeThreeBar.getFishIconWidth() - 1) {
success = true; success();
FishHook fishHook = fishingManager.getHook(player.getUniqueId());
if (fishHook != null) {
fishingManager.proceedReelIn(fishHook.getLocation(), player, this);
fishingManager.removeHook(player.getUniqueId());
}
fishingManager.removeFishingPlayer(player);
cancel();
return; return;
} }
if (fish_position + modeThreeBar.getFish_icon_width() > modeThreeBar.getBar_effective_width() || strain >= modeThreeBar.getUltimate_strain()) { if (fish_position + modeThreeBar.getFishIconWidth() > modeThreeBar.getBarEffectiveWidth() || strain >= modeThreeBar.getUltimateStrain()) {
FishHook fishHook = fishingManager.getHook(player.getUniqueId()); fail();
if (fishHook != null) {
fishingManager.proceedReelIn(fishHook.getLocation(), player, this);
fishingManager.removeHook(player.getUniqueId());
}
fishingManager.removeFishingPlayer(player);
cancel();
return; return;
} }
showBar(); showBar();
} }
public void pull() { public void pull() {
played = true;
if (struggling_time > 0) { if (struggling_time > 0) {
strain += (modeThreeBar.getStruggling_increase() + ((double) difficulty / 5)); strain += (modeThreeBar.getStrugglingIncrease() + ((double) difficulty / 5));
fish_position -= 1; fish_position -= 1;
} else { } else {
strain += modeThreeBar.getNormal_increase(); strain += modeThreeBar.getNormalIncrease();
fish_position -= 2; fish_position -= 2;
} }
} }
public void loosen() { public void loosen() {
fish_position++; fish_position++;
strain -= modeThreeBar.getStrain_loss(); strain -= modeThreeBar.getStrainLoss();
} }
@Override @Override
public void showBar() { public void showBar() {
String bar = "<font:" + modeThreeBar.getFont() + ">" + modeThreeBar.getBarImage() String bar = "<font:" + modeThreeBar.getFont() + ">" + modeThreeBar.getBarImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars(modeThreeBar.getFish_offset() + fish_position) + "</font>" + "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars(modeThreeBar.getFishOffset() + fish_position) + "</font>"
+ (struggling_time > 0 ? modeThreeBar.getStruggling_fish_image()[timer] : modeThreeBar.getFish_image()) + (struggling_time > 0 ? modeThreeBar.getStrugglingFishImage()[timer] : modeThreeBar.getFishImage())
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars(modeThreeBar.getBar_effective_width() - fish_position - modeThreeBar.getFish_icon_width()) + "</font>" + "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars(modeThreeBar.getBarEffectiveWidth() - fish_position - modeThreeBar.getFishIconWidth()) + "</font>"
+ "</font>"; + "</font>";
strain = Math.max(0, Math.min(strain, modeThreeBar.getUltimate_strain())); strain = Math.max(0, Math.min(strain, modeThreeBar.getUltimateStrain()));
AdventureUtils.playerTitle(player, AdventureUtils.playerTitle(
title.replace("{strain}", modeThreeBar.getStrain()[(int) ((strain / modeThreeBar.getUltimate_strain()) * modeThreeBar.getStrain().length)]) player,
, bar,0,500,0 modeThreeBar.getTip() != null && !played ? modeThreeBar.getTip() :
title.replace("{strain}", modeThreeBar.getStrain()[(int) ((strain / modeThreeBar.getUltimateStrain()) * modeThreeBar.getStrain().length)]),
bar,
0,
500,
0
); );
} }

View File

@@ -25,12 +25,12 @@ import net.momirealms.customfishing.util.LocationUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerFishEvent;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class ModeTwoGame extends FishingGame { public class ModeTwoGame extends FishingGame {
private boolean success;
private double hold_time; private double hold_time;
private final ModeTwoBar modeTwoBar; private final ModeTwoBar modeTwoBar;
private double judgement_position; private double judgement_position;
@@ -39,35 +39,34 @@ public class ModeTwoGame extends FishingGame {
private double fish_velocity; private double fish_velocity;
private int timer; private int timer;
private final int time_requirement; private final int time_requirement;
private final Location hookLoc; private boolean played;
private double distance;
public ModeTwoGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, ModeTwoBar modeTwoBar, Location hookLoc) { public ModeTwoGame(
CustomFishing plugin,
FishingManager fishingManager,
long deadline,
Player player,
int difficulty,
ModeTwoBar modeTwoBar,
Location hookLoc
) {
super(plugin, fishingManager, deadline, player, difficulty, modeTwoBar); super(plugin, fishingManager, deadline, player, difficulty, modeTwoBar);
this.success = false; this.success = false;
this.judgement_position = (double) (modeTwoBar.getBar_effective_width() - modeTwoBar.getJudgement_area_width()) / 2; this.judgement_position = (double) (modeTwoBar.getBarEffectiveWidth() - modeTwoBar.getJudgementAreaWidth()) / 2;
this.fish_position = 0; this.fish_position = 0;
this.timer = 0; this.timer = 0;
this.modeTwoBar = modeTwoBar; this.modeTwoBar = modeTwoBar;
this.time_requirement = modeTwoBar.getRandomTimeRequirement(); this.time_requirement = modeTwoBar.getRandomTimeRequirement();
this.hookLoc = hookLoc; this.played = false;
this.distance = LocationUtils.getDistance(player.getLocation(), hookLoc); this.gameTask = plugin.getScheduler().runTaskTimerAsync(this, 50, 40, TimeUnit.MILLISECONDS);
this.gameTask = plugin.getScheduler().runTaskTimer(this, 50, 33, TimeUnit.MILLISECONDS);
} }
@Override @Override
public void run() { public void run() {
super.run(); super.run();
if (modeTwoBar.isSneakMode()) { if (player.isSneaking()) addV();
if (player.isSneaking()) addV(true);
else reduceV(); else reduceV();
} else { if (timer < 40 - difficulty) {
double newDistance = LocationUtils.getDistance(player.getLocation(), hookLoc);
if (distance < newDistance) addV(true);
else if (distance > newDistance) addV(false);
distance = newDistance;
}
if (timer < 30) {
timer++; timer++;
} else { } else {
timer = 0; timer = 0;
@@ -77,24 +76,15 @@ public class ModeTwoGame extends FishingGame {
} }
judgement_position += judgement_velocity; judgement_position += judgement_velocity;
fish_position += fish_velocity; fish_position += fish_velocity;
fraction(); fraction();
calibrate(); calibrate();
if (fish_position >= judgement_position - 2 && fish_position + modeTwoBar.getFishIconWidth() <= judgement_position + modeTwoBar.getJudgementAreaWidth() + 2) {
if (fish_position >= judgement_position - 2 && fish_position + modeTwoBar.getFish_icon_width() <= judgement_position + modeTwoBar.getJudgement_area_width() + 2) {
hold_time += 0.66; hold_time += 0.66;
} else { } else {
hold_time -= modeTwoBar.getPunishment() * 0.66; hold_time -= modeTwoBar.getPunishment() * 0.66;
} }
if (hold_time >= time_requirement) { if (hold_time >= time_requirement) {
success = true; success();
FishHook fishHook = fishingManager.getHook(player.getUniqueId());
if (fishHook != null) {
fishingManager.proceedReelIn(fishHook.getLocation(), player, this);
fishingManager.removeHook(player.getUniqueId());
}
fishingManager.removeFishingPlayer(player);
cancel();
return; return;
} }
showBar(); showBar();
@@ -103,22 +93,28 @@ public class ModeTwoGame extends FishingGame {
@Override @Override
public void showBar() { public void showBar() {
String bar = "<font:" + modeTwoBar.getFont() + ">" + modeTwoBar.getBarImage() String bar = "<font:" + modeTwoBar.getFont() + ">" + modeTwoBar.getBarImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getJudgement_area_offset() + judgement_position)) + "</font>" + "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getJudgementAreaOffset() + judgement_position)) + "</font>"
+ modeTwoBar.getJudgement_area_image() + modeTwoBar.getJudgementAreaImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - judgement_position - modeTwoBar.getJudgement_area_width())) + "</font>" + "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBarEffectiveWidth() - judgement_position - modeTwoBar.getJudgementAreaWidth())) + "</font>"
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (-modeTwoBar.getBar_effective_width() - 1 + fish_position)) + "</font>" + "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (-modeTwoBar.getBarEffectiveWidth() - 1 + fish_position)) + "</font>"
+ modeTwoBar.getFish_image() + modeTwoBar.getFishImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - fish_position - modeTwoBar.getFish_icon_width() + 1)) + "</font>" + "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBarEffectiveWidth() - fish_position - modeTwoBar.getFishIconWidth() + 1)) + "</font>"
+ "</font>"; + "</font>";
hold_time = Math.max(0, Math.min(hold_time, time_requirement)); hold_time = Math.max(0, Math.min(hold_time, time_requirement));
AdventureUtils.playerTitle(player, AdventureUtils.playerTitle(
player,
modeTwoBar.getTip() != null && !played ? modeTwoBar.getTip() :
title.replace("{progress}", modeTwoBar.getProgress()[(int) ((hold_time / time_requirement) * modeTwoBar.getProgress().length)]) title.replace("{progress}", modeTwoBar.getProgress()[(int) ((hold_time / time_requirement) * modeTwoBar.getProgress().length)])
, bar,0,500,0 ,
bar,
0,
500,
0
); );
} }
private void burst() { private void burst() {
if (Math.random() < (judgement_position / modeTwoBar.getBar_effective_width())) { if (Math.random() < (judgement_position / modeTwoBar.getBarEffectiveWidth())) {
judgement_velocity = -1 - 0.8 * Math.random() * difficulty; judgement_velocity = -1 - 0.8 * Math.random() * difficulty;
} else { } else {
judgement_velocity = 1 + 0.8 * Math.random() * difficulty; judgement_velocity = 1 + 0.8 * Math.random() * difficulty;
@@ -127,21 +123,21 @@ public class ModeTwoGame extends FishingGame {
private void fraction() { private void fraction() {
if (judgement_velocity > 0) { if (judgement_velocity > 0) {
judgement_velocity -= modeTwoBar.getWater_resistance(); judgement_velocity -= modeTwoBar.getWaterResistance();
if (judgement_velocity < 0) judgement_velocity = 0; if (judgement_velocity < 0) judgement_velocity = 0;
} else { } else {
judgement_velocity += modeTwoBar.getWater_resistance(); judgement_velocity += modeTwoBar.getWaterResistance();
if (judgement_velocity > 0) judgement_velocity = 0; if (judgement_velocity > 0) judgement_velocity = 0;
} }
} }
private void reduceV() { private void reduceV() {
fish_velocity -= modeTwoBar.getLoosening_loss(); fish_velocity -= modeTwoBar.getLooseningLoss();
} }
private void addV(boolean add) { private void addV() {
if (add) fish_velocity += modeTwoBar.getPulling_strength(); played = true;
else fish_velocity -= modeTwoBar.getPulling_strength(); fish_velocity += modeTwoBar.getPullingStrength();
} }
private void calibrate() { private void calibrate() {
@@ -149,16 +145,16 @@ public class ModeTwoGame extends FishingGame {
fish_position = 0; fish_position = 0;
fish_velocity = 0; fish_velocity = 0;
} }
if (fish_position + modeTwoBar.getFish_icon_width() > modeTwoBar.getBar_effective_width()) { if (fish_position + modeTwoBar.getFishIconWidth() > modeTwoBar.getBarEffectiveWidth()) {
fish_position = modeTwoBar.getBar_effective_width() - modeTwoBar.getFish_icon_width(); fish_position = modeTwoBar.getBarEffectiveWidth() - modeTwoBar.getFishIconWidth();
fish_velocity = 0; fish_velocity = 0;
} }
if (judgement_position < 0) { if (judgement_position < 0) {
judgement_position = 0; judgement_position = 0;
judgement_velocity = 0; judgement_velocity = 0;
} }
if (judgement_position + modeTwoBar.getJudgement_area_width() > modeTwoBar.getBar_effective_width()) { if (judgement_position + modeTwoBar.getJudgementAreaWidth() > modeTwoBar.getBarEffectiveWidth()) {
judgement_position = modeTwoBar.getBar_effective_width() - modeTwoBar.getJudgement_area_width(); judgement_position = modeTwoBar.getBarEffectiveWidth() - modeTwoBar.getJudgementAreaWidth();
judgement_velocity = 0; judgement_velocity = 0;
} }
} }

View File

@@ -1,6 +1,5 @@
package net.momirealms.customfishing.integration; package net.momirealms.customfishing.integration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.List; import java.util.List;

View File

@@ -1,7 +1,6 @@
package net.momirealms.customfishing.integration.item; package net.momirealms.customfishing.integration.item;
import net.momirealms.customfishing.integration.ItemInterface; import net.momirealms.customfishing.integration.ItemInterface;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View File

@@ -22,7 +22,6 @@ import io.github.battlepass.quests.quests.external.executor.ExternalQuestExecuto
import io.github.battlepass.registry.quest.QuestRegistry; import io.github.battlepass.registry.quest.QuestRegistry;
import net.momirealms.customfishing.api.event.FishResultEvent; import net.momirealms.customfishing.api.event.FishResultEvent;
import net.momirealms.customfishing.fishing.FishResult; import net.momirealms.customfishing.fishing.FishResult;
import net.momirealms.customfishing.helper.Log;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@@ -22,7 +22,6 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.api.event.FishResultEvent; import net.momirealms.customfishing.api.event.FishResultEvent;
import net.momirealms.customfishing.fishing.FishResult; import net.momirealms.customfishing.fishing.FishResult;
import net.momirealms.customfishing.fishing.loot.Loot; import net.momirealms.customfishing.fishing.loot.Loot;
import net.momirealms.customfishing.fishing.loot.LootImpl;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@@ -21,7 +21,6 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
import net.momirealms.customfishing.integration.SkillInterface; import net.momirealms.customfishing.integration.SkillInterface;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@@ -364,8 +364,7 @@ public class FishingManager extends Function {
} }
//else vanilla fishing mechanic //else vanilla fishing mechanic
} }
} } else {
else {
// No custom loot // No custom loot
if (loot == null) { if (loot == null) {
event.setCancelled(true); event.setCancelled(true);
@@ -381,8 +380,7 @@ public class FishingManager extends Function {
showFishingBar(player, loot); showFishingBar(player, loot);
} }
} }
} } else {
else {
event.setCancelled(true); event.setCancelled(true);
removeHook(uuid); removeHook(uuid);
proceedReelIn(event.getHook().getLocation(), player, fishingGame); proceedReelIn(event.getHook().getLocation(), player, fishingGame);
@@ -992,7 +990,7 @@ public class FishingManager extends Function {
} }
public void removeHook(UUID uuid) { public void removeHook(UUID uuid) {
FishHook fishHook = hooks.remove(uuid); FishHook fishHook = removeHookCache(uuid);
if (fishHook != null) { if (fishHook != null) {
if (plugin.getVersionHelper().isFolia()) { if (plugin.getVersionHelper().isFolia()) {
plugin.getScheduler().runTask(fishHook::remove, fishHook.getLocation()); plugin.getScheduler().runTask(fishHook::remove, fishHook.getLocation());
@@ -1002,6 +1000,10 @@ public class FishingManager extends Function {
} }
} }
public FishHook removeHookCache(UUID uuid) {
return hooks.remove(uuid);
}
@Nullable @Nullable
public FishHook getHook(UUID uuid) { public FishHook getHook(UUID uuid) {
return hooks.get(uuid); return hooks.get(uuid);

View File

@@ -0,0 +1,22 @@
package net.momirealms.customfishing.scheduler;
import org.bukkit.scheduler.BukkitTask;
public class BukkitTimerTask implements TimerTask {
private final BukkitTask bukkitTask;
public BukkitTimerTask(BukkitTask bukkitTask) {
this.bukkitTask = bukkitTask;
}
@Override
public void cancel() {
this.bukkitTask.cancel();
}
@Override
public boolean isCancelled() {
return bukkitTask.isCancelled();
}
}

View File

@@ -0,0 +1,22 @@
package net.momirealms.customfishing.scheduler;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
public class FoliaTimerTask implements TimerTask {
private final ScheduledTask timerTask;
public FoliaTimerTask(ScheduledTask timerTask) {
this.timerTask = timerTask;
}
@Override
public void cancel() {
this.timerTask.cancel();
}
@Override
public boolean isCancelled() {
return timerTask.isCancelled();
}
}

View File

@@ -36,15 +36,15 @@ public class Scheduler extends Function {
} else { } else {
this.schedulerPlatform = new BukkitSchedulerImpl(plugin); this.schedulerPlatform = new BukkitSchedulerImpl(plugin);
} }
this.schedule = new ScheduledThreadPoolExecutor(1); this.schedule = new ScheduledThreadPoolExecutor(4);
this.schedule.setMaximumPoolSize(1); this.schedule.setMaximumPoolSize(4);
this.schedule.setKeepAliveTime(10, TimeUnit.SECONDS); this.schedule.setKeepAliveTime(10, TimeUnit.SECONDS);
this.schedule.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); this.schedule.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
} }
public void reload() { public void reload() {
this.schedule.setCorePoolSize(ConfigManager.corePoolSize); this.schedule.setCorePoolSize(Math.max(ConfigManager.corePoolSize, 4));
this.schedule.setMaximumPoolSize(ConfigManager.maximumPoolSize); this.schedule.setMaximumPoolSize(Math.max(Math.max(ConfigManager.maximumPoolSize, 4), ConfigManager.corePoolSize));
this.schedule.setKeepAliveTime(ConfigManager.keepAliveTime, TimeUnit.SECONDS); this.schedule.setKeepAliveTime(ConfigManager.keepAliveTime, TimeUnit.SECONDS);
} }

View File

@@ -0,0 +1,8 @@
package net.momirealms.customfishing.scheduler;
public interface TimerTask {
void cancel();
boolean isCancelled();
}

View File

@@ -187,11 +187,12 @@ other-settings:
# 线程池设置 # 线程池设置
thread-pool-settings: thread-pool-settings:
# The size of the core Thread pool, that is, the size of the Thread pool when there is no task to execute # The size of the core Thread pool, that is, the size of the Thread pool when there is no task to execute
# Increase the size of corePoolSize when you are running a large server with many players fishing at the same time
# 核心线程池大小,即在没有任务需要执行的时候线程池的大小 # 核心线程池大小,即在没有任务需要执行的时候线程池的大小
corePoolSize: 1 corePoolSize: 4
# The maximum number of threads allowed to be created in the Thread pool. The current number of threads in the Thread pool will not exceed this value # The maximum number of threads allowed to be created in the Thread pool. The current number of threads in the Thread pool will not exceed this value
# 线程池中允许创建的最大线程数,线程池中的当前线程数目不会超过该值 # 线程池中允许创建的最大线程数,线程池中的当前线程数目不会超过该值
maximumPoolSize: 4 maximumPoolSize: 8
# If a thread is idle for more than this attribute value, it will exit due to timeout # If a thread is idle for more than this attribute value, it will exit due to timeout
# 如果一个线程处在空闲状态的时间超过了该属性值,就会因为超时而退出(秒) # 如果一个线程处在空闲状态的时间超过了该属性值,就会因为超时而退出(秒)
keepAliveTime: 10 keepAliveTime: 10

View File

@@ -507,14 +507,14 @@ bar_9:
bar_10: bar_10:
game-type: 2 game-type: 2
title: '{progress}' title: '{progress}'
# Tip would show on the title to guide the player how to play
tip: '<gray>Press <red><key:key.sneak> <gray>to start'
subtitle: subtitle:
font: 'customfishing:default' font: 'customfishing:default'
bar: '뀌' bar: '뀌'
judgment-area: '뀍' judgment-area: '뀍'
fish: '뀎' fish: '뀎'
arguments: arguments:
# sneak / move
pull-method: sneak
punishment: 0.2 punishment: 0.2
bar-effective-area-width: 155 bar-effective-area-width: 155
judgment-area-offset: -160 judgment-area-offset: -160
@@ -540,13 +540,14 @@ bar_10:
- '<font:customfishing:icons>뀈</font>' - '<font:customfishing:icons>뀈</font>'
- '<font:customfishing:icons>뀉</font>' - '<font:customfishing:icons>뀉</font>'
############### ###############
# Game Type 3 # # Game Type 3 #
############### ###############
bar_11: bar_11:
game-type: 3 game-type: 3
title: '{strain}' title: '{strain}'
# Tip would show on the title to guide the player how to play
tip: '<gray>Press <red><key:key.sneak> <gray>to start'
subtitle: subtitle:
font: 'customfishing:default' font: 'customfishing:default'
bar: '뀓' bar: '뀓'
@@ -576,4 +577,3 @@ bar_11:
- '<font:customfishing:icons>뀗</font>' - '<font:customfishing:icons>뀗</font>'
- '<font:customfishing:icons>뀘</font>' - '<font:customfishing:icons>뀘</font>'
- '<font:customfishing:icons>뀙</font>' - '<font:customfishing:icons>뀙</font>'