Merge branch 'develop' of https://github.com/BentoBoxWorld/BentoBox.git into develop

This commit is contained in:
tastybento 2021-07-31 08:48:58 -07:00
commit 1bd11bbff6
74 changed files with 497 additions and 740 deletions

View File

@ -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){

View File

@ -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);

View File

@ -1,5 +1,7 @@
package world.bentobox.bentobox.api.addons.exceptions;
import java.io.Serial;
/**
* @since 1.11.0
*/
@ -8,6 +10,7 @@ public class InvalidAddonDescriptionException extends AddonException {
/**
*
*/
@Serial
private static final long serialVersionUID = 7741502900847049986L;
public InvalidAddonDescriptionException(String errorMessage) {

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.addons.exceptions;
import java.io.Serial;
import java.util.logging.Level;
import org.bukkit.Bukkit;
@ -9,6 +10,7 @@ public class InvalidAddonFormatException extends AddonException {
/**
*
*/
@Serial
private static final long serialVersionUID = 7741502900847049986L;
public InvalidAddonFormatException(String errorMessage) {

View File

@ -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) {

View File

@ -144,7 +144,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
// Run setup
setup();
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
if (getSubCommand("help").isEmpty() && !label.equals("help")) {
new DefaultHelpCommand(this);
}
}
@ -204,11 +204,11 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
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);
}
}
@ -278,7 +278,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
// 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
@ -602,7 +602,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
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));
}
@ -701,7 +701,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @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);
}
/**
@ -711,7 +711,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @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);
}
/**

View File

@ -59,7 +59,7 @@ public class AdminSetProtectionCenterCommand extends ConfirmableCommand
return false;
}
Optional<Island> optionalIsland = getIslands().getIslandAt(targetLoc);
if (!optionalIsland.isPresent()) {
if (optionalIsland.isEmpty()) {
user.sendMessage("commands.admin.setspawnpoint.no-island-here");
return false;
}

View File

@ -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;
@ -258,20 +258,14 @@ public class AdminSettingsCommand extends CompositeCommand {
}
} 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));

View File

@ -63,7 +63,7 @@ public class AdminSwitchtoCommand extends ConfirmableCommand {
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;

View File

@ -70,7 +70,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
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;

View File

@ -46,29 +46,15 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
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);
}
}

View File

@ -75,10 +75,9 @@ public class Invite {
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;
}
}

View File

@ -82,14 +82,10 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
// 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;
}

View File

@ -51,15 +51,9 @@ public class IslandTeamInviteCommand extends CompositeCommand {
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;
}

View File

@ -100,29 +100,21 @@ public class AddonEvent {
}
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);
};
}
/**

View File

@ -801,103 +801,58 @@ public class IslandEvent extends IslandBaseEvent {
* @return deprecated event
*/
private IslandBaseEvent getDeprecatedEvent() {
switch (reason) {
case EXPEL:
return new IslandExpelEvent(island, player, admin, location);
case BAN:
return new IslandBanEvent(island, player, admin, location);
case PRECREATE:
return new IslandPreCreateEvent(player);
case CREATE:
return new IslandCreateEvent(island, player, admin, location, blueprintBundle);
case CREATED:
return new IslandCreatedEvent(island, player, admin, location);
case DELETE:
return new IslandDeleteEvent(island, player, admin, location);
case DELETE_CHUNKS:
return new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
case DELETED:
return new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
case ENTER:
return new IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
case EXIT:
return new IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
case LOCK:
return new IslandLockEvent(island, player, admin, location);
case RESET:
return new IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
case RESETTED:
return new IslandResettedEvent(island, player, admin, location, oldIsland);
case UNBAN:
return new IslandUnbanEvent(island, player, admin, location);
case UNLOCK:
return new IslandUnlockEvent(island, player, admin, location);
case REGISTERED:
return new IslandRegisteredEvent(island, player, admin, location);
case UNREGISTERED:
return new IslandUnregisteredEvent(island, player, admin, location);
case RANGE_CHANGE:
return new IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange);
case PRECLEAR:
return new IslandPreclearEvent(island, player, admin, location, oldIsland);
case RESERVED:
return new IslandReservedEvent(island, player, admin, location);
case RANK_CHANGE:
return new IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
default:
return new IslandGeneralEvent(island, player, admin, location);
}
return switch (reason) {
case EXPEL -> new IslandExpelEvent(island, player, admin, location);
case BAN -> new IslandBanEvent(island, player, admin, location);
case PRECREATE -> new IslandPreCreateEvent(player);
case CREATE -> new IslandCreateEvent(island, player, admin, location, blueprintBundle);
case CREATED -> new IslandCreatedEvent(island, player, admin, location);
case DELETE -> new IslandDeleteEvent(island, player, admin, location);
case DELETE_CHUNKS -> new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
case DELETED -> new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
case ENTER -> new IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
case EXIT -> new IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
case LOCK -> new IslandLockEvent(island, player, admin, location);
case RESET -> new IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
case RESETTED -> new IslandResettedEvent(island, player, admin, location, oldIsland);
case UNBAN -> new IslandUnbanEvent(island, player, admin, location);
case UNLOCK -> new IslandUnlockEvent(island, player, admin, location);
case REGISTERED -> new IslandRegisteredEvent(island, player, admin, location);
case UNREGISTERED -> new IslandUnregisteredEvent(island, player, admin, location);
case RANGE_CHANGE -> new IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange);
case PRECLEAR -> new IslandPreclearEvent(island, player, admin, location, oldIsland);
case RESERVED -> new IslandReservedEvent(island, player, admin, location);
case RANK_CHANGE -> new IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
default -> new IslandGeneralEvent(island, player, admin, location);
};
}
private IslandBaseEvent getEvent() {
switch (reason) {
case EXPEL:
return new world.bentobox.bentobox.api.events.island.IslandExpelEvent(island, player, admin, location);
case BAN:
return new world.bentobox.bentobox.api.events.island.IslandBanEvent(island, player, admin, location);
case PRECREATE:
return new world.bentobox.bentobox.api.events.island.IslandPreCreateEvent(player);
case CREATE:
return new world.bentobox.bentobox.api.events.island.IslandCreateEvent(island, player, admin, location, blueprintBundle);
case CREATED:
return new world.bentobox.bentobox.api.events.island.IslandCreatedEvent(island, player, admin, location);
case DELETE:
return new world.bentobox.bentobox.api.events.island.IslandDeleteEvent(island, player, admin, location);
case DELETE_CHUNKS:
return new world.bentobox.bentobox.api.events.island.IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
case DELETED:
return new world.bentobox.bentobox.api.events.island.IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
case ENTER:
return new world.bentobox.bentobox.api.events.island.IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
case EXIT:
return new world.bentobox.bentobox.api.events.island.IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
case LOCK:
return new world.bentobox.bentobox.api.events.island.IslandLockEvent(island, player, admin, location);
case RESET:
return new world.bentobox.bentobox.api.events.island.IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
case RESETTED:
return new world.bentobox.bentobox.api.events.island.IslandResettedEvent(island, player, admin, location, oldIsland);
case UNBAN:
return new world.bentobox.bentobox.api.events.island.IslandUnbanEvent(island, player, admin, location);
case UNLOCK:
return new world.bentobox.bentobox.api.events.island.IslandUnlockEvent(island, player, admin, location);
case REGISTERED:
return new world.bentobox.bentobox.api.events.island.IslandRegisteredEvent(island, player, admin, location);
case UNREGISTERED:
return new world.bentobox.bentobox.api.events.island.IslandUnregisteredEvent(island, player, admin, location);
case RANGE_CHANGE:
return new world.bentobox.bentobox.api.events.island.IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange);
case PRECLEAR:
return new world.bentobox.bentobox.api.events.island.IslandPreclearEvent(island, player, admin, location, oldIsland);
case RESERVED:
return new world.bentobox.bentobox.api.events.island.IslandReservedEvent(island, player, admin, location);
case RANK_CHANGE:
return new world.bentobox.bentobox.api.events.island.IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
case NEW_ISLAND:
return new IslandNewIslandEvent(island, player, admin, location);
default:
return new world.bentobox.bentobox.api.events.island.IslandGeneralEvent(island, player, admin, location);
}
return switch (reason) {
case EXPEL -> new world.bentobox.bentobox.api.events.island.IslandExpelEvent(island, player, admin, location);
case BAN -> new world.bentobox.bentobox.api.events.island.IslandBanEvent(island, player, admin, location);
case PRECREATE -> new world.bentobox.bentobox.api.events.island.IslandPreCreateEvent(player);
case CREATE -> new world.bentobox.bentobox.api.events.island.IslandCreateEvent(island, player, admin, location, blueprintBundle);
case CREATED -> new world.bentobox.bentobox.api.events.island.IslandCreatedEvent(island, player, admin, location);
case DELETE -> new world.bentobox.bentobox.api.events.island.IslandDeleteEvent(island, player, admin, location);
case DELETE_CHUNKS -> new world.bentobox.bentobox.api.events.island.IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
case DELETED -> new world.bentobox.bentobox.api.events.island.IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
case ENTER -> new world.bentobox.bentobox.api.events.island.IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
case EXIT -> new world.bentobox.bentobox.api.events.island.IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
case LOCK -> new world.bentobox.bentobox.api.events.island.IslandLockEvent(island, player, admin, location);
case RESET -> new world.bentobox.bentobox.api.events.island.IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
case RESETTED -> new world.bentobox.bentobox.api.events.island.IslandResettedEvent(island, player, admin, location, oldIsland);
case UNBAN -> new world.bentobox.bentobox.api.events.island.IslandUnbanEvent(island, player, admin, location);
case UNLOCK -> new world.bentobox.bentobox.api.events.island.IslandUnlockEvent(island, player, admin, location);
case REGISTERED -> new world.bentobox.bentobox.api.events.island.IslandRegisteredEvent(island, player, admin, location);
case UNREGISTERED -> new world.bentobox.bentobox.api.events.island.IslandUnregisteredEvent(island, player, admin, location);
case RANGE_CHANGE -> new world.bentobox.bentobox.api.events.island.IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange);
case PRECLEAR -> new world.bentobox.bentobox.api.events.island.IslandPreclearEvent(island, player, admin, location, oldIsland);
case RESERVED -> new world.bentobox.bentobox.api.events.island.IslandReservedEvent(island, player, admin, location);
case RANK_CHANGE -> new world.bentobox.bentobox.api.events.island.IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
case NEW_ISLAND -> new IslandNewIslandEvent(island, player, admin, location);
default -> new world.bentobox.bentobox.api.events.island.IslandGeneralEvent(island, player, admin, location);
};
}
/**

View File

@ -237,57 +237,35 @@ public class TeamEvent {
}
private IslandBaseEvent getDeprecatedEvent() {
switch (reason) {
case JOIN:
return new TeamJoinEvent(island, player, admin, location);
case JOINED:
return new TeamJoinedEvent(island, player, admin, location);
case INVITE:
return new TeamInviteEvent(island, player, admin, location);
case LEAVE:
return new TeamLeaveEvent(island, player, admin, location);
case REJECT:
return new TeamRejectEvent(island, player, admin, location);
case KICK:
return new TeamKickEvent(island, player, admin, location);
case SETOWNER:
return new TeamSetownerEvent(island, player, admin, location);
case INFO:
return new TeamInfoEvent(island, player, admin, location);
case DELETE:
return new TeamDeleteEvent(island, player, admin, location);
case UNINVITE:
return new TeamUninviteEvent(island, player, admin, location);
default:
return new TeamGeneralEvent(island, player, admin, location);
}
return switch (reason) {
case JOIN -> new TeamJoinEvent(island, player, admin, location);
case JOINED -> new TeamJoinedEvent(island, player, admin, location);
case INVITE -> new TeamInviteEvent(island, player, admin, location);
case LEAVE -> new TeamLeaveEvent(island, player, admin, location);
case REJECT -> new TeamRejectEvent(island, player, admin, location);
case KICK -> new TeamKickEvent(island, player, admin, location);
case SETOWNER -> new TeamSetownerEvent(island, player, admin, location);
case INFO -> new TeamInfoEvent(island, player, admin, location);
case DELETE -> new TeamDeleteEvent(island, player, admin, location);
case UNINVITE -> new TeamUninviteEvent(island, player, admin, location);
default -> new TeamGeneralEvent(island, player, admin, location);
};
}
private IslandBaseEvent getEvent() {
switch (reason) {
case JOIN:
return new world.bentobox.bentobox.api.events.team.TeamJoinEvent(island, player, admin, location);
case JOINED:
return new world.bentobox.bentobox.api.events.team.TeamJoinedEvent(island, player, admin, location);
case INVITE:
return new world.bentobox.bentobox.api.events.team.TeamInviteEvent(island, player, admin, location);
case LEAVE:
return new world.bentobox.bentobox.api.events.team.TeamLeaveEvent(island, player, admin, location);
case REJECT:
return new world.bentobox.bentobox.api.events.team.TeamRejectEvent(island, player, admin, location);
case KICK:
return new world.bentobox.bentobox.api.events.team.TeamKickEvent(island, player, admin, location);
case SETOWNER:
return new world.bentobox.bentobox.api.events.team.TeamSetownerEvent(island, player, admin, location);
case INFO:
return new world.bentobox.bentobox.api.events.team.TeamInfoEvent(island, player, admin, location);
case DELETE:
return new world.bentobox.bentobox.api.events.team.TeamDeleteEvent(island, player, admin, location);
case UNINVITE:
return new world.bentobox.bentobox.api.events.team.TeamUninviteEvent(island, player, admin, location);
default:
return new world.bentobox.bentobox.api.events.team.TeamGeneralEvent(island, player, admin, location);
}
return switch (reason) {
case JOIN -> new world.bentobox.bentobox.api.events.team.TeamJoinEvent(island, player, admin, location);
case JOINED -> new world.bentobox.bentobox.api.events.team.TeamJoinedEvent(island, player, admin, location);
case INVITE -> new world.bentobox.bentobox.api.events.team.TeamInviteEvent(island, player, admin, location);
case LEAVE -> new world.bentobox.bentobox.api.events.team.TeamLeaveEvent(island, player, admin, location);
case REJECT -> new world.bentobox.bentobox.api.events.team.TeamRejectEvent(island, player, admin, location);
case KICK -> new world.bentobox.bentobox.api.events.team.TeamKickEvent(island, player, admin, location);
case SETOWNER -> new world.bentobox.bentobox.api.events.team.TeamSetownerEvent(island, player, admin, location);
case INFO -> new world.bentobox.bentobox.api.events.team.TeamInfoEvent(island, player, admin, location);
case DELETE -> new world.bentobox.bentobox.api.events.team.TeamDeleteEvent(island, player, admin, location);
case UNINVITE -> new world.bentobox.bentobox.api.events.team.TeamUninviteEvent(island, player, admin, location);
default -> new world.bentobox.bentobox.api.events.team.TeamGeneralEvent(island, player, admin, location);
};
}
/**

View File

@ -91,14 +91,11 @@ public class Flag implements Comparable<Flag> {
* @return next ranking mode
*/
public Mode getNext() {
switch(this) {
case ADVANCED:
return EXPERT;
case BASIC:
return ADVANCED;
default:
return BASIC;
}
return switch (this) {
case ADVANCED -> EXPERT;
case BASIC -> ADVANCED;
default -> BASIC;
};
}
/**
@ -107,14 +104,11 @@ public class Flag implements Comparable<Flag> {
* @return true if ranked greater
*/
public boolean isGreaterThan(Mode rank) {
switch(this) {
case EXPERT:
return rank.equals(BASIC) || rank.equals(ADVANCED);
case ADVANCED:
return rank.equals(BASIC);
default:
return false;
}
return switch (this) {
case EXPERT -> rank.equals(BASIC) || rank.equals(ADVANCED);
case ADVANCED -> rank.equals(BASIC);
default -> false;
};
}
}
@ -300,10 +294,9 @@ public class Flag implements Comparable<Flag> {
if (obj == null) {
return false;
}
if (!(obj instanceof Flag)) {
if (!(obj instanceof Flag other)) {
return false;
}
Flag other = (Flag) obj;
if (id == null) {
if (other.id != null) {
return false;
@ -392,16 +385,12 @@ public class Flag implements Comparable<Flag> {
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
return pib.build();
}
switch(getType()) {
case PROTECTION:
return createProtectionFlag(plugin, user, island, pib).build();
case SETTING:
return createSettingFlag(user, island, pib).build();
case WORLD_SETTING:
return createWorldSettingFlag(user, pib).build();
default:
return pib.build();
}
return switch (getType()) {
case PROTECTION -> createProtectionFlag(plugin, user, island, pib).build();
case SETTING -> createSettingFlag(user, island, pib).build();
case WORLD_SETTING -> createWorldSettingFlag(user, pib).build();
default -> pib.build();
};
}
private PanelItemBuilder createWorldSettingFlag(User user, PanelItemBuilder pib) {
@ -653,17 +642,9 @@ public class Flag implements Comparable<Flag> {
// If no clickHandler has been set, then apply default ones
if (clickHandler == null) {
switch (type) {
case SETTING:
clickHandler = new IslandToggleClick(id);
break;
case WORLD_SETTING:
clickHandler = new WorldToggleClick(id);
break;
case PROTECTION:
// Default option
default:
clickHandler = new CycleClick(id);
break;
case SETTING -> clickHandler = new IslandToggleClick(id);
case WORLD_SETTING -> clickHandler = new WorldToggleClick(id);
default -> clickHandler = new CycleClick(id);
}
}

View File

@ -13,13 +13,13 @@ public interface MetaDataAble {
/**
* @return the metaData
*/
public Optional<Map<String, MetaDataValue>> getMetaData();
Optional<Map<String, MetaDataValue>> getMetaData();
/**
* @param metaData the metaData to set
* @since 1.15.4
*/
public void setMetaData(Map<String, MetaDataValue> metaData);
void setMetaData(Map<String, MetaDataValue> metaData);
/**
* Get meta data by key

View File

@ -29,7 +29,7 @@ public class MetaDataValue {
@Expose
private Boolean booleanValue;
@Expose
private @NonNull String stringValue;
private String stringValue;
/**
* Initialize this meta data value
@ -85,6 +85,6 @@ public class MetaDataValue {
@NonNull
public String asString() {
return stringValue;
return stringValue == null ? "" : stringValue;
}
}

View File

@ -80,15 +80,9 @@ public class Panel implements HeadRequester, InventoryHolder {
// Create panel
switch (type) {
case INVENTORY:
inventory = Bukkit.createInventory(null, fixSize(size), name);
break;
case HOPPER:
inventory = Bukkit.createInventory(null, InventoryType.HOPPER, name);
break;
case DROPPER:
inventory = Bukkit.createInventory(null, InventoryType.DROPPER, name);
break;
case INVENTORY -> inventory = Bukkit.createInventory(null, fixSize(size), name);
case HOPPER -> inventory = Bukkit.createInventory(null, InventoryType.HOPPER, name);
case DROPPER -> inventory = Bukkit.createInventory(null, InventoryType.DROPPER, name);
}
// Fill the inventory and return

View File

@ -146,7 +146,7 @@ public class TabbedPanel extends Panel implements PanelListener {
}
}
// Add any subsidiary icons
tab.getTabIcons().forEach(items::put);
items.putAll(tab.getTabIcons());
}
private void setupFooter(TreeMap<Integer, PanelItem> items) {

View File

@ -22,7 +22,7 @@ public class Notifier {
.expireAfterAccess(NOTIFICATION_DELAY, TimeUnit.SECONDS)
.maximumSize(500)
.build(
new CacheLoader<User, Notification>() {
new CacheLoader<>() {
@Override
public Notification load(User user) {
return new Notification(null, 0);

View File

@ -618,10 +618,9 @@ public class User implements MetaDataAble {
if (obj == null) {
return false;
}
if (!(obj instanceof User)) {
if (!(obj instanceof User other)) {
return false;
}
User other = (User) obj;
if (playerUUID == null) {
return other.playerUUID == null;
} else return playerUUID.equals(other.playerUUID);

View File

@ -198,8 +198,7 @@ public class BlueprintClipboard {
if (entity instanceof Villager) {
setVillager(entity, bpe);
}
if (entity instanceof Colorable) {
Colorable c = (Colorable)entity;
if (entity instanceof Colorable c) {
if (c.getColor() != null) {
bpe.setColor(c.getColor());
}
@ -214,8 +213,7 @@ public class BlueprintClipboard {
if (entity instanceof Ageable && !((Ageable)entity).isAdult()) {
bpe.setAdult(false);
}
if (entity instanceof AbstractHorse) {
AbstractHorse horse = (AbstractHorse)entity;
if (entity instanceof AbstractHorse horse) {
bpe.setDomestication(horse.getDomestication());
bpe.setInventory(new HashMap<>());
for (int i = 0; i < horse.getInventory().getSize(); i++) {
@ -226,8 +224,7 @@ public class BlueprintClipboard {
}
}
if (entity instanceof Horse) {
Horse horse = (Horse)entity;
if (entity instanceof Horse horse) {
bpe.setStyle(horse.getStyle());
}
bpEnts.add(bpe);
@ -248,8 +245,7 @@ public class BlueprintClipboard {
// Biome
b.setBiome(block.getBiome());
// Signs
if (blockState instanceof Sign) {
Sign sign = (Sign)blockState;
if (blockState instanceof Sign sign) {
b.setSignLines(Arrays.asList(sign.getLines()));
}
// Set block data
@ -272,9 +268,8 @@ public class BlueprintClipboard {
}
// Chests
if (blockState instanceof InventoryHolder) {
if (blockState instanceof InventoryHolder ih) {
b.setInventory(new HashMap<>());
InventoryHolder ih = (InventoryHolder)blockState;
for (int i = 0; i < ih.getInventory().getSize(); i++) {
ItemStack item = ih.getInventory().getItem(i);
if (item != null) {
@ -283,8 +278,7 @@ public class BlueprintClipboard {
}
}
if (blockState instanceof CreatureSpawner) {
CreatureSpawner spawner = (CreatureSpawner)blockState;
if (blockState instanceof CreatureSpawner spawner) {
BlueprintCreatureSpawner cs = new BlueprintCreatureSpawner();
cs.setSpawnedType(spawner.getSpawnedType());
cs.setDelay(spawner.getDelay());

View File

@ -301,8 +301,7 @@ public class BlueprintPaster {
bpBlock.getInventory().forEach(ih::setItem);
}
// Mob spawners
if (bs instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) bs);
if (bs instanceof CreatureSpawner spawner) {
BlueprintCreatureSpawner s = bpBlock.getCreatureSpawner();
spawner.setSpawnedType(s.getSpawnedType());
spawner.setMaxNearbyEntities(s.getMaxNearbyEntities());
@ -314,8 +313,7 @@ public class BlueprintPaster {
bs.update(true, false);
}
// Banners
if (bs instanceof Banner && bpBlock.getBannerPatterns() != null) {
Banner banner = (Banner) bs;
if (bs instanceof Banner banner && bpBlock.getBannerPatterns() != null) {
bpBlock.getBannerPatterns().removeIf(Objects::isNull);
banner.setPatterns(bpBlock.getBannerPatterns());
banner.update(true, false);

View File

@ -42,7 +42,6 @@ public class NameSuccessPrompt extends MessagePrompt {
if (bp != null) {
BentoBox.getInstance().getBlueprintsManager().renameBlueprint(addon, bp, name);
new BlueprintManagementPanel(BentoBox.getInstance(), user, addon).openBB(bb);
return user.getTranslation("commands.admin.blueprint.management.description.success");
} else {
// Blueprint Bundle
if (bb == null) {
@ -61,8 +60,8 @@ public class NameSuccessPrompt extends MessagePrompt {
new BlueprintManagementPanel(BentoBox.getInstance(), user, addon).openPanel();
// Set the name
// if successfully
return user.getTranslation("commands.admin.blueprint.management.description.success");
}
return user.getTranslation("commands.admin.blueprint.management.description.success");
}
@Override

View File

@ -75,8 +75,7 @@ public class BlueprintEntity {
((Ageable)e).setBaby();
}
}
if (e instanceof AbstractHorse) {
AbstractHorse horse = (AbstractHorse)e;
if (e instanceof AbstractHorse horse) {
if (domestication != null) horse.setDomestication(domestication);
if (inventory != null) {
inventory.forEach(horse.getInventory()::setItem);

View File

@ -49,12 +49,12 @@ public class BlueprintClipboardFormat implements ClipboardFormat {
}
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
public ClipboardReader getReader(InputStream inputStream) {
return new BlueprintClipboardReader(inputStream);
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
public ClipboardWriter getWriter(OutputStream outputStream) {
return new BlueprintClipboardWriter(outputStream);
}

View File

@ -1,6 +1,5 @@
package world.bentobox.bentobox.blueprints.worldedit;
import java.io.IOException;
import java.io.InputStream;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -19,12 +18,12 @@ public class BlueprintClipboardReader implements ClipboardReader {
}
@Override
public Clipboard read() throws IOException {
public Clipboard read() {
throw new UnsupportedOperationException(); // TODO
}
@Override
public void close() throws IOException {
public void close() {
throw new UnsupportedOperationException(); // TODO
}

View File

@ -1,6 +1,5 @@
package world.bentobox.bentobox.blueprints.worldedit;
import java.io.IOException;
import java.io.OutputStream;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -18,12 +17,12 @@ public class BlueprintClipboardWriter implements ClipboardWriter {
this.outputStream = outputStream;
}
@Override
public void write(Clipboard clipboard) throws IOException {
public void write(Clipboard clipboard) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public void close() throws IOException {
public void close() {
throw new UnsupportedOperationException(); // TODO
}

View File

@ -18,7 +18,7 @@ public class BlueprintSchematicConverter {
private File blueprintFile;
public BlueprintSchematicConverter(File blueprintFile) {
if(!BentoBox.getInstance().getHooks().getHook("WorldEdit").isPresent()) {
if(BentoBox.getInstance().getHooks().getHook("WorldEdit").isEmpty()) {
BentoBox.getInstance().logError("WorldEdit must be installed to use that class !");
return;
}

View File

@ -23,11 +23,11 @@ public class JSONDatabaseConnector implements DatabaseConnector {
@NonNull
public String getUniqueId(String tableName) {
UUID uuid = UUID.randomUUID();
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + JSON);
File file = new File(dataFolder, tableName + File.separator + uuid + JSON);
int limit = 0;
while (file.exists() && limit++ < MAX_LOOPS) {
uuid = UUID.randomUUID();
file = new File(dataFolder, tableName + File.separator + uuid.toString() + JSON);
file = new File(dataFolder, tableName + File.separator + uuid + JSON);
}
return uuid.toString();
}

View File

@ -42,7 +42,7 @@ public class FlagTypeAdapter extends TypeAdapter<Flag> {
// Flags can end up null if an addon that created one is removed or if a flag name was changed
if (f == null) {
// Create a temporary flag with a unique key. It will be immediately deleted after loading
f = new Flag.Builder("NULL_FLAG_"+ UUID.randomUUID().toString(), Material.STONE).build();
f = new Flag.Builder("NULL_FLAG_"+ UUID.randomUUID(), Material.STONE).build();
}
return f;
}

View File

@ -142,12 +142,11 @@ public class MongoDBDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
completableFuture.complete(false);
return completableFuture;
}
if (!(instance instanceof DataObject)) {
if (!(instance instanceof DataObject dataObj)) {
plugin.logError("This class is not a DataObject: " + instance.getClass().getName());
completableFuture.complete(false);
return completableFuture;
}
DataObject dataObj = (DataObject)instance;
try {
Gson gson = getGson();
String toStore = gson.toJson(instance);

View File

@ -1346,7 +1346,7 @@ public class Island implements DataObject, MetaDataAble {
* @param flag - Flag to cooldown
*/
public void setCooldown(Flag flag) {
cooldowns.put(flag, flag.getCooldown() * 1000 + System.currentTimeMillis());
cooldowns.put(flag, flag.getCooldown() * 1000L + System.currentTimeMillis());
setChanged();
}

View File

@ -79,10 +79,9 @@ public class IslandDeletion implements DataObject {
if (obj == null) {
return false;
}
if (!(obj instanceof IslandDeletion)) {
if (!(obj instanceof IslandDeletion other)) {
return false;
}
IslandDeletion other = (IslandDeletion) obj;
if (uniqueId == null) {
return other.uniqueId == null;
} else return uniqueId.equals(other.uniqueId);

View File

@ -26,8 +26,7 @@ public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<
return result;
}
// For YAML
if (object instanceof MemorySection) {
MemorySection section = (MemorySection) object;
if (object instanceof MemorySection section) {
for (String key : section.getKeys(false)) {
BentoBox.getInstance().getFlagsManager().getFlag(key).ifPresent(flag -> result.put(flag, section.getInt(key)));
}

View File

@ -23,8 +23,7 @@ public class FlagSerializer2 implements AdapterInterface<Map<Flag, Integer>, Map
return result;
}
// For YAML
if (object instanceof MemorySection) {
MemorySection section = (MemorySection) object;
if (object instanceof MemorySection section) {
for (String key : section.getKeys(false)) {
BentoBox.getInstance().getFlagsManager().getFlag(key).ifPresent(flag -> result.put(flag, section.getBoolean(key) ? 0 : -1));
}

View File

@ -26,8 +26,7 @@ public class FlagSerializer3 implements AdapterInterface<Map<Flag, Long>, Map<St
return result;
}
// For YAML
if (object instanceof MemorySection) {
MemorySection section = (MemorySection) object;
if (object instanceof MemorySection section) {
for (String key : section.getKeys(false)) {
BentoBox.getInstance().getFlagsManager().getFlag(key).ifPresent(flag -> result.put(flag, section.getLong(key)));
}

View File

@ -152,9 +152,7 @@ public class YamlDatabaseConnector implements DatabaseConnector {
if (nextLine.contains(e.getKey())) {
// We want the comment to start at the same level as the entry
StringBuilder commentLine = new StringBuilder();
for (int i = 0; i < nextLine.indexOf(e.getKey()); i++){
commentLine.append(' ');
}
commentLine.append(" ".repeat(Math.max(0, nextLine.indexOf(e.getKey()))));
commentLine.append(e.getValue());
nextLine = commentLine.toString();
break;
@ -191,11 +189,11 @@ public class YamlDatabaseConnector implements DatabaseConnector {
@NonNull
public String getUniqueId(String tableName) {
UUID uuid = UUID.randomUUID();
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + YML);
File file = new File(dataFolder, tableName + File.separator + uuid + YML);
int limit = 0;
while (file.exists() && limit++ < MAX_LOOPS) {
uuid = UUID.randomUUID();
file = new File(dataFolder, tableName + File.separator + uuid.toString() + YML);
file = new File(dataFolder, tableName + File.separator + uuid + YML);
}
return uuid.toString();
}

View File

@ -534,7 +534,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
}
private void setComment(@NonNull String comment, @NonNull YamlConfiguration config, @NonNull Map<String, String> yamlComments, @NonNull String parent) {
String random = "comment-" + UUID.randomUUID().toString();
String random = "comment-" + UUID.randomUUID();
// Store placeholder
config.set(parent + random, " ");
// Create comment

View File

@ -262,31 +262,30 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getPotionName(potionType, getUserLocale(user));
}
switch (potionType) {
case UNCRAFTABLE: return "Uncraftable Potion";
case WATER: return "Water Bottle";
case MUNDANE: return "Mundane Potion";
case THICK: return "Thick Potion";
case AWKWARD: return "Awkward Potion";
case NIGHT_VISION: return "Potion of Night Vision";
case INVISIBILITY: return "Potion of Invisibility";
case JUMP: return "Potion of Leaping";
case FIRE_RESISTANCE: return "Potion of Fire Resistance";
case SPEED: return "Potion of Swiftness";
case SLOWNESS: return "Potion of Slowness";
case WATER_BREATHING: return "Potion of Water Breathing";
case INSTANT_HEAL: return "Potion of Healing";
case INSTANT_DAMAGE: return "Potion of Harming";
case POISON: return "Potion of Poison";
case REGEN: return "Potion of Regeneration";
case STRENGTH: return "Potion of Strength";
case WEAKNESS: return "Potion of Weakness";
case LUCK: return "Potion of Luck";
case TURTLE_MASTER: return "Potion of the Turtle Master";
case SLOW_FALLING: return "Potion of Slow Falling";
default:
return Util.prettifyText(potionType.name());
}
return switch (potionType) {
case UNCRAFTABLE -> "Uncraftable Potion";
case WATER -> "Water Bottle";
case MUNDANE -> "Mundane Potion";
case THICK -> "Thick Potion";
case AWKWARD -> "Awkward Potion";
case NIGHT_VISION -> "Potion of Night Vision";
case INVISIBILITY -> "Potion of Invisibility";
case JUMP -> "Potion of Leaping";
case FIRE_RESISTANCE -> "Potion of Fire Resistance";
case SPEED -> "Potion of Swiftness";
case SLOWNESS -> "Potion of Slowness";
case WATER_BREATHING -> "Potion of Water Breathing";
case INSTANT_HEAL -> "Potion of Healing";
case INSTANT_DAMAGE -> "Potion of Harming";
case POISON -> "Potion of Poison";
case REGEN -> "Potion of Regeneration";
case STRENGTH -> "Potion of Strength";
case WEAKNESS -> "Potion of Weakness";
case LUCK -> "Potion of Luck";
case TURTLE_MASTER -> "Potion of the Turtle Master";
case SLOW_FALLING -> "Potion of Slow Falling";
default -> Util.prettifyText(potionType.name());
};
}
@ -301,31 +300,30 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getSplashPotionName(potionType, getUserLocale(user));
}
switch (potionType) {
case UNCRAFTABLE: return "Splash Uncraftable Potion";
case WATER: return "Splash Water Bottle";
case MUNDANE: return "Mundane Splash Potion";
case THICK: return "Thick Splash Potion";
case AWKWARD: return "Awkward Splash Potion";
case NIGHT_VISION: return "Splash Potion of Night Vision";
case INVISIBILITY: return "Splash Potion of Invisibility";
case JUMP: return "Splash Potion of Leaping";
case FIRE_RESISTANCE: return "Splash Potion of Fire Resistance";
case SPEED: return "Splash Potion of Swiftness";
case SLOWNESS: return "Splash Potion of Slowness";
case WATER_BREATHING: return "Splash Potion of Water Breathing";
case INSTANT_HEAL: return "Splash Potion of Healing";
case INSTANT_DAMAGE: return "Splash Potion of Harming";
case POISON: return "Splash Potion of Poison";
case REGEN: return "Splash Potion of Regeneration";
case STRENGTH: return "Splash Potion of Strength";
case WEAKNESS: return "Splash Potion of Weakness";
case LUCK: return "Splash Potion of Luck";
case TURTLE_MASTER: return "Splash Potion of the Turtle Master";
case SLOW_FALLING: return "Splash Potion of Slow Falling";
default:
return Util.prettifyText(potionType.name());
}
return switch (potionType) {
case UNCRAFTABLE -> "Splash Uncraftable Potion";
case WATER -> "Splash Water Bottle";
case MUNDANE -> "Mundane Splash Potion";
case THICK -> "Thick Splash Potion";
case AWKWARD -> "Awkward Splash Potion";
case NIGHT_VISION -> "Splash Potion of Night Vision";
case INVISIBILITY -> "Splash Potion of Invisibility";
case JUMP -> "Splash Potion of Leaping";
case FIRE_RESISTANCE -> "Splash Potion of Fire Resistance";
case SPEED -> "Splash Potion of Swiftness";
case SLOWNESS -> "Splash Potion of Slowness";
case WATER_BREATHING -> "Splash Potion of Water Breathing";
case INSTANT_HEAL -> "Splash Potion of Healing";
case INSTANT_DAMAGE -> "Splash Potion of Harming";
case POISON -> "Splash Potion of Poison";
case REGEN -> "Splash Potion of Regeneration";
case STRENGTH -> "Splash Potion of Strength";
case WEAKNESS -> "Splash Potion of Weakness";
case LUCK -> "Splash Potion of Luck";
case TURTLE_MASTER -> "Splash Potion of the Turtle Master";
case SLOW_FALLING -> "Splash Potion of Slow Falling";
default -> Util.prettifyText(potionType.name());
};
}
/**
@ -339,31 +337,30 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getLingeringPotionName(potionType, getUserLocale(user));
}
switch (potionType) {
case UNCRAFTABLE: return "Lingering Uncraftable Potion";
case WATER: return "Lingering Water Bottle";
case MUNDANE: return "Mundane Lingering Potion";
case THICK: return "Thick Lingering Potion";
case AWKWARD: return "Awkward Lingering Potion";
case NIGHT_VISION: return "Lingering Potion of Night Vision";
case INVISIBILITY: return "Lingering Potion of Invisibility";
case JUMP: return "Lingering Potion of Leaping";
case FIRE_RESISTANCE: return "Lingering Potion of Fire Resistance";
case SPEED: return "Lingering Potion of Swiftness";
case SLOWNESS: return "Lingering Potion of Slowness";
case WATER_BREATHING: return "Lingering Potion of Water Breathing";
case INSTANT_HEAL: return "Lingering Potion of Healing";
case INSTANT_DAMAGE: return "Lingering Potion of Harming";
case POISON: return "Lingering Potion of Poison";
case REGEN: return "Lingering Potion of Regeneration";
case STRENGTH: return "Lingering Potion of Strength";
case WEAKNESS: return "Lingering Potion of Weakness";
case LUCK: return "Lingering Potion of Luck";
case TURTLE_MASTER: return "Lingering Potion of the Turtle Master";
case SLOW_FALLING: return "Lingering Potion of Slow Falling";
default:
return Util.prettifyText(potionType.name());
}
return switch (potionType) {
case UNCRAFTABLE -> "Lingering Uncraftable Potion";
case WATER -> "Lingering Water Bottle";
case MUNDANE -> "Mundane Lingering Potion";
case THICK -> "Thick Lingering Potion";
case AWKWARD -> "Awkward Lingering Potion";
case NIGHT_VISION -> "Lingering Potion of Night Vision";
case INVISIBILITY -> "Lingering Potion of Invisibility";
case JUMP -> "Lingering Potion of Leaping";
case FIRE_RESISTANCE -> "Lingering Potion of Fire Resistance";
case SPEED -> "Lingering Potion of Swiftness";
case SLOWNESS -> "Lingering Potion of Slowness";
case WATER_BREATHING -> "Lingering Potion of Water Breathing";
case INSTANT_HEAL -> "Lingering Potion of Healing";
case INSTANT_DAMAGE -> "Lingering Potion of Harming";
case POISON -> "Lingering Potion of Poison";
case REGEN -> "Lingering Potion of Regeneration";
case STRENGTH -> "Lingering Potion of Strength";
case WEAKNESS -> "Lingering Potion of Weakness";
case LUCK -> "Lingering Potion of Luck";
case TURTLE_MASTER -> "Lingering Potion of the Turtle Master";
case SLOW_FALLING -> "Lingering Potion of Slow Falling";
default -> Util.prettifyText(potionType.name());
};
}
/**
@ -377,31 +374,28 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getTippedArrowName(potionType, getUserLocale(user));
}
switch (potionType) {
case UNCRAFTABLE: return "Uncraftable Tipped Arrow";
case WATER: return "Arrow of Splashing";
case MUNDANE:
case THICK:
case AWKWARD: return "Tipped Arrow";
case NIGHT_VISION: return "Arrow of Night Vision";
case INVISIBILITY: return "Arrow of Invisibility";
case JUMP: return "Arrow of Leaping";
case FIRE_RESISTANCE: return "Arrow of Fire Resistance";
case SPEED: return "Arrow of Swiftness";
case SLOWNESS: return "Arrow of Slowness";
case WATER_BREATHING: return "Arrow of Water Breathing";
case INSTANT_HEAL: return "Arrow of Healing";
case INSTANT_DAMAGE: return "Arrow of Harming";
case POISON: return "Arrow of Poison";
case REGEN: return "Arrow of Regeneration";
case STRENGTH: return "Arrow of Strength";
case WEAKNESS: return "Arrow of Weakness";
case LUCK: return "Arrow of Luck";
case TURTLE_MASTER: return "Arrow of the Turtle Master";
case SLOW_FALLING: return "Arrow of Slow Falling";
default:
return Util.prettifyText(potionType.name());
}
return switch (potionType) {
case UNCRAFTABLE -> "Uncraftable Tipped Arrow";
case WATER -> "Arrow of Splashing";
case MUNDANE, THICK, AWKWARD -> "Tipped Arrow";
case NIGHT_VISION -> "Arrow of Night Vision";
case INVISIBILITY -> "Arrow of Invisibility";
case JUMP -> "Arrow of Leaping";
case FIRE_RESISTANCE -> "Arrow of Fire Resistance";
case SPEED -> "Arrow of Swiftness";
case SLOWNESS -> "Arrow of Slowness";
case WATER_BREATHING -> "Arrow of Water Breathing";
case INSTANT_HEAL -> "Arrow of Healing";
case INSTANT_DAMAGE -> "Arrow of Harming";
case POISON -> "Arrow of Poison";
case REGEN -> "Arrow of Regeneration";
case STRENGTH -> "Arrow of Strength";
case WEAKNESS -> "Arrow of Weakness";
case LUCK -> "Arrow of Luck";
case TURTLE_MASTER -> "Arrow of the Turtle Master";
case SLOW_FALLING -> "Arrow of Slow Falling";
default -> Util.prettifyText(potionType.name());
};
}
/**
@ -620,22 +614,22 @@ public class LangUtilsHook extends Hook {
// The description of the music record is the same in any language,
// so directly output it here.
switch (material) {
case MUSIC_DISC_13 : return "C418 - 13";
case MUSIC_DISC_CAT : return "C418 - cat";
case MUSIC_DISC_BLOCKS : return "C418 - blocks";
case MUSIC_DISC_CHIRP : return "C418 - chirp";
case MUSIC_DISC_FAR : return "C418 - far";
case MUSIC_DISC_MALL : return "C418 - mall";
case MUSIC_DISC_MELLOHI : return "C418 - mellohi";
case MUSIC_DISC_STAL : return "C418 - stal";
case MUSIC_DISC_STRAD : return "C418 - strad";
case MUSIC_DISC_WARD : return "C418 - ward";
case MUSIC_DISC_11 : return "C418 - 11";
case MUSIC_DISC_WAIT : return "C418 - wait";
case MUSIC_DISC_PIGSTEP : return "Lena Raine - Pigstep";
default : return null;
}
return switch (material) {
case MUSIC_DISC_13 -> "C418 - 13";
case MUSIC_DISC_CAT -> "C418 - cat";
case MUSIC_DISC_BLOCKS -> "C418 - blocks";
case MUSIC_DISC_CHIRP -> "C418 - chirp";
case MUSIC_DISC_FAR -> "C418 - far";
case MUSIC_DISC_MALL -> "C418 - mall";
case MUSIC_DISC_MELLOHI -> "C418 - mellohi";
case MUSIC_DISC_STAL -> "C418 - stal";
case MUSIC_DISC_STRAD -> "C418 - strad";
case MUSIC_DISC_WARD -> "C418 - ward";
case MUSIC_DISC_11 -> "C418 - 11";
case MUSIC_DISC_WAIT -> "C418 - wait";
case MUSIC_DISC_PIGSTEP -> "Lena Raine - Pigstep";
default -> null;
};
}
}

View File

@ -80,7 +80,7 @@ public class JoinLeaveListener implements Listener {
players.setPlayerName(user);
players.save(playerUUID);
} else {
plugin.logWarning("Player that just logged in has no name! " + playerUUID.toString());
plugin.logWarning("Player that just logged in has no name! " + playerUUID);
}
// If mobs have to be removed when a player joins, then wipe all the mobs on his island.
@ -126,9 +126,8 @@ public class JoinLeaveListener implements Listener {
// - abort on logout is false
// - abort on logout is true && user is online
if (!plugin.getIWM().isCreateIslandOnFirstLoginAbortOnLogout(w) || user.isOnline()){
plugin.getIWM().getAddon(w).ifPresent(addon -> addon.getPlayerCommand()
.map(command -> command.getSubCommand("create").orElse(null))
.ifPresent(command -> command.execute(user, "create", Collections.singletonList(BlueprintsManager.DEFAULT_BUNDLE_NAME))));
plugin.getIWM().getAddon(w).flatMap(addon -> addon.getPlayerCommand().map(command -> command.getSubCommand("create").orElse(null)))
.ifPresent(command -> command.execute(user, "create", Collections.singletonList(BlueprintsManager.DEFAULT_BUNDLE_NAME)));
}
};

View File

@ -47,7 +47,7 @@ public class PlayerEntityPortalEvent {
* @return whether there should create be a destination portal created
*/
public boolean getCanCreatePortal() {
return epe == null ? ppe.getCanCreatePortal() : false;
return epe == null && ppe.getCanCreatePortal();
}
/**

View File

@ -117,7 +117,7 @@ public class PortalTeleportationListener implements Listener {
|| m.equals(Material.END_PORTAL)
|| m.equals(Material.END_GATEWAY))
.findFirst();
if (!mat.isPresent()) {
if (mat.isEmpty()) {
e.setCancelled(true);
return false;
} else if (mat.get().equals(Material.NETHER_PORTAL)){
@ -135,15 +135,11 @@ public class PortalTeleportationListener implements Listener {
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public boolean onIslandPortal(PlayerPortalEvent e) {
switch (e.getCause()) {
case END_GATEWAY:
case END_PORTAL:
return processPortal(new PlayerEntityPortalEvent(e), Environment.THE_END);
case NETHER_PORTAL:
return processPortal(new PlayerEntityPortalEvent(e), Environment.NETHER);
default:
return false;
}
return switch (e.getCause()) {
case END_GATEWAY, END_PORTAL -> processPortal(new PlayerEntityPortalEvent(e), Environment.THE_END);
case NETHER_PORTAL -> processPortal(new PlayerEntityPortalEvent(e), Environment.NETHER);
default -> false;
};
}

View File

@ -1,7 +1,5 @@
package world.bentobox.bentobox.listeners.flags.protection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@ -36,9 +34,7 @@ public class BlockInteractionListener extends FlagListener {
*/
private final static Map<String, String> stringFlags;
static {
Map<String, String> f = new HashMap<>();
f.put("RESPAWN_ANCHOR", "PLACE_BLOCKS");
stringFlags = Collections.unmodifiableMap(f);
stringFlags = Map.<String, String>of("RESPAWN_ANCHOR", "PLACE_BLOCKS");
}
/**

View File

@ -46,9 +46,8 @@ public class BreakBlocksListener extends FlagListener {
checkIsland(e, (Player)e.getRemover(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
}
// Check for projectiles
if (e.getRemover() instanceof Projectile) {
if (e.getRemover() instanceof Projectile p) {
// Find out who fired it
Projectile p = (Projectile)e.getRemover();
if (p.getShooter() instanceof Player) {
checkIsland(e, (Player)p.getShooter(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
}
@ -118,9 +117,8 @@ public class BreakBlocksListener extends FlagListener {
if (e.getDamager() instanceof Player) {
// Check the break blocks flag
notAllowed(e, (Player)e.getDamager(), e.getEntity().getLocation());
} else if (e.getDamager() instanceof Projectile) {
} else if (e.getDamager() instanceof Projectile p) {
// Find out who fired the arrow
Projectile p = (Projectile) e.getDamager();
if (p.getShooter() instanceof Player && notAllowed(e, (Player)p.getShooter(), e.getEntity().getLocation())) {
e.getEntity().setFireTicks(0);
p.setFireTicks(0);

View File

@ -73,8 +73,7 @@ public class BreedingListener extends FlagListener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
Player p = e.getPlayer();
if (e.getRightClicked() instanceof Animals && BREEDING_ITEMS.containsKey(e.getRightClicked().getType())) {
Animals animal = (Animals) e.getRightClicked();
if (e.getRightClicked() instanceof Animals animal && BREEDING_ITEMS.containsKey(e.getRightClicked().getType())) {
ItemStack inHand = p.getInventory().getItemInMainHand();
if (e.getHand().equals(EquipmentSlot.OFF_HAND)) {
inHand = p.getInventory().getItemInOffHand();

View File

@ -40,18 +40,21 @@ public class BucketListener extends FlagListener {
public void onBucketFill(final PlayerBucketFillEvent e) {
// Check filling of various liquids
switch (e.getItemStack().getType()) {
case LAVA_BUCKET:
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA);
return;
case WATER_BUCKET:
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_WATER);
return;
case MILK_BUCKET:
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.MILKING);
return;
default:
// Check general bucket use
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.BUCKET);
case LAVA_BUCKET -> {
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA);
return;
}
case WATER_BUCKET -> {
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_WATER);
return;
}
case MILK_BUCKET -> {
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.MILKING);
return;
}
default ->
// Check general bucket use
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.BUCKET);
}
}

View File

@ -18,8 +18,7 @@ public class ElytraListener extends FlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onGlide(EntityToggleGlideEvent e) {
if (e.getEntity() instanceof Player) {
Player player = (Player) e.getEntity();
if (e.getEntity() instanceof Player player) {
if (!checkIsland(e, player, player.getLocation(), Flags.ELYTRA)) {
player.setGliding(false);
}

View File

@ -71,9 +71,8 @@ public class HurtingListener extends FlagListener {
// Get the attacker
if (damager instanceof Player) {
checkIsland(e, (Player)damager, damager.getLocation(), flag);
} else if (damager instanceof Projectile) {
} else if (damager instanceof Projectile p) {
// Find out who fired the projectile
Projectile p = (Projectile) damager;
if (p.getShooter() instanceof Player && !checkIsland(e, (Player)p.getShooter(), damager.getLocation(), flag)) {
e.getEntity().setFireTicks(0);
}
@ -123,8 +122,7 @@ public class HurtingListener extends FlagListener {
public void onSplashPotionSplash(final PotionSplashEvent e) {
// Try to get the shooter
Projectile projectile = e.getEntity();
if (projectile.getShooter() instanceof Player) {
Player attacker = (Player)projectile.getShooter();
if (projectile.getShooter() instanceof Player attacker) {
// Run through all the affected entities
for (LivingEntity entity: e.getAffectedEntities()) {
// Self damage

View File

@ -72,9 +72,8 @@ public class InventoryListener extends FlagListener {
else if (inventoryHolder instanceof ShulkerBox) {
checkIsland(e, player, e.getInventory().getLocation(), Flags.SHULKER_BOX);
}
else if (inventoryHolder instanceof Chest) {
else if (inventoryHolder instanceof Chest chestInventoryHolder) {
// To differentiate between a Chest and a Trapped Chest we need to get the Block corresponding to the inventory
Chest chestInventoryHolder = (Chest) inventoryHolder;
try {
if (chestInventoryHolder.getType() == Material.TRAPPED_CHEST) {
checkIsland(e, player, e.getInventory().getLocation(), Flags.TRAPPED_CHEST);

View File

@ -53,10 +53,9 @@ public class PhysicalInteractionListener extends FlagListener {
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileHit(EntityInteractEvent e) {
if (!(e.getEntity() instanceof Projectile)) {
if (!(e.getEntity() instanceof Projectile p)) {
return;
}
Projectile p = (Projectile)e.getEntity();
if (p.getShooter() instanceof Player) {
if (Tag.WOODEN_BUTTONS.isTagged(e.getBlock().getType())) {
checkIsland(e, (Player)p.getShooter(), e.getBlock().getLocation(), Flags.BUTTON);
@ -71,23 +70,10 @@ public class PhysicalInteractionListener extends FlagListener {
}
private boolean isPressurePlate(Material material) {
switch(material) {
case STONE_PRESSURE_PLATE:
case POLISHED_BLACKSTONE_PRESSURE_PLATE:
case ACACIA_PRESSURE_PLATE:
case BIRCH_PRESSURE_PLATE:
case CRIMSON_PRESSURE_PLATE:
case DARK_OAK_PRESSURE_PLATE:
case HEAVY_WEIGHTED_PRESSURE_PLATE:
case JUNGLE_PRESSURE_PLATE:
case LIGHT_WEIGHTED_PRESSURE_PLATE:
case OAK_PRESSURE_PLATE:
case SPRUCE_PRESSURE_PLATE:
case WARPED_PRESSURE_PLATE:
return true;
default:
return false;
}
return switch (material) {
case STONE_PRESSURE_PLATE, POLISHED_BLACKSTONE_PRESSURE_PLATE, ACACIA_PRESSURE_PLATE, BIRCH_PRESSURE_PLATE, CRIMSON_PRESSURE_PLATE, DARK_OAK_PRESSURE_PLATE, HEAVY_WEIGHTED_PRESSURE_PLATE, JUNGLE_PRESSURE_PLATE, LIGHT_WEIGHTED_PRESSURE_PLATE, OAK_PRESSURE_PLATE, SPRUCE_PRESSURE_PLATE, WARPED_PRESSURE_PLATE -> true;
default -> false;
};
}
}

View File

@ -1,7 +1,5 @@
package world.bentobox.bentobox.listeners.flags.protection;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.Location;
@ -31,13 +29,13 @@ public class TNTListener extends FlagListener {
* Contains {@link EntityType}s that generates an explosion.
* @since 1.5.0
*/
private static final List<EntityType> TNT_TYPES = Collections.unmodifiableList(Arrays.asList(EntityType.PRIMED_TNT, EntityType.MINECART_TNT));
private static final List<EntityType> TNT_TYPES = List.of(EntityType.PRIMED_TNT, EntityType.MINECART_TNT);
/**
* Contains {@link Material}s that can be used to prime a TNT.
* @since 1.5.0
*/
private static final List<Material> PRIMING_ITEMS = Collections.unmodifiableList(Arrays.asList(Material.FLINT_AND_STEEL, Material.FIRE_CHARGE));
private static final List<Material> PRIMING_ITEMS = List.of(Material.FLINT_AND_STEEL, Material.FIRE_CHARGE);
/**
* Protect TNT from being set light by a fire arrow
@ -50,8 +48,7 @@ public class TNTListener extends FlagListener {
return false;
}
// Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
if (e.getEntity() instanceof Projectile) {
Projectile projectile = (Projectile) e.getEntity();
if (e.getEntity() instanceof Projectile projectile) {
// Find out who fired it
if (projectile.getShooter() instanceof Player && projectile.getFireTicks() > 0
&& !checkIsland(e, (Player)projectile.getShooter(), e.getBlock().getLocation(), Flags.TNT_PRIMING)) {

View File

@ -83,9 +83,8 @@ public class PVPListener extends FlagListener {
user.notify(getFlag(damager.getWorld()).getHintReference());
e.setCancelled(true);
}
} else if (damager instanceof Projectile && ((Projectile)damager).getShooter() instanceof Player) {
} else if (damager instanceof Projectile p && ((Projectile)damager).getShooter() instanceof Player) {
// Find out who fired the arrow
Projectile p = (Projectile) damager;
Player shooter =(Player)p.getShooter();
processDamage(e, damager, shooter, hurtEntity, flag);
} else if (damager instanceof Firework && firedFireworks.containsKey(damager)) {
@ -198,14 +197,11 @@ public class PVPListener extends FlagListener {
}
private Flag getFlag(World w) {
switch (w.getEnvironment()) {
case NETHER:
return Flags.PVP_NETHER;
case THE_END:
return Flags.PVP_END;
default:
return Flags.PVP_OVERWORLD;
}
return switch (w.getEnvironment()) {
case NETHER -> Flags.PVP_NETHER;
case THE_END -> Flags.PVP_END;
default -> Flags.PVP_OVERWORLD;
};
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)

View File

@ -41,8 +41,7 @@ public class CreeperListener extends FlagListener {
}
// Check for griefing
Creeper creeper = (Creeper)e.getEntity();
if (!Flags.CREEPER_GRIEFING.isSetForWorld(e.getLocation().getWorld()) && creeper.getTarget() instanceof Player) {
Player target = (Player)creeper.getTarget();
if (!Flags.CREEPER_GRIEFING.isSetForWorld(e.getLocation().getWorld()) && creeper.getTarget() instanceof Player target) {
if (!getIslands().locationIsOnIsland(target, e.getLocation())) {
User user = User.getInstance(target);
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.CREEPER_GRIEFING.getHintReference()));

View File

@ -69,8 +69,7 @@ public class GeoLimitMobsListener extends FlagListener {
public void onProjectileExplode(final ExplosionPrimeEvent e) {
if (e.getEntity() instanceof Projectile && getIWM().inWorld(e.getEntity().getLocation())) {
ProjectileSource source = ((Projectile)e.getEntity()).getShooter();
if (source instanceof Entity) {
Entity shooter = (Entity)source;
if (source instanceof Entity shooter) {
if (mobSpawnTracker.containsKey(shooter)
&& !mobSpawnTracker.get(shooter).onIsland(e.getEntity().getLocation())) {
e.getEntity().remove();

View File

@ -124,7 +124,7 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVisitorGetDamage(EntityDamageEvent e) {
World world = e.getEntity().getWorld();
if (!(e.getEntity() instanceof Player)
if (!(e.getEntity() instanceof Player p)
|| !getIWM().inWorld(world)
|| e.getEntity().hasMetadata("NPC")
|| !getIWM().getIvSettings(world).contains(e.getCause().name())
@ -133,7 +133,6 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan
}
// Player is a visitor and should be protected from damage
e.setCancelled(true);
Player p = (Player) e.getEntity();
// Handle the void - teleport player back to island in a safe spot
if(e.getCause().equals(DamageCause.VOID)) {
if (getIslands().getIslandAt(p.getLocation()).isPresent()) {

View File

@ -38,7 +38,7 @@ public class LiquidsFlowingOutListener extends FlagListener {
// Only prevent if it is flowing into the area between islands or into another island.
Optional<Island> fromIsland = getIslands().getProtectedIslandAt(from.getLocation());
Optional<Island> toIsland = getIslands().getProtectedIslandAt(to.getLocation());
if (!toIsland.isPresent() || (fromIsland.isPresent() && !fromIsland.equals(toIsland))) {
if (toIsland.isEmpty() || (fromIsland.isPresent() && !fromIsland.equals(toIsland))) {
e.setCancelled(true);
}
}

View File

@ -23,7 +23,7 @@ public class NaturalSpawningOutsideRangeListener extends FlagListener {
}
// If it is a natural spawn and there is no protected island at the location, block the spawn.
if (e.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && !getIslands().getProtectedIslandAt(e.getLocation()).isPresent()) {
if (e.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && getIslands().getProtectedIslandAt(e.getLocation()).isEmpty()) {
e.setCancelled(true);
}
}

View File

@ -25,9 +25,8 @@ public class PetTeleportListener extends FlagListener {
if (e.getTo() == null
|| !getIWM().inWorld(e.getFrom())
|| !Flags.PETS_STAY_AT_HOME.isSetForWorld(e.getFrom().getWorld())
|| !(e.getEntity() instanceof Tameable)
|| !(e.getEntity() instanceof Tameable t)
) return;
Tameable t = (Tameable)e.getEntity();
if (t.isTamed() && t.getOwner() != null) {
// Get where the pet is going
e.setCancelled(getIslands().getProtectedIslandAt(e.getTo())

View File

@ -24,14 +24,14 @@ public class TreesGrowingOutsideRangeListener extends FlagListener {
}
// If there is no protected island at the location of the sapling, just cancel the event (prevents the sapling from growing).
if (!getIslands().getProtectedIslandAt(e.getLocation()).isPresent()) {
if (getIslands().getProtectedIslandAt(e.getLocation()).isEmpty()) {
e.setCancelled(true);
return;
}
// Now, run through all the blocks that will be generated and if there is no protected island at their location, turn them into AIR.
e.getBlocks().stream()
.filter(blockState -> !getIslands().getProtectedIslandAt(blockState.getLocation()).isPresent())
.filter(blockState -> getIslands().getProtectedIslandAt(blockState.getLocation()).isEmpty())
.forEach(blockState -> blockState.setType(Material.AIR));
}
@ -45,13 +45,13 @@ public class TreesGrowingOutsideRangeListener extends FlagListener {
}
// If there is no protected island at the location of the chorus flower, just cancel the event (prevents the flower from growing).
if (!getIslands().getProtectedIslandAt(e.getSource().getLocation()).isPresent()) {
if (getIslands().getProtectedIslandAt(e.getSource().getLocation()).isEmpty()) {
e.setCancelled(true);
return;
}
// Now prevent the flower to grow if this is growing outside the island
if (!getIslands().getProtectedIslandAt(e.getBlock().getLocation()).isPresent()) {
if (getIslands().getProtectedIslandAt(e.getBlock().getLocation()).isEmpty()) {
e.setCancelled(true);
}
}

View File

@ -211,8 +211,7 @@ public class AddonsManager {
// Run the onLoad.
addon.onLoad();
// if game mode, get the world name and generate
if (addon instanceof GameModeAddon && !addon.getState().equals(State.DISABLED)) {
GameModeAddon gameMode = (GameModeAddon) addon;
if (addon instanceof GameModeAddon gameMode && !addon.getState().equals(State.DISABLED)) {
if (!gameMode.getWorldSettings().getWorldName().isEmpty()) {
worldNames.put(gameMode.getWorldSettings().getWorldName().toLowerCase(Locale.ENGLISH), gameMode);
}
@ -282,8 +281,7 @@ public class AddonsManager {
plugin.log("Enabling " + addon.getDescription().getName() + " (" + addon.getDescription().getVersion() + ")...");
try {
// If this is a GameModeAddon create the worlds, register it and load the blueprints
if (addon instanceof GameModeAddon) {
GameModeAddon gameMode = (GameModeAddon) addon;
if (addon instanceof GameModeAddon gameMode) {
// Create the gameWorlds
gameMode.createWorlds();
plugin.getIWM().addGameMode(gameMode);
@ -296,8 +294,7 @@ public class AddonsManager {
plugin.log(addon.getDescription().getName() + " is disabled.");
return;
}
if (addon instanceof GameModeAddon) {
GameModeAddon gameMode = (GameModeAddon) addon;
if (addon instanceof GameModeAddon gameMode) {
// Set the worlds for the commands
gameMode.getPlayerCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld()));
gameMode.getAdminCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld()));
@ -327,7 +324,7 @@ public class AddonsManager {
plugin.logWarning("NOTE: DO NOT report this as a bug from BentoBox.");
StringBuilder a = new StringBuilder();
addon.getDescription().getAuthors().forEach(author -> a.append(author).append(" "));
plugin.getLogger().log(Level.SEVERE, "Please report this stack trace to the addon's author(s): " + a.toString(), e);
plugin.getLogger().log(Level.SEVERE, "Please report this stack trace to the addon's author(s): " + a, e);
}

View File

@ -144,7 +144,7 @@ public class IslandsManager {
depth = i;
} else {
Optional<Island> island = getIslandAt(l);
if (!island.isPresent()) {
if (island.isEmpty()) {
return null;
}
i = island.get().getProtectionRange();
@ -270,31 +270,12 @@ public class IslandsManager {
return false;
}
// Known unsafe blocks
switch (ground) {
// Unsafe
case ANVIL:
case BARRIER:
case CACTUS:
case END_PORTAL:
case END_ROD:
case FIRE:
case FLOWER_POT:
case LADDER:
case LEVER:
case TALL_GRASS:
case PISTON_HEAD:
case MOVING_PISTON:
case TORCH:
case WALL_TORCH:
case TRIPWIRE:
case WATER:
case COBWEB:
case NETHER_PORTAL:
case MAGMA_BLOCK:
return false;
default:
return true;
}
return switch (ground) {
// Unsafe
case ANVIL, BARRIER, CACTUS, END_PORTAL, END_ROD, FIRE, FLOWER_POT, LADDER, LEVER, TALL_GRASS, PISTON_HEAD,
MOVING_PISTON, TORCH, WALL_TORCH, TRIPWIRE, WATER, COBWEB, NETHER_PORTAL, MAGMA_BLOCK -> false;
default -> true;
};
}
/**
@ -324,7 +305,7 @@ public class IslandsManager {
// This should never happen, so although this is a potential infinite loop I'm going to leave it here because
// it will be bad if this does occur and the server should crash.
plugin.logWarning("Duplicate island UUID occurred");
island.setUniqueId(gmName + UUID.randomUUID().toString());
island.setUniqueId(gmName + UUID.randomUUID());
}
if (islandCache.addIsland(island)) {
return island;
@ -919,7 +900,7 @@ public class IslandsManager {
* @since 1.16.0
*/
public boolean removeHomeLocation(@Nullable Island island, String name) {
return island == null ? false : island.removeHome(name);
return island != null && island.removeHome(name);
}
/**
@ -930,7 +911,7 @@ public class IslandsManager {
* @return true if successful, false if not
*/
public boolean renameHomeLocation(@Nullable Island island, String oldName, String newName) {
return island == null ? false : island.renameHome(oldName, newName);
return island != null && island.renameHome(oldName, newName);
}
/**
@ -1200,7 +1181,7 @@ public class IslandsManager {
player.leaveVehicle();
// Remove the boat so they don't lie around everywhere
boat.remove();
Material boatMat = Material.getMaterial(((Boat) boat).getWoodType().toString() + "_BOAT");
Material boatMat = Material.getMaterial(((Boat) boat).getWoodType() + "_BOAT");
if (boatMat == null) {
boatMat = Material.OAK_BOAT;
}
@ -1796,7 +1777,7 @@ public class IslandsManager {
* @since 1.7.0
*/
public boolean nameExists(@NonNull World world, @NonNull String name) {
return getIslands(world).stream().filter(island -> island.getName() != null).map(Island::getName)
return getIslands(world).stream().map(Island::getName).filter(Objects::nonNull)
.anyMatch(n -> ChatColor.stripColor(n).equals(ChatColor.stripColor(name)));
}

View File

@ -102,7 +102,7 @@ public class DefaultNewIslandLocationStrategy implements NewIslandLocationStrate
// Block check
if (plugin.getIWM().isCheckForBlocks(world)
&& !plugin.getIWM().isUseOwnGenerator(world)
&& Arrays.asList(BlockFace.values()).stream().anyMatch(bf ->
&& Arrays.stream(BlockFace.values()).anyMatch(bf ->
!location.getBlock().getRelative(bf).isEmpty()
&& !location.getBlock().getRelative(bf).getType().equals(Material.WATER))) {
// Block found

View File

@ -1,11 +1,9 @@
package world.bentobox.bentobox.managers.island;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@ -115,7 +113,7 @@ public class IslandCache {
grids.putIfAbsent(island.getWorld(), new IslandGrid());
return grids.get(island.getWorld()).removeFromGrid(island);
}
/**
* Delete island from the cache by ID. Does not remove blocks.
* @param uniqueId - island unique ID
@ -180,12 +178,10 @@ public class IslandCache {
@NonNull
public Collection<Island> getIslands(@NonNull World world) {
World overworld = Util.getWorld(world);
List<Island> islandsInWorld = islandsByLocation.entrySet().stream()
.filter(entry -> overworld.equals(Util.getWorld(entry.getKey().getWorld()))) // shouldn't make NPEs
.map(Map.Entry::getValue)
.collect(Collectors.toCollection(ArrayList::new));
return Collections.unmodifiableCollection(islandsInWorld);
return islandsByLocation.entrySet().stream()
.filter(entry -> overworld.equals(Util.getWorld(entry.getKey().getWorld()))) // shouldn't make NPEs
.map(Map.Entry::getValue).collect(Collectors.toUnmodifiableList());
}
/**

View File

@ -16,6 +16,6 @@ public interface NMSAbstraction {
* @param blockData - block data to set the block
* @param applyPhysics - apply physics or not
*/
public void setBlockInNativeChunk(Chunk chunk, int x, int y, int z, BlockData blockData, boolean applyPhysics);
void setBlockInNativeChunk(Chunk chunk, int x, int y, int z, BlockData blockData, boolean applyPhysics);
}

View File

@ -257,21 +257,22 @@ public class BlueprintManagementPanel {
Material icon;
String worldName;
switch (env) {
case NORMAL:
case NORMAL -> {
icon = Material.GRASS_BLOCK;
worldName = normalBlueprint.getName();
break;
case NETHER:
}
case NETHER -> {
icon = Material.NETHERRACK;
worldName = netherBlueprint.getName();
break;
case THE_END:
}
case THE_END -> {
icon = Material.END_STONE;
worldName = endBlueprint.getName();
break;
default:
}
default -> {
icon = Material.STONE;
worldName = Util.prettifyText(env.name());
}
}
return new PanelItemBuilder()

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.panels;
import java.util.Locale;
import java.util.Objects;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
@ -38,11 +39,8 @@ public class LanguagePanel {
BentoBoxLocale language = localesManager.getLanguages().get(locale);
ItemStack localeBanner = language.getBanner();
if (localeBanner != null) {
localeIcon.icon(localeBanner);
} else {
localeIcon.icon(new ItemStack(Material.WHITE_BANNER, 1)); // Set to a blank banner.
}
// Set to a blank banner.
localeIcon.icon(Objects.requireNonNullElseGet(localeBanner, () -> new ItemStack(Material.WHITE_BANNER, 1)));
localeIcon.name(ChatColor.WHITE + WordUtils.capitalize(locale.getDisplayName(user.getLocale())))
.clickHandler((panel, u, click, slot) -> {
BentoBox.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag());

View File

@ -53,86 +53,86 @@ public class ManagementPanel {
int i = 0;
List<? extends Addon> addons;
switch (view) {
case GAMEMODES:
addons = plugin.getAddonsManager().getGameModeAddons();
if (addons.isEmpty()) {
looksEmpty(builder, user);
break;
}
for (Addon addon : addons) {
GameModeAddon gameModeAddon = (GameModeAddon) addon;
PanelItem addonItem = new PanelItemBuilder()
.icon(addon.getDescription().getIcon())
.name(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.name", TextVariables.NAME, addon.getDescription().getName()))
.description(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.description",
"[islands]", String.valueOf(addon.getIslands().getIslandCount(gameModeAddon.getOverWorld()))))
.clickHandler((panel, user1, clickType, slot) -> {
if (clickType.equals(ClickType.MIDDLE)) {
CreditsPanel.openPanel(user, addon);
}
return true;
})
.build();
case GAMEMODES -> {
addons = plugin.getAddonsManager().getGameModeAddons();
if (addons.isEmpty()) {
looksEmpty(builder, user);
break;
}
for (Addon addon : addons) {
GameModeAddon gameModeAddon = (GameModeAddon) addon;
PanelItem addonItem = new PanelItemBuilder()
.icon(addon.getDescription().getIcon())
.name(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.name", TextVariables.NAME, addon.getDescription().getName()))
.description(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.description",
"[islands]", String.valueOf(addon.getIslands().getIslandCount(gameModeAddon.getOverWorld()))))
.clickHandler((panel, user1, clickType, slot) -> {
if (clickType.equals(ClickType.MIDDLE)) {
CreditsPanel.openPanel(user, addon);
}
return true;
})
.build();
builder.item(startSlot + i, addonItem);
builder.item(startSlot + i, addonItem);
PanelItem blueprints = new PanelItemBuilder()
.icon(Material.STRUCTURE_BLOCK)
.name(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.name"))
.description(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.description"))
.clickHandler((panel, user1, clickType, slot) -> {
new BlueprintManagementPanel(plugin, user, gameModeAddon).openPanel();
return true;
})
.build();
PanelItem blueprints = new PanelItemBuilder()
.icon(Material.STRUCTURE_BLOCK)
.name(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.name"))
.description(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.description"))
.clickHandler((panel, user1, clickType, slot) -> {
new BlueprintManagementPanel(plugin, user, gameModeAddon).openPanel();
return true;
})
.build();
builder.item(startSlot + i + 9, blueprints);
i++;
}
break;
case ADDONS:
addons = plugin.getAddonsManager().getEnabledAddons().stream().filter(addon -> !(addon instanceof GameModeAddon)).collect(Collectors.toList());
if (addons.isEmpty()) {
looksEmpty(builder, user);
break;
}
for (Addon addon : addons) {
PanelItem addonItem = new PanelItemBuilder()
.icon(addon.getDescription().getIcon())
.name(ChatColor.WHITE + addon.getDescription().getName())
.clickHandler((panel, user1, clickType, slot) -> {
if (clickType.equals(ClickType.MIDDLE)) {
CreditsPanel.openPanel(user, addon);
}
return true;
})
.build();
builder.item(startSlot + i, addonItem);
i++;
if (builder.slotOccupied(startSlot + i)) {
i = i+2;
builder.item(startSlot + i + 9, blueprints);
i++;
}
}
break;
case HOOKS:
if (plugin.getHooks().getHooks().isEmpty()) {
looksEmpty(builder, user);
break;
}
for (Hook hook : plugin.getHooks().getHooks()) {
PanelItem hookItem = new PanelItemBuilder()
.icon(hook.getIcon())
.name(ChatColor.WHITE + hook.getPluginName())
.build();
case ADDONS -> {
addons = plugin.getAddonsManager().getEnabledAddons().stream().filter(addon -> !(addon instanceof GameModeAddon)).collect(Collectors.toList());
if (addons.isEmpty()) {
looksEmpty(builder, user);
break;
}
for (Addon addon : addons) {
PanelItem addonItem = new PanelItemBuilder()
.icon(addon.getDescription().getIcon())
.name(ChatColor.WHITE + addon.getDescription().getName())
.clickHandler((panel, user1, clickType, slot) -> {
if (clickType.equals(ClickType.MIDDLE)) {
CreditsPanel.openPanel(user, addon);
}
return true;
})
.build();
builder.item(startSlot + i, hookItem);
i++;
if (builder.slotOccupied(startSlot + i)) {
i = i+2;
builder.item(startSlot + i, addonItem);
i++;
if (builder.slotOccupied(startSlot + i)) {
i = i + 2;
}
}
}
case HOOKS -> {
if (plugin.getHooks().getHooks().isEmpty()) {
looksEmpty(builder, user);
break;
}
for (Hook hook : plugin.getHooks().getHooks()) {
PanelItem hookItem = new PanelItemBuilder()
.icon(hook.getIcon())
.name(ChatColor.WHITE + hook.getPluginName())
.build();
builder.item(startSlot + i, hookItem);
i++;
if (builder.slotOccupied(startSlot + i)) {
i = i + 2;
}
}
}
break;
}
// Setup a few more buttons
@ -196,15 +196,9 @@ public class ManagementPanel {
});
switch (view) {
case GAMEMODES:
gamemodesIconBuilder.glow(true);
break;
case ADDONS:
addonsIconBuilder.glow(true);
break;
case HOOKS:
hooksIconBuilder.glow(true);
break;
case GAMEMODES -> gamemodesIconBuilder.glow(true);
case ADDONS -> addonsIconBuilder.glow(true);
case HOOKS -> hooksIconBuilder.glow(true);
}
builder.item(1, gamemodesIconBuilder.build());
@ -235,16 +229,9 @@ public class ManagementPanel {
TextVariables.VERSION, serverVersion != null ? serverVersion.toString() : user.getTranslation("general.invalid")));
switch (compatibility) {
case COMPATIBLE:
case SUPPORTED:
compatibilityItemBuilder.icon(Material.GREEN_CONCRETE);
break;
case NOT_SUPPORTED:
compatibilityItemBuilder.icon(Material.ORANGE_CONCRETE);
break;
case INCOMPATIBLE:
compatibilityItemBuilder.icon(Material.RED_CONCRETE);
break;
case COMPATIBLE, SUPPORTED -> compatibilityItemBuilder.icon(Material.GREEN_CONCRETE);
case NOT_SUPPORTED -> compatibilityItemBuilder.icon(Material.ORANGE_CONCRETE);
case INCOMPATIBLE -> compatibilityItemBuilder.icon(Material.RED_CONCRETE);
}
builder.item(7, compatibilityItemBuilder.build());

View File

@ -135,27 +135,22 @@ public class SettingsTab implements Tab, ClickHandler {
icons.put(5, Flags.LOCK.toPanelItem(plugin, user, island, false));
}
// Add the mode icon
switch(plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId())) {
case ADVANCED:
icons.put(7, new PanelItemBuilder().icon(Material.GOLD_INGOT)
switch (plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId())) {
case ADVANCED -> icons.put(7, new PanelItemBuilder().icon(Material.GOLD_INGOT)
.name(user.getTranslation(PROTECTION_PANEL + "mode.advanced.name"))
.description(user.getTranslation(PROTECTION_PANEL + "mode.advanced.description"), "",
user.getTranslation(CLICK_TO_SWITCH,
TextVariables.NEXT, user.getTranslation(PROTECTION_PANEL + "mode.expert.name")))
.clickHandler(this)
.build());
break;
case EXPERT:
icons.put(7, new PanelItemBuilder().icon(Material.NETHER_BRICK)
case EXPERT -> icons.put(7, new PanelItemBuilder().icon(Material.NETHER_BRICK)
.name(user.getTranslation(PROTECTION_PANEL + "mode.expert.name"))
.description(user.getTranslation(PROTECTION_PANEL + "mode.expert.description"), "",
user.getTranslation(CLICK_TO_SWITCH,
TextVariables.NEXT, user.getTranslation(PROTECTION_PANEL + "mode.basic.name")))
.clickHandler(this)
.build());
break;
default:
icons.put(7, new PanelItemBuilder().icon(Material.IRON_INGOT)
default -> icons.put(7, new PanelItemBuilder().icon(Material.IRON_INGOT)
.name(user.getTranslation(PROTECTION_PANEL + "mode.basic.name"))
.description(user.getTranslation(PROTECTION_PANEL + "mode.basic.description"), "",
user.getTranslation(CLICK_TO_SWITCH,
@ -219,8 +214,7 @@ public class SettingsTab implements Tab, ClickHandler {
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
// Cycle the mode
plugin.getPlayers().setFlagsDisplayMode(user.getUniqueId(), plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId()).getNext());
if (panel instanceof TabbedPanel) {
TabbedPanel tp = ((TabbedPanel)panel);
if (panel instanceof TabbedPanel tp) {
tp.setActivePage(0);
tp.refreshPanel();
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 1F, 1F);

View File

@ -67,10 +67,9 @@ public class Pair<X, Z> {
if (obj == null) {
return false;
}
if (!(obj instanceof Pair)) {
if (!(obj instanceof Pair<?, ?> other)) {
return false;
}
Pair<?, ?> other = (Pair<?, ?>) obj;
if (x == null) {
if (other.x != null) {
return false;

View File

@ -278,38 +278,23 @@ public class Util {
* @return degrees
*/
public static float blockFaceToFloat(BlockFace face) {
switch (face) {
case EAST:
return 90F;
case EAST_NORTH_EAST:
return 67.5F;
case NORTH_EAST:
return 45F;
case NORTH_NORTH_EAST:
return 22.5F;
case NORTH_NORTH_WEST:
return 337.5F;
case NORTH_WEST:
return 315F;
case SOUTH:
return 180F;
case SOUTH_EAST:
return 135F;
case SOUTH_SOUTH_EAST:
return 157.5F;
case SOUTH_SOUTH_WEST:
return 202.5F;
case SOUTH_WEST:
return 225F;
case WEST:
return 270F;
case WEST_NORTH_WEST:
return 292.5F;
case WEST_SOUTH_WEST:
return 247.5F;
default:
return 0F;
}
return switch (face) {
case EAST -> 90F;
case EAST_NORTH_EAST -> 67.5F;
case NORTH_EAST -> 45F;
case NORTH_NORTH_EAST -> 22.5F;
case NORTH_NORTH_WEST -> 337.5F;
case NORTH_WEST -> 315F;
case SOUTH -> 180F;
case SOUTH_EAST -> 135F;
case SOUTH_SOUTH_EAST -> 157.5F;
case SOUTH_SOUTH_WEST -> 202.5F;
case SOUTH_WEST -> 225F;
case WEST -> 270F;
case WEST_NORTH_WEST -> 292.5F;
case WEST_SOUTH_WEST -> 247.5F;
default -> 0F;
};
}
/**