1
0
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:
Zrips 2024-04-15 12:39:18 +03:00 committed by GitHub
commit 0a02f2a396
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import com.gamingmesh.jobs.api.JobsBlockOwnershipRegisterEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -104,6 +105,12 @@ public class BlockOwnerShip {
return ownershipFeedback.invalid; 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()); UUID ownerUUID = this.getOwnerByLocation(block.getLocation());
if (ownerUUID != null && ownerUUID.equals(player.getUniqueId())) { if (ownerUUID != null && ownerUUID.equals(player.getUniqueId())) {