Compare commits

..

9 Commits

66 changed files with 1480 additions and 813 deletions

View File

@ -2,6 +2,7 @@ name: Announce release on discord
on:
release:
types: [published]
jobs:
send_announcement:
runs-on: ubuntu-latest
@ -11,7 +12,7 @@ jobs:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_USERNAME: PlotSquared Release
DISCORD_AVATAR: https://raw.githubusercontent.com/IntellectualSites/Assets/main/plugins/PlotSquared/PlotSquared.png
uses: Ilshidur/action-discord@0c4b27844ba47cb1c7bee539c8eead5284ce9fa9 # ratchet:Ilshidur/action-discord@0.3.2
uses: Ilshidur/action-discord@0.3.2
with:
args: |
"<@&525015541815967744> <@&679322738552471574> <@&699293353862496266>"

View File

@ -1,17 +1,19 @@
name: Build PR
on: [pull_request]
on: [ pull_request ]
jobs:
build_pr:
if: github.repository_owner == 'IntellectualSites'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@55e685c48d84285a5b0418cd094606e199cca3b6 # v1
uses: gradle/wrapper-validation-action@v1
- name: Setup Java
uses: actions/setup-java@v3
with:

View File

@ -1,8 +1,10 @@
name: build
on:
push:
branches:
- v7
jobs:
build:
if: github.repository_owner == 'IntellectualSites'
@ -11,7 +13,7 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@55e685c48d84285a5b0418cd094606e199cca3b6 # v1
uses: gradle/wrapper-validation-action@v1
- name: Setup Java
uses: actions/setup-java@v3
with:
@ -42,14 +44,9 @@ jobs:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
- name: Publish core javadoc
<<<<<<< HEAD
# if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/v7'}}
if: ${{ runner.os == 'Linux' && env.STATUS == 'snapshot' && github.event_name == 'push' && github.ref == 'refs/heads/v7'}}
uses: cpina/github-action-push-to-another-repository@main
=======
if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/v6'}}
uses: cpina/github-action-push-to-another-repository@0a14457bb28b04dfa1652e0ffdfda866d2845c73 # main
>>>>>>> v6
env:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:
@ -62,7 +59,7 @@ jobs:
- name: Publish bukkit javadoc
# if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/v7'}}
if: ${{ runner.os == 'Linux' && env.STATUS == 'snapshot' && github.event_name == 'push' && github.ref == 'refs/heads/v7'}}
uses: cpina/github-action-push-to-another-repository@0a14457bb28b04dfa1652e0ffdfda866d2845c73 # main
uses: cpina/github-action-push-to-another-repository@main
env:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:

View File

@ -1,4 +1,5 @@
name: "CodeQL"
on:
push:
branches: [ v7 ]
@ -14,18 +15,23 @@ jobs:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ['java']
language: [ 'java' ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2
uses: github/codeql-action/analyze@v2

View File

@ -1,12 +1,14 @@
name: draft release
on:
push:
branches:
- v6
pull_request:
types: [opened, reopened, synchronize]
types: [ opened, reopened, synchronize ]
pull_request_target:
types: [opened, reopened, synchronize]
types: [ opened, reopened, synchronize ]
jobs:
update_release_draft:
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}

View File

@ -53,6 +53,10 @@ dependencies {
// Adventure
implementation("net.kyori:adventure-platform-bukkit")
// Cloud
implementation(libs.cloudPaper)
implementation(libs.cloudMinecraftExtras)
}
tasks.processResources {

View File

@ -63,6 +63,7 @@ import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.commands.PlotSquaredCommandManager;
import com.plotsquared.core.components.ComponentPresetManager;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;
@ -215,6 +216,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
@Inject
private PlatformWorldManager<World> worldManager;
private Locale serverLocale;
@Inject
private PlotSquaredCommandManager commandManager;
@SuppressWarnings("StringSplitter")
@Override
@ -382,6 +385,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
// Commands
if (Settings.Enabled_Components.COMMANDS) {
this.registerCommands();
this.commandManager.initializeCommands();
}
// Permissions

View File

@ -18,12 +18,16 @@
*/
package com.plotsquared.bukkit.inject;
import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.paper.PaperCommandManager;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.listener.SingleWorldListener;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.bukkit.queue.BukkitChunkCoordinator;
import com.plotsquared.bukkit.queue.BukkitQueueCoordinator;
@ -47,6 +51,8 @@ import com.plotsquared.core.inject.factory.ChunkCoordinatorBuilderFactory;
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
@ -68,10 +74,14 @@ import com.sk89q.worldedit.extension.platform.Actor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Function;
public class BukkitModule extends AbstractModule {
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + BukkitModule.class.getSimpleName());
@ -145,4 +155,27 @@ public class BukkitModule extends AbstractModule {
return EconHandler.nullEconHandler();
}
@Provides
@Singleton
@NonNull CommandManager<PlotPlayer<?>> provideCommandManager() throws Exception {
final Function<PlotPlayer<?>, CommandSender> plotToPlatform = plotPlayer -> {
if (plotPlayer instanceof BukkitPlayer bukkitPlayer) {
return bukkitPlayer.getPlatformPlayer();
}
return Bukkit.getConsoleSender();
};
final Function<CommandSender, PlotPlayer<?>> platformToPlot = commandSender -> {
if (commandSender instanceof Player player) {
return BukkitUtil.adapt(player);
}
return ConsolePlayer.getConsole();
};
return new PaperCommandManager<>(
this.bukkitPlatform,
AsynchronousCommandExecutionCoordinator.<PlotPlayer<?>>builder().withSynchronousParsing().build(),
platformToPlot,
plotToPlatform
);
}
}

View File

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

View File

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

View File

@ -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().settingsNodes();
new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes();
String world = builder.worldName();
PlotAreaType type = builder.plotAreaType();
String worldPath = "worlds." + builder.worldName();

View File

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

View File

@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at contact<at>intellectualsites.com. All
reported by contacting the project team at contact@intellectualsites.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.

View File

@ -15,6 +15,11 @@ dependencies {
api("net.kyori:adventure-api")
api("net.kyori:adventure-text-minimessage")
// Cloud
api(libs.cloudServices)
api(libs.cloudCore)
api(libs.cloudAnnotations)
// Guice
api(libs.guice) {
exclude(group = "com.google.guava")
@ -40,7 +45,6 @@ dependencies {
// Other libraries
api(libs.prtree)
api(libs.aopalliance)
api(libs.cloudServices)
api(libs.arkitektonika)
api("com.intellectualsites.paster:Paster")
api("com.intellectualsites.informative-annotations:informative-annotations")

View File

@ -136,9 +136,13 @@ public class SimpleBackupManager implements BackupManager {
return this.backupLimit;
}
private record PlotCacheKey(
Plot plot
) {
private static final class PlotCacheKey {
private final Plot plot;
private PlotCacheKey(Plot plot) {
this.plot = plot;
}
@Override
public boolean equals(final Object o) {

View File

@ -1,172 +0,0 @@
/*
* 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.command;
import com.google.inject.Inject;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "add",
usage = "/plot add <player | *>",
category = CommandCategory.SETTINGS,
permission = "plots.add",
requiredType = RequiredType.PLAYER)
public class Add extends Command {
private final EventDispatcher eventDispatcher;
@Inject
public Add(final @NonNull EventDispatcher eventDispatcher) {
super(MainCommand.getInstance(), true);
this.eventDispatcher = eventDispatcher;
}
@Override
public CompletableFuture<Boolean> execute(
final PlotPlayer<?> player,
String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone
) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
checkTrue(
plot.isOwner(player.getUUID()) || player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_TRUST),
TranslatableCaption.of("permission.no_plot_perms")
);
checkTrue(args.length == 1,
TranslatableCaption.of("commandconfig.command_syntax"),
TagResolver.resolver("value", Tag.inserting(Component.text("/plot add <player | *>")))
);
final CompletableFuture<Boolean> future = new CompletableFuture<>();
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
if (throwable != null) {
if (throwable instanceof TimeoutException) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
} else {
player.sendMessage(
TranslatableCaption.of("errors.invalid_player"),
TagResolver.resolver("value", Tag.inserting(Component.text(args[0])))
);
}
future.completeExceptionally(throwable);
return;
} else {
try {
checkTrue(!uuids.isEmpty(), TranslatableCaption.of("errors.invalid_player"),
TagResolver.resolver("value", Tag.inserting(Component.text(args[0])))
);
Iterator<UUID> iterator = uuids.iterator();
int size = plot.getTrusted().size() + plot.getMembers().size();
while (iterator.hasNext()) {
UUID uuid = iterator.next();
if (uuid == DBFunc.EVERYONE && !(player.hasPermission(Permission.PERMISSION_TRUST_EVERYONE) || player.hasPermission(
Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
player.sendMessage(
TranslatableCaption.of("errors.invalid_player"),
TagResolver.resolver("value", Tag.inserting(
PlayerManager.resolveName(uuid).toComponent(player)
))
);
iterator.remove();
continue;
}
if (plot.isOwner(uuid)) {
player.sendMessage(
TranslatableCaption.of("member.already_added"),
TagResolver.resolver("player", Tag.inserting(
PlayerManager.resolveName(uuid).toComponent(player)
))
);
iterator.remove();
continue;
}
if (plot.getMembers().contains(uuid)) {
player.sendMessage(
TranslatableCaption.of("member.already_added"),
TagResolver.resolver("player", Tag.inserting(
PlayerManager.resolveName(uuid).toComponent(player)
))
);
iterator.remove();
continue;
}
size += plot.getTrusted().contains(uuid) ? 0 : 1;
}
checkTrue(!uuids.isEmpty(), null);
int localAddSize = plot.getMembers().size();
int maxAddSize = player.hasPermissionRange(Permission.PERMISSION_ADD, Settings.Limit.MAX_PLOTS);
if (localAddSize >= maxAddSize) {
player.sendMessage(
TranslatableCaption.of("members.plot_max_members_added"),
TagResolver.resolver("amount", Tag.inserting(Component.text(localAddSize)))
);
return;
}
// Success
confirm.run(this, () -> {
for (UUID uuid : uuids) {
if (uuid != DBFunc.EVERYONE) {
if (!plot.removeTrusted(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
}
}
}
plot.addMember(uuid);
this.eventDispatcher.callMember(player, plot, uuid, true);
player.sendMessage(TranslatableCaption.of("member.member_added"));
}
}, null);
} catch (final Throwable exception) {
future.completeExceptionally(exception);
return;
}
}
future.complete(true);
});
return future;
}
@Override
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
}
}

View File

@ -1,210 +0,0 @@
/*
* 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.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.query.PlotQuery;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "alias",
permission = "plots.alias",
usage = "/plot alias <set | remove> <alias>",
aliases = {"setalias", "sa", "name", "rename", "setname", "seta", "nameplot"},
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class Alias extends SubCommand {
private static final Command SET_COMMAND = new Command(null, false, "set", null, RequiredType.NONE, null) {
};
private static final Command REMOVE_COMMAND = new Command(null, false, "remove", null, RequiredType.NONE, null) {
};
@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
sendUsage(player);
return false;
}
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
return false;
}
boolean result = false;
boolean owner = plot.isOwner(player.getUUID());
boolean permission;
boolean admin;
switch (args[0].toLowerCase()) {
case "set" -> {
if (args.length != 2) {
sendUsage(player);
return false;
}
permission = isPermitted(player, Permission.PERMISSION_ALIAS_SET);
admin = isPermitted(player, Permission.PERMISSION_ADMIN_ALIAS_SET);
if (!admin && !owner) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false;
}
if (permission) { // is either admin or owner
setAlias(player, plot, args[1]);
return true;
} else {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
TagResolver.resolver(
"node",
Tag.inserting(Permission.PERMISSION_ALIAS_SET)
)
);
}
}
case "remove" -> {
permission = isPermitted(player, Permission.PERMISSION_ALIAS_REMOVE);
admin = isPermitted(player, Permission.PERMISSION_ADMIN_ALIAS_REMOVE);
if (!admin && !owner) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false;
}
if (permission) {
result = removeAlias(player, plot);
} else {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
TagResolver.resolver(
"node",
Tag.inserting(Permission.PERMISSION_ALIAS_REMOVE)
)
);
}
}
default -> {
sendUsage(player);
result = false;
}
}
return result;
}
@Override
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
final List<Command> commands = new ArrayList<>(2);
if (args.length == 1) {
if ("set".startsWith(args[0])) {
commands.add(SET_COMMAND);
}
if ("remove".startsWith(args[0])) {
commands.add(REMOVE_COMMAND);
}
return commands;
}
return Collections.emptySet();
}
private void setAlias(PlotPlayer<?> player, Plot plot, String alias) {
if (alias.isEmpty()) {
sendUsage(player);
} else if (alias.length() >= 50) {
player.sendMessage(TranslatableCaption.of("alias.alias_too_long"));
} else if (MathMan.isInteger(alias)) {
player.sendMessage(TranslatableCaption.of("flag.not_valid_value")); // TODO this is obviously wrong
} else {
if (PlotQuery.newQuery().inArea(plot.getArea())
.withAlias(alias)
.anyMatch()) {
player.sendMessage(
TranslatableCaption.of("alias.alias_is_taken"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
return;
}
if (Settings.UUID.OFFLINE) {
plot.setAlias(alias);
player.sendMessage(
TranslatableCaption.of("alias.alias_set_to"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
return;
}
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
} else if (uuid != null) {
player.sendMessage(
TranslatableCaption.of("alias.alias_is_taken"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
} else {
plot.setAlias(alias);
player.sendMessage(
TranslatableCaption.of("alias.alias_set_to"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
}
}));
}
}
private boolean removeAlias(PlotPlayer<?> player, Plot plot) {
String alias = plot.getAlias();
if (!plot.getAlias().isEmpty()) {
player.sendMessage(
TranslatableCaption.of("alias.alias_removed"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
} else {
player.sendMessage(
TranslatableCaption.of("alias.no_alias_set")
);
}
plot.setAlias(null);
return true;
}
private boolean isPermitted(PlotPlayer<?> player, Permission permission) {
return player.hasPermission(permission);
}
}

View File

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

View File

@ -108,6 +108,7 @@ public class Clear extends Command {
BackupManager.backup(player, plot, () -> {
final long start = System.currentTimeMillis();
boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> {
plot.getPlotModificationManager().unlink();
TaskManager.runTask(() -> {
plot.removeRunning();
// If the state changes, then mark it as no longer done

View File

@ -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(

View File

@ -474,20 +474,20 @@ public class ListCmd extends SubCommand {
final List<UUIDMapping> 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.uuid());
PlotPlayer<?> pp = PlotSquared.platform().playerManager().getPlayerIfExists(uuidMapping.getUuid());
TagResolver resolver = TagResolver.builder()
.tag("prefix", Tag.inserting(Component.text(prefix)))
.tag("player", Tag.inserting(Component.text(uuidMapping.username())))
.tag("player", Tag.inserting(Component.text(uuidMapping.getUsername())))
.build();
if (pp != null) {
builder.append(MINI_MESSAGE.deserialize(online, resolver));
} else if (uuidMapping.username().equalsIgnoreCase("unknown")) {
} else if (uuidMapping.getUsername().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.uuid().equals(DBFunc.EVERYONE)) {
} else if (uuidMapping.getUuid().equals(DBFunc.EVERYONE)) {
TagResolver everyoneResolver = TagResolver.resolver(
"info.everyone",
Tag.inserting(TranslatableCaption.of("info.everyone").toComponent(player))

View File

@ -86,7 +86,6 @@ public class MainCommand extends Command {
commands.add(CreateRoadSchematic.class);
commands.add(DebugAllowUnsafe.class);
commands.add(RegenAllRoads.class);
commands.add(Claim.class);
commands.add(Auto.class);
commands.add(HomeCommand.class);
commands.add(Visit.class);
@ -94,7 +93,6 @@ public class MainCommand extends Command {
commands.add(Clear.class);
commands.add(Delete.class);
commands.add(Trust.class);
commands.add(Add.class);
commands.add(Leave.class);
commands.add(Deny.class);
commands.add(Remove.class);
@ -130,7 +128,6 @@ public class MainCommand extends Command {
commands.add(Owner.class);
commands.add(Desc.class);
commands.add(Biome.class);
commands.add(Alias.class);
commands.add(SetHome.class);
commands.add(Cluster.class);
commands.add(DebugImportWorlds.class);

View File

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

View File

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

View File

@ -0,0 +1,104 @@
/*
* 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.commands;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import com.google.inject.Inject;
import com.plotsquared.core.commands.arguments.PlotMember;
import com.plotsquared.core.commands.requirements.Requirement;
import com.plotsquared.core.commands.requirements.CommandRequirement;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.PlayerManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
class CommandAdd implements PlotSquaredCommandContainer {
private final EventDispatcher eventDispatcher;
@Inject
CommandAdd(final @NonNull EventDispatcher eventDispatcher) {
this.eventDispatcher = eventDispatcher;
}
@Requirement(CommandRequirement.PLAYER)
@Requirement(CommandRequirement.IS_OWNER)
@CommandPermission("plots.add")
@CommandMethod("${command.prefix} add [target]")
public void commandAdd(
final @NonNull PlotPlayer<?> sender,
@Argument("target") final PlotMember target,
final @NonNull Plot plot
) {
if (target instanceof PlotMember.Everyone) {
if (!sender.hasPermission(Permission.PERMISSION_TRUST_EVERYONE) && !sender.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_TRUST)) {
sender.sendMessage(
TranslatableCaption.of("errors.invalid_player"),
TagResolver.resolver("value", Tag.inserting(
PlayerManager.resolveName(target.uuid()).toComponent(sender)
))
);
return;
}
} else if (plot.isOwner(target.uuid())) {
sender.sendMessage(
TranslatableCaption.of("member.already_added"),
TagResolver.resolver("player", Tag.inserting(
PlayerManager.resolveName(target.uuid()).toComponent(sender)
))
);
return;
} else if (plot.getMembers().contains(target.uuid())) {
sender.sendMessage(
TranslatableCaption.of("member.already_added"),
TagResolver.resolver("player", Tag.inserting(
PlayerManager.resolveName(target.uuid()).toComponent(sender)
))
);
return;
} else if (plot.getMembers().size() >= sender.hasPermissionRange(Permission.PERMISSION_ADD, Settings.Limit.MAX_PLOTS)) {
sender.sendMessage(
TranslatableCaption.of("members.plot_max_members_added"),
TagResolver.resolver("amount", Tag.inserting(Component.text(plot.getMembers().size())))
);
return;
}
if (target instanceof PlotMember.Player) {
if (!plot.removeTrusted(target.uuid())) {
if (plot.getDenied().contains(target.uuid())) {
plot.removeDenied(target.uuid());
}
}
}
plot.addMember(target.uuid());
this.eventDispatcher.callMember(sender, plot, target.uuid(), true);
sender.sendMessage(TranslatableCaption.of("member.member_added"));
}
}

View File

@ -0,0 +1,136 @@
package com.plotsquared.core.commands;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.commands.requirements.CommandRequirement;
import com.plotsquared.core.commands.requirements.Requirement;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.query.PlotQuery;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.concurrent.TimeoutException;
public class CommandAlias implements PlotSquaredCommandContainer {
@Requirement(CommandRequirement.PLAYER)
@Requirement(CommandRequirement.PLOT_HAS_OWNER)
@CommandPermission("plots.alias")
@CommandMethod("${command.prefix} alias set <alias>")
public void commandAliasSet(
final @NonNull PlotPlayer<?> sender,
final @NonNull Plot plot,
@Argument("alias") final @NonNull String alias
) {
final boolean isOwner = plot.isOwner(sender.getUUID());
if (!isOwner && !sender.hasPermission(Permission.PERMISSION_ADMIN_ALIAS_SET)) {
sender.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return;
} else if (!sender.hasPermission(Permission.PERMISSION_ALIAS_SET)) {
sender.sendMessage(
TranslatableCaption.of("permission.no_permission"),
TagResolver.resolver(
"node",
Tag.inserting(Permission.PERMISSION_ALIAS_SET)
)
);
return;
}
if (alias.length() >= 50) {
sender.sendMessage(TranslatableCaption.of("alias.alias_too_long"));
return;
}
if (MathMan.isInteger(alias)) {
sender.sendMessage(TranslatableCaption.of("flag.not_valid_value")); // TODO this is obviously wrong
return;
}
if (PlotQuery.newQuery().inArea(plot.getArea())
.withAlias(alias)
.anyMatch()) {
sender.sendMessage(
TranslatableCaption.of("alias.alias_is_taken"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
return;
}
if (Settings.UUID.OFFLINE) {
plot.setAlias(alias);
sender.sendMessage(
TranslatableCaption.of("alias.alias_set_to"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
return;
}
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
sender.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
} else if (uuid != null) {
sender.sendMessage(
TranslatableCaption.of("alias.alias_is_taken"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
} else {
plot.setAlias(alias);
sender.sendMessage(
TranslatableCaption.of("alias.alias_set_to"),
TagResolver.resolver("alias", Tag.inserting(Component.text(alias)))
);
}
}));
}
@Requirement(CommandRequirement.PLAYER)
@Requirement(CommandRequirement.PLOT_HAS_OWNER)
@CommandPermission("plots.alias")
@CommandMethod("${command.prefix} alias remove")
public void commandAliasRemove(
final @NonNull PlotPlayer<?> sender,
final @NonNull Plot plot
) {
final boolean isOwner = plot.isOwner(sender.getUUID());
if (!isOwner && !sender.hasPermission(Permission.PERMISSION_ADMIN_ALIAS_REMOVE)) {
sender.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return;
} else if (!sender.hasPermission(Permission.PERMISSION_ALIAS_REMOVE)) {
sender.sendMessage(
TranslatableCaption.of("permission.no_permission"),
TagResolver.resolver(
"node",
Tag.inserting(Permission.PERMISSION_ALIAS_REMOVE)
)
);
return;
}
if (plot.getAlias().isEmpty()) {
sender.sendMessage(
TranslatableCaption.of("alias.no_alias_set")
);
return;
}
final String currentAlias = plot.getAlias();
plot.setAlias(null);
sender.sendMessage(
TranslatableCaption.of("alias.alias_removed"),
TagResolver.resolver("alias", Tag.inserting(Component.text(currentAlias)))
);
}
}

View File

@ -1,24 +1,11 @@
/*
* 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.command;
package com.plotsquared.core.commands;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import com.google.inject.Inject;
import com.plotsquared.core.commands.requirements.CommandRequirement;
import com.plotsquared.core.commands.requirements.Requirement;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
@ -26,7 +13,6 @@ import com.plotsquared.core.events.PlayerClaimPlotEvent;
import com.plotsquared.core.events.PlotMergeEvent;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.location.Direction;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.MetaDataAccess;
import com.plotsquared.core.player.PlayerMetaDataKeys;
@ -43,22 +29,17 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@CommandDeclaration(
command = "claim",
aliases = "c",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER, permission = "plots.claim",
usage = "/plot claim")
public class Claim extends SubCommand {
public class CommandClaim implements PlotSquaredCommandContainer {
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + Claim.class.getSimpleName());
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + CommandClaim.class.getSimpleName());
private final EventDispatcher eventDispatcher;
private final EconHandler econHandler;
@Inject
public Claim(
CommandClaim(
final @NonNull EventDispatcher eventDispatcher,
final @NonNull EconHandler econHandler
) {
@ -66,124 +47,132 @@ public class Claim extends SubCommand {
this.econHandler = econHandler;
}
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String schematic = null;
if (args.length >= 1) {
schematic = args[0];
}
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
final PlayerClaimPlotEvent event = this.eventDispatcher.callClaim(player, plot, schematic);
schematic = event.getSchematic();
@Requirement(CommandRequirement.PLAYER)
@Requirement(CommandRequirement.IN_PLOT)
@CommandPermission("plots.add")
@CommandMethod("${command.prefix} claim [schematic]")
public void commandClaim(
final @NonNull PlotPlayer<?> sender,
final @NonNull Plot plot,
@Argument("schematic") final @Nullable String schematic
) {
final PlayerClaimPlotEvent event = this.eventDispatcher.callClaim(sender, plot, schematic);
if (event.getEventResult() == Result.DENY) {
player.sendMessage(
sender.sendMessage(
TranslatableCaption.of("events.event_denied"),
TagResolver.resolver("value", Tag.inserting(Component.text("Claim")))
);
return true;
return;
}
boolean force = event.getEventResult() == Result.FORCE;
int currentPlots = Settings.Limit.GLOBAL ?
player.getPlotCount() :
player.getPlotCount(location.getWorldName());
final boolean forceClaim = event.getEventResult() == Result.FORCE;
final int currentPlots = Settings.Limit.GLOBAL ?
sender.getPlotCount() :
sender.getPlotCount(sender.getLocation().getWorldName());
final PlotArea area = plot.getArea();
try (final MetaDataAccess<Integer> metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
try (final MetaDataAccess<Integer> metaDataAccess = sender.accessPersistentMetaData(
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS
)) {
int grants = 0;
if (currentPlots >= player.getAllowedPlots() && !force) {
if (currentPlots >= sender.getAllowedPlots() && !forceClaim) {
if (metaDataAccess.isPresent()) {
grants = metaDataAccess.get().orElse(0);
if (grants <= 0) {
player.sendMessage(
sender.sendMessage(
TranslatableCaption.of("permission.cant_claim_more_plots"),
TagResolver.resolver("amount", Tag.inserting(Component.text(grants)))
);
metaDataAccess.remove();
}
} else {
player.sendMessage(
sender.sendMessage(
TranslatableCaption.of("permission.cant_claim_more_plots"),
TagResolver.resolver("amount", Tag.inserting(Component.text(player.getAllowedPlots())))
TagResolver.resolver("amount", Tag.inserting(Component.text(sender.getAllowedPlots())))
);
return false;
return;
}
}
if (!plot.canClaim(player)) {
player.sendMessage(TranslatableCaption.of("working.plot_is_claimed"));
return false;
if (!plot.canClaim(sender)) {
sender.sendMessage(TranslatableCaption.of("working.plot_is_claimed"));
return;
}
if (schematic != null && !schematic.isEmpty()) {
if (area.isSchematicClaimSpecify()) {
if (!area.hasSchematic(schematic)) {
player.sendMessage(
sender.sendMessage(
TranslatableCaption.of("schematics.schematic_invalid_named"),
TagResolver.builder()
.tag("schemname", Tag.inserting(Component.text(schematic)))
.tag("reason", Tag.inserting(Component.text("non-existent")))
.build()
);
return;
}
if (!player.hasPermission(Permission.PERMISSION_CLAIM_SCHEMATIC
.format(schematic)) && !player.hasPermission(
if (!sender.hasPermission(
Permission.PERMISSION_CLAIM_SCHEMATIC.format(schematic)
) && !sender.hasPermission(
"plots.admin.command.schematic"
) && !force) {
player.sendMessage(
) && !forceClaim) {
sender.sendMessage(
TranslatableCaption.of("permission.no_schematic_permission"),
TagResolver.resolver("value", Tag.inserting(Component.text(schematic)))
);
return;
}
}
}
if (this.econHandler.isEnabled(area) && !force) {
PlotExpression costExr = area.getPrices().get("claim");
double cost = costExr.evaluate(currentPlots);
if (this.econHandler.isEnabled(area) && !forceClaim) {
final PlotExpression costExr = area.getPrices().get("claim");
final double cost = costExr.evaluate(currentPlots);
if (cost > 0d) {
if (!this.econHandler.isSupported()) {
player.sendMessage(TranslatableCaption.of("economy.vault_or_consumer_null"));
return false;
sender.sendMessage(TranslatableCaption.of("economy.vault_or_consumer_null"));
return;
}
if (this.econHandler.getMoney(player) < cost) {
player.sendMessage(
if (this.econHandler.getMoney(sender) < cost) {
sender.sendMessage(
TranslatableCaption.of("economy.cannot_afford_plot"),
TagResolver.builder()
.tag("money", Tag.inserting(Component.text(this.econHandler.format(cost))))
.tag(
"balance",
Tag.inserting(Component.text(this.econHandler.format(this.econHandler.getMoney(
player))))
Tag.inserting(
Component.text(this.econHandler.format(this.econHandler.getMoney(sender)))
)
)
.build()
);
return false;
return;
}
this.econHandler.withdrawMoney(player, cost);
player.sendMessage(
this.econHandler.withdrawMoney(sender, cost);
sender.sendMessage(
TranslatableCaption.of("economy.removed_balance"),
TagResolver.builder()
.tag("money", Tag.inserting(Component.text(this.econHandler.format(cost))))
.tag(
"balance",
Tag.inserting(Component.text(this.econHandler.format(this.econHandler.getMoney(
player))))
Tag.inserting(
Component.text(this.econHandler.format(this.econHandler.getMoney(sender)))
)
)
.build()
);
}
}
if (grants > 0) {
if (grants == 1) {
metaDataAccess.remove();
} else {
metaDataAccess.set(grants - 1);
}
player.sendMessage(
sender.sendMessage(
TranslatableCaption.of("economy.removed_granted_plot"),
TagResolver.builder()
.tag("usedGrants", Tag.inserting(Component.text(grants - 1)))
@ -192,27 +181,34 @@ public class Claim extends SubCommand {
);
}
}
if (!player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_BORDER)) {
int border = area.getBorder();
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) {
player.sendMessage(TranslatableCaption.of("border.denied"));
return false;
if (!sender.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_BORDER)) {
final int border = area.getBorder();
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !forceClaim) {
sender.sendMessage(TranslatableCaption.of("border.denied"));
return;
}
}
plot.setOwnerAbs(player.getUUID());
final String finalSchematic = schematic;
// Actually update the owner :)
plot.setOwnerAbs(sender.getUUID());
DBFunc.createPlotSafe(plot, () -> {
try {
TaskManager.getPlatformImplementation().sync(() -> {
if (!plot.claim(player, true, finalSchematic, false, false)) {
if (!plot.claim(sender, true, event.getSchematic(), false, false)) {
LOGGER.info("Failed to claim plot {}", plot.getId().toCommaSeparatedString());
player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
sender.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
plot.setOwnerAbs(null);
} else if (area.isAutoMerge()) {
PlotMergeEvent mergeEvent = Claim.this.eventDispatcher
.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player);
final PlotMergeEvent mergeEvent = this.eventDispatcher.callMerge(
plot,
Direction.ALL,
Integer.MAX_VALUE,
sender
);
if (mergeEvent.getEventResult() == Result.DENY) {
player.sendMessage(
sender.sendMessage(
TranslatableCaption.of("events.event_denied"),
TagResolver.resolver("value", Tag.inserting(Component.text("Auto merge on claim")))
);
@ -220,11 +216,11 @@ public class Claim extends SubCommand {
if (plot.getPlotModificationManager().autoMerge(
mergeEvent.getDir(),
mergeEvent.getMax(),
player.getUUID(),
player,
sender.getUUID(),
sender,
true
)) {
eventDispatcher.callPostMerge(player, plot);
eventDispatcher.callPostMerge(sender, plot);
}
}
}
@ -235,10 +231,8 @@ public class Claim extends SubCommand {
}
}, () -> {
LOGGER.info("Failed to add plot to database: {}", plot.getId().toCommaSeparatedString());
player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
sender.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
plot.setOwnerAbs(null);
});
return true;
}
}

View File

@ -0,0 +1,26 @@
/*
* 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.commands;
import cloud.commandframework.captions.Caption;
public final class PlotSquaredCaptionKeys {
public static final Caption ARGUMENT_PARSE_FAILURE_TARGET = Caption.of("argument.parse.failure.target");
}

View File

@ -0,0 +1,26 @@
/*
* 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.commands;
/**
* Indicates that a class contains commands.
*/
public interface PlotSquaredCommandContainer {
}

View File

@ -0,0 +1,82 @@
/*
* 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.commands;
import cloud.commandframework.CommandManager;
import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.meta.SimpleCommandMeta;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.plotsquared.core.commands.parsers.PlotMemberParser;
import com.plotsquared.core.commands.requirements.CommandRequirementBuilderModifier;
import com.plotsquared.core.commands.requirements.CommandRequirementPostProcessor;
import com.plotsquared.core.commands.requirements.Requirements;
import com.plotsquared.core.player.PlotPlayer;
import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.stream.Stream;
public class PlotSquaredCommandManager {
private final Injector injector;
private final CommandManager<PlotPlayer<?>> commandManager;
private final AnnotationParser<PlotPlayer<?>> annotationParser;
@Inject
public PlotSquaredCommandManager(
final @NonNull Injector injector,
final @NonNull CommandManager<PlotPlayer<?>> commandManager
) {
this.injector = injector;
this.commandManager = commandManager;
this.annotationParser = new AnnotationParser<PlotPlayer<?>>(
this.commandManager,
new TypeToken<PlotPlayer<?>>() {
},
parameters -> SimpleCommandMeta.empty()
);
this.annotationParser.registerBuilderModifier(Requirements.class, new CommandRequirementBuilderModifier());
this.commandManager.registerCommandPostProcessor(new CommandRequirementPostProcessor());
}
/**
* Scans the given {@code instance} for commands, and registers them.
*
* @param instance the instance to scan
*/
public void scanClass(final @NonNull Object instance) {
this.annotationParser.parse(instance);
}
/**
* Initializes all the known commands.
*/
public void initializeCommands() {
// We start by scanning the parsers.
Stream.of(
PlotMemberParser.class
).map(this.injector::getInstance).forEach(this::scanClass);
// Then we scan the commands.
Stream.of(
CommandAdd.class,
CommandClaim.class
).map(this.injector::getInstance).forEach(this::scanClass);
}
}

View File

@ -0,0 +1,94 @@
/*
* 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.commands.arguments;
import cloud.commandframework.context.CommandContext;
import com.plotsquared.core.commands.parsers.PlotMemberParser;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.player.PlotPlayer;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID;
public sealed interface PlotMember {
PlotMember EVERYONE = new Everyone();
default @NonNull UUID uuid(@NonNull CommandContext<PlotPlayer<?>> context) {
return this.uuid();
}
@NonNull UUID uuid();
sealed interface PlayerLike extends PlotMember {
}
record Player(@NonNull UUID uuid) implements PlayerLike {
}
final class LazyPlayer implements PlayerLike {
private final String candidate;
private final UuidSupplier uuidSupplier;
private @MonotonicNonNull UUID cachedUuid = null;
public LazyPlayer(
final @NonNull String candidate,
final @NonNull UuidSupplier uuidSupplier
) {
this.candidate = candidate;
this.uuidSupplier = uuidSupplier;
}
public @NonNull UUID uuid() {
throw new UnsupportedOperationException();
}
@Override
public synchronized @NonNull UUID uuid(final @NonNull CommandContext<PlotPlayer<?>> context) {
if (this.cachedUuid == null) {
try {
this.cachedUuid = this.uuidSupplier.uuid();
} catch (Exception ignored) {
}
// The player didn't exist :-(
if (this.cachedUuid == null) {
throw new PlotMemberParser.TargetParseException(this.candidate, context);
}
}
return this.cachedUuid;
}
@FunctionalInterface
public interface UuidSupplier {
@Nullable UUID uuid() throws Exception;
}
}
final class Everyone implements PlotMember {
@Override
public @NonNull UUID uuid() {
return DBFunc.EVERYONE;
}
}
}

View File

@ -0,0 +1,124 @@
/*
* 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.commands.parsers;
import cloud.commandframework.annotations.parsers.Parser;
import cloud.commandframework.captions.CaptionVariable;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import cloud.commandframework.exceptions.parsing.ParserException;
import com.google.inject.Inject;
import com.plotsquared.core.commands.PlotSquaredCaptionKeys;
import com.plotsquared.core.commands.arguments.PlotMember;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.inject.annotations.ImpromptuPipeline;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.uuid.UUIDMapping;
import com.plotsquared.core.uuid.UUIDPipeline;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.io.Serial;
import java.util.Queue;
import java.util.UUID;
public class PlotMemberParser {
private final UUIDPipeline uuidPipeline;
@Inject
public PlotMemberParser(@ImpromptuPipeline final @NonNull UUIDPipeline uuidPipeline) {
this.uuidPipeline = uuidPipeline;
}
@Parser
public @NonNull PlotMember parse(
final @NonNull CommandContext<PlotPlayer<?>> context,
final @NonNull Queue<@NonNull String> input
) {
final var candidate = input.peek();
if (candidate == null) {
throw new NoInputProvidedException(this.getClass(), context);
}
if ("*".equals(candidate)) {
return PlotMember.EVERYONE;
} else if (candidate.length() > 16) {
try {
return new PlotMember.Player(UUID.fromString(candidate));
} catch (IllegalArgumentException ignored) {
throw new TargetParseException(candidate, context);
}
}
if (Settings.Paper_Components.PAPER_LISTENERS) {
try {
return this.uuidPipeline.getUUID(candidate, Settings.UUID.NON_BLOCKING_TIMEOUT)
.get()
.map(UUIDMapping::getUuid)
.map(PlotMember.Player::new)
.orElseThrow();
} catch (Exception e) {
throw new TargetParseException(candidate, context);
}
} else {
return new PlotMember.LazyPlayer(
candidate,
() -> this.uuidPipeline.getUUID(candidate, Settings.UUID.NON_BLOCKING_TIMEOUT)
.get()
.map(UUIDMapping::getUuid)
.orElse(null)
);
}
}
public static final class TargetParseException extends ParserException {
@Serial
private static final long serialVersionUID = 927476591631527552L;
private final String input;
/**
* Construct a new Player parse exception
*
* @param input String input
* @param context Command context
*/
public TargetParseException(
final @NonNull String input,
final @NonNull CommandContext<?> context
) {
super(
PlotMemberParser.class,
context,
PlotSquaredCaptionKeys.ARGUMENT_PARSE_FAILURE_TARGET,
CaptionVariable.of("input", input)
);
this.input = input;
}
/**
* Get the supplied input
*
* @return String value
*/
public @NonNull String getInput() {
return this.input;
}
}
}

View File

@ -0,0 +1,88 @@
/*
* 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.commands.requirements;
import cloud.commandframework.meta.CommandMeta;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
public enum CommandRequirement {
PLAYER(
"",
player -> !(player instanceof ConsolePlayer)
),
IN_PLOT(
"errors.not_in_plot",
player -> player.getCurrentPlot() != null
),
PLOT_HAS_OWNER(
"info.plot_unowned",
player -> Objects.requireNonNull(player.getCurrentPlot()).hasOwner(),
IN_PLOT
),
IS_OWNER(
"permission.no_plot_perms",
player -> Objects.requireNonNull(player.getCurrentPlot()).isOwner(player.getUUID()),
PLOT_HAS_OWNER
);
public static final CommandMeta.Key<List<CommandRequirement>> COMMAND_REQUIREMENTS_KEY = CommandMeta.Key.of(
new TypeToken<List<CommandRequirement>>() {
},
"command_requirements"
);
private final @NonNull Caption caption;
private final @NonNull Predicate<@NonNull PlotPlayer<?>> requirementPredicate;
private final @NonNull Set<@NonNull CommandRequirement> inheritedRequirements;
CommandRequirement(
final @NonNull String caption,
final @NonNull Predicate<@NonNull PlotPlayer<?>> requirementPredicate,
final @NonNull CommandRequirement... inheritedRequirements
) {
this.caption = TranslatableCaption.of(caption);
this.requirementPredicate = requirementPredicate;
this.inheritedRequirements = EnumSet.copyOf(Arrays.asList(inheritedRequirements));
}
public @NonNull Set<@NonNull CommandRequirement> inheritedRequirements() {
return Collections.unmodifiableSet(this.inheritedRequirements);
}
public @NonNull Caption caption() {
return this.caption;
}
public boolean checkRequirement(final @NonNull PlotPlayer<?> player) {
return this.requirementPredicate.test(player);
}
}

View File

@ -0,0 +1,61 @@
/*
* 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.commands.requirements;
import cloud.commandframework.Command;
import com.plotsquared.core.player.PlotPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
public class CommandRequirementBuilderModifier implements BiFunction<
@NonNull Requirements,
Command.@NonNull Builder<PlotPlayer<?>>,
Command.@NonNull Builder<PlotPlayer<?>>
> {
@Override
public Command.@NonNull Builder<PlotPlayer<?>> apply(
final @NonNull Requirements requirements,
final Command.@NonNull Builder<PlotPlayer<?>> builder
) {
// We use a list, because we want them to be evaluated in order.
final Set<CommandRequirement> commandRequirements = EnumSet.noneOf(CommandRequirement.class);
for (final Requirement requirement : requirements.value()) {
this.addRequirements(commandRequirements, requirement.value());
}
// We then sort the requirements.
final List<CommandRequirement> sortedRequirements = commandRequirements.stream().sorted().toList();
// We then register all the types in the command metadata.
return builder.meta(CommandRequirement.COMMAND_REQUIREMENTS_KEY, sortedRequirements);
}
private void addRequirements(
final @NonNull Set<@NonNull CommandRequirement> requirements,
final @NonNull CommandRequirement requirement
) {
for (final CommandRequirement inheritedRequirement : requirement.inheritedRequirements()) {
addRequirements(requirements, inheritedRequirement);
}
requirements.add(requirement);
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.commands.requirements;
import cloud.commandframework.Command;
import cloud.commandframework.execution.postprocessor.CommandPostprocessingContext;
import cloud.commandframework.execution.postprocessor.CommandPostprocessor;
import cloud.commandframework.services.types.ConsumerService;
import com.plotsquared.core.player.PlotPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List;
public class CommandRequirementPostProcessor implements CommandPostprocessor<PlotPlayer<?>> {
@Override
public void accept(
@NonNull final CommandPostprocessingContext<PlotPlayer<?>> context
) {
final Command<PlotPlayer<?>> command = context.getCommand();
final PlotPlayer<?> player = context.getCommandContext().getSender();;
final List<CommandRequirement> commandRequirements = command.getCommandMeta().get(
CommandRequirement.COMMAND_REQUIREMENTS_KEY
).orElse(List.of());
for (final CommandRequirement requirement : commandRequirements) {
if (requirement.checkRequirement(player)) {
continue;
}
// They failed the requirement =(
player.sendMessage(requirement.caption());
// Then we interrupt to make sure the command isn't executed.
ConsumerService.interrupt();
}
}
}

View File

@ -0,0 +1,35 @@
/*
* 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.commands.requirements;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Repeatable(Requirements.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Requirement {
@NonNull CommandRequirement value();
}

View File

@ -0,0 +1,33 @@
/*
* 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.commands.requirements;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Requirements {
@NonNull Requirement @NonNull[] value();
}

View File

@ -35,15 +35,28 @@ import java.util.Map;
* the component GUI
*/
@SerializableAs("preset")
public record ComponentPreset(
ClassicPlotManagerComponent component,
String pattern,
double cost,
String permission,
String displayName,
List<String> description,
ItemType icon
) implements ConfigurationSerializable {
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<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")
public static ComponentPreset deserialize(final @NonNull Map<String, Object> map) {
@ -61,6 +74,34 @@ public record ComponentPreset(
);
}
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
public Map<String, Object> serialize() {
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());
for (final ComponentPreset componentPreset : this.presets) {
if (!componentPreset.permission().isEmpty() && !player.hasPermission(
componentPreset.permission()
if (!componentPreset.getPermission().isEmpty() && !player.hasPermission(
componentPreset.getPermission()
)) {
continue;
}
@ -200,30 +200,30 @@ public class ComponentPresetManager {
return false;
}
final Pattern pattern = PatternUtil.parse(null, componentPreset.pattern(), false);
final Pattern pattern = PatternUtil.parse(null, componentPreset.getPattern(), false);
if (pattern == null) {
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_invalid"));
return false;
}
if (componentPreset.cost() > 0.0D) {
if (componentPreset.getCost() > 0.0D) {
if (!econHandler.isEnabled(plot.getArea())) {
getPlayer().sendMessage(
TranslatableCaption.of("preset.economy_disabled"),
TagResolver.resolver("preset", Tag.inserting(Component.text(componentPreset.displayName())))
TagResolver.resolver("preset", Tag.inserting(Component.text(componentPreset.getDisplayName())))
);
return false;
}
if (econHandler.getMoney(getPlayer()) < componentPreset.cost()) {
if (econHandler.getMoney(getPlayer()) < componentPreset.getCost()) {
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_cannot_afford"));
return false;
} else {
econHandler.withdrawMoney(getPlayer(), componentPreset.cost());
econHandler.withdrawMoney(getPlayer(), componentPreset.getCost());
getPlayer().sendMessage(
TranslatableCaption.of("economy.removed_balance"),
TagResolver.resolver(
"money",
Tag.inserting(Component.text(econHandler.format(componentPreset.cost())))
Tag.inserting(Component.text(econHandler.format(componentPreset.getCost())))
)
);
}
@ -235,7 +235,7 @@ public class ComponentPresetManager {
queue.setCompleteTask(plot::removeRunning);
for (Plot current : plot.getConnectedPlots()) {
current.getPlotModificationManager().setComponent(
componentPreset.component().name(),
componentPreset.getComponent().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<String> lore = new ArrayList<>();
if (preset.cost() > 0) {
if (preset.getCost() > 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.cost()))))
TagResolver.resolver("cost", Tag.inserting(Component.text(String.format("%.2f", preset.getCost()))))
)));
}
}
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.component().name().toLowerCase())))
.tag("component", Tag.inserting(Component.text(preset.getComponent().name().toLowerCase())))
.tag("prefix", Tag.inserting(TranslatableCaption.of("core.prefix").toComponent(player)))
.build()
)));
lore.removeIf(String::isEmpty);
lore.addAll(preset.description());
lore.addAll(preset.getDescription());
plotInventory.setItem(
i,
new PlotItemStack(
preset.icon().getId().replace("minecraft:", ""),
preset.getIcon().getId().replace("minecraft:", ""),
1,
preset.displayName(),
preset.getDisplayName(),
lore.toArray(new String[0])
)
);

View File

@ -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,10 +3414,15 @@ public class SQLManager implements AbstractDB {
}
}
private record LegacySettings(
int id,
PlotSettings settings
) {
private static class LegacySettings {
public final int id;
public final PlotSettings settings;
public LegacySettings(int id, PlotSettings settings) {
this.id = id;
this.settings = settings;
}
}

View File

@ -18,7 +18,6 @@
*/
package com.plotsquared.core.events;
import com.plotsquared.core.command.Claim;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;

View File

@ -18,7 +18,6 @@
*/
package com.plotsquared.core.events;
import com.plotsquared.core.command.Claim;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import org.checkerframework.checker.nullness.qual.Nullable;

View File

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

View File

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

View File

@ -288,7 +288,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
*
* @return the plot the player is standing on or null if standing on a road or not in a {@link PlotArea}
*/
public Plot getCurrentPlot() {
public @Nullable Plot getCurrentPlot() {
try (final MetaDataAccess<Plot> lastPlotAccess =
this.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
if (lastPlotAccess.get().orElse(null) == null && !Settings.Enabled_Components.EVENTS) {

View File

@ -215,11 +215,17 @@ public final class BlockBucket implements ConfigurationSerializable {
return result;
}
private record Range(
int min,
int max,
boolean automatic
) {
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;
}
public int getWeight() {
return max - min;
@ -229,6 +235,14 @@ public final class BlockBucket implements ConfigurationSerializable {
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;
@ -236,13 +250,13 @@ public final class BlockBucket implements ConfigurationSerializable {
if (!(o instanceof final Range other)) {
return false;
}
if (this.min() != other.min()) {
if (this.getMin() != other.getMin()) {
return false;
}
if (this.max() != other.max()) {
if (this.getMax() != other.getMax()) {
return false;
}
if (this.automatic() != other.automatic()) {
if (this.isAutomatic() != other.isAutomatic()) {
return false;
}
return true;
@ -251,12 +265,16 @@ public final class BlockBucket implements ConfigurationSerializable {
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.min();
result = result * PRIME + this.max();
result = result * PRIME + (this.automatic() ? 79 : 97);
result = result * PRIME + this.getMin();
result = result * PRIME + this.getMax();
result = result * PRIME + (this.isAutomatic() ? 79 : 97);
return result;
}
public boolean isAutomatic() {
return this.automatic;
}
}
}

View File

@ -113,12 +113,13 @@ public class PlotSettings {
this.position = position;
}
@SuppressWarnings({"UnstableApiUsage"})
public List<PlotComment> 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());
}

View File

@ -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++;
}
}

View File

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

View File

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

View File

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

View File

@ -76,10 +76,23 @@ public abstract class TimedFlag<T, F extends PlotFlag<TimedFlag.Timed<T>, F>>
return getValue().toString();
}
public record Timed<T>(
int interval,
T value
) {
public static final class Timed<T> {
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
public String toString() {

View File

@ -1,105 +0,0 @@
/*
* 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,7 +21,9 @@ 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;
@ -32,12 +34,88 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
public interface AutoService extends Service<AutoQuery, List<Plot>> {
public interface AutoService extends Service<AutoService.AutoQuery, List<Plot>> {
Cache<PlotId, Plot> 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
@ -47,16 +125,17 @@ public interface AutoService extends Service<AutoQuery, List<Plot>> {
}
final class SinglePlotService implements AutoService, Predicate<AutoQuery> {
@Nullable
@Override
public List<Plot> handle(@NonNull AutoQuery autoQuery) {
Plot plot;
PlotId nextId = autoQuery.startId();
PlotId nextId = autoQuery.getStartId();
do {
synchronized (plotLock) {
plot = autoQuery.plotArea().getNextFreePlot(autoQuery.player(), nextId);
plot = autoQuery.getPlotArea().getNextFreePlot(autoQuery.getPlayer(), nextId);
if (plot != null && plotCandidateCache.getIfPresent(plot.getId()) == null) {
plotCandidateCache.put(plot.getId(), plot);
return Collections.singletonList(plot);
@ -72,11 +151,12 @@ public interface AutoService extends Service<AutoQuery, List<Plot>> {
@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<AutoQuery> {
@Override
@ -86,14 +166,14 @@ public interface AutoService extends Service<AutoQuery, List<Plot>> {
while (true) {
synchronized (plotLock) {
final PlotId start =
autoQuery.plotArea().getMeta("lastPlot", PlotId.of(0, 0)).getNextId();
autoQuery.getPlotArea().getMeta("lastPlot", PlotId.of(0, 0)).getNextId();
final PlotId end = PlotId.of(
start.getX() + autoQuery.sizeX() - 1,
start.getY() + autoQuery.sizeZ() - 1
start.getX() + autoQuery.getSizeX() - 1,
start.getY() + autoQuery.getSizeZ() - 1
);
final List<Plot> plots =
autoQuery.plotArea().canClaim(autoQuery.player(), start, end);
autoQuery.plotArea().setMeta("lastPlot", start); // set entry point for next try
autoQuery.getPlotArea().canClaim(autoQuery.getPlayer(), start, end);
autoQuery.getPlotArea().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) {
@ -109,7 +189,7 @@ public interface AutoService extends Service<AutoQuery, List<Plot>> {
@Override
public boolean test(final @NonNull AutoQuery autoQuery) {
return autoQuery.plotArea().getType() != PlotAreaType.PARTIAL;
return autoQuery.getPlotArea().getType() != PlotAreaType.PARTIAL;
}
}

View File

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

View File

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

View File

@ -18,9 +18,14 @@
*/
package com.plotsquared.core.util;
public record FileBytes(
String path,
byte[] data
) {
public class FileBytes {
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);
} else {
for (final UUIDMapping uuid : uuids) {
result.add(uuid.uuid());
result.add(uuid.getUuid());
}
consumer.accept(result, null);
}
@ -136,7 +136,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
try {
for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline()
.getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS)) {
users.add(Component.text(mapping.username()));
users.add(Component.text(mapping.getUsername()));
}
} catch (final Exception e) {
e.printStackTrace();
@ -200,7 +200,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
final UUIDMapping uuidMapping =
PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner);
if (uuidMapping != null) {
name = uuidMapping.username();
name = uuidMapping.getUsername();
} else {
name = null;
}

View File

@ -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.uuid())) {
players.add(mapping.username());
if (uuidFilter.test(mapping.getUuid())) {
players.add(mapping.getUsername());
}
}
cachedCompletionValues.put(cacheIdentifier, players);

View File

@ -300,9 +300,17 @@ public final class PlaceholderRegistry {
/**
* Event called when a new {@link Placeholder} has been added
*/
public record PlaceholderAddedEvent(
Placeholder placeholder
) {
public static class PlaceholderAddedEvent {
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
public void accept(final @NonNull List<@NonNull UUIDMapping> uuidMappings) {
for (final UUIDMapping mapping : uuidMappings) {
this.uuidCache.put(mapping.uuid(), mapping);
this.usernameCache.put(mapping.username(), mapping);
this.uuidCache.put(mapping.getUuid(), mapping);
this.usernameCache.put(mapping.getUsername(), mapping);
}
}

View File

@ -20,15 +20,29 @@ 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 record UUIDMapping(
@NonNull UUID uuid,
@NonNull String 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) {
@ -42,4 +56,9 @@ public record UUIDMapping(
return uuid.equals(that.uuid) && username.equals(that.username);
}
@Override
public int hashCode() {
return Objects.hash(uuid, username);
}
}

View File

@ -36,6 +36,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@ -157,7 +158,7 @@ public class UUIDPipeline {
TimeUnit.MILLISECONDS
);
if (mappings.size() == 1) {
return mappings.get(0).uuid();
return mappings.get(0).getUuid();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
@ -182,7 +183,7 @@ public class UUIDPipeline {
try {
final List<UUIDMapping> mappings = this.getNames(Collections.singletonList(uuid)).get(timeout, TimeUnit.MILLISECONDS);
if (mappings.size() == 1) {
return mappings.get(0).username();
return mappings.get(0).getUsername();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
@ -209,7 +210,7 @@ public class UUIDPipeline {
uuid.accept(null, throwable);
} else {
if (!uuids.isEmpty()) {
uuid.accept(uuids.get(0).uuid(), null);
uuid.accept(uuids.get(0).getUuid(), null);
} else {
uuid.accept(null, null);
}
@ -231,7 +232,7 @@ public class UUIDPipeline {
username.accept(null, throwable);
} else {
if (!uuids.isEmpty()) {
username.accept(uuids.get(0).username(), null);
username.accept(uuids.get(0).getUsername(), null);
} else {
username.accept(null, null);
}
@ -273,6 +274,25 @@ public class UUIDPipeline {
return this.getUUIDs(requests).orTimeout(timeout, TimeUnit.MILLISECONDS);
}
/**
* Asynchronously attempt to fetch the mapping from a name.
* <p>
* This will timeout after the specified time and throws a {@link TimeoutException}
* if this happens
*
* @param username Name
* @param timeout Timeout in milliseconds
* @return Mapping
*/
public @NonNull CompletableFuture<Optional<UUIDMapping>> getUUID(
final @NonNull String username,
final long timeout
) {
return this.getUUIDs(List.of(username), timeout).thenApply(
results -> results.stream().findFirst()
);
}
/**
* Asynchronously attempt to fetch the mapping from a list of UUIDs
*
@ -296,7 +316,7 @@ public class UUIDPipeline {
if (service.canBeSynchronous()) {
final List<UUIDMapping> completedRequests = service.getNames(remainingRequests);
for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.uuid());
remainingRequests.remove(mapping.getUuid());
}
mappings.addAll(completedRequests);
} else {
@ -311,7 +331,7 @@ public class UUIDPipeline {
for (final UUIDService service : serviceList) {
final List<UUIDMapping> completedRequests = service.getNames(remainingRequests);
for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.uuid());
remainingRequests.remove(mapping.getUuid());
}
mappings.addAll(completedRequests);
if (remainingRequests.isEmpty()) {
@ -365,7 +385,7 @@ public class UUIDPipeline {
if (service.canBeSynchronous()) {
final List<UUIDMapping> completedRequests = service.getUUIDs(remainingRequests);
for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.username());
remainingRequests.remove(mapping.getUsername());
}
mappings.addAll(completedRequests);
} else {
@ -380,7 +400,7 @@ public class UUIDPipeline {
for (final UUIDService service : serviceList) {
final List<UUIDMapping> completedRequests = service.getUUIDs(remainingRequests);
for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.username());
remainingRequests.remove(mapping.getUsername());
}
mappings.addAll(completedRequests);
if (remainingRequests.isEmpty()) {

View File

@ -155,7 +155,7 @@ subprojects {
id.set("NotMyFault")
name.set("Alexander Brandes")
organization.set("IntellectualSites")
email.set("contact(at)notmyfault.dev")
email.set("contact@notmyfault.dev")
}
developer {
id.set("SirYwell")

View File

@ -11,17 +11,17 @@ essentialsx = "2.19.7"
mvdwapi = "3.1.1"
# Third party
prtree = "2.0.1"
prtree = "2.0.0"
aopalliance = "1.0"
cloud-services = "1.8.2"
arkitektonika = "2.1.1"
squirrelid = "0.3.1"
cloud = "1.8.0"
# Gradle plugins
shadow = "7.1.2"
grgit = "4.1.1"
spotless = "6.16.0"
nexus = "1.2.0"
spotless = "6.15.0"
nexus = "1.1.0"
[libraries]
# Platform expectations
@ -39,10 +39,14 @@ essentialsx = { group = "net.essentialsx", name = "EssentialsX", version.ref = "
# Third party
prtree = { group = "com.intellectualsites.prtree", name = "PRTree", version.ref = "prtree" }
aopalliance = { group = "aopalliance", name = "aopalliance", version.ref = "aopalliance" }
cloudServices = { group = "cloud.commandframework", name = "cloud-services", version.ref = "cloud-services" }
mvdwapi = { group = "com.intellectualsites.mvdwplaceholderapi", name = "MVdWPlaceholderAPI", version.ref = "mvdwapi" }
squirrelid = { group = "org.enginehub", name = "squirrelid", version.ref = "squirrelid" }
arkitektonika = { group = "com.intellectualsites.arkitektonika", name = "Arkitektonika-Client", version.ref = "arkitektonika" }
cloudServices = { group = "cloud.commandframework", name = "cloud-services", version.ref = "cloud" }
cloudCore = { group = "cloud.commandframework", name = "cloud-core", version.ref = "cloud" }
cloudAnnotations = { group = "cloud.commandframework", name = "cloud-annotations", version.ref = "cloud" }
cloudPaper = { group = "cloud.commandframework", name = "cloud-paper", version.ref = "cloud" }
cloudMinecraftExtras = { group = "cloud.commandframework", name = "cloud-minecraft-extras", version.ref = "cloud" }
[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists