Removes tabs
This commit is contained in:
parent
22f398fe53
commit
cd6780de60
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -39,33 +39,33 @@ public class NewIsland {
|
|||
private NewIslandLocationStrategy locationStrategy;
|
||||
|
||||
public NewIsland(Builder builder) throws IOException {
|
||||
plugin = BentoBox.getInstance();
|
||||
this.user = builder.user2;
|
||||
this.reason = builder.reason2;
|
||||
this.world = builder.world2;
|
||||
this.name = builder.name2;
|
||||
this.noPaste = builder.noPaste2;
|
||||
this.addon = builder.addon2;
|
||||
this.locationStrategy = builder.locationStrategy2;
|
||||
plugin = BentoBox.getInstance();
|
||||
this.user = builder.user2;
|
||||
this.reason = builder.reason2;
|
||||
this.world = builder.world2;
|
||||
this.name = builder.name2;
|
||||
this.noPaste = builder.noPaste2;
|
||||
this.addon = builder.addon2;
|
||||
this.locationStrategy = builder.locationStrategy2;
|
||||
|
||||
if (this.locationStrategy == null) {
|
||||
this.locationStrategy = new DefaultNewIslandLocationStrategy();
|
||||
}
|
||||
// Fire pre-create event
|
||||
IslandBaseEvent event = IslandEvent.builder().involvedPlayer(user.getUniqueId()).reason(Reason.PRECREATE)
|
||||
.build();
|
||||
if (event.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(event.isCancelled())) {
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
newIsland(builder.oldIsland2);
|
||||
if (this.locationStrategy == null) {
|
||||
this.locationStrategy = new DefaultNewIslandLocationStrategy();
|
||||
}
|
||||
// Fire pre-create event
|
||||
IslandBaseEvent event = IslandEvent.builder().involvedPlayer(user.getUniqueId()).reason(Reason.PRECREATE)
|
||||
.build();
|
||||
if (event.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(event.isCancelled())) {
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
newIsland(builder.oldIsland2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the island that was created
|
||||
*/
|
||||
public Island getIsland() {
|
||||
return island;
|
||||
return island;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,7 @@ public class NewIsland {
|
|||
* @return New island builder object
|
||||
*/
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,87 +83,87 @@ public class NewIsland {
|
|||
* @author tastybento
|
||||
*/
|
||||
public static class Builder {
|
||||
private Island oldIsland2;
|
||||
private User user2;
|
||||
private Reason reason2;
|
||||
private World world2;
|
||||
private String name2 = BlueprintsManager.DEFAULT_BUNDLE_NAME;
|
||||
private boolean noPaste2;
|
||||
private GameModeAddon addon2;
|
||||
private NewIslandLocationStrategy locationStrategy2;
|
||||
private Island oldIsland2;
|
||||
private User user2;
|
||||
private Reason reason2;
|
||||
private World world2;
|
||||
private String name2 = BlueprintsManager.DEFAULT_BUNDLE_NAME;
|
||||
private boolean noPaste2;
|
||||
private GameModeAddon addon2;
|
||||
private NewIslandLocationStrategy locationStrategy2;
|
||||
|
||||
public Builder oldIsland(Island oldIsland) {
|
||||
this.oldIsland2 = oldIsland;
|
||||
this.world2 = oldIsland.getWorld();
|
||||
return this;
|
||||
}
|
||||
public Builder oldIsland(Island oldIsland) {
|
||||
this.oldIsland2 = oldIsland;
|
||||
this.world2 = oldIsland.getWorld();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder player(User player) {
|
||||
this.user2 = player;
|
||||
return this;
|
||||
}
|
||||
public Builder player(User player) {
|
||||
this.user2 = player;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the reason
|
||||
*
|
||||
* @param reason reason, can only be {@link Reason#CREATE} or
|
||||
* {@link Reason#RESET}.
|
||||
*/
|
||||
public Builder reason(Reason reason) {
|
||||
if (!reason.equals(Reason.CREATE) && !reason.equals(Reason.RESET)) {
|
||||
throw new IllegalArgumentException("Reason must be CREATE or RESET.");
|
||||
}
|
||||
this.reason2 = reason;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Sets the reason
|
||||
*
|
||||
* @param reason reason, can only be {@link Reason#CREATE} or
|
||||
* {@link Reason#RESET}.
|
||||
*/
|
||||
public Builder reason(Reason reason) {
|
||||
if (!reason.equals(Reason.CREATE) && !reason.equals(Reason.RESET)) {
|
||||
throw new IllegalArgumentException("Reason must be CREATE or RESET.");
|
||||
}
|
||||
this.reason2 = reason;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the addon
|
||||
*
|
||||
* @param addon a game mode addon
|
||||
*/
|
||||
public Builder addon(GameModeAddon addon) {
|
||||
this.addon2 = addon;
|
||||
this.world2 = addon.getOverWorld();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the addon
|
||||
*
|
||||
* @param addon a game mode addon
|
||||
*/
|
||||
public Builder addon(GameModeAddon addon) {
|
||||
this.addon2 = addon;
|
||||
this.world2 = addon.getOverWorld();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* No blocks will be pasted
|
||||
*/
|
||||
public Builder noPaste() {
|
||||
this.noPaste2 = true;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* No blocks will be pasted
|
||||
*/
|
||||
public Builder noPaste() {
|
||||
this.noPaste2 = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name - name of Blueprint bundle
|
||||
*/
|
||||
public Builder name(String name) {
|
||||
this.name2 = name;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param name - name of Blueprint bundle
|
||||
*/
|
||||
public Builder name(String name) {
|
||||
this.name2 = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strategy - the location strategy to use
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public Builder locationStrategy(NewIslandLocationStrategy strategy) {
|
||||
this.locationStrategy2 = strategy;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param strategy - the location strategy to use
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public Builder locationStrategy(NewIslandLocationStrategy strategy) {
|
||||
this.locationStrategy2 = strategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Island
|
||||
* @throws IOException - if there are insufficient parameters, i.e., no user
|
||||
*/
|
||||
public Island build() throws IOException {
|
||||
if (user2 != null) {
|
||||
NewIsland newIsland = new NewIsland(this);
|
||||
return newIsland.getIsland();
|
||||
}
|
||||
throw new IOException("Insufficient parameters. Must have a user!");
|
||||
}
|
||||
/**
|
||||
* @return Island
|
||||
* @throws IOException - if there are insufficient parameters, i.e., no user
|
||||
*/
|
||||
public Island build() throws IOException {
|
||||
if (user2 != null) {
|
||||
NewIsland newIsland = new NewIsland(this);
|
||||
return newIsland.getIsland();
|
||||
}
|
||||
throw new IOException("Insufficient parameters. Must have a user!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,47 +174,47 @@ public class NewIsland {
|
|||
* the user.
|
||||
*/
|
||||
public void newIsland(Island oldIsland) throws IOException {
|
||||
// Find the new island location
|
||||
Location next = checkReservedIsland();
|
||||
if (next == null) {
|
||||
next = this.makeNextIsland();
|
||||
}
|
||||
// Clean up the user
|
||||
cleanUpUser(next);
|
||||
// Fire event
|
||||
IslandBaseEvent event = IslandEvent.builder().involvedPlayer(user.getUniqueId()).reason(reason).island(island)
|
||||
.location(island.getCenter())
|
||||
.blueprintBundle(plugin.getBlueprintsManager().getBlueprintBundles(addon).get(name))
|
||||
.oldIsland(oldIsland).build();
|
||||
if (event.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(event.isCancelled())) {
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
event = event.getNewEvent().orElse(event);
|
||||
// Get the new BlueprintBundle if it was changed
|
||||
switch (reason) {
|
||||
case CREATE -> name = ((IslandCreateEvent) event).getBlueprintBundle().getUniqueId();
|
||||
case RESET -> name = ((IslandResetEvent) event).getBlueprintBundle().getUniqueId();
|
||||
default -> {
|
||||
// Do nothing of other cases
|
||||
}
|
||||
}
|
||||
// Set the player's primary island
|
||||
plugin.getIslands().setPrimaryIsland(user.getUniqueId(), island);
|
||||
// Run task to run after creating the island in one tick if island is not being
|
||||
// pasted
|
||||
if (noPaste) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> postCreationTask(oldIsland));
|
||||
} else {
|
||||
// Create islands, then run task
|
||||
plugin.getBlueprintsManager().paste(addon, island, name, () -> postCreationTask(oldIsland));
|
||||
}
|
||||
// Set default settings
|
||||
island.setFlagsDefaults();
|
||||
// Register metrics
|
||||
plugin.getMetrics().ifPresent(BStats::increaseIslandsCreatedCount);
|
||||
// Save island
|
||||
plugin.getIslands().save(island);
|
||||
// Find the new island location
|
||||
Location next = checkReservedIsland();
|
||||
if (next == null) {
|
||||
next = this.makeNextIsland();
|
||||
}
|
||||
// Clean up the user
|
||||
cleanUpUser(next);
|
||||
// Fire event
|
||||
IslandBaseEvent event = IslandEvent.builder().involvedPlayer(user.getUniqueId()).reason(reason).island(island)
|
||||
.location(island.getCenter())
|
||||
.blueprintBundle(plugin.getBlueprintsManager().getBlueprintBundles(addon).get(name))
|
||||
.oldIsland(oldIsland).build();
|
||||
if (event.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(event.isCancelled())) {
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
event = event.getNewEvent().orElse(event);
|
||||
// Get the new BlueprintBundle if it was changed
|
||||
switch (reason) {
|
||||
case CREATE -> name = ((IslandCreateEvent) event).getBlueprintBundle().getUniqueId();
|
||||
case RESET -> name = ((IslandResetEvent) event).getBlueprintBundle().getUniqueId();
|
||||
default -> {
|
||||
// Do nothing of other cases
|
||||
}
|
||||
}
|
||||
// Set the player's primary island
|
||||
plugin.getIslands().setPrimaryIsland(user.getUniqueId(), island);
|
||||
// Run task to run after creating the island in one tick if island is not being
|
||||
// pasted
|
||||
if (noPaste) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> postCreationTask(oldIsland));
|
||||
} else {
|
||||
// Create islands, then run task
|
||||
plugin.getBlueprintsManager().paste(addon, island, name, () -> postCreationTask(oldIsland));
|
||||
}
|
||||
// Set default settings
|
||||
island.setFlagsDefaults();
|
||||
// Register metrics
|
||||
plugin.getMetrics().ifPresent(BStats::increaseIslandsCreatedCount);
|
||||
// Save island
|
||||
plugin.getIslands().save(island);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,28 +223,28 @@ public class NewIsland {
|
|||
* @param oldIsland - old island that will be deleted
|
||||
*/
|
||||
private void postCreationTask(Island oldIsland) {
|
||||
// Set initial spawn point if one exists
|
||||
if (island.getSpawnPoint(Environment.NORMAL) != null) {
|
||||
plugin.getIslands().setHomeLocation(user, island.getSpawnPoint(Environment.NORMAL));
|
||||
}
|
||||
// Stop the player from falling or moving if they are
|
||||
if (user.isOnline()) {
|
||||
if (reason.equals(Reason.RESET) || (reason.equals(Reason.CREATE)
|
||||
&& plugin.getIWM().isTeleportPlayerToIslandUponIslandCreation(world))) {
|
||||
user.getPlayer().setVelocity(new Vector(0, 0, 0));
|
||||
user.getPlayer().setFallDistance(0F);
|
||||
// Teleport player after this island is built
|
||||
plugin.getIslands().homeTeleportAsync(world, user.getPlayer(), true).thenRun(() -> tidyUp(oldIsland));
|
||||
return;
|
||||
} else {
|
||||
// let's send him a message so that he knows he can teleport to his island!
|
||||
user.sendMessage("commands.island.create.you-can-teleport-to-your-island");
|
||||
}
|
||||
} else {
|
||||
// Remove the player again to completely clear the data
|
||||
User.removePlayer(user.getPlayer());
|
||||
}
|
||||
tidyUp(oldIsland);
|
||||
// Set initial spawn point if one exists
|
||||
if (island.getSpawnPoint(Environment.NORMAL) != null) {
|
||||
plugin.getIslands().setHomeLocation(user, island.getSpawnPoint(Environment.NORMAL));
|
||||
}
|
||||
// Stop the player from falling or moving if they are
|
||||
if (user.isOnline()) {
|
||||
if (reason.equals(Reason.RESET) || (reason.equals(Reason.CREATE)
|
||||
&& plugin.getIWM().isTeleportPlayerToIslandUponIslandCreation(world))) {
|
||||
user.getPlayer().setVelocity(new Vector(0, 0, 0));
|
||||
user.getPlayer().setFallDistance(0F);
|
||||
// Teleport player after this island is built
|
||||
plugin.getIslands().homeTeleportAsync(world, user.getPlayer(), true).thenRun(() -> tidyUp(oldIsland));
|
||||
return;
|
||||
} else {
|
||||
// let's send him a message so that he knows he can teleport to his island!
|
||||
user.sendMessage("commands.island.create.you-can-teleport-to-your-island");
|
||||
}
|
||||
} else {
|
||||
// Remove the player again to completely clear the data
|
||||
User.removePlayer(user.getPlayer());
|
||||
}
|
||||
tidyUp(oldIsland);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,17 +254,17 @@ public class NewIsland {
|
|||
* @param loc - the new island location
|
||||
*/
|
||||
private void cleanUpUser(Location loc) {
|
||||
// Reset deaths
|
||||
if (plugin.getIWM().isDeathsResetOnNewIsland(world)) {
|
||||
plugin.getPlayers().setDeaths(world, user.getUniqueId(), 0);
|
||||
}
|
||||
// Check if owner has a different range permission than the island size
|
||||
island.setProtectionRange(user.getPermissionValue(
|
||||
plugin.getIWM().getAddon(island.getWorld()).map(GameModeAddon::getPermissionPrefix).orElse("")
|
||||
+ "island.range",
|
||||
island.getProtectionRange()));
|
||||
// Save the player so that if the server crashes weird things won't happen
|
||||
plugin.getPlayers().save(user.getUniqueId());
|
||||
// Reset deaths
|
||||
if (plugin.getIWM().isDeathsResetOnNewIsland(world)) {
|
||||
plugin.getPlayers().setDeaths(world, user.getUniqueId(), 0);
|
||||
}
|
||||
// Check if owner has a different range permission than the island size
|
||||
island.setProtectionRange(user.getPermissionValue(
|
||||
plugin.getIWM().getAddon(island.getWorld()).map(GameModeAddon::getPermissionPrefix).orElse("")
|
||||
+ "island.range",
|
||||
island.getProtectionRange()));
|
||||
// Save the player so that if the server crashes weird things won't happen
|
||||
plugin.getPlayers().save(user.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,20 +275,20 @@ public class NewIsland {
|
|||
* not be added to the grid
|
||||
*/
|
||||
private Location makeNextIsland() throws IOException {
|
||||
// If the reservation fails, then we need to make a new island anyway
|
||||
Location next = this.locationStrategy.getNextLocation(world);
|
||||
if (next == null) {
|
||||
plugin.logError("Failed to make island - no unoccupied spot found.");
|
||||
plugin.logError("If the world was imported, try multiple times until all unowned islands are known.");
|
||||
throw new IOException("commands.island.create.cannot-create-island");
|
||||
}
|
||||
// Add to the grid
|
||||
island = plugin.getIslands().createIsland(next, user.getUniqueId());
|
||||
if (island == null) {
|
||||
plugin.logError("Failed to make island! Island could not be added to the grid.");
|
||||
throw new IOException("commands.island.create.unable-create-island");
|
||||
}
|
||||
return next;
|
||||
// If the reservation fails, then we need to make a new island anyway
|
||||
Location next = this.locationStrategy.getNextLocation(world);
|
||||
if (next == null) {
|
||||
plugin.logError("Failed to make island - no unoccupied spot found.");
|
||||
plugin.logError("If the world was imported, try multiple times until all unowned islands are known.");
|
||||
throw new IOException("commands.island.create.cannot-create-island");
|
||||
}
|
||||
// Add to the grid
|
||||
island = plugin.getIslands().createIsland(next, user.getUniqueId());
|
||||
if (island == null) {
|
||||
plugin.logError("Failed to make island! Island could not be added to the grid.");
|
||||
throw new IOException("commands.island.create.unable-create-island");
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -297,30 +297,30 @@ public class NewIsland {
|
|||
* @return reserved island location, or null if none found
|
||||
*/
|
||||
private Location checkReservedIsland() {
|
||||
if (plugin.getIslands().hasIsland(world, user)) {
|
||||
// Island exists, it just needs pasting
|
||||
island = plugin.getIslands().getIsland(world, user);
|
||||
if (island != null && island.isReserved()) {
|
||||
Location l = island.getCenter();
|
||||
// Clear the reservation
|
||||
island.setReserved(false);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if (plugin.getIslands().hasIsland(world, user)) {
|
||||
// Island exists, it just needs pasting
|
||||
island = plugin.getIslands().getIsland(world, user);
|
||||
if (island != null && island.isReserved()) {
|
||||
Location l = island.getCenter();
|
||||
// Clear the reservation
|
||||
island.setReserved(false);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void tidyUp(Island oldIsland) {
|
||||
// Delete old island
|
||||
if (oldIsland != null) {
|
||||
// Delete the old island
|
||||
plugin.getIslands().deleteIsland(oldIsland, true, user.getUniqueId());
|
||||
}
|
||||
// Delete old island
|
||||
if (oldIsland != null) {
|
||||
// Delete the old island
|
||||
plugin.getIslands().deleteIsland(oldIsland, true, user.getUniqueId());
|
||||
}
|
||||
|
||||
// Fire exit event
|
||||
IslandEvent.builder().involvedPlayer(user.getUniqueId())
|
||||
.reason(reason == Reason.RESET ? Reason.RESETTED : Reason.CREATED).island(island)
|
||||
.location(island.getCenter()).oldIsland(oldIsland).build();
|
||||
// Fire exit event
|
||||
IslandEvent.builder().involvedPlayer(user.getUniqueId())
|
||||
.reason(reason == Reason.RESET ? Reason.RESETTED : Reason.CREATED).island(island)
|
||||
.location(island.getCenter()).oldIsland(oldIsland).build();
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -58,157 +58,157 @@ import world.bentobox.bentobox.util.Util;
|
|||
@PrepareForTest({ Util.class, IslandEvent.class, Bukkit.class })
|
||||
public class NewIslandTest {
|
||||
|
||||
private static final String NAME = "name";
|
||||
@Mock
|
||||
private BentoBox plugin;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private GameModeAddon addon;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private Island oldIsland;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private Island island;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
@Mock
|
||||
private IslandCreateEvent ice;
|
||||
@Mock
|
||||
private IslandResetEvent ire;
|
||||
@Mock
|
||||
private IslandDeletionManager idm;
|
||||
@Mock
|
||||
private Location location;
|
||||
@Mock
|
||||
private Block block;
|
||||
@Mock
|
||||
private BukkitScheduler scheduler;
|
||||
@Mock
|
||||
private IslandEventBuilder builder;
|
||||
@Mock
|
||||
private BlueprintBundle bpb;
|
||||
private static final String NAME = "name";
|
||||
@Mock
|
||||
private BentoBox plugin;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private GameModeAddon addon;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private Island oldIsland;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private Island island;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
@Mock
|
||||
private IslandCreateEvent ice;
|
||||
@Mock
|
||||
private IslandResetEvent ire;
|
||||
@Mock
|
||||
private IslandDeletionManager idm;
|
||||
@Mock
|
||||
private Location location;
|
||||
@Mock
|
||||
private Block block;
|
||||
@Mock
|
||||
private BukkitScheduler scheduler;
|
||||
@Mock
|
||||
private IslandEventBuilder builder;
|
||||
@Mock
|
||||
private BlueprintBundle bpb;
|
||||
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
@Mock
|
||||
private BlueprintsManager bpm;
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
@Mock
|
||||
private BlueprintsManager bpm;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
// Islands manager
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
when(im.createIsland(any(), any())).thenReturn(island);
|
||||
when(im.getLast(any())).thenReturn(location);
|
||||
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||
when(im.getPrimaryIsland(any(), any())).thenReturn(island);
|
||||
when(island.isReserved()).thenReturn(true);
|
||||
// Player's manager
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
Optional<GameModeAddon> optionalAddon = Optional.of(addon);
|
||||
when(iwm.getAddon(any())).thenReturn(optionalAddon);
|
||||
when(iwm.isDeathsResetOnNewIsland(any())).thenReturn(true);
|
||||
// Island deletion manager
|
||||
when(plugin.getIslandDeletionManager()).thenReturn(idm);
|
||||
when(idm.inDeletion(any())).thenReturn(false);
|
||||
// blueprints Manager
|
||||
when(bpb.getUniqueId()).thenReturn(NAME);
|
||||
when(bpm.getBlueprintBundles(any())).thenReturn(Collections.singletonMap(NAME, bpb));
|
||||
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
// Islands manager
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
when(im.createIsland(any(), any())).thenReturn(island);
|
||||
when(im.getLast(any())).thenReturn(location);
|
||||
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||
when(im.getPrimaryIsland(any(), any())).thenReturn(island);
|
||||
when(island.isReserved()).thenReturn(true);
|
||||
// Player's manager
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
Optional<GameModeAddon> optionalAddon = Optional.of(addon);
|
||||
when(iwm.getAddon(any())).thenReturn(optionalAddon);
|
||||
when(iwm.isDeathsResetOnNewIsland(any())).thenReturn(true);
|
||||
// Island deletion manager
|
||||
when(plugin.getIslandDeletionManager()).thenReturn(idm);
|
||||
when(idm.inDeletion(any())).thenReturn(false);
|
||||
// blueprints Manager
|
||||
when(bpb.getUniqueId()).thenReturn(NAME);
|
||||
when(bpm.getBlueprintBundles(any())).thenReturn(Collections.singletonMap(NAME, bpb));
|
||||
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
||||
|
||||
// User
|
||||
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(20);
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
// User
|
||||
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(20);
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
|
||||
// Events
|
||||
PowerMockito.mockStatic(IslandEvent.class);
|
||||
when(IslandEvent.builder()).thenReturn(builder);
|
||||
when(builder.admin(anyBoolean())).thenReturn(builder);
|
||||
when(builder.blueprintBundle(any())).thenReturn(builder);
|
||||
when(builder.deletedIslandInfo(any())).thenReturn(builder);
|
||||
when(builder.involvedPlayer(any())).thenReturn(builder);
|
||||
when(builder.island(any())).thenReturn(builder);
|
||||
when(builder.location(any())).thenReturn(builder);
|
||||
when(builder.reason(any())).thenReturn(builder);
|
||||
when(builder.oldIsland(any())).thenReturn(builder);
|
||||
when(builder.build()).thenReturn(ice);
|
||||
when(ice.getBlueprintBundle()).thenReturn(bpb);
|
||||
when(ire.getBlueprintBundle()).thenReturn(bpb);
|
||||
// Events
|
||||
PowerMockito.mockStatic(IslandEvent.class);
|
||||
when(IslandEvent.builder()).thenReturn(builder);
|
||||
when(builder.admin(anyBoolean())).thenReturn(builder);
|
||||
when(builder.blueprintBundle(any())).thenReturn(builder);
|
||||
when(builder.deletedIslandInfo(any())).thenReturn(builder);
|
||||
when(builder.involvedPlayer(any())).thenReturn(builder);
|
||||
when(builder.island(any())).thenReturn(builder);
|
||||
when(builder.location(any())).thenReturn(builder);
|
||||
when(builder.reason(any())).thenReturn(builder);
|
||||
when(builder.oldIsland(any())).thenReturn(builder);
|
||||
when(builder.build()).thenReturn(ice);
|
||||
when(ice.getBlueprintBundle()).thenReturn(bpb);
|
||||
when(ire.getBlueprintBundle()).thenReturn(bpb);
|
||||
|
||||
// Location and blocks
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
when(location.getWorld()).thenReturn(world);
|
||||
when(world.getMaxHeight()).thenReturn(5);
|
||||
when(location.getBlock()).thenReturn(block);
|
||||
when(block.getType()).thenReturn(Material.AIR);
|
||||
when(block.isEmpty()).thenReturn(true);
|
||||
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||
when(oldIsland.getWorld()).thenReturn(world);
|
||||
// Location and blocks
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
when(location.getWorld()).thenReturn(world);
|
||||
when(world.getMaxHeight()).thenReturn(5);
|
||||
when(location.getBlock()).thenReturn(block);
|
||||
when(block.getType()).thenReturn(Material.AIR);
|
||||
when(block.isEmpty()).thenReturn(true);
|
||||
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||
when(oldIsland.getWorld()).thenReturn(world);
|
||||
|
||||
// Util - return the same location
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getClosestIsland(any()))
|
||||
.thenAnswer((Answer<Location>) invocation -> invocation.getArgument(0, Location.class));
|
||||
// Util - return the same location
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getClosestIsland(any()))
|
||||
.thenAnswer((Answer<Location>) invocation -> invocation.getArgument(0, Location.class));
|
||||
|
||||
// Bukkit Scheduler
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
||||
// Bukkit Scheduler
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
||||
|
||||
// Addon
|
||||
when(addon.getOverWorld()).thenReturn(world);
|
||||
}
|
||||
// Addon
|
||||
when(addon.getOverWorld()).thenReturn(world);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
Mockito.framework().clearInlineMocks();
|
||||
}
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
Mockito.framework().clearInlineMocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilderNoUser() {
|
||||
try {
|
||||
NewIsland.builder().build();
|
||||
} catch (Exception e) {
|
||||
assertEquals("Insufficient parameters. Must have a user!", e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilderNoUser() {
|
||||
try {
|
||||
NewIsland.builder().build();
|
||||
} catch (Exception e) {
|
||||
assertEquals("Insufficient parameters. Must have a user!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilder() throws Exception {
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).oldIsland(oldIsland)
|
||||
.build();
|
||||
// Verifications
|
||||
verify(im).save(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
verify(bpb).getUniqueId();
|
||||
verify(ice).getBlueprintBundle();
|
||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||
verify(im, never()).setHomeLocation(eq(user), any());
|
||||
verify(island).setProtectionRange(eq(20));
|
||||
}
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilder() throws Exception {
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).oldIsland(oldIsland)
|
||||
.build();
|
||||
// Verifications
|
||||
verify(im).save(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
verify(bpb).getUniqueId();
|
||||
verify(ice).getBlueprintBundle();
|
||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||
verify(im, never()).setHomeLocation(eq(user), any());
|
||||
verify(island).setProtectionRange(eq(20));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
|
@ -227,43 +227,43 @@ public class NewIslandTest {
|
|||
verify(im, never()).setHomeLocation(eq(user), any());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilderNoOldIsland() throws Exception {
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).build();
|
||||
// Verifications
|
||||
verify(im).save(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
verify(bpb).getUniqueId();
|
||||
verify(ice).getBlueprintBundle();
|
||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||
verify(im, never()).setHomeLocation(eq(user), any());
|
||||
}
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilderNoOldIsland() throws Exception {
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).build();
|
||||
// Verifications
|
||||
verify(im).save(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
verify(bpb).getUniqueId();
|
||||
verify(ice).getBlueprintBundle();
|
||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||
verify(im, never()).setHomeLocation(eq(user), any());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilderNoOldIslandPaste() throws Exception {
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).reason(Reason.CREATE).build();
|
||||
// Verifications
|
||||
verify(im).save(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
verify(bpb).getUniqueId();
|
||||
verify(ice).getBlueprintBundle();
|
||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||
verify(im, never()).setHomeLocation(eq(user), any());
|
||||
}
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testBuilderNoOldIslandPaste() throws Exception {
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).reason(Reason.CREATE).build();
|
||||
// Verifications
|
||||
verify(im).save(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
verify(bpb).getUniqueId();
|
||||
verify(ice).getBlueprintBundle();
|
||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||
verify(im, never()).setHomeLocation(eq(user), any());
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
|
@ -283,7 +283,7 @@ public class NewIslandTest {
|
|||
verify(island).setReserved(eq(false));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
|
@ -304,7 +304,7 @@ public class NewIslandTest {
|
|||
//verify(plugin).logError("New island for user tastybento was not reserved!");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||
*/
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue