mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-24 01:19:32 +00:00
checkpoint - 28
This commit is contained in:
@@ -17,53 +17,77 @@
|
|||||||
|
|
||||||
package net.momirealms.customfishing.api.event;
|
package net.momirealms.customfishing.api.event;
|
||||||
|
|
||||||
|
import net.momirealms.customfishing.api.mechanic.context.Context;
|
||||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
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;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class FishingLootSpawnEvent extends PlayerEvent implements Cancellable {
|
public class FishingLootSpawnEvent extends PlayerEvent {
|
||||||
|
|
||||||
private static final HandlerList handlerList = new HandlerList();
|
private static final HandlerList handlerList = new HandlerList();
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private final Item item;
|
private final Entity entity;
|
||||||
private final Loot loot;
|
private final Loot loot;
|
||||||
private boolean isCancelled;
|
private final Context<Player> context;
|
||||||
|
private boolean skipActions;
|
||||||
|
private boolean summonEntity;
|
||||||
|
|
||||||
public FishingLootSpawnEvent(@NotNull Player who, Location location, Loot loot, Item item) {
|
public FishingLootSpawnEvent(@NotNull Context<Player> context, Location location, Loot loot, @Nullable Entity entity) {
|
||||||
super(who);
|
super(context.getHolder());
|
||||||
this.item = item;
|
this.entity = entity;
|
||||||
this.loot = loot;
|
this.loot = loot;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.isCancelled = false;
|
this.skipActions = false;
|
||||||
|
this.summonEntity = true;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Context<Player> getContext() {
|
||||||
public boolean isCancelled() {
|
return context;
|
||||||
return isCancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
isCancelled = cancel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item getItem() {
|
/**
|
||||||
return item;
|
* Get the loot entity
|
||||||
|
*
|
||||||
|
* @return entity
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Entity getEntity() {
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public Loot getLoot() {
|
public Loot getLoot() {
|
||||||
return loot;
|
return loot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean summonEntity() {
|
||||||
|
return summonEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void summonEntity(boolean summonEntity) {
|
||||||
|
this.summonEntity = summonEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean skipActions() {
|
||||||
|
return skipActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void skipActions(boolean skipActions) {
|
||||||
|
this.skipActions = skipActions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull HandlerList getHandlers() {
|
public @NotNull HandlerList getHandlers() {
|
||||||
return handlerList;
|
return handlerList;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public interface BlockManager extends Reloadable {
|
|||||||
|
|
||||||
boolean registerBlock(@NotNull BlockConfig block);
|
boolean registerBlock(@NotNull BlockConfig block);
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
FallingBlock summonBlockLoot(@NotNull Context<Player> context);
|
FallingBlock summonBlockLoot(@NotNull Context<Player> context);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -34,11 +34,10 @@ public class ContextKeys<T> {
|
|||||||
public static final ContextKeys<LootType> LOOT = of("loot", LootType.class);
|
public static final ContextKeys<LootType> LOOT = of("loot", LootType.class);
|
||||||
public static final ContextKeys<String> NICK = of("nick", String.class);
|
public static final ContextKeys<String> NICK = of("nick", String.class);
|
||||||
public static final ContextKeys<Boolean> OPEN_WATER = of("open_water", Boolean.class);
|
public static final ContextKeys<Boolean> OPEN_WATER = of("open_water", Boolean.class);
|
||||||
public static final ContextKeys<String> TYPE = of("type", String.class);
|
public static final ContextKeys<Float> SIZE = of("size", Float.class);
|
||||||
public static final ContextKeys<Float> SIZE = of("SIZE", Float.class);
|
public static final ContextKeys<String> SIZE_FORMATTED = of("size_formatted", String.class);
|
||||||
public static final ContextKeys<String> SIZE_FORMATTED = of("size", String.class);
|
public static final ContextKeys<Double> PRICE = of("price", Double.class);
|
||||||
public static final ContextKeys<Double> PRICE = of("PRICE", Double.class);
|
public static final ContextKeys<String> PRICE_FORMATTED = of("price_formatted", String.class);
|
||||||
public static final ContextKeys<String> PRICE_FORMATTED = of("price", String.class);
|
|
||||||
public static final ContextKeys<String> SURROUNDING = of("surrounding", String.class);
|
public static final ContextKeys<String> SURROUNDING = of("surrounding", String.class);
|
||||||
public static final ContextKeys<String> TEMP_NEAR_PLAYER = of("near", String.class);
|
public static final ContextKeys<String> TEMP_NEAR_PLAYER = of("near", String.class);
|
||||||
public static final ContextKeys<String> ROD = of("rod", String.class);
|
public static final ContextKeys<String> ROD = of("rod", String.class);
|
||||||
@@ -67,8 +66,9 @@ public class ContextKeys<T> {
|
|||||||
public static final ContextKeys<Integer> AMOUNT = of("amount", Integer.class);
|
public static final ContextKeys<Integer> AMOUNT = of("amount", Integer.class);
|
||||||
public static final ContextKeys<Double> WEIGHT = of("0", Double.class);
|
public static final ContextKeys<Double> WEIGHT = of("0", Double.class);
|
||||||
public static final ContextKeys<String> TIME_LEFT = of("time_left", String.class);
|
public static final ContextKeys<String> TIME_LEFT = of("time_left", String.class);
|
||||||
public static final ContextKeys<String> REASON = of("reason", String.class);
|
|
||||||
public static final ContextKeys<String> PROGRESS = of("progress", String.class);
|
public static final ContextKeys<String> PROGRESS = of("progress", String.class);
|
||||||
|
public static final ContextKeys<Float> RECORD = of("record", Float.class);
|
||||||
|
public static final ContextKeys<String> RECORD_FORMATTED = of("record_formatted", String.class);
|
||||||
public static final ContextKeys<Integer> CLICKS_LEFT = of("left_clicks", Integer.class);
|
public static final ContextKeys<Integer> CLICKS_LEFT = of("left_clicks", Integer.class);
|
||||||
public static final ContextKeys<Integer> REQUIRED_TIMES = of("clicks", Integer.class);
|
public static final ContextKeys<Integer> REQUIRED_TIMES = of("clicks", Integer.class);
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import net.momirealms.customfishing.api.mechanic.context.Context;
|
|||||||
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
|
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -40,6 +41,6 @@ public interface EntityManager extends Reloadable {
|
|||||||
|
|
||||||
boolean registerEntity(EntityConfig entity);
|
boolean registerEntity(EntityConfig entity);
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
Entity summonEntityLoot(Context<Player> context);
|
Entity summonEntityLoot(Context<Player> context);
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,6 @@ public interface EventManager extends Reloadable {
|
|||||||
*
|
*
|
||||||
* @param context The context in which the event is triggered.
|
* @param context The context in which the event is triggered.
|
||||||
* @param id The unique identifier of the event carrier.
|
* @param id The unique identifier of the event carrier.
|
||||||
* @param type
|
|
||||||
* @param trigger The trigger that initiates the event.
|
* @param trigger The trigger that initiates the event.
|
||||||
*/
|
*/
|
||||||
default void trigger(Context<Player> context, String id, MechanicType type, ActionTrigger trigger) {
|
default void trigger(Context<Player> context, String id, MechanicType type, ActionTrigger trigger) {
|
||||||
@@ -63,7 +62,6 @@ public interface EventManager extends Reloadable {
|
|||||||
*
|
*
|
||||||
* @param context The context in which the event is triggered.
|
* @param context The context in which the event is triggered.
|
||||||
* @param id The unique identifier of the event carrier.
|
* @param id The unique identifier of the event carrier.
|
||||||
* @param type
|
|
||||||
* @param trigger The trigger that initiates the event.
|
* @param trigger The trigger that initiates the event.
|
||||||
* @param previousTimes The previous times count for the event.
|
* @param previousTimes The previous times count for the event.
|
||||||
* @param afterTimes The after times count for the event.
|
* @param afterTimes The after times count for the event.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customfishing.api.mechanic.fishing;
|
package net.momirealms.customfishing.api.mechanic.fishing;
|
||||||
|
|
||||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||||
|
import net.momirealms.customfishing.api.event.FishingLootSpawnEvent;
|
||||||
import net.momirealms.customfishing.api.event.FishingResultEvent;
|
import net.momirealms.customfishing.api.event.FishingResultEvent;
|
||||||
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
|
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
|
||||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal;
|
import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal;
|
||||||
@@ -44,13 +45,14 @@ import net.momirealms.customfishing.common.util.TriConsumer;
|
|||||||
import net.momirealms.customfishing.common.util.TriFunction;
|
import net.momirealms.customfishing.common.util.TriFunction;
|
||||||
import net.momirealms.sparrow.heart.SparrowHeart;
|
import net.momirealms.sparrow.heart.SparrowHeart;
|
||||||
import net.momirealms.sparrow.heart.feature.inventory.HandSlot;
|
import net.momirealms.sparrow.heart.feature.inventory.HandSlot;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -218,7 +220,7 @@ public class CustomFishingHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void end() {
|
public void end() {
|
||||||
plugin.getFishingManager().destroy(context.getHolder().getUniqueId());
|
plugin.getFishingManager().destroy(context.getHolder().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,18 +244,6 @@ public class CustomFishingHook {
|
|||||||
return gamingPlayer != null && gamingPlayer.isValid();
|
return gamingPlayer != null && gamingPlayer.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGameResult() {
|
|
||||||
if (gamingPlayer == null || !gamingPlayer.isValid()) {
|
|
||||||
throw new RuntimeException("You can't call this method if the player is not playing the game");
|
|
||||||
}
|
|
||||||
if (gamingPlayer.isSuccessful()) {
|
|
||||||
handleSuccessfulFishing();
|
|
||||||
} else {
|
|
||||||
handleFailedFishing();
|
|
||||||
}
|
|
||||||
end();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelCurrentGame() {
|
public void cancelCurrentGame() {
|
||||||
if (gamingPlayer == null || !gamingPlayer.isValid()) {
|
if (gamingPlayer == null || !gamingPlayer.isValid()) {
|
||||||
throw new RuntimeException("You can't call this method if the player is not playing the game");
|
throw new RuntimeException("You can't call this method if the player is not playing the game");
|
||||||
@@ -270,11 +260,13 @@ public class CustomFishingHook {
|
|||||||
return;
|
return;
|
||||||
Game nextGame = plugin.getGameManager().getNextGame(tempFinalEffect, context);
|
Game nextGame = plugin.getGameManager().getNextGame(tempFinalEffect, context);
|
||||||
if (nextGame != null) {
|
if (nextGame != null) {
|
||||||
|
plugin.debug("Next game: " + nextGame.id());
|
||||||
gamingPlayer = nextGame.start(this, tempFinalEffect);
|
gamingPlayer = nextGame.start(this, tempFinalEffect);
|
||||||
if (this.hookMechanic != null) {
|
if (this.hookMechanic != null) {
|
||||||
this.hookMechanic.freeze();
|
this.hookMechanic.freeze();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
plugin.debug("Next game: " + "`null`");
|
||||||
handleSuccessfulFishing();
|
handleSuccessfulFishing();
|
||||||
end();
|
end();
|
||||||
}
|
}
|
||||||
@@ -302,16 +294,16 @@ public class CustomFishingHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onEscape() {
|
public void onEscape() {
|
||||||
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.ESCAPE);
|
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.ESCAPE);
|
||||||
gears.trigger(ActionTrigger.ESCAPE, context);
|
gears.trigger(ActionTrigger.ESCAPE, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLure() {
|
public void onLure() {
|
||||||
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.LURE);
|
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.LURE);
|
||||||
gears.trigger(ActionTrigger.LURE, context);
|
gears.trigger(ActionTrigger.LURE, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleFailedFishing() {
|
public void handleFailedFishing() {
|
||||||
|
|
||||||
// update the hook location
|
// update the hook location
|
||||||
context.arg(ContextKeys.HOOK_LOCATION, hook.getLocation());
|
context.arg(ContextKeys.HOOK_LOCATION, hook.getLocation());
|
||||||
@@ -320,10 +312,10 @@ public class CustomFishingHook {
|
|||||||
context.arg(ContextKeys.HOOK_Z, hook.getLocation().getBlockZ());
|
context.arg(ContextKeys.HOOK_Z, hook.getLocation().getBlockZ());
|
||||||
|
|
||||||
gears.trigger(ActionTrigger.FAILURE, context);
|
gears.trigger(ActionTrigger.FAILURE, context);
|
||||||
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.FAILURE);
|
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSuccessfulFishing() {
|
public void handleSuccessfulFishing() {
|
||||||
|
|
||||||
// update the hook location
|
// update the hook location
|
||||||
context.arg(ContextKeys.HOOK_LOCATION, hook.getLocation());
|
context.arg(ContextKeys.HOOK_LOCATION, hook.getLocation());
|
||||||
@@ -350,6 +342,8 @@ public class CustomFishingHook {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gears.trigger(ActionTrigger.SUCCESS, context);
|
||||||
|
|
||||||
switch (lootType) {
|
switch (lootType) {
|
||||||
case ITEM -> {
|
case ITEM -> {
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
@@ -364,21 +358,41 @@ public class CustomFishingHook {
|
|||||||
context.arg(ContextKeys.NICK, "<lang:" + stack.getType().translationKey() + ">");
|
context.arg(ContextKeys.NICK, "<lang:" + stack.getType().translationKey() + ">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FishingLootSpawnEvent spawnEvent = new FishingLootSpawnEvent(context, hook.getLocation(), nextLoot, item);
|
||||||
|
Bukkit.getPluginManager().callEvent(spawnEvent);
|
||||||
|
if (item != null && !spawnEvent.summonEntity())
|
||||||
|
item.remove();
|
||||||
|
if (spawnEvent.skipActions())
|
||||||
|
return;
|
||||||
|
if (item != null && item.isValid() && nextLoot.preventGrabbing()) {
|
||||||
|
item.getPersistentDataContainer().set(Objects.requireNonNull(NamespacedKey.fromString("owner", plugin.getBoostrap())), PersistentDataType.STRING, context.getHolder().getName());
|
||||||
|
}
|
||||||
doSuccessActions();
|
doSuccessActions();
|
||||||
}, (long) ConfigManager.multipleLootSpawnDelay() * i, hook.getLocation());
|
}, (long) ConfigManager.multipleLootSpawnDelay() * i, hook.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case BLOCK -> {
|
case BLOCK -> {
|
||||||
plugin.getBlockManager().summonBlockLoot(context);
|
FallingBlock fallingBlock = plugin.getBlockManager().summonBlockLoot(context);
|
||||||
|
FishingLootSpawnEvent spawnEvent = new FishingLootSpawnEvent(context, hook.getLocation(), nextLoot, fallingBlock);
|
||||||
|
Bukkit.getPluginManager().callEvent(spawnEvent);
|
||||||
|
if (!spawnEvent.summonEntity())
|
||||||
|
fallingBlock.remove();
|
||||||
|
if (spawnEvent.skipActions())
|
||||||
|
return;
|
||||||
doSuccessActions();
|
doSuccessActions();
|
||||||
}
|
}
|
||||||
case ENTITY -> {
|
case ENTITY -> {
|
||||||
plugin.getEntityManager().summonEntityLoot(context);
|
Entity entity = plugin.getEntityManager().summonEntityLoot(context);
|
||||||
|
FishingLootSpawnEvent spawnEvent = new FishingLootSpawnEvent(context, hook.getLocation(), nextLoot, entity);
|
||||||
|
Bukkit.getPluginManager().callEvent(spawnEvent);
|
||||||
|
if (!spawnEvent.summonEntity())
|
||||||
|
entity.remove();
|
||||||
|
if (spawnEvent.skipActions())
|
||||||
|
return;
|
||||||
doSuccessActions();
|
doSuccessActions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gears.trigger(ActionTrigger.SUCCESS, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doSuccessActions() {
|
private void doSuccessActions() {
|
||||||
@@ -416,13 +430,15 @@ public class CustomFishingHook {
|
|||||||
String id = context.arg(ContextKeys.ID);
|
String id = context.arg(ContextKeys.ID);
|
||||||
Player player = context.getHolder();
|
Player player = context.getHolder();
|
||||||
MechanicType type = MechanicType.getTypeByID(id);
|
MechanicType type = MechanicType.getTypeByID(id);
|
||||||
plugin.getEventManager().trigger(context, id, type, ActionTrigger.SUCCESS);
|
|
||||||
player.setStatistic(Statistic.FISH_CAUGHT, player.getStatistic(Statistic.FISH_CAUGHT) + 1);
|
|
||||||
if (!nextLoot.disableStats()) {
|
if (!nextLoot.disableStats()) {
|
||||||
plugin.getStorageManager().getOnlineUser(player.getUniqueId()).ifPresent(
|
plugin.getStorageManager().getOnlineUser(player.getUniqueId()).ifPresent(
|
||||||
userData -> {
|
userData -> {
|
||||||
userData.statistics().addAmount(id, 1);
|
userData.statistics().addAmount(id, 1);
|
||||||
Optional.ofNullable(context.arg(ContextKeys.SIZE)).ifPresent(size -> {
|
Optional.ofNullable(context.arg(ContextKeys.SIZE)).ifPresent(size -> {
|
||||||
|
float max = Math.max(0, userData.statistics().getMaxSize(id));
|
||||||
|
context.arg(ContextKeys.RECORD, max);
|
||||||
|
context.arg(ContextKeys.RECORD_FORMATTED, String.format("%.2f", max));
|
||||||
if (userData.statistics().updateSize(id, size)) {
|
if (userData.statistics().updateSize(id, size)) {
|
||||||
plugin.getEventManager().trigger(context, id, type, ActionTrigger.NEW_SIZE_RECORD);
|
plugin.getEventManager().trigger(context, id, type, ActionTrigger.NEW_SIZE_RECORD);
|
||||||
}
|
}
|
||||||
@@ -430,5 +446,8 @@ public class CustomFishingHook {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.getEventManager().trigger(context, id, type, ActionTrigger.SUCCESS);
|
||||||
|
player.setStatistic(Statistic.FISH_CAUGHT, player.getStatistic(Statistic.FISH_CAUGHT) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable {
|
public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable {
|
||||||
|
|
||||||
// private final FishingManager manager;
|
|
||||||
protected long deadline;
|
protected long deadline;
|
||||||
protected boolean success;
|
protected boolean success;
|
||||||
protected SchedulerTask task;
|
protected SchedulerTask task;
|
||||||
@@ -130,8 +129,16 @@ public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable {
|
|||||||
protected abstract void tick();
|
protected abstract void tick();
|
||||||
|
|
||||||
protected void endGame() {
|
protected void endGame() {
|
||||||
hook.handleGameResult();
|
destroy();
|
||||||
valid = false;
|
boolean success = isSuccessful();
|
||||||
|
BukkitCustomFishingPlugin.getInstance().getScheduler().sync().run(() -> {
|
||||||
|
if (success) {
|
||||||
|
hook.handleSuccessfulFishing();
|
||||||
|
} else {
|
||||||
|
hook.handleFailedFishing();
|
||||||
|
}
|
||||||
|
hook.end();
|
||||||
|
}, hook.getHookEntity().getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setGameResult(boolean success) {
|
protected void setGameResult(boolean success) {
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public interface Loot {
|
|||||||
*/
|
*/
|
||||||
boolean showInFinder();
|
boolean showInFinder();
|
||||||
|
|
||||||
|
boolean preventGrabbing();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the unique identifier for this loot.
|
* Get the unique identifier for this loot.
|
||||||
*
|
*
|
||||||
@@ -151,6 +153,8 @@ public interface Loot {
|
|||||||
*/
|
*/
|
||||||
Builder disableGame(boolean disableGame);
|
Builder disableGame(boolean disableGame);
|
||||||
|
|
||||||
|
Builder preventGrabbing(boolean preventGrabbing);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify whether statistics recording is disabled for this loot.
|
* Specify whether statistics recording is disabled for this loot.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class LootImpl implements Loot {
|
|||||||
private final boolean disableGame;
|
private final boolean disableGame;
|
||||||
private final boolean disableStatistics;
|
private final boolean disableStatistics;
|
||||||
private final boolean showInFinder;
|
private final boolean showInFinder;
|
||||||
|
private final boolean preventGrabbing;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String nick;
|
private final String nick;
|
||||||
private final StatisticsKeys statisticsKeys;
|
private final StatisticsKeys statisticsKeys;
|
||||||
@@ -41,7 +42,7 @@ public class LootImpl implements Loot {
|
|||||||
private final String[] groups;
|
private final String[] groups;
|
||||||
private final LootBaseEffect lootBaseEffect;
|
private final LootBaseEffect lootBaseEffect;
|
||||||
|
|
||||||
public LootImpl(LootType type, boolean instantGame, boolean disableGame, boolean disableStatistics, boolean showInFinder, String id, String nick, StatisticsKeys statisticsKeys, MathValue<Player> score, String[] groups, LootBaseEffect lootBaseEffect) {
|
public LootImpl(LootType type, boolean instantGame, boolean disableGame, boolean disableStatistics, boolean showInFinder, boolean preventGrabbing, String id, String nick, StatisticsKeys statisticsKeys, MathValue<Player> score, String[] groups, LootBaseEffect lootBaseEffect) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.instantGame = instantGame;
|
this.instantGame = instantGame;
|
||||||
this.disableGame = disableGame;
|
this.disableGame = disableGame;
|
||||||
@@ -53,6 +54,7 @@ public class LootImpl implements Loot {
|
|||||||
this.score = score;
|
this.score = score;
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
this.lootBaseEffect = lootBaseEffect;
|
this.lootBaseEffect = lootBaseEffect;
|
||||||
|
this.preventGrabbing = preventGrabbing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,6 +88,11 @@ public class LootImpl implements Loot {
|
|||||||
return showInFinder;
|
return showInFinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean preventGrabbing() {
|
||||||
|
return preventGrabbing;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MathValue<Player> score() {
|
public MathValue<Player> score() {
|
||||||
return score;
|
return score;
|
||||||
@@ -118,6 +125,7 @@ public class LootImpl implements Loot {
|
|||||||
private boolean disableGame = Loot.DefaultProperties.DEFAULT_DISABLE_GAME;
|
private boolean disableGame = Loot.DefaultProperties.DEFAULT_DISABLE_GAME;
|
||||||
private boolean disableStatistics = Loot.DefaultProperties.DEFAULT_DISABLE_STATS;
|
private boolean disableStatistics = Loot.DefaultProperties.DEFAULT_DISABLE_STATS;
|
||||||
private boolean showInFinder = Loot.DefaultProperties.DEFAULT_SHOW_IN_FINDER;
|
private boolean showInFinder = Loot.DefaultProperties.DEFAULT_SHOW_IN_FINDER;
|
||||||
|
private boolean preventGrabbing = false;
|
||||||
private String id = null;
|
private String id = null;
|
||||||
private String nick = "UNDEFINED";
|
private String nick = "UNDEFINED";
|
||||||
private StatisticsKeys statisticsKeys = null;
|
private StatisticsKeys statisticsKeys = null;
|
||||||
@@ -141,6 +149,11 @@ public class LootImpl implements Loot {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
public Builder preventGrabbing(boolean preventGrabbing) {
|
||||||
|
this.preventGrabbing = preventGrabbing;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public Builder disableStatistics(boolean disableStatistics) {
|
public Builder disableStatistics(boolean disableStatistics) {
|
||||||
this.disableStatistics = disableStatistics;
|
this.disableStatistics = disableStatistics;
|
||||||
return this;
|
return this;
|
||||||
@@ -188,6 +201,7 @@ public class LootImpl implements Loot {
|
|||||||
disableGame,
|
disableGame,
|
||||||
disableStatistics,
|
disableStatistics,
|
||||||
showInFinder,
|
showInFinder,
|
||||||
|
preventGrabbing,
|
||||||
requireNonNull(id),
|
requireNonNull(id),
|
||||||
Optional.ofNullable(nick).orElse(id),
|
Optional.ofNullable(nick).orElse(id),
|
||||||
Optional.ofNullable(statisticsKeys).orElse(new StatisticsKeys(id, id)),
|
Optional.ofNullable(statisticsKeys).orElse(new StatisticsKeys(id, id)),
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public class FishingStatisticsImpl implements FishingStatistics {
|
|||||||
float previous = sizeMap.getOrDefault(id, 0f);
|
float previous = sizeMap.getOrDefault(id, 0f);
|
||||||
if (previous >= newSize) return false;
|
if (previous >= newSize) return false;
|
||||||
sizeMap.put(id, newSize);
|
sizeMap.put(id, newSize);
|
||||||
|
System.out.println(sizeMap);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public abstract class AbstractJavaScheduler<T> implements SchedulerAdapter<T> {
|
|||||||
public AbstractJavaScheduler(CustomFishingPlugin plugin) {
|
public AbstractJavaScheduler(CustomFishingPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
this.scheduler = new ScheduledThreadPoolExecutor(1, r -> {
|
this.scheduler = new ScheduledThreadPoolExecutor(4, r -> {
|
||||||
Thread thread = Executors.defaultThreadFactory().newThread(r);
|
Thread thread = Executors.defaultThreadFactory().newThread(r);
|
||||||
thread.setName("customfishing-scheduler");
|
thread.setName("customfishing-scheduler");
|
||||||
return thread;
|
return thread;
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ public class StatisticsPapi extends PlaceholderExpansion {
|
|||||||
return String.valueOf(statistics.getAmount(split[1]));
|
return String.valueOf(statistics.getAmount(split[1]));
|
||||||
}
|
}
|
||||||
case "size-record" -> {
|
case "size-record" -> {
|
||||||
return String.format("%.2f", statistics.getMaxSize(split[1]));
|
float size = statistics.getMaxSize(split[1]);
|
||||||
|
return String.format("%.2f", size < 0 ? 0 : size);
|
||||||
}
|
}
|
||||||
case "category" -> {
|
case "category" -> {
|
||||||
if (split.length == 1) return "Invalid format";
|
if (split.length == 1) return "Invalid format";
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ dependencies {
|
|||||||
implementation("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
|
implementation("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
|
||||||
// nms util
|
// nms util
|
||||||
implementation("com.github.Xiao-MoMi:Sparrow-Heart:${rootProject.properties["sparrow_heart_version"]}")
|
implementation("com.github.Xiao-MoMi:Sparrow-Heart:${rootProject.properties["sparrow_heart_version"]}")
|
||||||
//implementation(files("libs/Sparrow-Heart-${rootProject.properties["sparrow_heart_version"]}.jar"))
|
// implementation(files("libs/Sparrow-Heart-${rootProject.properties["sparrow_heart_version"]}.jar"))
|
||||||
// bstats
|
// bstats
|
||||||
compileOnly("org.bstats:bstats-bukkit:${rootProject.properties["bstats_version"]}")
|
compileOnly("org.bstats:bstats-bukkit:${rootProject.properties["bstats_version"]}")
|
||||||
// config
|
// config
|
||||||
|
|||||||
@@ -19,17 +19,26 @@ package net.momirealms.customfishing.bukkit.bag;
|
|||||||
|
|
||||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||||
|
import net.momirealms.customfishing.api.event.FishingBagPreCollectEvent;
|
||||||
|
import net.momirealms.customfishing.api.event.FishingLootSpawnEvent;
|
||||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||||
|
import net.momirealms.customfishing.api.mechanic.action.ActionManager;
|
||||||
import net.momirealms.customfishing.api.mechanic.bag.BagManager;
|
import net.momirealms.customfishing.api.mechanic.bag.BagManager;
|
||||||
import net.momirealms.customfishing.api.mechanic.bag.FishingBagHolder;
|
import net.momirealms.customfishing.api.mechanic.bag.FishingBagHolder;
|
||||||
|
import net.momirealms.customfishing.api.mechanic.context.Context;
|
||||||
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
|
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
|
||||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||||
|
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
|
||||||
import net.momirealms.customfishing.api.storage.user.UserData;
|
import net.momirealms.customfishing.api.storage.user.UserData;
|
||||||
|
import net.momirealms.customfishing.api.util.EventUtils;
|
||||||
import net.momirealms.customfishing.bukkit.config.BukkitConfigManager;
|
import net.momirealms.customfishing.bukkit.config.BukkitConfigManager;
|
||||||
|
import net.momirealms.customfishing.bukkit.util.ItemStackUtils;
|
||||||
|
import net.momirealms.customfishing.bukkit.util.PlayerUtils;
|
||||||
import net.momirealms.customfishing.common.helper.AdventureHelper;
|
import net.momirealms.customfishing.common.helper.AdventureHelper;
|
||||||
import net.momirealms.sparrow.heart.SparrowHeart;
|
import net.momirealms.sparrow.heart.SparrowHeart;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@@ -51,6 +60,7 @@ public class BukkitBagManager implements BagManager, Listener {
|
|||||||
private Action<Player>[] collectLootActions;
|
private Action<Player>[] collectLootActions;
|
||||||
private Action<Player>[] bagFullActions;
|
private Action<Player>[] bagFullActions;
|
||||||
private boolean bagStoreLoots;
|
private boolean bagStoreLoots;
|
||||||
|
private boolean enable;
|
||||||
private String bagTitle;
|
private String bagTitle;
|
||||||
private List<Material> bagWhiteListItems = new ArrayList<>();
|
private List<Material> bagWhiteListItems = new ArrayList<>();
|
||||||
private Requirement<Player>[] collectRequirements;
|
private Requirement<Player>[] collectRequirements;
|
||||||
@@ -77,9 +87,55 @@ public class BukkitBagManager implements BagManager, Listener {
|
|||||||
this.plugin.getStorageManager().getDataSource().updateManyPlayersData(tempEditMap.values(), true);
|
this.plugin.getStorageManager().getDataSource().updateManyPlayersData(tempEditMap.values(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onLootSpawn(FishingLootSpawnEvent event) {
|
||||||
|
if (!enable || !bagStoreLoots) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!event.summonEntity()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(event.getEntity() instanceof Item itemEntity)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Context<Player> context = event.getContext();
|
||||||
|
if (!RequirementManager.isSatisfied(context, collectRequirements)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<UserData> onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
||||||
|
if (onlineUser.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UserData userData = onlineUser.get();
|
||||||
|
Inventory inventory = userData.holder().getInventory();
|
||||||
|
ItemStack item = itemEntity.getItemStack();
|
||||||
|
FishingBagPreCollectEvent preCollectEvent = new FishingBagPreCollectEvent(player, item, inventory);
|
||||||
|
if (EventUtils.fireAndCheckCancel(preCollectEvent)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cannotPut = PlayerUtils.putItemsToInventory(inventory, item, item.getAmount());
|
||||||
|
// some are put into bag
|
||||||
|
if (cannotPut != item.getAmount()) {
|
||||||
|
ActionManager.trigger(context, collectLootActions);
|
||||||
|
}
|
||||||
|
// all are put
|
||||||
|
if (cannotPut == 0) {
|
||||||
|
event.summonEntity(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
item.setAmount(cannotPut);
|
||||||
|
itemEntity.setItemStack(item);
|
||||||
|
ActionManager.trigger(context, bagFullActions);
|
||||||
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
private void loadConfig() {
|
||||||
Section config = BukkitConfigManager.getMainConfig().getSection("mechanics.fishing-bag");
|
Section config = BukkitConfigManager.getMainConfig().getSection("mechanics.fishing-bag");
|
||||||
|
|
||||||
|
enable = config.getBoolean("enable", true);
|
||||||
bagTitle = config.getString("bag-title", "");
|
bagTitle = config.getString("bag-title", "");
|
||||||
bagStoreLoots = config.getBoolean("can-store-loot", false);
|
bagStoreLoots = config.getBoolean("can-store-loot", false);
|
||||||
bagWhiteListItems = config.getStringList("whitelist-items").stream().map(it -> Material.valueOf(it.toUpperCase(Locale.ENGLISH))).toList();
|
bagWhiteListItems = config.getStringList("whitelist-items").stream().map(it -> Material.valueOf(it.toUpperCase(Locale.ENGLISH))).toList();
|
||||||
@@ -91,21 +147,25 @@ public class BukkitBagManager implements BagManager, Listener {
|
|||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> openBag(Player viewer, UUID owner) {
|
public CompletableFuture<Boolean> openBag(Player viewer, UUID owner) {
|
||||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
Optional<UserData> onlineUser = plugin.getStorageManager().getOnlineUser(owner);
|
if (enable) {
|
||||||
onlineUser.ifPresentOrElse(data -> {
|
Optional<UserData> onlineUser = plugin.getStorageManager().getOnlineUser(owner);
|
||||||
viewer.openInventory(data.holder().getInventory());
|
onlineUser.ifPresentOrElse(data -> {
|
||||||
SparrowHeart.getInstance().updateInventoryTitle(viewer, AdventureHelper.componentToJson(AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(Bukkit.getOfflinePlayer(owner), bagTitle, Map.of("{uuid}", owner.toString(), "{player}", data.name())))));
|
viewer.openInventory(data.holder().getInventory());
|
||||||
future.complete(true);
|
SparrowHeart.getInstance().updateInventoryTitle(viewer, AdventureHelper.componentToJson(AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(Bukkit.getOfflinePlayer(owner), bagTitle, Map.of("{uuid}", owner.toString(), "{player}", data.name())))));
|
||||||
}, () -> plugin.getStorageManager().getOfflineUserData(owner, true).thenAccept(result -> result.ifPresentOrElse(data -> {
|
future.complete(true);
|
||||||
if (data.isLocked()) {
|
}, () -> plugin.getStorageManager().getOfflineUserData(owner, true).thenAccept(result -> result.ifPresentOrElse(data -> {
|
||||||
future.completeExceptionally(new RuntimeException("Data is locked"));
|
if (data.isLocked()) {
|
||||||
return;
|
future.completeExceptionally(new RuntimeException("Data is locked"));
|
||||||
}
|
return;
|
||||||
this.tempEditMap.put(viewer.getUniqueId(), data);
|
}
|
||||||
viewer.openInventory(data.holder().getInventory());
|
this.tempEditMap.put(viewer.getUniqueId(), data);
|
||||||
SparrowHeart.getInstance().updateInventoryTitle(viewer, AdventureHelper.componentToJson(AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(Bukkit.getOfflinePlayer(owner), bagTitle, Map.of("{uuid}", owner.toString(), "{player}", data.name())))));
|
viewer.openInventory(data.holder().getInventory());
|
||||||
future.complete(true);
|
SparrowHeart.getInstance().updateInventoryTitle(viewer, AdventureHelper.componentToJson(AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(Bukkit.getOfflinePlayer(owner), bagTitle, Map.of("{uuid}", owner.toString(), "{player}", data.name())))));
|
||||||
}, () -> future.complete(false))));
|
future.complete(true);
|
||||||
|
}, () -> future.complete(false))));
|
||||||
|
} else {
|
||||||
|
future.complete(false);
|
||||||
|
}
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ public class BukkitBlockManager implements BlockManager, Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@NotNull
|
||||||
public FallingBlock summonBlockLoot(@NotNull Context<Player> context) {
|
public FallingBlock summonBlockLoot(@NotNull Context<Player> context) {
|
||||||
String id = context.arg(ContextKeys.ID);
|
String id = context.arg(ContextKeys.ID);
|
||||||
BlockConfig config = requireNonNull(blocks.get(id), "Block " + id + " not found");
|
BlockConfig config = requireNonNull(blocks.get(id), "Block " + id + " not found");
|
||||||
|
|||||||
@@ -779,6 +779,10 @@ public class BukkitConfigManager extends ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerBuiltInLootParser() {
|
private void registerBuiltInLootParser() {
|
||||||
|
this.registerLootParser(object -> {
|
||||||
|
boolean value = (boolean) object;
|
||||||
|
return builder -> builder.preventGrabbing(value);
|
||||||
|
}, "prevent-grabbing");
|
||||||
this.registerLootParser(object -> {
|
this.registerLootParser(object -> {
|
||||||
String string = (String) object;
|
String string = (String) object;
|
||||||
return builder -> builder.nick(string);
|
return builder -> builder.nick(string);
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class BukkitEntityManager implements EntityManager {
|
|||||||
return entityProviders.remove(id) != null;
|
return entityProviders.remove(id) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Entity summonEntityLoot(Context<Player> context) {
|
public Entity summonEntityLoot(Context<Player> context) {
|
||||||
String id = context.arg(ContextKeys.ID);
|
String id = context.arg(ContextKeys.ID);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class BukkitFishingManager implements FishingManager, Listener {
|
public class BukkitFishingManager implements FishingManager, Listener {
|
||||||
|
|
||||||
@@ -257,12 +258,12 @@ public class BukkitFishingManager implements FishingManager, Listener {
|
|||||||
private void onReelIn(PlayerFishEvent event) {
|
private void onReelIn(PlayerFishEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
getFishHook(player).ifPresent(hook -> {
|
getFishHook(player).ifPresent(hook -> {
|
||||||
|
event.setCancelled(true);
|
||||||
Optional<GamingPlayer> gamingPlayer = hook.getGamingPlayer();
|
Optional<GamingPlayer> gamingPlayer = hook.getGamingPlayer();
|
||||||
if (gamingPlayer.isPresent()) {
|
if (gamingPlayer.isPresent()) {
|
||||||
((AbstractGamingPlayer) gamingPlayer.get()).internalRightClick();
|
((AbstractGamingPlayer) gamingPlayer.get()).internalRightClick();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
|
||||||
hook.onReelIn();
|
hook.onReelIn();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -832,8 +832,8 @@ public class BukkitGameManager implements GameManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void arrangeTask() {
|
public void arrangeTask() {
|
||||||
var period = ((double) 10*(200-settings.difficulty()))/((double) (1+4*settings.difficulty()));
|
var period = Math.min(200, ((double) 10*(200-settings.difficulty()))/((double) (1+4*settings.difficulty())));
|
||||||
this.task = plugin.getScheduler().asyncRepeating(this, 50, (long) period, TimeUnit.MILLISECONDS);
|
this.task = plugin.getScheduler().asyncRepeating(this, 10, (long) 10, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -847,6 +847,7 @@ public class BukkitGameManager implements GameManager {
|
|||||||
face = !face;
|
face = !face;
|
||||||
progress = -progress;
|
progress = -progress;
|
||||||
}
|
}
|
||||||
|
if (!isValid()) return;
|
||||||
showUI();
|
showUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -862,7 +863,7 @@ public class BukkitGameManager implements GameManager {
|
|||||||
+ OffsetUtils.getOffsetChars(pointerOffset + progress)
|
+ OffsetUtils.getOffsetChars(pointerOffset + progress)
|
||||||
+ AdventureHelper.surroundWithMiniMessageFont(pointerImage, font)
|
+ AdventureHelper.surroundWithMiniMessageFont(pointerImage, font)
|
||||||
+ OffsetUtils.getOffsetChars(totalWidth - progress - pointerWidth);
|
+ OffsetUtils.getOffsetChars(totalWidth - progress - pointerWidth);
|
||||||
SparrowHeart.getInstance().sendTitle(getPlayer(), AdventureHelper.miniMessageToJson(sendTitle.render(hook.getContext())), AdventureHelper.miniMessageToJson(bar), 0, 20, 0);
|
SparrowHeart.getInstance().sendTitle(getPlayer(), AdventureHelper.miniMessageToJson(sendTitle.render(hook.getContext())), AdventureHelper.miniMessageToJson(bar), 0, 10, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.*;
|
import org.bukkit.event.block.*;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||||
|
import org.bukkit.event.player.PlayerAttemptPickupItemEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
@@ -196,12 +197,6 @@ public class BukkitItemManager implements ItemManager, Listener {
|
|||||||
Vector vector = new Vector(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
|
Vector vector = new Vector(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
|
||||||
|
|
||||||
org.bukkit.entity.Item itemEntity = hookLocation.getWorld().dropItem(hookLocation, itemStack);
|
org.bukkit.entity.Item itemEntity = hookLocation.getWorld().dropItem(hookLocation, itemStack);
|
||||||
FishingLootSpawnEvent spawnEvent = new FishingLootSpawnEvent(player, hookLocation, plugin.getLootManager().getLoot(id).orElseThrow(), itemEntity);
|
|
||||||
Bukkit.getPluginManager().callEvent(spawnEvent);
|
|
||||||
if (spawnEvent.isCancelled()) {
|
|
||||||
itemEntity.remove();
|
|
||||||
return itemEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemEntity.setInvulnerable(true);
|
itemEntity.setInvulnerable(true);
|
||||||
// prevent from being killed by lava
|
// prevent from being killed by lava
|
||||||
@@ -340,6 +335,16 @@ public class BukkitItemManager implements ItemManager, Listener {
|
|||||||
handleExplosion(event.blockList());
|
handleExplosion(event.blockList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler (ignoreCancelled = true)
|
||||||
|
public void onPickUpItem(PlayerAttemptPickupItemEvent event) {
|
||||||
|
String owner = event.getItem().getPersistentDataContainer().get(requireNonNull(NamespacedKey.fromString("owner", plugin.getBoostrap())), PersistentDataType.STRING);
|
||||||
|
if (owner != null) {
|
||||||
|
if (!owner.equals(event.getPlayer().getName())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleExplosion(List<Block> blocks) {
|
private void handleExplosion(List<Block> blocks) {
|
||||||
ArrayList<Block> blockToRemove = new ArrayList<>();
|
ArrayList<Block> blockToRemove = new ArrayList<>();
|
||||||
for (Block block : blocks) {
|
for (Block block : blocks) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import net.momirealms.customfishing.common.util.RandomUtils;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@@ -54,6 +55,47 @@ public class PlayerUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int putItemsToInventory(Inventory inventory, ItemStack itemStack, int amount) {
|
||||||
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
|
int maxStackSize = itemStack.getMaxStackSize();
|
||||||
|
for (ItemStack other : inventory.getStorageContents()) {
|
||||||
|
if (other != null) {
|
||||||
|
if (other.getType() == itemStack.getType() && other.getItemMeta().equals(meta)) {
|
||||||
|
if (other.getAmount() < maxStackSize) {
|
||||||
|
int delta = maxStackSize - other.getAmount();
|
||||||
|
if (amount > delta) {
|
||||||
|
other.setAmount(maxStackSize);
|
||||||
|
amount -= delta;
|
||||||
|
} else {
|
||||||
|
other.setAmount(amount + other.getAmount());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount > 0) {
|
||||||
|
for (ItemStack other : inventory.getStorageContents()) {
|
||||||
|
if (other == null) {
|
||||||
|
if (amount > maxStackSize) {
|
||||||
|
amount -= maxStackSize;
|
||||||
|
ItemStack cloned = itemStack.clone();
|
||||||
|
cloned.setAmount(maxStackSize);
|
||||||
|
inventory.addItem(cloned);
|
||||||
|
} else {
|
||||||
|
ItemStack cloned = itemStack.clone();
|
||||||
|
cloned.setAmount(amount);
|
||||||
|
inventory.addItem(cloned);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
public static int giveItem(Player player, ItemStack itemStack, int amount) {
|
public static int giveItem(Player player, ItemStack itemStack, int amount) {
|
||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ config-version: "${config_version}"
|
|||||||
#
|
#
|
||||||
# For safety reasons, editing this file requires a restart to apply
|
# For safety reasons, editing this file requires a restart to apply
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# A command to reload the plugin
|
||||||
reload:
|
reload:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.reload
|
permission: customfishing.command.reload
|
||||||
@@ -13,18 +15,21 @@ reload:
|
|||||||
- /customfishing reload
|
- /customfishing reload
|
||||||
- /cfishing reload
|
- /cfishing reload
|
||||||
|
|
||||||
|
# A command designed for players to sell fish
|
||||||
sellfish:
|
sellfish:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.sellfish
|
permission: customfishing.sellfish
|
||||||
usage:
|
usage:
|
||||||
- /sellfish
|
- /sellfish
|
||||||
|
|
||||||
|
# A command designed for players to open the fishing bag
|
||||||
fishingbag:
|
fishingbag:
|
||||||
enable: true
|
enable: true
|
||||||
permission: fishingbag.user
|
permission: fishingbag.user
|
||||||
usage:
|
usage:
|
||||||
- /fishingbag
|
- /fishingbag
|
||||||
|
|
||||||
|
# A command to get items
|
||||||
get_item:
|
get_item:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.getitem
|
permission: customfishing.command.getitem
|
||||||
@@ -32,6 +37,7 @@ get_item:
|
|||||||
- /customfishing items get
|
- /customfishing items get
|
||||||
- /cfishing items get
|
- /cfishing items get
|
||||||
|
|
||||||
|
# A command to give items
|
||||||
give_item:
|
give_item:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.giveitem
|
permission: customfishing.command.giveitem
|
||||||
@@ -39,6 +45,7 @@ give_item:
|
|||||||
- /customfishing items give
|
- /customfishing items give
|
||||||
- /cfishing items give
|
- /cfishing items give
|
||||||
|
|
||||||
|
# A command to stop the competition
|
||||||
stop_competition:
|
stop_competition:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.competition
|
permission: customfishing.command.competition
|
||||||
@@ -46,6 +53,7 @@ stop_competition:
|
|||||||
- /customfishing competition stop
|
- /customfishing competition stop
|
||||||
- /cfishing competition stop
|
- /cfishing competition stop
|
||||||
|
|
||||||
|
# A command to end the competition
|
||||||
end_competition:
|
end_competition:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.competition
|
permission: customfishing.command.competition
|
||||||
@@ -53,6 +61,7 @@ end_competition:
|
|||||||
- /customfishing competition end
|
- /customfishing competition end
|
||||||
- /cfishing competition end
|
- /cfishing competition end
|
||||||
|
|
||||||
|
# A command to start competitions
|
||||||
start_competition:
|
start_competition:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.competition
|
permission: customfishing.command.competition
|
||||||
@@ -60,6 +69,7 @@ start_competition:
|
|||||||
- /customfishing competition start
|
- /customfishing competition start
|
||||||
- /cfishing competition start
|
- /cfishing competition start
|
||||||
|
|
||||||
|
# A command to open market for players
|
||||||
open_market:
|
open_market:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.open.market
|
permission: customfishing.command.open.market
|
||||||
@@ -67,6 +77,7 @@ open_market:
|
|||||||
- /customfishing open market
|
- /customfishing open market
|
||||||
- /cfishing open market
|
- /cfishing open market
|
||||||
|
|
||||||
|
# A command to open bag for players
|
||||||
open_bag:
|
open_bag:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.open.bag
|
permission: customfishing.command.open.bag
|
||||||
@@ -74,6 +85,7 @@ open_bag:
|
|||||||
- /customfishing open bag
|
- /customfishing open bag
|
||||||
- /cfishing open bag
|
- /cfishing open bag
|
||||||
|
|
||||||
|
# A command to edit bag contents
|
||||||
edit_online_bag:
|
edit_online_bag:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.edit.bag
|
permission: customfishing.command.edit.bag
|
||||||
@@ -81,16 +93,10 @@ edit_online_bag:
|
|||||||
- /customfishing fishingbag edit-online
|
- /customfishing fishingbag edit-online
|
||||||
- /cfishing fishingbag edit-online
|
- /cfishing fishingbag edit-online
|
||||||
|
|
||||||
|
# A command to edit bag contents
|
||||||
edit_offline_bag:
|
edit_offline_bag:
|
||||||
enable: true
|
enable: true
|
||||||
permission: customfishing.command.edit.bag
|
permission: customfishing.command.edit.bag
|
||||||
usage:
|
usage:
|
||||||
- /customfishing fishingbag edit-offline
|
- /customfishing fishingbag edit-offline
|
||||||
- /cfishing fishingbag edit-offline
|
- /cfishing fishingbag edit-offline
|
||||||
|
|
||||||
browser:
|
|
||||||
enable: true
|
|
||||||
permission: customfishing.command.browser
|
|
||||||
usage:
|
|
||||||
- /customfishing browser
|
|
||||||
- /cfishing browser
|
|
||||||
@@ -57,7 +57,7 @@ mechanics:
|
|||||||
actions:
|
actions:
|
||||||
actionbar_action:
|
actionbar_action:
|
||||||
type: actionbar
|
type: actionbar
|
||||||
value: '<#FFD700>[New Record]</#FFD700> <#FFFFF0>You caught a(n) {nick} which is <#FFA500>{size}cm</#FFA500> long!</#FFFFF0>'
|
value: '<#FFD700>[New Record]</#FFD700> <#FFFFF0>You caught a(n) {nick} which is <#FFA500>{size_formatted}cm</#FFA500> long!</#FFFFF0>'
|
||||||
sound_action:
|
sound_action:
|
||||||
type: sound
|
type: sound
|
||||||
value:
|
value:
|
||||||
@@ -87,7 +87,7 @@ mechanics:
|
|||||||
actions:
|
actions:
|
||||||
actionbar_action:
|
actionbar_action:
|
||||||
type: actionbar
|
type: actionbar
|
||||||
value: '<gray>You caught a(n) {nick} which is <#F5F5F5>{size}cm</#F5F5F5> long!</gray> <#C0C0C0>(Best record: {record}cm)</#C0C0C0>'
|
value: '<gray>You caught a(n) {nick} which is <#F5F5F5>{size_formatted}cm</#F5F5F5> long!</gray> <#C0C0C0>(Best record: {record_formatted}cm)</#C0C0C0>'
|
||||||
title_action:
|
title_action:
|
||||||
type: random-title
|
type: random-title
|
||||||
value:
|
value:
|
||||||
@@ -407,7 +407,6 @@ other-settings:
|
|||||||
lock-data: true
|
lock-data: true
|
||||||
# Requires PlaceholderAPI to work
|
# Requires PlaceholderAPI to work
|
||||||
placeholder-register:
|
placeholder-register:
|
||||||
'{record}': '%fishingstats_size-record_{loot}%'
|
|
||||||
# Requires server expansion
|
# Requires server expansion
|
||||||
'{date}': '%server_time_yyyy-MM-dd-HH:mm:ss%'
|
'{date}': '%server_time_yyyy-MM-dd-HH:mm:ss%'
|
||||||
# Requires player expansion
|
# Requires player expansion
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ h2_driver_version=2.2.224
|
|||||||
sqlite_driver_version=3.46.0.0
|
sqlite_driver_version=3.46.0.0
|
||||||
adventure_bundle_version=4.17.0
|
adventure_bundle_version=4.17.0
|
||||||
adventure_platform_version=4.3.3
|
adventure_platform_version=4.3.3
|
||||||
sparrow_heart_version=0.23
|
sparrow_heart_version=0.27
|
||||||
cloud_core_version=2.0.0-rc.2
|
cloud_core_version=2.0.0-rc.2
|
||||||
cloud_services_version=2.0.0-rc.2
|
cloud_services_version=2.0.0-rc.2
|
||||||
cloud_brigadier_version=2.0.0-beta.8
|
cloud_brigadier_version=2.0.0-beta.8
|
||||||
|
|||||||
Reference in New Issue
Block a user