mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-25 20:16:13 +01:00
Merge pull request #1710 from rayanbzd/master
Implement JobsBlockOwnershipRegisterEvent
This commit is contained in:
commit
0a02f2a396
@ -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