Adds constructor to IslandResetCommand to allow no pasting

This is for games like SkyGrid that do not need pasting of a blueprint.
This commit is contained in:
tastybento 2019-08-30 10:16:05 -07:00
parent bbbe2565eb
commit 60d7dfef85
3 changed files with 54 additions and 11 deletions

View File

@ -17,6 +17,7 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.BlueprintsManager;
import world.bentobox.bentobox.managers.island.NewIsland;
import world.bentobox.bentobox.managers.island.NewIsland.Builder;
import world.bentobox.bentobox.panels.IslandCreationPanel;
/**
@ -24,10 +25,22 @@ import world.bentobox.bentobox.panels.IslandCreationPanel;
*/
public class IslandResetCommand extends ConfirmableCommand {
private boolean noPaste;
public IslandResetCommand(CompositeCommand islandCommand) {
super(islandCommand, "reset", "restart");
}
/**
* Creates the island reset command
* @param islandCommand - parent command
* @param noPaste - true if resetting should not paste a new island
*/
public IslandResetCommand(CompositeCommand islandCommand, boolean noPaste) {
super(islandCommand, "reset", "restart");
this.noPaste = noPaste;
}
@Override
public void setup() {
setPermission("island.create");
@ -115,13 +128,14 @@ public class IslandResetCommand extends ConfirmableCommand {
getPlayers().addReset(getWorld(), user.getUniqueId());
// Create new island and then delete the old one
try {
NewIsland.builder()
.player(user)
.reason(Reason.RESET)
.addon((GameModeAddon)getAddon())
.oldIsland(oldIsland)
.name(name)
.build();
Builder builder = NewIsland.builder()
.player(user)
.reason(Reason.RESET)
.addon((GameModeAddon)getAddon())
.oldIsland(oldIsland)
.name(name);
if (noPaste) builder.noPaste();
builder.build();
} catch (IOException e) {
getPlugin().logError("Could not create island for player. " + e.getMessage());
user.sendMessage("commands.island.create.unable-create-island");

View File

@ -1,8 +1,6 @@
package world.bentobox.bentobox.managers;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
import org.bukkit.entity.Player;

View File

@ -229,8 +229,6 @@ public class IslandResetCommandTest {
public void testUnlimitedResets() throws IOException {
// Now has island, but is not the owner
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
// Now is owner, but still has team
when(im.isOwner(any(), eq(uuid))).thenReturn(true);
// Now has no team
when(im.inTeam(any(), eq(uuid))).thenReturn(false);
// Set so no confirmation required
@ -257,6 +255,39 @@ public class IslandResetCommandTest {
assertTrue(irc.canExecute(user, irc.getLabel(), Collections.emptyList()));
}
/**
* Test method for {@link IslandResetCommand#canExecute(User, String, java.util.List)}
*/
@Test
public void testNoPaste() throws IOException {
irc = new IslandResetCommand(ic, true);
// Now has island, but is not the owner
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
// Set so no confirmation required
when(s.isResetConfirmation()).thenReturn(false);
// Old island mock
Island oldIsland = mock(Island.class);
when(im.getIsland(any(), eq(uuid))).thenReturn(oldIsland);
// Mock up NewIsland builder
NewIsland.Builder builder = mock(NewIsland.Builder.class);
when(builder.player(any())).thenReturn(builder);
when(builder.oldIsland(any())).thenReturn(builder);
when(builder.reason(any())).thenReturn(builder);
when(builder.name(any())).thenReturn(builder);
when(builder.addon(any())).thenReturn(builder);
when(builder.build()).thenReturn(mock(Island.class));
PowerMockito.mockStatic(NewIsland.class);
when(NewIsland.builder()).thenReturn(builder);
// Test with unlimited resets
when(pm.getResetsLeft(eq(world), eq(uuid))).thenReturn(-1);
// Reset
assertTrue(irc.canExecute(user, irc.getLabel(), Collections.emptyList()));
verify(builder, never()).noPaste();
}
/**
* Test method for {@link IslandResetCommand#execute(User, String, java.util.List)}
*/