9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-28 03:19:15 +00:00

Fix some bugs

This commit is contained in:
XiaoMoMi
2024-09-06 01:48:07 +08:00
parent e1943950c2
commit 5632bf8bad
6 changed files with 28 additions and 12 deletions

View File

@@ -83,9 +83,9 @@ public class ActionBreak<T> extends AbstractBuiltInAction<T> {
if (player != null) {
EquipmentSlot slot = requireNonNull(context.arg(ContextKeys.SLOT));
ItemStack itemStack = player.getInventory().getItem(slot);
state.type().onBreak(new WrappedBreakEvent(player, null, world, location, stageConfig.stageID(), itemStack, plugin.getItemManager().id(itemStack), BreakReason.ACTION, dummyCancellable));
state.type().onBreak(new WrappedBreakEvent(player, null, context.arg(ContextKeys.SLOT), location, stageConfig.stageID(), itemStack, plugin.getItemManager().id(itemStack), BreakReason.ACTION, world, dummyCancellable));
} else {
state.type().onBreak(new WrappedBreakEvent(null, null, world, location, stageConfig.stageID(), null, null, BreakReason.ACTION, dummyCancellable));
state.type().onBreak(new WrappedBreakEvent(null, null, null, location, stageConfig.stageID(), null, null, BreakReason.ACTION, world, dummyCancellable));
}
if (dummyCancellable.isCancelled()) {
return;

View File

@@ -45,6 +45,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.List;
@@ -103,6 +104,9 @@ public class CropBlock extends AbstractCustomCropsBlock {
final Player player = event.playerBreaker();
Context<Player> context = Context.player(player);
if (event.hand() != null) {
context.arg(ContextKeys.SLOT, event.hand());
}
context.updateLocation(location);

View File

@@ -93,8 +93,11 @@ public class CropConfigImpl implements CropConfig {
point2Stages.put(config.point(), config);
navigablePoint2Stages.put(config.point(), config);
String stageID = config.stageID();
id2Stages.put(stageID, config);
stageIDs.add(stageID);
if (stageID != null) {
id2Stages.put(stageID, config);
stageIDs.add(stageID);
cropStageWithModelMap.put(config.point(), config);
}
}
CropStageConfig tempConfig = null;
for (int i = 0; i <= maxPoints; i++) {
@@ -206,7 +209,7 @@ public class CropConfigImpl implements CropConfig {
@Override
public CropStageConfig stageWithModelByPoint(int point) {
return cropStageWithModelMap.get(Math.min(maxPoints, point));
return cropStageWithModelMap.get(point);
}
@Override

View File

@@ -24,6 +24,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,22 +40,25 @@ public class WrappedBreakEvent {
private final Cancellable event;
private final CustomCropsWorld<?> world;
private final BreakReason reason;
private final EquipmentSlot hand;
public WrappedBreakEvent(
@Nullable Entity entityBreaker,
@Nullable Block blockBreaker,
CustomCropsWorld<?> world,
@Nullable EquipmentSlot hand,
Location location,
String brokenID,
ItemStack itemInHand,
String itemID,
BreakReason reason,
CustomCropsWorld<?> world,
Cancellable event
) {
this.entity = entityBreaker;
this.block = blockBreaker;
this.location = location;
this.brokenID = brokenID;
this.hand = hand;
this.itemInHand = itemInHand;
this.itemID = itemID;
this.event = event;
@@ -92,6 +96,11 @@ public class WrappedBreakEvent {
return itemID;
}
@Nullable
public EquipmentSlot hand() {
return hand;
}
public boolean isCancelled() {
return event.isCancelled();
}