mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-19 15:09:25 +00:00
fix possible NPE from plant action
This commit is contained in:
@@ -37,7 +37,6 @@ import net.momirealms.customcrops.api.core.world.Pos3;
|
|||||||
import net.momirealms.customcrops.api.event.CropPlantEvent;
|
import net.momirealms.customcrops.api.event.CropPlantEvent;
|
||||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||||
import net.momirealms.customcrops.api.util.EventUtils;
|
import net.momirealms.customcrops.api.util.EventUtils;
|
||||||
import net.momirealms.customcrops.api.util.LocationUtils;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
@@ -51,7 +50,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
|||||||
private final int point;
|
private final int point;
|
||||||
private final String key;
|
private final String key;
|
||||||
private final int y;
|
private final int y;
|
||||||
private final boolean triggerAction;
|
private final boolean triggerEvent;
|
||||||
|
|
||||||
public ActionPlant(
|
public ActionPlant(
|
||||||
BukkitCustomCropsPlugin plugin,
|
BukkitCustomCropsPlugin plugin,
|
||||||
@@ -62,7 +61,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
|||||||
this.point = section.getInt("point", 0);
|
this.point = section.getInt("point", 0);
|
||||||
this.key = requireNonNull(section.getString("crop"));
|
this.key = requireNonNull(section.getString("crop"));
|
||||||
this.y = section.getInt("y", 0);
|
this.y = section.getInt("y", 0);
|
||||||
this.triggerAction = section.getBoolean("trigger-event", false);
|
this.triggerEvent = section.getBoolean("trigger-event", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -94,17 +93,15 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
|||||||
cropBlock.id(state, key);
|
cropBlock.id(state, key);
|
||||||
cropBlock.point(state, point);
|
cropBlock.point(state, point);
|
||||||
|
|
||||||
if (context.holder() instanceof Player player) {
|
if (context.holder() instanceof Player player && this.triggerEvent) {
|
||||||
EquipmentSlot slot = requireNonNull(context.arg(ContextKeys.SLOT));
|
EquipmentSlot slot = Optional.ofNullable(context.arg(ContextKeys.SLOT)).orElse(EquipmentSlot.HAND);
|
||||||
CropPlantEvent plantEvent = new CropPlantEvent(player, player.getInventory().getItem(slot), slot, cropLocation, cropConfig, state, point);
|
CropPlantEvent plantEvent = new CropPlantEvent(player, player.getInventory().getItem(slot), slot, cropLocation, cropConfig, state, point);
|
||||||
if (EventUtils.fireAndCheckCancel(plantEvent)) {
|
if (EventUtils.fireAndCheckCancel(plantEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cropBlock.point(state, plantEvent.point());
|
cropBlock.point(state, plantEvent.point());
|
||||||
if (triggerAction) {
|
|
||||||
ActionManager.trigger((Context<Player>) context, cropConfig.plantActions());
|
ActionManager.trigger((Context<Player>) context, cropConfig.plantActions());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CropStageConfig stageConfigWithModel = cropConfig.stageWithModelByPoint(cropBlock.point(state));
|
CropStageConfig stageConfigWithModel = cropConfig.stageWithModelByPoint(cropBlock.point(state));
|
||||||
world.addBlockState(Pos3.from(cropLocation), state);
|
world.addBlockState(Pos3.from(cropLocation), state);
|
||||||
@@ -127,6 +124,6 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean triggerPlantAction() {
|
public boolean triggerPlantAction() {
|
||||||
return triggerAction;
|
return triggerEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ public class BukkitConfigManager extends ConfigManager {
|
|||||||
save = true;
|
save = true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getPluginLogger().warn("Error occurs during parsing configs", e);
|
plugin.getPluginLogger().warn("Error occurs during parsing config section " + entry.getKey() + " in file " + subFile.toPath(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user