Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.18.0 #1860

Merged
merged 7 commits into from
Sep 26, 2021
Merged

1.18.0 #1860

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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.17.4</build.version>
<build.version>1.18.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public void onEnable(){
completeSetup(loadTime);
} catch (Exception e) {
fireCriticalError(e.getMessage(), "");
e.printStackTrace();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private void deletePlayer(User user, UUID targetUUID) {
vector = oldIsland.getCenter().toVector();
getIslands().deleteIsland(oldIsland, true, targetUUID);
}
getPlayers().clearHomeLocations(getWorld(), targetUUID);
if (vector == null) {
user.sendMessage("general.success");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ private void setSpawn(User user, Island i) {
.build();
}
// If island is owned, then unregister the owner and any members
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
getIslands().removePlayer(getWorld(), m);
getPlayers().clearHomeLocations(getWorld(), m);
});
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m ->
getIslands().removePlayer(getWorld(), m));
}
getIslands().setSpawn(i);
i.setSpawnPoint(World.Environment.NORMAL, user.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ void unregisterPlayer(User user, String targetName, UUID targetUUID) {
.rankChange(RanksManager.OWNER_RANK, RanksManager.VISITOR_RANK)
.build();
// Remove all island members
oldIsland.getMemberSet().forEach(m -> {
getIslands().removePlayer(getWorld(), m);
getPlayers().clearHomeLocations(getWorld(), m);
});
oldIsland.getMemberSet().forEach(m -> getIslands().removePlayer(getWorld(), m));
// Remove all island players that reference this island
oldIsland.getMembers().clear();
getIslands().save(oldIsland);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public boolean execute(User user, String label, @NonNull List<String> args) {
target.sendMessage("commands.admin.team.kick.admin-kicked");

getIslands().removePlayer(getWorld(), targetUUID);
getPlayers().clearHomeLocations(getWorld(), targetUUID);
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner()));

// Fire event so add-ons know
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ private void deleteOldIsland(User user, Island oldIsland) {

// Add a reset
getPlayers().addReset(getWorld(), user.getUniqueId());

// Reset the homes of the player
getPlayers().clearHomeLocations(getWorld(), user.getUniqueId());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean canExecute(User user, String label, List<String> args) {
// Check number of homes
int maxHomes = getIslands().getMaxHomes(island);
if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes) {
user.sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, String.valueOf(island.getMaxHomes()));
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));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ private void acceptTeamInvite(User user, Invite invite) {
cleanPlayer(user);
// Add the player as a team member of the new island
getIslands().setJoinTeam(teamIsland, playerUUID);
//Move player to team's island
getPlayers().clearHomeLocations(getWorld(), playerUUID);
// Move player to team's island
getIslands().homeTeleportAsync(getWorld(), user.getPlayer()).thenRun(() -> {
// Delete the old island
if (island != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/world/bentobox/bentobox/api/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private String translate(String addonPrefix, String reference, String[] variable
// Replace the [gamemode] text variable
prefixTranslation = prefixTranslation.replace("[gamemode]", addon != null ? addon.getDescription().getName() : "[gamemode]");
// Replace the [friendly_name] text variable
prefixTranslation = prefixTranslation.replace("[friendly_name]", getWorld() != null ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
prefixTranslation = prefixTranslation.replace("[friendly_name]", isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");

// Replace the prefix in the actual message
translation = translation.replace("[prefix_" + prefix + "]", prefixTranslation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,8 @@ public boolean renameHome(String oldName, String newName) {
}

/**
* Get the max homes. You shouldn't access this directly.
* Use {@link world.bentobox.bentobox.managers.IslandsManager#getMaxHomes(Island)}
* @return the maxHomes. If null, then the world default should be used.
* @since 1.16.0
*/
Expand All @@ -1477,6 +1479,8 @@ public Integer getMaxHomes() {

/**
* @param maxHomes the maxHomes to set. If null then the world default will be used.
* You shouldn't access this directly.
* Use {@link world.bentobox.bentobox.managers.IslandsManager#setMaxHomes(Island, Integer)}
* @since 1.16.0
*/
public void setMaxHomes(@Nullable Integer maxHomes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public Players(BentoBox plugin, UUID uniqueId) {
* Gets the default home location.
* @param world - world to check
* @return Location - home location in world
* @deprecated Homes are stored in the Island object now
*/
@Deprecated(since="1.18.0", forRemoval=true)
@Nullable
public Location getHomeLocation(World world) {
return getHomeLocation(world, 1); // Default
Expand All @@ -101,7 +103,9 @@ public Location getHomeLocation(World world) {
* @param world - includes world and any related nether or end worlds
* @param number - a number
* @return Location of this home or null if not available
* @deprecated Homes are stored in the island object now
*/
@Deprecated(since="1.18.0", forRemoval=true)
@Nullable
public Location getHomeLocation(World world, int number) {
// Remove any lost worlds/locations
Expand All @@ -116,7 +120,9 @@ public Location getHomeLocation(World world, int number) {
/**
* @param world - world
* @return List of home locations
* @deprecated Homes are stored in the island object now
*/
@Deprecated(since="1.18.0", forRemoval=true)
public Map<Location, Integer> getHomeLocations(World world) {
// Remove any lost worlds/locations
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null);
Expand All @@ -126,7 +132,9 @@ public Map<Location, Integer> getHomeLocations(World world) {

/**
* @return the homeLocations
* @deprecated Homes are stored in the Island object now
*/
@Deprecated(since="1.18.0", forRemoval=true)
public Map<Location, Integer> getHomeLocations() {
// Remove any lost worlds/locations
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null);
Expand All @@ -135,7 +143,9 @@ public Map<Location, Integer> getHomeLocations() {

/**
* @param homeLocations the homeLocations to set
* @deprecated Homes are stored in the Island object now
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void setHomeLocations(Map<Location, Integer> homeLocations) {
this.homeLocations = homeLocations;
// Remove any lost worlds/locations
Expand Down Expand Up @@ -195,9 +205,10 @@ public void setResets(World world, int resets) {
/**
* Stores the home location of the player in a String format
*
* @param l
* a Bukkit location
* @param l a Bukkit location
* @deprecated Home locations are stored in islands
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void setHomeLocation(final Location l) {
setHomeLocation(l, 1);
}
Expand All @@ -206,7 +217,9 @@ public void setHomeLocation(final Location l) {
* Stores the numbered home location of the player. Numbering starts at 1.
* @param location - the location
* @param number - a number
* @deprecated Home locations are no longer stored for players. They are stored in islands.
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void setHomeLocation(Location location, int number) {
// Remove any home locations in the same world with the same number
homeLocations.entrySet().removeIf(e -> e.getKey() == null || (Util.sameWorld(location.getWorld(), e.getKey().getWorld()) && e.getValue().equals(number)));
Expand All @@ -224,7 +237,9 @@ public void setPlayerUUID(UUID uuid) {
/**
* Clears all home Locations in world
* @param world - world
* @deprecated Home locations are no longer stored for players. Use {@link IslandManager}
*/
@Deprecated(since="1.18.0", forRemoval=true)
public void clearHomeLocations(World world) {
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null || Util.sameWorld(l.getWorld(), world));
}
Expand Down
54 changes: 35 additions & 19 deletions src/main/java/world/bentobox/bentobox/managers/IslandsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ public int getMaxHomes(@NonNull Island island) {
islandMax = owner.getPermissionValue(plugin.getIWM().getPermissionPrefix(island.getWorld())
+ "island.maxhomes", islandMax);
}
// If the island maxHomes is just the same as the world default, then set to null
island.setMaxHomes(islandMax == plugin.getIWM().getMaxHomes(island.getWorld()) ? null : islandMax);
this.save(island);
return islandMax;
Expand Down Expand Up @@ -668,6 +669,7 @@ private void tryIsland(CompletableFuture<Location> result, Location islandLoc, @
* @param name - named home location. Blank means default.
* @return Location of a safe teleport spot or {@code null} if one cannot be found or if the world is not an island world.
*/
@Nullable
public Location getSafeHomeLocation(@NonNull World world, @NonNull User user, String name) {
// Check if the world is a gamemode world
if (!plugin.getIWM().inWorld(world)) {
Expand Down Expand Up @@ -745,6 +747,17 @@ public Location getSafeHomeLocation(@NonNull World world, @NonNull User user, St
return null;
}

/**
* Sets a default home location on user's island. Replaces previous default location.
* @param user - user
* @param location - location on island
* @return true if home location was set. False if this location is not on the island.
* @since 1.18.0
*/
public boolean setHomeLocation(@NonNull User user, Location location) {
return setHomeLocation(user.getUniqueId(), location, "");
}

/**
* Sets a home location on user's island. Replaces previous location if the same name is used
* @param user - user
Expand Down Expand Up @@ -801,10 +814,10 @@ public boolean setHomeLocation(@Nullable Island island, Location location, Strin
* Get the home location for user in world
* @param world - world
* @param user - user
* @return home location
* @return home location or null if there is no home
* @since 1.16.0
*/
@NonNull
@Nullable
public Location getHomeLocation(@NonNull World world, @NonNull User user) {
return getHomeLocation(world, user, "");
}
Expand All @@ -813,10 +826,10 @@ public Location getHomeLocation(@NonNull World world, @NonNull User user) {
* Get the home location for player's UUID in world
* @param world - world
* @param uuid - uuid of player
* @return home location
* @return home location or null if there is no home
* @since 1.16.0
*/
@NonNull
@Nullable
public Location getHomeLocation(@NonNull World world, @NonNull UUID uuid) {
return getHomeLocation(world, uuid, "");
}
Expand All @@ -826,10 +839,10 @@ public Location getHomeLocation(@NonNull World world, @NonNull UUID uuid) {
* @param world - world
* @param user - user
* @param name - name of home, or blank for default
* @return home location
* @return home location or null if there is no home
* @since 1.16.0
*/
@NonNull
@Nullable
public Location getHomeLocation(@NonNull World world, @NonNull User user, String name) {
return getHomeLocation(world, user.getUniqueId(), name);
}
Expand All @@ -839,13 +852,16 @@ public Location getHomeLocation(@NonNull World world, @NonNull User user, String
* @param world - world
* @param uuid - uuid of player
* @param name - name of home, or blank for default
* @return home location
* @return home location or null if there is no home
* @since 1.16.0
*/
@NonNull
@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);
}
Expand Down Expand Up @@ -880,20 +896,20 @@ private String getHomeName(Entry<Location, Integer> e) {
* @since 1.16.0
*/
@NonNull
public Location getHomeLocation(@Nullable Island island) {
public Location getHomeLocation(@NonNull Island island) {
return getHomeLocation(island, "");
}

/**
* Get the named home location for this island
* @param island - island
* @param name - name of home, or blank for default
* @return home location
* @return home location or if there is none, then the island's center
* @since 1.16.0
*/
@NonNull
public Location getHomeLocation(@Nullable Island island, String name) {
return island == null ? null : island.getHome(name);
public Location getHomeLocation(@NonNull Island island, @NonNull String name) {
return Objects.requireNonNullElse(island.getHome(name), island.getCenter());
}

/**
Expand All @@ -903,8 +919,8 @@ public Location getHomeLocation(@Nullable Island island, String name) {
* @return true if successful, false if not
* @since 1.16.0
*/
public boolean removeHomeLocation(@Nullable Island island, String name) {
return island != null && island.removeHome(name);
public boolean removeHomeLocation(@NonNull Island island, @NonNull String name) {
return island.removeHome(name);
}

/**
Expand All @@ -914,8 +930,8 @@ public boolean removeHomeLocation(@Nullable Island island, String name) {
* @param newName - new name
* @return true if successful, false if not
*/
public boolean renameHomeLocation(@Nullable Island island, String oldName, String newName) {
return island != null && island.renameHome(oldName, newName);
public boolean renameHomeLocation(@NonNull Island island, @NonNull String oldName, @NonNull String newName) {
return island.renameHome(oldName, newName);
}

/**
Expand All @@ -935,7 +951,7 @@ public Map<String, Location> getHomeLocations(@NonNull Island island) {
* @param name - name being checked
* @return true if it exists or not
*/
public boolean isHomeLocation(@NonNull Island island, String name) {
public boolean isHomeLocation(@NonNull Island island, @NonNull String name) {
return island.getHomes().containsKey(name.toLowerCase());
}

Expand All @@ -945,7 +961,7 @@ public boolean isHomeLocation(@NonNull Island island, String name) {
* @param name - name
* @return number of homes after adding this one
*/
public int getNumberOfHomesIfAdded(@NonNull Island island, String name) {
public int getNumberOfHomesIfAdded(@NonNull Island island, @NonNull String name) {
return isHomeLocation(island, name) ? getHomeLocations(island).size() : getHomeLocations(island).size() + 1;
}

Expand All @@ -964,6 +980,7 @@ public Optional<Island> getSpawn(@NonNull World world){
* @param world - world
* @return the spawnPoint or null if spawn does not exist
*/
@Nullable
public Location getSpawnPoint(@NonNull World world) {
return spawn.containsKey(world) ? spawn.get(world).getSpawnPoint(world.getEnvironment()) : null;
}
Expand Down Expand Up @@ -1530,7 +1547,6 @@ public void setLast(Location last) {
* @param uuid - the player's UUID
*/
public void setLeaveTeam(World world, UUID uuid) {
plugin.getPlayers().clearHomeLocations(world, uuid);
removePlayer(world, uuid);
}

Expand Down
Loading