Harvest listener

This commit is contained in:
tastybento 2021-02-14 12:52:51 -08:00
parent 582aa9fa9e
commit 770d8b0bef
4 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,26 @@
package world.bentobox.bentobox.listeners.flags.protection;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerHarvestBlockEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
/**
* Handles harvesting
* @author tastybento
* @since 1.16.0
*/
public class HarvestListener extends FlagListener {
/**
* Handle visitor harvesting, e.g. honey
* @param e - event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public boolean onHarvest(PlayerHarvestBlockEvent e) {
return checkIsland(e, e.getPlayer(), e.getHarvestedBlock().getLocation(), Flags.HARVEST);
}
}

View File

@ -23,6 +23,7 @@ import world.bentobox.bentobox.listeners.flags.protection.ElytraListener;
import world.bentobox.bentobox.listeners.flags.protection.EntityInteractListener;
import world.bentobox.bentobox.listeners.flags.protection.ExperiencePickupListener;
import world.bentobox.bentobox.listeners.flags.protection.FireListener;
import world.bentobox.bentobox.listeners.flags.protection.HarvestListener;
import world.bentobox.bentobox.listeners.flags.protection.HurtingListener;
import world.bentobox.bentobox.listeners.flags.protection.InventoryListener;
import world.bentobox.bentobox.listeners.flags.protection.ItemDropPickUpListener;
@ -524,6 +525,12 @@ public final class Flags {
*/
public static final Flag PETS_STAY_AT_HOME = new Flag.Builder("PETS_STAY_AT_HOME", Material.TROPICAL_FISH).listener(new PetTeleportListener()).type(Type.WORLD_SETTING).defaultSetting(true).build();
/**
* Protects against harvesting, e.g. honey
* @since 1.16.0
* @see HarvestListener
*/
public static final Flag HARVEST = new Flag.Builder("HARVEST", Material.HONEY_BOTTLE).listener(new HarvestListener()).type(Type.PROTECTION).build();
/**
* Provides a list of all the Flag instances contained in this class using reflection.
* Deprecated Flags are ignored.

View File

@ -952,6 +952,12 @@ protection:
&a outside protected
&a island space
name: "&e Limit mobs to island"
HARVEST:
description: |-
&a Toggle harvesting, e.g.
&a honey harvesting
name: "Harvesting"
hint: "Harvesting disabled"
HURT_ANIMALS:
description: "Toggle hurting"
name: "Hurt animals"

View File

@ -46,7 +46,7 @@ public class FlagsManagerTest {
/**
* Update this value if the number of registered listeners changes
*/
private static final int NUMBER_OF_LISTENERS = 48;
private static final int NUMBER_OF_LISTENERS = 50;
@Mock
private BentoBox plugin;
@Mock