mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Merge pull request #2102 from dordsor21/master
Add PlotChangeOwner Event
This commit is contained in:
@ -4,11 +4,7 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.Set;
|
||||
@ -34,7 +30,8 @@ public class Owner extends SetCommand {
|
||||
try {
|
||||
uuid = UUID.fromString(value);
|
||||
name = MainUtil.getName(uuid);
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(value, null);
|
||||
name = UUIDHandler.getName(uuid);
|
||||
@ -80,13 +77,15 @@ public class Owner extends SetCommand {
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (removeDenied) plot.removeDenied(finalUUID);
|
||||
plot.setOwner(finalUUID);
|
||||
plot.setSign(finalName);
|
||||
MainUtil.sendMessage(player, C.SET_OWNER);
|
||||
if (other != null) {
|
||||
MainUtil.sendMessage(other, C.NOW_OWNER, plot.getArea() + ";" + plot.getId());
|
||||
}
|
||||
if (plot.setOwner(finalUUID, player)) {
|
||||
if (removeDenied) plot.removeDenied(finalUUID);
|
||||
plot.setSign(finalName);
|
||||
MainUtil.sendMessage(player, C.SET_OWNER);
|
||||
if (other != null) {
|
||||
MainUtil.sendMessage(other, C.NOW_OWNER, plot.getArea() + ";" + plot.getId());
|
||||
}
|
||||
} else
|
||||
MainUtil.sendMessage(player, C.SET_OWNER_CANCELLED);
|
||||
}
|
||||
};
|
||||
if (hasConfirmation(player)) {
|
||||
|
@ -692,6 +692,7 @@ public enum C {
|
||||
* Set Owner
|
||||
*/
|
||||
SET_OWNER("$4You successfully set the plot owner", "Owner"),
|
||||
SET_OWNER_CANCELLED("$2The setowner action was cancelled", "Owner"),
|
||||
NOW_OWNER("$4You are now owner of plot %s", "Owner"),
|
||||
/*
|
||||
* Signs
|
||||
|
@ -746,6 +746,37 @@ public class Plot {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plot owner (and update the database)
|
||||
* @param owner
|
||||
* @param initiator
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean setOwner(UUID owner, PlotPlayer initiator) {
|
||||
boolean result = EventUtil.manager.callOwnerChange(initiator, this, owner, hasOwner() ? this.owner : null, hasOwner());
|
||||
if(!result)
|
||||
return false;
|
||||
if (!hasOwner()) {
|
||||
this.owner = owner;
|
||||
create();
|
||||
return true;
|
||||
}
|
||||
if (!isMerged()) {
|
||||
if (!this.owner.equals(owner)) {
|
||||
this.owner = owner;
|
||||
DBFunc.setOwner(this, owner);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
for (Plot current : getConnectedPlots()) {
|
||||
if (!owner.equals(current.owner)) {
|
||||
current.owner = owner;
|
||||
DBFunc.setOwner(current, owner);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a plot.
|
||||
* @see this#clear(boolean, boolean, Runnable)
|
||||
|
@ -67,6 +67,8 @@ public abstract class EventUtil {
|
||||
|
||||
public abstract void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added);
|
||||
|
||||
public abstract boolean callOwnerChange(PlotPlayer initiator, Plot plot, UUID newOwner, UUID oldOwner, boolean hasOldOwner);
|
||||
|
||||
public void doJoinTask(final PlotPlayer player) {
|
||||
if (player == null) {
|
||||
return; //possible future warning message to figure out where we are retrieving null
|
||||
|
@ -63,4 +63,6 @@ public class EventUtilTest extends EventUtil {
|
||||
@Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {}
|
||||
|
||||
@Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {}
|
||||
|
||||
@Override public boolean callOwnerChange(PlotPlayer initiator, Plot plot, UUID newOwner, UUID oldOwner, boolean hasOldOwner) {return false;}
|
||||
}
|
||||
|
Reference in New Issue
Block a user