Skip to content

Commit

Permalink
Merge pull request #2493 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 2.5.3
  • Loading branch information
tastybento authored Sep 1, 2024
2 parents c433987 + d654776 commit 97d42e4
Show file tree
Hide file tree
Showing 25 changed files with 588 additions and 57 deletions.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>2.5.2</build.version>
<build.version>2.5.3</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
Expand Down Expand Up @@ -228,6 +228,13 @@
<version>3.11.1</version>
<scope>test</scope>
</dependency>
<!-- For test that need a time to test -->
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.2</version>
<scope>test</scope>
</dependency>
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ public void onDisable() {
// Stop all async database tasks
shutdown = true;

HeadGetter.shutdown();

if (addonsManager != null) {
addonsManager.disableAddons();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,30 @@ public void addInvite(TeamInvite.Type type, @NonNull UUID inviter, @NonNull UUID
}

/**
* Check if a player has been invited
* Check if a player has been invited - validates any invite that may be in the system
* @param invitee - UUID of invitee to check
* @return true if invited, false if not
* @since 1.8.0
*/
public boolean isInvited(@NonNull UUID invitee) {
return handler.objectExists(invitee.toString());
boolean valid = false;
if (handler.objectExists(invitee.toString())) {
@Nullable
TeamInvite invite = getInvite(invitee);
valid = getIslands().getIslandById(invite.getUniqueId()).map(island -> island.isOwned() // Still owned by someone
&& !island.isDeleted() // Not deleted
&& island.getMemberSet().contains(invite.getInviter()) // the inviter is still a member of the island
).orElse(false);
if (!valid) {
// Remove invite
handler.deleteObject(invite);
}
}
return valid;
}

/**
* Get whoever invited invitee
* Get whoever invited invitee.
* @param invitee - uuid
* @return UUID of inviter, or null if invitee has not been invited
* @since 1.8.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public boolean canExecute(User user, String label, List<String> args) {
UUID prospectiveOwnerUUID = itc.getInviter(playerUUID);
if (prospectiveOwnerUUID == null) {
user.sendMessage(INVALID_INVITE);
itc.removeInvite(playerUUID);
return false;
}
TeamInvite invite = itc.getInvite(playerUUID);
Expand All @@ -65,6 +66,7 @@ public boolean canExecute(User user, String label, List<String> args) {
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()
&& getIslands().inTeam(getWorld(), playerUUID)) {
user.sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
itc.removeInvite(playerUUID);
return false;
}
// Fire event so add-ons can run commands, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean canExecute(User user, String label, List<String> args) {

if (args.size() != 1) {
new IslandTeamInviteGUI(itc, true, island).build(user);
return true;
return false;
}

int rank = Objects.requireNonNull(island).getRank(user);
Expand Down Expand Up @@ -153,6 +153,7 @@ public boolean execute(User user, String label, List<String> args) {
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
if (island == null) {
user.sendMessage("general.errors.no-island");
invitedPlayer = null;
return false;
}
// Fire event so add-ons can run commands, etc.
Expand All @@ -162,6 +163,7 @@ public boolean execute(User user, String label, List<String> args) {
.involvedPlayer(invitedPlayer.getUniqueId())
.build();
if (e.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(e.isCancelled())) {
invitedPlayer = null;
return false;
}
// Put the invited player (key) onto the list with inviter (value)
Expand All @@ -175,6 +177,7 @@ public boolean execute(User user, String label, List<String> args) {
&& getIslands().hasIsland(getWorld(), invitedPlayer.getUniqueId())) {
invitedPlayer.sendMessage("commands.island.team.invite.you-will-lose-your-island");
}
invitedPlayer = null;
return true;
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/world/bentobox/bentobox/api/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,6 @@ private String translate(String addonPrefix, String reference, String[] variable
private String replacePrefixes(String translation, String[] variables) {
for (String prefix : plugin.getLocalesManager().getAvailablePrefixes(this)) {
String prefixTranslation = getTranslation("prefixes." + prefix);
// 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]",
isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");

// Replace the prefix in the actual message
translation = translation.replace("[prefix_" + prefix + "]", prefixTranslation);
Expand All @@ -530,6 +524,17 @@ private String replacePrefixes(String translation, String[] variables) {
if (player != null) {
translation = plugin.getPlaceholdersManager().replacePlaceholders(player, translation);
}

// Replace game mode and friendly name in general
// Replace the [gamemode] text variable
if (addon != null && addon.getDescription() != null) {
translation = translation.replace("[gamemode]", addon.getDescription().getName());
}
if (player != null && player.getWorld() != null) {
// Replace the [friendly_name] text variable
translation = translation.replace("[friendly_name]",
isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
}
return translation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.google.common.base.Enums;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;

Expand Down Expand Up @@ -51,6 +50,7 @@ public void onBlockBreak(final BlockBreakEvent e) {
|| m == Material.SWEET_BERRY_BUSH
|| m == Material.BAMBOO
|| m == Material.NETHER_WART
|| m == Material.CACTUS
) {
this.checkIsland(e, p, l, Flags.HARVEST);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ else if (e.getRightClicked() instanceof Boat)
this.checkIsland(e, p, l, Flags.BOAT);
}
}
else if (e.getRightClicked() instanceof Villager || e.getRightClicked() instanceof WanderingTrader)
else if (e.getRightClicked() instanceof Villager && !(e.getRightClicked() instanceof WanderingTrader))
{
// Villager trading
// Check naming and check trading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ public boolean isAtSpawn(Location playerLoc) {
*/
public void setSpawn(@NonNull Island spawn) {
if (spawn.getWorld() != null) {
spawn.setSpawn(true);
spawns.put(Util.getWorld(spawn.getWorld()), spawn);
// Tell other servers
MultiLib.notify("bentobox-setspawn", spawn.getWorld().getUID().toString() + "," + spawn.getUniqueId());
Expand All @@ -1223,9 +1224,12 @@ public void setSpawn(@NonNull Island spawn) {
* @since 1.8.0
*/
public void clearSpawn(World world) {
spawns.remove(world);
// Tell other servers
MultiLib.notify("bentobox-setspawn", world.getUID().toString());
if (spawns.containsKey(world)) {
spawns.get(world).setSpawn(false);
spawns.remove(world);
// Tell other servers
MultiLib.notify("bentobox-setspawn", world.getUID().toString());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import org.bukkit.World;
import org.bukkit.entity.Player;
Expand All @@ -23,14 +22,15 @@
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.Names;
import world.bentobox.bentobox.database.objects.Players;
import world.bentobox.bentobox.util.ExpiringMap;
import world.bentobox.bentobox.util.Util;

public class PlayersManager {

private final BentoBox plugin;
private Database<Players> handler;
private final Database<Names> names;
private final Map<UUID, Players> playerCache = new ConcurrentHashMap<>();
private final ExpiringMap<UUID, Players> playerCache = new ExpiringMap<>(2, TimeUnit.HOURS);
private final @NonNull List<Names> nameCache;
private final Set<UUID> inTeleport; // this needs databasing

Expand Down Expand Up @@ -61,6 +61,7 @@ public void setHandler(Database<Players> handler) {

public void shutdown(){
handler.close();
playerCache.shutdown();
}

/**
Expand Down
Loading

0 comments on commit 97d42e4

Please sign in to comment.