mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-28 11:29:19 +00:00
3.4.1
This commit is contained in:
@@ -19,29 +19,31 @@ package net.momirealms.customcrops.api.event;
|
||||
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.WorldCrop;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* An event that triggered when breaking a crop
|
||||
*/
|
||||
public class CropBreakEvent extends PlayerEvent implements Cancellable {
|
||||
public class CropBreakEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final Location location;
|
||||
private final WorldCrop worldCrop;
|
||||
private final Entity entity;
|
||||
|
||||
public CropBreakEvent(
|
||||
@NotNull Player player,
|
||||
@Nullable Entity entity,
|
||||
@NotNull Location location,
|
||||
@Nullable WorldCrop worldCrop
|
||||
) {
|
||||
super(player);
|
||||
this.entity = entity;
|
||||
this.location = location;
|
||||
this.worldCrop = worldCrop;
|
||||
}
|
||||
@@ -84,4 +86,17 @@ public class CropBreakEvent extends PlayerEvent implements Cancellable {
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Player getPlayer() {
|
||||
if (entity instanceof Player player) {
|
||||
return player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.api.event;
|
||||
|
||||
import net.momirealms.customcrops.api.mechanic.item.water.PassiveFillMethod;
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.WorldPot;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An event that triggered when a pot is watered by the fill-methods set in each pot's config
|
||||
*/
|
||||
public class PotFillEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final Location location;
|
||||
private final WorldPot pot;
|
||||
private final ItemStack itemInHand;
|
||||
private final PassiveFillMethod fillMethod;
|
||||
|
||||
public PotFillEvent(
|
||||
@NotNull Player player,
|
||||
@NotNull ItemStack itemInHand,
|
||||
@NotNull Location location,
|
||||
@NotNull PassiveFillMethod fillMethod,
|
||||
@NotNull WorldPot pot
|
||||
) {
|
||||
super(player);
|
||||
this.location = location;
|
||||
this.itemInHand = itemInHand;
|
||||
this.pot = pot;
|
||||
this.fillMethod = fillMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pot location
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the pot's data
|
||||
* @return pot
|
||||
*/
|
||||
@NotNull
|
||||
public WorldPot getPot() {
|
||||
return pot;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PassiveFillMethod getFillMethod() {
|
||||
return fillMethod;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.api.event;
|
||||
|
||||
import net.momirealms.customcrops.api.mechanic.item.water.PassiveFillMethod;
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.WorldSprinkler;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An event that triggered when a sprinkler is watered by the fill-methods set in each sprinkler's config
|
||||
*/
|
||||
public class SprinklerFillEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final ItemStack itemInHand;
|
||||
private final Location location;
|
||||
private final PassiveFillMethod fillMethod;
|
||||
private final WorldSprinkler sprinkler;
|
||||
|
||||
public SprinklerFillEvent(
|
||||
@NotNull Player player,
|
||||
@NotNull ItemStack itemInHand,
|
||||
@NotNull Location location,
|
||||
@NotNull PassiveFillMethod fillMethod,
|
||||
@NotNull WorldSprinkler sprinkler
|
||||
) {
|
||||
super(player);
|
||||
this.itemInHand = itemInHand;
|
||||
this.location = location;
|
||||
this.fillMethod = fillMethod;
|
||||
this.sprinkler = sprinkler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item in player's hand
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sprinkler location
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PassiveFillMethod getFillMethod() {
|
||||
return fillMethod;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WorldSprinkler getSprinkler() {
|
||||
return sprinkler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.api.event;
|
||||
|
||||
import net.momirealms.customcrops.api.mechanic.item.WateringCan;
|
||||
import net.momirealms.customcrops.api.mechanic.item.water.PositiveFillMethod;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An event that triggered when player tries to add water to the watering-can
|
||||
*/
|
||||
public class WateringCanFillEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final ItemStack itemInHand;
|
||||
private final WateringCan wateringCan;
|
||||
private final PositiveFillMethod fillMethod;
|
||||
private final Location location;
|
||||
|
||||
public WateringCanFillEvent(
|
||||
@NotNull Player player,
|
||||
@NotNull ItemStack itemInHand,
|
||||
@NotNull WateringCan wateringCan,
|
||||
@NotNull Location location,
|
||||
@NotNull PositiveFillMethod fillMethod
|
||||
) {
|
||||
super(player);
|
||||
this.cancelled = false;
|
||||
this.itemInHand = itemInHand;
|
||||
this.wateringCan = wateringCan;
|
||||
this.location = location;
|
||||
this.fillMethod = fillMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WateringCan getWateringCan() {
|
||||
return wateringCan;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PositiveFillMethod getFillMethod() {
|
||||
return fillMethod;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.api.event;
|
||||
|
||||
import net.momirealms.customcrops.api.common.item.KeyItem;
|
||||
import net.momirealms.customcrops.api.mechanic.item.WateringCan;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An event that triggered when player tries to use watering-can to add water to pots/sprinklers
|
||||
*/
|
||||
public class WateringCanWaterEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final ItemStack itemInHand;
|
||||
private final WateringCan wateringCan;
|
||||
private final KeyItem potOrSprinkler;
|
||||
private final Location location;
|
||||
|
||||
public WateringCanWaterEvent(
|
||||
@NotNull Player player,
|
||||
@NotNull ItemStack itemInHand,
|
||||
@NotNull WateringCan wateringCan,
|
||||
@NotNull Location location,
|
||||
@NotNull KeyItem potOrSprinkler
|
||||
) {
|
||||
super(player);
|
||||
this.cancelled = false;
|
||||
this.itemInHand = itemInHand;
|
||||
this.wateringCan = wateringCan;
|
||||
this.location = location;
|
||||
this.potOrSprinkler = potOrSprinkler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WateringCan getWateringCan() {
|
||||
return wateringCan;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KeyItem getPotOrSprinkler() {
|
||||
return potOrSprinkler;
|
||||
}
|
||||
}
|
||||
@@ -35,14 +35,30 @@ public abstract class AbstractFillMethod {
|
||||
this.requirements = requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of water to add
|
||||
*
|
||||
* @return amount
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger actions related to this fill methods
|
||||
*
|
||||
* @param state state
|
||||
*/
|
||||
public void trigger(State state) {
|
||||
ActionManager.triggerActions(state, actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* If player meet the requirements for this fill method
|
||||
*
|
||||
* @param state state
|
||||
* @return meet or not
|
||||
*/
|
||||
public boolean canFill(State state) {
|
||||
return RequirementManager.isRequirementMet(state, requirements);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user