mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
1.0
This commit is contained in:
@@ -1,35 +0,0 @@
|
|||||||
package net.momirealms.customfishing;
|
|
||||||
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import net.kyori.adventure.title.Title;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
au.showTitle(title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package net.momirealms.customfishing.titlebar;
|
|
||||||
|
|
||||||
public record Difficulty(int timer, int speed) {
|
|
||||||
|
|
||||||
public int getTimer() {
|
|
||||||
return this.timer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSpeed() {
|
|
||||||
return this.speed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package net.momirealms.customfishing.titlebar;
|
|
||||||
|
|
||||||
import net.momirealms.customfishing.timer.Timer;
|
|
||||||
|
|
||||||
public record FishingPlayer(Long fishingTime, Timer timer) {
|
|
||||||
|
|
||||||
public Long getFishingTime() {
|
|
||||||
return this.fishingTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timer getTimer() {
|
|
||||||
return this.timer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package net.momirealms.customfishing.titlebar;
|
|
||||||
|
|
||||||
public class Layout {
|
|
||||||
|
|
||||||
private final String key;
|
|
||||||
private final int range;
|
|
||||||
private final double[] successRate;
|
|
||||||
private final int size;
|
|
||||||
|
|
||||||
private String start;
|
|
||||||
private String bar;
|
|
||||||
private String pointer;
|
|
||||||
private String offset;
|
|
||||||
private String end;
|
|
||||||
private String pointerOffset;
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
public Layout(String key, int range, double[] successRate, int size){
|
|
||||||
this.key = key;
|
|
||||||
this.range = range;
|
|
||||||
this.successRate = successRate;
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBar(String bar) {this.bar = bar;}
|
|
||||||
public void setEnd(String end) {this.end = end;}
|
|
||||||
public void setOffset(String offset) {this.offset = offset;}
|
|
||||||
public void setPointer(String pointer) {this.pointer = pointer;}
|
|
||||||
public void setPointerOffset(String pointerOffset) {this.pointerOffset = pointerOffset;}
|
|
||||||
public void setStart(String start) {this.start = start;}
|
|
||||||
public void setTitle(String title) {this.title = title;}
|
|
||||||
|
|
||||||
public int getRange(){return this.range;}
|
|
||||||
public double[] getSuccessRate(){return this.successRate;}
|
|
||||||
public int getSize(){return this.size;}
|
|
||||||
public String getBar() {return bar;}
|
|
||||||
public String getEnd() {return end;}
|
|
||||||
public String getOffset() {return offset;}
|
|
||||||
public String getPointer() {return pointer;}
|
|
||||||
public String getPointerOffset() {return pointerOffset;}
|
|
||||||
public String getStart() {return start;}
|
|
||||||
public String getTitle() {return title;}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package net.momirealms.customfishing.timer;
|
|
||||||
|
|
||||||
import net.momirealms.customfishing.CustomFishing;
|
|
||||||
import net.momirealms.customfishing.titlebar.Difficulty;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
public class Timer {
|
|
||||||
|
|
||||||
private final TimerTask timerTask;
|
|
||||||
private final BukkitTask task;
|
|
||||||
private final String layout;
|
|
||||||
|
|
||||||
public Timer(Player player, Difficulty difficulty, String layout) {
|
|
||||||
this.layout = layout;
|
|
||||||
this.timerTask = new TimerTask(player, difficulty, layout);
|
|
||||||
this.task = timerTask.runTaskTimerAsynchronously(CustomFishing.instance, 1,1);
|
|
||||||
timerTask.setTaskID(task.getTaskId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimerTask getTimerTask(){ return this.timerTask; }
|
|
||||||
public int getTaskID (){ return this.task.getTaskId(); }
|
|
||||||
public String getLayout(){return this.layout;}
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
package net.momirealms.customfishing.timer;
|
|
||||||
|
|
||||||
import net.momirealms.customfishing.AdventureManager;
|
|
||||||
import net.momirealms.customfishing.ConfigReader;
|
|
||||||
import net.momirealms.customfishing.CustomFishing;
|
|
||||||
import net.momirealms.customfishing.titlebar.Difficulty;
|
|
||||||
import net.momirealms.customfishing.titlebar.Layout;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
|
|
||||||
import static net.momirealms.customfishing.listener.PlayerListener.fishingPlayers;
|
|
||||||
|
|
||||||
public class TimerTask extends BukkitRunnable {
|
|
||||||
|
|
||||||
private final Player player;
|
|
||||||
private final Difficulty difficulty;
|
|
||||||
private int taskID;
|
|
||||||
private int progress;
|
|
||||||
private int internalTimer;
|
|
||||||
private final int size;
|
|
||||||
private boolean face;
|
|
||||||
private BukkitScheduler bukkitScheduler;
|
|
||||||
|
|
||||||
private final String start;
|
|
||||||
private final String bar;
|
|
||||||
private final String pointer;
|
|
||||||
private final String offset;
|
|
||||||
private final String end;
|
|
||||||
private final String pointerOffset;
|
|
||||||
private final String title;
|
|
||||||
|
|
||||||
public TimerTask(Player player, Difficulty difficulty, String layout){
|
|
||||||
this.player = player;
|
|
||||||
this.difficulty = difficulty;
|
|
||||||
this.progress = 0;
|
|
||||||
this.internalTimer = 0;
|
|
||||||
this.face = true;
|
|
||||||
this.bukkitScheduler = Bukkit.getScheduler();
|
|
||||||
Layout layoutUtil = ConfigReader.LAYOUT.get(layout);
|
|
||||||
this.start = layoutUtil.getStart();
|
|
||||||
this.bar = layoutUtil.getBar();
|
|
||||||
this.pointer = layoutUtil.getPointer();
|
|
||||||
this.offset = layoutUtil.getOffset();
|
|
||||||
this.end = layoutUtil.getEnd();
|
|
||||||
this.pointerOffset = layoutUtil.getPointerOffset();
|
|
||||||
this.title = layoutUtil.getTitle();
|
|
||||||
this.size = layoutUtil.getSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getProgress() { return this.progress; }
|
|
||||||
public void setTaskID(int taskID){
|
|
||||||
this.taskID = taskID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
//移除提前收杆玩家
|
|
||||||
if (fishingPlayers.get(player) == null){
|
|
||||||
bukkitScheduler.cancelTask(taskID);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//移除超时玩家
|
|
||||||
if (System.currentTimeMillis() > fishingPlayers.get(player).getFishingTime()){
|
|
||||||
fishingPlayers.remove(player);
|
|
||||||
bukkitScheduler.cancelTask(taskID);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int timer = difficulty.getTimer() - 1;
|
|
||||||
int speed = difficulty.getSpeed();
|
|
||||||
//设置指针方向
|
|
||||||
if (progress <= speed - 1){
|
|
||||||
face = true;
|
|
||||||
}else if(progress >= size - speed + 1){
|
|
||||||
face = false;
|
|
||||||
}
|
|
||||||
//内部计时器操控
|
|
||||||
if (internalTimer < timer){
|
|
||||||
internalTimer++;
|
|
||||||
return;
|
|
||||||
}else {
|
|
||||||
if (face){
|
|
||||||
internalTimer -= timer;
|
|
||||||
progress += speed;
|
|
||||||
}else {
|
|
||||||
internalTimer -= timer;
|
|
||||||
progress -= speed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//发送title
|
|
||||||
StringBuilder stringBuilder = new StringBuilder(start + bar + pointerOffset);
|
|
||||||
for (int index = 0; index <= size; index++){
|
|
||||||
if (index == progress){
|
|
||||||
stringBuilder.append(pointer);
|
|
||||||
}else {
|
|
||||||
stringBuilder.append(offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stringBuilder.append(end);
|
|
||||||
AdventureManager.playerTitle(player, title, stringBuilder.toString(),0,300,0);
|
|
||||||
//移除切换物品的玩家
|
|
||||||
PlayerInventory playerInventory = player.getInventory();
|
|
||||||
if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD){
|
|
||||||
fishingPlayers.remove(player);
|
|
||||||
bukkitScheduler.cancelTask(taskID);
|
|
||||||
bukkitScheduler.runTask(CustomFishing.instance, ()-> {
|
|
||||||
player.removePotionEffect(PotionEffectType.SLOW);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package net.momirealms.customfishing.utils;
|
|
||||||
|
|
||||||
import io.lumine.mythic.api.adapters.AbstractLocation;
|
|
||||||
import io.lumine.mythic.api.adapters.AbstractVector;
|
|
||||||
import io.lumine.mythic.api.mobs.MobManager;
|
|
||||||
import io.lumine.mythic.api.mobs.MythicMob;
|
|
||||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
|
||||||
import io.lumine.mythic.bukkit.utils.serialize.Position;
|
|
||||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
|
||||||
import net.momirealms.customfishing.item.Loot;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MMUtil {
|
|
||||||
|
|
||||||
public static void summonMM(Location pLocation, Location bLocation, Loot loot){
|
|
||||||
MobManager mobManager = MythicBukkit.inst().getMobManager();
|
|
||||||
Optional<MythicMob> mythicMob = mobManager.getMythicMob(loot.getMm());
|
|
||||||
if (mythicMob.isPresent()) {
|
|
||||||
//获取MM怪实例
|
|
||||||
MythicMob theMob = mythicMob.get();
|
|
||||||
//生成MM怪
|
|
||||||
Position position = Position.of(bLocation);
|
|
||||||
AbstractLocation abstractLocation = new AbstractLocation(position);
|
|
||||||
ActiveMob activeMob = theMob.spawn(abstractLocation, loot.getMmLevel());
|
|
||||||
|
|
||||||
VectorUtil vectorUtil = loot.getVectorUtil();
|
|
||||||
Vector vector = pLocation.subtract(bLocation).toVector().multiply((vectorUtil.getHorizontal())-1);
|
|
||||||
vector = vector.setY((vector.getY()+0.2)*vectorUtil.getVertical());
|
|
||||||
activeMob.getEntity().setVelocity(new AbstractVector(vector.getX(),vector.getY(),vector.getZ()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user