Package simplexity.scythe.events
Class HarvestEvent
java.lang.Object
org.bukkit.event.Event
simplexity.scythe.events.HarvestEvent
- All Implemented Interfaces:
org.bukkit.event.Cancellable
public class HarvestEvent
extends org.bukkit.event.Event
implements org.bukkit.event.Cancellable
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bukkit.event.Event
org.bukkit.event.Event.Result
-
Constructor Summary
ConstructorDescriptionHarvestEvent
(org.bukkit.entity.Player player, org.bukkit.block.Block block, boolean isRightClick, org.bukkit.inventory.ItemStack usedItem) -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.block.Block
getBlock()
List<org.bukkit.Material>
Returns a list of Material objects that represent the configured crops.org.bukkit.Particle
Returns a Particle object that represents the configured particle.int
Returns an integer that represents the configured particle count.int
Returns an integer that represents the configured sound pitch.org.bukkit.Sound
Returns a Sound object that represents the configured sound.List<org.bukkit.inventory.ItemStack>
Returns a list of ItemStack objects that represent the configured tools.int
Returns an integer that represents the configured sound volume.org.bukkit.block.data.BlockData
Returns the block data of the crop.org.bukkit.Location
Returns the location of the block where the crop is planted.org.bukkit.Material
Returns the material of the crop.static org.bukkit.event.HandlerList
@NotNull org.bukkit.event.HandlerList
org.bukkit.entity.Player
boolean
Returns a boolean value that specifies whether tool right-click harvesting is required or not.org.bukkit.inventory.ItemStack
void
Harvests the crop at the specified location and performs additional actions such as breaking the block, logging the removal using CoreProtect API (if enabled),
playing sound, and showing particles based on the configuration settings.boolean
Returns a boolean value that indicates whether the block is ageable or not.boolean
Returns a boolean value that indicates whether the event is cancelled or not.boolean
Returns a boolean value that indicates whether CoreProtect API is enabled or not.boolean
Returns a boolean value indicating whether the crop is allowed or not.boolean
Returns a boolean value that indicates whether the crop is fully grown or not.boolean
boolean
Returns a boolean value that indicates whether right-click harvest is enabled or not.boolean
Returns a boolean value that indicates whether the player's PDC (Persistent Data Container) toggle is enabled or not.void
Performs pre-harvest checks to determine if the harvest action is allowed.void
setCancelled
(boolean cancel) Sets the cancelled flag to the specified value.boolean
Returns a boolean value that indicates whether sounds should be played or not.boolean
Returns a boolean value that indicates whether break particles should be shown or not.boolean
Returns a boolean value that specifies whether the configured tool was used or not.Methods inherited from class org.bukkit.event.Event
callEvent, getEventName, isAsynchronous
-
Constructor Details
-
HarvestEvent
public HarvestEvent(org.bukkit.entity.Player player, org.bukkit.block.Block block, boolean isRightClick, org.bukkit.inventory.ItemStack usedItem)
-
-
Method Details
-
preHarvestChecks
public void preHarvestChecks()Performs pre-harvest checks to determine if the harvest action is allowed.
Checks for crop allowance, right-click harvesting permission, the use of configured tool for right-click harvesting, ageable block type, player permission, PDC (Persistent Data Container) toggle, and crop growth level (if right-click harvesting).
If any of the checks fail, the action is cancelled by calling the setCancelled() method and returning.
If all checks pass, the method completes without any issues. -
harvestCrop
public void harvestCrop()Harvests the crop at the specified location and performs additional actions such as breaking the block, logging the removal using CoreProtect API (if enabled),
playing sound, and showing particles based on the configuration settings.
The method performs pre-harvest checks by calling the preHarvestChecks() method, and returns immediately if the action has been cancelled.
If the crop is not fully grown, the method sets the action as cancelled and returns.
If the crop is full-grown, the block is broken using the usedItem parameter specified.
If CoreProtect API is enabled, the removal of the crop is logged using the CoreProtectAPIs logRemoval() method.
If sound is enabled, it will be played using the getConfiguredSound() method and the getConfiguredVolume() and getConfiguredPitch() settings to determine the volume and pitch.
If particles are enabled, the particle effect will be shown using the getConfiguredParticle(), getConfiguredParticleCount(), and getCropBlockData() settings to determine the type, count, and data of the particle. -
isCoreProtectEnabled
public boolean isCoreProtectEnabled()Returns a boolean value that indicates whether CoreProtect API is enabled or not.
The method checks if the coreProtectAPI object is null or not.
If the object is not null, it means that the CoreProtect API is enabled and the method returns true.
If the object is null, it means that the CoreProtect API is disabled and the method returns false.- Returns:
- boolean
-
isAgeableBlock
public boolean isAgeableBlock()Returns a boolean value that indicates whether the block is ageable or not.
The method attempts to cast the block's block data to an Ageable object using the getBlockData() method on the "block" object.
If the cast is successful, the method stores the Ageable object in the "ageable" variable and returns true.
If the cast fails, the method prints a stack trace and returns false.- Returns:
- boolean
-
isCropFullGrown
public boolean isCropFullGrown()Returns a boolean value that indicates whether the crop is fully grown or not.
The method obtains the maximum age of the crop and its current age using the getMaximumAge() and getAge() methods on the "ageable" object.
It then checks if the current age is equal to the maximum age and returns the result.- Returns:
- boolean
-
shouldPlaySound
public boolean shouldPlaySound()Returns a boolean value that indicates whether sounds should be played or not.
The method internally gets the instance of the ConfigHandler class and calls its shouldPlaySounds() method to retrieve the value.- Returns:
- boolean
-
shouldShowParticles
public boolean shouldShowParticles()Returns a boolean value that indicates whether break particles should be shown or not.
The method internally gets the instance of the ConfigHandler class and calls its showBreakParticles() method to retrieve the value.- Returns:
- boolean
-
getCropBlockData
public org.bukkit.block.data.BlockData getCropBlockData()Returns the block data of the crop.
The method returns the block data of the block where the crop is planted.- Returns:
- BlockData
-
getCropLocation
public org.bukkit.Location getCropLocation()Returns the location of the block where the crop is planted.- Returns:
- Location
-
getCropMaterial
public org.bukkit.Material getCropMaterial()Returns the material of the crop.
The method returns the type of the block where the crop is planted.- Returns:
- Material
-
isCropAllowed
public boolean isCropAllowed()Returns a boolean value indicating whether the crop is allowed or not.
The method internally checks whether the crop material is present in the configured crop list or not.- Returns:
- boolean
-
isRightClickHarvestEnabled
public boolean isRightClickHarvestEnabled()Returns a boolean value that indicates whether right-click harvest is enabled or not.
The method internally gets the ConfigHandler instance and calls its allowRightClickHarvest() method to retrieve the value.- Returns:
- boolean
-
wasConfiguredToolUsed
public boolean wasConfiguredToolUsed()Returns a boolean value that specifies whether the configured tool was used or not.
The method internally checks whether the used item is present in the configured tool list or not.- Returns:
- boolean
-
getRequireToolRightClickHarvest
public boolean getRequireToolRightClickHarvest()Returns a boolean value that specifies whether tool right-click harvesting is required or not.
The method internally gets the instance of the ConfigHandler class and calls its shouldRequireToolRightClickHarvest() method to retrieve the value.- Returns:
- boolean
-
getConfiguredToolList
Returns a list of ItemStack objects that represent the configured tools.
The method internally gets the instance of the ConfigHandler class and calls its getConfiguredTools() method to retrieve the list.- Returns:
- List
-
getConfiguredCropList
Returns a list of Material objects that represent the configured crops.
The method internally gets the instance of the ConfigHandler class and calls its getConfiguredCrops() method to retrieve the list.- Returns:
- List
-
getConfiguredSound
public org.bukkit.Sound getConfiguredSound()Returns a Sound object that represents the configured sound.
The method internally gets the instance of the ConfigHandler class and calls its getConfigSound() method to retrieve the sound.- Returns:
- Sound
-
getConfiguredVolume
public int getConfiguredVolume()Returns an integer that represents the configured sound volume.
The method internally gets the instance of the ConfigHandler class and calls its getSoundVolume() method to retrieve the configured sound volume.- Returns:
- int
-
getConfiguredPitch
public int getConfiguredPitch()Returns an integer that represents the configured sound pitch.
The method internally gets the instance of the ConfigHandler class and calls its getSoundPitch() method to retrieve the configured sound pitch.- Returns:
- int
-
getConfiguredParticle
public org.bukkit.Particle getConfiguredParticle()Returns a Particle object that represents the configured particle.
The method internally gets the instance of the ConfigHandler class and calls its getConfigParticle() method to retrieve the particle.- Returns:
- Particle
-
getConfiguredParticleCount
public int getConfiguredParticleCount()Returns an integer that represents the configured particle count.
The method internally gets the instance of the ConfigHandler class and calls its getParticleCount() method to retrieve the configured particle count.- Returns:
- int
-
playerPDCToggleEnabled
public boolean playerPDCToggleEnabled()Returns a boolean value that indicates whether the player's PDC (Persistent Data Container) toggle is enabled or not.
The method obtains the player's PDC using the getPersistentDataContainer() method on the "player" object.
It then uses the PersistentDataContainer's getOrDefault() method to retrieve the value of the "functionToggle" key and checks if it is equal to 0.- Returns:
- boolean
-
isCancelled
public boolean isCancelled()Returns a boolean value that indicates whether the event is cancelled or not.
The method returns the value of the "cancelled" flag, which is set by the setCancelled() method.- Specified by:
isCancelled
in interfaceorg.bukkit.event.Cancellable
- Returns:
- boolean
-
setCancelled
public void setCancelled(boolean cancel) Sets the cancelled flag to the specified value.
The method sets the value of the "cancelled" flag to the specified boolean value.- Specified by:
setCancelled
in interfaceorg.bukkit.event.Cancellable
- Parameters:
cancel
- boolean
-
getHandlerList
public static org.bukkit.event.HandlerList getHandlerList()- Returns:
- HandlerList
-
getHandlers
@NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()- Specified by:
getHandlers
in classorg.bukkit.event.Event
- Returns:
- HandlerList
-
getPlayer
public org.bukkit.entity.Player getPlayer()- Returns:
- Player
-
getBlock
public org.bukkit.block.Block getBlock()- Returns:
- Block
-
isRightClick
public boolean isRightClick()- Returns:
- boolean
-
getUsedItem
public org.bukkit.inventory.ItemStack getUsedItem()- Returns:
- ItemStack
-