mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 05:55:27 +01:00
Implement JobsBlockOwnershipRegisterEvent
This commit is contained in:
parent
d9cb1bf337
commit
d79e0b89a5
@ -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;
|
||||
}
|
||||
}
|
@ -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())) {
|
||||
|
Loading…
Reference in New Issue
Block a user