mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 11:15:24 +01:00
Adds PreCreateEvent for API
This commit is contained in:
parent
b024d0cc8b
commit
f09ea1ffef
@ -50,6 +50,12 @@ public class IslandEvent extends IslandBaseEvent {
|
|||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
BAN,
|
BAN,
|
||||||
|
/**
|
||||||
|
* Fired when a player tries to create a new island. If canceled will
|
||||||
|
* proceed no further.
|
||||||
|
* @since 1.15.1
|
||||||
|
*/
|
||||||
|
PRECREATE,
|
||||||
/**
|
/**
|
||||||
* Called when a player has been allocated a new island spot
|
* Called when a player has been allocated a new island spot
|
||||||
* but before the island itself has been pasted or the player teleported.
|
* but before the island itself has been pasted or the player teleported.
|
||||||
@ -220,6 +226,18 @@ public class IslandEvent extends IslandBaseEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when attempting to make a new island.
|
||||||
|
* May be cancelled. No island object exists at this point.
|
||||||
|
* @since 1.15.1
|
||||||
|
*/
|
||||||
|
public static class IslandPreCreateEvent extends IslandBaseEvent {
|
||||||
|
private IslandPreCreateEvent(UUID player) {
|
||||||
|
// Final variables have to be declared in the constructor
|
||||||
|
super(null, player, false, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when an island is going to be created.
|
* Fired when an island is going to be created.
|
||||||
* May be cancelled.
|
* May be cancelled.
|
||||||
@ -681,6 +699,10 @@ public class IslandEvent extends IslandBaseEvent {
|
|||||||
IslandBanEvent ban = new IslandBanEvent(island, player, admin, location);
|
IslandBanEvent ban = new IslandBanEvent(island, player, admin, location);
|
||||||
Bukkit.getPluginManager().callEvent(ban);
|
Bukkit.getPluginManager().callEvent(ban);
|
||||||
return ban;
|
return ban;
|
||||||
|
case PRECREATE:
|
||||||
|
IslandPreCreateEvent precreate = new IslandPreCreateEvent(player);
|
||||||
|
Bukkit.getPluginManager().callEvent(precreate);
|
||||||
|
return precreate;
|
||||||
case CREATE:
|
case CREATE:
|
||||||
IslandCreateEvent create = new IslandCreateEvent(island, player, admin, location, blueprintBundle);
|
IslandCreateEvent create = new IslandCreateEvent(island, player, admin, location, blueprintBundle);
|
||||||
Bukkit.getPluginManager().callEvent(create);
|
Bukkit.getPluginManager().callEvent(create);
|
||||||
|
@ -48,7 +48,15 @@ public class NewIsland {
|
|||||||
if (this.locationStrategy == null) {
|
if (this.locationStrategy == null) {
|
||||||
this.locationStrategy = new DefaultNewIslandLocationStrategy();
|
this.locationStrategy = new DefaultNewIslandLocationStrategy();
|
||||||
}
|
}
|
||||||
|
// Fire pre-create event
|
||||||
|
IslandBaseEvent event = IslandEvent.builder()
|
||||||
|
.involvedPlayer(user.getUniqueId())
|
||||||
|
.reason(Reason.PRECREATE)
|
||||||
|
.build();
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
newIsland(builder.oldIsland2);
|
newIsland(builder.oldIsland2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
|
|||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -197,7 +198,7 @@ public class NewIslandTest {
|
|||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||||
verify(builder).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
@ -205,7 +206,7 @@ public class NewIslandTest {
|
|||||||
verify(pm).clearHomeLocations(eq(world), any(UUID.class));
|
verify(pm).clearHomeLocations(eq(world), any(UUID.class));
|
||||||
verify(island).setProtectionRange(eq(20));
|
verify(island).setProtectionRange(eq(20));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
* Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@ -218,7 +219,7 @@ public class NewIslandTest {
|
|||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||||
verify(builder).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice, never()).getBlueprintBundle();
|
verify(ice, never()).getBlueprintBundle();
|
||||||
verify(ire).getBlueprintBundle();
|
verify(ire).getBlueprintBundle();
|
||||||
@ -238,7 +239,7 @@ public class NewIslandTest {
|
|||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||||
verify(builder).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
@ -257,7 +258,7 @@ public class NewIslandTest {
|
|||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class));
|
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class));
|
||||||
verify(builder).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
@ -277,7 +278,7 @@ public class NewIslandTest {
|
|||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||||
verify(builder).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
@ -300,7 +301,7 @@ public class NewIslandTest {
|
|||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||||
verify(builder).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
@ -323,7 +324,7 @@ public class NewIslandTest {
|
|||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||||
verify(builder).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
|
Loading…
Reference in New Issue
Block a user