9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 03:49:07 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-10 18:27:57 +08:00
parent 6d44100b93
commit 0823b09463
12 changed files with 280 additions and 123 deletions

View File

@@ -146,6 +146,7 @@ public class ConfigReader{
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#00BFFF>PlaceholderAPI <color:#E1FFFF>Hooked!");
}
}
skillXP = null;
if(config.getBoolean("config.integrations.mcMMO",false)){
@@ -173,7 +174,6 @@ public class ConfigReader{
}
}
season = config.getBoolean("config.season.enable");
if (!papi && season) {
season = false;
@@ -189,6 +189,7 @@ public class ConfigReader{
convertMMOItems = config.getBoolean("config.convert-MMOITEMS");
needOpenWater = config.getBoolean("config.need-open-water");
needSpecialRod = config.getBoolean("config.need-special-rod");
fishFinderCoolDown = config.getInt("config.fishfinder-cooldown");
timeMultiply = config.getDouble("config.time-multiply");
lang = config.getString("config.lang","cn");

View File

@@ -18,6 +18,7 @@
package net.momirealms.customfishing;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.momirealms.customfishing.command.Execute;
import net.momirealms.customfishing.command.TabComplete;
import net.momirealms.customfishing.competition.CompetitionSchedule;
@@ -35,6 +36,7 @@ public final class CustomFishing extends JavaPlugin {
public static JavaPlugin instance;
public static BukkitAudiences adventure;
public static MiniMessage miniMessage;
private CompetitionSchedule competitionSchedule;
@Override
@@ -48,6 +50,7 @@ public final class CustomFishing extends JavaPlugin {
@Override
public void onEnable() {
adventure = BukkitAudiences.create(this);
miniMessage = MiniMessage.miniMessage();
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setExecutor(new Execute());
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setTabCompleter(new TabComplete());
Bukkit.getPluginManager().registerEvents(new PlayerListener(),this);

View File

@@ -45,6 +45,9 @@ public class Execute implements CommandExecutor {
}
if (sender instanceof Player player){
SaveItem.saveToFile(player.getInventory().getItemInMainHand(), args[1]);
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + "Done!");
}else {
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
}
return true;
}
@@ -311,7 +314,6 @@ public class Execute implements CommandExecutor {
return true;
}
private void lackArgs(CommandSender sender){
if (sender instanceof Player){
AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.lackArgs);

View File

@@ -20,28 +20,53 @@ public class TabComplete implements TabCompleter {
return null;
}
if (args.length == 1){
return Arrays.asList("competition","reload","items","export");
List<String> arrayList = new ArrayList<>();
for (String cmd : Arrays.asList("competition","reload","items","export")) {
if (cmd.startsWith(args[0]))
arrayList.add(cmd);
}
return arrayList;
}
if (args.length == 2){
if (args[0].equalsIgnoreCase("items")){
return Arrays.asList("loot","bait","rod","util");
List<String> arrayList = new ArrayList<>();
for (String cmd : Arrays.asList("loot","bait","rod","util")) {
if (cmd.startsWith(args[1]))
arrayList.add(cmd);
}
return arrayList;
}
if (args[0].equalsIgnoreCase("export")){
return List.of("FileName");
}
if (args[0].equalsIgnoreCase("competition")){
return List.of("start","end","cancel");
List<String> arrayList = new ArrayList<>();
for (String cmd : List.of("start","end","cancel")) {
if (cmd.startsWith(args[1]))
arrayList.add(cmd);
}
return arrayList;
}
}
if (args.length == 3){
if (args[0].equalsIgnoreCase("items")){
if (args[1].equalsIgnoreCase("loot") || args[1].equalsIgnoreCase("util") || args[1].equalsIgnoreCase("rod") || args[1].equalsIgnoreCase("bait")){
return Arrays.asList("get","give");
List<String> arrayList = new ArrayList<>();
for (String cmd : Arrays.asList("get","give")) {
if (cmd.startsWith(args[2]))
arrayList.add(cmd);
}
return arrayList;
}
}
if (args[0].equalsIgnoreCase("competition")){
if (args[1].equalsIgnoreCase("start")){
return competitions();
List<String> arrayList = new ArrayList<>();
for (String cmd : competitions()) {
if (cmd.startsWith(args[2]))
arrayList.add(cmd);
}
return arrayList;
}
}
}
@@ -49,31 +74,71 @@ public class TabComplete implements TabCompleter {
if (args[0].equalsIgnoreCase("items")){
if (args[1].equalsIgnoreCase("loot")){
if (args[2].equalsIgnoreCase("give")){
return online_players();
List<String> arrayList = new ArrayList<>();
for (String cmd : online_players()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
if (args[2].equalsIgnoreCase("get")){
return loots();
List<String> arrayList = new ArrayList<>();
for (String cmd : loots()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
}else if (args[1].equalsIgnoreCase("util")){
if (args[2].equalsIgnoreCase("give")){
return online_players();
List<String> arrayList = new ArrayList<>();
for (String cmd : online_players()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
if (args[2].equalsIgnoreCase("get")){
return utils();
List<String> arrayList = new ArrayList<>();
for (String cmd : utils()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
}else if (args[1].equalsIgnoreCase("rod")){
if (args[2].equalsIgnoreCase("give")){
return online_players();
List<String> arrayList = new ArrayList<>();
for (String cmd : online_players()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
if (args[2].equalsIgnoreCase("get")){
return rods();
List<String> arrayList = new ArrayList<>();
for (String cmd : rods()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
}else if (args[1].equalsIgnoreCase("bait")){
if (args[2].equalsIgnoreCase("give")){
return online_players();
List<String> arrayList = new ArrayList<>();
for (String cmd : online_players()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
if (args[2].equalsIgnoreCase("get")){
return baits();
List<String> arrayList = new ArrayList<>();
for (String cmd : baits()) {
if (cmd.startsWith(args[3]))
arrayList.add(cmd);
}
return arrayList;
}
}
}
@@ -82,20 +147,40 @@ public class TabComplete implements TabCompleter {
if (args[0].equalsIgnoreCase("items")){
if (args[1].equalsIgnoreCase("loot")){
if (args[2].equalsIgnoreCase("give")){
return loots();
List<String> arrayList = new ArrayList<>();
for (String cmd : loots()) {
if (cmd.startsWith(args[4]))
arrayList.add(cmd);
}
return arrayList;
}
}else if (args[1].equalsIgnoreCase("util")){
if (args[2].equalsIgnoreCase("give")){
return utils();
List<String> arrayList = new ArrayList<>();
for (String cmd : utils()) {
if (cmd.startsWith(args[4]))
arrayList.add(cmd);
}
return arrayList;
}
}else if (args[1].equalsIgnoreCase("rod")){
if (args[2].equalsIgnoreCase("give")){
return rods();
List<String> arrayList = new ArrayList<>();
for (String cmd : rods()) {
if (cmd.startsWith(args[4]))
arrayList.add(cmd);
}
return arrayList;
}
}
else if (args[1].equalsIgnoreCase("bait")){
if (args[2].equalsIgnoreCase("give")){
return baits();
List<String> arrayList = new ArrayList<>();
for (String cmd : baits()) {
if (cmd.startsWith(args[4]))
arrayList.add(cmd);
}
return arrayList;
}
}
}

View File

@@ -189,8 +189,8 @@ public class Competition {
}
public void cancel() {
ranking.clear();
BossBarManager.stopAllTimer();
ranking.clear();
this.timerTask.cancel();
status = false;
}

View File

@@ -20,7 +20,7 @@ package net.momirealms.customfishing.competition.bossbar;
import net.kyori.adventure.bossbar.BossBar;
public record BossBarConfig(String text, BossBar.Overlay overlay,
BossBar.Color color, int rate) {
BossBar.Color color, int rate){
public BossBar.Color getColor() {return color;}
public int getRate() {return rate;}

View File

@@ -19,7 +19,6 @@ package net.momirealms.customfishing.competition.bossbar;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.competition.Competition;
@@ -36,17 +35,19 @@ public class BossBarSender extends BukkitRunnable {
private final Audience audience;
private BossBar bossBar;
private int timer;
private final BossBarConfig bossbarConfig;
private final BossBar.Color color;
private final BossBar.Overlay overlay;
private final String text;
private final int rate;
public BossBarSender(Player player, BossBarConfig bossbarConfig){
this.player = player;
this.bossbarConfig = bossbarConfig;
this.audience = CustomFishing.adventure.player(player);
this.timer = 0;
this.color = bossbarConfig.getColor();
this.overlay = bossbarConfig.getOverlay();
this.text = bossbarConfig.getText();
this.rate = bossbarConfig.getRate();
}
public void hideBossbar(){
@@ -54,18 +55,9 @@ public class BossBarSender extends BukkitRunnable {
}
public void showBossbar(){
String text;
if (ConfigReader.Config.papi){
text = PapiHook.parse(player, bossbarConfig.getText());
}else {
text = bossbarConfig.getText();
}
String newText = updateText();
bossBar = BossBar.bossBar(
MiniMessage.miniMessage().deserialize(text.replace("{time}", String.valueOf(Competition.remainingTime))
.replace("{rank}", Optional.ofNullable(CompetitionSchedule.competition.getRanking().getPlayerRank(player.getName())).orElse(ConfigReader.Message.noRank))
.replace("{minute}", String.format("%02d",Competition.remainingTime/60))
.replace("{second}",String.format("%02d",Competition.remainingTime%60))
.replace("{point}", String.format("%.1f",Optional.ofNullable(CompetitionSchedule.competition.getRanking().getCompetitionPlayer(player.getName())).orElse(Competition.emptyPlayer).getScore()))),
CustomFishing.miniMessage.deserialize(newText),
Competition.progress,
color,
overlay);
@@ -74,23 +66,38 @@ public class BossBarSender extends BukkitRunnable {
@Override
public void run() {
if (timer < bossbarConfig.getRate()){
if (timer < rate){
timer++;
}else {
String text;
if (ConfigReader.Config.papi){
text = PapiHook.parse(player, bossbarConfig.getText());
}else {
text = bossbarConfig.getText();
}
bossBar.name(
MiniMessage.miniMessage().deserialize(text.replace("{time}", String.valueOf(Competition.remainingTime))
.replace("{rank}", Optional.ofNullable(CompetitionSchedule.competition.getRanking().getPlayerRank(player.getName())).orElse(ConfigReader.Message.noRank))
.replace("{minute}", String.format("%02d",Competition.remainingTime/60))
.replace("{second}",String.format("%02d",Competition.remainingTime%60))
.replace("{point}", String.format("%.1f",Optional.ofNullable(CompetitionSchedule.competition.getRanking().getCompetitionPlayer(player.getName())).orElse(Competition.emptyPlayer).getScore()))));
updateText();
String newText = updateText();
bossBar.name(CustomFishing.miniMessage.deserialize(newText));
bossBar.progress(Competition.progress);
timer = 0;
}
}
private String updateText() {
String text;
if (ConfigReader.Config.papi){
text = PapiHook.parse(player, this.text);
}else {
text = this.text;
}
String newText;
if (ConfigReader.Config.papi){
newText = PapiHook.parse(player, text.replace("{time}", String.valueOf(Competition.remainingTime))
.replace("{rank}", Optional.ofNullable(CompetitionSchedule.competition.getRanking().getPlayerRank(player.getName())).orElse(ConfigReader.Message.noRank))
.replace("{minute}", String.format("%02d",Competition.remainingTime/60))
.replace("{second}",String.format("%02d",Competition.remainingTime%60))
.replace("{point}", String.format("%.1f",Optional.ofNullable(CompetitionSchedule.competition.getRanking().getCompetitionPlayer(player.getName())).orElse(Competition.emptyPlayer).getScore())));
}else {
newText = text.replace("{time}", String.valueOf(Competition.remainingTime))
.replace("{rank}", Optional.ofNullable(CompetitionSchedule.competition.getRanking().getPlayerRank(player.getName())).orElse(ConfigReader.Message.noRank))
.replace("{minute}", String.format("%02d",Competition.remainingTime/60))
.replace("{second}",String.format("%02d",Competition.remainingTime%60))
.replace("{point}", String.format("%.1f",Optional.ofNullable(CompetitionSchedule.competition.getRanking().getCompetitionPlayer(player.getName())).orElse(Competition.emptyPlayer).getScore()));
}
return newText;
}
}

View File

@@ -26,7 +26,7 @@ import java.util.HashMap;
public class BossBarTimer {
public HashMap<Integer, BossBarSender> bossbarCache = new HashMap<>();
private HashMap<Integer, BossBarSender> bossbarCache = new HashMap<>();
public BossBarTimer(Player player, BossBarConfig bossBarConfig){

View File

@@ -240,7 +240,7 @@ public class PlayerListener implements Listener {
nextLoot.put(player, availableLoots.get(pos));
return;
}
//以防万一,丢入空值
nextLoot.put(player, null);
});
}
@@ -255,11 +255,10 @@ public class PlayerListener implements Listener {
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()-> {
Loot lootInstance = nextLoot.get(player);
//获取布局名,或是随机布局
String layout = Optional.ofNullable(lootInstance.getLayout()).orElseGet(() ->{
Random generator = new Random();
Object[] values = ConfigReader.LAYOUT.keySet().toArray();
return (String) values[generator.nextInt(values.length)];
return (String) values[new Random().nextInt(values.length)];
});
int difficulty = lootInstance.getDifficulty().getSpeed();
@@ -269,7 +268,6 @@ public class PlayerListener implements Listener {
}
Difficulty difficult = new Difficulty(lootInstance.getDifficulty().getTimer(), difficulty);
//根据鱼的时间放入玩家实例,并应用药水效果
fishingPlayers.put(player,
new FishingPlayer(System.currentTimeMillis() + lootInstance.getTime(),
new Timer(player, difficult, layout)

View File

@@ -33,30 +33,26 @@ public class AdventureManager {
public static void consoleMessage(String s) {
Audience au = CustomFishing.adventure.sender(Bukkit.getConsoleSender());
MiniMessage mm = MiniMessage.miniMessage();
Component parsed = mm.deserialize(s);
Component parsed = CustomFishing.miniMessage.deserialize(s);
au.sendMessage(parsed);
}
public static void playerMessage(Player player, String s) {
Audience au = CustomFishing.adventure.player(player);
MiniMessage mm = MiniMessage.miniMessage();
Component parsed = mm.deserialize(s);
Component parsed = CustomFishing.miniMessage.deserialize(s);
au.sendMessage(parsed);
}
public static void playerTitle(Player player, String s1, String s2, int in, int duration, int out) {
Audience au = CustomFishing.adventure.player(player);
MiniMessage mm = MiniMessage.miniMessage();
Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out));
Title title = Title.title(mm.deserialize(s1), mm.deserialize(s2), times);
Title title = Title.title(CustomFishing.miniMessage.deserialize(s1), CustomFishing.miniMessage.deserialize(s2), times);
au.showTitle(title);
}
public static void playerActionbar(Player player, String s) {
Audience au = CustomFishing.adventure.player(player);
MiniMessage mm = MiniMessage.miniMessage();
au.sendActionBar(mm.deserialize(s));
au.sendActionBar(CustomFishing.miniMessage.deserialize(s));
}
public static void playerSound(Player player, Sound.Source source, Key key) {

View File

@@ -0,0 +1,121 @@
bar1:
range: 16
title: 'The fish is hooked, focus on it!'
subtitle:
start: '<font:customfishing:default>'
bar: '뀄'
pointer_offset: '뀂'
pointer: '뀃'
offset: '뀁'
end: '</font>'
layout:
1: 0
2: 0
3: 0
4: 0.1
5: 0.5
6: 1
7: 0.5
8: 0.1
9: 0
10: 0
11: 0
bar2:
range: 8
title: 'The fish is hooked, focus on it!'
subtitle:
start: '<font:customfishing:default>'
bar: '뀅'
pointer_offset: '뀂'
pointer: '뀃'
offset: '뀁'
end: '</font>'
layout:
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0.1
8: 0.1
9: 0.3
10: 0.3
11: 1
12: 0.3
13: 0.1
14: 0
15: 0.1
16: 0.3
17: 1
18: 0.3
19: 0.1
20: 0
21: 0
22: 0
bar3:
range: 8 #frame pixels, all must be the same
title: 'The fish is hooked, focus on it!'
subtitle:
start: '<font:customfishing:default>'
bar: '뀆' #bar unicode
pointer_offset: '뀂'
pointer: '뀃'
offset: '뀁'
end: '</font>'
layout:
1: 1 #green
2: 0.3 #yellow
3: 0.1 #orange
4: 0 #red
5: 0 #red
6: 0.1 #orange
7: 0.3 #yellow
8: 0 #red
9: 0.3 #yellow
10: 0.1 #orange
11: 0 #red
12: 0.1 #orange
13: 0.3 #yellow
14: 1 #green
15: 0.3 #yellow
16: 1 #green
17: 0.1
18: 0 #red
19: 0.1 #orange
20: 0.3 #yellow
21: 0.1 #orange
22: 0 #red
bar4:
range: 8
title: 'The fish is hooked, focus on it!'
subtitle:
start: '<font:customfishing:default>'
bar: '뀇'
pointer_offset: '뀂'
pointer: '뀃'
offset: '뀁'
end: '</font>'
layout:
1: 0
2: 0.3
3: 0.1
4: 0.3
5: 1
6: 0.3
7: 0
8: 1
9: 0.1
10: 0
11: 1
12: 0.1
13: 0.3
14: 1
15: 0
16: 1
17: 0
18: 0.3
19: 0.1
20: 0
21: 1
22: 0

View File

@@ -1,3 +1,6 @@
# don't change
config-version: 1
config:
#en/es/cn
@@ -42,64 +45,5 @@ config:
#转换MMOItems鱼竿为插件物品鱼竿(修改此项需要重启)
convert-MMOITEMS: false
#成功率
#你可以自定义区域数量这为自定义UI提供了可能
success-rate:
bar1:
#每个判定区间的像素个数
#默认配置为16个像素每区间
#如果你对自定义UI很感兴趣建议联系作者提供相关帮助
range: 16
title: '鱼上钩了,集中注意!'
subtitle:
start: '<font:customfishing:default>'
bar: '뀄'
pointer_offset: '뀂'
pointer: '뀃'
offset: '뀁'
end: '</font>'
layout:
1: 0
2: 0
3: 0
4: 0.1
5: 0.5
6: 1
7: 0.5
8: 0.1
9: 0
10: 0
11: 0
bar2:
range: 8
title: '鱼上钩了,集中注意!'
subtitle:
start: '<font:customfishing:default>'
bar: '뀅'
pointer_offset: '뀂'
pointer: '뀃'
offset: '뀁'
end: '</font>'
layout:
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0.1
8: 0.1
9: 0.3
10: 0.3
11: 1
12: 0.3
13: 0.1
14: 0
15: 0.1
16: 0.3
17: 1
18: 0.3
19: 0.1
20: 0
21: 0
22: 0
# ProtocolLib 模式 (修改此项需要重启)
protocollib-bossbar: false