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

Java upgrade #1814

Merged
merged 24 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f89050f
Version 1.17.3
tastybento Jul 25, 2021
b810026
Use Map.of and List.of instead of Immutable collections
tastybento Jul 31, 2021
0717cd9
Replace explicit type argument.
tastybento Jul 31, 2021
9fb7ec4
Replace lamba with method reference
tastybento Jul 31, 2021
dd64424
Replace condition with Objects.requireNonNullElseGet
tastybento Jul 31, 2021
591936e
Use String.repeat
tastybento Jul 31, 2021
e284589
Use new switch expressions
tastybento Jul 31, 2021
34b34ca
Use instanceof patten variables which are more compact
tastybento Jul 31, 2021
2215aed
Fuse toUnmodifiableList into stream and return it.
tastybento Jul 31, 2021
07cee7f
Remove unnecessary toString() calls.
tastybento Jul 31, 2021
d0d692f
Remove unnecessary public
tastybento Jul 31, 2021
9b3aa83
Extracted common part from if
tastybento Jul 31, 2021
1a28fd9
Simplify conditional expressions
tastybento Jul 31, 2021
24a2cd0
Remove unused IOExceptions
tastybento Jul 31, 2021
bc766be
Cast to long
tastybento Jul 31, 2021
5cd8ca8
Use Map.putAll
tastybento Jul 31, 2021
16a5282
Use primitives
tastybento Jul 31, 2021
a3645f7
Clarify what is null or not
tastybento Jul 31, 2021
c481545
Addedd @Serial annotation introduced with Java 14.
tastybento Jul 31, 2021
3962848
Use Optional.isEmpty instead of !isPresent
tastybento Jul 31, 2021
6f1a6a7
Use flatMap then ifPresent
tastybento Jul 31, 2021
98b85b0
Just use Arrays.stream
tastybento Jul 31, 2021
58c6420
Swap map and filter for null with Objects::nonNull
tastybento Jul 31, 2021
eeb91fc
Use expression lambda
tastybento Jul 31, 2021
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.2</build.version>
<build.version>1.17.3</build.version>
</properties>

<!-- Profiles will allow to automatically change build version. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package world.bentobox.bentobox.api.addons.exceptions;

import java.io.Serial;

public abstract class AddonException extends Exception {

/**
*
*/
@Serial
private static final long serialVersionUID = 4203162022348693854L;

protected AddonException(String errorMessage){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package world.bentobox.bentobox.api.addons.exceptions;

import java.io.Serial;

public class AddonRequestException extends AddonException
{
private static final long serialVersionUID = -5698456013070166174L;
@Serial
private static final long serialVersionUID = -5698456013070166174L;

public AddonRequestException(String errorMessage) {
super(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package world.bentobox.bentobox.api.addons.exceptions;

import java.io.Serial;

/**
* @since 1.11.0
*/
Expand All @@ -8,6 +10,7 @@ public class InvalidAddonDescriptionException extends AddonException {
/**
*
*/
@Serial
private static final long serialVersionUID = 7741502900847049986L;

public InvalidAddonDescriptionException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.addons.exceptions;

import java.io.Serial;
import java.util.logging.Level;

import org.bukkit.Bukkit;
Expand All @@ -9,6 +10,7 @@ public class InvalidAddonFormatException extends AddonException {
/**
*
*/
@Serial
private static final long serialVersionUID = 7741502900847049986L;

public InvalidAddonFormatException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package world.bentobox.bentobox.api.addons.exceptions;

import java.io.Serial;

public class InvalidAddonInheritException extends AddonException {

/**
*
*/
@Serial
private static final long serialVersionUID = -5847358994397613244L;

public InvalidAddonInheritException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected CompositeCommand(Addon addon, String label, String... aliases) {

// Run setup
setup();
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
if (getSubCommand("help").isEmpty() && !label.equals("help")) {
new DefaultHelpCommand(this);
}
}
Expand Down Expand Up @@ -204,11 +204,11 @@ protected CompositeCommand(Addon addon, CompositeCommand parent, String label, S
p = p.getParent();
index++;
}
setDescription(COMMANDS + reference.toString() + ".description");
setParametersHelp(COMMANDS + reference.toString() + ".parameters");
setDescription(COMMANDS + reference + ".description");
setParametersHelp(COMMANDS + reference + ".parameters");
setup();
// If this command does not define its own help class, then use the default help command
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
if (getSubCommand("help").isEmpty() && !label.equals("help")) {
new DefaultHelpCommand(this);
}
}
Expand Down Expand Up @@ -278,7 +278,7 @@ private CompositeCommand getCommandFromArgs(String[] args) {
// get the subcommand corresponding to the arg
if (subCommand.hasSubCommands()) {
Optional<CompositeCommand> sub = subCommand.getSubCommand(arg);
if (!sub.isPresent()) {
if (sub.isEmpty()) {
return subCommand;
}
// Step down one
Expand Down Expand Up @@ -602,7 +602,7 @@ public List<String> tabComplete(final CommandSender sender, final String alias,
return options;
}
// Add any tab completion from the subcommand
options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(() -> new ArrayList<>()));
options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(ArrayList::new));
if (command.hasSubCommands()) {
options.addAll(getSubCommandLabels(sender, command));
}
Expand Down Expand Up @@ -701,7 +701,7 @@ public String getTopLabel() {
* @since 1.5.0
*/
public void setCooldown(String uniqueId, String targetUUID, int timeInSeconds) {
cooldowns.computeIfAbsent(uniqueId, k -> new HashMap<>()).put(targetUUID, System.currentTimeMillis() + timeInSeconds * 1000);
cooldowns.computeIfAbsent(uniqueId, k -> new HashMap<>()).put(targetUUID, System.currentTimeMillis() + timeInSeconds * 1000L);
}

/**
Expand All @@ -711,7 +711,7 @@ public void setCooldown(String uniqueId, String targetUUID, int timeInSeconds) {
* @param timeInSeconds - time in seconds to cool down
*/
public void setCooldown(UUID uniqueId, UUID targetUUID, int timeInSeconds) {
cooldowns.computeIfAbsent(uniqueId.toString(), k -> new HashMap<>()).put(targetUUID == null ? null : targetUUID.toString(), System.currentTimeMillis() + timeInSeconds * 1000);
cooldowns.computeIfAbsent(uniqueId.toString(), k -> new HashMap<>()).put(targetUUID == null ? null : targetUUID.toString(), System.currentTimeMillis() + timeInSeconds * 1000L);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean canExecute(User user, String label, List<String> args) {
return false;
}
Optional<Island> optionalIsland = getIslands().getIslandAt(targetLoc);
if (!optionalIsland.isPresent()) {
if (optionalIsland.isEmpty()) {
user.sendMessage("commands.admin.setspawnpoint.no-island-here");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class AdminSettingsCommand extends CompositeCommand {
private Island island;
private final List<String> SETTING_FLAG_NAMES;
private List<String> WORLD_SETTING_FLAG_NAMES;
private @NonNull Optional<Flag> flag;
private @NonNull Optional<Flag> flag = Optional.empty();
private boolean activeState;
private int rank;

Expand Down Expand Up @@ -258,20 +258,14 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
}
} else if (args.size() == 4) {
// Get flag in previous argument
options = getPlugin().getFlagsManager().getFlag(args.get(2).toUpperCase(Locale.ENGLISH)).map(f -> {
switch (f.getType()) {
case PROTECTION:
return getPlugin().getRanksManager()
.getRanks().entrySet().stream()
.filter(en -> en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK)
.map(Entry::getKey)
.map(user::getTranslation).collect(Collectors.toList());
case SETTING:
return Arrays.asList(active, disabled);
default:
return Collections.<String>emptyList();

}
options = getPlugin().getFlagsManager().getFlag(args.get(2).toUpperCase(Locale.ENGLISH)).map(f -> switch (f.getType()) {
case PROTECTION -> getPlugin().getRanksManager()
.getRanks().entrySet().stream()
.filter(en -> en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK)
.map(Entry::getKey)
.map(user::getTranslation).collect(Collectors.toList());
case SETTING -> Arrays.asList(active, disabled);
default -> Collections.<String>emptyList();
}).orElse(Collections.emptyList());
}
return Optional.of(Util.tabLimit(options, lastArg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean canExecute(User user, String label, List<String> args) {
public boolean execute(User user, String label, List<String> args) {
if (NumberUtils.isDigits(args.get(1))) {
try {
Integer n = Integer.valueOf(args.get(1));
int n = Integer.parseInt(args.get(1));
if (n < 1 || n > islands.size()) {
user.sendMessage("commands.admin.switchto.out-of-range", TextVariables.NUMBER, String.valueOf(islands.size()), TextVariables.LABEL, getTopLabel());
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public boolean execute(User user, String label, List<String> args) {
islands.clear();
this.user = user;
try {
Integer days = Integer.parseInt(args.get(0));
int days = Integer.parseInt(args.get(0));
if (days < 1) {
user.sendMessage("commands.admin.purge.days-one-or-more");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,15 @@ public boolean execute(User user, String label, List<String> args) {

if (!displayRanges.containsKey(user)) {
switch (label) {
case DISPLAY:
case SHOW:
showZones(user);
break;
case HIDE:
user.sendMessage("commands.admin.range.display.already-off");
break;
default:
showHelp(this, user);
break;
case DISPLAY, SHOW -> showZones(user);
case HIDE -> user.sendMessage("commands.admin.range.display.already-off");
default -> showHelp(this, user);
}
} else {
switch (label) {
case DISPLAY:
case HIDE:
hideZones(user);
break;
case SHOW:
user.sendMessage("commands.admin.range.display.already-on");
break;
default:
showHelp(this, user);
break;
case DISPLAY, HIDE -> hideZones(user);
case SHOW -> user.sendMessage("commands.admin.range.display.already-on");
default -> showHelp(this, user);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof Invite)) {
if (!(obj instanceof Invite other)) {
return false;
}
Invite other = (Invite) obj;
return Objects.equals(invitee, other.invitee) && Objects.equals(inviter, other.inviter) && type == other.type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ public boolean execute(User user, String label, List<String> args) {
// Get the invite
Invite invite = itc.getInvite(playerUUID);
switch (invite.getType()) {
case COOP:
askConfirmation(user, () -> acceptCoopInvite(user, invite));
break;
case TRUST:
askConfirmation(user, () -> acceptTrustInvite(user, invite));
break;
default:
askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"), () -> acceptTeamInvite(user, invite));
case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite));
case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite));
default -> askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"),
() -> acceptTeamInvite(user, invite));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,9 @@ public boolean canExecute(User user, String label, List<String> args) {
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);
break;
case TRUST:
user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name);
break;
default:
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name);
break;
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,21 @@ public AddonEventBuilder reason(Reason reason) {
}

private AddonBaseEvent getDeprecatedEvent() {
switch (reason) {
case ENABLE:
return new AddonEnableEvent(addon, keyValues);
case DISABLE:
return new AddonDisableEvent(addon, keyValues);
case LOAD:
return new AddonLoadEvent(addon, keyValues);
default:
return new AddonGeneralEvent(addon, keyValues);
}
return switch (reason) {
case ENABLE -> new AddonEnableEvent(addon, keyValues);
case DISABLE -> new AddonDisableEvent(addon, keyValues);
case LOAD -> new AddonLoadEvent(addon, keyValues);
default -> new AddonGeneralEvent(addon, keyValues);
};
}

private AddonBaseEvent getEvent() {
switch (reason) {
case ENABLE:
return new world.bentobox.bentobox.api.events.addon.AddonEnableEvent(addon, keyValues);
case DISABLE:
return new world.bentobox.bentobox.api.events.addon.AddonDisableEvent(addon, keyValues);
case LOAD:
return new world.bentobox.bentobox.api.events.addon.AddonLoadEvent(addon, keyValues);
default:
return new world.bentobox.bentobox.api.events.addon.AddonGeneralEvent(addon, keyValues);
}
return switch (reason) {
case ENABLE -> new world.bentobox.bentobox.api.events.addon.AddonEnableEvent(addon, keyValues);
case DISABLE -> new world.bentobox.bentobox.api.events.addon.AddonDisableEvent(addon, keyValues);
case LOAD -> new world.bentobox.bentobox.api.events.addon.AddonLoadEvent(addon, keyValues);
default -> new world.bentobox.bentobox.api.events.addon.AddonGeneralEvent(addon, keyValues);
};
}

/**
Expand Down
Loading