From a5c53a96d1c79b07af5c591a4c837279d67647e4 Mon Sep 17 00:00:00 2001 From: Alexander Brandes Date: Sun, 5 Mar 2023 10:07:36 +0100 Subject: [PATCH] Record-inize methods (#3976) --- .../bukkit/placeholder/MVdWPlaceholders.java | 2 +- .../plotsquared/bukkit/queue/GenChunk.java | 6 +- .../bukkit/util/BukkitSetupUtils.java | 2 +- .../bukkit/uuid/SQLiteUUIDService.java | 4 +- .../core/backup/SimpleBackupManager.java | 40 ++++--- .../com/plotsquared/core/command/Auto.java | 3 +- .../com/plotsquared/core/command/Inbox.java | 16 +-- .../com/plotsquared/core/command/ListCmd.java | 8 +- .../com/plotsquared/core/command/Purge.java | 4 +- .../plotsquared/core/command/Template.java | 4 +- .../core/components/ComponentPreset.java | 59 ++--------- .../components/ComponentPresetManager.java | 30 +++--- .../plotsquared/core/database/SQLManager.java | 33 +++--- .../core/listener/PlotListener.java | 8 +- .../core/location/ChunkWrapper.java | 16 +-- .../plotsquared/core/plot/BlockBucket.java | 64 ++--------- .../plotsquared/core/plot/PlotSettings.java | 3 +- .../core/plot/comment/CommentManager.java | 2 +- .../core/plot/comment/PlotComment.java | 28 ++--- .../plot/flag/implementations/FeedFlag.java | 2 +- .../plot/flag/implementations/HealFlag.java | 2 +- .../core/plot/flag/types/TimedFlag.java | 29 ++--- .../core/services/plots/AutoQuery.java | 94 ++++++++++++++++ .../core/services/plots/AutoService.java | 100 ++---------------- .../core/setup/SettingsNodeStep.java | 6 +- .../core/setup/SettingsNodesWrapper.java | 21 +--- .../com/plotsquared/core/util/FileBytes.java | 13 +-- .../plotsquared/core/util/PlayerManager.java | 6 +- .../plotsquared/core/util/TabCompletions.java | 4 +- .../placeholders/PlaceholderRegistry.java | 18 +--- .../core/uuid/CacheUUIDService.java | 4 +- .../plotsquared/core/uuid/UUIDMapping.java | 39 +------ .../plotsquared/core/uuid/UUIDPipeline.java | 16 +-- 33 files changed, 258 insertions(+), 428 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/services/plots/AutoQuery.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java index 426a88ec6..b7a311345 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java @@ -52,7 +52,7 @@ public class MVdWPlaceholders { @Subscribe public void onNewPlaceholder(final PlaceholderRegistry.@NonNull PlaceholderAddedEvent event) { - this.addPlaceholder(event.getPlaceholder()); + this.addPlaceholder(event.placeholder()); } private void addPlaceholder(final @NonNull Placeholder placeholder) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java index 9542bddbf..94e2cdde9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java @@ -110,9 +110,9 @@ public class GenChunk extends ZeroedDelegateScopedQueueCoordinator { */ public void setChunk(@NonNull ChunkWrapper wrap) { chunk = null; - world = wrap.world; - chunkX = wrap.x; - chunkZ = wrap.z; + world = wrap.world(); + chunkX = wrap.x(); + chunkZ = wrap.z(); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index 911b40c95..88ede2cc5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -124,7 +124,7 @@ public class BukkitSetupUtils extends SetupUtils { public String setupWorld(PlotAreaBuilder builder) { this.updateGenerators(false); ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ? - new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes(); + new ConfigurationNode[0] : builder.settingsNodesWrapper().settingsNodes(); String world = builder.worldName(); PlotAreaType type = builder.plotAreaType(); String worldPath = "worlds." + builder.worldName(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java index 3e816548a..9193b4f0a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java @@ -111,8 +111,8 @@ public class SQLiteUUIDService implements UUIDService, Consumer plots = this.servicePipeline - .pump(new AutoService.AutoQuery(player, null, sizeX, sizeZ, plotarea)) + .pump(new AutoQuery(player, null, sizeX, sizeZ, plotarea)) .through(AutoService.class) .getResult(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Inbox.java b/Core/src/main/java/com/plotsquared/core/command/Inbox.java index 35dac0e27..e0e2ec5d7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Inbox.java +++ b/Core/src/main/java/com/plotsquared/core/command/Inbox.java @@ -85,24 +85,24 @@ public class Inbox extends SubCommand { for (int x = page * 12; x < max; x++) { PlotComment comment = comments[x]; Component commentColored; - if (player.getName().equals(comment.senderName)) { + if (player.getName().equals(comment.senderName())) { commentColored = MINI_MESSAGE .deserialize( TranslatableCaption.of("list.comment_list_by_lister").getComponent(player), - TagResolver.resolver("comment", Tag.inserting(Component.text(comment.comment))) + TagResolver.resolver("comment", Tag.inserting(Component.text(comment.comment()))) ); } else { commentColored = MINI_MESSAGE .deserialize( TranslatableCaption.of("list.comment_list_by_other").getComponent(player), - TagResolver.resolver("comment", Tag.inserting(Component.text(comment.comment))) + TagResolver.resolver("comment", Tag.inserting(Component.text(comment.comment()))) ); } TagResolver resolver = TagResolver.builder() .tag("number", Tag.inserting(Component.text(x))) - .tag("world", Tag.inserting(Component.text(comment.world))) - .tag("plot_id", Tag.inserting(Component.text(comment.id.getX() + ";" + comment.id.getY()))) - .tag("commenter", Tag.inserting(Component.text(comment.senderName))) + .tag("world", Tag.inserting(Component.text(comment.world()))) + .tag("plot_id", Tag.inserting(Component.text(comment.id().getX() + ";" + comment.id().getY()))) + .tag("commenter", Tag.inserting(Component.text(comment.senderName()))) .tag("comment", Tag.inserting(commentColored)) .build(); builder.append(MINI_MESSAGE @@ -137,7 +137,7 @@ public class Inbox extends SubCommand { int unread = 0; for (PlotComment comment : value) { total++; - if (comment.timestamp > CommentManager + if (comment.timestamp() > CommentManager .getTimestamp(player, inbox.toString())) { unread++; } @@ -242,7 +242,7 @@ public class Inbox extends SubCommand { if (success) { player.sendMessage( TranslatableCaption.of("comment.comment_removed_success"), - TagResolver.resolver("value", Tag.inserting(Component.text(comment.comment))) + TagResolver.resolver("value", Tag.inserting(Component.text(comment.comment()))) ); } else { player.sendMessage( diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index 6781d4758..4533a15db 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -474,20 +474,20 @@ public class ListCmd extends SubCommand { final List names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners()) .get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS); for (final UUIDMapping uuidMapping : names) { - PlotPlayer pp = PlotSquared.platform().playerManager().getPlayerIfExists(uuidMapping.getUuid()); + PlotPlayer pp = PlotSquared.platform().playerManager().getPlayerIfExists(uuidMapping.uuid()); TagResolver resolver = TagResolver.builder() .tag("prefix", Tag.inserting(Component.text(prefix))) - .tag("player", Tag.inserting(Component.text(uuidMapping.getUsername()))) + .tag("player", Tag.inserting(Component.text(uuidMapping.username()))) .build(); if (pp != null) { builder.append(MINI_MESSAGE.deserialize(online, resolver)); - } else if (uuidMapping.getUsername().equalsIgnoreCase("unknown")) { + } else if (uuidMapping.username().equalsIgnoreCase("unknown")) { TagResolver unknownResolver = TagResolver.resolver( "info.unknown", Tag.inserting(TranslatableCaption.of("info.unknown").toComponent(player)) ); builder.append(MINI_MESSAGE.deserialize(unknown, unknownResolver)); - } else if (uuidMapping.getUuid().equals(DBFunc.EVERYONE)) { + } else if (uuidMapping.uuid().equals(DBFunc.EVERYONE)) { TagResolver everyoneResolver = TagResolver.resolver( "info.everyone", Tag.inserting(TranslatableCaption.of("info.everyone").toComponent(player)) diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 12c2c93d7..8a14d7306 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -127,7 +127,7 @@ public class Purge extends SubCommand { ); return false; } - owner = ownerMapping.getUuid(); + owner = ownerMapping.uuid(); break; case "shared": case "s": @@ -139,7 +139,7 @@ public class Purge extends SubCommand { ); return false; } - added = addedMapping.getUuid(); + added = addedMapping.uuid(); break; case "clear": case "c": diff --git a/Core/src/main/java/com/plotsquared/core/command/Template.java b/Core/src/main/java/com/plotsquared/core/command/Template.java index d9a5da2b0..b96f1a58d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Template.java +++ b/Core/src/main/java/com/plotsquared/core/command/Template.java @@ -156,9 +156,9 @@ public class Template extends SubCommand { ZipOutputStream zos = new ZipOutputStream(fos)) { for (FileBytes file : files) { - ZipEntry ze = new ZipEntry(file.path); + ZipEntry ze = new ZipEntry(file.path()); zos.putNextEntry(ze); - zos.write(file.data); + zos.write(file.data()); } zos.closeEntry(); } diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPreset.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPreset.java index cb1e989c4..f4b04d5c5 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPreset.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPreset.java @@ -35,28 +35,15 @@ import java.util.Map; * the component GUI */ @SerializableAs("preset") -public class ComponentPreset implements ConfigurationSerializable { - - private final ClassicPlotManagerComponent component; - private final String pattern; - private final double cost; - private final String permission; - private final String displayName; - private final List description; - private final ItemType icon; - - public ComponentPreset( - ClassicPlotManagerComponent component, String pattern, double cost, - String permission, String displayName, List description, final ItemType icon - ) { - this.component = component; - this.pattern = pattern; - this.cost = cost; - this.permission = permission; - this.displayName = displayName; - this.description = description; - this.icon = icon; - } +public record ComponentPreset( + ClassicPlotManagerComponent component, + String pattern, + double cost, + String permission, + String displayName, + List description, + ItemType icon +) implements ConfigurationSerializable { @SuppressWarnings("unchecked") public static ComponentPreset deserialize(final @NonNull Map map) { @@ -74,34 +61,6 @@ public class ComponentPreset implements ConfigurationSerializable { ); } - public ClassicPlotManagerComponent getComponent() { - return this.component; - } - - public String getPattern() { - return this.pattern; - } - - public double getCost() { - return this.cost; - } - - public String getPermission() { - return this.permission; - } - - public String getDisplayName() { - return this.displayName; - } - - public List getDescription() { - return this.description; - } - - public ItemType getIcon() { - return this.icon; - } - @Override public Map serialize() { final Map map = new HashMap<>(); diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index a28a7e17f..fd8e5b5ab 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -165,8 +165,8 @@ public class ComponentPresetManager { final List allowedPresets = new ArrayList<>(this.presets.size()); for (final ComponentPreset componentPreset : this.presets) { - if (!componentPreset.getPermission().isEmpty() && !player.hasPermission( - componentPreset.getPermission() + if (!componentPreset.permission().isEmpty() && !player.hasPermission( + componentPreset.permission() )) { continue; } @@ -200,30 +200,30 @@ public class ComponentPresetManager { return false; } - final Pattern pattern = PatternUtil.parse(null, componentPreset.getPattern(), false); + final Pattern pattern = PatternUtil.parse(null, componentPreset.pattern(), false); if (pattern == null) { getPlayer().sendMessage(TranslatableCaption.of("preset.preset_invalid")); return false; } - if (componentPreset.getCost() > 0.0D) { + if (componentPreset.cost() > 0.0D) { if (!econHandler.isEnabled(plot.getArea())) { getPlayer().sendMessage( TranslatableCaption.of("preset.economy_disabled"), - TagResolver.resolver("preset", Tag.inserting(Component.text(componentPreset.getDisplayName()))) + TagResolver.resolver("preset", Tag.inserting(Component.text(componentPreset.displayName()))) ); return false; } - if (econHandler.getMoney(getPlayer()) < componentPreset.getCost()) { + if (econHandler.getMoney(getPlayer()) < componentPreset.cost()) { getPlayer().sendMessage(TranslatableCaption.of("preset.preset_cannot_afford")); return false; } else { - econHandler.withdrawMoney(getPlayer(), componentPreset.getCost()); + econHandler.withdrawMoney(getPlayer(), componentPreset.cost()); getPlayer().sendMessage( TranslatableCaption.of("economy.removed_balance"), TagResolver.resolver( "money", - Tag.inserting(Component.text(econHandler.format(componentPreset.getCost()))) + Tag.inserting(Component.text(econHandler.format(componentPreset.cost()))) ) ); } @@ -235,7 +235,7 @@ public class ComponentPresetManager { queue.setCompleteTask(plot::removeRunning); for (Plot current : plot.getConnectedPlots()) { current.getPlotModificationManager().setComponent( - componentPreset.getComponent().name(), + componentPreset.component().name(), pattern, player, queue @@ -252,32 +252,32 @@ public class ComponentPresetManager { for (int i = 0; i < allowedPresets.size(); i++) { final ComponentPreset preset = allowedPresets.get(i); final List lore = new ArrayList<>(); - if (preset.getCost() > 0) { + if (preset.cost() > 0) { if (!this.econHandler.isEnabled(plot.getArea())) { lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize( TranslatableCaption.of("preset.preset_lore_economy_disabled").getComponent(player)))); } else { lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize( TranslatableCaption.of("preset.preset_lore_cost").getComponent(player), - TagResolver.resolver("cost", Tag.inserting(Component.text(String.format("%.2f", preset.getCost())))) + TagResolver.resolver("cost", Tag.inserting(Component.text(String.format("%.2f", preset.cost())))) ))); } } lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize( TranslatableCaption.of("preset.preset_lore_component").getComponent(player), TagResolver.builder() - .tag("component", Tag.inserting(Component.text(preset.getComponent().name().toLowerCase()))) + .tag("component", Tag.inserting(Component.text(preset.component().name().toLowerCase()))) .tag("prefix", Tag.inserting(TranslatableCaption.of("core.prefix").toComponent(player))) .build() ))); lore.removeIf(String::isEmpty); - lore.addAll(preset.getDescription()); + lore.addAll(preset.description()); plotInventory.setItem( i, new PlotItemStack( - preset.getIcon().getId().replace("minecraft:", ""), + preset.icon().getId().replace("minecraft:", ""), 1, - preset.getDisplayName(), + preset.displayName(), lore.toArray(new String[0]) ) ); diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java index 8721fd892..83a32e39c 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -2400,13 +2400,13 @@ public class SQLManager implements AbstractDB { if (plot != null) { statement.setString(1, plot.getArea().toString()); statement.setInt(2, plot.getId().hashCode()); - statement.setString(3, comment.comment); - statement.setString(4, comment.inbox); - statement.setString(5, comment.senderName); + statement.setString(3, comment.comment()); + statement.setString(4, comment.inbox()); + statement.setString(5, comment.senderName()); } else { - statement.setString(1, comment.comment); - statement.setString(2, comment.inbox); - statement.setString(3, comment.senderName); + statement.setString(1, comment.comment()); + statement.setString(2, comment.inbox()); + statement.setString(3, comment.senderName()); } } @@ -2518,10 +2518,10 @@ public class SQLManager implements AbstractDB { public void set(PreparedStatement statement) throws SQLException { statement.setString(1, plot.getArea().toString()); statement.setInt(2, plot.getId().hashCode()); - statement.setString(3, comment.comment); - statement.setString(4, comment.inbox); - statement.setInt(5, (int) (comment.timestamp / 1000)); - statement.setString(6, comment.senderName); + statement.setString(3, comment.comment()); + statement.setString(4, comment.inbox()); + statement.setInt(5, (int) (comment.timestamp() / 1000)); + statement.setString(6, comment.senderName()); } @Override @@ -3414,15 +3414,10 @@ public class SQLManager implements AbstractDB { } } - private static class LegacySettings { - - public final int id; - public final PlotSettings settings; - - public LegacySettings(int id, PlotSettings settings) { - this.id = id; - this.settings = settings; - } + private record LegacySettings( + int id, + PlotSettings settings + ) { } diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 428376476..c0585dff6 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -341,14 +341,14 @@ public class PlotListener { } TimedFlag.Timed feed = plot.getFlag(FeedFlag.class); - if (feed.getInterval() != 0 && feed.getValue() != 0) { + if (feed.interval() != 0 && feed.value() != 0) { feedRunnable - .put(player.getUUID(), new Interval(feed.getInterval(), feed.getValue(), 20)); + .put(player.getUUID(), new Interval(feed.interval(), feed.value(), 20)); } TimedFlag.Timed heal = plot.getFlag(HealFlag.class); - if (heal.getInterval() != 0 && heal.getValue() != 0) { + if (heal.interval() != 0 && heal.value() != 0) { healRunnable - .put(player.getUUID(), new Interval(heal.getInterval(), heal.getValue(), 20)); + .put(player.getUUID(), new Interval(heal.interval(), heal.value(), 20)); } return true; } diff --git a/Core/src/main/java/com/plotsquared/core/location/ChunkWrapper.java b/Core/src/main/java/com/plotsquared/core/location/ChunkWrapper.java index 2d721168e..2d858bacb 100644 --- a/Core/src/main/java/com/plotsquared/core/location/ChunkWrapper.java +++ b/Core/src/main/java/com/plotsquared/core/location/ChunkWrapper.java @@ -21,17 +21,11 @@ package com.plotsquared.core.location; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.StringMan; -public class ChunkWrapper { - - public final int x; - public final int z; - public final String world; - - public ChunkWrapper(String world, int x, int z) { - this.world = world; - this.x = x; - this.z = z; - } +public record ChunkWrapper( + String world, + int x, + int z +) { @Override public int hashCode() { diff --git a/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java b/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java index 864e5a007..122483ab6 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java +++ b/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java @@ -215,66 +215,20 @@ public final class BlockBucket implements ConfigurationSerializable { return result; } - private static final class Range { - - private final int min; - private final int max; - private final boolean automatic; - - public Range(int min, int max, boolean automatic) { - this.min = min; - this.max = max; - this.automatic = automatic; - } + private record Range( + int min, + int max, + boolean automatic + ) { public int getWeight() { - return max - min; - } - - public boolean isInRange(final int num) { - return num <= max && num >= min; - } - - public int getMin() { - return this.min; - } - - public int getMax() { - return this.max; - } - - public boolean equals(final Object o) { - if (o == this) { - return true; + return max - min; } - if (!(o instanceof final Range other)) { - return false; - } - if (this.getMin() != other.getMin()) { - return false; - } - if (this.getMax() != other.getMax()) { - return false; - } - if (this.isAutomatic() != other.isAutomatic()) { - return false; - } - return true; - } - public int hashCode() { - final int PRIME = 59; - int result = 1; - result = result * PRIME + this.getMin(); - result = result * PRIME + this.getMax(); - result = result * PRIME + (this.isAutomatic() ? 79 : 97); - return result; - } + public boolean isInRange(final int num) { + return num <= max && num >= min; + } - public boolean isAutomatic() { - return this.automatic; } - } - } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java b/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java index 6e727a095..9c7150e4f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java @@ -113,13 +113,12 @@ public class PlotSettings { this.position = position; } - @SuppressWarnings({"UnstableApiUsage"}) public List getComments(String inbox) { if (this.comments == null) { return Collections.emptyList(); } - return this.comments.stream().filter(comment -> comment.inbox.equals(inbox)) + return this.comments.stream().filter(comment -> comment.inbox().equals(inbox)) .collect(ImmutableList.toImmutableList()); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java index a318164dc..0fad7f4ac 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java @@ -58,7 +58,7 @@ public class CommentManager { if (value != null) { int num = 0; for (PlotComment comment : value) { - if (comment.timestamp > getTimestamp(player, inbox.toString())) { + if (comment.timestamp() > getTimestamp(player, inbox.toString())) { num++; } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/PlotComment.java b/Core/src/main/java/com/plotsquared/core/plot/comment/PlotComment.java index 5e8eb07bd..5b1f125e2 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/PlotComment.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/PlotComment.java @@ -20,25 +20,13 @@ package com.plotsquared.core.plot.comment; import com.plotsquared.core.plot.PlotId; -public class PlotComment { - - public final String comment; - public final String inbox; - public final String senderName; - public final PlotId id; - public final String world; - public final long timestamp; - - public PlotComment( - String world, PlotId id, String comment, String senderName, String inbox, - long timestamp - ) { - this.world = world; - this.id = id; - this.comment = comment; - this.senderName = senderName; - this.inbox = inbox; - this.timestamp = timestamp; - } +public record PlotComment( + String world, + PlotId id, + String comment, + String senderName, + String inbox, + long timestamp +) { } diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java index 0ee553117..ee87815a3 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java @@ -60,7 +60,7 @@ public class FeedFlag extends TimedFlag { @Override protected Integer mergeValue(Integer other) { - return this.getValue().getValue() + other; + return this.getValue().value() + other; } @Override diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java index 88f2291c4..bfa3d0017 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java @@ -60,7 +60,7 @@ public class HealFlag extends TimedFlag { @Override protected Integer mergeValue(Integer other) { - return this.getValue().getValue() + other; + return this.getValue().value() + other; } @Override diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/types/TimedFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/types/TimedFlag.java index 4ca3cba74..9731c74d9 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/types/TimedFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/types/TimedFlag.java @@ -76,29 +76,16 @@ public abstract class TimedFlag, F>> return getValue().toString(); } - public static final class Timed { - - private final int interval; - private final T value; - - public Timed(int interval, T value) { - this.interval = interval; - this.value = value; - } - - public int getInterval() { - return interval; - } - - public T getValue() { - return value; - } + public record Timed( + int interval, + T value + ) { @Override - public String toString() { - return String.format("%d %s", interval, value); + public String toString() { + return String.format("%d %s", interval, value); + } + } - } - } diff --git a/Core/src/main/java/com/plotsquared/core/services/plots/AutoQuery.java b/Core/src/main/java/com/plotsquared/core/services/plots/AutoQuery.java new file mode 100644 index 000000000..7cced5dbc --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/services/plots/AutoQuery.java @@ -0,0 +1,94 @@ +/* + * PlotSquared, a land and world management plugin for Minecraft. + * Copyright (C) IntellectualSites + * Copyright (C) IntellectualSites team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.services.plots; + +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.PlotId; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Crate a new auto query + * + * @param player Player to claim for + * @param startId Plot ID to start searching from + * @param sizeX Number of plots along the X axis + * @param sizeZ Number of plots along the Z axis + * @param plotArea Plot area to search in + */ +public record AutoQuery( + @NonNull PlotPlayer player, + @Nullable PlotId startId, + int sizeX, + int sizeZ, + @NonNull PlotArea plotArea +) { + + /** + * Get the player that the plots are meant for + * + * @return Player + */ + @Override + public @NonNull PlotPlayer player() { + return this.player; + } + + /** + * Get the plot ID to start searching from + * + * @return Start ID + */ + @Override + public @Nullable PlotId startId() { + return this.startId; + } + + /** + * Get the number of plots along the X axis + * + * @return Number of plots along the X axis + */ + @Override + public int sizeX() { + return this.sizeX; + } + + /** + * Get the number of plots along the Z axis + * + * @return Number of plots along the Z axis + */ + @Override + public int sizeZ() { + return this.sizeZ; + } + + /** + * Get the plot area to search in + * + * @return Plot area + */ + @Override + public @NonNull PlotArea plotArea() { + return this.plotArea; + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java b/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java index b3839ef87..b2fdb1441 100644 --- a/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java +++ b/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java @@ -21,9 +21,7 @@ package com.plotsquared.core.services.plots; import cloud.commandframework.services.types.Service; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; -import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; import org.checkerframework.checker.nullness.qual.NonNull; @@ -34,88 +32,12 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; -public interface AutoService extends Service> { +public interface AutoService extends Service> { Cache plotCandidateCache = CacheBuilder.newBuilder() .expireAfterWrite(20, TimeUnit.SECONDS).build(); Object plotLock = new Object(); - final class AutoQuery { - - private final PlotPlayer player; - private final PlotId startId; - private final int sizeX; - private final int sizeZ; - private final PlotArea plotArea; - - /** - * Crate a new auto query - * - * @param player Player to claim for - * @param startId Plot ID to start searching from - * @param sizeX Number of plots along the X axis - * @param sizeZ Number of plots along the Z axis - * @param plotArea Plot area to search in - */ - public AutoQuery( - final @NonNull PlotPlayer player, final @Nullable PlotId startId, - final int sizeX, final int sizeZ, final @NonNull PlotArea plotArea - ) { - this.player = player; - this.startId = startId; - this.sizeX = sizeX; - this.sizeZ = sizeZ; - this.plotArea = plotArea; - } - - /** - * Get the player that the plots are meant for - * - * @return Player - */ - public @NonNull PlotPlayer getPlayer() { - return this.player; - } - - /** - * Get the plot ID to start searching from - * - * @return Start ID - */ - public @Nullable PlotId getStartId() { - return this.startId; - } - - /** - * Get the number of plots along the X axis - * - * @return Number of plots along the X axis - */ - public int getSizeX() { - return this.sizeX; - } - - /** - * Get the number of plots along the Z axis - * - * @return Number of plots along the Z axis - */ - public int getSizeZ() { - return this.sizeZ; - } - - /** - * Get the plot area to search in - * - * @return Plot area - */ - public @NonNull PlotArea getPlotArea() { - return this.plotArea; - } - - } - - final class DefaultAutoService implements AutoService { @Override @@ -125,17 +47,16 @@ public interface AutoService extends Service> } - final class SinglePlotService implements AutoService, Predicate { @Nullable @Override public List handle(@NonNull AutoQuery autoQuery) { Plot plot; - PlotId nextId = autoQuery.getStartId(); + PlotId nextId = autoQuery.startId(); do { synchronized (plotLock) { - plot = autoQuery.getPlotArea().getNextFreePlot(autoQuery.getPlayer(), nextId); + plot = autoQuery.plotArea().getNextFreePlot(autoQuery.player(), nextId); if (plot != null && plotCandidateCache.getIfPresent(plot.getId()) == null) { plotCandidateCache.put(plot.getId(), plot); return Collections.singletonList(plot); @@ -151,12 +72,11 @@ public interface AutoService extends Service> @Override public boolean test(final @NonNull AutoQuery autoQuery) { - return autoQuery.sizeX == 1 && autoQuery.sizeZ == 1; + return autoQuery.sizeX() == 1 && autoQuery.sizeZ() == 1; } } - final class MultiPlotService implements AutoService, Predicate { @Override @@ -166,14 +86,14 @@ public interface AutoService extends Service> while (true) { synchronized (plotLock) { final PlotId start = - autoQuery.getPlotArea().getMeta("lastPlot", PlotId.of(0, 0)).getNextId(); + autoQuery.plotArea().getMeta("lastPlot", PlotId.of(0, 0)).getNextId(); final PlotId end = PlotId.of( - start.getX() + autoQuery.getSizeX() - 1, - start.getY() + autoQuery.getSizeZ() - 1 + start.getX() + autoQuery.sizeX() - 1, + start.getY() + autoQuery.sizeZ() - 1 ); final List plots = - autoQuery.getPlotArea().canClaim(autoQuery.getPlayer(), start, end); - autoQuery.getPlotArea().setMeta("lastPlot", start); // set entry point for next try + autoQuery.plotArea().canClaim(autoQuery.player(), start, end); + autoQuery.plotArea().setMeta("lastPlot", start); // set entry point for next try if (plots != null && !plots.isEmpty()) { for (final Plot plot : plots) { if (plotCandidateCache.getIfPresent(plot.getId()) != null) { @@ -189,7 +109,7 @@ public interface AutoService extends Service> @Override public boolean test(final @NonNull AutoQuery autoQuery) { - return autoQuery.getPlotArea().getType() != PlotAreaType.PARTIAL; + return autoQuery.plotArea().getType() != PlotAreaType.PARTIAL; } } diff --git a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java index 0a1a7d38f..71b6deffc 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java +++ b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java @@ -48,10 +48,10 @@ public class SettingsNodeStep implements SetupStep { ) { this.configurationNode = configurationNode; this.id = id; - if (wrapper.getSettingsNodes().length > id + 1) { - this.next = new SettingsNodeStep(wrapper.getSettingsNodes()[id + 1], id + 1, wrapper); + if (wrapper.settingsNodes().length > id + 1) { + this.next = new SettingsNodeStep(wrapper.settingsNodes()[id + 1], id + 1, wrapper); } else { - this.next = wrapper.getAfterwards(); + this.next = wrapper.afterwards(); } } diff --git a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java index 9ccacac2f..a9c8f7a76 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java +++ b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java @@ -23,15 +23,10 @@ import com.plotsquared.core.configuration.ConfigurationNode; /** * This class wraps an array of {@link ConfigurationNode}s. */ -public class SettingsNodesWrapper { - - private final ConfigurationNode[] settingsNodes; - private final SetupStep afterwards; - - public SettingsNodesWrapper(final ConfigurationNode[] settingsNodes, final SetupStep afterwards) { - this.settingsNodes = settingsNodes; - this.afterwards = afterwards; - } +public record SettingsNodesWrapper( + ConfigurationNode[] settingsNodes, + SetupStep afterwards +) { /** * Returns the first step of this wrapper or the step or the @@ -43,12 +38,4 @@ public class SettingsNodesWrapper { return this.settingsNodes.length == 0 ? this.afterwards : new SettingsNodeStep(this.settingsNodes[0], 0, this); } - public ConfigurationNode[] getSettingsNodes() { - return this.settingsNodes; - } - - public SetupStep getAfterwards() { - return this.afterwards; - } - } diff --git a/Core/src/main/java/com/plotsquared/core/util/FileBytes.java b/Core/src/main/java/com/plotsquared/core/util/FileBytes.java index d314d892c..95d1aa7da 100644 --- a/Core/src/main/java/com/plotsquared/core/util/FileBytes.java +++ b/Core/src/main/java/com/plotsquared/core/util/FileBytes.java @@ -18,14 +18,9 @@ */ package com.plotsquared.core.util; -public class FileBytes { - - public final String path; - public final byte[] data; - - public FileBytes(String path, byte[] data) { - this.path = path; - this.data = data; - } +public record FileBytes( + String path, + byte[] data +) { } diff --git a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java index ff53f299b..1f4e98a3d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java @@ -98,7 +98,7 @@ public abstract class PlayerManager

, T> { consumer.accept(null, throwable); } else { for (final UUIDMapping uuid : uuids) { - result.add(uuid.getUuid()); + result.add(uuid.uuid()); } consumer.accept(result, null); } @@ -136,7 +136,7 @@ public abstract class PlayerManager

, T> { try { for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline() .getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS)) { - users.add(Component.text(mapping.getUsername())); + users.add(Component.text(mapping.username())); } } catch (final Exception e) { e.printStackTrace(); @@ -200,7 +200,7 @@ public abstract class PlayerManager

, T> { final UUIDMapping uuidMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner); if (uuidMapping != null) { - name = uuidMapping.getUsername(); + name = uuidMapping.username(); } else { name = null; } diff --git a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java index 386990082..b3324f549 100644 --- a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java +++ b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java @@ -238,8 +238,8 @@ public final class TabCompletions { PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately(); players = new ArrayList<>(mappings.size()); for (final UUIDMapping mapping : mappings) { - if (uuidFilter.test(mapping.getUuid())) { - players.add(mapping.getUsername()); + if (uuidFilter.test(mapping.uuid())) { + players.add(mapping.username()); } } cachedCompletionValues.put(cacheIdentifier, players); diff --git a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java index 3fa3930d2..a6b39845c 100644 --- a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java +++ b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java @@ -298,19 +298,11 @@ public final class PlaceholderRegistry { } /** - * Event called when a new {@link Placeholder} has been added - */ - public static class PlaceholderAddedEvent { - - private final Placeholder placeholder; - - public PlaceholderAddedEvent(Placeholder placeholder) { - this.placeholder = placeholder; - } - - public Placeholder getPlaceholder() { - return this.placeholder; - } + * Event called when a new {@link Placeholder} has been added + */ + public record PlaceholderAddedEvent( + Placeholder placeholder + ) { } diff --git a/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java b/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java index 9da230b1e..f5f94f1c3 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java @@ -67,8 +67,8 @@ public class CacheUUIDService implements UUIDService, Consumer @Override public void accept(final @NonNull List<@NonNull UUIDMapping> uuidMappings) { for (final UUIDMapping mapping : uuidMappings) { - this.uuidCache.put(mapping.getUuid(), mapping); - this.usernameCache.put(mapping.getUsername(), mapping); + this.uuidCache.put(mapping.uuid(), mapping); + this.usernameCache.put(mapping.username(), mapping); } } diff --git a/Core/src/main/java/com/plotsquared/core/uuid/UUIDMapping.java b/Core/src/main/java/com/plotsquared/core/uuid/UUIDMapping.java index af0b1db0d..8a54c0172 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDMapping.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDMapping.java @@ -20,45 +20,14 @@ package com.plotsquared.core.uuid; import org.checkerframework.checker.nullness.qual.NonNull; -import java.util.Objects; import java.util.UUID; /** * A pair consisting of a UUID and a username */ -public class UUIDMapping { - - private final UUID uuid; - private final String username; - - public UUIDMapping(final @NonNull UUID uuid, final @NonNull String username) { - this.uuid = uuid; - this.username = username; - } - - public @NonNull String getUsername() { - return this.username; - } - - public @NonNull UUID getUuid() { - return this.uuid; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final UUIDMapping that = (UUIDMapping) o; - return uuid.equals(that.uuid) && username.equals(that.username); - } - - @Override - public int hashCode() { - return Objects.hash(uuid, username); - } +public record UUIDMapping( + @NonNull UUID uuid, + @NonNull String username +) { } diff --git a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java index 036eeda05..b9d2c01a6 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java @@ -157,7 +157,7 @@ public class UUIDPipeline { TimeUnit.MILLISECONDS ); if (mappings.size() == 1) { - return mappings.get(0).getUuid(); + return mappings.get(0).uuid(); } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -182,7 +182,7 @@ public class UUIDPipeline { try { final List mappings = this.getNames(Collections.singletonList(uuid)).get(timeout, TimeUnit.MILLISECONDS); if (mappings.size() == 1) { - return mappings.get(0).getUsername(); + return mappings.get(0).username(); } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -209,7 +209,7 @@ public class UUIDPipeline { uuid.accept(null, throwable); } else { if (!uuids.isEmpty()) { - uuid.accept(uuids.get(0).getUuid(), null); + uuid.accept(uuids.get(0).uuid(), null); } else { uuid.accept(null, null); } @@ -231,7 +231,7 @@ public class UUIDPipeline { username.accept(null, throwable); } else { if (!uuids.isEmpty()) { - username.accept(uuids.get(0).getUsername(), null); + username.accept(uuids.get(0).username(), null); } else { username.accept(null, null); } @@ -296,7 +296,7 @@ public class UUIDPipeline { if (service.canBeSynchronous()) { final List completedRequests = service.getNames(remainingRequests); for (final UUIDMapping mapping : completedRequests) { - remainingRequests.remove(mapping.getUuid()); + remainingRequests.remove(mapping.uuid()); } mappings.addAll(completedRequests); } else { @@ -311,7 +311,7 @@ public class UUIDPipeline { for (final UUIDService service : serviceList) { final List completedRequests = service.getNames(remainingRequests); for (final UUIDMapping mapping : completedRequests) { - remainingRequests.remove(mapping.getUuid()); + remainingRequests.remove(mapping.uuid()); } mappings.addAll(completedRequests); if (remainingRequests.isEmpty()) { @@ -365,7 +365,7 @@ public class UUIDPipeline { if (service.canBeSynchronous()) { final List completedRequests = service.getUUIDs(remainingRequests); for (final UUIDMapping mapping : completedRequests) { - remainingRequests.remove(mapping.getUsername()); + remainingRequests.remove(mapping.username()); } mappings.addAll(completedRequests); } else { @@ -380,7 +380,7 @@ public class UUIDPipeline { for (final UUIDService service : serviceList) { final List completedRequests = service.getUUIDs(remainingRequests); for (final UUIDMapping mapping : completedRequests) { - remainingRequests.remove(mapping.getUsername()); + remainingRequests.remove(mapping.username()); } mappings.addAll(completedRequests); if (remainingRequests.isEmpty()) {