mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-09 09:57:40 +01:00
Merge pull request #2332 from BentoBoxWorld/admin_range_multi_island
Adds support for multi islands to the admin range command
This commit is contained in:
commit
b734d579a1
@ -0,0 +1,103 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.range;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public abstract class AbstractAdminRangeCommand extends CompositeCommand {
|
||||
|
||||
protected @Nullable UUID targetUUID;
|
||||
protected Island targetIsland;
|
||||
|
||||
public AbstractAdminRangeCommand(CompositeCommand parent, String string) {
|
||||
super(parent, string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
targetUUID = Util.getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Util.isInteger(args.get(1), true) || Integer.parseInt(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
// Check if the player has more than one island
|
||||
Map<String, Island> islands = getIslandsXYZ(targetUUID);
|
||||
if (islands.size() == 0) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
} else if (args.size() == 2) {
|
||||
// If they only have one island, 2 args are fine
|
||||
if (islands.size() == 1) {
|
||||
targetIsland = islands.values().iterator().next();
|
||||
return true;
|
||||
} else {
|
||||
// They need to specify which island
|
||||
user.sendMessage("commands.admin.unregister.errors.player-has-more-than-one-island");
|
||||
user.sendMessage("commands.admin.unregister.errors.specify-island-location");
|
||||
return false;
|
||||
}
|
||||
} else if (args.size() != 3) {
|
||||
// No location
|
||||
user.sendMessage("commands.admin.unregister.errors.specify-island-location");
|
||||
return false;
|
||||
} else if (!islands.containsKey(args.get(2))) {
|
||||
if (args.get(2).equalsIgnoreCase("help")) {
|
||||
this.showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
user.sendMessage("commands.admin.unregister.errors.unknown-island-location");
|
||||
return false;
|
||||
}
|
||||
targetIsland = islands.get(args.get(2));
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Map<String, Island> getIslandsXYZ(UUID target) {
|
||||
return getIslands().getOwnedIslands(getWorld(), target).stream()
|
||||
.collect(Collectors.toMap(island -> Util.xyz(island.getCenter().toVector()), island -> island));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size() - 1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
} else if (args.size() == 3) {
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
} else if (args.size() > 4) {
|
||||
// Find out which user
|
||||
UUID uuid = getPlayers().getUUID(args.get(2));
|
||||
if (uuid != null) {
|
||||
return Optional.of(Util.tabLimit(new ArrayList<>(getIslandsXYZ(uuid).keySet()), lastArg));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@ -1,23 +1,18 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* @since 1.10.0
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminRangeAddCommand extends CompositeCommand {
|
||||
public class AdminRangeAddCommand extends AbstractAdminRangeCommand {
|
||||
|
||||
public AdminRangeAddCommand(AdminRangeCommand parent) {
|
||||
super(parent, "add");
|
||||
@ -32,53 +27,28 @@ public class AdminRangeAddCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
int newRange = targetIsland.getProtectionRange() + Integer.parseInt(args.get(1));
|
||||
|
||||
UUID targetUUID = Util.getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
if (newRange > targetIsland.getRange()) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER,
|
||||
String.valueOf(targetIsland.getRange()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(getIslands().hasIsland(getWorld(), targetUUID) || getIslands().inTeam(getWorld(), targetUUID))) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Util.isInteger(args.get(1), true) || Integer.parseInt(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||
int newRange = island.getProtectionRange() + Integer.parseInt(args.get(1));
|
||||
|
||||
if (newRange > island.getRange()) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER, String.valueOf(island.getRange()));
|
||||
return false;
|
||||
} else if (newRange == island.getProtectionRange()) {
|
||||
} else if (newRange == targetIsland.getProtectionRange()) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get old range for event
|
||||
int oldRange = island.getProtectionRange();
|
||||
int oldRange = targetIsland.getProtectionRange();
|
||||
|
||||
// Well, now it can be applied without taking any risks!
|
||||
island.setProtectionRange(newRange);
|
||||
targetIsland.setProtectionRange(newRange);
|
||||
|
||||
// Call Protection Range Change event. Does not support cancelling.
|
||||
IslandEvent.builder()
|
||||
.island(island)
|
||||
.location(island.getCenter())
|
||||
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.protectionRange(newRange, oldRange)
|
||||
.build();
|
||||
.island(targetIsland).location(targetIsland.getCenter())
|
||||
.reason(IslandEvent.Reason.RANGE_CHANGE).involvedPlayer(targetUUID).admin(true)
|
||||
.protectionRange(newRange, oldRange).build();
|
||||
|
||||
user.sendMessage("commands.admin.range.add.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
@ -86,4 +56,6 @@ public class AdminRangeAddCommand extends CompositeCommand {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -31,4 +31,5 @@ public class AdminRangeCommand extends CompositeCommand {
|
||||
showHelp(this, user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +1,19 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* @since 1.10.0
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminRangeRemoveCommand extends CompositeCommand {
|
||||
public class AdminRangeRemoveCommand extends AbstractAdminRangeCommand {
|
||||
|
||||
public AdminRangeRemoveCommand(AdminRangeCommand parent) {
|
||||
super(parent, "remove");
|
||||
@ -32,48 +28,31 @@ public class AdminRangeRemoveCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID targetUUID = Util.getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(getIslands().hasIsland(getWorld(), targetUUID) || getIslands().inTeam(getWorld(), targetUUID))) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Util.isInteger(args.get(1), true) || Integer.parseInt(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||
int newRange = island.getProtectionRange() - Integer.parseInt(args.get(1));
|
||||
int newRange = targetIsland.getProtectionRange() - Integer.parseInt(args.get(1));
|
||||
|
||||
if (newRange <= 1) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER, String.valueOf(island.getRange()));
|
||||
user.sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER,
|
||||
String.valueOf(targetIsland.getRange()));
|
||||
return false;
|
||||
} else if (newRange == island.getProtectionRange()) {
|
||||
} else if (newRange == targetIsland.getProtectionRange()) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get old range for event
|
||||
int oldRange = island.getProtectionRange();
|
||||
int oldRange = targetIsland.getProtectionRange();
|
||||
|
||||
// Well, now it can be applied without taking any risks!
|
||||
island.setProtectionRange(newRange);
|
||||
targetIsland.setProtectionRange(newRange);
|
||||
|
||||
// Call Protection Range Change event. Does not support cancelling.
|
||||
IslandEvent.builder()
|
||||
.island(island)
|
||||
.location(island.getCenter())
|
||||
.island(targetIsland).location(targetIsland.getCenter())
|
||||
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
|
@ -1,19 +1,14 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.range;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminRangeSetCommand extends CompositeCommand {
|
||||
public class AdminRangeSetCommand extends AbstractAdminRangeCommand {
|
||||
|
||||
public AdminRangeSetCommand(CompositeCommand parent) {
|
||||
super(parent, "set");
|
||||
@ -28,23 +23,6 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get target player
|
||||
UUID targetUUID = Util.getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
if (!(getIslands().hasIsland(getWorld(), targetUUID) || getIslands().inTeam(getWorld(), targetUUID))) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get new range
|
||||
if (!Util.isInteger(args.get(1), true) || Integer.parseInt(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
@ -52,33 +30,30 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
||||
}
|
||||
int range = Integer.parseInt(args.get(1));
|
||||
|
||||
// Get island
|
||||
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||
|
||||
// Do some sanity checks to make sure the new protection range won't cause problems
|
||||
if (range < 1) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
if (range > island.getRange() * 2) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER, String.valueOf(2 * island.getRange()));
|
||||
if (range > targetIsland.getRange() * 2) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER,
|
||||
String.valueOf(2 * targetIsland.getRange()));
|
||||
return false;
|
||||
}
|
||||
if (range == island.getProtectionRange()) {
|
||||
if (range == targetIsland.getProtectionRange()) {
|
||||
user.sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get old range for event
|
||||
int oldRange = island.getProtectionRange();
|
||||
int oldRange = targetIsland.getProtectionRange();
|
||||
|
||||
// Well, now it can be applied without taking any risks!
|
||||
island.setProtectionRange(range);
|
||||
targetIsland.setProtectionRange(range);
|
||||
|
||||
// Call Protection Range Change event. Does not support canceling.
|
||||
IslandEvent.builder()
|
||||
.island(island)
|
||||
.location(island.getCenter())
|
||||
.island(targetIsland).location(targetIsland.getCenter())
|
||||
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
@ -90,14 +65,4 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
||||
|
@ -81,8 +81,10 @@ public class DefaultPasteUtil {
|
||||
*/
|
||||
public static BlockData createBlockData(BlueprintBlock block) {
|
||||
try {
|
||||
return Bukkit.createBlockData(block.getBlockData());
|
||||
return Material.STONE.createBlockData();
|
||||
//return Bukkit.createBlockData(block.getBlockData());
|
||||
} catch (Exception e) {
|
||||
BentoBox.getInstance().logStacktrace(e);
|
||||
return convertBlockData(block);
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ commands:
|
||||
&a Green Particles &f show the default protected range if the island protection range differs from it.
|
||||
showing: '&2 Showing range indicators'
|
||||
set:
|
||||
parameters: <player> <range>
|
||||
parameters: <player> <range> [island location]
|
||||
description: sets the island protected range
|
||||
success: '&a Set island protection range to &b [number]&a .'
|
||||
reset:
|
||||
@ -175,12 +175,12 @@ commands:
|
||||
success: '&a Reset island protection range to &b [number]&a .'
|
||||
add:
|
||||
description: increases the island protected range
|
||||
parameters: <player> <range>
|
||||
parameters: <player> <range> [island location]
|
||||
success: '&a Successfully increased &b [name]&a ''s island protected range
|
||||
to &b [total] &7 (&b +[number]&7 )&a .'
|
||||
remove:
|
||||
description: decreases the island protected range
|
||||
parameters: <player> <range>
|
||||
parameters: <player> <range> [island location]
|
||||
success: '&a Successfully decreased &b [name]&a ''s island protected range
|
||||
to &b [total] &7 (&b -[number]&7 )&a .'
|
||||
register:
|
||||
|
@ -1,7 +1,11 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.range;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -9,14 +13,18 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -56,6 +64,8 @@ public class AdminRangeSetCommandTest {
|
||||
private PlayersManager pm;
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
@Mock
|
||||
private @NonNull Location location;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -92,23 +102,25 @@ public class AdminRangeSetCommandTest {
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(iwm.getIslandProtectionRange(Mockito.any())).thenReturn(200);
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(iwm.getIslandProtectionRange(any())).thenReturn(200);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
Island island = mock(Island.class);
|
||||
when(island.getRange()).thenReturn(50);
|
||||
when(island.getProtectionRange()).thenReturn(50);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
when(location.toVector()).thenReturn(new Vector(2, 3, 4));
|
||||
when(island.getCenter()).thenReturn(location);
|
||||
when(im.getOwnedIslands(any(), any(UUID.class))).thenReturn(Set.of(island));
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -122,11 +134,11 @@ public class AdminRangeSetCommandTest {
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
Answer<String> answer = invocation -> invocation.getArgument(1, String.class);
|
||||
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Addon
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||
}
|
||||
|
||||
@After
|
||||
@ -137,69 +149,72 @@ public class AdminRangeSetCommandTest {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteConsoleNoArgs() {
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
User console = User.getInstance(sender);
|
||||
arc.execute(console, "", new ArrayList<>());
|
||||
assertFalse(arc.canExecute(console, "", new ArrayList<>()));
|
||||
// Show help
|
||||
Mockito.verify(sender).sendMessage("commands.help.header");
|
||||
verify(sender).sendMessage("commands.help.header");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerNoArgs() {
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
arc.execute(user, "", new ArrayList<>());
|
||||
assertFalse(arc.canExecute(user, "", List.of()));
|
||||
// Show help
|
||||
Mockito.verify(user).sendMessage("commands.help.header", "[label]", "BSkyBlock");
|
||||
verify(user).sendMessage("commands.help.header", "[label]", "BSkyBlock");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
String[] args = { "tastybento", "100" };
|
||||
arc.execute(user, "", Arrays.asList(args));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", args[0]);
|
||||
assertFalse(arc.canExecute(user, "", Arrays.asList(args)));
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", args[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteKnownPlayerNotOwnerNoTeam() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
when(im.getOwnedIslands(any(), any(UUID.class))).thenReturn(Set.of());
|
||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("100");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("general.errors.player-has-no-island");
|
||||
assertFalse(arc.canExecute(user, "", args));
|
||||
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#canExecute(User, String, List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteKnownPlayerNotOwnerButInTeam() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
when(im.getOwnedIslands(any(), any(UUID.class))).thenReturn(Set.of());
|
||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("100");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user, never()).sendMessage("general.errors.player-has-no-island");
|
||||
assertFalse(arc.canExecute(user, "", args));
|
||||
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,41 +222,42 @@ public class AdminRangeSetCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteTooHigh() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("1000");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER, "100");
|
||||
assertTrue(arc.canExecute(user, "", args));
|
||||
assertFalse(arc.execute(user, "", args));
|
||||
verify(user).sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER, "100");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNotANumber() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("NAN");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "NAN");
|
||||
assertFalse(arc.canExecute(user, "", args));
|
||||
verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "NAN");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test()
|
||||
public void testExecuteDoubleNumber() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("3.141592654");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "3.141592654");
|
||||
assertFalse(arc.canExecute(user, "", args));
|
||||
verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "3.141592654");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,13 +265,14 @@ public class AdminRangeSetCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteZero() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("0");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER, "0");
|
||||
assertTrue(arc.canExecute(user, "", args));
|
||||
assertFalse(arc.execute(user, "", args));
|
||||
verify(user).sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER, "0");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -263,13 +280,13 @@ public class AdminRangeSetCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNegNumber() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("-437645");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "-437645");
|
||||
assertFalse(arc.canExecute(user, "", args));
|
||||
verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "-437645");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,13 +294,14 @@ public class AdminRangeSetCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSame() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("50");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, "50");
|
||||
assertTrue(arc.canExecute(user, "", args));
|
||||
assertFalse(arc.execute(user, "", args));
|
||||
verify(user).sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, "50");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,13 +309,14 @@ public class AdminRangeSetCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecute() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("tastybento");
|
||||
args.add("48");
|
||||
arc.execute(user, "", args);
|
||||
Mockito.verify(user).sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, "48");
|
||||
assertTrue(arc.canExecute(user, "", args));
|
||||
assertTrue(arc.execute(user, "", args));
|
||||
verify(user).sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, "48");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user