diff --git a/src/main/java/com/gamingmesh/jobs/api/JobsBlockOwnershipRegisterEvent.java b/src/main/java/com/gamingmesh/jobs/api/JobsBlockOwnershipRegisterEvent.java new file mode 100644 index 00000000..d020ef66 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/api/JobsBlockOwnershipRegisterEvent.java @@ -0,0 +1,45 @@ +package com.gamingmesh.jobs.api; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; + +public class JobsBlockOwnershipRegisterEvent extends BaseEvent implements Cancellable{ + + private boolean cancelled = false; + private final Player player; + private final Block block; + + public JobsBlockOwnershipRegisterEvent(Player player, Block block) { + this.player = player; + this.block = block; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + /** + * Returns the player who try to register a block ownership. + * + * @return {@link Player} + */ + public Player getPlayer() { + return player; + } + + /** + * Returns the block which the player tried to register. + * + * @return {@link Block} + */ + public Block getBlock() { + return block; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java index 2717f1d5..1e7c166d 100644 --- a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java +++ b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import com.gamingmesh.jobs.api.JobsBlockOwnershipRegisterEvent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -104,6 +105,12 @@ public class BlockOwnerShip { return ownershipFeedback.invalid; } + JobsBlockOwnershipRegisterEvent jobsBlockOwnershipRegisterEvent = new JobsBlockOwnershipRegisterEvent(player, block); + Bukkit.getServer().getPluginManager().callEvent(jobsBlockOwnershipRegisterEvent); + if(jobsBlockOwnershipRegisterEvent.isCancelled()) { + return ownershipFeedback.invalid; + } + UUID ownerUUID = this.getOwnerByLocation(block.getLocation()); if (ownerUUID != null && ownerUUID.equals(player.getUniqueId())) {