API: add ClaimTransferEvent (#1641)
This commit is contained in:
parent
4bb31bc49d
commit
ca11fd1695
|
|
@ -23,6 +23,7 @@ import me.ryanhamshire.GriefPrevention.events.ClaimCreatedEvent;
|
|||
import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent;
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimExtendEvent;
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent;
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimTransferEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
|
|
@ -410,16 +411,23 @@ public abstract class DataStore
|
|||
ownerData = this.getPlayerData(claim.ownerID);
|
||||
}
|
||||
|
||||
//call event
|
||||
ClaimTransferEvent event = new ClaimTransferEvent(claim, newOwnerID);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
//return if event is cancelled
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
//determine new owner
|
||||
PlayerData newOwnerData = null;
|
||||
|
||||
if (newOwnerID != null)
|
||||
if (event.getNewOwner() != null)
|
||||
{
|
||||
newOwnerData = this.getPlayerData(newOwnerID);
|
||||
newOwnerData = this.getPlayerData(event.getNewOwner());
|
||||
}
|
||||
|
||||
//transfer
|
||||
claim.ownerID = newOwnerID;
|
||||
claim.ownerID = event.getNewOwner();
|
||||
this.saveClaim(claim);
|
||||
|
||||
//adjust blocks and other records
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This Event is thrown when a claim is being transferred. If it is cancelled the claim will not be transferred.
|
||||
* <p>
|
||||
* Created by bertek41 on 30/10/2021.
|
||||
*/
|
||||
|
||||
public class ClaimTransferEvent extends Event implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
private UUID newOwner;
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public ClaimTransferEvent(Claim claim, UUID newOwner) {
|
||||
this.claim = claim;
|
||||
this.newOwner = newOwner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Claim
|
||||
*
|
||||
* @return {@link Claim}
|
||||
*/
|
||||
public Claim getClaim()
|
||||
{
|
||||
return claim;
|
||||
}
|
||||
|
||||
/**
|
||||
* New owner of the claim
|
||||
*
|
||||
* @return the {@link java.util.UUID} of new owner or null
|
||||
*/
|
||||
public UUID getNewOwner()
|
||||
{
|
||||
return newOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new owner of the claim
|
||||
*
|
||||
* @param {@link java.util.UUID} newOwner can be null
|
||||
*/
|
||||
public void setNewOwner(UUID newOwner)
|
||||
{
|
||||
this.newOwner = newOwner;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user