Skip to content
This repository was archived by the owner on Apr 20, 2019. It is now read-only.

Commit dd09019

Browse files
authored
Add ClaimInspectionEvent (#942)
1 parent a3d0aec commit dd09019

3 files changed

Lines changed: 64 additions & 16 deletions

File tree

src/main/java/me/ryanhamshire/GriefPrevention/Claim.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,24 @@ boolean hasSurfaceFluids()
250250
this(lesserBoundaryCorner, greaterBoundaryCorner, ownerID, builderIDs, containerIDs, accessorIDs, managerIDs, false, id);
251251
}
252252

253+
//produces a copy of a claim.
254+
public Claim(Claim claim) {
255+
this.modifiedDate = claim.modifiedDate;
256+
this.lesserBoundaryCorner = claim.greaterBoundaryCorner.clone();
257+
this.greaterBoundaryCorner = claim.greaterBoundaryCorner.clone();
258+
this.id = claim.id;
259+
this.ownerID = claim.ownerID;
260+
this.managers = new ArrayList<>(claim.managers);
261+
this.playerIDToClaimPermissionMap = new HashMap<>(claim.playerIDToClaimPermissionMap);
262+
this.inDataStore = false; //since it's a copy of a claim, not in datastore!
263+
this.areExplosivesAllowed = claim.areExplosivesAllowed;
264+
this.parent = claim.parent;
265+
this.inheritNothing = claim.inheritNothing;
266+
this.children = new ArrayList<>(claim.children);
267+
this.siegeData = claim.siegeData;
268+
this.doorsOpen = claim.doorsOpen;
269+
}
270+
253271
//measurements. all measurements are in blocks
254272
public int getArea()
255273
{

src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,6 @@ synchronized public void extendClaim(Claim claim, int newDepth)
10511051

10521052
//save changes
10531053
this.saveClaim(claim);
1054-
ClaimModifiedEvent event = new ClaimModifiedEvent(claim, null);
1055-
Bukkit.getPluginManager().callEvent(event);
10561054
}
10571055

10581056
//starts a siege on a claim
@@ -1314,8 +1312,6 @@ synchronized public CreateClaimResult resizeClaim(Claim claim, int newx1, int ne
13141312

13151313
//save those changes
13161314
this.saveClaim(result.claim);
1317-
ClaimModifiedEvent event = new ClaimModifiedEvent(result.claim, resizingPlayer);
1318-
Bukkit.getPluginManager().callEvent(event);
13191315
}
13201316

13211317
return result;
@@ -1362,18 +1358,24 @@ void resizeClaimWithChecks(Player player, PlayerData playerData, int newx1, int
13621358
}
13631359
}
13641360

1361+
Claim oldClaim = playerData.claimResizing;
1362+
Claim newClaim = new Claim(oldClaim);
1363+
World world = newClaim.getLesserBoundaryCorner().getWorld();
1364+
newClaim.lesserBoundaryCorner = new Location(world, newx1, newy1, newz1);
1365+
newClaim.greaterBoundaryCorner = new Location(world, newx2, newy2, newz2);
1366+
1367+
//call event here to check if it has been cancelled
1368+
ClaimModifiedEvent event = new ClaimModifiedEvent(oldClaim, newClaim, player);
1369+
Bukkit.getPluginManager().callEvent(event);
1370+
1371+
//return here if event is cancelled
1372+
if (event.isCancelled()) return;
1373+
13651374
//special rule for making a top-level claim smaller. to check this, verifying the old claim's corners are inside the new claim's boundaries.
13661375
//rule: in any mode, shrinking a claim removes any surface fluids
1367-
Claim oldClaim = playerData.claimResizing;
13681376
boolean smaller = false;
13691377
if (oldClaim.parent == null)
13701378
{
1371-
//temporary claim instance, just for checking contains()
1372-
Claim newClaim = new Claim(
1373-
new Location(oldClaim.getLesserBoundaryCorner().getWorld(), newx1, newy1, newz1),
1374-
new Location(oldClaim.getLesserBoundaryCorner().getWorld(), newx2, newy2, newz2),
1375-
null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), null);
1376-
13771379
//if the new claim is smaller
13781380
if (!newClaim.contains(oldClaim.getLesserBoundaryCorner(), true, false) || !newClaim.contains(oldClaim.getGreaterBoundaryCorner(), true, false))
13791381
{

src/main/java/me/ryanhamshire/GriefPrevention/events/ClaimModifiedEvent.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import me.ryanhamshire.GriefPrevention.Claim;
55
import org.bukkit.command.CommandSender;
6+
import org.bukkit.event.Cancellable;
67
import org.bukkit.event.Event;
78
import org.bukkit.event.HandlerList;
89

@@ -11,7 +12,7 @@
1112
* a claim has changed. The CommandSender can be null in the event that the modification is called by the plugin itself.
1213
* Created by Narimm on 5/08/2018.
1314
*/
14-
public class ClaimModifiedEvent extends Event
15+
public class ClaimModifiedEvent extends Event implements Cancellable
1516
{
1617

1718
private static final HandlerList handlers = new HandlerList();
@@ -21,12 +22,15 @@ public static HandlerList getHandlerList()
2122
return handlers;
2223
}
2324

24-
private final Claim claim;
25+
private final Claim from;
26+
private final Claim to;
2527
private CommandSender modifier;
28+
private boolean cancelled;
2629

27-
public ClaimModifiedEvent(Claim claim, CommandSender modifier)
30+
public ClaimModifiedEvent(Claim from, Claim to, CommandSender modifier)
2831
{
29-
this.claim = claim;
32+
this.from = from;
33+
this.to = to;
3034
this.modifier = modifier;
3135
}
3236

@@ -40,10 +44,22 @@ public HandlerList getHandlers()
4044
* The claim
4145
*
4246
* @return the claim
47+
* @deprecated Use the {@link #getTo() getTo} method.
4348
*/
49+
@Deprecated
4450
public Claim getClaim()
4551
{
46-
return claim;
52+
return to;
53+
}
54+
55+
public Claim getFrom()
56+
{
57+
return from;
58+
}
59+
60+
public Claim getTo()
61+
{
62+
return to;
4763
}
4864

4965
/**
@@ -55,4 +71,16 @@ public CommandSender getModifier()
5571
{
5672
return modifier;
5773
}
74+
75+
@Override
76+
public boolean isCancelled()
77+
{
78+
return cancelled;
79+
}
80+
81+
@Override
82+
public void setCancelled(boolean cancelled)
83+
{
84+
this.cancelled = cancelled;
85+
}
5886
}

0 commit comments

Comments
 (0)