Adds involved player UUID to IslandDeleteEvent

https://github.com/BentoBoxWorld/BentoBox/issues/790
This commit is contained in:
tastybento 2019-06-26 19:03:56 -07:00
parent 7c16908768
commit 3f217e30ad
6 changed files with 16 additions and 12 deletions

View File

@ -27,10 +27,10 @@ public class AdminDeleteCommand extends ConfirmableCommand {
@Override
public boolean canExecute(User user, String label, List<String> args) {
if (args.size() != 1) {
showHelp(this, user);
return false;
}
if (args.size() != 1) {
showHelp(this, user);
return false;
}
// Get target
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
@ -86,7 +86,7 @@ public class AdminDeleteCommand extends ConfirmableCommand {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
}
}
getIslands().deleteIsland(oldIsland, true);
getIslands().deleteIsland(oldIsland, true, targetUUID);
}
getPlayers().clearHomeLocations(getWorld(), targetUUID);
user.sendMessage("general.success");

View File

@ -89,7 +89,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
getIslands().homeTeleport(getWorld(), user.getPlayer());
// Delete the old island
if (island != null) {
getIslands().deleteIsland(island, true);
getIslands().deleteIsland(island, true, user.getUniqueId());
}
// TODO Set the cooldown
// Reset deaths

View File

@ -222,7 +222,10 @@ public class IslandEvent extends IslandBaseEvent {
}
}
/**
* Fired when an island is deleted.
* Fired when island blocks are going to be deleted.
* If canceled, the island blocks will not be deleted. Note that by the time this is called
* the ownership of the island may have been removed. This event is just for detecting
* that the island blocks are going to be removed.
*
*/
public static class IslandDeletedEvent extends IslandBaseEvent {

View File

@ -276,10 +276,11 @@ public class IslandsManager {
* Deletes island.
* @param island island to delete, not null
* @param removeBlocks whether the island blocks should be removed or not
* @param involvedPlayer - player related to the island deletion, if any
*/
public void deleteIsland(@NonNull Island island, boolean removeBlocks) {
public void deleteIsland(@NonNull Island island, boolean removeBlocks, UUID involvedPlayer) {
// Fire event
IslandBaseEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
IslandBaseEvent event = IslandEvent.builder().island(island).involvedPlayer(involvedPlayer).reason(Reason.DELETE).build();
if (event.isCancelled()) {
return;
}

View File

@ -207,7 +207,7 @@ public class NewIsland {
// Delete old island
if (oldIsland != null) {
// Delete the old island
plugin.getIslands().deleteIsland(oldIsland, true);
plugin.getIslands().deleteIsland(oldIsland, true, user.getUniqueId());
}
// Fire exit event

View File

@ -431,7 +431,7 @@ public class IslandsManagerTest {
IslandsManager im = new IslandsManager(plugin);
UUID owner = UUID.randomUUID();
Island island = im.createIsland(location, owner);
im.deleteIsland(island, false);
im.deleteIsland(island, false, owner);
assertNull(island.getOwner());
Mockito.verify(pim, Mockito.times(2)).callEvent(Mockito.any(IslandDeleteEvent.class));
}
@ -445,7 +445,7 @@ public class IslandsManagerTest {
IslandsManager im = new IslandsManager(plugin);
UUID owner = UUID.randomUUID();
Island island = im.createIsland(location, owner);
im.deleteIsland(island, true);
im.deleteIsland(island, true, owner);
assertNull(island.getOwner());
Mockito.verify(pim, Mockito.times(4)).callEvent(Mockito.any(IslandDeleteEvent.class));
}