Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClaimTransferEvent #1641

Merged
merged 2 commits into from Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -410,16 +411,23 @@ synchronized public void changeClaimOwner(Claim claim, UUID newOwnerID)
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
Expand Down
@@ -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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either YYYYMMDD or MMDDYYYY

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in general, no datestamp is really needed, and I can't be bothered to care when imma branch this off at some point anyway.

*/

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