Migrate left over occurrences to enhanced switches (#3979)

* Migrate left-overs to enhanced switches

* More
This commit is contained in:
Alexander Brandes
2023-03-06 10:25:02 +01:00
committed by GitHub
parent 42e146b8c7
commit 89031447f2
16 changed files with 243 additions and 418 deletions

View File

@ -107,37 +107,35 @@ public class Clear extends Command {
}
BackupManager.backup(player, plot, () -> {
final long start = System.currentTimeMillis();
boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> {
TaskManager.runTask(() -> {
plot.removeRunning();
// If the state changes, then mark it as no longer done
if (DoneFlag.isDone(plot)) {
PlotFlag<?, ?> plotFlag =
plot.getFlagContainer().getFlag(DoneFlag.class);
PlotFlagRemoveEvent event = this.eventDispatcher
.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> TaskManager.runTask(() -> {
plot.removeRunning();
// If the state changes, then mark it as no longer done
if (DoneFlag.isDone(plot)) {
PlotFlag<?, ?> plotFlag =
plot.getFlagContainer().getFlag(DoneFlag.class);
PlotFlagRemoveEvent event = this.eventDispatcher
.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
if (!plot.getFlag(AnalysisFlag.class).isEmpty()) {
PlotFlag<?, ?> plotFlag =
plot.getFlagContainer().getFlag(AnalysisFlag.class);
PlotFlagRemoveEvent event = this.eventDispatcher
.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
}
if (!plot.getFlag(AnalysisFlag.class).isEmpty()) {
PlotFlag<?, ?> plotFlag =
plot.getFlagContainer().getFlag(AnalysisFlag.class);
PlotFlagRemoveEvent event = this.eventDispatcher
.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
player.sendMessage(
TranslatableCaption.of("working.clearing_done"),
TagResolver.builder()
.tag("amount", Tag.inserting(Component.text(System.currentTimeMillis() - start)))
.tag("plot", Tag.inserting(Component.text(plot.getId().toString())))
.build()
);
});
});
}
player.sendMessage(
TranslatableCaption.of("working.clearing_done"),
TagResolver.builder()
.tag("amount", Tag.inserting(Component.text(System.currentTimeMillis() - start)))
.tag("plot", Tag.inserting(Component.text(plot.getId().toString())))
.build()
);
}));
if (!result) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
} else {

View File

@ -46,6 +46,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
@ -77,8 +78,7 @@ public class Cluster extends SubCommand {
}
String sub = args[0].toLowerCase();
switch (sub) {
case "l":
case "list": {
case "l", "list" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_LIST)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -133,8 +133,7 @@ public class Cluster extends SubCommand {
}
return true;
}
case "c":
case "create": {
case "c", "create" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_CREATE)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -269,9 +268,7 @@ public class Cluster extends SubCommand {
);
return true;
}
case "disband":
case "del":
case "delete": {
case "disband", "del", "delete" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_DELETE)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -330,8 +327,7 @@ public class Cluster extends SubCommand {
));
return true;
}
case "res":
case "resize": {
case "res", "resize" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_RESIZE)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -452,9 +448,7 @@ public class Cluster extends SubCommand {
player.sendMessage(TranslatableCaption.of("cluster.cluster_resized"));
return true;
}
case "add":
case "inv":
case "invite": {
case "add", "inv", "invite" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_INVITE)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -523,9 +517,7 @@ public class Cluster extends SubCommand {
});
return true;
}
case "k":
case "remove":
case "kick": {
case "k", "remove", "kick" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_KICK)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -605,8 +597,7 @@ public class Cluster extends SubCommand {
});
return true;
}
case "quit":
case "leave": {
case "quit", "leave" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_LEAVE)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -667,7 +658,7 @@ public class Cluster extends SubCommand {
removePlayerPlots(cluster, uuid, player.getLocation().getWorldName());
return true;
}
case "members": {
case "members" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_HELPERS)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -728,9 +719,7 @@ public class Cluster extends SubCommand {
});
return true;
}
case "spawn":
case "home":
case "tp": {
case "spawn", "home", "tp" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_TP)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -778,10 +767,7 @@ public class Cluster extends SubCommand {
player.sendMessage(TranslatableCaption.of("cluster.cluster_teleporting"));
return true;
}
case "i":
case "info":
case "show":
case "information": {
case "i", "info", "show", "information" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_INFO)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
@ -828,11 +814,7 @@ public class Cluster extends SubCommand {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
} else {
final String owner;
if (username == null) {
owner = "unknown";
} else {
owner = username;
}
owner = Objects.requireNonNullElse(username, "unknown");
String name = cluster.getName();
String size = (cluster.getP2().getX() - cluster.getP1().getX() + 1) + "x" + (
cluster.getP2().getY() - cluster.getP1().getY() + 1);
@ -850,9 +832,7 @@ public class Cluster extends SubCommand {
});
return true;
}
case "sh":
case "setspawn":
case "sethome": {
case "sh", "setspawn", "sethome" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_SETHOME)) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),

View File

@ -559,9 +559,10 @@ public abstract class Command {
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
switch (args.length) {
case 0:
case 0 -> {
return this.allCommands;
case 1:
}
case 1 -> {
String arg = args[0].toLowerCase();
if (space) {
Command cmd = getCommand(arg);
@ -580,13 +581,15 @@ public abstract class Command {
}
return commands;
}
default:
}
default -> {
Command cmd = getCommand(args[0]);
if (cmd != null) {
return cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space);
} else {
return null;
}
}
}
}

View File

@ -75,16 +75,19 @@ public class DebugRoadRegen extends SubCommand {
}
String kind = args[0].toLowerCase();
switch (kind) {
case "plot":
case "plot" -> {
return regenPlot(player);
case "region":
}
case "region" -> {
return regenRegion(player, Arrays.copyOfRange(args, 1, args.length));
default:
}
default -> {
player.sendMessage(
TranslatableCaption.of("commandconfig.command_syntax"),
TagResolver.resolver("value", Tag.inserting(Component.text(DebugRoadRegen.USAGE)))
);
return false;
}
}
}

View File

@ -60,9 +60,10 @@ public class Help extends Command {
RunnableVal2<Command, CommandResult> whenDone
) {
switch (args.length) {
case 0:
case 0 -> {
return displayHelp(player, null, 0);
case 1:
}
case 1 -> {
if (MathMan.isInteger(args[0])) {
try {
return displayHelp(player, null, Integer.parseInt(args[0]));
@ -72,7 +73,8 @@ public class Help extends Command {
} else {
return displayHelp(player, args[0], 1);
}
case 2:
}
case 2 -> {
if (MathMan.isInteger(args[1])) {
try {
return displayHelp(player, args[0], Integer.parseInt(args[1]));
@ -81,8 +83,8 @@ public class Help extends Command {
}
}
return CompletableFuture.completedFuture(false);
default:
sendUsage(player);
}
default -> sendUsage(player);
}
return CompletableFuture.completedFuture(true);
}

View File

@ -190,7 +190,7 @@ public class Inbox extends SubCommand {
final int page;
if (args.length > 1) {
switch (args[1].toLowerCase()) {
case "delete":
case "delete" -> {
if (!inbox.canModify(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
return false;
@ -225,7 +225,6 @@ public class Inbox extends SubCommand {
);
return false;
}
if (!inbox.getComments(plot, new RunnableVal<>() {
@Override
public void run(List<PlotComment> value) {
@ -254,7 +253,8 @@ public class Inbox extends SubCommand {
return false;
}
return true;
case "clear":
}
case "clear" -> {
if (!inbox.canModify(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
}
@ -268,13 +268,15 @@ public class Inbox extends SubCommand {
plot.getPlotCommentContainer().removeComments(comments);
}
return true;
default:
}
default -> {
try {
page = Integer.parseInt(args[1]);
} catch (NumberFormatException ignored) {
sendUsage(player);
return false;
}
}
}
} else {
page = 1;

View File

@ -90,12 +90,8 @@ public class Purge extends SubCommand {
return false;
}
switch (split[0].toLowerCase()) {
case "world":
case "w":
world = split[1];
break;
case "area":
case "a":
case "world", "w" -> world = split[1];
case "area", "a" -> {
area = this.plotAreaManager.getPlotAreaByString(split[1]);
if (area == null) {
player.sendMessage(
@ -104,9 +100,8 @@ public class Purge extends SubCommand {
);
return false;
}
break;
case "plotid":
case "id":
}
case "plotid", "id" -> {
try {
id = PlotId.fromString(split[1]);
} catch (IllegalArgumentException ignored) {
@ -116,9 +111,8 @@ public class Purge extends SubCommand {
);
return false;
}
break;
case "owner":
case "o":
}
case "owner", "o" -> {
UUIDMapping ownerMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
if (ownerMapping == null) {
player.sendMessage(
@ -128,9 +122,8 @@ public class Purge extends SubCommand {
return false;
}
owner = ownerMapping.uuid();
break;
case "shared":
case "s":
}
case "shared", "s" -> {
UUIDMapping addedMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
if (addedMapping == null) {
player.sendMessage(
@ -140,22 +133,13 @@ public class Purge extends SubCommand {
return false;
}
added = addedMapping.uuid();
break;
case "clear":
case "c":
case "delete":
case "d":
case "del":
clear = Boolean.parseBoolean(split[1]);
break;
case "unknown":
case "?":
case "u":
unknown = Boolean.parseBoolean(split[1]);
break;
default:
}
case "clear", "c", "delete", "d", "del" -> clear = Boolean.parseBoolean(split[1]);
case "unknown", "?", "u" -> unknown = Boolean.parseBoolean(split[1]);
default -> {
sendUsage(player);
return false;
}
}
}
final HashSet<Plot> toDelete = new HashSet<>();
@ -236,9 +220,8 @@ public class Purge extends SubCommand {
try {
ids.add(plot.temp);
if (finalClear) {
plot.getPlotModificationManager().clear(false, true, player, () -> {
LOGGER.info("Plot {} cleared by purge", plot.getId());
});
plot.getPlotModificationManager().clear(false, true, player,
() -> LOGGER.info("Plot {} cleared by purge", plot.getId()));
} else {
plot.getPlotModificationManager().removeSign();
}

View File

@ -185,30 +185,38 @@ public abstract class SquarePlotManager extends GridPlotManager {
return null;
}
switch (hash) {
case 8:
case 8 -> {
// north
return plot.isMerged(Direction.NORTH) ? id : null;
case 4:
}
case 4 -> {
// east
return plot.isMerged(Direction.EAST) ? id : null;
case 2:
}
case 2 -> {
// south
return plot.isMerged(Direction.SOUTH) ? id : null;
case 1:
}
case 1 -> {
// west
return plot.isMerged(Direction.WEST) ? id : null;
case 12:
}
case 12 -> {
// northeast
return plot.isMerged(Direction.NORTHEAST) ? id : null;
case 6:
}
case 6 -> {
// southeast
return plot.isMerged(Direction.SOUTHEAST) ? id : null;
case 3:
}
case 3 -> {
// southwest
return plot.isMerged(Direction.SOUTHWEST) ? id : null;
case 9:
}
case 9 -> {
// northwest
return plot.isMerged(Direction.NORTHWEST) ? id : null;
}
}
} catch (Exception ignored) {
LOGGER.error("Invalid plot / road width in settings.yml for world: {}", squarePlotWorld.getWorldName());

View File

@ -57,24 +57,15 @@ public class DenyTeleportFlag extends PlotFlag<DenyTeleportFlag.DeniedGroup, Den
}
final boolean result;
switch (value) {
case TRUSTED:
result = !plot.getTrusted().contains(player.getUUID());
break;
case MEMBERS:
result = !plot.getMembers().contains(player.getUUID());
break;
case NONMEMBERS:
result = plot.isAdded(player.getUUID());
break;
case NONTRUSTED:
result =
plot.getTrusted().contains(player.getUUID()) || plot.isOwner(player.getUUID());
break;
case NONOWNERS:
result = plot.isOwner(player.getUUID());
break;
default:
case TRUSTED -> result = !plot.getTrusted().contains(player.getUUID());
case MEMBERS -> result = !plot.getMembers().contains(player.getUUID());
case NONMEMBERS -> result = plot.isAdded(player.getUUID());
case NONTRUSTED -> result =
plot.getTrusted().contains(player.getUUID()) || plot.isOwner(player.getUUID());
case NONOWNERS -> result = plot.isOwner(player.getUUID());
default -> {
return true;
}
}
return result || player.hasPermission("plots.admin.entry.denied");
}

View File

@ -68,14 +68,11 @@ public class FlyFlag extends PlotFlag<FlyFlag.FlyStatus, FlyFlag> {
@Override
protected FlyFlag flagOf(final @NonNull FlyStatus value) {
switch (value) {
case ENABLED:
return FLIGHT_FLAG_ENABLED;
case DISABLED:
return FLIGHT_FLAG_DISABLED;
default:
return FLIGHT_FLAG_DEFAULT;
}
return switch (value) {
case ENABLED -> FLIGHT_FLAG_ENABLED;
case DISABLED -> FLIGHT_FLAG_DISABLED;
default -> FLIGHT_FLAG_DEFAULT;
};
}
@Override

View File

@ -36,6 +36,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@ -92,11 +93,7 @@ public class DefaultProgressSubscriber implements ProgressSubscriber {
this.actor = actor;
this.interval = TaskTime.ms(interval);
this.wait = TaskTime.ms(wait);
if (caption == null) {
this.caption = TranslatableCaption.of("working.progress");
} else {
this.caption = caption;
}
this.caption = Objects.requireNonNullElseGet(caption, () -> TranslatableCaption.of("working.progress"));
}
@Override

View File

@ -359,11 +359,13 @@ public class EventDispatcher {
}
}
switch (type) {
case TELEPORT_OBJECT:
case TELEPORT_OBJECT -> {
return false;
case READ:
}
case READ -> {
return true;
case INTERACT_BLOCK: {
}
case INTERACT_BLOCK -> {
if (plot == null) {
final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) {
@ -398,7 +400,7 @@ public class EventDispatcher {
}
return false;
}
case TRIGGER_PHYSICAL: {
case TRIGGER_PHYSICAL -> {
if (plot == null) {
final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) {
@ -430,7 +432,7 @@ public class EventDispatcher {
false
);
}
case SPAWN_MOB: {
case SPAWN_MOB -> {
if (plot == null) {
return player.hasPermission(
Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms
@ -472,7 +474,7 @@ public class EventDispatcher {
}
return false;
}
case PLACE_MISC: {
case PLACE_MISC -> {
if (plot == null) {
return player.hasPermission(
Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms
@ -514,7 +516,7 @@ public class EventDispatcher {
}
return false;
}
case PLACE_VEHICLE:
case PLACE_VEHICLE -> {
if (plot == null) {
return player.hasPermission(
Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms
@ -526,8 +528,9 @@ public class EventDispatcher {
);
}
return plot.getFlag(VehiclePlaceFlag.class);
default:
break;
}
default -> {
}
}
return true;
}