2 0 0 multi island (#2185)

* Multi world WIP - stashing

* Initial work on supporting multiple islands per player

The default allowed number is 5 for now, but will be set to 1 by
default.

Lots more work to do on this!

* More work on multi island. Fixed tests so clean compile.

* Remove unused imports

* Updated island go and homes command to multi island

Updated tests.

* Do not reload addons anymore.

* Add island name when entering or leaving own island

* Remove unused import

* Adds island names to /island go command.

* Enables more homes to be set if player has more than one island

* Switch to using a set for islands and explicit primary boolean in Island

* WIP

* Fix bugs with the go command.

* Be able to delete multiple islands, e.g. when joining a team

This is not fully tested.

* Do not remove all islands when a player does reset.

Players can reset just the island they are on.

* More fixes for go command

* Fix tests

* Fix @NonNull annotation

* Fix home syntax listing reference for IslandDeleteHome

* Fixed deletehome for multiple islands.

* Fix /island command teleport to current island default home.

* Remove deprecated code.

* Fix tag for concurrent island setting in config.yml

* Improve error when trying to make additional islands over limit

* Update config.yml

* Correctly assign invites for islands.

* Switch to canExecute API in prep for multi-island handling

* Prevent players from obtaining more concurrent islands by owner transfer

* Handle leaving and disbanding of teams

* Fix tests

* Fix minor bugs or code smells.

* Restore the quarantine code from deprecation.

This code can stay. It checks if islands can load, and if not puts them
in a trash. It does no harm.

* Remove unneeded eq()'s

* Fix tests
This commit is contained in:
tastybento 2023-09-16 15:55:52 -07:00 committed by GitHub
parent 503107a90c
commit a4bef159be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 1844 additions and 1669 deletions

View File

@ -88,7 +88,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.24.2</build.version>
<build.version>2.0.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>

View File

@ -31,6 +31,7 @@ import world.bentobox.bentobox.listeners.BlockEndDragon;
import world.bentobox.bentobox.listeners.DeathListener;
import world.bentobox.bentobox.listeners.JoinLeaveListener;
import world.bentobox.bentobox.listeners.PanelListenerManager;
import world.bentobox.bentobox.listeners.PrimaryIslandListener;
import world.bentobox.bentobox.listeners.StandardSpawnProtectionListener;
import world.bentobox.bentobox.listeners.teleports.EntityTeleportListener;
import world.bentobox.bentobox.listeners.teleports.PlayerTeleportListener;
@ -308,6 +309,8 @@ public class BentoBox extends JavaPlugin implements Listener {
// Island Delete Manager
islandDeletionManager = new IslandDeletionManager(this);
manager.registerEvents(islandDeletionManager, this);
// Primary Island Listener
manager.registerEvents(new PrimaryIslandListener(this), this);
}
@Override

View File

@ -190,6 +190,12 @@ public class Settings implements ConfigObject {
/*
* Island
*/
// Number of islands
@ConfigComment("The default number of concurrent islands a player may have.")
@ConfigComment("This may be overridden by individual game mode config settings.")
@ConfigEntry(path = "island.concurrent-islands")
private int islandNumber = 1;
// Cooldowns
@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")
@ -1045,4 +1051,21 @@ public class Settings implements ConfigObject {
public void setReadyCommands(List<String> readyCommands) {
this.readyCommands = readyCommands;
}
/**
* @return the islandNumber
* @since 2.0.0
*/
public int getIslandNumber() {
return islandNumber;
}
/**
* @param islandNumber the islandNumber to set
* @since 2.0.0
*/
public void setIslandNumber(int islandNumber) {
this.islandNumber = islandNumber;
}
}

View File

@ -461,17 +461,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return getSubCommands();
}
/**
* Convenience method to obtain the user's island owner
* @param world world to check
* @param user the User
* @return UUID of player's island owner or null if user has no island
*/
@Nullable
protected UUID getOwner(@NonNull World world, @NonNull User user) {
return plugin.getIslands().getOwner(world, user.getUniqueId());
}
@Override
public @NonNull String getUsage() {
return "/" + usage;

View File

@ -5,8 +5,6 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.util.Vector;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -41,14 +39,14 @@ public class AdminDeleteCommand extends ConfirmableCommand {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
UUID owner = getIslands().getOwner(getWorld(), targetUUID);
if (owner == null) {
Island island = getIslands().getIsland(getWorld(), user);
if (island == null) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Team members should be kicked before deleting otherwise the whole team will become weird
if (getIslands().inTeam(getWorld(), targetUUID) && owner.equals(targetUUID)) {
if (getIslands().inTeam(getWorld(), targetUUID) && user.getUniqueId().equals(island.getOwner())) {
user.sendMessage("commands.admin.delete.cannot-delete-owner");
return false;
}
@ -66,10 +64,7 @@ public class AdminDeleteCommand extends ConfirmableCommand {
private void deletePlayer(User user, UUID targetUUID) {
// Delete player and island
// Get the target's island
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
Vector vector = null;
if (oldIsland != null) {
for (Island oldIsland : getIslands().getIslands(getWorld(), targetUUID)) {
// Fire island preclear event
IslandEvent.builder()
.involvedPlayer(user.getUniqueId())
@ -78,21 +73,17 @@ public class AdminDeleteCommand extends ConfirmableCommand {
.oldIsland(oldIsland)
.location(oldIsland.getCenter())
.build();
// Check if player is online and on the island
User target = User.getInstance(targetUUID);
// Remove them from this island (it still exists and will be deleted later)
getIslands().removePlayer(getWorld(), targetUUID);
if (target.isPlayer() && target.isOnline()) {
cleanUp(target);
}
vector = oldIsland.getCenter().toVector();
user.sendMessage("commands.admin.delete.deleted-island", TextVariables.XYZ, Util.xyz(oldIsland.getCenter().toVector()));
getIslands().deleteIsland(oldIsland, true, targetUUID);
}
if (vector == null) {
user.sendMessage("general.success");
} else {
user.sendMessage("commands.admin.delete.deleted-island", TextVariables.XYZ, Util.xyz(vector));
// Check if player is online and on the island
User target = User.getInstance(targetUUID);
// Remove them from this island (it still exists and will be deleted later)
getIslands().removePlayer(getWorld(), targetUUID);
if (target.isPlayer() && target.isOnline()) {
cleanUp(target);
}
user.sendMessage("general.success");
}
private void cleanUp(User target) {

View File

@ -57,7 +57,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
mUser.sendMessage("commands.admin.team.disband.disbanded");
// The owner gets to keep the island
if (!m.equals(targetUUID)) {
getIslands().setLeaveTeam(getWorld(), m);
island.removeMember(m);
TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.KICK)

View File

@ -42,14 +42,20 @@ public class IslandCreateCommand extends CompositeCommand {
public boolean canExecute(User user, String label, List<String> args) {
// Check if the island is reserved
@Nullable
Island island = getIslands().getIsland(getWorld(), user);
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
if (island != null) {
// Reserved islands can be made
if (island.isReserved()) {
return true;
}
// Get how many islands this player has
int num = this.getIslands().getNumberOfConcurrentIslands(user.getUniqueId(), getWorld());
int max = this.getIWM().getWorldSettings(getWorld()).getConcurrentIslands();
if (num < max) {
return true;
}
// You cannot make an island
user.sendMessage("general.errors.already-have-island");
user.sendMessage("general.errors.you-cannot-make");
return false;
}
if (getIWM().getMaxIslands(getWorld()) > 0

View File

@ -1,12 +1,12 @@
package world.bentobox.bentobox.api.commands.island;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
@ -22,8 +22,6 @@ import world.bentobox.bentobox.util.Util;
*/
public class IslandDeletehomeCommand extends ConfirmableCommand {
private @Nullable Island island;
/**
* Deletes a home
* @param islandCommand parent command
@ -48,7 +46,7 @@ public class IslandDeletehomeCommand extends ConfirmableCommand {
this.showHelp(this, user);
return false;
}
island = getIslands().getIsland(getWorld(), user);
Island island = getIslands().getIsland(getWorld(), user);
// Check island
if (island == null) {
user.sendMessage("general.errors.no-island");
@ -63,19 +61,21 @@ public class IslandDeletehomeCommand extends ConfirmableCommand {
return false;
}
// Check if the name is known
if (!getIslands().isHomeLocation(island, String.join(" ", args))) {
user.sendMessage("commands.island.go.unknown-home");
user.sendMessage("commands.island.sethome.homes-are");
island.getHomes().keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s));
return false;
}
return true;
}
@Override
public boolean execute(User user, String label, List<String> args) {
this.askConfirmation(user, () -> delete(island, user, String.join(" ", args)));
// Check if the name is known
Map<String, Island> map = getNameIslandMap(user);
String name = String.join(" ", args);
if (!map.containsKey(name)) {
user.sendMessage("commands.island.go.unknown-home");
user.sendMessage("commands.island.sethome.homes-are");
map.keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s));
return false;
}
this.askConfirmation(user, () -> delete(map.get(name), user, name));
return true;
}
@ -88,11 +88,19 @@ public class IslandDeletehomeCommand extends ConfirmableCommand {
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
Island is = getIslands().getIsland(getWorld(), user.getUniqueId());
if (is != null) {
return Optional.of(Util.tabLimit(new ArrayList<>(is.getHomes().keySet()), lastArg));
} else {
return Optional.empty();
}
return Optional.of(Util.tabLimit(new ArrayList<>(getNameIslandMap(user).keySet()), lastArg));
}
private Map<String, Island> getNameIslandMap(User user) {
Map<String, Island> islandMap = new HashMap<>();
for (Island isle : getIslands().getIslands(getWorld(), user.getUniqueId())) {
// Add homes.
isle.getHomes().keySet().forEach(name -> islandMap.put(name, isle));
}
return islandMap;
}
}

View File

@ -2,8 +2,11 @@ package world.bentobox.bentobox.api.commands.island;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.DelayedTeleportCommand;
@ -12,6 +15,7 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
/**
* @author tastybento
@ -38,47 +42,101 @@ public class IslandGoCommand extends DelayedTeleportCommand {
user.sendMessage("commands.island.go.teleport");
return false;
}
// Check if the island is reserved
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
if (island == null) {
Set<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
if (islands.isEmpty()) {
user.sendMessage("general.errors.no-island");
return false;
}
if (island.isReserved()) {
// Send player to create an island
getParent().getSubCommand("create").ifPresent(createCmd -> createCmd.call(user, createCmd.getLabel(), Collections.emptyList()));
// Check if the island is reserved
if (checkReserved(user, islands)) {
return false;
}
// Prevent command if player is falling and its not allowed
if ((getIWM().inWorld(user.getWorld()) && Flags.PREVENT_TELEPORT_WHEN_FALLING.isSetForWorld(user.getWorld()))
&& user.getPlayer().getFallDistance() > 0) {
// We're sending the "hint" to the player to tell them they cannot teleport while falling.
user.sendMessage(Flags.PREVENT_TELEPORT_WHEN_FALLING.getHintReference());
return false;
}
if (!args.isEmpty() && !getIslands().isHomeLocation(island, String.join(" ", args))) {
user.sendMessage("commands.island.go.unknown-home");
user.sendMessage("commands.island.sethome.homes-are");
island.getHomes().keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s));
return false;
}
return true;
}
@Override
public boolean execute(User user, String label, List<String> args) {
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer(), String.join(" ", args)));
// Check if the home is known
if (!args.isEmpty()) {
Map<String, IslandInfo> names = getNameIslandMap(user);
final String name = String.join(" ", args);
if (!names.containsKey(name)) {
// Failed home name check
user.sendMessage("commands.island.go.unknown-home");
user.sendMessage("commands.island.sethome.homes-are");
names.keySet().forEach(n -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, n));
return false;
} else {
IslandInfo info = names.get(name);
getIslands().setPrimaryIsland(user.getUniqueId(), info.island);
if (info.islandName) {
this.delayCommand(user, () -> new SafeSpotTeleport.Builder(getPlugin())
.entity(user.getPlayer())
.location(getIslands().getHomeLocation(info.island))
.thenRun(() -> user.sendMessage("general.success"))
.build());
} else {
this.delayCommand(user, () -> new SafeSpotTeleport.Builder(getPlugin())
.entity(user.getPlayer())
.location(getIslands().getHomeLocation(info.island, name))
.thenRun(() -> user.sendMessage("general.success"))
.build());
}
}
} else {
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer()));
}
return true;
}
private boolean checkReserved(User user, Set<Island> islands) {
for (Island island : islands) {
if (island.isReserved()) {
// Send player to create an island
getParent().getSubCommand("create").ifPresent(createCmd -> createCmd.call(user, createCmd.getLabel(), Collections.emptyList()));
return true;
}
}
return false;
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
if (island != null) {
return Optional.of(Util.tabLimit(new ArrayList<>(island.getHomes().keySet()), lastArg));
} else {
return Optional.empty();
return Optional.of(Util.tabLimit(new ArrayList<>(getNameIslandMap(user).keySet()), lastArg));
}
private record IslandInfo(Island island, boolean islandName) {}
private Map<String, IslandInfo> getNameIslandMap(User user) {
Map<String, IslandInfo> islandMap = new HashMap<>();
int index = 0;
for (Island island : getIslands().getIslands(getWorld(), user.getUniqueId())) {
index++;
if (island.getName() != null && !island.getName().isBlank()) {
// Name has been set
islandMap.put(island.getName(), new IslandInfo(island, true));
} else {
// Name has not been set
String text = user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()) + " " + index;
islandMap.put(text, new IslandInfo(island, true));
}
// Add homes. Homes do not need an island specified
island.getHomes().keySet().forEach(n -> islandMap.put(n, new IslandInfo(island, false)));
}
return islandMap;
}
}

View File

@ -1,18 +1,20 @@
package world.bentobox.bentobox.api.commands.island;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.annotation.Nullable;
import java.util.Optional;
import java.util.Set;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
public class IslandHomesCommand extends ConfirmableCommand {
private @Nullable Island island;
private Set<Island> islands;
public IslandHomesCommand(CompositeCommand islandCommand) {
super(islandCommand, "homes");
@ -27,9 +29,9 @@ public class IslandHomesCommand extends ConfirmableCommand {
@Override
public boolean canExecute(User user, String label, List<String> args) {
island = getIslands().getIsland(getWorld(), user);
islands = getIslands().getIslands(getWorld(), user);
// Check island
if (island == null || island.getOwner() == null) {
if (islands.isEmpty()) {
user.sendMessage("general.errors.no-island");
return false;
}
@ -39,9 +41,21 @@ public class IslandHomesCommand extends ConfirmableCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
user.sendMessage("commands.island.sethome.homes-are");
islands.forEach(island ->
island.getHomes().keySet().stream().filter(s -> !s.isEmpty())
.forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s));
.forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s)));
return true;
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
List<String> result = new ArrayList<>();
for (Island island : getIslands().getIslands(getWorld(), user.getUniqueId())) {
result.addAll(island.getHomes().keySet());
}
return Optional.of(Util.tabLimit(result, lastArg));
}
}

View File

@ -124,9 +124,8 @@ public class IslandResetCommand extends ConfirmableCommand {
private boolean resetIsland(User user, String name) {
// Get the player's old island
Island oldIsland = getIslands().getIsland(getWorld(), user);
if (oldIsland != null) {
deleteOldIsland(user, oldIsland);
}
deleteOldIsland(user, oldIsland);
user.sendMessage("commands.island.create.creating-island");
// Create new island and then delete the old one
try {

View File

@ -51,11 +51,13 @@ public class IslandSethomeCommand extends ConfirmableCommand {
}
// Check number of homes
int maxHomes = getIslands().getMaxHomes(island);
int maxHomes = getIslands().getIslands(getWorld(), user).stream().mapToInt(getIslands()::getMaxHomes).sum();
if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes) {
user.sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
user.sendMessage("commands.island.sethome.homes-are");
island.getHomes().keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s));
getIslands().getIslands(getWorld(), user).forEach(is ->
is.getHomes().keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s)));
return false;
}
return true;

View File

@ -3,6 +3,8 @@ package world.bentobox.bentobox.api.commands.island.team;
import java.util.Objects;
import java.util.UUID;
import world.bentobox.bentobox.database.objects.Island;
/**
* Represents an invite
* @author tastybento
@ -23,16 +25,19 @@ public class Invite {
private final Type type;
private final UUID inviter;
private final UUID invitee;
private final Island island;
/**
* @param type - invitation type, e.g., coop, team, trust
* @param inviter - UUID of inviter
* @param invitee - UUID of invitee
* @param island - the island this invite is for
*/
public Invite(Type type, UUID inviter, UUID invitee) {
public Invite(Type type, UUID inviter, UUID invitee, Island island) {
this.type = type;
this.inviter = inviter;
this.invitee = invitee;
this.island = island;
}
/**
@ -56,6 +61,13 @@ public class Invite {
return invitee;
}
/**
* @return the island
*/
public Island getIsland() {
return island;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/

View File

@ -58,24 +58,20 @@ public class IslandTeamCommand extends CompositeCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
// Player issuing the command must have an island
UUID ownerUUID = getOwner(getWorld(), user);
if (ownerUUID == null) {
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
if (island == null) {
user.sendMessage("general.errors.no-island");
return false;
}
UUID playerUUID = user.getUniqueId();
// Fire event so add-ons can run commands, etc.
if (fireEvent(user)) {
if (fireEvent(user, island)) {
// Cancelled
return false;
}
Island island = getIslands().getIsland(getWorld(), playerUUID);
if (island == null) {
return false;
}
Set<UUID> teamMembers = getMembers(getWorld(), user);
if (ownerUUID.equals(playerUUID)) {
if (playerUUID.equals(island.getOwner())) {
int maxSize = getIslands().getMaxMembers(island, RanksManager.MEMBER_RANK);
if (teamMembers.size() < maxSize) {
user.sendMessage("commands.island.team.invite.you-can-invite", TextVariables.NUMBER, String.valueOf(maxSize - teamMembers.size()));
@ -169,10 +165,9 @@ public class IslandTeamCommand extends CompositeCommand {
}
private boolean fireEvent(User user) {
private boolean fireEvent(User user, Island island) {
IslandBaseEvent e = TeamEvent.builder()
.island(getIslands()
.getIsland(getWorld(), user.getUniqueId()))
.island(island)
.reason(TeamEvent.Reason.INFO)
.involvedPlayer(user.getUniqueId())
.build();
@ -187,8 +182,8 @@ public class IslandTeamCommand extends CompositeCommand {
* @param invitee - uuid of invitee
* @since 1.8.0
*/
public void addInvite(Invite.Type type, @NonNull UUID inviter, @NonNull UUID invitee) {
inviteMap.put(invitee, new Invite(type, inviter, invitee));
public void addInvite(Invite.Type type, @NonNull UUID inviter, @NonNull UUID invitee, @NonNull Island island) {
inviteMap.put(invitee, new Invite(type, inviter, invitee, island));
}
/**

View File

@ -93,7 +93,7 @@ public class IslandTeamCoopCommand extends CompositeCommand {
if (getPlugin().getSettings().isInviteConfirmation()) {
// Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the previous invite!
itc.addInvite(Invite.Type.COOP, user.getUniqueId(), target.getUniqueId());
itc.addInvite(Invite.Type.COOP, user.getUniqueId(), target.getUniqueId(), island);
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
// Send message to online player
target.sendMessage("commands.island.team.coop.name-has-invited-you", TextVariables.NAME, user.getName());

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.commands.island.team;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand;
@ -23,7 +24,6 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
private static final String INVALID_INVITE = "commands.island.team.invite.errors.invalid-invite";
private final IslandTeamCommand itc;
private UUID playerUUID;
private UUID prospectiveOwnerUUID;
public IslandTeamInviteAcceptCommand(IslandTeamCommand islandTeamCommand) {
super(islandTeamCommand, "accept");
@ -46,7 +46,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
return false;
}
// Get the island owner
prospectiveOwnerUUID = itc.getInviter(playerUUID);
UUID prospectiveOwnerUUID = itc.getInviter(playerUUID);
if (prospectiveOwnerUUID == null) {
user.sendMessage(INVALID_INVITE);
return false;
@ -96,7 +96,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
// Remove the invite
itc.removeInvite(playerUUID);
User inviter = User.getInstance(invite.getInviter());
Island island = getIslands().getIsland(getWorld(), inviter);
Island island = invite.getIsland();
if (island != null) {
if (island.getMemberSet(RanksManager.TRUSTED_RANK, false).size() > getIslands().getMaxMembers(island, RanksManager.TRUSTED_RANK)) {
user.sendMessage("commands.island.team.trust.is-full");
@ -123,7 +123,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
// Remove the invite
itc.removeInvite(playerUUID);
User inviter = User.getInstance(invite.getInviter());
Island island = getIslands().getIsland(getWorld(), inviter);
Island island = invite.getIsland();
if (island != null) {
if (island.getMemberSet(RanksManager.COOP_RANK, false).size() > getIslands().getMaxMembers(island, RanksManager.COOP_RANK)) {
user.sendMessage("commands.island.team.coop.is-full");
@ -150,9 +150,9 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
// Remove the invite
itc.removeInvite(playerUUID);
// Get the player's island - may be null if the player has no island
Island island = getIslands().getIsland(getWorld(), playerUUID);
Set<Island> islands = getIslands().getIslands(getWorld(), playerUUID);
// Get the team's island
Island teamIsland = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
Island teamIsland = invite.getIsland();
if (teamIsland == null) {
user.sendMessage(INVALID_INVITE);
return;
@ -169,10 +169,9 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
getIslands().setJoinTeam(teamIsland, playerUUID);
// Move player to team's island
getIslands().homeTeleportAsync(getWorld(), user.getPlayer()).thenRun(() -> {
// Delete the old island
if (island != null) {
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
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
@ -193,7 +192,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
getIslands().save(teamIsland);
// Fire event
TeamEvent.builder()
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
.island(teamIsland)
.reason(TeamEvent.Reason.JOINED)
.involvedPlayer(playerUUID)
.build();

View File

@ -166,9 +166,14 @@ public class IslandTeamInviteCommand extends CompositeCommand {
itc.removeInvite(invitedPlayer.getUniqueId());
user.sendMessage("commands.island.team.invite.removing-invite");
}
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
if (island == null) {
user.sendMessage("general.errors.no-island");
return false;
}
// Fire event so add-ons can run commands, etc.
IslandBaseEvent e = TeamEvent.builder()
.island(getIslands().getIsland(getWorld(), user.getUniqueId()))
.island(island)
.reason(TeamEvent.Reason.INVITE)
.involvedPlayer(invitedPlayer.getUniqueId())
.build();
@ -177,7 +182,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
}
// Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the previous invite!
itc.addInvite(Invite.Type.TEAM, user.getUniqueId(), invitedPlayer.getUniqueId());
itc.addInvite(Invite.Type.TEAM, user.getUniqueId(), invitedPlayer.getUniqueId(), island);
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName(), TextVariables.DISPLAY_NAME, invitedPlayer.getDisplayName());
// Send message to online player
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());

View File

@ -67,6 +67,10 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
private void leave(User user) {
Island island = getIslands().getIsland(getWorld(), user);
if (island == null) {
user.sendMessage("general.errors.no-island");
return;
}
// Fire event
IslandBaseEvent event = TeamEvent.builder()
.island(island)
@ -76,11 +80,11 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
if (event.isCancelled()) {
return;
}
UUID ownerUUID = getIslands().getOwner(getWorld(), user.getUniqueId());
UUID ownerUUID = island.getOwner();
if (ownerUUID != null) {
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
}
getIslands().setLeaveTeam(getWorld(), user.getUniqueId());
island.removeMember(user.getUniqueId());
// Clean the player
getPlayers().cleanLeavingPlayer(getWorld(), user, false, island);

View File

@ -4,6 +4,8 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -16,6 +18,8 @@ import world.bentobox.bentobox.util.Util;
public class IslandTeamSetownerCommand extends CompositeCommand {
private @Nullable UUID targetUUID;
public IslandTeamSetownerCommand(CompositeCommand islandTeamCommand) {
super(islandTeamCommand, "setowner");
}
@ -29,37 +33,48 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
}
@Override
public boolean execute(User user, String label, List<String> args) {
UUID playerUUID = user.getUniqueId();
// Can use if in a team
boolean inTeam = getIslands().inTeam(getWorld(), playerUUID);
if (!inTeam) {
user.sendMessage("general.errors.no-team");
return false;
}
UUID ownerUUID = getOwner(getWorld(), user);
if (ownerUUID == null || !ownerUUID.equals(playerUUID)) {
user.sendMessage("general.errors.not-owner");
return false;
}
public boolean canExecute(User user, String label, List<String> args) {
// If args are not right, show help
if (args.size() != 1) {
showHelp(this, user);
return false;
}
UUID targetUUID = getPlayers().getUUID(args.get(0));
// Can use if in a team
boolean inTeam = getIslands().inTeam(getWorld(), user.getUniqueId());
if (!inTeam) {
user.sendMessage("general.errors.no-team");
return false;
}
UUID ownerUUID = getIslands().getOwner(getWorld(), user.getUniqueId());
if (ownerUUID == null || !ownerUUID.equals(user.getUniqueId())) {
user.sendMessage("general.errors.not-owner");
return false;
}
targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
if (targetUUID.equals(playerUUID)) {
if (targetUUID.equals(user.getUniqueId())) {
user.sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
return false;
}
if (!getIslands().getMembers(getWorld(), playerUUID).contains(targetUUID)) {
if (!getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
user.sendMessage("commands.island.team.setowner.errors.target-is-not-member");
return false;
}
// Check how many islands target has
if (getIslands().getNumberOfConcurrentIslands(targetUUID, getWorld()) >= this.getIWM().getWorldSettings(getWorld()).getConcurrentIslands()) {
// Too many
user.sendMessage("commands.island.team.setowner.errors.at-max");
return false;
}
return true;
}
@Override
public boolean execute(User user, String label, List<String> args) {
// Fire event so add-ons can run commands, etc.
Island island = getIslands().getIsland(getWorld(), user);
// Fire event so add-ons can run commands, etc.
@ -83,10 +98,10 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
// Call the event for the previous owner
IslandEvent.builder()
.island(island)
.involvedPlayer(playerUUID)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(RanksManager.OWNER_RANK, island.getRank(user))
.rankChange(RanksManager.OWNER_RANK, RanksManager.VISITOR_RANK)
.build();
getIslands().save(island);
return true;

View File

@ -95,7 +95,7 @@ public class IslandTeamTrustCommand extends CompositeCommand {
if (getPlugin().getSettings().isInviteConfirmation()) {
// Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the previous invite!
itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId());
itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId(), island);
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName());
// Send message to online player
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());

View File

@ -13,6 +13,7 @@ import org.bukkit.GameMode;
import org.bukkit.entity.EntityType;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.lists.Flags;
@ -634,4 +635,13 @@ public interface WorldSettings extends ConfigObject {
default boolean isCheckForBlocks() {
return true;
}
/**
* Get the number of concurrent islands a player can have in the world
* @return 1 by default
* @since 2.0.0
*/
default int getConcurrentIslands() {
return BentoBox.getInstance().getSettings().getIslandNumber();
}
}

View File

@ -176,7 +176,7 @@ public class IslandEvent extends IslandBaseEvent {
* Event that will fire when an island is named or renamed
* @since 1.24.0
*/
NAME,
NAME,
/**
* Event that will fire when the info command is executed. Allows addons to add to it
* @since 1.24.0
@ -334,7 +334,7 @@ public class IslandEvent extends IslandBaseEvent {
this.previousName = previousName;
return this;
}
/**
* Addon that triggered this event, e.g. BSkyBlock
* @param addon Addon.
@ -389,4 +389,4 @@ public class IslandEvent extends IslandBaseEvent {
}
}
}
}

View File

@ -2,11 +2,8 @@ package world.bentobox.bentobox.commands;
import java.util.List;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.panels.reader.TemplateReader;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.commands.reload.BentoBoxReloadLocalesCommand;
@ -40,7 +37,7 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
public boolean execute(User user, String label, List<String> args) {
if (args.isEmpty()) {
this.askConfirmation(user, user.getTranslation("commands.bentobox.reload.warning"), () -> {
// Unregister all placeholders
getPlugin().getPlaceholdersManager().unregisterAll();
@ -53,22 +50,13 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
getPlugin().loadSettings();
user.sendMessage("commands.bentobox.reload.settings-reloaded");
// Reload addons
getPlugin().getAddonsManager().reloadAddons();
user.sendMessage("commands.bentobox.reload.addons-reloaded");
// Reload locales
getPlugin().getLocalesManager().reloadLanguages();
user.sendMessage("commands.bentobox.reload.locales-reloaded");
// Register new default gamemode placeholders
getPlugin().getAddonsManager().getGameModeAddons().forEach(getPlugin().getPlaceholdersManager()::registerDefaultPlaceholders);
// Call the all Loaded method for addons
getPlugin().getAddonsManager().allLoaded();
// Fire ready event
Bukkit.getPluginManager().callEvent(new BentoBoxReadyEvent());
});
} else {
showHelp(this, user);

View File

@ -55,6 +55,9 @@ import world.bentobox.bentobox.util.Util;
@Table(name = "Islands")
public class Island implements DataObject, MetaDataAble {
@Expose
private boolean primary;
/**
* Set to true if this data object has been changed since being loaded from the database
*/
@ -1648,12 +1651,15 @@ public class Island implements DataObject, MetaDataAble {
}
/**
* @return the homes
* Get the location of a named home
* @param name home name case insensitive (name is forced to lower case)
* @return the home location or if none found the protection center of the island is returned.
* @since 1.16.0
*/
@Nullable
@NonNull
public Location getHome(String name) {
return getHomes().get(name.toLowerCase());
Location l = getHomes().get(name.toLowerCase());
return l == null ? getProtectionCenter() : l;
}
/**
@ -1842,6 +1848,21 @@ public class Island implements DataObject, MetaDataAble {
setChanged();
}
/**
* @return the primary
*/
public boolean isPrimary() {
return primary;
}
/**
* @param primary the primary to set
*/
public void setPrimary(boolean primary) {
this.primary = primary;
setChanged();
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/

View File

@ -215,33 +215,30 @@ public class JoinLeaveListener implements Listener {
}
private void updateIslandRange(User user) {
plugin.getIWM().getOverWorlds().stream()
.filter(world -> plugin.getIslands().isOwner(world, user.getUniqueId()))
.forEach(world -> {
Island island = plugin.getIslands().getIsland(world, user);
if (island != null) {
// Check if new owner has a different range permission than the island size
int range = user.getPermissionValue(plugin.getIWM().getAddon(island.getWorld()).map(GameModeAddon::getPermissionPrefix).orElse("") + "island.range", island.getRawProtectionRange());
// Range cannot be greater than the island distance
range = Math.min(range, plugin.getIWM().getIslandDistance(island.getWorld()));
// Range can go up or down
if (range != island.getRawProtectionRange()) {
user.sendMessage("commands.admin.setrange.range-updated", TextVariables.NUMBER, String.valueOf(range));
int oldRange = island.getProtectionRange();
island.setProtectionRange(range);
plugin.getIslands().getIslands().stream()
.filter(island -> island.getOwner() != null && island.getOwner().equals(user.getUniqueId()))
.forEach(island -> {
// Check if new owner has a different range permission than the island size
int range = user.getPermissionValue(plugin.getIWM().getAddon(island.getWorld()).map(GameModeAddon::getPermissionPrefix).orElse("") + "island.range", island.getRawProtectionRange());
// Range cannot be greater than the island distance
range = Math.min(range, plugin.getIWM().getIslandDistance(island.getWorld()));
// Range can go up or down
if (range != island.getRawProtectionRange()) {
user.sendMessage("commands.admin.setrange.range-updated", TextVariables.NUMBER, String.valueOf(range));
int oldRange = island.getProtectionRange();
island.setProtectionRange(range);
plugin.log("Island protection range changed from " + oldRange + " to "
+ island.getProtectionRange() + " for " + user.getName() + " due to permission.");
// Call Protection Range Change event. Does not support canceling.
IslandEvent.builder()
.island(island)
.location(island.getProtectionCenter())
.reason(IslandEvent.Reason.RANGE_CHANGE)
.involvedPlayer(user.getUniqueId())
.admin(true)
.protectionRange(island.getProtectionRange(), oldRange)
.build();
}
plugin.log("Island protection range changed from " + oldRange + " to "
+ island.getProtectionRange() + " for " + user.getName() + " due to permission.");
// Call Protection Range Change event. Does not support canceling.
IslandEvent.builder()
.island(island)
.location(island.getProtectionCenter())
.reason(IslandEvent.Reason.RANGE_CHANGE)
.involvedPlayer(user.getUniqueId())
.admin(true)
.protectionRange(island.getProtectionRange(), oldRange)
.build();
}
});
}

View File

@ -0,0 +1,57 @@
package world.bentobox.bentobox.listeners;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.managers.IslandsManager;
/**
* Sets the player's primary island based on where they teleported or moved to
* @author tastybento
*
*/
public class PrimaryIslandListener implements Listener {
private final IslandsManager im;
/**
* @param plugin - plugin object
*/
public PrimaryIslandListener(@NonNull BentoBox plugin) {
this.im = plugin.getIslands();
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent event) {
setIsland(event.getPlayer(), event.getPlayer().getLocation());
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent event) {
if (event.getTo() != null && !event.getFrom().toVector().equals(event.getTo().toVector())) {
setIsland(event.getPlayer(), event.getTo());
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerMove(final PlayerTeleportEvent event) {
if (event.getTo() != null) {
setIsland(event.getPlayer(), event.getTo());
}
}
private void setIsland(Player player, Location location) {
im.getIslandAt(location)
.filter(i -> i.getOwner() != null && i.getOwner().equals(player.getUniqueId()))
.ifPresent(i -> im.setPrimaryIsland(player.getUniqueId(), i));
}
}

View File

@ -9,7 +9,6 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
@ -80,7 +79,9 @@ public class IslandsManager {
*/
private final Map<World, Location> last;
// Island Cache
/**
* Island Cache
*/
@NonNull
private IslandCache islandCache;
// Quarantined islands
@ -121,80 +122,6 @@ public class IslandsManager {
this.handler = handler;
}
/**
* This is a generic scan that can work in the overworld or the nether
* @param l - location around which to scan
* @param i - the range to scan for a location less than 0 means the full island.
* @return - safe location, or null if none can be found
*/
@Nullable
public Location bigScan(@NonNull Location l, int i) {
final int height;
final int depth;
if (i > 0) {
height = i;
depth = i;
} else {
Optional<Island> island = getIslandAt(l);
if (island.isEmpty()) {
return null;
}
i = island.get().getProtectionRange();
height = l.getWorld().getMaxHeight() - l.getBlockY();
depth = l.getBlockY();
}
// Work outwards from l until the closest safe location is found.
int minXradius = 0;
int maxXradius = 0;
int minZradius = 0;
int maxZradius = 0;
int minYradius = 0;
int maxYradius = 0;
do {
int minX = l.getBlockX()-minXradius;
int minZ = l.getBlockZ()-minZradius;
int minY = l.getBlockY()-minYradius;
int maxX = l.getBlockX()+maxXradius;
int maxZ = l.getBlockZ()+maxZradius;
int maxY = l.getBlockY()+maxYradius;
for (int x = minX; x<= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
if (!((x > minX && x < maxX) && (z > minZ && z < maxZ) && (y > minY && y < maxY))) {
Location ultimate = new Location(l.getWorld(), x + 0.5D, y, z + 0.5D);
if (isSafeLocation(ultimate)) {
return ultimate;
}
}
}
}
}
if (minXradius < i) {
minXradius++;
}
if (maxXradius < i) {
maxXradius++;
}
if (minZradius < i) {
minZradius++;
}
if (maxZradius < i) {
maxZradius++;
}
if (minYradius < depth) {
minYradius++;
}
if (maxYradius < height) {
maxYradius++;
}
} while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth
|| maxYradius < height);
// Nothing worked
return null;
}
/**
* Checks if this location is safe for a player to teleport to. Used by
* warps and boat exits Unsafe is any liquid or air and also if there's no
@ -347,17 +274,29 @@ public class IslandsManager {
}
}
/**
* Get the number of islands made on this server. Used by stats.
* @return total number of islands known to this server
*/
public int getIslandCount() {
return islandCache.size();
}
public int getIslandCount(@NonNull World world) {
/**
* Get the number of islands made on this server in a particular world. Used to limit the number of islands
* if required by settings.
* @param world game world
* @return number of islands
*/
public long getIslandCount(@NonNull World world) {
return islandCache.size(world);
}
/**
* Gets the island for this player.
* Gets the current active island for this player.
* If they are in a team, the team island is returned.
* If they have more than one island, then the island they are on now, or the last island they were on
* is returned.
* @param world world to check
* @param user user
* @return Island or null if not found or null user
@ -368,7 +307,33 @@ public class IslandsManager {
}
/**
* Gets the island for this player. If they are in a team, the team island is returned.
* Gets the islands for this player.
* If they are in a team, the team island is returned.
* @param world world to check
* @param user user
* @return List of islands or empty list if none found for user
*/
@NonNull
public Set<Island> getIslands(@NonNull World world, @NonNull User user){
return getIslands(world, user.getUniqueId());
}
/**
* Gets all the islands for this player in this world.
* If they are in a team, the team island is returned.
* @param world world to check
* @param uuid user's uuid
* @return List of islands or empty list if none found for user
*/
@NonNull
public Set<Island> getIslands(@NonNull World world, UUID uniqueId) {
return islandCache.getIslands(world, uniqueId);
}
/**
* Gets the active island for this player. If they are in a team, the team island is returned.
* User may have more than one island.
* Returns the island the player is on now, or their last known island.
* @param world world to check. Includes nether and end worlds.
* @param uuid user's uuid
* @return Island or null
@ -430,7 +395,7 @@ public class IslandsManager {
}
/**
* Returns the player's island location in World based on the island protection center.
* Returns the player's current island location in World based on the island protection center.
* If you need the actual island center location for some reason use {@link Island#getCenter()}<p>
*
* @param world - world to check
@ -463,6 +428,7 @@ public class IslandsManager {
* @param minimumRank - the minimum rank to be included in the set.
* @return Set of team UUIDs
*/
@NonNull
public Set<UUID> getMembers(@NonNull World world, @NonNull UUID playerUUID, int minimumRank) {
return islandCache.getMembers(world, playerUUID, minimumRank);
}
@ -476,6 +442,7 @@ public class IslandsManager {
* @param playerUUID - the player's UUID
* @return Set of team UUIDs
*/
@NonNull
public Set<UUID> getMembers(@NonNull World world, @NonNull UUID playerUUID) {
return islandCache.getMembers(world, playerUUID, RanksManager.MEMBER_RANK);
}
@ -580,11 +547,11 @@ public class IslandsManager {
* Get a safe home location using async chunk loading and set the home location
* @param world - world
* @param user - user
* @param name - home name
* @param homeName - home name
* @return CompletableFuture with the location found, or null
* @since 1.14.0
*/
private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World world, @NonNull User user, String name) {
private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World world, @NonNull User user, String homeName) {
CompletableFuture<Location> result = new CompletableFuture<>();
// Check if the world is a gamemode world and the player has an island
Location islandLoc = getIslandLocation(world, user.getUniqueId());
@ -592,9 +559,18 @@ public class IslandsManager {
result.complete(null);
return result;
}
// Check if the user is switching island and if so, switch name
String name = this.getIslands(world, user).stream()
.filter(i -> !homeName.isBlank() && i.getName() != null && !i.getName().isBlank() && i.getName().equalsIgnoreCase(homeName))
.findFirst().map(island -> {
// This is an island, so switch to that island and then go to the default home
this.setPrimaryIsland(user.getUniqueId(), island);
return "";
}).orElse(homeName);
// Try the home location first
Location defaultHome = getHomeLocation(world, user);
Location namedHome = getHomeLocation(world, user, name);
Location namedHome = homeName.isBlank() ? null : getHomeLocation(world, user, name);
Location l = namedHome != null ? namedHome : defaultHome;
if (l != null) {
Util.getChunkAtAsync(l).thenRun(() -> {
@ -813,27 +789,27 @@ public class IslandsManager {
}
/**
* Get the home location for user in world
* Get the home location for user in world for their primary island
* @param world - world
* @param user - user
* @return home location or null if there is no home
* @since 1.16.0
* @return home location or the protection center location if no home defined
* @since 2.0.0
*/
@Nullable
public Location getHomeLocation(@NonNull World world, @NonNull User user) {
return getHomeLocation(world, user, "");
return this.getPrimaryIsland(world, user.getUniqueId()).getHome("");
}
/**
* Get the home location for player's UUID in world
* Get the home location for player's UUID in world for their primary island
* @param world - world
* @param uuid - uuid of player
* @return home location or null if there is no home
* @return home location or the protection center location if no home defined
* @since 1.16.0
*/
@Nullable
public Location getHomeLocation(@NonNull World world, @NonNull UUID uuid) {
return getHomeLocation(world, uuid, "");
return this.getPrimaryIsland(world, uuid).getHome("");
}
/**
@ -859,37 +835,7 @@ public class IslandsManager {
*/
@Nullable
public Location getHomeLocation(@NonNull World world, @NonNull UUID uuid, String name) {
// Migrate from player homes to island homes
Island island = this.getIsland(world, uuid);
if (island == null) {
return null;
}
migrateHomes(world, uuid, name, island);
return getHomeLocation(island, name);
}
@SuppressWarnings("removal")
private void migrateHomes(@NonNull World world, @NonNull UUID uuid, String name, Island island) {
Map<Location, Integer> homes = plugin
.getPlayers()
.getHomeLocations(world, uuid);
if (homes.isEmpty()) {
// No migration required
return;
}
if (island.getOwner() != null && island.getOwner().equals(uuid)) {
// Owner
island.setHomes(homes.entrySet().stream().collect(Collectors.toMap(this::getHomeName, Map.Entry::getKey)));
plugin.getPlayers().clearHomeLocations(world, uuid);
}
}
private String getHomeName(Entry<Location, Integer> e) {
// Home 1 has an empty name
if (e.getValue() == 1) {
return "";
}
return String.valueOf(e.getValue());
return getIslands(world, uuid).stream().map(is -> is.getHome(name)).filter(Objects::nonNull).findFirst().orElse(null);
}
/**
@ -912,7 +858,7 @@ public class IslandsManager {
*/
@NonNull
public Location getHomeLocation(@NonNull Island island, @NonNull String name) {
return Objects.requireNonNullElse(island.getHome(name), island.getCenter());
return Objects.requireNonNullElse(island.getHome(name), island.getProtectionCenter());
}
/**
@ -1038,7 +984,7 @@ public class IslandsManager {
*
* @param world - world to check
* @param player - the player
* @param name - a named home location. Blank means default.
* @param name - a named home location or island name. Blank means default home for current island.
* @return CompletableFuture true if successful, false if not
* @since 1.16.0
*/
@ -1061,6 +1007,14 @@ public class IslandsManager {
}
/**
* Teleports player async
* @param world world
* @param player player
* @param name - a named home location or island name. Blank means default home for current island.
* @param newIsland true if this is a new island
* @return completable future that is true when the teleport has been completed
*/
private CompletableFuture<Boolean> homeTeleportAsync(@NonNull World world, @NonNull Player player, String name, boolean newIsland) {
CompletableFuture<Boolean> result = new CompletableFuture<>();
User user = User.getInstance(player);
@ -1081,10 +1035,6 @@ public class IslandsManager {
.thenAccept(result::complete);
return;
}
// Add home
if (getHomeLocations(island).isEmpty()) {
setHomeLocation(player.getUniqueId(), home);
}
PaperLib.teleportAsync(player, home).thenAccept(b -> {
// Only run the commands if the player is successfully teleported
if (Boolean.TRUE.equals(b)) {
@ -1186,6 +1136,10 @@ public class IslandsManager {
}
}
/**
* Prepares the player for teleporting by: stopping gliding, exiting any boats and giving the player the boat
* @param player player
*/
private void readyPlayer(@NonNull Player player) {
// Stop any gliding
player.setGliding(false);
@ -1421,10 +1375,7 @@ public class IslandsManager {
* @param uuid - user's uuid
*/
public void removePlayer(World world, UUID uuid) {
Island island = islandCache.removePlayer(world, uuid);
if (island != null) {
handler.saveObjectAsync(island);
}
islandCache.removePlayer(world, uuid).forEach(handler::saveObjectAsync);
}
/**
@ -1520,15 +1471,6 @@ public class IslandsManager {
this.last.put(last.getWorld(), last);
}
/**
* Called when a player leaves a team
* @param world - world
* @param uuid - the player's UUID
*/
public void setLeaveTeam(World world, UUID uuid) {
removePlayer(world, uuid);
}
public void shutdown(){
plugin.log("Removing coops from islands...");
// Remove all coop associations
@ -1563,12 +1505,15 @@ public class IslandsManager {
/**
* Sets this target as the owner for this island
* @param user requester
* @param user previous owner
* @param targetUUID new owner
* @param island island to register
*/
public void setOwner(User user, UUID targetUUID, Island island) {
islandCache.setOwner(island, targetUUID);
// Remove the old owner from the island
island.removeMember(user.getUniqueId());
user.sendMessage("commands.island.team.setowner.name-is-the-owner", "[name]", plugin.getPlayers().getName(targetUUID));
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon -> {
User target = User.getInstance(targetUUID);
@ -1893,4 +1838,33 @@ public class IslandsManager {
return goingHome.contains(user.getUniqueId());
}
/**
* Get the number of concurrent islands for this player
* @param uuid UUID of player
* @param world world to check
* @return number of islands this player owns in this game world
*/
public int getNumberOfConcurrentIslands(UUID uuid, World world) {
return islandCache.getIslands(world, uuid).size();
}
/**
* Sets the user's primary island
* @param uuid user's uuid
* @param i island
*/
public void setPrimaryIsland(UUID uuid, Island i) {
this.getIslandCache().setPrimaryIsland(uuid, i);
}
/**
* Convenience method. See {@link IslandCache#get(World, UUID)}
* @param world world
* @param uuid player's UUID
* @return Island of player or null if there isn't one
*/
public Island getPrimaryIsland(World world, UUID uuid) {
return this.getIslandCache().get(world, uuid);
}
}

View File

@ -10,7 +10,6 @@ import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
@ -191,108 +190,6 @@ public class PlayersManager {
return uniqueID != null && (playerCache.containsKey(uniqueID) || handler.objectExists(uniqueID.toString()));
}
/**
* Sets the home location for the player
* @param user - the player
* @param location - the location
* @param number - a number - 1 is default. Can be any number.
* @deprecated Use {@link IslandsManager#setHomeLocation(User, Location, String)}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void setHomeLocation(User user, Location location, int number) {
setHomeLocation(user.getUniqueId(), location,number);
}
/**
* Sets the home location for the player
* @param playerUUID - the player's UUID
* @param location - the location
* @param number - a number - 1 is default. Can be any number.
* @deprecated Use {@link IslandsManager#setHomeLocation(UUID, Location, String)}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void setHomeLocation(UUID playerUUID, Location location, int number) {
addPlayer(playerUUID);
playerCache.get(playerUUID).setHomeLocation(location,number);
}
/**
* Set the default home location for player
* @param playerUUID - the player's UUID
* @param location - the location
* @deprecated Use {@link IslandsManager#setHomeLocation(UUID, Location)}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void setHomeLocation(UUID playerUUID, Location location) {
setHomeLocation(playerUUID, location,1);
}
/**
* Clears any home locations for player
* @param world - world
* @param playerUUID - the player's UUID
* @deprecated Not used anymore. Home locations are stored on islands.
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void clearHomeLocations(World world, UUID playerUUID) {
addPlayer(playerUUID);
playerCache.get(playerUUID).clearHomeLocations(world);
}
/**
* Returns the home location, or null if none
* @param world - world
*
* @param user - the player
* @param number - a number
* @return Home location or null if none
* @deprecated Use {@link IslandsManager#getHomeLocation(World, User, String)}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public Location getHomeLocation(World world, User user, int number) {
addPlayer(user.getUniqueId());
return playerCache.get(user.getUniqueId()).getHomeLocation(world, number);
}
/**
* Returns the home location, or null if none
* @param world - world
*
* @param playerUUID - the player's UUID
* @param number - a number
* @return Home location or null if none
* @deprecated Use {@link IslandsManager#getHomeLocation(World, UUID, String)}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public Location getHomeLocation(World world, UUID playerUUID, int number) {
addPlayer(playerUUID);
return playerCache.get(playerUUID).getHomeLocation(world, number);
}
/**
* Gets the default home location for player
* @param playerUUID - the player's UUID
* @return Home location or null if none
* @deprecated Use {@link IslandsManager#getHomeLocation(World, UUID)}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public Location getHomeLocation(World world, UUID playerUUID) {
addPlayer(playerUUID);
return playerCache.get(playerUUID).getHomeLocation(world, 1);
}
/**
* Provides all home locations for player
* @param playerUUID - the player's UUID
* @return Map of home locations
* @deprecated Use {@link IslandsManager#getHomeLocations(world.bentobox.bentobox.database.objects.Island)}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public Map<Location, Integer> getHomeLocations(World world, UUID playerUUID) {
addPlayer(playerUUID);
return playerCache.get(playerUUID).getHomeLocations(world);
}
/**
* Attempts to return a UUID for a given player's name.
* @param name - name of player

View File

@ -5,9 +5,9 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.World;
@ -20,6 +20,7 @@ import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
/**
* This class stores the islands in memory
* @author tastybento
*/
public class IslandCache {
@ -34,7 +35,8 @@ public class IslandCache {
* Every player who is associated with an island is in this map.
*/
@NonNull
private final Map<@NonNull World, @NonNull Map<@NonNull UUID, @NonNull Island>> islandsByUUID;
private final Map<@NonNull UUID, Set<Island>> islandsByUUID;
@NonNull
private final Map<@NonNull World, @NonNull IslandGrid> grids;
@ -62,12 +64,10 @@ public class IslandCache {
if (addToGrid(island)) {
islandsByLocation.put(island.getCenter(), island);
islandsById.put(island.getUniqueId(), island);
// Make world
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>());
// Only add islands to this map if they are owned
if (island.isOwned()) {
islandsByUUID.get(island.getWorld()).put(island.getOwner(), island);
island.getMemberSet().forEach(member -> islandsByUUID.get(island.getWorld()).put(member, island));
islandsByUUID.computeIfAbsent(island.getOwner(), k -> new HashSet<>()).add(island);
island.getMemberSet().forEach(member -> addPlayer(member, island));
}
return true;
}
@ -80,7 +80,7 @@ public class IslandCache {
* @param island island to associate with this uuid. Only one island can be associated per world.
*/
public void addPlayer(@NonNull UUID uuid, @NonNull Island island) {
islandsByUUID.computeIfAbsent(island.getWorld(), k -> new HashMap<>()).put(uuid, island);
islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).add(island);
}
/**
@ -99,21 +99,27 @@ public class IslandCache {
}
/**
* Deletes an island from the cache.. Does not remove blocks
* Deletes an island from the cache. Does not remove blocks.
* @param island island to delete
* @return true if successful, false if not
*/
public boolean deleteIslandFromCache(@NonNull Island island) {
if (!islandsByLocation.remove(island.getCenter(), island) || !islandsByUUID.containsKey(island.getWorld())) {
if (!islandsByLocation.remove(island.getCenter(), island)) {
return false;
}
islandsById.remove(island.getUniqueId());
islandsByUUID.get(island.getWorld()).entrySet().removeIf(en -> en.getValue().equals(island));
removeFromIslandsByUUID(island);
// Remove from grid
grids.putIfAbsent(island.getWorld(), new IslandGrid());
return grids.get(island.getWorld()).removeFromGrid(island);
}
private void removeFromIslandsByUUID(Island island) {
for (Set<Island> set : islandsByUUID.values()) {
set.removeIf(island::equals);
}
}
/**
* Delete island from the cache by ID. Does not remove blocks.
* @param uniqueId - island unique ID
@ -121,7 +127,9 @@ public class IslandCache {
public void deleteIslandFromCache(@NonNull String uniqueId) {
islandsById.remove(uniqueId);
islandsByLocation.values().removeIf(i -> i.getUniqueId().equals(uniqueId));
islandsByUUID.values().forEach(m -> m.values().removeIf(i -> i.getUniqueId().equals(uniqueId)));
for (Set<Island> set : islandsByUUID.values()) {
set.removeIf(i -> i.getUniqueId().equals(uniqueId));
}
}
/**
@ -135,18 +143,52 @@ public class IslandCache {
}
/**
* Returns island referenced by UUID
* Returns island referenced by player's UUID.
* Returns the island the player is on now, or their last known island
* @param world world to check. Includes nether and end worlds.
* @param uuid player's UUID
* @return island or null if none
*/
@Nullable
public Island get(@NonNull World world, @NonNull UUID uuid) {
World w = Util.getWorld(world);
if (w == null) {
Set<Island> islands = getIslands(world, uuid);
if (islands.isEmpty()) {
return null;
}
return islandsByUUID.containsKey(w) ? islandsByUUID.get(w).get(uuid) : null;
for (Island island : islands) {
if (island.isPrimary()) {
return island;
}
}
// If there is no primary set, then set one - it doesn't matter which.
Island result = islands.iterator().next();
result.setPrimary(true);
return result;
}
/**
* Returns all the islands referenced by player's UUID.
* @param world world to check. Includes nether and end worlds.
* @param uuid player's UUID
* @return list of island or empty list if none
*/
public Set<Island> getIslands(@NonNull World world, @NonNull UUID uuid) {
World w = Util.getWorld(world);
if (w == null) {
return new HashSet<>();
}
return islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).stream().filter(i -> world.equals(i.getWorld())).collect(Collectors.toSet());
}
/**
* Sets the current island for the user as their primary island
* @param uuid UUID of user
* @param island island to make primary
*/
public void setPrimaryIsland(@NonNull UUID uuid, @NonNull Island island) {
for (Island is : getIslands(island.getWorld(), uuid)) {
is.setPrimary(island.equals(is));
}
}
/**
@ -192,49 +234,44 @@ public class IslandCache {
}
/**
* Get the members of the user's team
* @param world world to check
* @param uuid uuid of player to check
* @param minimumRank minimum rank requested
* @return set of UUID's of island members. If there is no island, this set will be empty
* @return set of UUID's of island members. If there are no islands, this set will be empty
*/
@NonNull
public Set<UUID> getMembers(@NonNull World world, @NonNull UUID uuid, int minimumRank) {
World w = Util.getWorld(world);
if (w == null) {
return new HashSet<>();
}
Island island = islandsByUUID.computeIfAbsent(w, k -> new HashMap<>()).get(uuid);
return island != null ? island.getMemberSet(minimumRank) : new HashSet<>();
return getIslands(world, uuid)
.stream()
.flatMap(island -> island.getMemberSet(minimumRank).stream())
.collect(Collectors.toSet());
}
/**
* Get the UUID of the owner of the island of the player, which may be their UUID
* @param world the world to check
* @param uuid the player's UUID
* @return island owner's UUID, the player UUID if they are not in a team, or null if there is no island
* @return island owner's UUID or null if there is no island
*/
@Nullable
public UUID getOwner(@NonNull World world, @NonNull UUID uuid) {
World w = Util.getWorld(world);
if (w == null) {
Set<Island> islands = islandsByUUID.get(uuid);
if (w == null || islands == null || islands.isEmpty()) {
return null;
}
Island island = islandsByUUID.computeIfAbsent(w, k -> new HashMap<>()).get(uuid);
return island != null ? island.getOwner() : null;
return islands.iterator().next().getOwner(); // This assumes that all islands in this set have the same owner
}
/**
* Checks is a player has an island and owns it
* @param world the world to check
* @param uuid the player
* @return true if player has island and owns it
*/
public boolean hasIsland(@NonNull World world, @NonNull UUID uuid) {
World w = Util.getWorld(world);
if (w == null) {
return false;
}
Island island = islandsByUUID.computeIfAbsent(w, k -> new HashMap<>()).get(uuid);
return island != null && uuid.equals(island.getOwner());
return uuid.equals(getOwner(world, uuid));
}
/**
@ -242,27 +279,27 @@ public class IslandCache {
* The island is removed from the islandsByUUID map, but kept in the location map.
* @param world world
* @param uuid player's UUID
* @return island player had or null if none
* @return list of islands player had or empty if none
*/
@Nullable
public Island removePlayer(@NonNull World world, @NonNull UUID uuid) {
public Set<Island> removePlayer(@NonNull World world, @NonNull UUID uuid) {
World w = Util.getWorld(world);
if (w == null) {
return null;
Set<Island> islandSet = islandsByUUID.get(uuid);
if (w == null || islandSet == null) {
return Collections.emptySet(); // Return empty list if no islands map exists for the world
}
Island island = islandsByUUID.computeIfAbsent(w, k -> new HashMap<>()).get(uuid);
if (island != null) {
islandSet.forEach(island -> {
if (uuid.equals(island.getOwner())) {
// Clear ownership and members
island.getMembers().clear();
island.setOwner(null);
} else {
// Remove player from the island membership
island.removeMember(uuid);
}
}
islandsByUUID.get(w).remove(uuid);
return island;
});
islandsByUUID.remove(uuid);
return islandSet;
}
/**
@ -278,8 +315,8 @@ public class IslandCache {
* @param world world to get the number of islands in
* @return the number of islands
*/
public int size(World world) {
return islandsByUUID.getOrDefault(world, new HashMap<>(0)).size();
public long size(World world) {
return this.islandsByLocation.keySet().stream().map(Location::getWorld).filter(world::equals).count();
}
/**
@ -291,7 +328,7 @@ public class IslandCache {
public void setOwner(@NonNull Island island, @Nullable UUID newOwnerUUID) {
island.setOwner(newOwnerUUID);
if (newOwnerUUID != null) {
islandsByUUID.computeIfAbsent(Objects.requireNonNull(Util.getWorld(island.getWorld())), k -> new HashMap<>()).put(newOwnerUUID, island);
islandsByUUID.computeIfAbsent(newOwnerUUID, k -> new HashSet<>()).add(island);
}
islandsByLocation.put(island.getCenter(), island);
islandsById.put(island.getUniqueId(), island);
@ -316,13 +353,12 @@ public class IslandCache {
public void removeIsland(@NonNull Island island) {
islandsByLocation.values().removeIf(island::equals);
islandsById.values().removeIf(island::equals);
islandsByUUID.values().removeIf(island::equals);
World w = Util.getWorld(island.getWorld());
if (w == null) {
return;
}
if (islandsByUUID.containsKey(w)) {
islandsByUUID.get(w).values().removeIf(island::equals);
}
if (grids.containsKey(w)) {
grids.get(w).removeFromGrid(island);
}

View File

@ -322,4 +322,4 @@ public class NewIsland {
.build();
}
}
}

View File

@ -119,6 +119,9 @@ logs:
# Added since 1.5.0.
github-download-data: true
island:
# The default number of concurrent islands a player may have.
# This may be overridden by individual game mode config settings.
concurrent-islands: 1
cooldown:
time:
# How long a player must wait until they can rejoin a team island after being kicked in minutes.

View File

@ -863,9 +863,9 @@ protection:
island: 'Ostrov [name]'
name: Hlášení o návštěvě/opuštění
now-entering: '&a Právě vcházíš na &b [name]&a .'
now-entering-your-island: '&a Právě vcházíš na svůj ostrov.'
now-entering-your-island: '&a Právě vcházíš na svůj ostrov: &b [name]'
now-leaving: '&a Právě odcházíš od &b [name]&a .'
now-leaving-your-island: '&a Právě odcházíš ze svého ostrova.'
now-leaving-your-island: '&a Právě odcházíš ze svého ostrova: &b [name]'
EXPERIENCE_BOTTLE_THROWING:
name: Házení zkošenostními lahvičkami
description: Přepnout házení zkušenostními lahvičkami.

View File

@ -978,9 +978,9 @@ protection:
island: "[name]'s Insel"
name: Ein- und Ausgangsmeldungen
now-entering: "&b Du betrittst jetzt [name]"
now-entering-your-island: "&a Geben Sie jetzt Ihre Insel ein."
now-entering-your-island: "&a Geben Sie jetzt Ihre Insel ein: &b [name]"
now-leaving: "&b Du verlässt jetzt [name]"
now-leaving-your-island: "&a Verlasse jetzt deine Insel."
now-leaving-your-island: "&a Verlasse jetzt deine Insel: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: Erfahrungsflasche werfen
description: Umschalten des Werfens von Erfahrungsflaschen.

File diff suppressed because it is too large Load Diff

View File

@ -909,9 +909,9 @@ protection:
island: Isla de [name]
name: Mensaje de Entrada/Salida
now-entering: "&bEntrando a [name]"
now-entering-your-island: "&a Ahora entrando en tu isla."
now-entering-your-island: "&a Ahora entrando en tu isla: &b [name]"
now-leaving: "&bSaliendo de [name]"
now-leaving-your-island: "&a Ahora saliendo de tu isla."
now-leaving-your-island: "&a Ahora saliendo de tu isla: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: Lanzamiento de botellas de experiencia
description: Modificar lanzamiento de experiencia.

View File

@ -1003,9 +1003,9 @@ protection:
island: "[name]"
name: Enter/Exit messages
now-entering: "&a Entrer maintenant &b [nom] &a."
now-entering-your-island: "&a Vous venez d'entrer sur votre île."
now-entering-your-island: "&a Vous venez d'entrer sur votre île: &b [name]"
now-leaving: "&a Quittant maintenant &b [nom] &a."
now-leaving-your-island: "&a Vous venez de quitter votre île."
now-leaving-your-island: "&a Vous venez de quitter votre île: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
description: Toggle throwing experience bottles.
hint: Bouteilles d'expérience désactivées

View File

@ -992,8 +992,8 @@ protection:
name: Messaggi di Entrata/Uscita
now-entering: "&bStai entrando in [name]"
now-leaving: "&bStai uscendo da [name]"
now-entering-your-island: "&a Stai entrando nella tua isola."
now-leaving-your-island: "&a Stai uscendo dalla tua isola."
now-entering-your-island: "&a Stai entrando nella tua isola: &b [name]"
now-leaving-your-island: "&a Stai uscendo dalla tua isola: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
description: Abilita/disabilita lancio di boccette di esperienza.
hint: Lancio di boccette di esperienza disabilitato

View File

@ -1008,9 +1008,9 @@ protection:
island: "[name]の島"
name: 入り口/終了メッセージ
now-entering: 今[name]を入力する
now-entering-your-island: "&a今あなたの島に入っています。"
now-leaving: 今[name]を残し
now-leaving-your-island: "&a今あなたの島を去ります。"
now-entering-your-island: "&a今あなたの島に入っています。 &b [name]"
now-leaving-your-island: "&a今あなたの島を去ります。 &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: ボトル投げ体験
description: エクスペリエンスボトルの投げを切り替えます。

View File

@ -870,9 +870,9 @@ protection:
island: "[name]의 섬"
name: 출입 메시지
now-entering: "&b [name]&a으로 진입했습니다 ."
now-entering-your-island: "&a 자신의 섬으로 왔습니다."
now-entering-your-island: "&a 자신의 섬으로 왔습니다. &b [name]"
now-leaving: "&b [name]&a에서 떠나는 중입니다 ."
now-leaving-your-island: "&a 자신의 섬에서 떠나는 중입니다"
now-leaving-your-island: "&a 자신의 섬에서 떠나는 중입니다. &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: 경험치병 던지기
description: 경험치병을 던질수 있는지여부를 설정합니다

View File

@ -1009,8 +1009,8 @@ protection:
name: Ieejas/Izejas ziņa
now-entering: "&bTu ieej [name] salā"
now-leaving: "&bTu pamet [name] salu"
now-entering-your-island: "&a Tu ieej savā salā."
now-leaving-your-island: "&a Tu pamet savu salu."
now-entering-your-island: "&a Tu ieej savā salā: &b [name]"
now-leaving-your-island: "&a Tu pamet savu salu: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
description: Pārslēdz pieredzes pudeļu mešanu
hint: Pieredžu pudeļu mešana nav atļauta

View File

@ -976,9 +976,9 @@ protection:
island: Het eiland van [name]
name: Berichten invoeren / verlaten
now-entering: "&a Voer nu &b [name] in &a."
now-entering-your-island: "&a Nu betreedt u uw eiland."
now-entering-your-island: "&a Nu betreedt u uw eiland: &b [name]"
now-leaving: "&a Nu weggaan &b [name] &a."
now-leaving-your-island: "&a Verlaat nu je eiland."
now-leaving-your-island: "&a Verlaat nu je eiland: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: Ervaar het gooien van flessen
description: Wissel met het werpen van ervaringsflessen.

View File

@ -884,8 +884,8 @@ protection:
name: Wiadomości wejścia / wyjścia
now-entering: Wchodzisz na wyspę [name]
now-leaving: Wychodzisz z wyspy [name]
now-entering-your-island: '&a Wchodzisz na swoją wyspę.'
now-leaving-your-island: '&a Opuszczasz swoją wyspę.'
now-entering-your-island: '&a Wchodzisz na swoją wyspę: &b [name]'
now-leaving-your-island: '&a Opuszczasz swoją wyspę: &b [name]'
EXPERIENCE_BOTTLE_THROWING:
name: Rzucanie butelkami z doświadczeniem
description: Przełącz rzucanie butelkami z doświadczeniem

View File

@ -915,9 +915,9 @@ protection:
island: ilha de [name]
name: Mensagens de entrada/saída
now-entering: '&a Entrando na &b [name]&a .'
now-entering-your-island: '&a Entrando em sua ilha.'
now-entering-your-island: '&a Entrando em sua ilha: &b [name]'
now-leaving: '&a Deixando a &b [name]&a .'
now-leaving-your-island: '&a Deixando sua ilha.'
now-leaving-your-island: '&a Deixando sua ilha: &b [name]'
EXPERIENCE_BOTTLE_THROWING:
name: Arremesso de frasco de experiência
description: Permitir arremesso de frascos de experiência

View File

@ -949,9 +949,9 @@ protection:
island: insula [numele]
name: Introduceți / ieșiți din mesaje
now-entering: "&a Acum introduceți &b [name] &a."
now-entering-your-island: "&a Acum intrând în insula ta."
now-entering-your-island: "&a Acum intrând în insula ta: &b [name]"
now-leaving: "&a Acum plecăm de la &b [name] &a."
now-leaving-your-island: "&a Acum părăsind insula ta."
now-leaving-your-island: "&a Acum părăsind insula ta: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: Experimentați aruncarea cu sticle
description: Comutați aruncarea sticlelor de experiență.

View File

@ -976,9 +976,9 @@ protection:
island: "[name]"
name: Giriş/çıkış mesajları
now-entering: "&d[name] &badasına girdin!"
now-entering-your-island: "&aAdana giriş yaptın."
now-entering-your-island: "&aAdana giriş yaptın: &b [name]"
now-leaving: "&d[name] &badasından çıktın!"
now-leaving-your-island: "&aAdandan çıktın."
now-leaving-your-island: "&aAdandan çıktın: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: XP şisesi fırlatması
description: XP şişe fırlatılmasını değiş.

View File

@ -978,9 +978,9 @@ protection:
island: đảo của [name]
name: Thông báo Vào/Ra
now-entering: "&a Đang vào &b [name]&a ."
now-entering-your-island: "&a Đang vào đảo của bạn."
now-entering-your-island: "&a Đang vào đảo của bạn: &b [name]"
now-leaving: "&a Đang rời &b [name]&a ."
now-leaving-your-island: "&a Đang rời đảo của bạn."
now-leaving-your-island: "&a Đang rời đảo của bạn: &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: Quăng bình kinh nghiệm
description: Bật/Tắt quăng bình kinh nghiệm.

View File

@ -953,9 +953,9 @@ protection:
island: "[name] 的岛屿"
name: "&a&l进出岛屿提示"
now-entering: "&a您已进入 &b[name] &a。"
now-entering-your-island: "&a您已进入自己的岛屿。"
now-entering-your-island: "&a您已进入自己的岛屿。 &b [name]"
now-leaving: "&6您已离开 &b[name] &a。"
now-leaving-your-island: "&6您已离开自己的岛屿。"
now-leaving-your-island: "&6您已离开自己的岛屿。 &b [name]"
EXPERIENCE_BOTTLE_THROWING:
name: "&a&l投掷经验瓶"
description: 允许/禁止 在岛上扔经验瓶

View File

@ -973,9 +973,9 @@ protection:
island: '[name] 的島嶼'
name: '&a&l進出島嶼提示'
now-entering: '&a您已進入 &b[name] &a。'
now-entering-your-island: '&a您已進入自己的島嶼。'
now-entering-your-island: '&a您已進入自己的島嶼。 &b [name]'
now-leaving: '&6您已離開 &b[name] &a。'
now-leaving-your-island: '&6您已離開自己的島嶼。'
now-leaving-your-island: '&6您已離開自己的島嶼。 &b [name]'
EXPERIENCE_BOTTLE_THROWING:
name: '&a&l投擲經驗瓶'
description: 允許/禁止 在島上扔經驗瓶

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.addons;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;

View File

@ -11,18 +11,22 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -49,12 +53,20 @@ import world.bentobox.bentobox.util.Util;
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
public class AdminDeleteCommandTest {
@Mock
private CompositeCommand ac;
@Mock
private User user;
@Mock
private IslandsManager im;
@Mock
private PlayersManager pm;
private UUID notUUID;
private UUID uuid;
@Mock
private World world;
@Mock
private @Nullable Island island;
/**
*/
@ -79,7 +91,6 @@ public class AdminDeleteCommandTest {
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
user = mock(User.class);
when(user.isOp()).thenReturn(false);
uuid = UUID.randomUUID();
notUUID = UUID.randomUUID();
@ -92,9 +103,9 @@ public class AdminDeleteCommandTest {
User.setPlugin(plugin);
// Parent command has no aliases
ac = mock(CompositeCommand.class);
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ac.getTopLabel()).thenReturn("admin");
when(ac.getWorld()).thenReturn(world);
// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
@ -102,15 +113,17 @@ public class AdminDeleteCommandTest {
// Player has island to begin with
im = mock(IslandsManager.class);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
when(im.isOwner(any(),any())).thenReturn(true);
when(im.getOwner(any(),any())).thenReturn(uuid);
when(im.getIsland(world, user)).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
// Island
when(island.getOwner()).thenReturn(uuid);
// Has team
pm = mock(PlayersManager.class);
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
when(plugin.getPlayers()).thenReturn(pm);
@ -162,10 +175,9 @@ public class AdminDeleteCommandTest {
@Test
public void testExecutePlayerNoIsland() {
AdminDeleteCommand itl = new AdminDeleteCommand(ac);
String[] name = {"tastybento"};
when(pm.getUUID(any())).thenReturn(notUUID);
when(im.getOwner(any(), any())).thenReturn(null);
assertFalse(itl.canExecute(user, itl.getLabel(), Arrays.asList(name)));
when(im.getIsland(world, user)).thenReturn(null);
assertFalse(itl.canExecute(user, "", List.of("tastybento")));
verify(user).sendMessage(eq("general.errors.player-has-no-island"));
}
@ -174,6 +186,7 @@ public class AdminDeleteCommandTest {
*/
@Test
public void testExecuteOwner() {
when(im.inTeam(any(),any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(notUUID);
String[] name = {"tastybento"};

View File

@ -1,6 +1,9 @@
package world.bentobox.bentobox.api.commands.admin.blueprints;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;

View File

@ -229,8 +229,8 @@ public class AdminTeamDisbandCommandTest {
AdminTeamDisbandCommand itl = new AdminTeamDisbandCommand(ac);
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
verify(im, never()).setLeaveTeam(any(), eq(notUUID));
verify(im).setLeaveTeam(any(), eq(uuid));
verify(is, never()).removeMember(notUUID);
verify(is).removeMember(uuid);
verify(user).sendMessage("commands.admin.team.disband.success", TextVariables.NAME, name[0]);
verify(p).sendMessage("commands.admin.team.disband.disbanded");
verify(p2).sendMessage("commands.admin.team.disband.disbanded");

View File

@ -18,8 +18,10 @@ import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
@ -37,6 +39,7 @@ import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
@ -75,6 +78,12 @@ public class IslandCreateCommandTest {
private CompositeCommand ic;
@Mock
private BlueprintsManager bpm;
@Mock
private World world;
@Mock
private @NonNull WorldSettings ws;
@Mock
private Island island;
/**
*/
@ -115,6 +124,7 @@ public class IslandCreateCommandTest {
when(ic.getUsage()).thenReturn("");
when(ic.getSubCommand(Mockito.anyString())).thenReturn(Optional.empty());
when(ic.getAddon()).thenReturn(addon);
when(ic.getWorld()).thenReturn(world);
// No island for player to begin with (set it later in the tests)
@ -122,7 +132,7 @@ public class IslandCreateCommandTest {
when(im.isOwner(any(), eq(uuid))).thenReturn(false);
// Has team
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
when(im.getPrimaryIsland(world, uuid)).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
@ -136,6 +146,8 @@ public class IslandCreateCommandTest {
// IWM friendly name
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(ws.getConcurrentIslands()).thenReturn(1); // One island allowed
when(iwm.getWorldSettings(world)).thenReturn(ws);
when(plugin.getIWM()).thenReturn(iwm);
// NewIsland
@ -190,11 +202,11 @@ public class IslandCreateCommandTest {
*/
@Test
public void testCanExecuteUserStringListOfStringHasIsland() {
@Nullable
Island island = mock(Island.class);
when(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
// Currently user has two islands
when(im.getNumberOfConcurrentIslands(user.getUniqueId(), world)).thenReturn(2);
// Player has an island
assertFalse(cc.canExecute(user, "", Collections.emptyList()));
verify(user).sendMessage(eq("general.errors.already-have-island"));
verify(user).sendMessage("general.errors.you-cannot-make");
}
/**
@ -207,7 +219,7 @@ public class IslandCreateCommandTest {
when(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
when(island.isReserved()).thenReturn(true);
assertTrue(cc.canExecute(user, "", Collections.emptyList()));
verify(user, never()).sendMessage(eq("general.errors.already-have-island"));
verify(user, never()).sendMessage("general.errors.already-have-island");
}
@ -216,12 +228,12 @@ public class IslandCreateCommandTest {
*/
@Test
public void testCanExecuteUserStringListOfStringTooManyIslands() {
when(im.hasIsland(any(), Mockito.any(UUID.class))).thenReturn(false);
when(im.getPrimaryIsland(any(), Mockito.any(UUID.class))).thenReturn(null);
when(im.inTeam(any(), Mockito.any(UUID.class))).thenReturn(false);
when(iwm.getMaxIslands(any())).thenReturn(100);
when(im.getIslandCount(any())).thenReturn(100);
when(im.getIslandCount(any())).thenReturn(100L);
assertFalse(cc.canExecute(user, "", Collections.emptyList()));
verify(user).sendMessage(eq("commands.island.create.too-many-islands"));
verify(user).sendMessage("commands.island.create.too-many-islands");
}

View File

@ -14,12 +14,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.NonNull;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
@ -67,6 +69,10 @@ public class IslandDeletehomeCommandTest {
private IslandDeletehomeCommand idh;
@Mock
private IslandWorldManager iwm;
@Mock
private @NonNull World world;
@Mock
private Location location;
/**
* @throws java.lang.Exception
@ -100,6 +106,7 @@ public class IslandDeletehomeCommandTest {
when(ic.getUsage()).thenReturn("");
when(ic.getSubCommand(Mockito.anyString())).thenReturn(Optional.empty());
when(ic.getAddon()).thenReturn(addon);
when(ic.getWorld()).thenReturn(world);
when(plugin.getIslands()).thenReturn(im);
// Player
Player player = mock(Player.class);
@ -108,13 +115,14 @@ public class IslandDeletehomeCommandTest {
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(player);
when(user.getName()).thenReturn("tastybento");
when(user.getWorld()).thenReturn(mock(World.class));
when(user.getWorld()).thenReturn(world);
when(user.getTranslation(anyString())).thenAnswer(i -> i.getArgument(0, String.class));
// Island
when(island.getOwner()).thenReturn(uuid);
when(island.onIsland(any())).thenReturn(true);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getIsland(world, uuid)).thenReturn(island);
when(im.getIsland(world, user)).thenReturn(island);
when(im.getIslands(world, uuid)).thenReturn(Set.of(island));
@NotNull
Map<String, Location> homeMap = new HashMap<>();
homeMap.put("Home", null);
@ -175,7 +183,7 @@ public class IslandDeletehomeCommandTest {
@Test
public void testCanExecuteHelp() {
idh.canExecute(user, "label", List.of());
verify(user).sendMessage("commands.help.header","[label]","commands.help.console");
verify(user).sendMessage("commands.help.header","[label]","BSkyBlock");
}
/**
@ -201,41 +209,28 @@ public class IslandDeletehomeCommandTest {
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandDeletehomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandDeletehomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteUnknownHome() {
when(island.getRank(user)).thenReturn(RanksManager.OWNER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.COOP_RANK);
when(island.getHomes()).thenReturn(Map.of("home", mock(Location.class)));
public void testExecuteUnknownHome() {
when(island.getHomes()).thenReturn(Map.of("home", location));
when(im.isHomeLocation(eq(island), anyString())).thenReturn(false);
assertFalse(idh.canExecute(user, "label", List.of("something")));
assertFalse(idh.execute(user, "label", List.of("something")));
verify(user).sendMessage("commands.island.go.unknown-home");
verify(user).sendMessage("commands.island.sethome.homes-are");
verify(user).sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, "home");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandDeletehomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteKnownHome() {
when(island.getRank(user)).thenReturn(RanksManager.OWNER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.COOP_RANK);
when(island.getHomes()).thenReturn(Map.of("home", mock(Location.class)));
when(im.isHomeLocation(eq(island), anyString())).thenReturn(true);
assertTrue(idh.canExecute(user, "label", List.of("home")));
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandDeletehomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfString() {
when(island.getHomes()).thenReturn(Map.of("home", location));
when(im.isHomeLocation(eq(island), anyString())).thenReturn(true);
assertTrue(idh.execute(user, "label", List.of("home")));
verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "10");
}
@ -245,7 +240,7 @@ public class IslandDeletehomeCommandTest {
*/
@Test
public void testTabCompleteUserStringListOfString() {
when(island.getHomes()).thenReturn(Map.of("home", mock(Location.class)));
when(island.getHomes()).thenReturn(Map.of("home", location));
Optional<List<String>> list = idh.tabComplete(user, "label", List.of("hom"));
assertTrue(list.isPresent());
assertEquals("home", list.get().get(0));
@ -256,7 +251,7 @@ public class IslandDeletehomeCommandTest {
*/
@Test
public void testTabCompleteUserStringListOfStringNothing() {
when(island.getHomes()).thenReturn(Map.of("home", mock(Location.class)));
when(island.getHomes()).thenReturn(Map.of("home", location));
Optional<List<String>> list = idh.tabComplete(user, "label", List.of("f"));
assertTrue(list.isPresent());
assertTrue(list.get().isEmpty());

View File

@ -90,6 +90,7 @@ public class IslandGoCommandTest {
@Mock
private World world;
private @Nullable WorldSettings ws;
private UUID uuid = UUID.randomUUID();
/**
*/
@ -108,7 +109,6 @@ public class IslandGoCommandTest {
// Player
when(player.isOp()).thenReturn(false);
UUID uuid = UUID.randomUUID();
when(player.getUniqueId()).thenReturn(uuid);
when(player.getName()).thenReturn("tastybento");
when(player.getWorld()).thenReturn(world);
@ -123,10 +123,12 @@ public class IslandGoCommandTest {
// Have the create command point to the ic command
Optional<CompositeCommand> createCommand = Optional.of(ic);
when(ic.getSubCommand(eq("create"))).thenReturn(createCommand);
when(ic.getWorld()).thenReturn(world);
// No island for player to begin with (set it later in the tests)
when(im.hasIsland(any(), eq(uuid))).thenReturn(false);
when(im.isOwner(any(), eq(uuid))).thenReturn(false);
// Player has island by default
when(im.getIslands(world, uuid)).thenReturn(Set.of(island));
when(im.hasIsland(world, uuid)).thenReturn(true);
when(im.isOwner(world, uuid)).thenReturn(true);
when(plugin.getIslands()).thenReturn(im);
// Has team
@ -200,7 +202,7 @@ public class IslandGoCommandTest {
*/
@Test
public void testExecuteNoArgsNoIsland() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
when(im.getIslands(world, uuid)).thenReturn(Set.of());
assertFalse(igc.canExecute(user, igc.getLabel(), Collections.emptyList()));
verify(player).sendMessage("general.errors.no-island");
}
@ -210,7 +212,6 @@ public class IslandGoCommandTest {
*/
@Test
public void testExecuteNoArgs() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
assertTrue(igc.canExecute(user, igc.getLabel(), Collections.emptyList()));
}
@ -219,7 +220,6 @@ public class IslandGoCommandTest {
*/
@Test
public void testExecuteNoArgsReservedIsland() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(ic.call(any(), any(), any())).thenReturn(true);
when(island.isReserved()).thenReturn(true);
assertFalse(igc.canExecute(user, igc.getLabel(), Collections.emptyList()));
@ -232,7 +232,7 @@ public class IslandGoCommandTest {
@Test
public void testExecuteNoArgsReservedIslandNoCreateCommand() {
when(ic.getSubCommand(eq("create"))).thenReturn(Optional.empty());
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(ic.call(any(), any(), any())).thenReturn(true);
when(island.isReserved()).thenReturn(true);
assertFalse(igc.canExecute(user, igc.getLabel(), Collections.emptyList()));
@ -265,7 +265,7 @@ public class IslandGoCommandTest {
*/
@Test
public void testExecuteNoArgsMultipleHomes() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
//when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3);
assertTrue(igc.execute(user, igc.getLabel(), Collections.emptyList()));
}
@ -275,30 +275,10 @@ public class IslandGoCommandTest {
*/
@Test
public void testExecuteArgs1MultipleHomes() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
//when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3);
assertTrue(igc.execute(user, igc.getLabel(), Collections.singletonList("1")));
}
/**
* Test method for {@link IslandGoCommand#execute(User, String, List)}
*/
@Test
public void testExecuteArgs2MultipleHomes() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
//when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3);
assertTrue(igc.execute(user, igc.getLabel(), Collections.singletonList("2")));
}
/**
* Test method for {@link IslandGoCommand#execute(User, String, List)}
*/
@Test
public void testExecuteArgsJunkMultipleHomes() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
//when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3);
assertTrue(igc.execute(user, igc.getLabel(), Collections.singletonList("sdfghhj")));
assertFalse(igc.execute(user, igc.getLabel(), Collections.singletonList("1")));
verify(player).sendMessage("commands.island.go.unknown-home");
verify(player).sendMessage("commands.island.sethome.homes-are");
verify(player).sendMessage("commands.island.sethome.home-list-syntax");
}
/**
@ -307,7 +287,7 @@ public class IslandGoCommandTest {
@Test
public void testExecuteNoArgsDelay() {
when(s.getDelayTime()).thenReturn(10);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
assertTrue(igc.execute(user, igc.getLabel(), Collections.emptyList()));
verify(player).sendMessage(eq("commands.delay.stand-still"));
}
@ -327,19 +307,6 @@ public class IslandGoCommandTest {
verify(player, Mockito.times(2)).sendMessage(eq("commands.delay.stand-still"));
}
/**
* Test method for {@link IslandGoCommand#execute(User, String, List)}
*/
@Test
public void testExecuteNoArgsDelayMultiHome() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
//when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3);
when(s.getDelayTime()).thenReturn(10);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
assertTrue(igc.execute(user, igc.getLabel(), Collections.singletonList("2")));
verify(player).sendMessage(eq("commands.delay.stand-still"));
}
/**
* Test method for {@link IslandGoCommand#onPlayerMove(PlayerMoveEvent)}
*/

View File

@ -15,6 +15,7 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -22,6 +23,7 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
@ -65,6 +67,8 @@ public class IslandHomesCommandTest {
private Island island;
@Mock
private IslandWorldManager iwm;
@Mock
private @NonNull World world;
/**
*/
@ -89,13 +93,14 @@ public class IslandHomesCommandTest {
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(player);
when(user.getName()).thenReturn("tastybento");
when(user.getWorld()).thenReturn(mock(World.class));
when(user.getWorld()).thenReturn(world);
when(user.getTranslation(anyString())).thenAnswer(i -> i.getArgument(0, String.class));
// Parent command has no aliases
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ic.getTopLabel()).thenReturn("island");
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
when(ic.getWorld()).thenReturn(world);
// No island for player to begin with (set it later in the tests)
when(im.hasIsland(any(), any(User.class))).thenReturn(false);
@ -171,8 +176,6 @@ public class IslandHomesCommandTest {
@Test
public void testCanExecuteNoIsland() {
// Player doesn't have an island
when(im.getIsland(any(), eq(user))).thenReturn(null);
IslandHomesCommand isc = new IslandHomesCommand(ic);
assertFalse(isc.canExecute(user, "island", Collections.emptyList()));
verify(user).sendMessage("general.errors.no-island");
@ -183,6 +186,7 @@ public class IslandHomesCommandTest {
*/
@Test
public void testCanExecute() {
when(im.getIslands(world, user)).thenReturn(Set.of(island));
IslandHomesCommand isc = new IslandHomesCommand(ic);
assertTrue(isc.canExecute(user, "island", Collections.emptyList()));
verify(user, never()).sendMessage("general.errors.no-island");
@ -193,6 +197,7 @@ public class IslandHomesCommandTest {
*/
@Test
public void testExecuteUserStringListOfString() {
when(im.getIslands(world, user)).thenReturn(Set.of(island));
IslandHomesCommand isc = new IslandHomesCommand(ic);
assertTrue(isc.canExecute(user, "island", Collections.emptyList()));
assertTrue(isc.execute(user, "island", Collections.emptyList()));

View File

@ -449,4 +449,4 @@ public class IslandResetCommandTest {
verify(pim, times(14)).callEvent(any(IslandBaseEvent.class));
}
}
}

View File

@ -14,12 +14,14 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -64,6 +66,8 @@ public class IslandSethomeCommandTest {
private IslandWorldManager iwm;
@Mock
private WorldSettings ws;
@Mock
private @NonNull World world;
/**
*/
@ -88,17 +92,19 @@ public class IslandSethomeCommandTest {
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(player);
when(user.getName()).thenReturn("tastybento");
when(user.getWorld()).thenReturn(mock(World.class));
when(user.getWorld()).thenReturn(world);
when(user.getTranslation(anyString())).thenAnswer(i -> i.getArgument(0, String.class));
// Parent command has no aliases
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ic.getTopLabel()).thenReturn("island");
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
when(ic.getWorld()).thenReturn(world);
// No island for player to begin with (set it later in the tests)
when(im.hasIsland(any(), any(User.class))).thenReturn(false);
when(im.isOwner(any(), eq(uuid))).thenReturn(false);
// Island for player to begin with
when(im.hasIsland(world, user)).thenReturn(true);
when(im.isOwner(world, uuid)).thenReturn(true);
when(im.getIslands(world, user)).thenReturn(Set.of(island));
when(plugin.getIslands()).thenReturn(im);
// Has team
@ -168,7 +174,7 @@ public class IslandSethomeCommandTest {
@Test
public void testCanExecuteNoIsland() {
// Player doesn't have an island
when(im.getIsland(any(), eq(user))).thenReturn(null);
when(im.getIsland(world, user)).thenReturn(null);
IslandSethomeCommand isc = new IslandSethomeCommand(ic);
assertFalse(isc.canExecute(user, "island", Collections.emptyList()));

View File

@ -103,6 +103,7 @@ public class IslandTeamCommandTest {
when(plugin.getIslands()).thenReturn(im);
// is owner of island
when(im.getOwner(any(), any())).thenReturn(uuid);
when(im.getPrimaryIsland(world, uuid)).thenReturn(island);
// Max members
when(im.getMaxMembers(eq(island), eq(RanksManager.MEMBER_RANK))).thenReturn(3);
// No team members
@ -160,7 +161,7 @@ public class IslandTeamCommandTest {
*/
@Test
public void testExecuteUserStringListOfStringNoIsland() {
when(im.getOwner(any(), any())).thenReturn(null);
when(im.getPrimaryIsland(world, uuid)).thenReturn(null);
assertFalse(tc.execute(user, "team", Collections.emptyList()));
verify(user).sendMessage(eq("general.errors.no-island"));
}
@ -190,7 +191,7 @@ public class IslandTeamCommandTest {
*/
@Test
public void testAddInvite() {
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island);
assertTrue(tc.isInvited(invitee));
}
@ -207,7 +208,7 @@ public class IslandTeamCommandTest {
*/
@Test
public void testGetInviter() {
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island);
assertEquals(uuid, tc.getInviter(invitee));
}
@ -225,7 +226,7 @@ public class IslandTeamCommandTest {
@Test
public void testGetInvite() {
assertNull(tc.getInvite(invitee));
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island);
@Nullable
Invite invite = tc.getInvite(invitee);
assertEquals(invitee, invite.getInvitee());
@ -239,7 +240,7 @@ public class IslandTeamCommandTest {
@Test
public void testRemoveInvite() {
assertNull(tc.getInvite(invitee));
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island);
tc.removeInvite(invitee);
assertNull(tc.getInvite(invitee));
}

View File

@ -17,9 +17,11 @@ import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -76,6 +78,8 @@ public class IslandTeamInviteCommandTest {
private UUID notUUID;
@Mock
private Player p;
@Mock
private @NonNull World world;
/**
@ -106,7 +110,7 @@ public class IslandTeamInviteCommandTest {
when(user.isOnline()).thenReturn(true);
// Permission to invite 3 more players
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3);
when(User.getInstance(eq(uuid))).thenReturn(user);
when(User.getInstance(uuid)).thenReturn(user);
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
// Vanished players
when(p.canSee(any())).thenReturn(true);
@ -119,11 +123,12 @@ public class IslandTeamInviteCommandTest {
when(target.isOnline()).thenReturn(true);
when(target.getName()).thenReturn("target");
when(target.getDisplayName()).thenReturn("&Ctarget");
when(User.getInstance(eq(notUUID))).thenReturn(target);
when(User.getInstance(notUUID)).thenReturn(target);
// Parent command has no aliases
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ic.getWorld()).thenReturn(world);
// Island
islandUUID = UUID.randomUUID();
@ -144,8 +149,8 @@ public class IslandTeamInviteCommandTest {
// Player Manager
when(plugin.getPlayers()).thenReturn(pm);
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
when(pm.getUUID(eq("target"))).thenReturn(notUUID);
when(pm.getUUID("tastybento")).thenReturn(uuid);
when(pm.getUUID("target")).thenReturn(notUUID);
// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
@ -227,7 +232,7 @@ public class IslandTeamInviteCommandTest {
public void testCanExecuteNoTarget() {
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
// Show help
verify(user).sendMessage(eq("commands.help.header"),eq(TextVariables.LABEL),eq("commands.help.console"));
verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "BSkyBlock");
}
/**
@ -294,12 +299,13 @@ public class IslandTeamInviteCommandTest {
*/
@Test
public void testExecuteSuccessTargetHasIsland() {
when(im.hasIsland(any(), eq(notUUID))).thenReturn(true);
when(im.getIsland(world, uuid)).thenReturn(island);
when(im.hasIsland(world, notUUID)).thenReturn(true);
testCanExecuteSuccess();
assertTrue(itl.execute(user, itl.getLabel(), List.of("target")));
verify(pim).callEvent(any(IslandBaseEvent.class));
verify(user, never()).sendMessage(eq("commands.island.team.invite.removing-invite"));
verify(ic).addInvite(eq(Invite.Type.TEAM), eq(uuid), eq(notUUID));
verify(ic).addInvite(Invite.Type.TEAM, uuid, notUUID, island);
verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget");
verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento", TextVariables.DISPLAY_NAME, "&Ctastbento");
verify(target).sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, "island");
@ -313,10 +319,11 @@ public class IslandTeamInviteCommandTest {
@Test
public void testExecuteSuccessTargetHasNoIsland() {
testCanExecuteSuccess();
when(im.getIsland(world, uuid)).thenReturn(island);
assertTrue(itl.execute(user, itl.getLabel(), List.of("target")));
verify(pim).callEvent(any(IslandBaseEvent.class));
verify(user, never()).sendMessage("commands.island.team.invite.removing-invite");
verify(ic).addInvite(Invite.Type.TEAM, uuid, notUUID);
verify(ic).addInvite(Invite.Type.TEAM, uuid, notUUID, island);
verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget");
verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento", TextVariables.DISPLAY_NAME, "&Ctastbento");
verify(target).sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, "island");
@ -330,7 +337,7 @@ public class IslandTeamInviteCommandTest {
@Test
public void testExecuteTargetAlreadyInvited() {
testCanExecuteSuccess();
when(im.getIsland(world, uuid)).thenReturn(island);
when(ic.isInvited(notUUID)).thenReturn(true);
// Set up invite
when(ic.getInviter(notUUID)).thenReturn(uuid);

View File

@ -18,6 +18,7 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -66,6 +67,8 @@ public class IslandTeamLeaveCommandTest {
private PlayersManager pm;
@Mock
private World world;
@Mock
private @Nullable Island island;
/**
*/
@ -120,10 +123,8 @@ public class IslandTeamLeaveCommandTest {
when(Bukkit.getPluginManager()).thenReturn(pim);
// Island
Island island = mock(Island.class);
when(island.getUniqueId()).thenReturn("uniqueid");
when(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
when(im.getIsland(world, user)).thenReturn(island);
}
@ -161,7 +162,7 @@ public class IslandTeamLeaveCommandTest {
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
verify(im).setLeaveTeam(any(), eq(uuid));
verify(island).removeMember(uuid);
verify(user).sendMessage(eq("commands.island.team.leave.success"));
}
@ -220,10 +221,10 @@ public class IslandTeamLeaveCommandTest {
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
verify(im).setLeaveTeam(any(), eq(uuid));
verify(user).sendMessage(eq("commands.island.team.leave.success"));
verify(island).removeMember(uuid);
verify(user).sendMessage("commands.island.team.leave.success");
verify(pm).addReset(eq(world), eq(uuid));
verify(user).sendMessage(eq("commands.island.reset.resets-left"), eq(TextVariables.NUMBER), eq("100"));
verify(user).sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, "100");
}
/**

View File

@ -12,6 +12,7 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@ -20,6 +21,7 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
@ -35,6 +37,7 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
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.user.User;
import world.bentobox.bentobox.database.objects.Island;
@ -119,6 +122,10 @@ public class IslandTeamSetownerCommandTest {
// Island World Manager
when(plugin.getIWM()).thenReturn(iwm);
@NonNull
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(world)).thenReturn(ws);
when(ws.getConcurrentIslands()).thenReturn(3);
// Plugin Manager
PluginManager pim = mock(PluginManager.class);
@ -152,81 +159,101 @@ public class IslandTeamSetownerCommandTest {
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringNullOwner() {
public void testCanExecuteUserStringListOfStringNullOwner() {
when(im.getOwner(any(), any())).thenReturn(null);
assertFalse(its.execute(user, "", Collections.emptyList()));
assertFalse(its.canExecute(user, "", List.of("gibby")));
verify(user).sendMessage("general.errors.not-owner");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringNotInTeam() {
public void testCanExecuteUserStringListOfStringNotInTeam() {
when(im.inTeam(any(), any())).thenReturn(false);
assertFalse(its.execute(user, "", Collections.emptyList()));
assertFalse(its.canExecute(user, "", List.of("gibby")));
verify(user).sendMessage("general.errors.no-team");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringNotOwner() {
public void testCanExecuteUserStringListOfStringNotOwner() {
when(im.inTeam(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(UUID.randomUUID());
assertFalse(its.execute(user, "", Collections.emptyList()));
assertFalse(its.canExecute(user, "", List.of("gibby")));
verify(user).sendMessage("general.errors.not-owner");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringShowHelp() {
public void testCanExecuteUserStringListOfStringShowHelp() {
when(im.inTeam(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
assertFalse(its.execute(user, "", Collections.emptyList()));
assertFalse(its.canExecute(user, "", Collections.emptyList()));
verify(user).sendMessage("commands.help.header","[label]", null);
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringUnknownPlayer() {
public void testCanExecuteUserStringListOfStringUnknownPlayer() {
when(im.inTeam(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
when(pm.getUUID(anyString())).thenReturn(null);
assertFalse(its.execute(user, "", Collections.singletonList("tastybento")));
assertFalse(its.canExecute(user, "", Collections.singletonList("tastybento")));
verify(user).sendMessage("general.errors.unknown-player", TextVariables.NAME, "tastybento");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringSamePlayer() {
public void testCanExecuteUserStringListOfStringSamePlayer() {
when(im.inTeam(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
when(pm.getUUID(anyString())).thenReturn(uuid);
assertFalse(its.execute(user, "", Collections.singletonList("tastybento")));
assertFalse(its.canExecute(user, "", Collections.singletonList("tastybento")));
verify(user).sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringTargetNotInTeam() {
public void testCanExecuteUserStringListOfStringTargetAtMaxIslands() {
when(im.inTeam(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
UUID target = UUID.randomUUID();
when(pm.getUUID(anyString())).thenReturn(target);
when(im.getMembers(any(), any())).thenReturn(Collections.singleton(target));
@Nullable
Island island = mock(Island.class);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getNumberOfConcurrentIslands(target, world)).thenReturn(3);
assertFalse(its.canExecute(user, "", Collections.singletonList("tastybento")));
verify(user).sendMessage("commands.island.team.setowner.errors.at-max");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteUserStringListOfStringTargetNotInTeam() {
when(im.inTeam(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
when(pm.getUUID(anyString())).thenReturn(UUID.randomUUID());
when(im.getMembers(any(), any())).thenReturn(Collections.singleton(uuid));
assertFalse(its.execute(user, "", Collections.singletonList("tastybento")));
assertFalse(its.canExecute(user, "", Collections.singletonList("tastybento")));
verify(user).sendMessage("commands.island.team.setowner.errors.target-is-not-member");
}
@ -243,7 +270,7 @@ public class IslandTeamSetownerCommandTest {
@Nullable
Island island = mock(Island.class);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
assertTrue(its.canExecute(user, "", Collections.singletonList("tastybento")));
assertTrue(its.execute(user, "", Collections.singletonList("tastybento")));
verify(im).setOwner(any(), eq(user), eq(target));
verify(im).save(island);

View File

@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.bentobox.database.objects;
import static org.junit.Assert.assertEquals;
@ -1156,7 +1153,7 @@ public class IslandTest {
*/
@Test
public void testGetHome() {
assertNull(i.getHome("default"));
assertEquals(i.getProtectionCenter(), i.getHome("default"));
}
/**

View File

@ -162,6 +162,7 @@ public class JoinLeaveListenerTest {
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(im.getIslands()).thenReturn(Collections.singletonList(island));
Map<UUID, Integer> memberMap = new HashMap<>();
memberMap.put(uuid, RanksManager.OWNER_RANK);

View File

@ -58,8 +58,6 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
private BreakBlocksListener bbl;
/**
*/
@Override
@Before
public void setUp() throws Exception {
@ -100,7 +98,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
*/
@ -115,7 +113,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
*/

View File

@ -16,8 +16,8 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerRespawnEvent.RespawnReason;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.After;
import org.junit.Before;

View File

@ -249,6 +249,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
when(islandCache.getIslandAt(any(Location.class))).thenReturn(island);
when(islandCache.get(any(), any())).thenReturn(island);
optionalIsland = Optional.ofNullable(island);
when(islandCache.getIslands(world, uuid)).thenReturn(Set.of(island));
// User location
when(user.getLocation()).thenReturn(location);
@ -531,16 +532,6 @@ public class IslandsManagerTest extends AbstractCommonSetup {
assertTrue("Wall sign 2", im.isSafeLocation(location));
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#bigScan(org.bukkit.Location, int)}.
*/
@Test
public void testBigScan() {
// Negative value = full island scan
// No island here yet
assertNull(im.bigScan(location, -1));
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#createIsland(org.bukkit.Location)}.
*/
@ -716,7 +707,6 @@ public class IslandsManagerTest extends AbstractCommonSetup {
im.setIslandCache(islandCache);
when(island.getHome(any())).thenReturn(location);
when(iwm.inWorld(eq(world))).thenReturn(true);
assertEquals(location, im.getSafeHomeLocation(world, user, ""));
// Change location so that it is not safe

View File

@ -1,6 +1,10 @@
package world.bentobox.bentobox.managers;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;

View File

@ -16,6 +16,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.World;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -81,6 +82,9 @@ public class IslandCacheTest {
// Island
when(island.getWorld()).thenReturn(world);
@NonNull
String uniqueId = UUID.randomUUID().toString();
when(island.getUniqueId()).thenReturn(uniqueId);
// Location
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(0);
@ -248,9 +252,8 @@ public class IslandCacheTest {
@Test
public void testGetOwner() {
ic.addIsland(island);
// Should be no owner, so null
assertEquals(owner, ic.getOwner(world, owner));
assertNull(ic.getOwner(world, null));
assertNull(ic.getOwner(world, UUID.randomUUID()));
}
@ -263,7 +266,6 @@ public class IslandCacheTest {
assertTrue(ic.hasIsland(world, owner));
assertFalse(ic.hasIsland(world, UUID.randomUUID()));
assertFalse(ic.hasIsland(world, null));
}
/**
@ -273,7 +275,6 @@ public class IslandCacheTest {
public void testRemovePlayer() {
ic.addIsland(island);
assertTrue(ic.hasIsland(world, owner));
ic.removePlayer(world, null);
assertTrue(ic.hasIsland(world, owner));
ic.removePlayer(world, UUID.randomUUID());
assertTrue(ic.hasIsland(world, owner));

View File

@ -317,4 +317,4 @@ public class NewIslandTest {
verify(plugin).logError("New island for user tastybento was not reserved!");
}
}
}