mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
Event Update
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
package net.momirealms.customfishing.api.event;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class FishingFailure extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
public FishingFailure(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package net.momirealms.customfishing.api.event;
|
||||||
|
|
||||||
|
import net.momirealms.customfishing.object.loot.Loot;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class FishingSuccess extends Event implements Cancellable {
|
||||||
|
private boolean cancelled;
|
||||||
|
private Player player;
|
||||||
|
private Loot loot;
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private boolean loseDurability;
|
||||||
|
|
||||||
|
public FishingSuccess(Player player, Loot loot, Boolean loseDurability) {
|
||||||
|
this.player = player;
|
||||||
|
this.loot = loot;
|
||||||
|
this.loseDurability = loseDurability;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Loot getLoot() {
|
||||||
|
return loot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoot(Loot loot) {
|
||||||
|
this.loot = loot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLoseDurability() {
|
||||||
|
return loseDurability;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoseDurability(boolean loseDurability) {
|
||||||
|
this.loseDurability = loseDurability;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
|
|||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.momirealms.customfishing.api.event.FishingFailure;
|
||||||
|
import net.momirealms.customfishing.api.event.FishingSuccess;
|
||||||
import net.momirealms.customfishing.competition.CompetitionSchedule;
|
import net.momirealms.customfishing.competition.CompetitionSchedule;
|
||||||
import net.momirealms.customfishing.competition.bossbar.BossBarManager;
|
import net.momirealms.customfishing.competition.bossbar.BossBarManager;
|
||||||
import net.momirealms.customfishing.hook.*;
|
import net.momirealms.customfishing.hook.*;
|
||||||
@@ -480,26 +482,34 @@ public class FishListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Math.random() < layout.getSuccessRate()[last]){
|
if (Math.random() < layout.getSuccessRate()[last]){
|
||||||
if (ConfigReader.Config.loseDurability)
|
|
||||||
loseDurability(player);
|
FishingSuccess successEvent = new FishingSuccess(player, loot, ConfigReader.Config.loseDurability);
|
||||||
Location location = event.getHook().getLocation();
|
Bukkit.getServer().getPluginManager().callEvent(successEvent);
|
||||||
if (loot instanceof Mob mob){
|
if(!successEvent.isCancelled()) {
|
||||||
summonMob(player, loot, location, mob);
|
if (successEvent.isLoseDurability())
|
||||||
}
|
loseDurability(player);
|
||||||
else if (loot instanceof DroppedItem droppedItem){
|
Location location = event.getHook().getLocation();
|
||||||
if (vanillaLoot != null) {
|
if (loot instanceof Mob mob){
|
||||||
dropVanillaLoot(player, vanillaLoot, location);
|
summonMob(player, loot, location, mob);
|
||||||
}
|
}
|
||||||
else if (ConfigReader.Config.mcMMOLoot && Math.random() < ConfigReader.Config.mcMMOLootChance){
|
else if (loot instanceof DroppedItem droppedItem){
|
||||||
if(dropMcMMOLoot(player, location)){
|
if (vanillaLoot != null) {
|
||||||
|
dropVanillaLoot(player, vanillaLoot, location);
|
||||||
|
}
|
||||||
|
else if (ConfigReader.Config.mcMMOLoot && Math.random() < ConfigReader.Config.mcMMOLootChance){
|
||||||
|
if(dropMcMMOLoot(player, location)){
|
||||||
|
dropMyLoot(player, loot, location, droppedItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
dropMyLoot(player, loot, location, droppedItem);
|
dropMyLoot(player, loot, location, droppedItem);
|
||||||
}
|
}
|
||||||
|
}else if (loot == null && vanillaLoot != null){
|
||||||
|
dropVanillaLoot(player, vanillaLoot, location);
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
dropMyLoot(player, loot, location, droppedItem);
|
else {
|
||||||
}
|
fail(player, loot, vanillaLoot != null);
|
||||||
}else if (loot == null && vanillaLoot != null){
|
|
||||||
dropVanillaLoot(player, vanillaLoot, location);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -920,6 +930,8 @@ public class FishListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fail(Player player, Loot loot, boolean isVanilla) {
|
private void fail(Player player, Loot loot, boolean isVanilla) {
|
||||||
|
//钓鱼失败不具有可取消性质
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new FishingFailure(player));
|
||||||
fishingPlayers.remove(player);
|
fishingPlayers.remove(player);
|
||||||
if (!isVanilla && loot != null){
|
if (!isVanilla && loot != null){
|
||||||
for (ActionB action : loot.getFailureActions())
|
for (ActionB action : loot.getFailureActions())
|
||||||
|
|||||||
Reference in New Issue
Block a user