Compare commits
31 Commits
49d05054d2
...
8649afdc4b
Author | SHA1 | Date |
---|---|---|
tastybento | 8649afdc4b | |
tastybento | 69a22e917e | |
tastybento | ffb955b22b | |
tastybento | 3de0ff236e | |
tastybento | c86eb6a19c | |
tastybento | e7055c6cba | |
tastybento | 5834dcbb59 | |
tastybento | 2c75939bc3 | |
tastybento | e570401912 | |
tastybento | f6f4da1c89 | |
tastybento | 6106b661e9 | |
tastybento | e1536fcae0 | |
tastybento | 1c19703f44 | |
tastybento | 24b7d26fbe | |
tastybento | ec60991aeb | |
tastybento | 33000f9371 | |
tastybento | 83eaa50b49 | |
tastybento | 1215a43766 | |
tastybento | 81f765df36 | |
tastybento | 0e6a25d74b | |
tastybento | 2b19d43c85 | |
tastybento | 1bce4ec1b9 | |
tastybento | ea8562f351 | |
tastybento | d8f2c12fe5 | |
tastybento | b734d579a1 | |
tastybento | 44454f5854 | |
tastybento | da590ce319 | |
tastybento | 6599e3de80 | |
tastybento | 3c6e3d1286 | |
tastybento | d77c94c30c | |
tastybento | d240e9c8d8 |
2
pom.xml
2
pom.xml
|
@ -88,7 +88,7 @@
|
||||||
<!-- Do not change unless you want different name for local builds. -->
|
<!-- Do not change unless you want different name for local builds. -->
|
||||||
<build.number>-LOCAL</build.number>
|
<build.number>-LOCAL</build.number>
|
||||||
<!-- This allows to change between versions. -->
|
<!-- This allows to change between versions. -->
|
||||||
<build.version>2.2.0</build.version>
|
<build.version>2.3.0</build.version>
|
||||||
<sonar.organization>bentobox-world</sonar.organization>
|
<sonar.organization>bentobox-world</sonar.organization>
|
||||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||||
<server.jars>${project.basedir}/lib</server.jars>
|
<server.jars>${project.basedir}/lib</server.jars>
|
||||||
|
|
|
@ -195,6 +195,12 @@ public class Settings implements ConfigObject {
|
||||||
@ConfigEntry(path = "island.concurrent-islands")
|
@ConfigEntry(path = "island.concurrent-islands")
|
||||||
private int islandNumber = 1;
|
private int islandNumber = 1;
|
||||||
|
|
||||||
|
@ConfigComment("Hide used blueprints.")
|
||||||
|
@ConfigComment("Blueprints can have a maximum use when players have concurrent islands.")
|
||||||
|
@ConfigComment("If this is true, then ones that are used up will not be shown in the island create menu.")
|
||||||
|
@ConfigEntry(path = "island.hide-used-blueprints", since = "2.3.0")
|
||||||
|
private boolean hideUsedBlueprints = false;
|
||||||
|
|
||||||
// Cooldowns
|
// Cooldowns
|
||||||
@ConfigComment("How long a player must wait until they can rejoin a team island after being kicked in minutes.")
|
@ConfigComment("How long a player must wait until they can rejoin a team island after being kicked in minutes.")
|
||||||
@ConfigComment("This slows the effectiveness of players repeating challenges")
|
@ConfigComment("This slows the effectiveness of players repeating challenges")
|
||||||
|
@ -1014,4 +1020,18 @@ public class Settings implements ConfigObject {
|
||||||
this.islandNumber = islandNumber;
|
this.islandNumber = islandNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the hideUsedBlueprints
|
||||||
|
*/
|
||||||
|
public boolean isHideUsedBlueprints() {
|
||||||
|
return hideUsedBlueprints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param hideUsedBlueprints the hideUsedBlueprints to set
|
||||||
|
*/
|
||||||
|
public void setHideUsedBlueprints(boolean hideUsedBlueprints) {
|
||||||
|
this.hideUsedBlueprints = hideUsedBlueprints;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,6 +524,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||||
* @param world - the world to check
|
* @param world - the world to check
|
||||||
* @param user - the User
|
* @param user - the User
|
||||||
* @return true if player is in a team
|
* @return true if player is in a team
|
||||||
|
* @see Consider checking the island itself {@link Island#inTeam(UUID)}
|
||||||
*/
|
*/
|
||||||
protected boolean inTeam(World world, User user) {
|
protected boolean inTeam(World world, User user) {
|
||||||
return plugin.getIslands().inTeam(world, user.getUniqueId());
|
return plugin.getIslands().inTeam(world, user.getUniqueId());
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class AdminDeleteCommand extends ConfirmableCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Team members should be kicked before deleting otherwise the whole team will become weird
|
// Team members should be kicked before deleting otherwise the whole team will become weird
|
||||||
if (getIslands().inTeam(getWorld(), targetUUID) && user.getUniqueId().equals(island.getOwner())) {
|
if (island.hasTeam() && user.getUniqueId().equals(island.getOwner())) {
|
||||||
user.sendMessage("commands.admin.delete.cannot-delete-owner");
|
user.sendMessage("commands.admin.delete.cannot-delete-owner");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
package world.bentobox.bentobox.api.commands.admin.range;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
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.events.island.IslandEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 1.10.0
|
* @since 1.10.0
|
||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
*/
|
*/
|
||||||
public class AdminRangeAddCommand extends CompositeCommand {
|
public class AdminRangeAddCommand extends AbstractAdminRangeCommand {
|
||||||
|
|
||||||
public AdminRangeAddCommand(AdminRangeCommand parent) {
|
public AdminRangeAddCommand(AdminRangeCommand parent) {
|
||||||
super(parent, "add");
|
super(parent, "add");
|
||||||
|
@ -32,53 +27,28 @@ public class AdminRangeAddCommand extends CompositeCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||||
if (args.size() != 2) {
|
int newRange = targetIsland.getProtectionRange() + Integer.parseInt(args.get(1));
|
||||||
showHelp(this, user);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
UUID targetUUID = Util.getUUID(args.get(0));
|
if (newRange > targetIsland.getRange()) {
|
||||||
if (targetUUID == null) {
|
user.sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER,
|
||||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
String.valueOf(targetIsland.getRange()));
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (newRange == targetIsland.getProtectionRange()) {
|
||||||
|
|
||||||
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()) {
|
|
||||||
user.sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
user.sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get old range for event
|
// Get old range for event
|
||||||
int oldRange = island.getProtectionRange();
|
int oldRange = targetIsland.getProtectionRange();
|
||||||
|
|
||||||
// Well, now it can be applied without taking any risks!
|
// 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.
|
// Call Protection Range Change event. Does not support cancelling.
|
||||||
IslandEvent.builder()
|
IslandEvent.builder()
|
||||||
.island(island)
|
.island(targetIsland).location(targetIsland.getCenter())
|
||||||
.location(island.getCenter())
|
.reason(IslandEvent.Reason.RANGE_CHANGE).involvedPlayer(targetUUID).admin(true)
|
||||||
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
.protectionRange(newRange, oldRange).build();
|
||||||
.involvedPlayer(targetUUID)
|
|
||||||
.admin(true)
|
|
||||||
.protectionRange(newRange, oldRange)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
user.sendMessage("commands.admin.range.add.success",
|
user.sendMessage("commands.admin.range.add.success",
|
||||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||||
|
@ -86,4 +56,6 @@ public class AdminRangeAddCommand extends CompositeCommand {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,4 +31,5 @@ public class AdminRangeCommand extends CompositeCommand {
|
||||||
showHelp(this, user);
|
showHelp(this, user);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
|
@ -1,23 +1,19 @@
|
||||||
package world.bentobox.bentobox.api.commands.admin.range;
|
package world.bentobox.bentobox.api.commands.admin.range;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
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.events.island.IslandEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 1.10.0
|
* @since 1.10.0
|
||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
*/
|
*/
|
||||||
public class AdminRangeRemoveCommand extends CompositeCommand {
|
public class AdminRangeRemoveCommand extends AbstractAdminRangeCommand {
|
||||||
|
|
||||||
public AdminRangeRemoveCommand(AdminRangeCommand parent) {
|
public AdminRangeRemoveCommand(AdminRangeCommand parent) {
|
||||||
super(parent, "remove");
|
super(parent, "remove");
|
||||||
|
@ -32,48 +28,31 @@ public class AdminRangeRemoveCommand extends CompositeCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
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) {
|
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));
|
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
int newRange = targetIsland.getProtectionRange() - Integer.parseInt(args.get(1));
|
||||||
int newRange = island.getProtectionRange() - Integer.parseInt(args.get(1));
|
|
||||||
|
|
||||||
if (newRange <= 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;
|
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));
|
user.sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get old range for event
|
// Get old range for event
|
||||||
int oldRange = island.getProtectionRange();
|
int oldRange = targetIsland.getProtectionRange();
|
||||||
|
|
||||||
// Well, now it can be applied without taking any risks!
|
// 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.
|
// Call Protection Range Change event. Does not support cancelling.
|
||||||
IslandEvent.builder()
|
IslandEvent.builder()
|
||||||
.island(island)
|
.island(targetIsland).location(targetIsland.getCenter())
|
||||||
.location(island.getCenter())
|
|
||||||
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
|
|
|
@ -1,19 +1,14 @@
|
||||||
package world.bentobox.bentobox.api.commands.admin.range;
|
package world.bentobox.bentobox.api.commands.admin.range;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
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.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
public class AdminRangeSetCommand extends CompositeCommand {
|
public class AdminRangeSetCommand extends AbstractAdminRangeCommand {
|
||||||
|
|
||||||
public AdminRangeSetCommand(CompositeCommand parent) {
|
public AdminRangeSetCommand(CompositeCommand parent) {
|
||||||
super(parent, "set");
|
super(parent, "set");
|
||||||
|
@ -28,23 +23,6 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
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
|
// Get new range
|
||||||
if (!Util.isInteger(args.get(1), true) || Integer.parseInt(args.get(1)) < 0) {
|
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));
|
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));
|
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
|
// Do some sanity checks to make sure the new protection range won't cause problems
|
||||||
if (range < 1) {
|
if (range < 1) {
|
||||||
user.sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER, args.get(1));
|
user.sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER, args.get(1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (range > island.getRange() * 2) {
|
if (range > targetIsland.getRange() * 2) {
|
||||||
user.sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER, String.valueOf(2 * island.getRange()));
|
user.sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER,
|
||||||
|
String.valueOf(2 * targetIsland.getRange()));
|
||||||
return false;
|
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));
|
user.sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get old range for event
|
// Get old range for event
|
||||||
int oldRange = island.getProtectionRange();
|
int oldRange = targetIsland.getProtectionRange();
|
||||||
|
|
||||||
// Well, now it can be applied without taking any risks!
|
// 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.
|
// Call Protection Range Change event. Does not support canceling.
|
||||||
IslandEvent.builder()
|
IslandEvent.builder()
|
||||||
.island(island)
|
.island(targetIsland).location(targetIsland.getCenter())
|
||||||
.location(island.getCenter())
|
|
||||||
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
.reason(IslandEvent.Reason.RANGE_CHANGE)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
|
@ -90,14 +65,4 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
||||||
return true;
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,17 +44,17 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
||||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(1));
|
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!getIslands().hasIsland(getWorld(), ownerUUID)) {
|
Island island = getIslands().getPrimaryIsland(getWorld(), ownerUUID);
|
||||||
|
if (island == null || !getIslands().hasIsland(getWorld(), ownerUUID)) {
|
||||||
user.sendMessage("general.errors.player-has-no-island");
|
user.sendMessage("general.errors.player-has-no-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Island island = getIslands().getPrimaryIsland(getWorld(), ownerUUID);
|
if (getIslands().inTeam(getWorld(), ownerUUID) && !ownerUUID.equals(island.getOwner())) {
|
||||||
if (getIslands().inTeam(getWorld(), ownerUUID) && island != null && !ownerUUID.equals(island.getOwner())) {
|
|
||||||
user.sendMessage("commands.admin.team.add.name-not-owner", TextVariables.NAME, args.get(0));
|
user.sendMessage("commands.admin.team.add.name-not-owner", TextVariables.NAME, args.get(0));
|
||||||
new IslandInfo(island).showMembers(user);
|
new IslandInfo(island).showMembers(user);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getIslands().inTeam(getWorld(), targetUUID)) {
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands() && island.inTeam(targetUUID)) {
|
||||||
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!getIslands().inTeam(getWorld(), targetUUID)) {
|
|
||||||
user.sendMessage("general.errors.player-is-not-owner", TextVariables.NAME, args.get(0));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Find the island the player is an owner of
|
// Find the island the player is an owner of
|
||||||
Map<String, Island> islands = getIslandsXYZ(targetUUID);
|
Map<String, Island> islands = getIslandsXYZ(targetUUID);
|
||||||
if (islands.isEmpty()) {
|
if (islands.isEmpty()) {
|
||||||
|
@ -77,6 +74,11 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||||
// Get the only island
|
// Get the only island
|
||||||
island = islands.values().iterator().next();
|
island = islands.values().iterator().next();
|
||||||
}
|
}
|
||||||
|
// Check that the target owns the island
|
||||||
|
if (island.getOwner() == null || !island.getOwner().equals(targetUUID)) {
|
||||||
|
user.sendMessage("general.errors.player-is-not-owner", TextVariables.NAME, args.get(0));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class IslandBanCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.island.ban.cannot-ban-yourself");
|
user.sendMessage("commands.island.ban.cannot-ban-yourself");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).getMemberSet().contains(targetUUID)) {
|
if (getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).inTeam(targetUUID)) {
|
||||||
user.sendMessage("commands.island.ban.cannot-ban-member");
|
user.sendMessage("commands.island.ban.cannot-ban-member");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,8 @@ public class IslandCreateCommand extends CompositeCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if this player is on a team in this world
|
// Check if this player is on a team in this world
|
||||||
if (getIslands().inTeam(getWorld(), user.getUniqueId()) && island != null
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()
|
||||||
|
&& getIslands().inTeam(getWorld(), user.getUniqueId()) && island != null
|
||||||
&& !user.getUniqueId().equals(island.getOwner())) {
|
&& !user.getUniqueId().equals(island.getOwner())) {
|
||||||
// Team members who are not owners cannot make additional islands
|
// Team members who are not owners cannot make additional islands
|
||||||
user.sendMessage("commands.island.create.you-cannot-make-team");
|
user.sendMessage("commands.island.create.you-cannot-make-team");
|
||||||
|
@ -86,22 +87,49 @@ public class IslandCreateCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.island.create.unknown-blueprint");
|
user.sendMessage("commands.island.create.unknown-blueprint");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Check perm
|
||||||
if (!getPlugin().getBlueprintsManager().checkPerm(getAddon(), user, Util.sanitizeInput(args.get(0)))) {
|
if (!getPlugin().getBlueprintsManager().checkPerm(getAddon(), user, Util.sanitizeInput(args.get(0)))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Check maximum uses
|
||||||
|
if (checkMaxUses(user, name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Make island
|
// Make island
|
||||||
return makeIsland(user, name);
|
return makeIsland(user, name);
|
||||||
} else {
|
} else {
|
||||||
|
if (getPlugin().getSettings().getIslandNumber() > 1
|
||||||
|
&& checkMaxUses(user, BlueprintsManager.DEFAULT_BUNDLE_NAME)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Show panel only if there are multiple bundles available
|
// Show panel only if there are multiple bundles available
|
||||||
if (getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).size() > 1) {
|
if (getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).size() > 1) {
|
||||||
// Show panel
|
// Show panel
|
||||||
IslandCreationPanel.openPanel(this, user, label);
|
IslandCreationPanel.openPanel(this, user, label, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return makeIsland(user, BlueprintsManager.DEFAULT_BUNDLE_NAME);
|
return makeIsland(user, BlueprintsManager.DEFAULT_BUNDLE_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkMaxUses(User user, String name) {
|
||||||
|
if (getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).containsKey(name)) {
|
||||||
|
int maxTimes = getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).get(name).getTimes();
|
||||||
|
// Check how many times this player has used this bundle
|
||||||
|
if (maxTimes > 0 && getBundleUses(user, name) >= maxTimes) {
|
||||||
|
user.sendMessage("commands.island.create.max-uses");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getBundleUses(User user, String name) {
|
||||||
|
return getIslands().getIslands(getWorld(), user).stream()
|
||||||
|
.filter(is -> is.getMetaData("bundle").map(mdv -> name.equalsIgnoreCase(mdv.asString())).orElse(false))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean makeIsland(User user, String name) {
|
private boolean makeIsland(User user, String name) {
|
||||||
user.sendMessage("commands.island.create.creating-island");
|
user.sendMessage("commands.island.create.creating-island");
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class IslandExpelCommand extends CompositeCommand {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Or team member
|
// Or team member
|
||||||
if (island.getMemberSet().contains(targetUUID)) {
|
if (island.inTeam(targetUUID)) {
|
||||||
user.sendMessage("commands.island.expel.cannot-expel-member");
|
user.sendMessage("commands.island.expel.cannot-expel-member");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.DelayedTeleportCommand;
|
import world.bentobox.bentobox.api.commands.DelayedTeleportCommand;
|
||||||
|
@ -41,7 +40,7 @@ public class IslandGoCommand extends DelayedTeleportCommand {
|
||||||
user.sendMessage("commands.island.go.teleport");
|
user.sendMessage("commands.island.go.teleport");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Set<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
|
List<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
|
||||||
if (islands.isEmpty()) {
|
if (islands.isEmpty()) {
|
||||||
user.sendMessage("general.errors.no-island");
|
user.sendMessage("general.errors.no-island");
|
||||||
return false;
|
return false;
|
||||||
|
@ -86,7 +85,7 @@ public class IslandGoCommand extends DelayedTeleportCommand {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkReserved(User user, Set<Island> islands) {
|
private boolean checkReserved(User user, List<Island> islands) {
|
||||||
for (Island island : islands) {
|
for (Island island : islands) {
|
||||||
if (island.isReserved()) {
|
if (island.isReserved()) {
|
||||||
// Send player to create an island
|
// Send player to create an island
|
||||||
|
|
|
@ -3,7 +3,6 @@ package world.bentobox.bentobox.api.commands.island;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
|
@ -14,7 +13,7 @@ import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
public class IslandHomesCommand extends ConfirmableCommand {
|
public class IslandHomesCommand extends ConfirmableCommand {
|
||||||
|
|
||||||
private Set<Island> islands;
|
private List<Island> islands;
|
||||||
|
|
||||||
public IslandHomesCommand(CompositeCommand islandCommand) {
|
public IslandHomesCommand(CompositeCommand islandCommand) {
|
||||||
super(islandCommand, "homes");
|
super(islandCommand, "homes");
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||||
// Show panel only if there are multiple bundles available
|
// Show panel only if there are multiple bundles available
|
||||||
if (getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).size() > 1) {
|
if (getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).size() > 1) {
|
||||||
// Show panel - once the player selected a bundle, this will re-run this command
|
// Show panel - once the player selected a bundle, this will re-run this command
|
||||||
IslandCreationPanel.openPanel(this, user, label);
|
IslandCreationPanel.openPanel(this, user, label, true);
|
||||||
} else {
|
} else {
|
||||||
resetIsland(user, BlueprintsManager.DEFAULT_BUNDLE_NAME);
|
resetIsland(user, BlueprintsManager.DEFAULT_BUNDLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package world.bentobox.bentobox.api.commands.island.team;
|
package world.bentobox.bentobox.api.commands.island.team;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
@ -62,7 +61,8 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if player is already in a team
|
// Check if player is already in a team
|
||||||
if (getIslands().inTeam(getWorld(), playerUUID)) {
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()
|
||||||
|
&& getIslands().inTeam(getWorld(), playerUUID)) {
|
||||||
user.sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
user.sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,14 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||||
switch (invite.getType()) {
|
switch (invite.getType()) {
|
||||||
case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite));
|
case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite));
|
||||||
case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite));
|
case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite));
|
||||||
default -> askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"),
|
default -> {
|
||||||
() -> acceptTeamInvite(user, invite));
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()) {
|
||||||
|
askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"),
|
||||||
|
() -> acceptTeamInvite(user, invite));
|
||||||
|
} else {
|
||||||
|
acceptTeamInvite(user, invite);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +150,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||||
// Remove the invite
|
// Remove the invite
|
||||||
itc.removeInvite(user.getUniqueId());
|
itc.removeInvite(user.getUniqueId());
|
||||||
// Get the player's island - may be null if the player has no island
|
// Get the player's island - may be null if the player has no island
|
||||||
Set<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
|
List<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
|
||||||
// Get the team's island
|
// Get the team's island
|
||||||
Island teamIsland = invite.getIsland();
|
Island teamIsland = invite.getIsland();
|
||||||
if (teamIsland == null) {
|
if (teamIsland == null) {
|
||||||
|
@ -156,17 +162,21 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||||
user.sendMessage("commands.island.team.invite.errors.island-is-full");
|
user.sendMessage("commands.island.team.invite.errors.island-is-full");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Remove the player's other islands
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()) {
|
||||||
getIslands().removePlayer(getWorld(), user.getUniqueId());
|
// Remove the player's other islands
|
||||||
// Remove money inventory etc. for leaving
|
getIslands().removePlayer(getWorld(), user.getUniqueId());
|
||||||
cleanPlayer(user);
|
// Remove money inventory etc. for leaving
|
||||||
|
cleanPlayer(user);
|
||||||
|
}
|
||||||
// Add the player as a team member of the new island
|
// Add the player as a team member of the new island
|
||||||
getIslands().setJoinTeam(teamIsland, user.getUniqueId());
|
getIslands().setJoinTeam(teamIsland, user.getUniqueId());
|
||||||
// Move player to team's island
|
// Move player to team's island
|
||||||
|
getIslands().setPrimaryIsland(user.getUniqueId(), teamIsland);
|
||||||
getIslands().homeTeleportAsync(getWorld(), user.getPlayer()).thenRun(() -> {
|
getIslands().homeTeleportAsync(getWorld(), user.getPlayer()).thenRun(() -> {
|
||||||
// Delete the old islands
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()) {
|
||||||
islands.forEach(island -> getIslands().deleteIsland(island, true, user.getUniqueId()));
|
// Delete the old islands
|
||||||
|
islands.forEach(island -> getIslands().deleteIsland(island, true, user.getUniqueId()));
|
||||||
|
}
|
||||||
// Put player back into normal mode
|
// Put player back into normal mode
|
||||||
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
|
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
|
||||||
|
|
||||||
|
@ -175,8 +185,9 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||||
Util.runCommands(user, ownerName, getIWM().getOnJoinCommands(getWorld()), "join");
|
Util.runCommands(user, ownerName, getIWM().getOnJoinCommands(getWorld()), "join");
|
||||||
|
|
||||||
});
|
});
|
||||||
// Reset deaths
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()
|
||||||
if (getIWM().isTeamJoinDeathReset(getWorld())) {
|
&& getIWM().isTeamJoinDeathReset(getWorld())) {
|
||||||
|
// Reset deaths
|
||||||
getPlayers().setDeaths(getWorld(), user.getUniqueId(), 0);
|
getPlayers().setDeaths(getWorld(), user.getUniqueId(), 0);
|
||||||
}
|
}
|
||||||
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
||||||
|
|
|
@ -105,7 +105,8 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player cannot invite someone already on a team
|
// Player cannot invite someone already on a team
|
||||||
if (getIslands().inTeam(getWorld(), invitedPlayerUUID)) {
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()
|
||||||
|
&& getIslands().inTeam(getWorld(), invitedPlayerUUID)) {
|
||||||
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +171,8 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||||
// Send message to online player
|
// Send message to online player
|
||||||
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
|
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
|
||||||
invitedPlayer.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
invitedPlayer.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
||||||
if (getIslands().hasIsland(getWorld(), invitedPlayer.getUniqueId())) {
|
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()
|
||||||
|
&& getIslands().hasIsland(getWorld(), invitedPlayer.getUniqueId())) {
|
||||||
invitedPlayer.sendMessage("commands.island.team.invite.you-will-lose-your-island");
|
invitedPlayer.sendMessage("commands.island.team.invite.you-will-lose-your-island");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||||
user.sendMessage("commands.island.team.kick.cannot-kick");
|
user.sendMessage("commands.island.team.kick.cannot-kick");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).getMemberSet().contains(targetUUID)) {
|
if (!getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).inTeam(targetUUID)) {
|
||||||
user.sendMessage("general.errors.not-in-team");
|
user.sendMessage("general.errors.not-in-team");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
Island oldIsland = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID)); // Should never be
|
Island oldIsland = Objects.requireNonNull(getIslands().getIsland(getWorld(), user)); // Should never be
|
||||||
// null because of
|
// null because of
|
||||||
// checks above
|
// checks above
|
||||||
// Fire event
|
// Fire event
|
||||||
|
@ -108,7 +108,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||||
getAddon().getDescription().getName(), TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME,
|
getAddon().getDescription().getName(), TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME,
|
||||||
user.getDisplayName());
|
user.getDisplayName());
|
||||||
|
|
||||||
getIslands().removePlayer(getWorld(), targetUUID);
|
getIslands().removePlayer(oldIsland, targetUUID);
|
||||||
// Clean the target player
|
// Clean the target player
|
||||||
getPlayers().cleanLeavingPlayer(getWorld(), target, true, oldIsland);
|
getPlayers().cleanLeavingPlayer(getWorld(), target, true, oldIsland);
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check that target is a member of this island
|
// Check that target is a member of this island
|
||||||
if (!island.getMemberSet().contains(target.getUniqueId())) {
|
if (!island.inTeam(target.getUniqueId())) {
|
||||||
user.sendMessage("commands.island.team.promote.errors.must-be-member");
|
user.sendMessage("commands.island.team.promote.errors.must-be-member");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
||||||
}
|
}
|
||||||
// Can use if in a team
|
// Can use if in a team
|
||||||
Island is = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
|
Island is = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
|
||||||
if (is == null || !is.getMemberSet().contains(user.getUniqueId())) {
|
if (is == null || !is.inTeam(user.getUniqueId())) {
|
||||||
user.sendMessage("general.errors.no-team");
|
user.sendMessage("general.errors.no-team");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
|
user.sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!is.getMemberSet().contains(targetUUID)) {
|
if (!is.inTeam(targetUUID)) {
|
||||||
user.sendMessage("commands.island.team.setowner.errors.target-is-not-member");
|
user.sendMessage("commands.island.team.setowner.errors.target-is-not-member");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-yourself");
|
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-yourself");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).getMemberSet().contains(targetUUID)) {
|
if (getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).inTeam(targetUUID)) {
|
||||||
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-member");
|
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-member");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class IslandTeamUntrustCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.island.team.untrust.cannot-untrust-yourself");
|
user.sendMessage("commands.island.team.untrust.cannot-untrust-yourself");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).getMemberSet().contains(targetUUID)) {
|
if (getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).inTeam(targetUUID)) {
|
||||||
user.sendMessage("commands.island.team.untrust.cannot-untrust-member");
|
user.sendMessage("commands.island.team.untrust.cannot-untrust-member");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -644,4 +644,13 @@ public interface WorldSettings extends ConfigObject {
|
||||||
default int getConcurrentIslands() {
|
default int getConcurrentIslands() {
|
||||||
return BentoBox.getInstance().getSettings().getIslandNumber();
|
return BentoBox.getInstance().getSettings().getIslandNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove islands when players join a team and not allow players to have other islands if they are in a team.
|
||||||
|
* @return true or false
|
||||||
|
* @since 2.3.0
|
||||||
|
*/
|
||||||
|
default boolean isDisallowTeamMemberIslands() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
@ -59,6 +60,11 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(Panel panel, User user2, ClickType click, int slot) {
|
public boolean onClick(Panel panel, User user2, ClickType click, int slot) {
|
||||||
|
if (panel.getWorld().isEmpty()) {
|
||||||
|
plugin.logError("Panel " + panel.getName()
|
||||||
|
+ " has no world associated with it. Please report this bug to the author.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// This click listener is used with TabbedPanel and SettingsTabs only
|
// This click listener is used with TabbedPanel and SettingsTabs only
|
||||||
TabbedPanel tp = (TabbedPanel)panel;
|
TabbedPanel tp = (TabbedPanel)panel;
|
||||||
SettingsTab st = (SettingsTab)tp.getActiveTab();
|
SettingsTab st = (SettingsTab)tp.getActiveTab();
|
||||||
|
@ -67,7 +73,7 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||||
this.user = user2;
|
this.user = user2;
|
||||||
changeOccurred = false;
|
changeOccurred = false;
|
||||||
// Permission prefix
|
// Permission prefix
|
||||||
String prefix = plugin.getIWM().getPermissionPrefix(Util.getWorld(user.getWorld()));
|
String prefix = plugin.getIWM().getPermissionPrefix(Util.getWorld(panel.getWorld().get()));
|
||||||
String reqPerm = prefix + "settings." + id;
|
String reqPerm = prefix + "settings." + id;
|
||||||
String allPerms = prefix + "settings.*";
|
String allPerms = prefix + "settings.*";
|
||||||
if (!user.hasPermission(reqPerm) && !user.hasPermission(allPerms)
|
if (!user.hasPermission(reqPerm) && !user.hasPermission(allPerms)
|
||||||
|
@ -91,7 +97,7 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||||
rightClick(flag, currentRank);
|
rightClick(flag, currentRank);
|
||||||
|
|
||||||
} else if (click.equals(ClickType.SHIFT_LEFT) && user2.isOp()) {
|
} else if (click.equals(ClickType.SHIFT_LEFT) && user2.isOp()) {
|
||||||
leftShiftClick(flag);
|
leftShiftClick(flag, panel.getWorld().get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -149,16 +155,16 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void leftShiftClick(Flag flag) {
|
private void leftShiftClick(Flag flag, World world) {
|
||||||
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID())) {
|
if (!plugin.getIWM().getHiddenFlags(world).contains(flag.getID())) {
|
||||||
plugin.getIWM().getHiddenFlags(user.getWorld()).add(flag.getID());
|
plugin.getIWM().getHiddenFlags(world).add(flag.getID());
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||||
} else {
|
} else {
|
||||||
plugin.getIWM().getHiddenFlags(user.getWorld()).remove(flag.getID());
|
plugin.getIWM().getHiddenFlags(world).remove(flag.getID());
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||||
}
|
}
|
||||||
// Save changes
|
// Save changes
|
||||||
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings);
|
plugin.getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,9 @@ public class BlueprintPaster {
|
||||||
Vector off = bp.getBedrock() != null ? bp.getBedrock() : new Vector(0,0,0);
|
Vector off = bp.getBedrock() != null ? bp.getBedrock() : new Vector(0,0,0);
|
||||||
// Calculate location for pasting
|
// Calculate location for pasting
|
||||||
this.location = island.getProtectionCenter().toVector().subtract(off).toLocation(world);
|
this.location = island.getProtectionCenter().toVector().subtract(off).toLocation(world);
|
||||||
|
// Ensure the y coordinate is within the world limits
|
||||||
|
int y = Math.min(world.getMaxHeight() - 1, Math.max(world.getMinHeight(), location.getBlockY()));
|
||||||
|
location.setY(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record Bits(Map<Vector, BlueprintBlock> blocks,
|
private record Bits(Map<Vector, BlueprintBlock> blocks,
|
||||||
|
|
|
@ -61,6 +61,11 @@ public class BlueprintBundle implements DataObject {
|
||||||
@Expose
|
@Expose
|
||||||
private int slot = 0;
|
private int slot = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of times this bundle can be used by a single player. 0 = unlimited
|
||||||
|
*/
|
||||||
|
@Expose
|
||||||
|
private int times = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,4 +193,18 @@ public class BlueprintBundle implements DataObject {
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the times
|
||||||
|
*/
|
||||||
|
public int getTimes() {
|
||||||
|
return times;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param times the times to set
|
||||||
|
*/
|
||||||
|
public void setTimes(int times) {
|
||||||
|
this.times = times;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,6 +286,9 @@ public class BlueprintEntity {
|
||||||
* @return the mythicMobsRecord
|
* @return the mythicMobsRecord
|
||||||
*/
|
*/
|
||||||
public MythicMobRecord getMythicMobsRecord() {
|
public MythicMobRecord getMythicMobsRecord() {
|
||||||
|
if (this.MMtype == null || this.MMLevel == null || this.MMpower == null || this.MMStance == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new MythicMobRecord(this.MMtype, this.getCustomName(), this.MMLevel, this.MMpower, this.MMStance);
|
return new MythicMobRecord(this.MMtype, this.getCustomName(), this.MMLevel, this.MMpower, this.MMStance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1950,6 +1950,25 @@ public class Island implements DataObject, MetaDataAble {
|
||||||
setChanged();
|
setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a player is in this island's team
|
||||||
|
* @param playerUUID player's UUID
|
||||||
|
* @return true if in team
|
||||||
|
* @since 2.3.0
|
||||||
|
*/
|
||||||
|
public boolean inTeam(UUID playerUUID) {
|
||||||
|
return this.getMemberSet().contains(playerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this island has a team
|
||||||
|
* @return true if this island has a team
|
||||||
|
* @since 2.3.0
|
||||||
|
*/
|
||||||
|
public boolean hasTeam() {
|
||||||
|
return this.getMemberSet().size() > 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|
|
@ -55,6 +55,9 @@ public class MythicMobsHook extends Hook {
|
||||||
* @return true if spawn is successful
|
* @return true if spawn is successful
|
||||||
*/
|
*/
|
||||||
public boolean spawnMythicMob(MythicMobRecord mmr, Location spawnLocation) {
|
public boolean spawnMythicMob(MythicMobRecord mmr, Location spawnLocation) {
|
||||||
|
if (!this.isPluginAvailable()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return MythicBukkit.inst().getMobManager().getMythicMob(mmr.type()).map(mob -> {
|
return MythicBukkit.inst().getMobManager().getMythicMob(mmr.type()).map(mob -> {
|
||||||
// A delay is required before spawning, I assume because the blocks are pasted using NMS
|
// A delay is required before spawning, I assume because the blocks are pasted using NMS
|
||||||
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> {
|
||||||
|
|
|
@ -79,6 +79,10 @@ public class JoinLeaveListener implements Listener {
|
||||||
plugin.logWarning("Player that just logged in has no name! " + playerUUID);
|
plugin.logWarning("Player that just logged in has no name! " + playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the primary island to the player's location if this is their island
|
||||||
|
plugin.getIslands().getIslandAt(user.getLocation()).filter(i -> user.getUniqueId().equals(i.getOwner()))
|
||||||
|
.ifPresent(i -> plugin.getIslands().setPrimaryIsland(playerUUID, i));
|
||||||
|
|
||||||
// If mobs have to be removed when a player joins, then wipe all the mobs on his
|
// If mobs have to be removed when a player joins, then wipe all the mobs on his
|
||||||
// island.
|
// island.
|
||||||
if (plugin.getIslands().locationIsOnIsland(event.getPlayer(), user.getLocation())
|
if (plugin.getIslands().locationIsOnIsland(event.getPlayer(), user.getLocation())
|
||||||
|
@ -219,7 +223,7 @@ public class JoinLeaveListener implements Listener {
|
||||||
.filter(island -> island.getMembers().containsKey(event.getPlayer().getUniqueId())).forEach(island -> {
|
.filter(island -> island.getMembers().containsKey(event.getPlayer().getUniqueId())).forEach(island -> {
|
||||||
// Are there any online players still for this island?
|
// Are there any online players still for this island?
|
||||||
if (Bukkit.getOnlinePlayers().stream().filter(p -> !event.getPlayer().equals(p))
|
if (Bukkit.getOnlinePlayers().stream().filter(p -> !event.getPlayer().equals(p))
|
||||||
.noneMatch(p -> island.getMemberSet().contains(p.getUniqueId()))) {
|
.noneMatch(p -> island.inTeam(p.getUniqueId()))) {
|
||||||
// No, there are no more players online on this island
|
// No, there are no more players online on this island
|
||||||
// Tell players they are being removed
|
// Tell players they are being removed
|
||||||
island.getMembers().entrySet().stream().filter(e -> e.getValue() == RanksManager.COOP_RANK)
|
island.getMembers().entrySet().stream().filter(e -> e.getValue() == RanksManager.COOP_RANK)
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class EnterExitListener extends FlagListener {
|
||||||
// Leave messages are always specific to this world
|
// Leave messages are always specific to this world
|
||||||
String islandMessage = user.getTranslation(island.getWorld(), ISLAND_MESSAGE, TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()));
|
String islandMessage = user.getTranslation(island.getWorld(), ISLAND_MESSAGE, TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()));
|
||||||
// Send specific message if the player is member of this island
|
// Send specific message if the player is member of this island
|
||||||
if (island.getMemberSet().contains(user.getUniqueId())) {
|
if (island.inTeam(user.getUniqueId())) {
|
||||||
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving-your-island", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving-your-island", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
||||||
} else {
|
} else {
|
||||||
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
||||||
|
@ -135,7 +135,7 @@ public class EnterExitListener extends FlagListener {
|
||||||
// Enter messages are always specific to this world
|
// Enter messages are always specific to this world
|
||||||
String islandMessage = user.getTranslation(island.getWorld(), ISLAND_MESSAGE, TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()));
|
String islandMessage = user.getTranslation(island.getWorld(), ISLAND_MESSAGE, TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()));
|
||||||
// Send specific message if the player is member of this island
|
// Send specific message if the player is member of this island
|
||||||
if (island.getMemberSet().contains(user.getUniqueId())) {
|
if (island.inTeam(user.getUniqueId())) {
|
||||||
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering-your-island", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering-your-island", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
||||||
} else {
|
} else {
|
||||||
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (island.getName() != null) ? island.getName() : islandMessage);
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class PetTeleportListener extends FlagListener {
|
||||||
// Get where the pet is going
|
// Get where the pet is going
|
||||||
e.setCancelled(getIslands().getProtectedIslandAt(e.getTo())
|
e.setCancelled(getIslands().getProtectedIslandAt(e.getTo())
|
||||||
// Not home island
|
// Not home island
|
||||||
.map(i -> !i.getMemberSet().contains(t.getOwner().getUniqueId()))
|
.map(i -> !i.inTeam(t.getOwner().getUniqueId()))
|
||||||
// Not any island
|
// Not any island
|
||||||
.orElse(true));
|
.orElse(true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class VisitorsStartingRaidListener extends FlagListener
|
||||||
|
|
||||||
Optional<Island> island = this.getIslands().getProtectedIslandAt(event.getPlayer().getLocation());
|
Optional<Island> island = this.getIslands().getProtectedIslandAt(event.getPlayer().getLocation());
|
||||||
|
|
||||||
if (island.isPresent() && !island.get().getMemberSet().contains(event.getPlayer().getUniqueId()))
|
if (island.isPresent() && !island.get().inTeam(event.getPlayer().getUniqueId()))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
this.report(User.getInstance(event.getPlayer()),
|
this.report(User.getInstance(event.getPlayer()),
|
||||||
|
|
|
@ -17,6 +17,9 @@ import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common Game Mode Placeholders
|
||||||
|
*/
|
||||||
public enum GameModePlaceholder {
|
public enum GameModePlaceholder {
|
||||||
|
|
||||||
/* World-related */
|
/* World-related */
|
||||||
|
|
|
@ -40,6 +40,7 @@ import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
import world.bentobox.bentobox.api.metadata.MetaDataValue;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.blueprints.Blueprint;
|
import world.bentobox.bentobox.blueprints.Blueprint;
|
||||||
import world.bentobox.bentobox.blueprints.BlueprintPaster;
|
import world.bentobox.bentobox.blueprints.BlueprintPaster;
|
||||||
|
@ -484,6 +485,8 @@ public class BlueprintsManager {
|
||||||
b2 ->
|
b2 ->
|
||||||
pasteEnd(addon, bb, island).thenAccept(message -> sendMessage(island)).thenAccept(b3 -> Bukkit.getScheduler().runTask(plugin, task))));
|
pasteEnd(addon, bb, island).thenAccept(message -> sendMessage(island)).thenAccept(b3 -> Bukkit.getScheduler().runTask(plugin, task))));
|
||||||
}
|
}
|
||||||
|
// Set the bundle name
|
||||||
|
island.putMetaData("bundle", new MetaDataValue(name));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,7 +321,7 @@ public class IslandsManager {
|
||||||
* @return List of islands or empty list if none found for user
|
* @return List of islands or empty list if none found for user
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Set<Island> getIslands(@NonNull World world, @NonNull User user) {
|
public List<Island> getIslands(@NonNull World world, @NonNull User user) {
|
||||||
return getIslands(world, user.getUniqueId());
|
return getIslands(world, user.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ public class IslandsManager {
|
||||||
* @return List of islands or empty list if none found for user
|
* @return List of islands or empty list if none found for user
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Set<Island> getIslands(@NonNull World world, UUID uniqueId) {
|
public List<Island> getIslands(@NonNull World world, UUID uniqueId) {
|
||||||
return islandCache.getIslands(world, uniqueId);
|
return islandCache.getIslands(world, uniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1319,7 +1319,7 @@ public class IslandsManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get the player's island
|
// Get the player's island
|
||||||
return getIslandAt(loc).filter(i -> i.onIsland(loc)).map(i -> i.getMemberSet().contains(player.getUniqueId()))
|
return getIslandAt(loc).filter(i -> i.onIsland(loc)).map(i -> i.inTeam(player.getUniqueId()))
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1389,7 +1389,7 @@ public class IslandsManager {
|
||||||
.filter(p -> p.getGameMode().equals(plugin.getIWM().getDefaultGameMode(island.getWorld())))
|
.filter(p -> p.getGameMode().equals(plugin.getIWM().getDefaultGameMode(island.getWorld())))
|
||||||
.filter(p -> island.onIsland(p.getLocation())).forEach(p -> {
|
.filter(p -> island.onIsland(p.getLocation())).forEach(p -> {
|
||||||
// Teleport island players to their island home
|
// Teleport island players to their island home
|
||||||
if (!island.getMemberSet().contains(p.getUniqueId())
|
if (!island.inTeam(p.getUniqueId())
|
||||||
&& (hasIsland(w, p.getUniqueId()) || inTeam(w, p.getUniqueId()))) {
|
&& (hasIsland(w, p.getUniqueId()) || inTeam(w, p.getUniqueId()))) {
|
||||||
homeTeleportAsync(w, p);
|
homeTeleportAsync(w, p);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1493,16 +1493,17 @@ public class IslandsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a player is in a team in this world. Note that the player may have
|
* Checks if a player is in any team in this world. Note that the player may have
|
||||||
* multiple islands in the world, any one of which may have a team.
|
* multiple islands in the world, any one of which may have a team.
|
||||||
*
|
*
|
||||||
* @param world - world
|
* @param world - world
|
||||||
* @param playerUUID - player's UUID
|
* @param playerUUID - player's UUID
|
||||||
* @return true if in team, false if not
|
* @return true if in team, false if not
|
||||||
|
* @see Consider checking the island itself {@link Island#inTeam(UUID)}
|
||||||
*/
|
*/
|
||||||
public boolean inTeam(World world, @NonNull UUID playerUUID) {
|
public boolean inTeam(World world, @NonNull UUID playerUUID) {
|
||||||
return this.islandCache.getIslands(world, playerUUID).stream()
|
return this.islandCache.getIslands(world, playerUUID).stream()
|
||||||
.anyMatch(island -> island.getMemberSet().size() > 1 && island.getMemberSet().contains(playerUUID));
|
.anyMatch(island -> island.getMemberSet().size() > 1 && island.inTeam(playerUUID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,9 @@ package world.bentobox.bentobox.managers;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
@ -13,6 +16,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.placeholders.PlaceholderReplacer;
|
import world.bentobox.bentobox.api.placeholders.PlaceholderReplacer;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
@ -72,6 +76,50 @@ public class PlaceholdersManager {
|
||||||
.forEach(placeholder -> registerPlaceholder(addon, placeholder.getPlaceholder(), new DefaultPlaceholder(addon, placeholder)));
|
.forEach(placeholder -> registerPlaceholder(addon, placeholder.getPlaceholder(), new DefaultPlaceholder(addon, placeholder)));
|
||||||
// Register team member placeholders
|
// Register team member placeholders
|
||||||
registerTeamMemberPlaceholders(addon);
|
registerTeamMemberPlaceholders(addon);
|
||||||
|
// Register potential island names and member info
|
||||||
|
registerOwnedIslandPlaceholders(addon);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerOwnedIslandPlaceholders(@NonNull GameModeAddon addon) {
|
||||||
|
int maxIslands = plugin.getIWM().getWorldSettings(addon.getOverWorld()).getConcurrentIslands();
|
||||||
|
IntStream.range(0, maxIslands).forEach(i -> registerPlaceholder(addon, "island_name_" + (i + 1), user -> {
|
||||||
|
if (user == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
AtomicInteger generatedCount = new AtomicInteger(1); // To increment within lambda
|
||||||
|
return plugin.getIslands().getIslands(addon.getOverWorld(), user).stream().map(island -> {
|
||||||
|
IslandName islandName = getIslandName(island, user, generatedCount.get());
|
||||||
|
if (islandName.generatated()) {
|
||||||
|
generatedCount.getAndIncrement(); // Increment if the name was generated
|
||||||
|
}
|
||||||
|
return islandName.name;
|
||||||
|
}).skip(i) // Skip to the island at index 'i'
|
||||||
|
.findFirst() // Take the first island after skipping, effectively the (i+1)th
|
||||||
|
.orElse(""); // Default to empty string if no island is found
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Island_memberlist
|
||||||
|
IntStream.range(0, maxIslands)
|
||||||
|
.forEach(i -> registerPlaceholder(addon, "island_memberlist_" + (i + 1), user -> user == null ? ""
|
||||||
|
: plugin.getIslands().getIslands(addon.getOverWorld(), user).stream().skip(i).findFirst()
|
||||||
|
.map(island -> island.getMemberSet().stream()
|
||||||
|
.map(addon.getPlayers()::getName).collect(Collectors.joining(",")))
|
||||||
|
.orElse("")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private record IslandName(String name, boolean generatated) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private IslandName getIslandName(Island island, User user, int index) {
|
||||||
|
if (island.getName() != null && !island.getName().isBlank()) {
|
||||||
|
// Name has been set
|
||||||
|
return new IslandName(island.getName(), false);
|
||||||
|
} else {
|
||||||
|
// Name has not been set
|
||||||
|
return new IslandName(user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME,
|
||||||
|
user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()) + " " + index, true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerTeamMemberPlaceholders(@NonNull GameModeAddon addon) {
|
private void registerTeamMemberPlaceholders(@NonNull GameModeAddon addon) {
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package world.bentobox.bentobox.managers.island;
|
package world.bentobox.bentobox.managers.island;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -170,7 +173,7 @@ public class IslandCache {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Island get(@NonNull World world, @NonNull UUID uuid) {
|
public Island get(@NonNull World world, @NonNull UUID uuid) {
|
||||||
Set<Island> islands = getIslands(world, uuid);
|
List<Island> islands = getIslands(world, uuid);
|
||||||
if (islands.isEmpty()) {
|
if (islands.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -190,15 +193,16 @@ public class IslandCache {
|
||||||
*
|
*
|
||||||
* @param world world to check. Includes nether and end worlds.
|
* @param world world to check. Includes nether and end worlds.
|
||||||
* @param uuid player's UUID
|
* @param uuid player's UUID
|
||||||
* @return list of island or empty list if none
|
* @return list of island or empty list if none sorted from oldest to youngest
|
||||||
*/
|
*/
|
||||||
public Set<Island> getIslands(@NonNull World world, @NonNull UUID uuid) {
|
public List<Island> getIslands(@NonNull World world, @NonNull UUID uuid) {
|
||||||
World w = Util.getWorld(world);
|
World w = Util.getWorld(world);
|
||||||
if (w == null) {
|
if (w == null) {
|
||||||
return new HashSet<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
return islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).stream().filter(i -> w.equals(i.getWorld()))
|
return islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).stream().filter(island -> w.equals(island.getWorld()))
|
||||||
.collect(Collectors.toSet());
|
.sorted(Comparator.comparingLong(Island::getCreatedDate))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -77,10 +77,21 @@ public class BlueprintManagementPanel {
|
||||||
environmentToBlueprint = Map.of(World.Environment.NORMAL, normalBlueprint, World.Environment.NETHER, netherBlueprint, World.Environment.THE_END, endBlueprint);
|
environmentToBlueprint = Map.of(World.Environment.NORMAL, normalBlueprint, World.Environment.NETHER, netherBlueprint, World.Environment.THE_END, endBlueprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate "commands.admin.blueprint.management." + t reference
|
||||||
|
* @param t - end of reference
|
||||||
|
* @return translation
|
||||||
|
*/
|
||||||
private String t(String t) {
|
private String t(String t) {
|
||||||
return user.getTranslation("commands.admin.blueprint.management." + t);
|
return user.getTranslation("commands.admin.blueprint.management." + t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate "commands.admin.blueprint.management." + t + vars reference
|
||||||
|
* @param t end of reference
|
||||||
|
* @param vars any other parameters
|
||||||
|
* @return transmation
|
||||||
|
*/
|
||||||
private String t(String t, String... vars) {
|
private String t(String t, String... vars) {
|
||||||
return user.getTranslation("commands.admin.blueprint.management." + t, vars);
|
return user.getTranslation("commands.admin.blueprint.management." + t, vars);
|
||||||
}
|
}
|
||||||
|
@ -186,6 +197,10 @@ public class BlueprintManagementPanel {
|
||||||
// Toggle permission - default is always allowed
|
// Toggle permission - default is always allowed
|
||||||
pb.item(39, getPermissionIcon(addon, bb));
|
pb.item(39, getPermissionIcon(addon, bb));
|
||||||
}
|
}
|
||||||
|
if (plugin.getSettings().getIslandNumber() > 1) {
|
||||||
|
// Number of times allowed
|
||||||
|
pb.item(42, getTimesIcon(bb));
|
||||||
|
}
|
||||||
// Preferred slot
|
// Preferred slot
|
||||||
pb.item(40, getSlotIcon(addon, bb));
|
pb.item(40, getSlotIcon(addon, bb));
|
||||||
// Panel has a Back icon.
|
// Panel has a Back icon.
|
||||||
|
@ -198,6 +213,25 @@ public class BlueprintManagementPanel {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PanelItem getTimesIcon(BlueprintBundle bb) {
|
||||||
|
return new PanelItemBuilder().icon(Material.CLOCK).name(t("times"))
|
||||||
|
.description(bb.getTimes() == 0 ? t("unlimited-times")
|
||||||
|
: t("maximum-times", TextVariables.NUMBER, String.valueOf(bb.getTimes())))
|
||||||
|
.clickHandler((panel, u, clickType, slot) -> {
|
||||||
|
// Left click up, right click down
|
||||||
|
u.getPlayer().playSound(u.getLocation(), Sound.UI_BUTTON_CLICK, 1F, 1F);
|
||||||
|
if (clickType == ClickType.LEFT) {
|
||||||
|
bb.setTimes(bb.getTimes() + 1);
|
||||||
|
} else if (clickType == ClickType.RIGHT && bb.getTimes() > 0) {
|
||||||
|
bb.setTimes(bb.getTimes() - 1);
|
||||||
|
}
|
||||||
|
// Save
|
||||||
|
plugin.getBlueprintsManager().saveBlueprintBundle(addon, bb);
|
||||||
|
panel.getInventory().setItem(42, getTimesIcon(bb).getItem());
|
||||||
|
return true;
|
||||||
|
}).build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the preferred slot icon
|
* Gets the preferred slot icon
|
||||||
* @param addon - addon
|
* @param addon - addon
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package world.bentobox.bentobox.panels.customizable;
|
package world.bentobox.bentobox.panels.customizable;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
@ -37,6 +38,94 @@ import world.bentobox.bentobox.util.Util;
|
||||||
*/
|
*/
|
||||||
public class IslandCreationPanel
|
public class IslandCreationPanel
|
||||||
{
|
{
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Constants
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constant is used for button to indicate that it is Blueprint Bundle type.
|
||||||
|
*/
|
||||||
|
private static final String BUNDLES = "BUNDLE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constant is used for button to indicate that it is previous page type.
|
||||||
|
*/
|
||||||
|
private static final String PREVIOUS = "PREVIOUS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constant is used for button to indicate that it is next page type.
|
||||||
|
*/
|
||||||
|
private static final String NEXT = "NEXT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constant is used for indicating that pages should contain numbering.
|
||||||
|
*/
|
||||||
|
private static final String INDEXING = "indexing";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constant stores value for SELECT action that is used in panels.
|
||||||
|
*/
|
||||||
|
private static final String SELECT_ACTION = "SELECT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constant stores value for COMMAND action that is used in panels.
|
||||||
|
*/
|
||||||
|
private static final String COMMANDS_ACTION = "COMMANDS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constant stores value for ERROR message that will be displayed upon failing to run creation commands.
|
||||||
|
*/
|
||||||
|
private static final String ISLAND_CREATION_COMMANDS = "ISLAND_CREATION_COMMANDS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Button reference
|
||||||
|
*/
|
||||||
|
private static final String BUNDLE_BUTTON_REF = "panels.island_creation.buttons.bundle.";
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Variables
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable allows to access plugin object.
|
||||||
|
*/
|
||||||
|
private final BentoBox plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable stores main command that was triggered.
|
||||||
|
*/
|
||||||
|
private final CompositeCommand mainCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable holds user who opens panel. Without it panel cannot be opened.
|
||||||
|
*/
|
||||||
|
private final User user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable holds world where panel is opened. Without it panel cannot be opened.
|
||||||
|
*/
|
||||||
|
private final String mainLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable stores filtered elements.
|
||||||
|
*/
|
||||||
|
private final List<BlueprintBundle> elementList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable holds current pageIndex for multi-page island choosing.
|
||||||
|
*/
|
||||||
|
private int pageIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The world that this command applies to
|
||||||
|
*/
|
||||||
|
private final World world;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true if this panel has been called by a reset command. Changes how the count of used islands is done.
|
||||||
|
*/
|
||||||
|
private final boolean reset;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Constructor
|
// Section: Constructor
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
@ -48,20 +137,22 @@ public class IslandCreationPanel
|
||||||
* @param command CompositeCommand object
|
* @param command CompositeCommand object
|
||||||
* @param label The main command label
|
* @param label The main command label
|
||||||
* @param user User who opens panel
|
* @param user User who opens panel
|
||||||
|
* @param reset
|
||||||
*/
|
*/
|
||||||
private IslandCreationPanel(@NonNull CompositeCommand command,
|
private IslandCreationPanel(@NonNull CompositeCommand command,
|
||||||
@NonNull User user,
|
@NonNull User user, @NonNull String label, boolean reset)
|
||||||
@NonNull String label)
|
|
||||||
{
|
{
|
||||||
this.plugin = BentoBox.getInstance();
|
this.plugin = BentoBox.getInstance();
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.mainLabel = label;
|
this.mainLabel = label;
|
||||||
|
this.world = command.getWorld();
|
||||||
|
this.reset = reset;
|
||||||
|
|
||||||
this.elementList = this.plugin.getBlueprintsManager().getBlueprintBundles(command.getAddon()).values().stream().
|
this.elementList = this.plugin.getBlueprintsManager().getBlueprintBundles(command.getAddon()).values().stream().
|
||||||
sorted(Comparator.comparingInt(BlueprintBundle::getSlot).thenComparing(BlueprintBundle::getUniqueId)).
|
sorted(Comparator.comparingInt(BlueprintBundle::getSlot).thenComparing(BlueprintBundle::getUniqueId))
|
||||||
filter(bundle -> !bundle.isRequirePermission() ||
|
.filter(bundle -> !bundle.isRequirePermission() || this.user
|
||||||
this.user.hasPermission(command.getPermissionPrefix() + "island.create." + bundle.getUniqueId())).
|
.hasPermission(command.getPermissionPrefix() + "island.create." + bundle.getUniqueId()))
|
||||||
toList();
|
.toList();
|
||||||
|
|
||||||
this.mainCommand = command;
|
this.mainCommand = command;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +174,7 @@ public class IslandCreationPanel
|
||||||
{
|
{
|
||||||
this.plugin.logError("There are no available phases for selection!");
|
this.plugin.logError("There are no available phases for selection!");
|
||||||
this.user.sendMessage("no-phases",
|
this.user.sendMessage("no-phases",
|
||||||
TextVariables.GAMEMODE, this.plugin.getDescription().getName());
|
TextVariables.GAMEMODE, this.plugin.getDescription().getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +217,8 @@ public class IslandCreationPanel
|
||||||
private boolean doesCustomPanelExists(GameModeAddon addon, String name)
|
private boolean doesCustomPanelExists(GameModeAddon addon, String name)
|
||||||
{
|
{
|
||||||
return addon.getDataFolder().exists() &&
|
return addon.getDataFolder().exists() &&
|
||||||
new File(addon.getDataFolder(), "panels").exists() &&
|
new File(addon.getDataFolder(), "panels").exists()
|
||||||
new File(addon.getDataFolder(), "panels" + File.separator + name + ".yml").exists();
|
&& new File(addon.getDataFolder(), "panels" + File.separator + name + ".yml").exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +240,7 @@ public class IslandCreationPanel
|
||||||
int size = this.elementList.size();
|
int size = this.elementList.size();
|
||||||
|
|
||||||
if (size <= slot.amountMap().getOrDefault(BUNDLES, 1) ||
|
if (size <= slot.amountMap().getOrDefault(BUNDLES, 1) ||
|
||||||
1.0 * size / slot.amountMap().getOrDefault(BUNDLES, 1) <= this.pageIndex + 1)
|
1.0 * size / slot.amountMap().getOrDefault(BUNDLES, 1) <= this.pageIndex + 1)
|
||||||
{
|
{
|
||||||
// There are no next elements
|
// There are no next elements
|
||||||
return null;
|
return null;
|
||||||
|
@ -179,7 +270,7 @@ public class IslandCreationPanel
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.mainCommand.getWorld(), template.description(),
|
builder.description(this.user.getTranslation(this.mainCommand.getWorld(), template.description(),
|
||||||
TextVariables.NUMBER, String.valueOf(nextPageIndex)));
|
TextVariables.NUMBER, String.valueOf(nextPageIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ClickHandler
|
// Add ClickHandler
|
||||||
|
@ -187,7 +278,7 @@ public class IslandCreationPanel
|
||||||
{
|
{
|
||||||
template.actions().forEach(action -> {
|
template.actions().forEach(action -> {
|
||||||
if ((clickType == action.clickType() ||
|
if ((clickType == action.clickType() ||
|
||||||
action.clickType() == ClickType.UNKNOWN) && NEXT.equalsIgnoreCase(action.actionType()))
|
action.clickType() == ClickType.UNKNOWN) && NEXT.equalsIgnoreCase(action.actionType()))
|
||||||
{
|
{
|
||||||
// Next button ignores click type currently.
|
// Next button ignores click type currently.
|
||||||
this.pageIndex++;
|
this.pageIndex++;
|
||||||
|
@ -202,10 +293,10 @@ public class IslandCreationPanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = template.actions().stream().
|
List<String> tooltips = template.actions().stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null)
|
||||||
map(action -> this.user.getTranslation(this.mainCommand.getWorld(), action.tooltip())).
|
.map(action -> this.user.getTranslation(this.mainCommand.getWorld(), action.tooltip()))
|
||||||
filter(text -> !text.isBlank()).
|
.filter(text -> !text.isBlank())
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
.collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -259,16 +350,15 @@ public class IslandCreationPanel
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.mainCommand.getWorld(), template.description(),
|
builder.description(this.user.getTranslation(this.mainCommand.getWorld(), template.description(),
|
||||||
TextVariables.NUMBER, String.valueOf(previousPageIndex)));
|
TextVariables.NUMBER, String.valueOf(previousPageIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ClickHandler
|
|
||||||
// Add ClickHandler
|
// Add ClickHandler
|
||||||
builder.clickHandler((panel, user, clickType, i) ->
|
builder.clickHandler((panel, user, clickType, i) ->
|
||||||
{
|
{
|
||||||
template.actions().forEach(action -> {
|
template.actions().forEach(action -> {
|
||||||
if ((clickType == action.clickType() ||
|
if ((clickType == action.clickType() ||
|
||||||
action.clickType() == ClickType.UNKNOWN) && PREVIOUS.equalsIgnoreCase(action.actionType()))
|
action.clickType() == ClickType.UNKNOWN) && PREVIOUS.equalsIgnoreCase(action.actionType()))
|
||||||
{
|
{
|
||||||
// Next button ignores click type currently.
|
// Next button ignores click type currently.
|
||||||
this.pageIndex--;
|
this.pageIndex--;
|
||||||
|
@ -283,10 +373,10 @@ public class IslandCreationPanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = template.actions().stream().
|
List<String> tooltips = template.actions().stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null)
|
||||||
map(action -> this.user.getTranslation(this.mainCommand.getWorld(), action.tooltip())).
|
.map(action -> this.user.getTranslation(this.mainCommand.getWorld(), action.tooltip()))
|
||||||
filter(text -> !text.isBlank()).
|
.filter(text -> !text.isBlank())
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
.collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -310,7 +400,7 @@ public class IslandCreationPanel
|
||||||
{
|
{
|
||||||
if (this.elementList.isEmpty())
|
if (this.elementList.isEmpty())
|
||||||
{
|
{
|
||||||
// Does not contain any sticks.
|
// Does not contain any blueprints.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,9 +422,8 @@ public class IslandCreationPanel
|
||||||
{
|
{
|
||||||
// Try to find bundle with requested ID. if not found, use already collected bundle.
|
// Try to find bundle with requested ID. if not found, use already collected bundle.
|
||||||
blueprintBundle = this.elementList.stream().
|
blueprintBundle = this.elementList.stream().
|
||||||
filter(bundle -> bundle.getUniqueId().equals(template.dataMap().get("unique_id"))).
|
filter(bundle -> bundle.getUniqueId().equals(template.dataMap().get("unique_id"))).findFirst()
|
||||||
findFirst().
|
.orElse(blueprintBundle);
|
||||||
orElse(blueprintBundle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.createBundleButton(template, blueprintBundle);
|
return this.createBundleButton(template, blueprintBundle);
|
||||||
|
@ -359,8 +448,6 @@ public class IslandCreationPanel
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String reference = "panels.island_creation.buttons.bundle.";
|
|
||||||
|
|
||||||
// Get settings for island.
|
// Get settings for island.
|
||||||
PanelItemBuilder builder = new PanelItemBuilder();
|
PanelItemBuilder builder = new PanelItemBuilder();
|
||||||
|
|
||||||
|
@ -376,72 +463,92 @@ public class IslandCreationPanel
|
||||||
if (template.title() != null)
|
if (template.title() != null)
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(this.mainCommand.getWorld(), template.title(),
|
builder.name(this.user.getTranslation(this.mainCommand.getWorld(), template.title(),
|
||||||
TextVariables.NAME, bundle.getDisplayName()));
|
TextVariables.NAME, bundle.getDisplayName()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(reference + "name",
|
builder.name(this.user.getTranslation(BUNDLE_BUTTON_REF + "name",
|
||||||
TextVariables.NAME, bundle.getDisplayName()));
|
TextVariables.NAME, bundle.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.mainCommand.getWorld(), template.description(),
|
builder.description(this.user.getTranslation(this.mainCommand.getWorld(), template.description(),
|
||||||
TextVariables.DESCRIPTION, String.join("\n", bundle.getDescription())));
|
TextVariables.DESCRIPTION, String.join("\n", bundle.getDescription())));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(reference + "description",
|
builder.description(this.user.getTranslation(BUNDLE_BUTTON_REF + "description",
|
||||||
TextVariables.DESCRIPTION, String.join("\n", bundle.getDescription())));
|
TextVariables.DESCRIPTION, String.join("\n", bundle.getDescription())));
|
||||||
|
}
|
||||||
|
boolean usedUp = false;
|
||||||
|
if (plugin.getSettings().getIslandNumber() > 1) {
|
||||||
|
// Show how many times this bundle can be used
|
||||||
|
int maxTimes = bundle.getTimes();
|
||||||
|
if (maxTimes > 0) {
|
||||||
|
long uses = plugin.getIslands().getIslands(world, user).stream()
|
||||||
|
.filter(is -> is.getMetaData("bundle")
|
||||||
|
.map(mdv -> bundle.getDisplayName().equalsIgnoreCase(mdv.asString())
|
||||||
|
&& !(reset && is.isPrimary())) // If this is a reset, then ignore the use of the island being reset
|
||||||
|
.orElse(false))
|
||||||
|
.count();
|
||||||
|
builder.description(this.user.getTranslation(BUNDLE_BUTTON_REF + "uses", TextVariables.NUMBER,
|
||||||
|
String.valueOf(uses), "[max]", String.valueOf(maxTimes)));
|
||||||
|
if (uses >= maxTimes) {
|
||||||
|
usedUp = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
builder.description(this.user.getTranslation(BUNDLE_BUTTON_REF + "unlimited"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ItemTemplateRecord.ActionRecords> actions = template.actions().stream().
|
if (usedUp) {
|
||||||
filter(action -> SELECT_ACTION.equalsIgnoreCase(action.actionType()) ||
|
if (plugin.getSettings().isHideUsedBlueprints()) {
|
||||||
COMMANDS_ACTION.equalsIgnoreCase(action.actionType())).
|
// Do not show used up blueprints
|
||||||
toList();
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
List<ItemTemplateRecord.ActionRecords> actions = template.actions().stream()
|
||||||
|
.filter(action -> SELECT_ACTION.equalsIgnoreCase(action.actionType())
|
||||||
|
|| COMMANDS_ACTION.equalsIgnoreCase(action.actionType()))
|
||||||
|
.toList();
|
||||||
|
// Add ClickHandler
|
||||||
|
builder.clickHandler((panel, user, clickType, i) -> {
|
||||||
|
actions.forEach(action -> {
|
||||||
|
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
|
||||||
|
{
|
||||||
|
if (SELECT_ACTION.equalsIgnoreCase(action.actionType())) {
|
||||||
|
user.closeInventory();
|
||||||
|
this.mainCommand.execute(user, this.mainLabel,
|
||||||
|
Collections.singletonList(bundle.getUniqueId()));
|
||||||
|
} else if (COMMANDS_ACTION.equalsIgnoreCase(action.actionType())) {
|
||||||
|
Util.runCommands(user,
|
||||||
|
Arrays.stream(action.content()
|
||||||
|
.replaceAll(Pattern.quote(TextVariables.LABEL),
|
||||||
|
this.mainCommand.getTopLabel())
|
||||||
|
.split("\n")).toList(),
|
||||||
|
ISLAND_CREATION_COMMANDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add ClickHandler
|
// Always return true.
|
||||||
builder.clickHandler((panel, user, clickType, i) ->
|
return true;
|
||||||
{
|
|
||||||
actions.forEach(action -> {
|
|
||||||
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
|
|
||||||
{
|
|
||||||
if (SELECT_ACTION.equalsIgnoreCase(action.actionType()))
|
|
||||||
{
|
|
||||||
user.closeInventory();
|
|
||||||
this.mainCommand.execute(user, this.mainLabel, Collections.singletonList(bundle.getUniqueId()));
|
|
||||||
}
|
|
||||||
else if (COMMANDS_ACTION.equalsIgnoreCase(action.actionType()))
|
|
||||||
{
|
|
||||||
Util.runCommands(user,
|
|
||||||
Arrays.stream(action.content().
|
|
||||||
replaceAll(Pattern.quote(TextVariables.LABEL), this.mainCommand.getTopLabel()).
|
|
||||||
split("\n")).
|
|
||||||
toList(),
|
|
||||||
ISLAND_CREATION_COMMANDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Always return true.
|
// Collect tooltips.
|
||||||
return true;
|
List<String> tooltips = actions.stream().filter(action -> action.tooltip() != null)
|
||||||
});
|
.map(action -> this.user.getTranslation(this.mainCommand.getWorld(), action.tooltip()))
|
||||||
|
.filter(text -> !text.isBlank())
|
||||||
|
.collect(Collectors.toCollection(() -> new ArrayList<>(actions.size())));
|
||||||
|
|
||||||
// Collect tooltips.
|
// Add tooltips.
|
||||||
List<String> tooltips = actions.stream().
|
if (!tooltips.isEmpty()) {
|
||||||
filter(action -> action.tooltip() != null).
|
// Empty line and tooltips.
|
||||||
map(action -> this.user.getTranslation(this.mainCommand.getWorld(), action.tooltip())).
|
builder.description("");
|
||||||
filter(text -> !text.isBlank()).
|
builder.description(tooltips);
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(actions.size())));
|
}
|
||||||
|
|
||||||
// Add tooltips.
|
|
||||||
if (!tooltips.isEmpty())
|
|
||||||
{
|
|
||||||
// Empty line and tooltips.
|
|
||||||
builder.description("");
|
|
||||||
builder.description(tooltips);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,87 +565,13 @@ public class IslandCreationPanel
|
||||||
* @param command CompositeCommand object
|
* @param command CompositeCommand object
|
||||||
* @param label The main command label
|
* @param label The main command label
|
||||||
* @param user User who opens panel
|
* @param user User who opens panel
|
||||||
|
* @param reset true if this is an island reset
|
||||||
*/
|
*/
|
||||||
public static void openPanel(@NonNull CompositeCommand command,
|
public static void openPanel(@NonNull CompositeCommand command,
|
||||||
@NonNull User user,
|
@NonNull User user, @NonNull String label, boolean reset)
|
||||||
@NonNull String label)
|
|
||||||
{
|
{
|
||||||
new IslandCreationPanel(command, user, label).build();
|
new IslandCreationPanel(command, user, label, reset).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
// Section: Constants
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant is used for button to indicate that it is Blueprint Bundle type.
|
|
||||||
*/
|
|
||||||
private static final String BUNDLES = "BUNDLE";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant is used for button to indicate that it is previous page type.
|
|
||||||
*/
|
|
||||||
private static final String PREVIOUS = "PREVIOUS";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant is used for button to indicate that it is next page type.
|
|
||||||
*/
|
|
||||||
private static final String NEXT = "NEXT";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant is used for indicating that pages should contain numbering.
|
|
||||||
*/
|
|
||||||
private static final String INDEXING = "indexing";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant stores value for SELECT action that is used in panels.
|
|
||||||
*/
|
|
||||||
private static final String SELECT_ACTION = "SELECT";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant stores value for COMMAND action that is used in panels.
|
|
||||||
*/
|
|
||||||
private static final String COMMANDS_ACTION = "COMMANDS";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant stores value for ERROR message that will be displayed upon failing to run creation commands.
|
|
||||||
*/
|
|
||||||
private static final String ISLAND_CREATION_COMMANDS = "ISLAND_CREATION_COMMANDS";
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
// Section: Variables
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This variable allows to access plugin object.
|
|
||||||
*/
|
|
||||||
private final BentoBox plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This variable stores main command that was triggered.
|
|
||||||
*/
|
|
||||||
private final CompositeCommand mainCommand;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This variable holds user who opens panel. Without it panel cannot be opened.
|
|
||||||
*/
|
|
||||||
private final User user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This variable holds world where panel is opened. Without it panel cannot be opened.
|
|
||||||
*/
|
|
||||||
private final String mainLabel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This variable stores filtered elements.
|
|
||||||
*/
|
|
||||||
private final List<BlueprintBundle> elementList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This variable holds current pageIndex for multi-page island choosing.
|
|
||||||
*/
|
|
||||||
private int pageIndex;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ commands:
|
||||||
&a Green Particles &f show the default protected range if the island protection range differs from it.
|
&a Green Particles &f show the default protected range if the island protection range differs from it.
|
||||||
showing: '&2 Showing range indicators'
|
showing: '&2 Showing range indicators'
|
||||||
set:
|
set:
|
||||||
parameters: <player> <range>
|
parameters: <player> <range> [island location]
|
||||||
description: sets the island protected range
|
description: sets the island protected range
|
||||||
success: '&a Set island protection range to &b [number]&a .'
|
success: '&a Set island protection range to &b [number]&a .'
|
||||||
reset:
|
reset:
|
||||||
|
@ -175,12 +175,12 @@ commands:
|
||||||
success: '&a Reset island protection range to &b [number]&a .'
|
success: '&a Reset island protection range to &b [number]&a .'
|
||||||
add:
|
add:
|
||||||
description: increases the island protected range
|
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
|
success: '&a Successfully increased &b [name]&a ''s island protected range
|
||||||
to &b [total] &7 (&b +[number]&7 )&a .'
|
to &b [total] &7 (&b +[number]&7 )&a .'
|
||||||
remove:
|
remove:
|
||||||
description: decreases the island protected range
|
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
|
success: '&a Successfully decreased &b [name]&a ''s island protected range
|
||||||
to &b [total] &7 (&b -[number]&7 )&a .'
|
to &b [total] &7 (&b -[number]&7 )&a .'
|
||||||
register:
|
register:
|
||||||
|
@ -414,6 +414,12 @@ commands:
|
||||||
slot-instructions: |
|
slot-instructions: |
|
||||||
&a Left click to increment
|
&a Left click to increment
|
||||||
&a Right click to decrement
|
&a Right click to decrement
|
||||||
|
times: |
|
||||||
|
&a Max concurrent uses by player
|
||||||
|
&a Left click to increment
|
||||||
|
&a Right click to decrement
|
||||||
|
unlimited-times: &a Unlimited
|
||||||
|
maximum-times: &a Max [number] times
|
||||||
resetflags:
|
resetflags:
|
||||||
parameters: '[flag]'
|
parameters: '[flag]'
|
||||||
description: Reset all islands to default flag settings in config.yml
|
description: Reset all islands to default flag settings in config.yml
|
||||||
|
@ -547,6 +553,7 @@ commands:
|
||||||
an administrator.'
|
an administrator.'
|
||||||
creating-island: '&a Finding a spot for your island...'
|
creating-island: '&a Finding a spot for your island...'
|
||||||
you-cannot-make: '&c You cannot make any more islands!'
|
you-cannot-make: '&c You cannot make any more islands!'
|
||||||
|
max-uses: "&c You cannot make any more of that type of island!"
|
||||||
you-cannot-make-team: '&c Team members cannot make islands in the same world as their team island.'
|
you-cannot-make-team: '&c Team members cannot make islands in the same world as their team island.'
|
||||||
pasting:
|
pasting:
|
||||||
estimated-time: '&a Estimated time: &b [number] &a seconds.'
|
estimated-time: '&a Estimated time: &b [number] &a seconds.'
|
||||||
|
@ -678,8 +685,10 @@ commands:
|
||||||
already-has-rank: '&c Player already has a rank!'
|
already-has-rank: '&c Player already has a rank!'
|
||||||
you-are-a-coop-member: '&2 You were cooped by &b[name]&a.'
|
you-are-a-coop-member: '&2 You were cooped by &b[name]&a.'
|
||||||
success: '&a You cooped &b [name]&a.'
|
success: '&a You cooped &b [name]&a.'
|
||||||
name-has-invited-you: '&a [name] has invited you to join as a coop member
|
name-has-invited-you: |
|
||||||
of their island.'
|
&a [name] has invited you
|
||||||
|
&a to join as a coop member
|
||||||
|
&a of their island.
|
||||||
uncoop:
|
uncoop:
|
||||||
description: remove a coop rank from player
|
description: remove a coop rank from player
|
||||||
parameters: <player>
|
parameters: <player>
|
||||||
|
@ -696,8 +705,10 @@ commands:
|
||||||
description: give a player trusted rank on your island
|
description: give a player trusted rank on your island
|
||||||
parameters: <player>
|
parameters: <player>
|
||||||
trust-in-yourself: '&c Trust in yourself!'
|
trust-in-yourself: '&c Trust in yourself!'
|
||||||
name-has-invited-you: '&a [name] has invited you to join as a trusted member
|
name-has-invited-you: |
|
||||||
of their island.'
|
&a [name] has invited you
|
||||||
|
&a to join as a trusted member
|
||||||
|
&a of their island.
|
||||||
player-already-trusted: '&c Player is already trusted!'
|
player-already-trusted: '&c Player is already trusted!'
|
||||||
you-are-trusted: '&2 You are trusted by &b [name]&a !'
|
you-are-trusted: '&2 You are trusted by &b [name]&a !'
|
||||||
success: '&a You trusted &b [name]&a .'
|
success: '&a You trusted &b [name]&a .'
|
||||||
|
@ -714,10 +725,14 @@ commands:
|
||||||
description: invite a player to join your island
|
description: invite a player to join your island
|
||||||
invitation-sent: '&a Invitation sent to &b[name]&a.'
|
invitation-sent: '&a Invitation sent to &b[name]&a.'
|
||||||
removing-invite: '&c Removing invite.'
|
removing-invite: '&c Removing invite.'
|
||||||
name-has-invited-you: '&a [name] has invited you to join their island.'
|
name-has-invited-you: |
|
||||||
|
&a [name] has invited you
|
||||||
|
&a to join their island.
|
||||||
to-accept-or-reject: '&a Do /[label] team accept to accept, or /[label] team
|
to-accept-or-reject: '&a Do /[label] team accept to accept, or /[label] team
|
||||||
reject to reject'
|
reject to reject'
|
||||||
you-will-lose-your-island: '&c WARNING! You will lose all your islands if you accept!'
|
you-will-lose-your-island: |
|
||||||
|
&c WARNING! You will lose all
|
||||||
|
&c your islands if you accept!
|
||||||
gui:
|
gui:
|
||||||
titles:
|
titles:
|
||||||
team-invite-panel: "Invite Players"
|
team-invite-panel: "Invite Players"
|
||||||
|
@ -758,9 +773,10 @@ commands:
|
||||||
you-joined-island: '&a You joined an island! Use &b/[label] team &a to see
|
you-joined-island: '&a You joined an island! Use &b/[label] team &a to see
|
||||||
the other members.'
|
the other members.'
|
||||||
name-joined-your-island: '&a [name] joined your island!'
|
name-joined-your-island: '&a [name] joined your island!'
|
||||||
confirmation: |-
|
confirmation: |
|
||||||
&c Are you sure you want to accept this invite?
|
&c Are you sure you
|
||||||
&c&l You will &n LOSE ALL &r&c&l your islands!
|
&c want to accept this
|
||||||
|
&c invite?
|
||||||
reject:
|
reject:
|
||||||
description: reject an invitation
|
description: reject an invitation
|
||||||
you-rejected-invite: '&a You rejected the invitation to join an island.'
|
you-rejected-invite: '&a You rejected the invitation to join an island.'
|
||||||
|
@ -1811,6 +1827,8 @@ panels:
|
||||||
name: "&l [name]"
|
name: "&l [name]"
|
||||||
description: |-
|
description: |-
|
||||||
[description]
|
[description]
|
||||||
|
uses: "&a Used [number]/[max]"
|
||||||
|
unlimited: "&a Unlimited uses allowed"
|
||||||
# The section of translations used in Language Panel
|
# The section of translations used in Language Panel
|
||||||
language:
|
language:
|
||||||
title: "&2&l Select your language"
|
title: "&2&l Select your language"
|
||||||
|
|
|
@ -121,6 +121,7 @@ public class AdminDeleteCommandTest {
|
||||||
|
|
||||||
// Island
|
// Island
|
||||||
when(island.getOwner()).thenReturn(uuid);
|
when(island.getOwner()).thenReturn(uuid);
|
||||||
|
when(island.hasTeam()).thenReturn(true);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||||
|
@ -190,6 +191,7 @@ public class AdminDeleteCommandTest {
|
||||||
public void testExecuteOwner() {
|
public void testExecuteOwner() {
|
||||||
|
|
||||||
when(im.inTeam(any(),any())).thenReturn(true);
|
when(im.inTeam(any(),any())).thenReturn(true);
|
||||||
|
when(island.inTeam(notUUID)).thenReturn(true);
|
||||||
//when(im.getOwner(any(), any())).thenReturn(notUUID);
|
//when(im.getOwner(any(), any())).thenReturn(notUUID);
|
||||||
String[] name = {"tastybento"};
|
String[] name = {"tastybento"};
|
||||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
|
@ -203,6 +205,7 @@ public class AdminDeleteCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testcanExecuteSuccessUUID() {
|
public void testcanExecuteSuccessUUID() {
|
||||||
|
when(island.hasTeam()).thenReturn(false);
|
||||||
when(im.inTeam(any(), any())).thenReturn(false);
|
when(im.inTeam(any(), any())).thenReturn(false);
|
||||||
//when(im.getOwner(any(), any())).thenReturn(uuid);
|
//when(im.getOwner(any(), any())).thenReturn(uuid);
|
||||||
Island is = mock(Island.class);
|
Island is = mock(Island.class);
|
||||||
|
@ -243,6 +246,7 @@ public class AdminDeleteCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteSuccess() {
|
public void testCanExecuteSuccess() {
|
||||||
|
when(island.hasTeam()).thenReturn(false);
|
||||||
when(im.inTeam(any(), any())).thenReturn(false);
|
when(im.inTeam(any(), any())).thenReturn(false);
|
||||||
//when(im.getOwner(any(), any())).thenReturn(uuid);
|
//when(im.getOwner(any(), any())).thenReturn(uuid);
|
||||||
Island is = mock(Island.class);
|
Island is = mock(Island.class);
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package world.bentobox.bentobox.api.commands.admin.range;
|
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.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -9,14 +13,18 @@ import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -56,6 +64,8 @@ public class AdminRangeSetCommandTest {
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
@Mock
|
@Mock
|
||||||
private PluginManager pim;
|
private PluginManager pim;
|
||||||
|
@Mock
|
||||||
|
private @NonNull Location location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -92,23 +102,25 @@ public class AdminRangeSetCommandTest {
|
||||||
|
|
||||||
// Island World Manager
|
// Island World Manager
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
when(iwm.getIslandProtectionRange(Mockito.any())).thenReturn(200);
|
when(iwm.getIslandProtectionRange(any())).thenReturn(200);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
im = mock(IslandsManager.class);
|
im = mock(IslandsManager.class);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||||
Island island = mock(Island.class);
|
Island island = mock(Island.class);
|
||||||
when(island.getRange()).thenReturn(50);
|
when(island.getRange()).thenReturn(50);
|
||||||
when(island.getProtectionRange()).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);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
pm = mock(PlayersManager.class);
|
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);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
|
@ -122,11 +134,11 @@ public class AdminRangeSetCommandTest {
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
Answer<String> answer = invocation -> invocation.getArgument(1, String.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);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -137,69 +149,72 @@ public class AdminRangeSetCommandTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* 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
|
@Test
|
||||||
public void testExecuteConsoleNoArgs() {
|
public void testExecuteConsoleNoArgs() {
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
CommandSender sender = mock(CommandSender.class);
|
CommandSender sender = mock(CommandSender.class);
|
||||||
User console = User.getInstance(sender);
|
User console = User.getInstance(sender);
|
||||||
arc.execute(console, "", new ArrayList<>());
|
assertFalse(arc.canExecute(console, "", new ArrayList<>()));
|
||||||
// Show help
|
// Show help
|
||||||
Mockito.verify(sender).sendMessage("commands.help.header");
|
verify(sender).sendMessage("commands.help.header");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* 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
|
@Test
|
||||||
public void testExecutePlayerNoArgs() {
|
public void testExecutePlayerNoArgs() {
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
arc.execute(user, "", new ArrayList<>());
|
assertFalse(arc.canExecute(user, "", List.of()));
|
||||||
// Show help
|
// Show help
|
||||||
Mockito.verify(user).sendMessage("commands.help.header", "[label]", "BSkyBlock");
|
verify(user).sendMessage("commands.help.header", "[label]", "BSkyBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* 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
|
@Test
|
||||||
public void testExecuteUnknownPlayer() {
|
public void testExecuteUnknownPlayer() {
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
String[] args = { "tastybento", "100" };
|
String[] args = { "tastybento", "100" };
|
||||||
arc.execute(user, "", Arrays.asList(args));
|
assertFalse(arc.canExecute(user, "", Arrays.asList(args)));
|
||||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", args[0]);
|
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
|
@Test
|
||||||
public void testExecuteKnownPlayerNotOwnerNoTeam() {
|
public void testExecuteKnownPlayerNotOwnerNoTeam() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
when(im.getOwnedIslands(any(), any(UUID.class))).thenReturn(Set.of());
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("100");
|
args.add("100");
|
||||||
arc.execute(user, "", args);
|
assertFalse(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("general.errors.player-has-no-island");
|
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
|
@Test
|
||||||
public void testExecuteKnownPlayerNotOwnerButInTeam() {
|
public void testExecuteKnownPlayerNotOwnerButInTeam() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
when(im.getOwnedIslands(any(), any(UUID.class))).thenReturn(Set.of());
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("100");
|
args.add("100");
|
||||||
arc.execute(user, "", args);
|
assertFalse(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user, never()).sendMessage("general.errors.player-has-no-island");
|
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,41 +222,42 @@ public class AdminRangeSetCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteTooHigh() {
|
public void testExecuteTooHigh() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("1000");
|
args.add("1000");
|
||||||
arc.execute(user, "", args);
|
assertTrue(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("commands.admin.range.invalid-value.too-high", TextVariables.NUMBER, "100");
|
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
|
@Test
|
||||||
public void testExecuteNotANumber() {
|
public void testExecuteNotANumber() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("NAN");
|
args.add("NAN");
|
||||||
arc.execute(user, "", args);
|
assertFalse(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "NAN");
|
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()
|
@Test()
|
||||||
public void testExecuteDoubleNumber() {
|
public void testExecuteDoubleNumber() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("3.141592654");
|
args.add("3.141592654");
|
||||||
arc.execute(user, "", args);
|
assertFalse(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "3.141592654");
|
verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "3.141592654");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -249,13 +265,14 @@ public class AdminRangeSetCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteZero() {
|
public void testExecuteZero() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("0");
|
args.add("0");
|
||||||
arc.execute(user, "", args);
|
assertTrue(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("commands.admin.range.invalid-value.too-low", TextVariables.NUMBER, "0");
|
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
|
@Test
|
||||||
public void testExecuteNegNumber() {
|
public void testExecuteNegNumber() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("-437645");
|
args.add("-437645");
|
||||||
arc.execute(user, "", args);
|
assertFalse(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "-437645");
|
verify(user).sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, "-437645");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -277,13 +294,14 @@ public class AdminRangeSetCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteSame() {
|
public void testExecuteSame() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("50");
|
args.add("50");
|
||||||
arc.execute(user, "", args);
|
assertTrue(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("commands.admin.range.invalid-value.same-as-before", TextVariables.NUMBER, "50");
|
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
|
@Test
|
||||||
public void testExecute() {
|
public void testExecute() {
|
||||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||||
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("tastybento");
|
args.add("tastybento");
|
||||||
args.add("48");
|
args.add("48");
|
||||||
arc.execute(user, "", args);
|
assertTrue(arc.canExecute(user, "", args));
|
||||||
Mockito.verify(user).sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, "48");
|
assertTrue(arc.execute(user, "", args));
|
||||||
|
verify(user).sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, "48");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -31,7 +32,9 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.TestWorldSettings;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
@ -123,6 +126,9 @@ public class AdminTeamAddCommandTest {
|
||||||
// Island World Manager
|
// Island World Manager
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
|
@NonNull
|
||||||
|
WorldSettings ws = new TestWorldSettings();
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(ws);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
|
@ -187,7 +193,7 @@ public class AdminTeamAddCommandTest {
|
||||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||||
|
|
||||||
when(im.inTeam(any(), eq(notUUID))).thenReturn(true);
|
when(im.inTeam(any(), eq(notUUID))).thenReturn(true);
|
||||||
|
when(island.inTeam(notUUID)).thenReturn(true);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||||
verify(user).sendMessage(eq("commands.island.team.invite.errors.already-on-team"));
|
verify(user).sendMessage(eq("commands.island.team.invite.errors.already-on-team"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ public class AdminTeamDisbandCommandTest {
|
||||||
public void testExecutePlayerNotInTeam() {
|
public void testExecutePlayerNotInTeam() {
|
||||||
when(Util.getUUID("tastybento")).thenReturn(notUUID);
|
when(Util.getUUID("tastybento")).thenReturn(notUUID);
|
||||||
assertFalse(itl.canExecute(user, itl.getLabel(), List.of("tastybento")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), List.of("tastybento")));
|
||||||
verify(user).sendMessage("general.errors.player-is-not-owner", "[name]", "tastybento");
|
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -228,6 +228,7 @@ public class IslandBanCommandTest extends RanksManagerBeforeClassTest {
|
||||||
UUID teamMate = UUID.randomUUID();
|
UUID teamMate = UUID.randomUUID();
|
||||||
when(pm.getUUID(anyString())).thenReturn(teamMate);
|
when(pm.getUUID(anyString())).thenReturn(teamMate);
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid, teamMate));
|
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid, teamMate));
|
||||||
|
when(island.inTeam(teamMate)).thenReturn(true);
|
||||||
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
||||||
verify(user).sendMessage("commands.island.ban.cannot-ban-member");
|
verify(user).sendMessage("commands.island.ban.cannot-ban-member");
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,6 +167,10 @@ public class IslandCreateCommandTest {
|
||||||
when(builder.build()).thenReturn(mock(Island.class));
|
when(builder.build()).thenReturn(mock(Island.class));
|
||||||
|
|
||||||
// Bundles manager
|
// Bundles manager
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
Map<String, BlueprintBundle> map = new HashMap<>();
|
||||||
|
when(bpm.getBlueprintBundles(addon)).thenReturn(map);
|
||||||
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
||||||
|
|
||||||
// IslandCreationPanel
|
// IslandCreationPanel
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -115,7 +114,7 @@ public class IslandDeletehomeCommandTest extends RanksManagerBeforeClassTest {
|
||||||
when(island.onIsland(any())).thenReturn(true);
|
when(island.onIsland(any())).thenReturn(true);
|
||||||
when(im.getIsland(world, uuid)).thenReturn(island);
|
when(im.getIsland(world, uuid)).thenReturn(island);
|
||||||
when(im.getIsland(world, user)).thenReturn(island);
|
when(im.getIsland(world, user)).thenReturn(island);
|
||||||
when(im.getIslands(world, uuid)).thenReturn(Set.of(island));
|
when(im.getIslands(world, uuid)).thenReturn(List.of(island));
|
||||||
@NotNull
|
@NotNull
|
||||||
Map<String, Location> homeMap = new HashMap<>();
|
Map<String, Location> homeMap = new HashMap<>();
|
||||||
homeMap.put("Home", null);
|
homeMap.put("Home", null);
|
||||||
|
|
|
@ -40,6 +40,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.TestWorldSettings;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
@ -140,6 +141,8 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||||
|
|
||||||
// IWM friendly name
|
// IWM friendly name
|
||||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
|
TestWorldSettings worldSettings = new TestWorldSettings();
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(worldSettings);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Server and Plugin Manager for events
|
// Server and Plugin Manager for events
|
||||||
|
@ -268,6 +271,7 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||||
UUID target = UUID.randomUUID();
|
UUID target = UUID.randomUUID();
|
||||||
when(pm.getUUID(anyString())).thenReturn(target);
|
when(pm.getUUID(anyString())).thenReturn(target);
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(target));
|
when(island.getMemberSet()).thenReturn(ImmutableSet.of(target));
|
||||||
|
when(island.inTeam(target)).thenReturn(true);
|
||||||
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
|
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
|
||||||
verify(user).sendMessage("commands.island.expel.cannot-expel-member");
|
verify(user).sendMessage("commands.island.expel.cannot-expel-member");
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class IslandGoCommandTest {
|
||||||
when(ic.getWorld()).thenReturn(world);
|
when(ic.getWorld()).thenReturn(world);
|
||||||
|
|
||||||
// Player has island by default
|
// Player has island by default
|
||||||
when(im.getIslands(world, uuid)).thenReturn(Set.of(island));
|
when(im.getIslands(world, uuid)).thenReturn(List.of(island));
|
||||||
when(im.hasIsland(world, uuid)).thenReturn(true);
|
when(im.hasIsland(world, uuid)).thenReturn(true);
|
||||||
// when(im.isOwner(world, uuid)).thenReturn(true);
|
// when(im.isOwner(world, uuid)).thenReturn(true);
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
@ -204,7 +204,7 @@ public class IslandGoCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteNoArgsNoIsland() {
|
public void testExecuteNoArgsNoIsland() {
|
||||||
when(im.getIslands(world, uuid)).thenReturn(Set.of());
|
when(im.getIslands(world, uuid)).thenReturn(List.of());
|
||||||
assertFalse(igc.canExecute(user, igc.getLabel(), Collections.emptyList()));
|
assertFalse(igc.canExecute(user, igc.getLabel(), Collections.emptyList()));
|
||||||
verify(player).sendMessage("general.errors.no-island");
|
verify(player).sendMessage("general.errors.no-island");
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@ import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -189,7 +189,7 @@ public class IslandHomesCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecute() {
|
public void testCanExecute() {
|
||||||
when(im.getIslands(world, user)).thenReturn(Set.of(island));
|
when(im.getIslands(world, user)).thenReturn(List.of(island));
|
||||||
IslandHomesCommand isc = new IslandHomesCommand(ic);
|
IslandHomesCommand isc = new IslandHomesCommand(ic);
|
||||||
assertTrue(isc.canExecute(user, "island", Collections.emptyList()));
|
assertTrue(isc.canExecute(user, "island", Collections.emptyList()));
|
||||||
verify(user, never()).sendMessage("general.errors.no-island");
|
verify(user, never()).sendMessage("general.errors.no-island");
|
||||||
|
@ -200,7 +200,7 @@ public class IslandHomesCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteUserStringListOfString() {
|
public void testExecuteUserStringListOfString() {
|
||||||
when(im.getIslands(world, user)).thenReturn(Set.of(island));
|
when(im.getIslands(world, user)).thenReturn(List.of(island));
|
||||||
IslandHomesCommand isc = new IslandHomesCommand(ic);
|
IslandHomesCommand isc = new IslandHomesCommand(ic);
|
||||||
assertTrue(isc.canExecute(user, "island", Collections.emptyList()));
|
assertTrue(isc.canExecute(user, "island", Collections.emptyList()));
|
||||||
assertTrue(isc.execute(user, "island", Collections.emptyList()));
|
assertTrue(isc.execute(user, "island", Collections.emptyList()));
|
||||||
|
|
|
@ -14,7 +14,7 @@ import static org.mockito.Mockito.when;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -104,8 +104,7 @@ public class IslandSethomeCommandTest {
|
||||||
|
|
||||||
// Island for player to begin with
|
// Island for player to begin with
|
||||||
when(im.hasIsland(world, user)).thenReturn(true);
|
when(im.hasIsland(world, user)).thenReturn(true);
|
||||||
// when(im.isOwner(world, uuid)).thenReturn(true);
|
when(im.getIslands(world, user)).thenReturn(List.of(island));
|
||||||
when(im.getIslands(world, user)).thenReturn(Set.of(island));
|
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
|
|
|
@ -77,7 +77,6 @@ public class IslandSetnameCommandTest {
|
||||||
private IslandSetnameCommand isc;
|
private IslandSetnameCommand isc;
|
||||||
@Mock
|
@Mock
|
||||||
private @NonNull World world;
|
private @NonNull World world;
|
||||||
private RanksManager rm;
|
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
@Mock
|
@Mock
|
||||||
private PluginManager pim;
|
private PluginManager pim;
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.TestWorldSettings;
|
||||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
|
@ -142,6 +143,8 @@ public class IslandTeamInviteAcceptCommandTest {
|
||||||
// IWM friendly name
|
// IWM friendly name
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
|
TestWorldSettings worldSettings = new TestWorldSettings();
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(worldSettings);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Invite
|
// Invite
|
||||||
|
|
|
@ -39,7 +39,9 @@ import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.TestWorldSettings;
|
||||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -170,6 +172,9 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
|
||||||
// IWM friendly name
|
// IWM friendly name
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
|
@NonNull
|
||||||
|
WorldSettings ws = new TestWorldSettings();
|
||||||
|
when(iwm.getWorldSettings(world)).thenReturn(ws);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Parent command
|
// Parent command
|
||||||
|
|
|
@ -211,7 +211,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
||||||
when(pm.getName(notUUID)).thenReturn("poslovitch");
|
when(pm.getName(notUUID)).thenReturn("poslovitch");
|
||||||
|
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
||||||
|
when(island.inTeam(notUUID)).thenReturn(true);
|
||||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||||
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
|
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
|
||||||
|
@ -229,7 +229,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
||||||
when(pm.getName(notUUID)).thenReturn("poslovitch");
|
when(pm.getName(notUUID)).thenReturn("poslovitch");
|
||||||
|
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
||||||
|
when(island.inTeam(notUUID)).thenReturn(true);
|
||||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||||
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
|
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
|
||||||
|
@ -250,7 +250,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
||||||
|
|
||||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
||||||
|
|
||||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
||||||
|
|
||||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||||
verify(target, never()).getInventory();
|
verify(target, never()).getInventory();
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
||||||
|
|
||||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||||
verify(target, Mockito.never()).getInventory();
|
verify(target, Mockito.never()).getInventory();
|
||||||
verify(pm).cleanLeavingPlayer(any(), any(User.class), eq(true), eq(island));
|
verify(pm).cleanLeavingPlayer(any(), any(User.class), eq(true), eq(island));
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.TestWorldSettings;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
@ -119,6 +120,11 @@ public class IslandTeamPromoteCommandTest extends RanksManagerBeforeClassTest {
|
||||||
|
|
||||||
// In team
|
// In team
|
||||||
when(im.inTeam(world, uuid)).thenReturn(true);
|
when(im.inTeam(world, uuid)).thenReturn(true);
|
||||||
|
when(island.inTeam(uuid)).thenReturn(true);
|
||||||
|
|
||||||
|
// IWM
|
||||||
|
TestWorldSettings worldSettings = new TestWorldSettings();
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(worldSettings);
|
||||||
|
|
||||||
// Ranks
|
// Ranks
|
||||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.SUB_OWNER_RANK); // Allow sub owners
|
when(island.getRankCommand(anyString())).thenReturn(RanksManager.SUB_OWNER_RANK); // Allow sub owners
|
||||||
|
|
|
@ -38,6 +38,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.TestWorldSettings;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
@ -119,7 +120,8 @@ public class IslandTeamSetownerCommandTest {
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
when(im.inTeam(world, uuid)).thenReturn(true);
|
||||||
|
when(island.inTeam(uuid)).thenReturn(true);
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
// Server & Scheduler
|
// Server & Scheduler
|
||||||
|
@ -128,6 +130,8 @@ public class IslandTeamSetownerCommandTest {
|
||||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||||
|
|
||||||
// Island World Manager
|
// Island World Manager
|
||||||
|
TestWorldSettings worldSettings = new TestWorldSettings();
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(worldSettings);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
@NonNull
|
@NonNull
|
||||||
WorldSettings ws = mock(WorldSettings.class);
|
WorldSettings ws = mock(WorldSettings.class);
|
||||||
|
@ -194,7 +198,7 @@ public class IslandTeamSetownerCommandTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteUserStringListOfStringNotInTeam() {
|
public void testCanExecuteUserStringListOfStringNotInTeam() {
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of());
|
when(island.inTeam(uuid)).thenReturn(false);
|
||||||
assertFalse(its.canExecute(user, "", List.of("gibby")));
|
assertFalse(its.canExecute(user, "", List.of("gibby")));
|
||||||
verify(user).sendMessage("general.errors.no-team");
|
verify(user).sendMessage("general.errors.no-team");
|
||||||
}
|
}
|
||||||
|
@ -267,6 +271,7 @@ public class IslandTeamSetownerCommandTest {
|
||||||
UUID target = UUID.randomUUID();
|
UUID target = UUID.randomUUID();
|
||||||
when(pm.getUUID(anyString())).thenReturn(target);
|
when(pm.getUUID(anyString())).thenReturn(target);
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid, target));
|
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid, target));
|
||||||
|
when(island.inTeam(any())).thenReturn(true);
|
||||||
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||||
|
@ -282,7 +287,7 @@ public class IslandTeamSetownerCommandTest {
|
||||||
when(im.inTeam(any(), any())).thenReturn(true);
|
when(im.inTeam(any(), any())).thenReturn(true);
|
||||||
UUID target = UUID.randomUUID();
|
UUID target = UUID.randomUUID();
|
||||||
when(pm.getUUID(anyString())).thenReturn(target);
|
when(pm.getUUID(anyString())).thenReturn(target);
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid, target));
|
when(island.inTeam(any())).thenReturn(true);
|
||||||
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||||
|
|
|
@ -211,6 +211,7 @@ public class IslandTeamUncoopCommandTest extends RanksManagerBeforeClassTest {
|
||||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
when(im.inTeam(any(), any())).thenReturn(true);
|
when(im.inTeam(any(), any())).thenReturn(true);
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
||||||
|
when(island.inTeam(notUUID)).thenReturn(true);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||||
verify(user).sendMessage(eq("commands.island.team.uncoop.cannot-uncoop-member"));
|
verify(user).sendMessage(eq("commands.island.team.uncoop.cannot-uncoop-member"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,7 @@ public class IslandTeamUntrustCommandTest extends RanksManagerBeforeClassTest {
|
||||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
when(im.inTeam(any(), any())).thenReturn(true);
|
when(im.inTeam(any(), any())).thenReturn(true);
|
||||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
||||||
|
when(island.inTeam(notUUID)).thenReturn(true);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||||
verify(user).sendMessage(eq("commands.island.team.untrust.cannot-untrust-member"));
|
verify(user).sendMessage(eq("commands.island.team.untrust.cannot-untrust-member"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,35 @@
|
||||||
package world.bentobox.bentobox.api.flags.clicklisteners;
|
package world.bentobox.bentobox.api.flags.clicklisteners;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
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;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -59,6 +66,8 @@ public class CycleClickTest {
|
||||||
private static final Integer X = 600;
|
private static final Integer X = 600;
|
||||||
private static final Integer Y = 120;
|
private static final Integer Y = 120;
|
||||||
private static final Integer Z = 10000;
|
private static final Integer Z = 10000;
|
||||||
|
private static final int SLOT = 5;
|
||||||
|
private static final String LOCK = "LOCK";
|
||||||
@Mock
|
@Mock
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@ -82,6 +91,9 @@ public class CycleClickTest {
|
||||||
private SettingsTab settingsTab;
|
private SettingsTab settingsTab;
|
||||||
@Mock
|
@Mock
|
||||||
private RanksManager rm;
|
private RanksManager rm;
|
||||||
|
private List<String> hiddenFlags;
|
||||||
|
@Mock
|
||||||
|
private @NonNull Player p;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception - exception
|
* @throws java.lang.Exception - exception
|
||||||
|
@ -99,9 +111,7 @@ public class CycleClickTest {
|
||||||
Settings s = mock(Settings.class);
|
Settings s = mock(Settings.class);
|
||||||
when(plugin.getSettings()).thenReturn(s);
|
when(plugin.getSettings()).thenReturn(s);
|
||||||
|
|
||||||
// Player
|
// User
|
||||||
Player p = mock(Player.class);
|
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
|
@ -178,6 +188,7 @@ public class CycleClickTest {
|
||||||
when(im.getIslandAt(any())).thenReturn(opIsland);
|
when(im.getIslandAt(any())).thenReturn(opIsland);
|
||||||
|
|
||||||
FlagsManager fm = mock(FlagsManager.class);
|
FlagsManager fm = mock(FlagsManager.class);
|
||||||
|
when(flag.getID()).thenReturn(LOCK);
|
||||||
when(fm.getFlag(anyString())).thenReturn(Optional.of(flag));
|
when(fm.getFlag(anyString())).thenReturn(Optional.of(flag));
|
||||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||||
|
|
||||||
|
@ -210,8 +221,13 @@ public class CycleClickTest {
|
||||||
|
|
||||||
// Active tab
|
// Active tab
|
||||||
when(panel.getActiveTab()).thenReturn(settingsTab);
|
when(panel.getActiveTab()).thenReturn(settingsTab);
|
||||||
|
when(panel.getWorld()).thenReturn(Optional.of(world));
|
||||||
|
when(panel.getName()).thenReturn("name");
|
||||||
when(settingsTab.getIsland()).thenReturn(island);
|
when(settingsTab.getIsland()).thenReturn(island);
|
||||||
|
|
||||||
|
// Hidden flags
|
||||||
|
hiddenFlags = new ArrayList<>();
|
||||||
|
when(iwm.getHiddenFlags(world)).thenReturn(hiddenFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -222,25 +238,28 @@ public class CycleClickTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNoPremission() {
|
public void testNoPremission() {
|
||||||
when(user.hasPermission(anyString())).thenReturn(false);
|
when(user.hasPermission(anyString())).thenReturn(false);
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
|
||||||
verify(user).sendMessage(eq("general.errors.no-permission"), eq("[permission]"), eq("bskyblock.settings.LOCK"));
|
verify(user).sendMessage(eq("general.errors.no-permission"), eq("[permission]"), eq("bskyblock.settings.LOCK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpDownClick() {
|
public void testUpDownClick() {
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
assertNotNull(udc);
|
assertNotNull(udc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnLeftClick() {
|
public void testOnLeftClick() {
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Click left
|
// Click left
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||||
verify(island).setFlag(eq(flag), eq(RanksManager.OWNER_RANK));
|
verify(island).setFlag(flag, RanksManager.OWNER_RANK);
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Owner should go to Visitor
|
// Clicking when Owner should go to Visitor
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.OWNER_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.OWNER_RANK);
|
||||||
|
@ -249,65 +268,114 @@ public class CycleClickTest {
|
||||||
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnLeftClickSetMinMax() {
|
public void testOnLeftClickSetMinMax() {
|
||||||
// Provide a current rank value - coop
|
// Provide a current rank value - coop
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick("LOCK", RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
CycleClick udc = new CycleClick(LOCK, RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Click left
|
// Click left
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||||
verify(island).setFlag(eq(flag), eq(RanksManager.TRUSTED_RANK));
|
verify(island).setFlag(flag, RanksManager.TRUSTED_RANK);
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Member should go to Coop
|
// Clicking when Member should go to Coop
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.MEMBER_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||||
verify(island).setFlag(eq(flag), eq(RanksManager.COOP_RANK));
|
verify(island).setFlag(flag, RanksManager.COOP_RANK);
|
||||||
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnRightClick() {
|
public void testOnRightClick() {
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Right click - down rank to Trusted
|
// Right click - down rank to Trusted
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
verify(island).setFlag(eq(flag), eq(RanksManager.TRUSTED_RANK));
|
verify(island).setFlag(flag, RanksManager.TRUSTED_RANK);
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Visitor should go to Owner
|
// Clicking when Visitor should go to Owner
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.VISITOR_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.VISITOR_RANK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
verify(island).setFlag(eq(flag), eq(RanksManager.OWNER_RANK));
|
verify(island).setFlag(flag, RanksManager.OWNER_RANK);
|
||||||
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnRightClickMinMaxSet() {
|
public void testOnRightClickMinMaxSet() {
|
||||||
// Provide a current rank value - coop
|
// Provide a current rank value - coop
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.TRUSTED_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.TRUSTED_RANK);
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick("LOCK", RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
CycleClick udc = new CycleClick(LOCK, RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Right click
|
// Right click
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
verify(island).setFlag(eq(flag), eq(RanksManager.COOP_RANK));
|
verify(island).setFlag(flag, RanksManager.COOP_RANK);
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Coop should go to Member
|
// Clicking when Coop should go to Member
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
verify(island).setFlag(eq(flag), eq(RanksManager.MEMBER_RANK));
|
verify(island).setFlag(flag, RanksManager.MEMBER_RANK);
|
||||||
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAllClicks() {
|
public void testAllClicks() {
|
||||||
// Test all possible click types
|
// Test all possible click types
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
Arrays.asList(ClickType.values()).forEach(c -> assertTrue(udc.onClick(panel, user, c, 0)));
|
Arrays.asList(ClickType.values()).forEach(c -> assertTrue(udc.onClick(panel, user, c, 0)));
|
||||||
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoWorld() {
|
||||||
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
|
when(panel.getWorld()).thenReturn(Optional.empty());
|
||||||
|
assertTrue(udc.onClick(panel, user, ClickType.SHIFT_LEFT, SLOT));
|
||||||
|
verify(plugin).logError("Panel name has no world associated with it. Please report this bug to the author.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnShiftLeftClickNotOp() {
|
||||||
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
|
// Click shift left
|
||||||
|
assertTrue(udc.onClick(panel, user, ClickType.SHIFT_LEFT, SLOT));
|
||||||
|
verify(user, never()).sendMessage(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnShiftLeftClickIsOp() {
|
||||||
|
when(user.isOp()).thenReturn(true);
|
||||||
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
|
// Click shift left
|
||||||
|
assertTrue(hiddenFlags.isEmpty());
|
||||||
|
assertTrue(udc.onClick(panel, user, ClickType.SHIFT_LEFT, SLOT));
|
||||||
|
assertFalse(hiddenFlags.isEmpty());
|
||||||
|
assertEquals(LOCK, hiddenFlags.get(0));
|
||||||
|
// Click shift left again to remove flag
|
||||||
|
assertTrue(udc.onClick(panel, user, ClickType.SHIFT_LEFT, SLOT));
|
||||||
|
assertTrue(hiddenFlags.isEmpty());
|
||||||
|
// Verify sounds
|
||||||
|
verify(p).playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||||
|
verify(p).playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,17 @@ public class MythicMobsHookTest {
|
||||||
* Test method for {@link world.bentobox.bentobox.hooks.MythicMobsHook#spawnMythicMob(world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity.MythicMobRecord, org.bukkit.Location)}.
|
* Test method for {@link world.bentobox.bentobox.hooks.MythicMobsHook#spawnMythicMob(world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity.MythicMobRecord, org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSpawnMythicMob() {
|
public void testSpawnMythicMobNoPLugin() {
|
||||||
|
MythicMobRecord mmr = hook.getMythicMob(entity);
|
||||||
|
assertFalse(hook.spawnMythicMob(mmr, location));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.hooks.MythicMobsHook#spawnMythicMob(world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity.MythicMobRecord, org.bukkit.Location)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSpawnMythicMobHasPlugin() {
|
||||||
|
when(mythicMobs.isEnabled()).thenReturn(true);
|
||||||
MythicMobRecord mmr = hook.getMythicMob(entity);
|
MythicMobRecord mmr = hook.getMythicMob(entity);
|
||||||
assertTrue(hook.spawnMythicMob(mmr, location));
|
assertTrue(hook.spawnMythicMob(mmr, location));
|
||||||
verify(mm).getMythicMob("GIANT");
|
verify(mm).getMythicMob("GIANT");
|
||||||
|
|
|
@ -47,6 +47,8 @@ public class PetTeleportListenerTest extends AbstractCommonSetup {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
// Island
|
||||||
|
when(this.island.inTeam(uuid)).thenReturn(true);
|
||||||
when(tamed.isTamed()).thenReturn(true);
|
when(tamed.isTamed()).thenReturn(true);
|
||||||
when(tamed.getOwner()).thenReturn(tamer);
|
when(tamed.getOwner()).thenReturn(tamer);
|
||||||
when(tamer.getUniqueId()).thenReturn(uuid);
|
when(tamer.getUniqueId()).thenReturn(uuid);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -250,7 +251,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
||||||
when(islandCache.getIslandAt(any(Location.class))).thenReturn(island);
|
when(islandCache.getIslandAt(any(Location.class))).thenReturn(island);
|
||||||
when(islandCache.get(any(), any())).thenReturn(island);
|
when(islandCache.get(any(), any())).thenReturn(island);
|
||||||
optionalIsland = Optional.ofNullable(island);
|
optionalIsland = Optional.ofNullable(island);
|
||||||
when(islandCache.getIslands(world, uuid)).thenReturn(Set.of(island));
|
when(islandCache.getIslands(world, uuid)).thenReturn(List.of(island));
|
||||||
|
|
||||||
// User location
|
// User location
|
||||||
when(user.getLocation()).thenReturn(location);
|
when(user.getLocation()).thenReturn(location);
|
||||||
|
@ -829,6 +830,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
||||||
Builder<UUID> members = new ImmutableSet.Builder<>();
|
Builder<UUID> members = new ImmutableSet.Builder<>();
|
||||||
members.add(uuid);
|
members.add(uuid);
|
||||||
when(is.getMemberSet()).thenReturn(members.build());
|
when(is.getMemberSet()).thenReturn(members.build());
|
||||||
|
when(is.inTeam(uuid)).thenReturn(true);
|
||||||
|
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
|
||||||
|
@ -841,10 +843,12 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
||||||
// No members
|
// No members
|
||||||
Builder<UUID> mem = new ImmutableSet.Builder<>();
|
Builder<UUID> mem = new ImmutableSet.Builder<>();
|
||||||
when(is.getMemberSet()).thenReturn(mem.build());
|
when(is.getMemberSet()).thenReturn(mem.build());
|
||||||
|
when(is.inTeam(uuid)).thenReturn(false);
|
||||||
assertFalse(im.locationIsOnIsland(player, location));
|
assertFalse(im.locationIsOnIsland(player, location));
|
||||||
|
|
||||||
// Not on island
|
// Not on island
|
||||||
when(is.getMemberSet()).thenReturn(members.build());
|
when(is.getMemberSet()).thenReturn(members.build());
|
||||||
|
when(is.inTeam(uuid)).thenReturn(true);
|
||||||
when(is.onIsland(any())).thenReturn(false);
|
when(is.onIsland(any())).thenReturn(false);
|
||||||
assertFalse(im.locationIsOnIsland(player, location));
|
assertFalse(im.locationIsOnIsland(player, location));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,14 @@ import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.TestWorldSettings;
|
||||||
import world.bentobox.bentobox.api.addons.AddonDescription;
|
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.hooks.Hook;
|
import world.bentobox.bentobox.api.hooks.Hook;
|
||||||
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
|
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
|
||||||
import world.bentobox.bentobox.lists.GameModePlaceholder;
|
import world.bentobox.bentobox.lists.GameModePlaceholder;
|
||||||
|
@ -43,9 +47,17 @@ public class PlaceholdersManagerTest {
|
||||||
private HooksManager hm;
|
private HooksManager hm;
|
||||||
@Mock
|
@Mock
|
||||||
private PlaceholderAPIHook hook;
|
private PlaceholderAPIHook hook;
|
||||||
|
@Mock
|
||||||
|
private IslandWorldManager iwm;
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
// Set up plugin
|
||||||
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
settings = new Settings();
|
||||||
|
when(plugin.getSettings()).thenReturn(settings);
|
||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
@NonNull
|
@NonNull
|
||||||
AddonDescription desc = new AddonDescription.Builder("main", "bskyblock", "1.0").build();
|
AddonDescription desc = new AddonDescription.Builder("main", "bskyblock", "1.0").build();
|
||||||
|
@ -61,6 +73,13 @@ public class PlaceholdersManagerTest {
|
||||||
when(hm.getHook(eq("PlaceholderAPI"))).thenReturn(optionalHook);
|
when(hm.getHook(eq("PlaceholderAPI"))).thenReturn(optionalHook);
|
||||||
when(hook.isPlaceholder(any(), any())).thenReturn(false);
|
when(hook.isPlaceholder(any(), any())).thenReturn(false);
|
||||||
|
|
||||||
|
// World settings
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
WorldSettings ws = new TestWorldSettings();
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(ws);
|
||||||
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Placeholder manager
|
// Placeholder manager
|
||||||
pm = new PlaceholdersManager(plugin);
|
pm = new PlaceholdersManager(plugin);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +96,7 @@ public class PlaceholdersManagerTest {
|
||||||
public void testRegisterGameModePlaceholdersAllDefaults() {
|
public void testRegisterGameModePlaceholdersAllDefaults() {
|
||||||
pm.registerDefaultPlaceholders(addon);
|
pm.registerDefaultPlaceholders(addon);
|
||||||
// + 300 because we register team member placeholders up to 50 members
|
// + 300 because we register team member placeholders up to 50 members
|
||||||
verify(hook, times(GameModePlaceholder.values().length + 302)).registerPlaceholder(any(), anyString(), any());
|
verify(hook, times(GameModePlaceholder.values().length + 304)).registerPlaceholder(any(), anyString(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +110,7 @@ public class PlaceholdersManagerTest {
|
||||||
pm.registerDefaultPlaceholders(addon);
|
pm.registerDefaultPlaceholders(addon);
|
||||||
|
|
||||||
// 3 less registrations for this addon
|
// 3 less registrations for this addon
|
||||||
verify(hook, times(GameModePlaceholder.values().length - 3 + 302)).registerPlaceholder(any(), anyString(),
|
verify(hook, times(GameModePlaceholder.values().length - 3 + 304)).registerPlaceholder(any(), anyString(),
|
||||||
any());
|
any());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.Settings;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -123,6 +124,9 @@ public class BlueprintManagementPanelTest {
|
||||||
// Blueprint
|
// Blueprint
|
||||||
when(blueprint.getName()).thenReturn("blueprint name");
|
when(blueprint.getName()).thenReturn("blueprint name");
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
Settings settings = new Settings();
|
||||||
|
when(plugin.getSettings()).thenReturn(settings);
|
||||||
|
|
||||||
// Set up
|
// Set up
|
||||||
bmp = new BlueprintManagementPanel(plugin, user, addon);
|
bmp = new BlueprintManagementPanel(plugin, user, addon);
|
||||||
|
|
|
@ -203,7 +203,7 @@ public class IslandCreationPanelTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOpenPanel() {
|
public void testOpenPanel() {
|
||||||
IslandCreationPanel.openPanel(ic, user, "");
|
IslandCreationPanel.openPanel(ic, user, "", false);
|
||||||
|
|
||||||
// Set correctly
|
// Set correctly
|
||||||
verify(inv).setItem(eq(0), any());
|
verify(inv).setItem(eq(0), any());
|
||||||
|
@ -220,7 +220,7 @@ public class IslandCreationPanelTest {
|
||||||
public void testOpenPanelSameSlot() {
|
public void testOpenPanelSameSlot() {
|
||||||
when(bb2.getSlot()).thenReturn(5);
|
when(bb2.getSlot()).thenReturn(5);
|
||||||
when(bb3.getSlot()).thenReturn(5);
|
when(bb3.getSlot()).thenReturn(5);
|
||||||
IslandCreationPanel.openPanel(ic, user, "");
|
IslandCreationPanel.openPanel(ic, user, "", false);
|
||||||
verify(inv).setItem(eq(0), any());
|
verify(inv).setItem(eq(0), any());
|
||||||
verify(inv).setItem(eq(1), any());
|
verify(inv).setItem(eq(1), any());
|
||||||
verify(meta).setDisplayName(eq("test"));
|
verify(meta).setDisplayName(eq("test"));
|
||||||
|
|
Loading…
Reference in New Issue