Skip to content

Commit

Permalink
Merge pull request #2158 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Version 1.24.1
  • Loading branch information
tastybento authored Jul 29, 2023
2 parents 363b23a + 475e67c commit 78092aa
Show file tree
Hide file tree
Showing 33 changed files with 1,669 additions and 611 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- Database related dependencies -->
<mongodb.version>3.12.8</mongodb.version>
<mongodb.version>3.12.12</mongodb.version>
<mariadb.version>3.0.5</mariadb.version>
<mysql.version>8.0.27</mysql.version>
<postgresql.version>42.2.18</postgresql.version>
Expand All @@ -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.0</build.version>
<build.version>1.24.1</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 @@ -127,6 +127,7 @@
<value>origin/master</value>
</property>
</activation>
<!--suppress CheckTagEmptyBody -->
<properties>
<!-- Override only if necessary -->
<revision>${build.version}</revision>
Expand Down Expand Up @@ -369,6 +370,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<!--suppress MavenModelInspection -->
<configuration>
<argLine>
${argLine}
Expand Down Expand Up @@ -505,7 +507,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.10</version>
<configuration>
<append>true</append>
<excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ public static AddonDescription asDescription(YamlConfiguration data) throws Inva
if (softDepend != null) {
builder.softDependencies(Arrays.asList(softDepend.split("\\s*,\\s*")));
}
builder.icon(Objects.requireNonNull(Material.getMaterial(data.getString("icon", "PAPER").toUpperCase(Locale.ENGLISH))));
Material icon = Material.getMaterial(data.getString("icon", "PAPER").toUpperCase(Locale.ENGLISH));
if (icon == null) {
throw new InvalidAddonDescriptionException("'icon' tag refers to an unknown Material: " + data.getString("icon"));
}
builder.icon(Objects.requireNonNull(icon));

String apiVersion = data.getString("api-version");
if (apiVersion != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,8 @@ public List<String> tabComplete(final @NonNull CommandSender sender, final @NonN
if (command.getPermission() != null && !command.getPermission().isEmpty() && !sender.hasPermission(command.getPermission()) && !sender.isOp()) {
return List.of();
}
List<String> options = new ArrayList<>();
// Add any tab completion from the subcommand
options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(ArrayList::new));
List<String> options = new ArrayList<>(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(ArrayList::new));
if (command.hasSubCommands()) {
options.addAll(getSubCommandLabels(sender, command));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

/**
* BentoBox Confirmable Command
* Adds ability to confirm a command before execution
* Adds ability to confirm a command before execution.
* See {@link #askConfirmation(User, Runnable)}, {@link #askConfirmation(User, String, Runnable)}
* @author tastybento
* @author Poslovitch
*/
Expand Down Expand Up @@ -88,7 +89,8 @@ public void askConfirmation(User user, String message, Runnable confirmed) {
}

/**
* Tells user to confirm command by retyping it.
* Tells user to confirm command by retyping it. Uses the default message to retype it.<p>
* If you need a custom message, use {@link #askConfirmation(User, String, Runnable)}
* @param user User to ask confirmation to.
* @param confirmed Runnable to be executed if successfully confirmed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,51 +107,66 @@ private boolean getIsland(User user, List<String> args) {

/**
* Check that this command is correct to set a setting
*
* @param user - user
* @param args - args
* @return true if the syntax is correct
*/
private boolean checkSyntax(User user, List<String> args) {
// Update the flag lists
this.makeLists();
if (args.size() == 2) {
// Should be a world setting
// If world settings, then active/disabled, otherwise player flags
if (worldSettingFlagNames.contains(args.get(0).toUpperCase(Locale.ENGLISH))) {
if (checkActiveDisabled(user, args.get(1))) {
flag = getPlugin().getFlagsManager().getFlag(args.get(0).toUpperCase(Locale.ENGLISH));
return true;
}
} else {
this.showHelp(this, user);
return false;
}
} else if (args.size() > 2) {
// Get island
if (!getIsland(user, args)) {
return false;
}

if (!settingFlagNames.contains(args.get(1).toUpperCase(Locale.ENGLISH))
&& !protectionFlagNames.contains(args.get(1).toUpperCase(Locale.ENGLISH))) {
user.sendMessage("commands.admin.settings.unknown-flag", TextVariables.NAME, args.get(2));
return false;
}
// Set flag
flag = getPlugin().getFlagsManager().getFlag(args.get(1).toUpperCase(Locale.ENGLISH));
// Check settings
if (flag.isPresent()) {
if (flag.get().getType().equals(Type.SETTING)) {
return checkActiveDisabled(user, args.get(2));
} else {
// Protection flag
return checkRank(user, String.join(" ", args.subList(2, args.size())));
}
int argSize = args.size();

if (argSize == 2) {
return checkWorldSetting(user, args);
} else if (argSize > 2) {
return checkIslandSetting(user, args);
}

return false;
}

private boolean checkWorldSetting(User user, List<String> args) {
String arg0 = args.get(0).toUpperCase(Locale.ENGLISH);

if (worldSettingFlagNames.contains(arg0)) {
if (checkActiveDisabled(user, args.get(1))) {
flag = getPlugin().getFlagsManager().getFlag(args.get(0).toUpperCase(Locale.ENGLISH));
return true;
}
} else {
this.showHelp(this, user);
return false;
}
return false;
}

private boolean checkIslandSetting(User user, List<String> args) {
// Get island
if (!getIsland(user, args)) {
return false;
}

String arg1 = args.get(1).toUpperCase(Locale.ENGLISH);

if (!settingFlagNames.contains(arg1) && !protectionFlagNames.contains(arg1)) {
user.sendMessage("commands.admin.settings.unknown-flag", TextVariables.NAME, args.get(2));
return false;
}
// Set flag
flag = getPlugin().getFlagsManager().getFlag(arg1);
// Check settings
if (flag.isPresent()) {
if (flag.get().getType().equals(Type.SETTING)) {
return checkActiveDisabled(user, args.get(2));
} else {
// Protection flag
return checkRank(user, String.join(" ", args.subList(2, args.size())));
}
}

return false;
}

/**
* Check the rank given.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;

Expand All @@ -39,74 +41,121 @@ public void setup() {

@Override
public boolean canExecute(User user, String label, List<String> args) {
UUID playerUUID = user.getUniqueId();
IslandsManager islandsManager = getIslands();

// Player issuing the command must have an island or be in a team
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
if (!islandsManager.inTeam(getWorld(), playerUUID) && !islandsManager.hasIsland(getWorld(), playerUUID)) {
user.sendMessage("general.errors.no-island");
return false;
}
UUID playerUUID = user.getUniqueId();

if (args.size() != 1) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far and why
if (itc.isInvited(playerUUID)) {
Invite invite = itc.getInvite(playerUUID);
String name = getPlayers().getName(playerUUID);
switch (invite.getType()) {
case COOP -> user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name);
case TRUST -> user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name);
default -> user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name);
}
return true;
return handleCommandWithNoArgs(user);
}

Island island = islandsManager.getIsland(getWorld(), user);
int rank = Objects.requireNonNull(island).getRank(user);

return checkRankAndInvitePlayer(user, island, rank, args.get(0));
}

private boolean handleCommandWithNoArgs(User user) {
UUID playerUUID = user.getUniqueId();
Type inviteType = getInviteType(playerUUID);

if (inviteType != null) {
String name = getPlayers().getName(playerUUID);
switch (inviteType) {
case COOP -> user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name);
case TRUST -> user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name);
default -> user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name);
}
// Show help
showHelp(this, user);
return false;
return true;
}

showHelp(this, user);
return false;
}

private boolean checkRankAndInvitePlayer(User user, Island island, int rank, String playerName) {
RanksManager ranksManager = getPlugin().getRanksManager();
PlayersManager playersManager = getPlayers();
UUID playerUUID = user.getUniqueId();

// Check rank to use command
Island island = getIslands().getIsland(getWorld(), user);
int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
int requiredRank = island.getRankCommand(getUsage());
if (rank < requiredRank) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(ranksManager.getRank(rank)));
return false;
}

// Check for space on team
if (island.getMemberSet().size() >= getIslands().getMaxMembers(island, RanksManager.MEMBER_RANK)) {
int maxMembers = getIslands().getMaxMembers(island, RanksManager.MEMBER_RANK);
if (island.getMemberSet().size() >= maxMembers) {
user.sendMessage("commands.island.team.invite.errors.island-is-full");
return false;
}

UUID invitedPlayerUUID = getPlayers().getUUID(args.get(0));
UUID invitedPlayerUUID = playersManager.getUUID(playerName);
if (invitedPlayerUUID == null) {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, playerName);
return false;
}
// Only online players can be invited
// Write to field as this is used by execute method
invitedPlayer = User.getInstance(invitedPlayerUUID);
if (!invitedPlayer.isOnline() || !user.getPlayer().canSee(invitedPlayer.getPlayer())) {
user.sendMessage("general.errors.offline-player");
if (!canInvitePlayer(user, invitedPlayer)) {
return false;
}
// Player cannot invite themselves
if (playerUUID.equals(invitedPlayerUUID)) {
user.sendMessage("commands.island.team.invite.errors.cannot-invite-self");
return false;
}
// Check cool down
if (getSettings().getInviteCooldown() > 0 && checkCooldown(user, getIslands().getIsland(getWorld(), user).getUniqueId(), invitedPlayerUUID.toString())) {

// Check cooldown
if (this.getSettings().getInviteCooldown() > 0 && checkCooldown(user, island.getUniqueId(), invitedPlayerUUID.toString())) {
return false;
}

// Player cannot invite someone already on a team
if (getIslands().inTeam(getWorld(), invitedPlayerUUID)) {
user.sendMessage("commands.island.team.invite.errors.already-on-team");
return false;
}
if (itc.isInvited(invitedPlayerUUID) && itc.getInviter(invitedPlayerUUID).equals(user.getUniqueId()) && itc.getInvite(invitedPlayerUUID).getType().equals(Type.TEAM)) {
// Prevent spam

if (isInvitedByUser(invitedPlayerUUID, playerUUID) && isInviteTypeTeam(invitedPlayerUUID)) {
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
return false;
}

return true;
}

private Type getInviteType(UUID playerUUID) {
if (itc.isInvited(playerUUID)) {
Invite invite = itc.getInvite(playerUUID);
return invite.getType();
}
return null;
}

private boolean canInvitePlayer(User user, User invitedPlayer) {
UUID playerUUID = user.getUniqueId();
if (!invitedPlayer.isOnline() || !user.getPlayer().canSee(invitedPlayer.getPlayer())) {
user.sendMessage("general.errors.offline-player");
return false;
}
if (playerUUID.equals(invitedPlayer.getUniqueId())) {
user.sendMessage("commands.island.team.invite.errors.cannot-invite-self");
return false;
}
return true;
}

private boolean isInvitedByUser(UUID invitedPlayerUUID, UUID inviterUUID) {
return itc.isInvited(invitedPlayerUUID) && itc.getInviter(invitedPlayerUUID).equals(inviterUUID);
}

private boolean isInviteTypeTeam(UUID invitedPlayerUUID) {
return Objects.requireNonNull(itc.getInvite(invitedPlayerUUID)).getType().equals(Type.TEAM);
}

@Override
public boolean execute(User user, String label, List<String> args) {
// Rare case when invited player is null. Could be a race condition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ public boolean isGlow() {
public void setGlow(boolean glow) {
this.glow = glow;
if (meta != null) {
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow);
if (glow) {
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow);
} else {
meta.removeEnchant(Enchantment.ARROW_DAMAGE);
}
icon.setItemMeta(meta);

}
}

Expand Down
Loading

0 comments on commit 78092aa

Please sign in to comment.