Record-inize methods

This commit is contained in:
Alexander Brandes 2023-03-04 12:55:50 +01:00
parent 276e619caa
commit 0484915233
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C
33 changed files with 247 additions and 413 deletions

View File

@ -52,7 +52,7 @@ public class MVdWPlaceholders {
@Subscribe @Subscribe
public void onNewPlaceholder(final PlaceholderRegistry.@NonNull PlaceholderAddedEvent event) { public void onNewPlaceholder(final PlaceholderRegistry.@NonNull PlaceholderAddedEvent event) {
this.addPlaceholder(event.getPlaceholder()); this.addPlaceholder(event.placeholder());
} }
private void addPlaceholder(final @NonNull Placeholder placeholder) { private void addPlaceholder(final @NonNull Placeholder placeholder) {

View File

@ -110,9 +110,9 @@ public class GenChunk extends ZeroedDelegateScopedQueueCoordinator {
*/ */
public void setChunk(@NonNull ChunkWrapper wrap) { public void setChunk(@NonNull ChunkWrapper wrap) {
chunk = null; chunk = null;
world = wrap.world; world = wrap.world();
chunkX = wrap.x; chunkX = wrap.x();
chunkZ = wrap.z; chunkZ = wrap.z();
} }
@Override @Override

View File

@ -124,7 +124,7 @@ public class BukkitSetupUtils extends SetupUtils {
public String setupWorld(PlotAreaBuilder builder) { public String setupWorld(PlotAreaBuilder builder) {
this.updateGenerators(false); this.updateGenerators(false);
ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ? ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ?
new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes(); new ConfigurationNode[0] : builder.settingsNodesWrapper().settingsNodes();
String world = builder.worldName(); String world = builder.worldName();
PlotAreaType type = builder.plotAreaType(); PlotAreaType type = builder.plotAreaType();
String worldPath = "worlds." + builder.worldName(); String worldPath = "worlds." + builder.worldName();

View File

@ -111,8 +111,8 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
try (final PreparedStatement statement = getConnection() try (final PreparedStatement statement = getConnection()
.prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) { .prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) {
for (final UUIDMapping mapping : uuidWrappers) { for (final UUIDMapping mapping : uuidWrappers) {
statement.setString(1, mapping.getUuid().toString()); statement.setString(1, mapping.uuid().toString());
statement.setString(2, mapping.getUsername()); statement.setString(2, mapping.username());
statement.executeUpdate(); statement.executeUpdate();
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -136,33 +136,27 @@ public class SimpleBackupManager implements BackupManager {
return this.backupLimit; return this.backupLimit;
} }
private static final class PlotCacheKey { private record PlotCacheKey(Plot plot) {
private final Plot plot;
private PlotCacheKey(Plot plot) {
this.plot = plot;
}
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (this == o) { if (this == o) {
return true; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final PlotCacheKey that = (PlotCacheKey) o;
return Objects.equals(plot.getArea(), that.plot.getArea())
&& Objects.equals(plot.getId(), that.plot.getId())
&& Objects.equals(plot.getOwnerAbs(), that.plot.getOwnerAbs());
} }
if (o == null || getClass() != o.getClass()) {
return false; @Override
public int hashCode() {
return Objects.hash(plot.getArea(), plot.getId(), plot.getOwnerAbs());
} }
final PlotCacheKey that = (PlotCacheKey) o;
return Objects.equals(plot.getArea(), that.plot.getArea())
&& Objects.equals(plot.getId(), that.plot.getId())
&& Objects.equals(plot.getOwnerAbs(), that.plot.getOwnerAbs());
}
@Override
public int hashCode() {
return Objects.hash(plot.getArea(), plot.getId(), plot.getOwnerAbs());
} }
}
} }

View File

@ -35,6 +35,7 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.services.plots.AutoQuery;
import com.plotsquared.core.services.plots.AutoService; import com.plotsquared.core.services.plots.AutoService;
import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.EventDispatcher;
@ -326,7 +327,7 @@ public class Auto extends SubCommand {
} }
List<Plot> plots = this.servicePipeline List<Plot> plots = this.servicePipeline
.pump(new AutoService.AutoQuery(player, null, sizeX, sizeZ, plotarea)) .pump(new AutoQuery(player, null, sizeX, sizeZ, plotarea))
.through(AutoService.class) .through(AutoService.class)
.getResult(); .getResult();

View File

@ -85,24 +85,24 @@ public class Inbox extends SubCommand {
for (int x = page * 12; x < max; x++) { for (int x = page * 12; x < max; x++) {
PlotComment comment = comments[x]; PlotComment comment = comments[x];
Component commentColored; Component commentColored;
if (player.getName().equals(comment.senderName)) { if (player.getName().equals(comment.senderName())) {
commentColored = MINI_MESSAGE commentColored = MINI_MESSAGE
.deserialize( .deserialize(
TranslatableCaption.of("list.comment_list_by_lister").getComponent(player), 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 { } else {
commentColored = MINI_MESSAGE commentColored = MINI_MESSAGE
.deserialize( .deserialize(
TranslatableCaption.of("list.comment_list_by_other").getComponent(player), 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() TagResolver resolver = TagResolver.builder()
.tag("number", Tag.inserting(Component.text(x))) .tag("number", Tag.inserting(Component.text(x)))
.tag("world", Tag.inserting(Component.text(comment.world))) .tag("world", Tag.inserting(Component.text(comment.world())))
.tag("plot_id", Tag.inserting(Component.text(comment.id.getX() + ";" + comment.id.getY()))) .tag("plot_id", Tag.inserting(Component.text(comment.id().getX() + ";" + comment.id().getY())))
.tag("commenter", Tag.inserting(Component.text(comment.senderName))) .tag("commenter", Tag.inserting(Component.text(comment.senderName())))
.tag("comment", Tag.inserting(commentColored)) .tag("comment", Tag.inserting(commentColored))
.build(); .build();
builder.append(MINI_MESSAGE builder.append(MINI_MESSAGE
@ -137,7 +137,7 @@ public class Inbox extends SubCommand {
int unread = 0; int unread = 0;
for (PlotComment comment : value) { for (PlotComment comment : value) {
total++; total++;
if (comment.timestamp > CommentManager if (comment.timestamp() > CommentManager
.getTimestamp(player, inbox.toString())) { .getTimestamp(player, inbox.toString())) {
unread++; unread++;
} }
@ -242,7 +242,7 @@ public class Inbox extends SubCommand {
if (success) { if (success) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("comment.comment_removed_success"), 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 { } else {
player.sendMessage( player.sendMessage(

View File

@ -474,20 +474,20 @@ public class ListCmd extends SubCommand {
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners()) final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners())
.get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS); .get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
for (final UUIDMapping uuidMapping : names) { 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() TagResolver resolver = TagResolver.builder()
.tag("prefix", Tag.inserting(Component.text(prefix))) .tag("prefix", Tag.inserting(Component.text(prefix)))
.tag("player", Tag.inserting(Component.text(uuidMapping.getUsername()))) .tag("player", Tag.inserting(Component.text(uuidMapping.username())))
.build(); .build();
if (pp != null) { if (pp != null) {
builder.append(MINI_MESSAGE.deserialize(online, resolver)); builder.append(MINI_MESSAGE.deserialize(online, resolver));
} else if (uuidMapping.getUsername().equalsIgnoreCase("unknown")) { } else if (uuidMapping.username().equalsIgnoreCase("unknown")) {
TagResolver unknownResolver = TagResolver.resolver( TagResolver unknownResolver = TagResolver.resolver(
"info.unknown", "info.unknown",
Tag.inserting(TranslatableCaption.of("info.unknown").toComponent(player)) Tag.inserting(TranslatableCaption.of("info.unknown").toComponent(player))
); );
builder.append(MINI_MESSAGE.deserialize(unknown, unknownResolver)); 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( TagResolver everyoneResolver = TagResolver.resolver(
"info.everyone", "info.everyone",
Tag.inserting(TranslatableCaption.of("info.everyone").toComponent(player)) Tag.inserting(TranslatableCaption.of("info.everyone").toComponent(player))

View File

@ -127,7 +127,7 @@ public class Purge extends SubCommand {
); );
return false; return false;
} }
owner = ownerMapping.getUuid(); owner = ownerMapping.uuid();
break; break;
case "shared": case "shared":
case "s": case "s":
@ -139,7 +139,7 @@ public class Purge extends SubCommand {
); );
return false; return false;
} }
added = addedMapping.getUuid(); added = addedMapping.uuid();
break; break;
case "clear": case "clear":
case "c": case "c":

View File

@ -156,9 +156,9 @@ public class Template extends SubCommand {
ZipOutputStream zos = new ZipOutputStream(fos)) { ZipOutputStream zos = new ZipOutputStream(fos)) {
for (FileBytes file : files) { for (FileBytes file : files) {
ZipEntry ze = new ZipEntry(file.path); ZipEntry ze = new ZipEntry(file.path());
zos.putNextEntry(ze); zos.putNextEntry(ze);
zos.write(file.data); zos.write(file.data());
} }
zos.closeEntry(); zos.closeEntry();
} }

View File

@ -35,28 +35,8 @@ import java.util.Map;
* the component GUI * the component GUI
*/ */
@SerializableAs("preset") @SerializableAs("preset")
public class ComponentPreset implements ConfigurationSerializable { public record ComponentPreset(ClassicPlotManagerComponent component, String pattern, double cost, String permission,
String displayName, List<String> description, ItemType icon) 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<String> description;
private final ItemType icon;
public ComponentPreset(
ClassicPlotManagerComponent component, String pattern, double cost,
String permission, String displayName, List<String> 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;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static ComponentPreset deserialize(final @NonNull Map<String, Object> map) { public static ComponentPreset deserialize(final @NonNull Map<String, Object> map) {
@ -74,34 +54,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<String> getDescription() {
return this.description;
}
public ItemType getIcon() {
return this.icon;
}
@Override @Override
public Map<String, Object> serialize() { public Map<String, Object> serialize() {
final Map<String, Object> map = new HashMap<>(); final Map<String, Object> map = new HashMap<>();

View File

@ -165,8 +165,8 @@ public class ComponentPresetManager {
final List<ComponentPreset> allowedPresets = new ArrayList<>(this.presets.size()); final List<ComponentPreset> allowedPresets = new ArrayList<>(this.presets.size());
for (final ComponentPreset componentPreset : this.presets) { for (final ComponentPreset componentPreset : this.presets) {
if (!componentPreset.getPermission().isEmpty() && !player.hasPermission( if (!componentPreset.permission().isEmpty() && !player.hasPermission(
componentPreset.getPermission() componentPreset.permission()
)) { )) {
continue; continue;
} }
@ -200,30 +200,30 @@ public class ComponentPresetManager {
return false; return false;
} }
final Pattern pattern = PatternUtil.parse(null, componentPreset.getPattern(), false); final Pattern pattern = PatternUtil.parse(null, componentPreset.pattern(), false);
if (pattern == null) { if (pattern == null) {
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_invalid")); getPlayer().sendMessage(TranslatableCaption.of("preset.preset_invalid"));
return false; return false;
} }
if (componentPreset.getCost() > 0.0D) { if (componentPreset.cost() > 0.0D) {
if (!econHandler.isEnabled(plot.getArea())) { if (!econHandler.isEnabled(plot.getArea())) {
getPlayer().sendMessage( getPlayer().sendMessage(
TranslatableCaption.of("preset.economy_disabled"), 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; return false;
} }
if (econHandler.getMoney(getPlayer()) < componentPreset.getCost()) { if (econHandler.getMoney(getPlayer()) < componentPreset.cost()) {
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_cannot_afford")); getPlayer().sendMessage(TranslatableCaption.of("preset.preset_cannot_afford"));
return false; return false;
} else { } else {
econHandler.withdrawMoney(getPlayer(), componentPreset.getCost()); econHandler.withdrawMoney(getPlayer(), componentPreset.cost());
getPlayer().sendMessage( getPlayer().sendMessage(
TranslatableCaption.of("economy.removed_balance"), TranslatableCaption.of("economy.removed_balance"),
TagResolver.resolver( TagResolver.resolver(
"money", "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); queue.setCompleteTask(plot::removeRunning);
for (Plot current : plot.getConnectedPlots()) { for (Plot current : plot.getConnectedPlots()) {
current.getPlotModificationManager().setComponent( current.getPlotModificationManager().setComponent(
componentPreset.getComponent().name(), componentPreset.component().name(),
pattern, pattern,
player, player,
queue queue
@ -252,32 +252,32 @@ public class ComponentPresetManager {
for (int i = 0; i < allowedPresets.size(); i++) { for (int i = 0; i < allowedPresets.size(); i++) {
final ComponentPreset preset = allowedPresets.get(i); final ComponentPreset preset = allowedPresets.get(i);
final List<String> lore = new ArrayList<>(); final List<String> lore = new ArrayList<>();
if (preset.getCost() > 0) { if (preset.cost() > 0) {
if (!this.econHandler.isEnabled(plot.getArea())) { if (!this.econHandler.isEnabled(plot.getArea())) {
lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize( lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize(
TranslatableCaption.of("preset.preset_lore_economy_disabled").getComponent(player)))); TranslatableCaption.of("preset.preset_lore_economy_disabled").getComponent(player))));
} else { } else {
lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize( lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize(
TranslatableCaption.of("preset.preset_lore_cost").getComponent(player), 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( lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.deserialize(
TranslatableCaption.of("preset.preset_lore_component").getComponent(player), TranslatableCaption.of("preset.preset_lore_component").getComponent(player),
TagResolver.builder() 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))) .tag("prefix", Tag.inserting(TranslatableCaption.of("core.prefix").toComponent(player)))
.build() .build()
))); )));
lore.removeIf(String::isEmpty); lore.removeIf(String::isEmpty);
lore.addAll(preset.getDescription()); lore.addAll(preset.description());
plotInventory.setItem( plotInventory.setItem(
i, i,
new PlotItemStack( new PlotItemStack(
preset.getIcon().getId().replace("minecraft:", ""), preset.icon().getId().replace("minecraft:", ""),
1, 1,
preset.getDisplayName(), preset.displayName(),
lore.toArray(new String[0]) lore.toArray(new String[0])
) )
); );

View File

@ -2400,13 +2400,13 @@ public class SQLManager implements AbstractDB {
if (plot != null) { if (plot != null) {
statement.setString(1, plot.getArea().toString()); statement.setString(1, plot.getArea().toString());
statement.setInt(2, plot.getId().hashCode()); statement.setInt(2, plot.getId().hashCode());
statement.setString(3, comment.comment); statement.setString(3, comment.comment());
statement.setString(4, comment.inbox); statement.setString(4, comment.inbox());
statement.setString(5, comment.senderName); statement.setString(5, comment.senderName());
} else { } else {
statement.setString(1, comment.comment); statement.setString(1, comment.comment());
statement.setString(2, comment.inbox); statement.setString(2, comment.inbox());
statement.setString(3, comment.senderName); statement.setString(3, comment.senderName());
} }
} }
@ -2518,10 +2518,10 @@ public class SQLManager implements AbstractDB {
public void set(PreparedStatement statement) throws SQLException { public void set(PreparedStatement statement) throws SQLException {
statement.setString(1, plot.getArea().toString()); statement.setString(1, plot.getArea().toString());
statement.setInt(2, plot.getId().hashCode()); statement.setInt(2, plot.getId().hashCode());
statement.setString(3, comment.comment); statement.setString(3, comment.comment());
statement.setString(4, comment.inbox); statement.setString(4, comment.inbox());
statement.setInt(5, (int) (comment.timestamp / 1000)); statement.setInt(5, (int) (comment.timestamp() / 1000));
statement.setString(6, comment.senderName); statement.setString(6, comment.senderName());
} }
@Override @Override
@ -3414,15 +3414,7 @@ public class SQLManager implements AbstractDB {
} }
} }
private static class LegacySettings { private record LegacySettings(int id, PlotSettings settings) {
public final int id;
public final PlotSettings settings;
public LegacySettings(int id, PlotSettings settings) {
this.id = id;
this.settings = settings;
}
} }

View File

@ -341,14 +341,14 @@ public class PlotListener {
} }
TimedFlag.Timed<Integer> feed = plot.getFlag(FeedFlag.class); TimedFlag.Timed<Integer> feed = plot.getFlag(FeedFlag.class);
if (feed.getInterval() != 0 && feed.getValue() != 0) { if (feed.interval() != 0 && feed.value() != 0) {
feedRunnable feedRunnable
.put(player.getUUID(), new Interval(feed.getInterval(), feed.getValue(), 20)); .put(player.getUUID(), new Interval(feed.interval(), feed.value(), 20));
} }
TimedFlag.Timed<Integer> heal = plot.getFlag(HealFlag.class); TimedFlag.Timed<Integer> heal = plot.getFlag(HealFlag.class);
if (heal.getInterval() != 0 && heal.getValue() != 0) { if (heal.interval() != 0 && heal.value() != 0) {
healRunnable healRunnable
.put(player.getUUID(), new Interval(heal.getInterval(), heal.getValue(), 20)); .put(player.getUUID(), new Interval(heal.interval(), heal.value(), 20));
} }
return true; return true;
} }

View File

@ -21,17 +21,7 @@ package com.plotsquared.core.location;
import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.StringMan;
public class ChunkWrapper { public record ChunkWrapper(String world, int x, int z) {
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;
}
@Override @Override
public int hashCode() { public int hashCode() {

View File

@ -215,66 +215,44 @@ public final class BlockBucket implements ConfigurationSerializable {
return result; return result;
} }
private static final class Range { private record Range(int min, int max, boolean automatic) {
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;
}
public int getWeight() { public int getWeight() {
return max - min; return max - min;
} }
public boolean isInRange(final int num) { public boolean isInRange(final int num) {
return num <= max && num >= min; return num <= max && num >= min;
} }
public int getMin() { public boolean equals(final Object o) {
return this.min; if (o == this) {
} return true;
}
public int getMax() { if (!(o instanceof final Range other)) {
return this.max; return false;
} }
if (this.min() != other.min()) {
public boolean equals(final Object o) { return false;
if (o == this) { }
if (this.max() != other.max()) {
return false;
}
if (this.automatic() != other.automatic()) {
return false;
}
return true; return true;
} }
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() { public int hashCode() {
final int PRIME = 59; final int PRIME = 59;
int result = 1; int result = 1;
result = result * PRIME + this.getMin(); result = result * PRIME + this.min();
result = result * PRIME + this.getMax(); result = result * PRIME + this.max();
result = result * PRIME + (this.isAutomatic() ? 79 : 97); result = result * PRIME + (this.automatic() ? 79 : 97);
return result; return result;
} }
public boolean isAutomatic() {
return this.automatic;
} }
}
} }

View File

@ -113,13 +113,12 @@ public class PlotSettings {
this.position = position; this.position = position;
} }
@SuppressWarnings({"UnstableApiUsage"})
public List<PlotComment> getComments(String inbox) { public List<PlotComment> getComments(String inbox) {
if (this.comments == null) { if (this.comments == null) {
return Collections.emptyList(); 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()); .collect(ImmutableList.toImmutableList());
} }

View File

@ -58,7 +58,7 @@ public class CommentManager {
if (value != null) { if (value != null) {
int num = 0; int num = 0;
for (PlotComment comment : value) { for (PlotComment comment : value) {
if (comment.timestamp > getTimestamp(player, inbox.toString())) { if (comment.timestamp() > getTimestamp(player, inbox.toString())) {
num++; num++;
} }
} }

View File

@ -20,25 +20,6 @@ package com.plotsquared.core.plot.comment;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
public class PlotComment { public record PlotComment(String world, PlotId id, String comment, String senderName, String inbox, long timestamp) {
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;
}
} }

View File

@ -60,7 +60,7 @@ public class FeedFlag extends TimedFlag<Integer, FeedFlag> {
@Override @Override
protected Integer mergeValue(Integer other) { protected Integer mergeValue(Integer other) {
return this.getValue().getValue() + other; return this.getValue().value() + other;
} }
@Override @Override

View File

@ -60,7 +60,7 @@ public class HealFlag extends TimedFlag<Integer, HealFlag> {
@Override @Override
protected Integer mergeValue(Integer other) { protected Integer mergeValue(Integer other) {
return this.getValue().getValue() + other; return this.getValue().value() + other;
} }
@Override @Override

View File

@ -76,29 +76,13 @@ public abstract class TimedFlag<T, F extends PlotFlag<TimedFlag.Timed<T>, F>>
return getValue().toString(); return getValue().toString();
} }
public static final class Timed<T> { public record Timed<T>(int interval, T value) {
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;
}
@Override @Override
public String toString() { public String toString() {
return String.format("%d %s", interval, value); return String.format("%d %s", interval, value);
}
} }
}
} }

View File

@ -0,0 +1,99 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* 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 <https://www.gnu.org/licenses/>.
*/
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;
public record AutoQuery(PlotPlayer<?> player, PlotId startId, int sizeX, int sizeZ, 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
*/
@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;
}
}

View File

@ -21,9 +21,7 @@ package com.plotsquared.core.services.plots;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@ -34,88 +32,12 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Predicate; import java.util.function.Predicate;
public interface AutoService extends Service<AutoService.AutoQuery, List<Plot>> { public interface AutoService extends Service<AutoQuery, List<Plot>> {
Cache<PlotId, Plot> plotCandidateCache = CacheBuilder.newBuilder() Cache<PlotId, Plot> plotCandidateCache = CacheBuilder.newBuilder()
.expireAfterWrite(20, TimeUnit.SECONDS).build(); .expireAfterWrite(20, TimeUnit.SECONDS).build();
Object plotLock = new Object(); 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 { final class DefaultAutoService implements AutoService {
@Override @Override
@ -125,17 +47,16 @@ public interface AutoService extends Service<AutoService.AutoQuery, List<Plot>>
} }
final class SinglePlotService implements AutoService, Predicate<AutoQuery> { final class SinglePlotService implements AutoService, Predicate<AutoQuery> {
@Nullable @Nullable
@Override @Override
public List<Plot> handle(@NonNull AutoQuery autoQuery) { public List<Plot> handle(@NonNull AutoQuery autoQuery) {
Plot plot; Plot plot;
PlotId nextId = autoQuery.getStartId(); PlotId nextId = autoQuery.startId();
do { do {
synchronized (plotLock) { synchronized (plotLock) {
plot = autoQuery.getPlotArea().getNextFreePlot(autoQuery.getPlayer(), nextId); plot = autoQuery.plotArea().getNextFreePlot(autoQuery.player(), nextId);
if (plot != null && plotCandidateCache.getIfPresent(plot.getId()) == null) { if (plot != null && plotCandidateCache.getIfPresent(plot.getId()) == null) {
plotCandidateCache.put(plot.getId(), plot); plotCandidateCache.put(plot.getId(), plot);
return Collections.singletonList(plot); return Collections.singletonList(plot);
@ -151,12 +72,11 @@ public interface AutoService extends Service<AutoService.AutoQuery, List<Plot>>
@Override @Override
public boolean test(final @NonNull AutoQuery autoQuery) { 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<AutoQuery> { final class MultiPlotService implements AutoService, Predicate<AutoQuery> {
@Override @Override
@ -166,14 +86,14 @@ public interface AutoService extends Service<AutoService.AutoQuery, List<Plot>>
while (true) { while (true) {
synchronized (plotLock) { synchronized (plotLock) {
final PlotId start = 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( final PlotId end = PlotId.of(
start.getX() + autoQuery.getSizeX() - 1, start.getX() + autoQuery.sizeX() - 1,
start.getY() + autoQuery.getSizeZ() - 1 start.getY() + autoQuery.sizeZ() - 1
); );
final List<Plot> plots = final List<Plot> plots =
autoQuery.getPlotArea().canClaim(autoQuery.getPlayer(), start, end); autoQuery.plotArea().canClaim(autoQuery.player(), start, end);
autoQuery.getPlotArea().setMeta("lastPlot", start); // set entry point for next try autoQuery.plotArea().setMeta("lastPlot", start); // set entry point for next try
if (plots != null && !plots.isEmpty()) { if (plots != null && !plots.isEmpty()) {
for (final Plot plot : plots) { for (final Plot plot : plots) {
if (plotCandidateCache.getIfPresent(plot.getId()) != null) { if (plotCandidateCache.getIfPresent(plot.getId()) != null) {
@ -189,7 +109,7 @@ public interface AutoService extends Service<AutoService.AutoQuery, List<Plot>>
@Override @Override
public boolean test(final @NonNull AutoQuery autoQuery) { public boolean test(final @NonNull AutoQuery autoQuery) {
return autoQuery.getPlotArea().getType() != PlotAreaType.PARTIAL; return autoQuery.plotArea().getType() != PlotAreaType.PARTIAL;
} }
} }

View File

@ -48,10 +48,10 @@ public class SettingsNodeStep implements SetupStep {
) { ) {
this.configurationNode = configurationNode; this.configurationNode = configurationNode;
this.id = id; this.id = id;
if (wrapper.getSettingsNodes().length > id + 1) { if (wrapper.settingsNodes().length > id + 1) {
this.next = new SettingsNodeStep(wrapper.getSettingsNodes()[id + 1], id + 1, wrapper); this.next = new SettingsNodeStep(wrapper.settingsNodes()[id + 1], id + 1, wrapper);
} else { } else {
this.next = wrapper.getAfterwards(); this.next = wrapper.afterwards();
} }
} }

View File

@ -23,15 +23,7 @@ import com.plotsquared.core.configuration.ConfigurationNode;
/** /**
* This class wraps an array of {@link ConfigurationNode}s. * This class wraps an array of {@link ConfigurationNode}s.
*/ */
public class SettingsNodesWrapper { public record SettingsNodesWrapper(ConfigurationNode[] settingsNodes, SetupStep afterwards) {
private final ConfigurationNode[] settingsNodes;
private final SetupStep afterwards;
public SettingsNodesWrapper(final ConfigurationNode[] settingsNodes, final SetupStep afterwards) {
this.settingsNodes = settingsNodes;
this.afterwards = afterwards;
}
/** /**
* Returns the first step of this wrapper or the step or the * Returns the first step of this wrapper or the step or the
@ -43,12 +35,4 @@ public class SettingsNodesWrapper {
return this.settingsNodes.length == 0 ? this.afterwards : new SettingsNodeStep(this.settingsNodes[0], 0, this); 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;
}
} }

View File

@ -18,14 +18,6 @@
*/ */
package com.plotsquared.core.util; package com.plotsquared.core.util;
public class FileBytes { public record FileBytes(String path, byte[] data) {
public final String path;
public final byte[] data;
public FileBytes(String path, byte[] data) {
this.path = path;
this.data = data;
}
} }

View File

@ -98,7 +98,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
consumer.accept(null, throwable); consumer.accept(null, throwable);
} else { } else {
for (final UUIDMapping uuid : uuids) { for (final UUIDMapping uuid : uuids) {
result.add(uuid.getUuid()); result.add(uuid.uuid());
} }
consumer.accept(result, null); consumer.accept(result, null);
} }
@ -136,7 +136,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
try { try {
for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline() for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline()
.getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS)) { .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) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -200,7 +200,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
final UUIDMapping uuidMapping = final UUIDMapping uuidMapping =
PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner); PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner);
if (uuidMapping != null) { if (uuidMapping != null) {
name = uuidMapping.getUsername(); name = uuidMapping.username();
} else { } else {
name = null; name = null;
} }

View File

@ -238,8 +238,8 @@ public final class TabCompletions {
PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately(); PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
players = new ArrayList<>(mappings.size()); players = new ArrayList<>(mappings.size());
for (final UUIDMapping mapping : mappings) { for (final UUIDMapping mapping : mappings) {
if (uuidFilter.test(mapping.getUuid())) { if (uuidFilter.test(mapping.uuid())) {
players.add(mapping.getUsername()); players.add(mapping.username());
} }
} }
cachedCompletionValues.put(cacheIdentifier, players); cachedCompletionValues.put(cacheIdentifier, players);

View File

@ -298,19 +298,9 @@ public final class PlaceholderRegistry {
} }
/** /**
* Event called when a new {@link Placeholder} has been added * Event called when a new {@link Placeholder} has been added
*/ */
public static class PlaceholderAddedEvent { public record PlaceholderAddedEvent(Placeholder placeholder) {
private final Placeholder placeholder;
public PlaceholderAddedEvent(Placeholder placeholder) {
this.placeholder = placeholder;
}
public Placeholder getPlaceholder() {
return this.placeholder;
}
} }

View File

@ -67,8 +67,8 @@ public class CacheUUIDService implements UUIDService, Consumer<List<UUIDMapping>
@Override @Override
public void accept(final @NonNull List<@NonNull UUIDMapping> uuidMappings) { public void accept(final @NonNull List<@NonNull UUIDMapping> uuidMappings) {
for (final UUIDMapping mapping : uuidMappings) { for (final UUIDMapping mapping : uuidMappings) {
this.uuidCache.put(mapping.getUuid(), mapping); this.uuidCache.put(mapping.uuid(), mapping);
this.usernameCache.put(mapping.getUsername(), mapping); this.usernameCache.put(mapping.username(), mapping);
} }
} }

View File

@ -20,29 +20,12 @@ package com.plotsquared.core.uuid;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
/** /**
* A pair consisting of a UUID and a username * A pair consisting of a UUID and a username
*/ */
public class UUIDMapping { public record UUIDMapping(@NonNull UUID uuid, @NonNull String username) {
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 @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
@ -56,9 +39,4 @@ public class UUIDMapping {
return uuid.equals(that.uuid) && username.equals(that.username); return uuid.equals(that.uuid) && username.equals(that.username);
} }
@Override
public int hashCode() {
return Objects.hash(uuid, username);
}
} }

View File

@ -157,7 +157,7 @@ public class UUIDPipeline {
TimeUnit.MILLISECONDS TimeUnit.MILLISECONDS
); );
if (mappings.size() == 1) { if (mappings.size() == 1) {
return mappings.get(0).getUuid(); return mappings.get(0).uuid();
} }
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
@ -182,7 +182,7 @@ public class UUIDPipeline {
try { try {
final List<UUIDMapping> mappings = this.getNames(Collections.singletonList(uuid)).get(timeout, TimeUnit.MILLISECONDS); final List<UUIDMapping> mappings = this.getNames(Collections.singletonList(uuid)).get(timeout, TimeUnit.MILLISECONDS);
if (mappings.size() == 1) { if (mappings.size() == 1) {
return mappings.get(0).getUsername(); return mappings.get(0).username();
} }
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
@ -209,7 +209,7 @@ public class UUIDPipeline {
uuid.accept(null, throwable); uuid.accept(null, throwable);
} else { } else {
if (!uuids.isEmpty()) { if (!uuids.isEmpty()) {
uuid.accept(uuids.get(0).getUuid(), null); uuid.accept(uuids.get(0).uuid(), null);
} else { } else {
uuid.accept(null, null); uuid.accept(null, null);
} }
@ -231,7 +231,7 @@ public class UUIDPipeline {
username.accept(null, throwable); username.accept(null, throwable);
} else { } else {
if (!uuids.isEmpty()) { if (!uuids.isEmpty()) {
username.accept(uuids.get(0).getUsername(), null); username.accept(uuids.get(0).username(), null);
} else { } else {
username.accept(null, null); username.accept(null, null);
} }
@ -296,7 +296,7 @@ public class UUIDPipeline {
if (service.canBeSynchronous()) { if (service.canBeSynchronous()) {
final List<UUIDMapping> completedRequests = service.getNames(remainingRequests); final List<UUIDMapping> completedRequests = service.getNames(remainingRequests);
for (final UUIDMapping mapping : completedRequests) { for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.getUuid()); remainingRequests.remove(mapping.uuid());
} }
mappings.addAll(completedRequests); mappings.addAll(completedRequests);
} else { } else {
@ -311,7 +311,7 @@ public class UUIDPipeline {
for (final UUIDService service : serviceList) { for (final UUIDService service : serviceList) {
final List<UUIDMapping> completedRequests = service.getNames(remainingRequests); final List<UUIDMapping> completedRequests = service.getNames(remainingRequests);
for (final UUIDMapping mapping : completedRequests) { for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.getUuid()); remainingRequests.remove(mapping.uuid());
} }
mappings.addAll(completedRequests); mappings.addAll(completedRequests);
if (remainingRequests.isEmpty()) { if (remainingRequests.isEmpty()) {
@ -365,7 +365,7 @@ public class UUIDPipeline {
if (service.canBeSynchronous()) { if (service.canBeSynchronous()) {
final List<UUIDMapping> completedRequests = service.getUUIDs(remainingRequests); final List<UUIDMapping> completedRequests = service.getUUIDs(remainingRequests);
for (final UUIDMapping mapping : completedRequests) { for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.getUsername()); remainingRequests.remove(mapping.username());
} }
mappings.addAll(completedRequests); mappings.addAll(completedRequests);
} else { } else {
@ -380,7 +380,7 @@ public class UUIDPipeline {
for (final UUIDService service : serviceList) { for (final UUIDService service : serviceList) {
final List<UUIDMapping> completedRequests = service.getUUIDs(remainingRequests); final List<UUIDMapping> completedRequests = service.getUUIDs(remainingRequests);
for (final UUIDMapping mapping : completedRequests) { for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.getUsername()); remainingRequests.remove(mapping.username());
} }
mappings.addAll(completedRequests); mappings.addAll(completedRequests);
if (remainingRequests.isEmpty()) { if (remainingRequests.isEmpty()) {