mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Initial annotation usage cleanup + EditorConfig
This commit is contained in:
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2021 IntellectualSites
|
||||
*
|
||||
* 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;
|
||||
|
||||
public enum Platform {
|
||||
Bukkit, Sponge, Spigot, Paper
|
||||
|
||||
}
|
@ -38,9 +38,9 @@ import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -59,7 +59,8 @@ import java.util.UUID;
|
||||
*
|
||||
* @version 5
|
||||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"}) public class PlotAPI {
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class PlotAPI {
|
||||
|
||||
public PlotAPI() {
|
||||
}
|
||||
@ -69,7 +70,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @return all plots
|
||||
*/
|
||||
public Set<Plot> getAllPlots() {
|
||||
public @NonNull Set<@NonNull Plot> getAllPlots() {
|
||||
return PlotQuery.newQuery().allPlots().asSet();
|
||||
}
|
||||
|
||||
@ -79,7 +80,7 @@ import java.util.UUID;
|
||||
* @param player Player, whose plots to search for
|
||||
* @return all plots that a player owns
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(PlotPlayer<?> player) {
|
||||
public @NonNull Set<@NonNull Plot> getPlayerPlots(final @NonNull PlotPlayer<?> player) {
|
||||
return PlotQuery.newQuery().ownedBy(player).asSet();
|
||||
}
|
||||
|
||||
@ -89,7 +90,7 @@ import java.util.UUID;
|
||||
* @param plotArea Plot World Object
|
||||
* @see PlotSquared#addPlotArea(PlotArea)
|
||||
*/
|
||||
public void addPlotArea(PlotArea plotArea) {
|
||||
public void addPlotArea(final @NonNull PlotArea plotArea) {
|
||||
PlotSquared.get().addPlotArea(plotArea);
|
||||
}
|
||||
|
||||
@ -106,7 +107,7 @@ import java.util.UUID;
|
||||
* @return ChunkManager
|
||||
* @see ChunkManager
|
||||
*/
|
||||
public ChunkManager getChunkManager() {
|
||||
public @NonNull ChunkManager getChunkManager() {
|
||||
return PlotSquared.platform().injector().getInstance(ChunkManager.class);
|
||||
}
|
||||
|
||||
@ -115,7 +116,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @return GlobalBlockQueue.IMP
|
||||
*/
|
||||
public GlobalBlockQueue getBlockQueue() {
|
||||
public @NonNull GlobalBlockQueue getBlockQueue() {
|
||||
return PlotSquared.platform().globalBlockQueue();
|
||||
}
|
||||
|
||||
@ -126,7 +127,7 @@ import java.util.UUID;
|
||||
* @return SchematicHandler
|
||||
* @see SchematicHandler
|
||||
*/
|
||||
public SchematicHandler getSchematicHandler() {
|
||||
public @NonNull SchematicHandler getSchematicHandler() {
|
||||
return PlotSquared.platform().injector().getInstance(SchematicHandler.class);
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ import java.util.UUID;
|
||||
* @param world The world to check for plot areas
|
||||
* @return A set of PlotAreas
|
||||
*/
|
||||
public Set<PlotArea> getPlotAreas(String world) {
|
||||
public @NonNull Set<@NonNull PlotArea> getPlotAreas(final @Nullable String world) {
|
||||
if (world == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
@ -149,7 +150,9 @@ import java.util.UUID;
|
||||
* @param message the message
|
||||
* @param replacements Variable replacements
|
||||
*/
|
||||
public void sendConsoleMessage(@Nonnull final String message, final Template... replacements) {
|
||||
public void sendConsoleMessage(
|
||||
final @NonNull String message,
|
||||
final @NonNull Template @NonNull... replacements) {
|
||||
ConsolePlayer.getConsole().sendMessage(StaticCaption.of(message), replacements);
|
||||
// TODO: Re-implement
|
||||
// PlotSquared.log(message);
|
||||
@ -161,7 +164,10 @@ import java.util.UUID;
|
||||
* @param caption the message
|
||||
* @param replacements Variable replacements
|
||||
*/
|
||||
public void sendConsoleMessage(@Nonnull final Caption caption, final Template... replacements) {
|
||||
public void sendConsoleMessage(
|
||||
final @NonNull Caption caption,
|
||||
final @NonNull Template @NonNull... replacements
|
||||
) {
|
||||
ConsolePlayer.getConsole().sendMessage(caption, replacements);
|
||||
}
|
||||
|
||||
@ -171,7 +177,7 @@ import java.util.UUID;
|
||||
* @return PlotSquared Class
|
||||
* @see PlotSquared
|
||||
*/
|
||||
public PlotSquared getPlotSquared() {
|
||||
public @NonNull PlotSquared getPlotSquared() {
|
||||
return PlotSquared.get();
|
||||
}
|
||||
|
||||
@ -179,12 +185,12 @@ import java.util.UUID;
|
||||
* Gets the PlotPlayer for a UUID.
|
||||
*
|
||||
* <p><i>Please note that PlotSquared can be configured to provide
|
||||
* different UUIDs than bukkit</i>
|
||||
* different UUIDs than Bukkit</i>
|
||||
*
|
||||
* @param uuid the uuid of the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
*/
|
||||
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final UUID uuid) {
|
||||
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull UUID uuid) {
|
||||
return PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
||||
}
|
||||
|
||||
@ -194,7 +200,7 @@ import java.util.UUID;
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
*/
|
||||
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final String player) {
|
||||
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull String player) {
|
||||
return PlotSquared.platform().playerManager().getPlayerIfExists(player);
|
||||
}
|
||||
|
||||
@ -204,7 +210,8 @@ import java.util.UUID;
|
||||
* @param listener the listener class to register
|
||||
* @see EventDispatcher#registerListener(Object)
|
||||
*/
|
||||
public void registerListener(Object listener) {
|
||||
public void registerListener(final @NonNull Object listener) {
|
||||
PlotSquared.get().getEventDispatcher().registerListener(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,9 +49,9 @@ import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@ -66,14 +66,14 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return the PlotSquared directory
|
||||
*/
|
||||
@Nonnull File getDirectory();
|
||||
@NonNull File getDirectory();
|
||||
|
||||
/**
|
||||
* Gets the folder where all world data is stored.
|
||||
*
|
||||
* @return the world folder
|
||||
*/
|
||||
@Nonnull File worldContainer();
|
||||
@NonNull File worldContainer();
|
||||
|
||||
/**
|
||||
* Completely shuts down the plugin.
|
||||
@ -85,7 +85,8 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Plugin name
|
||||
*/
|
||||
@Nonnull default String pluginName() {
|
||||
@NonNull
|
||||
default String pluginName() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
@ -94,21 +95,21 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return server version as array of numbers
|
||||
*/
|
||||
@Nonnull int[] serverVersion();
|
||||
int[] serverVersion();
|
||||
|
||||
/**
|
||||
* Gets the server implementation name and version
|
||||
*
|
||||
* @return server implementation and version as string
|
||||
*/
|
||||
@Nonnull String serverImplementation();
|
||||
@NonNull String serverImplementation();
|
||||
|
||||
/**
|
||||
* Gets the native server code package prefix.
|
||||
*
|
||||
* @return The package prefix
|
||||
*/
|
||||
@Nonnull String serverNativePackage();
|
||||
@NonNull String serverNativePackage();
|
||||
|
||||
/**
|
||||
* Start Metrics.
|
||||
@ -120,14 +121,14 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @param world The world to set the generator
|
||||
*/
|
||||
void setGenerator(String world);
|
||||
void setGenerator(@NonNull String world);
|
||||
|
||||
/**
|
||||
* Unregisters a {@link PlotPlayer} from cache e.g. if they have logged off.
|
||||
*
|
||||
* @param player the player to remove
|
||||
*/
|
||||
void unregister(PlotPlayer<?> player);
|
||||
void unregister(@NonNull PlotPlayer<?> player);
|
||||
|
||||
/**
|
||||
* Gets the generator wrapper for a world (world) and generator (name).
|
||||
@ -136,7 +137,10 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
* @param name The name of the generator
|
||||
* @return The generator being used for the provided world
|
||||
*/
|
||||
@Nullable GeneratorWrapper<?> getGenerator(@Nonnull String world, @Nullable String name);
|
||||
@Nullable GeneratorWrapper<?> getGenerator(
|
||||
@NonNull String world,
|
||||
@Nullable String name
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a platform generator from a plot generator
|
||||
@ -145,14 +149,17 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
* @param generator Plot generator
|
||||
* @return Platform generator wrapper
|
||||
*/
|
||||
@Nonnull GeneratorWrapper<?> wrapPlotGenerator(@Nonnull String world, @Nonnull IndependentPlotGenerator generator);
|
||||
@NonNull GeneratorWrapper<?> wrapPlotGenerator(
|
||||
@NonNull String world,
|
||||
@NonNull IndependentPlotGenerator generator
|
||||
);
|
||||
|
||||
/**
|
||||
* Usually HybridGen
|
||||
*
|
||||
* @return Default implementation generator
|
||||
*/
|
||||
@Nonnull default IndependentPlotGenerator defaultGenerator() {
|
||||
default @NonNull IndependentPlotGenerator defaultGenerator() {
|
||||
return injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
|
||||
}
|
||||
|
||||
@ -161,7 +168,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Backup manager
|
||||
*/
|
||||
@Nonnull default BackupManager backupManager() {
|
||||
default @NonNull BackupManager backupManager() {
|
||||
return injector().getInstance(BackupManager.class);
|
||||
}
|
||||
|
||||
@ -170,7 +177,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return World manager
|
||||
*/
|
||||
@Nonnull default PlatformWorldManager<?> worldManager() {
|
||||
default @NonNull PlatformWorldManager<?> worldManager() {
|
||||
return injector().getInstance(PlatformWorldManager.class);
|
||||
}
|
||||
|
||||
@ -179,8 +186,9 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Player manager
|
||||
*/
|
||||
@Nonnull default PlayerManager<? extends PlotPlayer<P>, ? extends P> playerManager() {
|
||||
return injector().getInstance(Key.get(new TypeLiteral<PlayerManager<? extends PlotPlayer<P>, ? extends P>>() {}));
|
||||
default @NonNull PlayerManager<? extends PlotPlayer<P>, ? extends P> playerManager() {
|
||||
return injector().getInstance(Key.get(new TypeLiteral<PlayerManager<? extends PlotPlayer<P>, ? extends P>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,21 +197,21 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
* @param worldName World name
|
||||
* @return Platform world wrapper
|
||||
*/
|
||||
@Nullable World<?> getPlatformWorld(@Nonnull final String worldName);
|
||||
@Nullable World<?> getPlatformWorld(@NonNull String worldName);
|
||||
|
||||
/**
|
||||
* Get the {@link com.google.inject.Injector} instance used by PlotSquared
|
||||
*
|
||||
* @return Injector instance
|
||||
*/
|
||||
@Nonnull Injector injector();
|
||||
@NonNull Injector injector();
|
||||
|
||||
/**
|
||||
* Get the world utility implementation
|
||||
*
|
||||
* @return World utility
|
||||
*/
|
||||
@Nonnull default WorldUtil worldUtil() {
|
||||
default @NonNull WorldUtil worldUtil() {
|
||||
return injector().getInstance(WorldUtil.class);
|
||||
}
|
||||
|
||||
@ -212,7 +220,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Global block queue implementation
|
||||
*/
|
||||
@Nonnull default GlobalBlockQueue globalBlockQueue() {
|
||||
default @NonNull GlobalBlockQueue globalBlockQueue() {
|
||||
return injector().getInstance(GlobalBlockQueue.class);
|
||||
}
|
||||
|
||||
@ -221,7 +229,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Hybrid utils
|
||||
*/
|
||||
@Nonnull default HybridUtils hybridUtils() {
|
||||
default @NonNull HybridUtils hybridUtils() {
|
||||
return injector().getInstance(HybridUtils.class);
|
||||
}
|
||||
|
||||
@ -230,16 +238,16 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Setup utils
|
||||
*/
|
||||
@Nonnull default SetupUtils setupUtils() {
|
||||
default @NonNull SetupUtils setupUtils() {
|
||||
return injector().getInstance(SetupUtils.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link EconHandler} implementation for the platform
|
||||
* *
|
||||
*
|
||||
* @return Econ handler
|
||||
*/
|
||||
@Nonnull default EconHandler econHandler() {
|
||||
default @NonNull EconHandler econHandler() {
|
||||
return injector().getInstance(EconHandler.class);
|
||||
}
|
||||
|
||||
@ -248,7 +256,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Region manager
|
||||
*/
|
||||
@Nonnull default RegionManager regionManager() {
|
||||
default @NonNull RegionManager regionManager() {
|
||||
return injector().getInstance(RegionManager.class);
|
||||
}
|
||||
|
||||
@ -257,7 +265,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Region manager
|
||||
*/
|
||||
@Nonnull default ChunkManager chunkManager() {
|
||||
default @NonNull ChunkManager chunkManager() {
|
||||
return injector().getInstance(ChunkManager.class);
|
||||
}
|
||||
|
||||
@ -266,7 +274,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Console audience
|
||||
*/
|
||||
@Nonnull Audience consoleAudience();
|
||||
@NonNull Audience consoleAudience();
|
||||
|
||||
/**
|
||||
* Get a formatted string containing all plugins on the server together
|
||||
@ -274,7 +282,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Formatted string
|
||||
*/
|
||||
@Nonnull String pluginsFormatted();
|
||||
@NonNull String pluginsFormatted();
|
||||
|
||||
/**
|
||||
* Load the caption maps
|
||||
@ -286,7 +294,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Permission handler
|
||||
*/
|
||||
@Nonnull default PermissionHandler permissionHandler() {
|
||||
default @NonNull PermissionHandler permissionHandler() {
|
||||
return injector().getInstance(PermissionHandler.class);
|
||||
}
|
||||
|
||||
@ -295,7 +303,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Service pipeline
|
||||
*/
|
||||
@Nonnull default ServicePipeline servicePipeline() {
|
||||
default @NonNull ServicePipeline servicePipeline() {
|
||||
return injector().getInstance(ServicePipeline.class);
|
||||
}
|
||||
|
||||
@ -304,10 +312,10 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
||||
*
|
||||
* @return Placeholder registry
|
||||
*/
|
||||
@Nonnull default PlaceholderRegistry placeholderRegistry() {
|
||||
default @NonNull PlaceholderRegistry placeholderRegistry() {
|
||||
return injector().getInstance(PlaceholderRegistry.class);
|
||||
}
|
||||
|
||||
@Nonnull String toLegacyPlatformString(Component component);
|
||||
@NonNull String toLegacyPlatformString(Component component);
|
||||
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.configuration.MemorySection;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.Storage;
|
||||
import com.plotsquared.core.configuration.caption.load.CaptionLoader;
|
||||
import com.plotsquared.core.configuration.caption.CaptionMap;
|
||||
import com.plotsquared.core.configuration.caption.DummyCaptionMap;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.configuration.caption.load.CaptionLoader;
|
||||
import com.plotsquared.core.configuration.caption.load.DefaultCaptionProvider;
|
||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
import com.plotsquared.core.configuration.serialization.ConfigurationSerialization;
|
||||
@ -73,10 +73,12 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -120,7 +122,7 @@ import java.util.zip.ZipInputStream;
|
||||
public class PlotSquared {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotSquared.class.getSimpleName());
|
||||
private static PlotSquared instance;
|
||||
private static @MonotonicNonNull PlotSquared instance;
|
||||
|
||||
// Implementation
|
||||
private final PlotPlatform<?> platform;
|
||||
@ -128,9 +130,13 @@ public class PlotSquared {
|
||||
private final Thread thread;
|
||||
// UUID pipelines
|
||||
private final UUIDPipeline impromptuUUIDPipeline =
|
||||
new UUIDPipeline(Executors.newCachedThreadPool());
|
||||
new UUIDPipeline(Executors.newCachedThreadPool());
|
||||
private final UUIDPipeline backgroundUUIDPipeline =
|
||||
new UUIDPipeline(Executors.newSingleThreadExecutor());
|
||||
new UUIDPipeline(Executors.newSingleThreadExecutor());
|
||||
// Localization
|
||||
private final CaptionLoader captionLoader;
|
||||
private final Map<String, CaptionMap> captionMaps = new HashMap<>();
|
||||
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
|
||||
// WorldEdit instance
|
||||
private WorldEdit worldedit;
|
||||
private File configFile;
|
||||
@ -138,11 +144,7 @@ public class PlotSquared {
|
||||
private YamlConfiguration worldConfiguration;
|
||||
// Temporary hold the plots/clusters before the worlds load
|
||||
private HashMap<String, Set<PlotCluster>> clustersTmp;
|
||||
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
|
||||
private YamlConfiguration config;
|
||||
// Localization
|
||||
private final CaptionLoader captionLoader;
|
||||
private final Map<String, CaptionMap> captionMaps = new HashMap<>();
|
||||
// Platform / Version / Update URL
|
||||
private PlotVersion version;
|
||||
// Files and configuration
|
||||
@ -157,7 +159,10 @@ public class PlotSquared {
|
||||
* @param iPlotMain Implementation of {@link PlotPlatform} used
|
||||
* @param platform The platform being used
|
||||
*/
|
||||
public PlotSquared(final PlotPlatform<?> iPlotMain, final String platform) {
|
||||
public PlotSquared(
|
||||
final @NonNull PlotPlatform<?> iPlotMain,
|
||||
final @NonNull String platform
|
||||
) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("Cannot re-initialize the PlotSquared singleton");
|
||||
}
|
||||
@ -175,10 +180,14 @@ public class PlotSquared {
|
||||
//
|
||||
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
|
||||
|
||||
this.captionLoader = CaptionLoader.of(Locale.ENGLISH,
|
||||
this.captionLoader = CaptionLoader.of(
|
||||
Locale.ENGLISH,
|
||||
CaptionLoader.patternExtractor(Pattern.compile("messages_(.*)\\.json")),
|
||||
DefaultCaptionProvider.forClassLoaderFormatString(this.getClass().getClassLoader(),
|
||||
"lang/messages_%s.json")); // the path in our jar file
|
||||
DefaultCaptionProvider.forClassLoaderFormatString(
|
||||
this.getClass().getClassLoader(),
|
||||
"lang/messages_%s.json"
|
||||
)
|
||||
); // the path in our jar file
|
||||
// Load caption map
|
||||
try {
|
||||
this.loadCaptionMap();
|
||||
@ -194,14 +203,16 @@ public class PlotSquared {
|
||||
try {
|
||||
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
this.jarFile = new File(
|
||||
new URL(logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
|
||||
.toURI().getPath());
|
||||
new URL(logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
|
||||
.toURI().getPath());
|
||||
} catch (MalformedURLException | URISyntaxException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
|
||||
if (!this.jarFile.exists()) {
|
||||
this.jarFile = new File(this.platform.getDirectory().getParentFile(),
|
||||
"PlotSquared-" + platform + ".jar");
|
||||
this.jarFile = new File(
|
||||
this.platform.getDirectory().getParentFile(),
|
||||
"PlotSquared-" + platform + ".jar"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,6 +245,27 @@ public class PlotSquared {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of PlotSquared.
|
||||
*
|
||||
* @return instance of PlotSquared
|
||||
*/
|
||||
public static @NonNull PlotSquared get() {
|
||||
return PlotSquared.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform specific implementation of PlotSquared
|
||||
*
|
||||
* @return Platform implementation
|
||||
*/
|
||||
public static @NonNull PlotPlatform<?> platform() {
|
||||
if (instance != null && instance.platform != null) {
|
||||
return instance.platform;
|
||||
}
|
||||
throw new IllegalStateException("Plot platform implementation is missing");
|
||||
}
|
||||
|
||||
public void loadCaptionMap() throws Exception {
|
||||
this.platform.copyCaptionMaps();
|
||||
// Setup localization
|
||||
@ -245,8 +277,10 @@ public class PlotSquared {
|
||||
captionMap = this.captionLoader.loadSingle(this.platform.getDirectory().toPath().resolve("lang").resolve(fileName));
|
||||
}
|
||||
this.captionMaps.put(TranslatableCaption.DEFAULT_NAMESPACE, captionMap);
|
||||
logger.info("Loaded caption map for namespace 'plotsquared': {}",
|
||||
this.captionMaps.get(TranslatableCaption.DEFAULT_NAMESPACE).getClass().getCanonicalName());
|
||||
logger.info(
|
||||
"Loaded caption map for namespace 'plotsquared': {}",
|
||||
this.captionMaps.get(TranslatableCaption.DEFAULT_NAMESPACE).getClass().getCanonicalName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,31 +288,10 @@ public class PlotSquared {
|
||||
*
|
||||
* @return Plot area manager
|
||||
*/
|
||||
@Nonnull public PlotAreaManager getPlotAreaManager() {
|
||||
public @NonNull PlotAreaManager getPlotAreaManager() {
|
||||
return this.platform.injector().getInstance(PlotAreaManager.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of PlotSquared.
|
||||
*
|
||||
* @return instance of PlotSquared
|
||||
*/
|
||||
public static PlotSquared get() {
|
||||
return PlotSquared.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform specific implementation of PlotSquared
|
||||
*
|
||||
* @return Platform implementation
|
||||
*/
|
||||
@Nonnull public static PlotPlatform<?> platform() {
|
||||
if (instance != null && instance.platform != null) {
|
||||
return instance.platform;
|
||||
}
|
||||
throw new IllegalStateException("Plot platform implementation is missing");
|
||||
}
|
||||
|
||||
public void startExpiryTasks() {
|
||||
if (Settings.Enabled_Components.PLOT_EXPIRY) {
|
||||
ExpireManager.IMP = new ExpireManager(this.eventDispatcher);
|
||||
@ -290,7 +303,7 @@ public class PlotSquared {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMainThread(Thread thread) {
|
||||
public boolean isMainThread(final @NonNull Thread thread) {
|
||||
return this.thread == thread;
|
||||
}
|
||||
|
||||
@ -301,9 +314,12 @@ public class PlotSquared {
|
||||
* @param version2 Second version
|
||||
* @return true if `version` is >= `version2`
|
||||
*/
|
||||
public boolean checkVersion(int[] version, int... version2) {
|
||||
public boolean checkVersion(
|
||||
final int[] version,
|
||||
final int... version2
|
||||
) {
|
||||
return version[0] > version2[0] || version[0] == version2[0] && version[1] > version2[1]
|
||||
|| version[0] == version2[0] && version[1] == version2[1] && version[2] >= version2[2];
|
||||
|| version[0] == version2[0] && version[1] == version2[1] && version[2] >= version2[2];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,7 +327,7 @@ public class PlotSquared {
|
||||
*
|
||||
* @return current version in config or null
|
||||
*/
|
||||
public PlotVersion getVersion() {
|
||||
public @NonNull PlotVersion getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@ -322,7 +338,7 @@ public class PlotSquared {
|
||||
*
|
||||
* @return the server implementation
|
||||
*/
|
||||
public String getPlatform() {
|
||||
public @NonNull String getPlatform() {
|
||||
return Settings.PLATFORM;
|
||||
}
|
||||
|
||||
@ -332,7 +348,7 @@ public class PlotSquared {
|
||||
* @param plotArea the {@code PlotArea} to add.
|
||||
* @see #removePlotArea(PlotArea) To remove the reference
|
||||
*/
|
||||
public void addPlotArea(PlotArea plotArea) {
|
||||
public void addPlotArea(final @NonNull PlotArea plotArea) {
|
||||
HashMap<PlotId, Plot> plots;
|
||||
if (plots_tmp == null || (plots = plots_tmp.remove(plotArea.toString())) == null) {
|
||||
if (plotArea.getType() == PlotAreaType.PARTIAL) {
|
||||
@ -358,8 +374,8 @@ public class PlotSquared {
|
||||
if (clustersTmp == null || (clusters = clustersTmp.remove(plotArea.toString())) == null) {
|
||||
if (plotArea.getType() == PlotAreaType.PARTIAL) {
|
||||
clusters = this.clustersTmp != null ?
|
||||
this.clustersTmp.get(plotArea.getWorldName()) :
|
||||
null;
|
||||
this.clustersTmp.get(plotArea.getWorldName()) :
|
||||
null;
|
||||
if (clusters != null) {
|
||||
Iterator<PlotCluster> iterator = clusters.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
@ -382,8 +398,8 @@ public class PlotSquared {
|
||||
return;
|
||||
}
|
||||
File file = new File(
|
||||
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId()
|
||||
+ "_" + plotArea.getWorldName());
|
||||
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId()
|
||||
+ "_" + plotArea.getWorldName());
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
@ -397,7 +413,11 @@ public class PlotSquared {
|
||||
regionInts.forEach(l -> regions.add(BlockVector2.at(l[0], l[1])));
|
||||
chunkInts.forEach(l -> chunks.add(BlockVector2.at(l[0], l[1])));
|
||||
int height = (int) list.get(2);
|
||||
logger.info("Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height);
|
||||
logger.info(
|
||||
"Incomplete road regeneration found. Restarting in world {} with height {}",
|
||||
plotArea.getWorldName(),
|
||||
height
|
||||
);
|
||||
logger.info(" - Regions: {}", regions.size());
|
||||
logger.info(" - Chunks: {}", chunks.size());
|
||||
HybridUtils.UPDATE = true;
|
||||
@ -417,12 +437,12 @@ public class PlotSquared {
|
||||
*
|
||||
* @param area the {@code PlotArea} to remove
|
||||
*/
|
||||
public void removePlotArea(PlotArea area) {
|
||||
public void removePlotArea(final @NonNull PlotArea area) {
|
||||
getPlotAreaManager().removePlotArea(area);
|
||||
setPlotsTmp(area);
|
||||
}
|
||||
|
||||
public void removePlotAreas(@Nonnull final String world) {
|
||||
public void removePlotAreas(final @NonNull String world) {
|
||||
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
|
||||
if (area.getWorldName().equals(world)) {
|
||||
removePlotArea(area);
|
||||
@ -430,12 +450,12 @@ public class PlotSquared {
|
||||
}
|
||||
}
|
||||
|
||||
private void setPlotsTmp(PlotArea area) {
|
||||
private void setPlotsTmp(final @NonNull PlotArea area) {
|
||||
if (this.plots_tmp == null) {
|
||||
this.plots_tmp = new HashMap<>();
|
||||
}
|
||||
HashMap<PlotId, Plot> map =
|
||||
this.plots_tmp.computeIfAbsent(area.toString(), k -> new HashMap<>());
|
||||
this.plots_tmp.computeIfAbsent(area.toString(), k -> new HashMap<>());
|
||||
for (Plot plot : area.getPlots()) {
|
||||
map.put(plot.getId(), plot);
|
||||
}
|
||||
@ -445,7 +465,7 @@ public class PlotSquared {
|
||||
this.clustersTmp.put(area.toString(), area.getClusters());
|
||||
}
|
||||
|
||||
public Set<PlotCluster> getClusters(@Nonnull final String world) {
|
||||
public Set<PlotCluster> getClusters(final @NonNull String world) {
|
||||
final Set<PlotCluster> set = new HashSet<>();
|
||||
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
|
||||
set.addAll(area.getClusters());
|
||||
@ -542,7 +562,7 @@ public class PlotSquared {
|
||||
*
|
||||
* @param input an array of plots to sort
|
||||
*/
|
||||
private void sortPlotsByHash(Plot[] input) {
|
||||
private void sortPlotsByHash(final @NonNull Plot @NonNull[] input) {
|
||||
List<Plot>[] bucket = new ArrayList[32];
|
||||
Arrays.fill(bucket, new ArrayList<>());
|
||||
boolean maxLength = false;
|
||||
@ -567,11 +587,11 @@ public class PlotSquared {
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<Plot> sortPlotsByTimestamp(Collection<Plot> plots) {
|
||||
private @NonNull List<Plot> sortPlotsByTimestamp(final @NonNull Collection<Plot> plots) {
|
||||
int hardMax = 256000;
|
||||
int max = 0;
|
||||
int overflowSize = 0;
|
||||
for (Plot plot : plots) {
|
||||
for (final Plot plot : plots) {
|
||||
int hash = MathMan.getPositiveId(plot.hashCode());
|
||||
if (hash > max) {
|
||||
if (hash >= hardMax) {
|
||||
@ -615,10 +635,10 @@ public class PlotSquared {
|
||||
/**
|
||||
* Sort plots by creation timestamp.
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
* @param input Plots to sort
|
||||
* @return Sorted list
|
||||
*/
|
||||
private List<Plot> sortPlotsByModified(Collection<Plot> input) {
|
||||
private @NonNull List<Plot> sortPlotsByModified(final @NonNull Collection<Plot> input) {
|
||||
List<Plot> list;
|
||||
if (input instanceof List) {
|
||||
list = (List<Plot>) input;
|
||||
@ -639,8 +659,11 @@ public class PlotSquared {
|
||||
* want default world order
|
||||
* @return ArrayList of plot
|
||||
*/
|
||||
public ArrayList<Plot> sortPlots(Collection<Plot> plots, SortType type,
|
||||
final PlotArea priorityArea) {
|
||||
public @NonNull List<Plot> sortPlots(
|
||||
final @NonNull Collection<Plot> plots,
|
||||
final @NonNull SortType type,
|
||||
final @Nullable PlotArea priorityArea
|
||||
) {
|
||||
// group by world
|
||||
// sort each
|
||||
HashMap<PlotArea, Collection<Plot>> map = new HashMap<>();
|
||||
@ -698,7 +721,7 @@ public class PlotSquared {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public void setPlots(@Nonnull final Map<String, HashMap<PlotId, Plot>> plots) {
|
||||
public void setPlots(final @NonNull Map<String, HashMap<PlotId, Plot>> plots) {
|
||||
if (this.plots_tmp == null) {
|
||||
this.plots_tmp = new HashMap<>();
|
||||
}
|
||||
@ -724,7 +747,10 @@ public class PlotSquared {
|
||||
* @param callEvent If to call an event about the plot being removed
|
||||
* @return true if plot existed | false if it didn't
|
||||
*/
|
||||
public boolean removePlot(Plot plot, boolean callEvent) {
|
||||
public boolean removePlot(
|
||||
final @NonNull Plot plot,
|
||||
final boolean callEvent
|
||||
) {
|
||||
if (plot == null) {
|
||||
return false;
|
||||
}
|
||||
@ -761,7 +787,10 @@ public class PlotSquared {
|
||||
* @param world the world to load
|
||||
* @param baseGenerator The generator for that world, or null
|
||||
*/
|
||||
public void loadWorld(String world, GeneratorWrapper<?> baseGenerator) {
|
||||
public void loadWorld(
|
||||
final @NonNull String world,
|
||||
final @Nullable GeneratorWrapper<?> baseGenerator
|
||||
) {
|
||||
if (world.equals("CheckingPlotSquaredGenerator")) {
|
||||
return;
|
||||
}
|
||||
@ -790,13 +819,13 @@ public class PlotSquared {
|
||||
} else if (worldSection != null) {
|
||||
String secondaryGeneratorName = worldSection.getString("generator.plugin");
|
||||
GeneratorWrapper<?> secondaryGenerator =
|
||||
this.platform.getGenerator(world, secondaryGeneratorName);
|
||||
this.platform.getGenerator(world, secondaryGeneratorName);
|
||||
if (secondaryGenerator != null && secondaryGenerator.isFull()) {
|
||||
plotGenerator = secondaryGenerator.getPlotGenerator();
|
||||
} else {
|
||||
String primaryGeneratorName = worldSection.getString("generator.init");
|
||||
GeneratorWrapper<?> primaryGenerator =
|
||||
this.platform.getGenerator(world, primaryGeneratorName);
|
||||
this.platform.getGenerator(world, primaryGeneratorName);
|
||||
if (primaryGenerator != null && primaryGenerator.isFull()) {
|
||||
plotGenerator = primaryGenerator.getPlotGenerator();
|
||||
} else {
|
||||
@ -840,7 +869,7 @@ public class PlotSquared {
|
||||
String gen_string = worldSection.getString("generator.plugin", platform.pluginName());
|
||||
if (type == PlotAreaType.PARTIAL) {
|
||||
Set<PlotCluster> clusters =
|
||||
this.clustersTmp != null ? this.clustersTmp.get(world) : new HashSet<>();
|
||||
this.clustersTmp != null ? this.clustersTmp.get(world) : new HashSet<>();
|
||||
if (clusters == null) {
|
||||
throw new IllegalArgumentException("No cluster exists for world: " + world);
|
||||
}
|
||||
@ -858,7 +887,7 @@ public class PlotSquared {
|
||||
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
|
||||
}
|
||||
PlotArea pa =
|
||||
areaGen.getPlotGenerator().getNewPlotArea(world, name, pos1, pos2);
|
||||
areaGen.getPlotGenerator().getNewPlotArea(world, name, pos1, pos2);
|
||||
pa.saveConfiguration(worldSection);
|
||||
pa.loadDefaultConfiguration(worldSection);
|
||||
try {
|
||||
@ -901,22 +930,22 @@ public class PlotSquared {
|
||||
}
|
||||
if (type == PlotAreaType.AUGMENTED) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid type for multi-area world. Expected `PARTIAL`, got `"
|
||||
+ PlotAreaType.AUGMENTED + "`");
|
||||
"Invalid type for multi-area world. Expected `PARTIAL`, got `"
|
||||
+ PlotAreaType.AUGMENTED + "`");
|
||||
}
|
||||
for (String areaId : areasSection.getKeys(false)) {
|
||||
logger.info(" - {}", areaId);
|
||||
String[] split = areaId.split("(?<=[^;-])-");
|
||||
if (split.length != 3) {
|
||||
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
|
||||
+ ". Expected form `<name>-<pos1>-<pos2>`");
|
||||
+ ". Expected form `<name>-<pos1>-<pos2>`");
|
||||
}
|
||||
String name = split[0];
|
||||
PlotId pos1 = PlotId.fromString(split[1]);
|
||||
PlotId pos2 = PlotId.fromString(split[2]);
|
||||
if (name.isEmpty()) {
|
||||
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
|
||||
+ ". Expected form `<name>-<x1;z1>-<x2;z2>`");
|
||||
+ ". Expected form `<name>-<x1;z1>-<x2;z2>`");
|
||||
}
|
||||
final PlotArea existing = this.getPlotAreaManager().getPlotArea(world, name);
|
||||
if (existing != null && name.equals(existing.getId())) {
|
||||
@ -989,18 +1018,23 @@ public class PlotSquared {
|
||||
* @param generator the plot generator
|
||||
* @return boolean | if valid arguments were provided
|
||||
*/
|
||||
public boolean setupPlotWorld(String world, String args, IndependentPlotGenerator generator) {
|
||||
public boolean setupPlotWorld(
|
||||
final @NonNull String world,
|
||||
final @Nullable String args,
|
||||
final @NonNull IndependentPlotGenerator generator
|
||||
) {
|
||||
if (args != null && !args.isEmpty()) {
|
||||
// save configuration
|
||||
|
||||
final List<String> validArguments = Arrays
|
||||
.asList("s=", "size=", "g=", "gap=", "h=", "height=", "f=", "floor=", "m=", "main=",
|
||||
"w=", "wall=", "b=", "border=");
|
||||
.asList("s=", "size=", "g=", "gap=", "h=", "height=", "f=", "floor=", "m=", "main=",
|
||||
"w=", "wall=", "b=", "border="
|
||||
);
|
||||
|
||||
// Calculate the number of expected arguments
|
||||
int expected = (int) validArguments.stream()
|
||||
.filter(validArgument -> args.toLowerCase(Locale.ENGLISH).contains(validArgument))
|
||||
.count();
|
||||
.filter(validArgument -> args.toLowerCase(Locale.ENGLISH).contains(validArgument))
|
||||
.count();
|
||||
|
||||
String[] split = args.toLowerCase(Locale.ENGLISH).split(",(?![^\\(\\[]*[\\]\\)])");
|
||||
|
||||
@ -1035,7 +1069,9 @@ public class PlotSquared {
|
||||
split = combinedArgs;
|
||||
}
|
||||
|
||||
final HybridPlotWorldFactory hybridPlotWorldFactory = this.platform.injector().getInstance(HybridPlotWorldFactory.class);
|
||||
final HybridPlotWorldFactory hybridPlotWorldFactory = this.platform
|
||||
.injector()
|
||||
.getInstance(HybridPlotWorldFactory.class);
|
||||
final HybridPlotWorld plotWorld = hybridPlotWorldFactory.create(world, null, generator, null, null);
|
||||
|
||||
for (String element : split) {
|
||||
@ -1051,42 +1087,60 @@ public class PlotSquared {
|
||||
switch (key) {
|
||||
case "s":
|
||||
case "size":
|
||||
this.worldConfiguration.set(base + "plot.size",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
||||
this.worldConfiguration.set(
|
||||
base + "plot.size",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||
);
|
||||
break;
|
||||
case "g":
|
||||
case "gap":
|
||||
this.worldConfiguration.set(base + "road.width",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
||||
this.worldConfiguration.set(
|
||||
base + "road.width",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||
);
|
||||
break;
|
||||
case "h":
|
||||
case "height":
|
||||
this.worldConfiguration.set(base + "road.height",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
||||
this.worldConfiguration.set(base + "plot.height",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
||||
this.worldConfiguration.set(base + "wall.height",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
||||
this.worldConfiguration.set(
|
||||
base + "road.height",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||
);
|
||||
this.worldConfiguration.set(
|
||||
base + "plot.height",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||
);
|
||||
this.worldConfiguration.set(
|
||||
base + "wall.height",
|
||||
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||
);
|
||||
break;
|
||||
case "f":
|
||||
case "floor":
|
||||
this.worldConfiguration.set(base + "plot.floor",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
||||
this.worldConfiguration.set(
|
||||
base + "plot.floor",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||
);
|
||||
break;
|
||||
case "m":
|
||||
case "main":
|
||||
this.worldConfiguration.set(base + "plot.filling",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
||||
this.worldConfiguration.set(
|
||||
base + "plot.filling",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||
);
|
||||
break;
|
||||
case "w":
|
||||
case "wall":
|
||||
this.worldConfiguration.set(base + "wall.filling",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
||||
this.worldConfiguration.set(
|
||||
base + "wall.filling",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||
);
|
||||
break;
|
||||
case "b":
|
||||
case "border":
|
||||
this.worldConfiguration.set(base + "wall.block",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
||||
this.worldConfiguration.set(
|
||||
base + "wall.block",
|
||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||
);
|
||||
break;
|
||||
default:
|
||||
logger.error("Key not found: {}", element);
|
||||
@ -1100,7 +1154,7 @@ public class PlotSquared {
|
||||
}
|
||||
try {
|
||||
ConfigurationSection section =
|
||||
this.worldConfiguration.getConfigurationSection("worlds." + world);
|
||||
this.worldConfiguration.getConfigurationSection("worlds." + world);
|
||||
plotWorld.saveConfiguration(section);
|
||||
plotWorld.loadDefaultConfiguration(section);
|
||||
this.worldConfiguration.save(this.worldsFile);
|
||||
@ -1117,7 +1171,10 @@ public class PlotSquared {
|
||||
* @param file Name of the file inside PlotSquared.jar
|
||||
* @param folder The output location relative to /plugins/PlotSquared/
|
||||
*/
|
||||
public void copyFile(String file, String folder) {
|
||||
public void copyFile(
|
||||
final @NonNull String file,
|
||||
final @NonNull String folder
|
||||
) {
|
||||
try {
|
||||
File output = this.platform.getDirectory();
|
||||
if (!output.exists()) {
|
||||
@ -1131,7 +1188,7 @@ public class PlotSquared {
|
||||
byte[] buffer = new byte[2048];
|
||||
if (stream == null) {
|
||||
try (ZipInputStream zis = new ZipInputStream(
|
||||
new FileInputStream(this.jarFile))) {
|
||||
new FileInputStream(this.jarFile))) {
|
||||
ZipEntry ze = zis.getNextEntry();
|
||||
while (ze != null) {
|
||||
String name = ze.getName();
|
||||
@ -1194,7 +1251,7 @@ public class PlotSquared {
|
||||
*/
|
||||
private void checkRoadRegenPersistence() {
|
||||
if (!HybridUtils.UPDATE || !Settings.Enabled_Components.PERSISTENT_ROAD_REGEN || (
|
||||
HybridUtils.regions.isEmpty() && HybridUtils.chunks.isEmpty())) {
|
||||
HybridUtils.regions.isEmpty() && HybridUtils.chunks.isEmpty())) {
|
||||
return;
|
||||
}
|
||||
logger.info("Road regeneration incomplete. Saving incomplete regions to disk");
|
||||
@ -1203,24 +1260,24 @@ public class PlotSquared {
|
||||
ArrayList<int[]> regions = new ArrayList<>();
|
||||
ArrayList<int[]> chunks = new ArrayList<>();
|
||||
for (BlockVector2 r : HybridUtils.regions) {
|
||||
regions.add(new int[] {r.getBlockX(), r.getBlockZ()});
|
||||
regions.add(new int[]{r.getBlockX(), r.getBlockZ()});
|
||||
}
|
||||
for (BlockVector2 c : HybridUtils.chunks) {
|
||||
chunks.add(new int[] {c.getBlockX(), c.getBlockZ()});
|
||||
chunks.add(new int[]{c.getBlockX(), c.getBlockZ()});
|
||||
}
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.add(regions);
|
||||
list.add(chunks);
|
||||
list.add(HybridUtils.height);
|
||||
File file = new File(
|
||||
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area
|
||||
.getId() + "_" + HybridUtils.area.getWorldName());
|
||||
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area
|
||||
.getId() + "_" + HybridUtils.area.getWorldName());
|
||||
if (file.exists() && !file.delete()) {
|
||||
logger.error("persistent_regene_data file already exists and could not be deleted");
|
||||
return;
|
||||
}
|
||||
try (ObjectOutputStream oos = new ObjectOutputStream(
|
||||
Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE_NEW))) {
|
||||
Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE_NEW))) {
|
||||
oos.writeObject(list);
|
||||
} catch (IOException e) {
|
||||
logger.error("Error creating persistent_region_data file", e);
|
||||
@ -1238,7 +1295,8 @@ public class PlotSquared {
|
||||
Database database;
|
||||
if (Storage.MySQL.USE) {
|
||||
database = new MySQL(Storage.MySQL.HOST, Storage.MySQL.PORT, Storage.MySQL.DATABASE,
|
||||
Storage.MySQL.USER, Storage.MySQL.PASSWORD);
|
||||
Storage.MySQL.USER, Storage.MySQL.PASSWORD
|
||||
);
|
||||
} else if (Storage.SQLite.USE) {
|
||||
File file = FileUtils.getFile(platform.getDirectory(), Storage.SQLite.DB + ".db");
|
||||
database = new SQLite(file);
|
||||
@ -1247,7 +1305,13 @@ public class PlotSquared {
|
||||
this.platform.shutdown(); //shutdown used instead of disable because no database is set
|
||||
return;
|
||||
}
|
||||
DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, this.eventDispatcher, this.plotListener, this.worldConfiguration);
|
||||
DBFunc.dbManager = new SQLManager(
|
||||
database,
|
||||
Storage.PREFIX,
|
||||
this.eventDispatcher,
|
||||
this.plotListener,
|
||||
this.worldConfiguration
|
||||
);
|
||||
this.plots_tmp = DBFunc.getPlots();
|
||||
if (getPlotAreaManager() instanceof SinglePlotAreaManager) {
|
||||
SinglePlotArea area = ((SinglePlotAreaManager) getPlotAreaManager()).getArea();
|
||||
@ -1261,32 +1325,35 @@ public class PlotSquared {
|
||||
}
|
||||
this.clustersTmp = DBFunc.getClusters();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
logger.error("Failed to open database connection ({}). Disabling PlotSquared", Storage.MySQL.USE ? "MySQL" : "SQLite");
|
||||
logger.error(
|
||||
"Failed to open database connection ({}). Disabling PlotSquared",
|
||||
Storage.MySQL.USE ? "MySQL" : "SQLite"
|
||||
);
|
||||
logger.error("==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||
e.printStackTrace();
|
||||
logger.error("==== End of stacktrace ====");
|
||||
logger.error("Please go to the {} 'storage.yml' and configure the database correctly",
|
||||
platform.pluginName());
|
||||
logger.error(
|
||||
"Please go to the {} 'storage.yml' and configure the database correctly",
|
||||
platform.pluginName()
|
||||
);
|
||||
this.platform.shutdown(); //shutdown used instead of disable because of database error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the default configuration.
|
||||
*
|
||||
* @throws IOException if the config failed to save
|
||||
*/
|
||||
public void setupConfig() throws IOException {
|
||||
public void setupConfig() {
|
||||
String lastVersionString = this.getConfig().getString("version");
|
||||
if (lastVersionString != null) {
|
||||
String[] split = lastVersionString.split("\\.");
|
||||
int[] lastVersion = new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1]),
|
||||
Integer.parseInt(split[2])};
|
||||
if (checkVersion(new int[] {3, 4, 0}, lastVersion)) {
|
||||
int[] lastVersion = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]),
|
||||
Integer.parseInt(split[2])};
|
||||
if (checkVersion(new int[]{3, 4, 0}, lastVersion)) {
|
||||
Settings.convertLegacy(configFile);
|
||||
if (getConfig().contains("worlds")) {
|
||||
ConfigurationSection worldSection =
|
||||
getConfig().getConfigurationSection("worlds");
|
||||
getConfig().getConfigurationSection("worlds");
|
||||
worldConfiguration.set("worlds", worldSection);
|
||||
try {
|
||||
worldConfiguration.save(worldsFile);
|
||||
@ -1335,22 +1402,23 @@ public class PlotSquared {
|
||||
|
||||
if (this.worldConfiguration.contains("worlds")) {
|
||||
if (!this.worldConfiguration.contains("configuration_version") || (
|
||||
!this.worldConfiguration.getString("configuration_version")
|
||||
.equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worldConfiguration
|
||||
.getString("configuration_version").equalsIgnoreCase("v5"))) {
|
||||
!this.worldConfiguration.getString("configuration_version")
|
||||
.equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worldConfiguration
|
||||
.getString("configuration_version").equalsIgnoreCase("v5"))) {
|
||||
// Conversion needed
|
||||
logger.info("A legacy configuration file was detected. Conversion will be attempted.");
|
||||
try {
|
||||
com.google.common.io.Files
|
||||
.copy(this.worldsFile, new File(folder, "worlds.yml.old"));
|
||||
.copy(this.worldsFile, new File(folder, "worlds.yml.old"));
|
||||
logger.info("A copy of worlds.yml has been saved in the file worlds.yml.old");
|
||||
final ConfigurationSection worlds =
|
||||
this.worldConfiguration.getConfigurationSection("worlds");
|
||||
this.worldConfiguration.getConfigurationSection("worlds");
|
||||
final LegacyConverter converter = new LegacyConverter(worlds);
|
||||
converter.convert();
|
||||
this.worldConfiguration.set("worlds", worlds);
|
||||
this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION);
|
||||
logger.info("The conversion has finished. PlotSquared will now be disabled and the new configuration file will be used at next startup. Please review the new worlds.yml file. Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. You need to re-generate the schematics.");
|
||||
logger.info(
|
||||
"The conversion has finished. PlotSquared will now be disabled and the new configuration file will be used at next startup. Please review the new worlds.yml file. Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. You need to re-generate the schematics.");
|
||||
} catch (final Exception e) {
|
||||
logger.error("Failed to convert the legacy configuration file. See stack trace for information.", e);
|
||||
}
|
||||
@ -1387,12 +1455,12 @@ public class PlotSquared {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getConfigurationVersion() {
|
||||
public @NonNull String getConfigurationVersion() {
|
||||
return this.worldConfiguration.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION)
|
||||
.toString();
|
||||
.toString();
|
||||
}
|
||||
|
||||
public void setConfigurationVersion(final String newVersion) throws IOException {
|
||||
public void setConfigurationVersion(final @NonNull String newVersion) throws IOException {
|
||||
this.worldConfiguration.set("configuration_version", newVersion);
|
||||
this.worldConfiguration.save(this.worldsFile);
|
||||
}
|
||||
@ -1418,7 +1486,7 @@ public class PlotSquared {
|
||||
}
|
||||
}
|
||||
|
||||
public void forEachPlotRaw(Consumer<Plot> consumer) {
|
||||
public void forEachPlotRaw(final @NonNull Consumer<Plot> consumer) {
|
||||
for (final PlotArea area : this.getPlotAreaManager().getAllPlotAreas()) {
|
||||
area.getPlots().forEach(consumer);
|
||||
}
|
||||
@ -1436,8 +1504,10 @@ public class PlotSquared {
|
||||
* @param chunkCoordinates Chunk coordinates
|
||||
* @return True if the chunk uses non-standard generation, false if not
|
||||
*/
|
||||
public boolean isNonStandardGeneration(@Nonnull final String world,
|
||||
@Nonnull final BlockVector2 chunkCoordinates) {
|
||||
public boolean isNonStandardGeneration(
|
||||
final @NonNull String world,
|
||||
final @NonNull BlockVector2 chunkCoordinates
|
||||
) {
|
||||
final Location location = Location.at(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
|
||||
final PlotArea area = getPlotAreaManager().getApplicablePlotArea(location);
|
||||
if (area == null) {
|
||||
@ -1446,31 +1516,31 @@ public class PlotSquared {
|
||||
return area.getTerrain() != PlotAreaTerrainType.NONE;
|
||||
}
|
||||
|
||||
public YamlConfiguration getConfig() {
|
||||
public @NonNull YamlConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public UUIDPipeline getImpromptuUUIDPipeline() {
|
||||
public @NonNull UUIDPipeline getImpromptuUUIDPipeline() {
|
||||
return this.impromptuUUIDPipeline;
|
||||
}
|
||||
|
||||
public UUIDPipeline getBackgroundUUIDPipeline() {
|
||||
public @NonNull UUIDPipeline getBackgroundUUIDPipeline() {
|
||||
return this.backgroundUUIDPipeline;
|
||||
}
|
||||
|
||||
public WorldEdit getWorldEdit() {
|
||||
public @NonNull WorldEdit getWorldEdit() {
|
||||
return this.worldedit;
|
||||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
public @NonNull File getConfigFile() {
|
||||
return this.configFile;
|
||||
}
|
||||
|
||||
public File getWorldsFile() {
|
||||
public @NonNull File getWorldsFile() {
|
||||
return this.worldsFile;
|
||||
}
|
||||
|
||||
public YamlConfiguration getWorldConfiguration() {
|
||||
public @NonNull YamlConfiguration getWorldConfiguration() {
|
||||
return this.worldConfiguration;
|
||||
}
|
||||
|
||||
@ -1482,33 +1552,42 @@ public class PlotSquared {
|
||||
* @return Map instance
|
||||
* @see #registerCaptionMap(String, CaptionMap) To register a caption map
|
||||
*/
|
||||
@Nonnull public CaptionMap getCaptionMap(@Nonnull final String namespace) {
|
||||
return this.captionMaps.computeIfAbsent(namespace.toLowerCase(Locale.ENGLISH),
|
||||
missingNamespace -> new DummyCaptionMap());
|
||||
public @NonNull CaptionMap getCaptionMap(final @NonNull String namespace) {
|
||||
return this.captionMaps.computeIfAbsent(
|
||||
namespace.toLowerCase(Locale.ENGLISH),
|
||||
missingNamespace -> new DummyCaptionMap()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a caption map
|
||||
*
|
||||
* @param namespace Namespace
|
||||
* @param namespace Namespace
|
||||
* @param captionMap Map instance
|
||||
*/
|
||||
public void registerCaptionMap(@Nonnull final String namespace, @Nonnull final CaptionMap captionMap) {
|
||||
public void registerCaptionMap(
|
||||
final @NonNull String namespace,
|
||||
final @NonNull CaptionMap captionMap
|
||||
) {
|
||||
if (namespace.equalsIgnoreCase(TranslatableCaption.DEFAULT_NAMESPACE)) {
|
||||
throw new IllegalArgumentException("Cannot replace default caption map");
|
||||
}
|
||||
this.captionMaps.put(namespace.toLowerCase(Locale.ENGLISH), captionMap);
|
||||
}
|
||||
|
||||
public EventDispatcher getEventDispatcher() {
|
||||
public @NonNull EventDispatcher getEventDispatcher() {
|
||||
return this.eventDispatcher;
|
||||
}
|
||||
|
||||
public PlotListener getPlotListener() {
|
||||
public @NonNull PlotListener getPlotListener() {
|
||||
return this.plotListener;
|
||||
}
|
||||
|
||||
public enum SortType {
|
||||
CREATION_DATE, CREATION_DATE_TIMESTAMP, LAST_MODIFIED, DISTANCE_FROM_ORIGIN
|
||||
CREATION_DATE,
|
||||
CREATION_DATE_TIMESTAMP,
|
||||
LAST_MODIFIED,
|
||||
DISTANCE_FROM_ORIGIN
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,13 +25,23 @@
|
||||
*/
|
||||
package com.plotsquared.core;
|
||||
|
||||
public class PlotVersion {
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class PlotVersion {
|
||||
|
||||
public final int year, month, day, hash;
|
||||
public final String versionString;
|
||||
public final int[] version;
|
||||
public final String suffix;
|
||||
|
||||
public PlotVersion(int year, int month, int day, int hash, String versionString) {
|
||||
public PlotVersion(
|
||||
final int year,
|
||||
final int month,
|
||||
final int day,
|
||||
final int hash,
|
||||
final String rawVersion
|
||||
) {
|
||||
String versionString = rawVersion;
|
||||
this.year = year;
|
||||
this.month = month;
|
||||
this.day = day;
|
||||
@ -51,7 +61,12 @@ public class PlotVersion {
|
||||
version[2] = verArray.length > 2 ? Integer.parseInt(verArray[2]) : 0;
|
||||
}
|
||||
|
||||
public PlotVersion(String versionString, String commit, String date) {
|
||||
public PlotVersion(
|
||||
final String rawVersion,
|
||||
final String commit,
|
||||
final String date
|
||||
) {
|
||||
String versionString = rawVersion;
|
||||
int dash = versionString.indexOf('-');
|
||||
if (dash != -1) {
|
||||
suffix = versionString.substring(dash);
|
||||
@ -73,7 +88,11 @@ public class PlotVersion {
|
||||
this.day = Integer.parseInt(split1[2]);
|
||||
}
|
||||
|
||||
public static PlotVersion tryParse(String versionString, String commit, String date) {
|
||||
public static @NonNull PlotVersion tryParse(
|
||||
final @NonNull String versionString,
|
||||
final @NonNull String commit,
|
||||
final @NonNull String date
|
||||
) {
|
||||
try {
|
||||
return new PlotVersion(versionString, commit, date);
|
||||
} catch (Exception e) {
|
||||
@ -82,7 +101,7 @@ public class PlotVersion {
|
||||
}
|
||||
}
|
||||
|
||||
public String versionString() {
|
||||
public @NonNull String versionString() {
|
||||
if (hash == 0 && versionString == null) {
|
||||
return "NoVer-SNAPSHOT";
|
||||
} else {
|
||||
@ -90,7 +109,8 @@ public class PlotVersion {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (hash == 0 && versionString == null) {
|
||||
return "PlotSquared-NoVer-SNAPSHOT";
|
||||
} else {
|
||||
@ -104,10 +124,10 @@ public class PlotVersion {
|
||||
* @param versionString the version to compare
|
||||
* @return true if the given version is a "later" version
|
||||
*/
|
||||
public boolean isLaterVersion(String versionString) {
|
||||
public boolean isLaterVersion(final @NonNull String versionString) {
|
||||
int dash = versionString.indexOf('-');
|
||||
String[] verArray =
|
||||
versionString.substring(0, dash == -1 ? versionString.length() : dash).split("\\.");
|
||||
versionString.substring(0, dash == -1 ? versionString.length() : dash).split("\\.");
|
||||
int one = Integer.parseInt(verArray[0]);
|
||||
int two = Integer.parseInt(verArray[1]);
|
||||
int three = Integer.parseInt(verArray[2]);
|
||||
@ -133,9 +153,8 @@ public class PlotVersion {
|
||||
return true;
|
||||
} else {
|
||||
return verArray[0] == version[0] && verArray[1] == version[1]
|
||||
&& verArray[2] > version[2];
|
||||
&& verArray[2] > version[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,8 @@
|
||||
*/
|
||||
package com.plotsquared.core.backup;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -38,7 +39,8 @@ public class Backup {
|
||||
|
||||
private final BackupProfile owner;
|
||||
private final long creationTime;
|
||||
@Nullable private final Path file;
|
||||
@Nullable
|
||||
private final Path file;
|
||||
|
||||
Backup(final BackupProfile owner, final long creationTime, final Path file) {
|
||||
this.owner = owner;
|
||||
@ -67,7 +69,8 @@ public class Backup {
|
||||
return this.creationTime;
|
||||
}
|
||||
|
||||
@Nullable public Path getFile() {
|
||||
public @Nullable Path getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ package com.plotsquared.core.backup;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -45,7 +45,7 @@ public interface BackupManager {
|
||||
* @param plot Plot to perform the automatic backup on
|
||||
* @param whenDone Action that runs when the automatic backup has been completed
|
||||
*/
|
||||
static void backup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone) {
|
||||
static void backup(@Nullable PlotPlayer player, final @NonNull Plot plot, @NonNull Runnable whenDone) {
|
||||
Objects.requireNonNull(PlotSquared.platform()).backupManager().automaticBackup(player, plot, whenDone);
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ public interface BackupManager {
|
||||
* @param plot Plot to get the backup profile for
|
||||
* @return Backup profile
|
||||
*/
|
||||
@Nonnull BackupProfile getProfile(@Nonnull final Plot plot);
|
||||
@NonNull BackupProfile getProfile(final @NonNull Plot plot);
|
||||
|
||||
/**
|
||||
* This will perform an automatic backup of the plot iff the plot has an owner,
|
||||
@ -67,14 +67,14 @@ public interface BackupManager {
|
||||
* @param plot Plot to perform the automatic backup on
|
||||
* @param whenDone Action that runs when the automatic backup has been completed
|
||||
*/
|
||||
void automaticBackup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone);
|
||||
void automaticBackup(@Nullable PlotPlayer player, final @NonNull Plot plot, @NonNull Runnable whenDone);
|
||||
|
||||
/**
|
||||
* Get the directory in which backups are stored
|
||||
*
|
||||
* @return Backup directory path
|
||||
*/
|
||||
@Nonnull Path getBackupPath();
|
||||
@NonNull Path getBackupPath();
|
||||
|
||||
/**
|
||||
* Get the maximum amount of backups that may be stored for
|
||||
|
@ -26,9 +26,9 @@
|
||||
package com.plotsquared.core.backup;
|
||||
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -40,7 +40,7 @@ public interface BackupProfile {
|
||||
*
|
||||
* @return Future that will be completed with available backups
|
||||
*/
|
||||
@Nonnull CompletableFuture<List<Backup>> listBackups();
|
||||
@NonNull CompletableFuture<List<Backup>> listBackups();
|
||||
|
||||
/**
|
||||
* Remove all backups stored for this profile
|
||||
@ -53,7 +53,7 @@ public interface BackupProfile {
|
||||
*
|
||||
* @return Folder that contains the backups for this profile
|
||||
*/
|
||||
@Nonnull Path getBackupDirectory();
|
||||
@NonNull Path getBackupDirectory();
|
||||
|
||||
/**
|
||||
* Create a backup of the plot. If the profile is at the
|
||||
@ -61,7 +61,7 @@ public interface BackupProfile {
|
||||
*
|
||||
* @return Future that completes with the created backup.
|
||||
*/
|
||||
@Nonnull CompletableFuture<Backup> createBackup();
|
||||
@NonNull CompletableFuture<Backup> createBackup();
|
||||
|
||||
/**
|
||||
* Restore a backup
|
||||
@ -70,6 +70,6 @@ public interface BackupProfile {
|
||||
* @param player The player restoring the backup
|
||||
* @return Future that completes when the backup has finished
|
||||
*/
|
||||
@Nonnull CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player);
|
||||
@NonNull CompletableFuture<Void> restoreBackup(final @NonNull Backup backup, @Nullable PlotPlayer<?> player);
|
||||
|
||||
}
|
||||
|
@ -29,35 +29,43 @@ import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Singleton public class NullBackupManager implements BackupManager {
|
||||
@Singleton
|
||||
public class NullBackupManager implements BackupManager {
|
||||
|
||||
@Override @Nonnull public BackupProfile getProfile(@Nonnull Plot plot) {
|
||||
@Override
|
||||
public @NonNull BackupProfile getProfile(@NonNull Plot plot) {
|
||||
return new NullBackupProfile();
|
||||
}
|
||||
|
||||
@Override public void automaticBackup(@Nullable PlotPlayer plotPlayer,
|
||||
@Nonnull Plot plot, @Nonnull Runnable whenDone) {
|
||||
@Override
|
||||
public void automaticBackup(
|
||||
@Nullable PlotPlayer plotPlayer,
|
||||
@NonNull Plot plot, @NonNull Runnable whenDone
|
||||
) {
|
||||
whenDone.run();
|
||||
}
|
||||
|
||||
@Override @Nonnull public Path getBackupPath() {
|
||||
@Override
|
||||
public @NonNull Path getBackupPath() {
|
||||
return Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath();
|
||||
}
|
||||
|
||||
@Override public int getBackupLimit() {
|
||||
@Override
|
||||
public int getBackupLimit() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override public boolean shouldAutomaticallyBackup() {
|
||||
@Override
|
||||
public boolean shouldAutomaticallyBackup() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,9 @@
|
||||
package com.plotsquared.core.backup;
|
||||
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
@ -41,22 +41,27 @@ import java.util.concurrent.CompletableFuture;
|
||||
*/
|
||||
public class NullBackupProfile implements BackupProfile {
|
||||
|
||||
@Override @Nonnull public CompletableFuture<List<Backup>> listBackups() {
|
||||
@Override
|
||||
public @NonNull CompletableFuture<List<Backup>> listBackups() {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override public void destroy(){
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override @Nonnull public Path getBackupDirectory() {
|
||||
@Override
|
||||
public @NonNull Path getBackupDirectory() {
|
||||
return new File(".").toPath();
|
||||
}
|
||||
|
||||
@Override @Nonnull public CompletableFuture<Backup> createBackup() {
|
||||
@Override
|
||||
public @NonNull CompletableFuture<Backup> createBackup() {
|
||||
throw new UnsupportedOperationException("Cannot create backup of an unowned plot");
|
||||
}
|
||||
|
||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player) {
|
||||
@Override
|
||||
public @NonNull CompletableFuture<Void> restoreBackup(final @NonNull Backup backup, @Nullable PlotPlayer<?> player) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@ import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -64,24 +64,42 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
private final Plot plot;
|
||||
private final BackupManager backupManager;
|
||||
private final SchematicHandler schematicHandler;
|
||||
|
||||
@Inject public PlayerBackupProfile(@Assisted @Nonnull final UUID owner, @Assisted @Nonnull final Plot plot,
|
||||
@Nonnull final BackupManager backupManager, @Nonnull final SchematicHandler schematicHandler) {
|
||||
private final Object backupLock = new Object();
|
||||
private volatile List<Backup> backupCache;
|
||||
@Inject
|
||||
public PlayerBackupProfile(
|
||||
@Assisted final @NonNull UUID owner, @Assisted final @NonNull Plot plot,
|
||||
final @NonNull BackupManager backupManager, final @NonNull SchematicHandler schematicHandler
|
||||
) {
|
||||
this.owner = owner;
|
||||
this.plot = plot;
|
||||
this.backupManager = backupManager;
|
||||
this.schematicHandler = schematicHandler;
|
||||
}
|
||||
|
||||
private volatile List<Backup> backupCache;
|
||||
private final Object backupLock = new Object();
|
||||
|
||||
private static boolean isValidFile(@Nonnull final Path path) {
|
||||
private static boolean isValidFile(final @NonNull Path path) {
|
||||
final String name = path.getFileName().toString();
|
||||
return name.endsWith(".schem") || name.endsWith(".schematic");
|
||||
}
|
||||
|
||||
@Override @Nonnull public CompletableFuture<List<Backup>> listBackups() {
|
||||
private static Path resolve(final @NonNull Path parent, final String child) {
|
||||
Path path = parent;
|
||||
try {
|
||||
if (!Files.exists(parent)) {
|
||||
Files.createDirectory(parent);
|
||||
}
|
||||
path = parent.resolve(child);
|
||||
if (!Files.exists(path)) {
|
||||
Files.createDirectory(path);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<List<Backup>> listBackups() {
|
||||
synchronized (this.backupLock) {
|
||||
if (this.backupCache != null) {
|
||||
return CompletableFuture.completedFuture(backupCache);
|
||||
@ -101,9 +119,9 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
Files.walk(path).filter(PlayerBackupProfile::isValidFile).forEach(file -> {
|
||||
try {
|
||||
final BasicFileAttributes basicFileAttributes =
|
||||
Files.readAttributes(file, BasicFileAttributes.class);
|
||||
Files.readAttributes(file, BasicFileAttributes.class);
|
||||
backups.add(
|
||||
new Backup(this, basicFileAttributes.creationTime().toMillis(), file));
|
||||
new Backup(this, basicFileAttributes.creationTime().toMillis(), file));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -117,38 +135,26 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void destroy() {
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.listBackups().whenCompleteAsync((backups, error) -> {
|
||||
if (error != null) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
backups.forEach(Backup::delete);
|
||||
this.backupCache = null;
|
||||
if (error != null) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
backups.forEach(Backup::delete);
|
||||
this.backupCache = null;
|
||||
});
|
||||
}
|
||||
|
||||
@Nonnull public Path getBackupDirectory() {
|
||||
return resolve(resolve(resolve(backupManager.getBackupPath(), Objects.requireNonNull(plot.getArea().toString(), "plot area id")),
|
||||
Objects.requireNonNull(plot.getId().toDashSeparatedString(), "plot id")), Objects.requireNonNull(owner.toString(), "owner"));
|
||||
public @NonNull Path getBackupDirectory() {
|
||||
return resolve(resolve(
|
||||
resolve(backupManager.getBackupPath(), Objects.requireNonNull(plot.getArea().toString(), "plot area id")),
|
||||
Objects.requireNonNull(plot.getId().toDashSeparatedString(), "plot id")
|
||||
), Objects.requireNonNull(owner.toString(), "owner"));
|
||||
}
|
||||
|
||||
private static Path resolve(@Nonnull final Path parent, final String child) {
|
||||
Path path = parent;
|
||||
try {
|
||||
if (!Files.exists(parent)) {
|
||||
Files.createDirectory(parent);
|
||||
}
|
||||
path = parent.resolve(child);
|
||||
if (!Files.exists(path)) {
|
||||
Files.createDirectory(path);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override @Nonnull public CompletableFuture<Backup> createBackup() {
|
||||
@Override
|
||||
public @NonNull CompletableFuture<Backup> createBackup() {
|
||||
final CompletableFuture<Backup> future = new CompletableFuture<>();
|
||||
this.listBackups().thenAcceptAsync(backups -> {
|
||||
synchronized (this.backupLock) {
|
||||
@ -157,8 +163,9 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
}
|
||||
final List<Plot> plots = Collections.singletonList(plot);
|
||||
final boolean result = this.schematicHandler.exportAll(plots, getBackupDirectory().toFile(),
|
||||
"%world%-%id%-" + System.currentTimeMillis(), () ->
|
||||
future.complete(new Backup(this, System.currentTimeMillis(), null)));
|
||||
"%world%-%id%-" + System.currentTimeMillis(), () ->
|
||||
future.complete(new Backup(this, System.currentTimeMillis(), null))
|
||||
);
|
||||
if (!result) {
|
||||
future.completeExceptionally(new RuntimeException("Failed to complete the backup"));
|
||||
}
|
||||
@ -168,7 +175,8 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player) {
|
||||
@Override
|
||||
public @NonNull CompletableFuture<Void> restoreBackup(final @NonNull Backup backup, @Nullable PlotPlayer<?> player) {
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
if (backup.getFile() == null || !Files.exists(backup.getFile())) {
|
||||
future.completeExceptionally(new IllegalArgumentException("The specific backup does not exist"));
|
||||
@ -181,15 +189,19 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (schematic == null) {
|
||||
future.completeExceptionally(new IllegalArgumentException("The backup is non-existent or not in the correct format"));
|
||||
future.completeExceptionally(new IllegalArgumentException(
|
||||
"The backup is non-existent or not in the correct format"));
|
||||
} else {
|
||||
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, player, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
@Override
|
||||
public void run(Boolean value) {
|
||||
if (value) {
|
||||
future.complete(null);
|
||||
} else {
|
||||
future.completeExceptionally(new RuntimeException(MINI_MESSAGE.stripTokens(
|
||||
TranslatableCaption.of("schematics.schematic_paste_failed").getComponent(ConsolePlayer.getConsole()))));
|
||||
TranslatableCaption
|
||||
.of("schematics.schematic_paste_failed")
|
||||
.getComponent(ConsolePlayer.getConsole()))));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -38,9 +38,9 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
@ -50,16 +50,18 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Singleton public class SimpleBackupManager implements BackupManager {
|
||||
@Singleton
|
||||
public class SimpleBackupManager implements BackupManager {
|
||||
|
||||
private final Path backupPath;
|
||||
private final boolean automaticBackup;
|
||||
private final int backupLimit;
|
||||
private final Cache<PlotCacheKey, BackupProfile> backupProfileCache = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(3, TimeUnit.MINUTES).build();
|
||||
.expireAfterAccess(3, TimeUnit.MINUTES).build();
|
||||
private final PlayerBackupProfileFactory playerBackupProfileFactory;
|
||||
|
||||
@Inject public SimpleBackupManager(@Nonnull final PlayerBackupProfileFactory playerBackupProfileFactory) throws Exception {
|
||||
@Inject
|
||||
public SimpleBackupManager(final @NonNull PlayerBackupProfileFactory playerBackupProfileFactory) throws Exception {
|
||||
this.playerBackupProfileFactory = playerBackupProfileFactory;
|
||||
this.backupPath = Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath().resolve("backups");
|
||||
if (!Files.exists(backupPath)) {
|
||||
@ -69,18 +71,24 @@ import java.util.concurrent.TimeUnit;
|
||||
this.backupLimit = Settings.Backup.BACKUP_LIMIT;
|
||||
}
|
||||
|
||||
public SimpleBackupManager(final Path backupPath, final boolean automaticBackup,
|
||||
final int backupLimit, final PlayerBackupProfileFactory playerBackupProfileFactory) {
|
||||
public SimpleBackupManager(
|
||||
final Path backupPath, final boolean automaticBackup,
|
||||
final int backupLimit, final PlayerBackupProfileFactory playerBackupProfileFactory
|
||||
) {
|
||||
this.backupPath = backupPath;
|
||||
this.automaticBackup = automaticBackup;
|
||||
this.backupLimit = backupLimit;
|
||||
this.playerBackupProfileFactory = playerBackupProfileFactory;
|
||||
}
|
||||
|
||||
@Override @Nonnull public BackupProfile getProfile(@Nonnull final Plot plot) {
|
||||
@Override
|
||||
public @NonNull BackupProfile getProfile(final @NonNull Plot plot) {
|
||||
if (plot.hasOwner()) {
|
||||
try {
|
||||
return backupProfileCache.get(new PlotCacheKey(plot), () -> this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot));
|
||||
return backupProfileCache.get(
|
||||
new PlotCacheKey(plot),
|
||||
() -> this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot)
|
||||
);
|
||||
} catch (ExecutionException e) {
|
||||
final BackupProfile profile = this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot);
|
||||
this.backupProfileCache.put(new PlotCacheKey(plot), profile);
|
||||
@ -90,32 +98,39 @@ import java.util.concurrent.TimeUnit;
|
||||
return new NullBackupProfile();
|
||||
}
|
||||
|
||||
@Override public void automaticBackup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone) {
|
||||
@Override
|
||||
public void automaticBackup(@Nullable PlotPlayer player, final @NonNull Plot plot, @NonNull Runnable whenDone) {
|
||||
final BackupProfile profile;
|
||||
if (!this.shouldAutomaticallyBackup() || (profile = getProfile(plot)) instanceof NullBackupProfile) {
|
||||
whenDone.run();
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_started"), Template.of("plot", String.valueOf(plot.getId())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("backups.backup_automatic_started"),
|
||||
Template.of("plot", String.valueOf(plot.getId()))
|
||||
);
|
||||
}
|
||||
profile.createBackup().whenComplete((backup, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (player != null) {
|
||||
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_failure"),
|
||||
Templates.of("reason", throwable.getMessage()));
|
||||
}
|
||||
throwable.printStackTrace();
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_finished"));
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
}
|
||||
}
|
||||
if (throwable != null) {
|
||||
if (player != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("backups.backup_automatic_failure"),
|
||||
Templates.of("reason", throwable.getMessage())
|
||||
);
|
||||
}
|
||||
throwable.printStackTrace();
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_finished"));
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean shouldAutomaticallyBackup() {
|
||||
@Override
|
||||
public boolean shouldAutomaticallyBackup() {
|
||||
return this.automaticBackup;
|
||||
}
|
||||
|
||||
@ -135,7 +150,8 @@ import java.util.concurrent.TimeUnit;
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
@Override public boolean equals(final Object o) {
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
@ -144,13 +160,15 @@ import java.util.concurrent.TimeUnit;
|
||||
}
|
||||
final PlotCacheKey that = (PlotCacheKey) o;
|
||||
return Objects.equals(plot.getArea(), that.plot.getArea())
|
||||
&& Objects.equals(plot.getId(), that.plot.getId())
|
||||
&& Objects.equals(plot.getOwnerAbs(), that.plot.getOwnerAbs());
|
||||
&& Objects.equals(plot.getId(), that.plot.getId())
|
||||
&& Objects.equals(plot.getOwnerAbs(), that.plot.getOwnerAbs());
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(plot.getArea(), plot.getId(), plot.getOwnerAbs());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ package com.plotsquared.core.collection;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ArrayUtil {
|
||||
|
||||
public static final <T> T[] concatAll(T[] first, T[]... rest) {
|
||||
int totalLength = first.length;
|
||||
for (T[] array : rest) {
|
||||
@ -41,4 +42,5 @@ public class ArrayUtil {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public class ByteArrayUtilities {
|
||||
}
|
||||
|
||||
public static byte[] booleanToBytes(boolean b) {
|
||||
return new byte[] {(byte) (b ? 1 : 0)};
|
||||
return new byte[]{(byte) (b ? 1 : 0)};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class FlatRandomCollection<T> extends RandomCollection<T> {
|
||||
|
||||
private T[] values;
|
||||
|
||||
public FlatRandomCollection(Map<T, Double> weights, Random random) {
|
||||
@ -63,7 +64,9 @@ public class FlatRandomCollection<T> extends RandomCollection<T> {
|
||||
this.values = (T[]) parsed.toArray();
|
||||
}
|
||||
|
||||
@Override public T next() {
|
||||
@Override
|
||||
public T next() {
|
||||
return values[random.nextInt(values.length)];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -127,8 +127,9 @@ public class QuadMap<T> {
|
||||
if (region.getMinimumPoint().getZ() >= this.z) {
|
||||
if (this.one == null) {
|
||||
this.one =
|
||||
newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize,
|
||||
this.min);
|
||||
newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize,
|
||||
this.min
|
||||
);
|
||||
}
|
||||
this.one.add(area);
|
||||
recalculateSkip();
|
||||
@ -136,8 +137,9 @@ public class QuadMap<T> {
|
||||
} else if (region.getMaximumPoint().getZ() < this.z) {
|
||||
if (this.two == null) {
|
||||
this.two =
|
||||
newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize,
|
||||
this.min);
|
||||
newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize,
|
||||
this.min
|
||||
);
|
||||
}
|
||||
this.two.add(area);
|
||||
recalculateSkip();
|
||||
@ -147,8 +149,9 @@ public class QuadMap<T> {
|
||||
if (region.getMinimumPoint().getZ() >= this.z) {
|
||||
if (this.four == null) {
|
||||
this.four =
|
||||
newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize,
|
||||
this.min);
|
||||
newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize,
|
||||
this.min
|
||||
);
|
||||
}
|
||||
this.four.add(area);
|
||||
recalculateSkip();
|
||||
@ -156,8 +159,9 @@ public class QuadMap<T> {
|
||||
} else if (region.getMaximumPoint().getZ() < this.z) {
|
||||
if (this.three == null) {
|
||||
this.three =
|
||||
newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize,
|
||||
this.min);
|
||||
newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize,
|
||||
this.min
|
||||
);
|
||||
}
|
||||
this.three.add(area);
|
||||
recalculateSkip();
|
||||
@ -177,7 +181,8 @@ public class QuadMap<T> {
|
||||
public QuadMap<T> newInstance(int newsize, int x, int z, int min) {
|
||||
try {
|
||||
return new QuadMap<T>(newsize, x, z, min) {
|
||||
@Override public CuboidRegion getRegion(T value) {
|
||||
@Override
|
||||
public CuboidRegion getRegion(T value) {
|
||||
return QuadMap.this.getRegion(value);
|
||||
}
|
||||
};
|
||||
@ -238,7 +243,7 @@ public class QuadMap<T> {
|
||||
|
||||
public void recalculateSkip() {
|
||||
QuadMap<T> map = null;
|
||||
for (QuadMap<T> current : new QuadMap[] {this.one, this.two, this.three, this.four}) {
|
||||
for (QuadMap<T> current : new QuadMap[]{this.one, this.two, this.three, this.four}) {
|
||||
if (current != null) {
|
||||
if (map != null) {
|
||||
this.skip = null;
|
||||
@ -282,8 +287,8 @@ public class QuadMap<T> {
|
||||
|
||||
public boolean intersects(CuboidRegion other) {
|
||||
return (other.getMinimumPoint().getX() <= this.x + this.size) && (
|
||||
other.getMaximumPoint().getX() >= this.x - this.size) && (other.getMinimumPoint().getZ()
|
||||
<= this.z + this.size) && (other.getMaximumPoint().getZ() >= this.z - this.size);
|
||||
other.getMaximumPoint().getX() >= this.x - this.size) && (other.getMinimumPoint().getZ()
|
||||
<= this.z + this.size) && (other.getMaximumPoint().getZ() >= this.z - this.size);
|
||||
}
|
||||
|
||||
public T get(int x, int z) {
|
||||
@ -321,4 +326,5 @@ public class QuadMap<T> {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import java.util.Random;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public abstract class RandomCollection<T> {
|
||||
|
||||
protected Random random;
|
||||
|
||||
public RandomCollection(Map<T, Double> weights, Random random) {
|
||||
@ -55,4 +56,5 @@ public abstract class RandomCollection<T> {
|
||||
}
|
||||
|
||||
public abstract T next();
|
||||
|
||||
}
|
||||
|
@ -43,8 +43,9 @@ public class SimpleRandomCollection<E> extends RandomCollection<E> {
|
||||
}
|
||||
|
||||
public void add(double weight, E result) {
|
||||
if (weight <= 0)
|
||||
if (weight <= 0) {
|
||||
return;
|
||||
}
|
||||
total += weight;
|
||||
map.put(total, result);
|
||||
}
|
||||
@ -52,4 +53,5 @@ public class SimpleRandomCollection<E> extends RandomCollection<E> {
|
||||
public E next() {
|
||||
return map.ceilingEntry(random.nextDouble()).getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
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;
|
||||
@ -39,8 +39,8 @@ 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.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@ -49,66 +49,81 @@ 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)
|
||||
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(@Nonnull 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 {
|
||||
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()) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||
TranslatableCaption.of("permission.no_plot_perms"));
|
||||
checkTrue(
|
||||
plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||
TranslatableCaption.of("permission.no_plot_perms")
|
||||
);
|
||||
checkTrue(args.length == 1, TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot add <player | *>"));
|
||||
Template.of("value", "/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"),
|
||||
Template.of("value", args[0]));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[0])
|
||||
);
|
||||
}
|
||||
future.completeExceptionally(throwable);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
checkTrue(!uuids.isEmpty(), TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[0]));
|
||||
Template.of("value", 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 && !(
|
||||
Permissions.hasPermission(player, Permission.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", PlayerManager.getName(uuid)));
|
||||
Permissions.hasPermission(player, Permission.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", PlayerManager.getName(uuid))
|
||||
);
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
player.sendMessage(TranslatableCaption.of("member.already_added"),
|
||||
Template.of("player", PlayerManager.getName(uuid)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("member.already_added"),
|
||||
Template.of("player", PlayerManager.getName(uuid))
|
||||
);
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (plot.getMembers().contains(uuid)) {
|
||||
player.sendMessage(TranslatableCaption.of("member.already_added"),
|
||||
Template.of("player", PlayerManager.getName(uuid)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("member.already_added"),
|
||||
Template.of("player", PlayerManager.getName(uuid))
|
||||
);
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
@ -117,7 +132,10 @@ public class Add extends Command {
|
||||
checkTrue(!uuids.isEmpty(), null);
|
||||
int maxAddSize = Permissions.hasPermissionRange(player, Permission.PERMISSION_ADD, Settings.Limit.MAX_PLOTS);
|
||||
if (size > maxAddSize) {
|
||||
player.sendMessage(TranslatableCaption.of("members.plot_max_members_added"), Template.of("amount", String.valueOf(size - 1)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("members.plot_max_members_added"),
|
||||
Template.of("amount", String.valueOf(size - 1))
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Success
|
||||
@ -145,7 +163,8 @@ public class Add extends Command {
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,10 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
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;
|
||||
@ -44,16 +44,20 @@ 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)
|
||||
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) {
|
||||
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);
|
||||
@ -94,8 +98,10 @@ public class Alias extends SubCommand {
|
||||
setAlias(player, plot, args[1]);
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_SET)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_SET))
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -109,8 +115,10 @@ public class Alias extends SubCommand {
|
||||
if (permission) {
|
||||
result = removeAlias(player, plot);
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE))
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -162,8 +170,10 @@ public class Alias extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("alias.alias_is_taken"));
|
||||
} else {
|
||||
plot.setAlias(alias);
|
||||
player.sendMessage(TranslatableCaption.of("alias.alias_set_to"),
|
||||
Template.of("alias", alias));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("alias.alias_set_to"),
|
||||
Template.of("alias", alias)
|
||||
);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -171,12 +181,15 @@ public class Alias extends SubCommand {
|
||||
|
||||
private boolean removeAlias(PlotPlayer<?> player, Plot plot) {
|
||||
plot.setAlias(null);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE))
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isPermitted(PlotPlayer<?> player, Permission permission) {
|
||||
return Permissions.hasPermission(player, permission);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -95,12 +95,12 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "area",
|
||||
permission = "plots.area",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.NONE,
|
||||
aliases = "world",
|
||||
usage = "/plot area <create | info | list | tp | regen>",
|
||||
confirmation = true)
|
||||
permission = "plots.area",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.NONE,
|
||||
aliases = "world",
|
||||
usage = "/plot area <create | info | list | tp | regen>",
|
||||
confirmation = true)
|
||||
public class Area extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
@ -114,14 +114,17 @@ public class Area extends SubCommand {
|
||||
|
||||
private final Map<UUID, Map<String, Object>> metaData = new HashMap<>();
|
||||
|
||||
@Inject public Area(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile,
|
||||
@Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory,
|
||||
@Nonnull final SetupUtils setupUtils,
|
||||
@Nonnull final WorldUtil worldUtil,
|
||||
@Nonnull final RegionManager regionManager,
|
||||
@Nonnull final GlobalBlockQueue blockQueue) {
|
||||
@Inject
|
||||
public Area(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
@WorldConfig final @NonNull YamlConfiguration worldConfiguration,
|
||||
@WorldFile final @NonNull File worldFile,
|
||||
final @NonNull HybridPlotWorldFactory hybridPlotWorldFactory,
|
||||
final @NonNull SetupUtils setupUtils,
|
||||
final @NonNull WorldUtil worldUtil,
|
||||
final @NonNull RegionManager regionManager,
|
||||
final @NonNull GlobalBlockQueue blockQueue
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
this.worldFile = worldFile;
|
||||
@ -132,7 +135,8 @@ public class Area extends SubCommand {
|
||||
this.blockQueue = blockQueue;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendUsage(player);
|
||||
return false;
|
||||
@ -144,11 +148,17 @@ public class Area extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_needs_name"), Template.of("command", "/plot area single <name>"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("single.single_area_needs_name"),
|
||||
Template.of("command", "/plot area single <name>")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]);
|
||||
@ -174,8 +184,10 @@ public class Area extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_not_square"));
|
||||
return false;
|
||||
}
|
||||
if (this.plotAreaManager.getPlotAreas(Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(),
|
||||
CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
|
||||
if (this.plotAreaManager.getPlotAreas(
|
||||
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(),
|
||||
CuboidRegion.makeCuboid(playerSelectedRegion)
|
||||
).length != 0) {
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_overlapping"));
|
||||
}
|
||||
// Alter the region
|
||||
@ -183,13 +195,19 @@ public class Area extends SubCommand {
|
||||
final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint();
|
||||
// Create a new selection that spans the entire vertical range of the world
|
||||
final CuboidRegion selectedRegion =
|
||||
new CuboidRegion(playerSelectedRegion.getWorld(), BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
|
||||
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
|
||||
new CuboidRegion(playerSelectedRegion.getWorld(),
|
||||
BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
|
||||
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ())
|
||||
);
|
||||
// There's only one plot in the area...
|
||||
final PlotId plotId = PlotId.of(1, 1);
|
||||
final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory
|
||||
.create(player.getLocation().getWorldName(), args[1], Objects.requireNonNull(PlotSquared.platform()).defaultGenerator(),
|
||||
plotId, plotId);
|
||||
.create(player.getLocation().getWorldName(),
|
||||
args[1],
|
||||
Objects.requireNonNull(PlotSquared.platform()).defaultGenerator(),
|
||||
plotId,
|
||||
plotId
|
||||
);
|
||||
// Plot size is the same as the region width
|
||||
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
|
||||
// We use a schematic generator
|
||||
@ -204,19 +222,25 @@ public class Area extends SubCommand {
|
||||
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
|
||||
// No sign plz
|
||||
hybridPlotWorld.setAllowSigns(false);
|
||||
final File parentFile = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
"schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator
|
||||
+ hybridPlotWorld.getId());
|
||||
final File parentFile = FileUtils.getFile(
|
||||
PlotSquared.platform().getDirectory(),
|
||||
"schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator
|
||||
+ hybridPlotWorld.getId()
|
||||
);
|
||||
if (!parentFile.exists() && !parentFile.mkdirs()) {
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_could_not_make_directories"));
|
||||
return false;
|
||||
}
|
||||
final File file = new File(parentFile, "plot.schem");
|
||||
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
||||
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(
|
||||
file))) {
|
||||
final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion);
|
||||
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(selectedRegion.getWorld(), -1);
|
||||
final EditSession editSession = WorldEdit
|
||||
.getInstance()
|
||||
.getEditSessionFactory()
|
||||
.getEditSession(selectedRegion.getWorld(), -1);
|
||||
final ForwardExtentCopy forwardExtentCopy =
|
||||
new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
|
||||
new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
|
||||
forwardExtentCopy.setCopyingBiomes(true);
|
||||
forwardExtentCopy.setCopyingEntities(true);
|
||||
Operations.complete(forwardExtentCopy);
|
||||
@ -238,12 +262,15 @@ public class Area extends SubCommand {
|
||||
final BlockVector3 singlePos1 = selectedRegion.getMinimumPoint();
|
||||
|
||||
// Now the schematic is saved, which is wonderful!
|
||||
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld).plotManager(PlotSquared.platform().pluginName())
|
||||
.generatorName(PlotSquared.platform().pluginName()).maximumId(plotId).minimumId(plotId);
|
||||
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld).plotManager(PlotSquared
|
||||
.platform()
|
||||
.pluginName())
|
||||
.generatorName(PlotSquared.platform().pluginName()).maximumId(plotId).minimumId(plotId);
|
||||
Runnable singleRun = () -> {
|
||||
final String path =
|
||||
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-' + singleBuilder.minimumId() + '-'
|
||||
+ singleBuilder.maximumId();
|
||||
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-' + singleBuilder
|
||||
.minimumId() + '-'
|
||||
+ singleBuilder.maximumId();
|
||||
final int offsetX = singlePos1.getX();
|
||||
final int offsetZ = singlePos1.getZ();
|
||||
if (offsetX != 0) {
|
||||
@ -257,7 +284,10 @@ public class Area extends SubCommand {
|
||||
PlotSquared.get().loadWorld(world, null);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_created"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", hybridPlotWorld.getWorldName()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.error_create"),
|
||||
Template.of("world", hybridPlotWorld.getWorldName())
|
||||
);
|
||||
}
|
||||
};
|
||||
singleRun.run();
|
||||
@ -266,43 +296,67 @@ public class Area extends SubCommand {
|
||||
case "setup":
|
||||
case "create":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]...")
|
||||
);
|
||||
return false;
|
||||
case 2:
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "pos1": { // Set position 1
|
||||
HybridPlotWorld area = (HybridPlotWorld) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>())
|
||||
.get("area_create_area");
|
||||
HybridPlotWorld area = (HybridPlotWorld) metaData.computeIfAbsent(
|
||||
player.getUUID(),
|
||||
missingUUID -> new HashMap<>()
|
||||
)
|
||||
.get("area_create_area");
|
||||
if (area == null) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]...")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_pos1", location);
|
||||
player.sendMessage(TranslatableCaption.of("set.set_attribute"), Template.of("attribute", "area_pos1"),
|
||||
Template.of("value", location.getX() + "," + location.getZ()));
|
||||
player.sendMessage(TranslatableCaption.of("area.set_pos2"), Template.of("command", "/plot area create pos2"));
|
||||
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put(
|
||||
"area_pos1",
|
||||
location
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("set.set_attribute"),
|
||||
Template.of("attribute", "area_pos1"),
|
||||
Template.of("value", location.getX() + "," + location.getZ())
|
||||
);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("area.set_pos2"),
|
||||
Template.of("command", "/plot area create pos2")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case "pos2": // Set position 2 and finish creation for type=2 (partial)
|
||||
final HybridPlotWorld area =
|
||||
(HybridPlotWorld) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>())
|
||||
.get("area_create_area");
|
||||
(HybridPlotWorld) metaData.computeIfAbsent(
|
||||
player.getUUID(),
|
||||
missingUUID -> new HashMap<>()
|
||||
)
|
||||
.get("area_create_area");
|
||||
if (area == null) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]...")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
Location pos1 = player.getLocation();
|
||||
Location pos2 =
|
||||
(Location) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get("area_pos1");
|
||||
(Location) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get(
|
||||
"area_pos1");
|
||||
int dx = Math.abs(pos1.getX() - pos2.getX());
|
||||
int dz = Math.abs(pos1.getZ() - pos2.getZ());
|
||||
int numX = Math.max(1, (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||
@ -319,16 +373,20 @@ public class Area extends SubCommand {
|
||||
final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz);
|
||||
final Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(area.getWorldName(), region);
|
||||
if (!areas.isEmpty()) {
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_intersection"),
|
||||
Template.of("cluster", areas.iterator().next().toString()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("cluster.cluster_intersection"),
|
||||
Template.of("cluster", areas.iterator().next().toString())
|
||||
);
|
||||
return false;
|
||||
}
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area).plotManager(PlotSquared.platform().pluginName())
|
||||
.generatorName(PlotSquared.platform().pluginName()).minimumId(PlotId.of(1, 1))
|
||||
.maximumId(PlotId.of(numX, numZ));
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area).plotManager(PlotSquared
|
||||
.platform()
|
||||
.pluginName())
|
||||
.generatorName(PlotSquared.platform().pluginName()).minimumId(PlotId.of(1, 1))
|
||||
.maximumId(PlotId.of(numX, numZ));
|
||||
final String path =
|
||||
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-' + builder.minimumId() + '-' + builder
|
||||
.maximumId();
|
||||
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-' + builder.minimumId() + '-' + builder
|
||||
.maximumId();
|
||||
Runnable run = () -> {
|
||||
if (offsetX != 0) {
|
||||
this.worldConfiguration.set(path + ".road.offset.x", offsetX);
|
||||
@ -343,12 +401,21 @@ public class Area extends SubCommand {
|
||||
player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND);
|
||||
if (area.getTerrain() != PlotAreaTerrainType.ALL) {
|
||||
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
|
||||
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(null, world, chunk.getX(), chunk.getZ(), null));
|
||||
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(
|
||||
null,
|
||||
world,
|
||||
chunk.getX(),
|
||||
chunk.getZ(),
|
||||
null
|
||||
));
|
||||
queue.addReadChunks(region.getChunks());
|
||||
queue.enqueue();
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", area.getWorldName()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.error_create"),
|
||||
Template.of("world", area.getWorldName())
|
||||
);
|
||||
}
|
||||
};
|
||||
if (hasConfirmation(player)) {
|
||||
@ -369,10 +436,19 @@ public class Area extends SubCommand {
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder();
|
||||
builder.worldName(split[0]);
|
||||
final HybridPlotWorld pa =
|
||||
this.hybridPlotWorldFactory.create(builder.worldName(), id, PlotSquared.platform().defaultGenerator(), null, null);
|
||||
this.hybridPlotWorldFactory.create(
|
||||
builder.worldName(),
|
||||
id,
|
||||
PlotSquared.platform().defaultGenerator(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id);
|
||||
if (other != null && Objects.equals(pa.getId(), other.getId())) {
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), Template.of("value", pa.toString()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("setup.setup_world_taken"),
|
||||
Template.of("value", pa.toString())
|
||||
);
|
||||
return false;
|
||||
}
|
||||
Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName());
|
||||
@ -384,9 +460,11 @@ public class Area extends SubCommand {
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
String[] pair = args[i].split("=");
|
||||
if (pair.length != 2) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||
Template.of("value1,", getCommandString()),
|
||||
Template.of("value2", " create [world[:id]] [<modifier>=<value>]..."));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||
Template.of("value1,", getCommandString()),
|
||||
Template.of("value2", " create [world[:id]] [<modifier>=<value>]...")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
switch (pair[0].toLowerCase()) {
|
||||
@ -425,24 +503,29 @@ public class Area extends SubCommand {
|
||||
break;
|
||||
case "terrain":
|
||||
pa.setTerrain(PlotAreaTerrainType.fromString(pair[1])
|
||||
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid terrain.")));
|
||||
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid terrain.")));
|
||||
builder.terrainType(pa.getTerrain());
|
||||
break;
|
||||
case "type":
|
||||
pa.setType(PlotAreaType.fromString(pair[1])
|
||||
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid type.")));
|
||||
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid type.")));
|
||||
builder.plotAreaType(pa.getType());
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||
Template.of("value1", getCommandString()),
|
||||
Template.of("value2", " create [world[:id]] [<modifier>=<value>]..."));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||
Template.of("value1", getCommandString()),
|
||||
Template.of("value2", " create [world[:id]] [<modifier>=<value>]...")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (pa.getType() != PlotAreaType.PARTIAL) {
|
||||
if (this.worldUtil.isWorld(pa.getWorldName())) {
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), Template.of("value", pa.getWorldName()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("setup.setup_world_taken"),
|
||||
Template.of("value", pa.getWorldName())
|
||||
);
|
||||
return false;
|
||||
}
|
||||
Runnable run = () -> {
|
||||
@ -460,7 +543,10 @@ public class Area extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
|
||||
player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND);
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", pa.getWorldName()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.error_create"),
|
||||
Template.of("world", pa.getWorldName())
|
||||
);
|
||||
}
|
||||
try {
|
||||
this.worldConfiguration.save(this.worldFile);
|
||||
@ -476,9 +562,14 @@ public class Area extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
if (pa.getId() == null) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", getUsage())
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||
Template.of("value1", getCommandString()), Template.of("value2", " create [world[:id]] [<modifier>=<value>]..."));
|
||||
Template.of("value1", getCommandString()),
|
||||
Template.of("value2", " create [world[:id]] [<modifier>=<value>]...")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (this.worldUtil.isWorld(pa.getWorldName())) {
|
||||
@ -492,14 +583,20 @@ public class Area extends SubCommand {
|
||||
player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), TeleportCause.COMMAND);
|
||||
}
|
||||
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_create_area", pa);
|
||||
player.sendMessage(TranslatableCaption.of("single.get_position"), Template.of("command", getCommandString()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("single.get_position"),
|
||||
Template.of("command", getCommandString())
|
||||
);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
case "i":
|
||||
case "info": {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_INFO)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_INFO)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_INFO))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
PlotArea area;
|
||||
@ -511,8 +608,10 @@ public class Area extends SubCommand {
|
||||
area = this.plotAreaManager.getPlotAreaByString(args[1]);
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), Template.of("value1", getCommandString()),
|
||||
Template.of("value2", " info [area]"));
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||
Template.of("value1", getCommandString()),
|
||||
Template.of("value2", " info [area]")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (area == null) {
|
||||
@ -541,7 +640,10 @@ public class Area extends SubCommand {
|
||||
percent = claimed == 0 ? 0 : 100d * claimed / Integer.MAX_VALUE;
|
||||
region = "N/A";
|
||||
}
|
||||
Template headerTemplate = Template.of("header", TranslatableCaption.of("info.plot_info_header").getComponent(player));
|
||||
Template headerTemplate = Template.of(
|
||||
"header",
|
||||
TranslatableCaption.of("info.plot_info_header").getComponent(player)
|
||||
);
|
||||
Template nameTemplate = Template.of("name", name);
|
||||
Template typeTemplate = Template.of("type", area.getType().name());
|
||||
Template terrainTemplate = Template.of("terrain", area.getTerrain().name());
|
||||
@ -550,15 +652,31 @@ public class Area extends SubCommand {
|
||||
Template clustersTemplate = Template.of("clusters", String.valueOf(clusters));
|
||||
Template regionTemplate = Template.of("region", region);
|
||||
Template generatorTemplate = Template.of("generator", generator);
|
||||
Template footerTemplate = Template.of("footer", TranslatableCaption.of("info.plot_info_footer").getComponent(player));
|
||||
player.sendMessage(TranslatableCaption.of("info.area_info_format"), headerTemplate, nameTemplate, typeTemplate, terrainTemplate,
|
||||
usageTemplate, claimedTemplate, clustersTemplate, regionTemplate, generatorTemplate, footerTemplate);
|
||||
Template footerTemplate = Template.of(
|
||||
"footer",
|
||||
TranslatableCaption.of("info.plot_info_footer").getComponent(player)
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("info.area_info_format"),
|
||||
headerTemplate,
|
||||
nameTemplate,
|
||||
typeTemplate,
|
||||
terrainTemplate,
|
||||
usageTemplate,
|
||||
claimedTemplate,
|
||||
clustersTemplate,
|
||||
regionTemplate,
|
||||
generatorTemplate,
|
||||
footerTemplate
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case "l":
|
||||
case "list":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_LIST)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_LIST)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_LIST))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
int page;
|
||||
@ -572,13 +690,16 @@ public class Area extends SubCommand {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), Template.of("value1", getCommandString()),
|
||||
Template.of("value2", " list [#]"));
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||
Template.of("value1", getCommandString()),
|
||||
Template.of("value2", " list [#]")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final List<PlotArea> areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas()));
|
||||
paginate(player, areas, 8, page, new RunnableVal3<Integer, PlotArea, CaptionHolder>() {
|
||||
@Override public void run(Integer i, PlotArea area, CaptionHolder caption) {
|
||||
@Override
|
||||
public void run(Integer i, PlotArea area, CaptionHolder caption) {
|
||||
String name;
|
||||
double percent;
|
||||
int claimed = area.getPlotCount();
|
||||
@ -603,8 +724,13 @@ public class Area extends SubCommand {
|
||||
Template regionTemplate = Template.of("region", region);
|
||||
Template generatorTemplate = Template.of("generator", generator);
|
||||
String tooltip = MINI_MESSAGE.serialize(MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("info.area_list_tooltip").getComponent(player), claimedTemplate, usageTemplate,
|
||||
clustersTemplate, regionTemplate, generatorTemplate));
|
||||
.parse(TranslatableCaption.of("info.area_list_tooltip").getComponent(player),
|
||||
claimedTemplate,
|
||||
usageTemplate,
|
||||
clustersTemplate,
|
||||
regionTemplate,
|
||||
generatorTemplate
|
||||
));
|
||||
Template tooltipTemplate = Template.of("hover_info", tooltip);
|
||||
Template visitcmdTemplate = Template.of("command_tp", "/plot area tp " + area.toString());
|
||||
Template infocmdTemplate = Template.of("command_info", "/plot area info " + area.toString());
|
||||
@ -613,8 +739,14 @@ public class Area extends SubCommand {
|
||||
Template typeTemplate = Template.of("area_type", area.getType().name());
|
||||
Template terrainTemplate = Template.of("area_terrain", area.getTerrain().name());
|
||||
caption.set(TranslatableCaption.of("info.area_list_item"));
|
||||
caption.setTemplates(tooltipTemplate, visitcmdTemplate, numberTemplate, nameTemplate, typeTemplate, terrainTemplate,
|
||||
infocmdTemplate);
|
||||
caption.setTemplates(tooltipTemplate,
|
||||
visitcmdTemplate,
|
||||
numberTemplate,
|
||||
nameTemplate,
|
||||
typeTemplate,
|
||||
terrainTemplate,
|
||||
infocmdTemplate
|
||||
);
|
||||
}
|
||||
}, "/plot area list", TranslatableCaption.of("list.area_list_header_paged"));
|
||||
return true;
|
||||
@ -623,7 +755,10 @@ public class Area extends SubCommand {
|
||||
case "reset":
|
||||
case "regenerate": {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_REGEN)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_REGEN)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_REGEN))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final PlotArea area = player.getApplicablePlotArea();
|
||||
@ -632,11 +767,20 @@ public class Area extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (area.getType() != PlotAreaType.PARTIAL) {
|
||||
player.sendMessage(TranslatableCaption.of("single.delete_world_region"), Template.of("world", area.getWorldName()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("single.delete_world_region"),
|
||||
Template.of("world", area.getWorldName())
|
||||
);
|
||||
return false;
|
||||
}
|
||||
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
|
||||
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(null, area.getWorldName(), chunk.getX(), chunk.getZ(), null));
|
||||
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(
|
||||
null,
|
||||
area.getWorldName(),
|
||||
chunk.getX(),
|
||||
chunk.getZ(),
|
||||
null
|
||||
));
|
||||
queue.addReadChunks(area.getRegion().getChunks());
|
||||
queue.setCompleteTask(() -> player.sendMessage(TranslatableCaption.of("single.regeneration_complete")));
|
||||
queue.enqueue();
|
||||
@ -648,11 +792,17 @@ public class Area extends SubCommand {
|
||||
case "visit":
|
||||
case "tp":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_TP)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_TP)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_TP))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot area tp [area]"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot area tp [area]")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]);
|
||||
@ -671,10 +821,16 @@ public class Area extends SubCommand {
|
||||
} else {
|
||||
CuboidRegion region = area.getRegion();
|
||||
center = Location.at(area.getWorldName(),
|
||||
region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, 0,
|
||||
region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2);
|
||||
region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region
|
||||
.getMinimumPoint()
|
||||
.getX()) / 2, 0,
|
||||
region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region
|
||||
.getMinimumPoint()
|
||||
.getZ()) / 2
|
||||
);
|
||||
this.worldUtil.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(),
|
||||
y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND));
|
||||
y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
case "delete":
|
||||
@ -685,6 +841,7 @@ public class Area extends SubCommand {
|
||||
sendUsage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
@ -704,8 +861,17 @@ public class Area extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_TP)) {
|
||||
completions.add("tp");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(
|
||||
null,
|
||||
true,
|
||||
completion,
|
||||
"",
|
||||
RequiredType.NONE,
|
||||
CommandCategory.ADMINISTRATION
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
@ -714,4 +880,5 @@ public class Area extends SubCommand {
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ import com.plotsquared.core.plot.PlotId;
|
||||
public abstract class Argument<T> {
|
||||
|
||||
public static final Argument<Integer> Integer = new Argument<Integer>("int", 16) {
|
||||
@Override public Integer parse(String in) {
|
||||
@Override
|
||||
public Integer parse(String in) {
|
||||
Integer value = null;
|
||||
try {
|
||||
value = java.lang.Integer.parseInt(in);
|
||||
@ -40,35 +41,39 @@ public abstract class Argument<T> {
|
||||
}
|
||||
};
|
||||
public static final Argument<Boolean> Boolean = new Argument<Boolean>("boolean", true) {
|
||||
@Override public Boolean parse(String in) {
|
||||
@Override
|
||||
public Boolean parse(String in) {
|
||||
Boolean value = null;
|
||||
if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in
|
||||
.equalsIgnoreCase("1")) {
|
||||
.equalsIgnoreCase("1")) {
|
||||
value = true;
|
||||
} else if (in.equalsIgnoreCase("false") || in.equalsIgnoreCase("No") || in
|
||||
.equalsIgnoreCase("0")) {
|
||||
.equalsIgnoreCase("0")) {
|
||||
value = false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
public static final Argument<String> String = new Argument<String>("String", "Example") {
|
||||
@Override public String parse(String in) {
|
||||
@Override
|
||||
public String parse(String in) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
public static final Argument<String> PlayerName =
|
||||
new Argument<String>("PlayerName", "<player | *>") {
|
||||
@Override public String parse(String in) {
|
||||
return in.length() <= 16 ? in : null;
|
||||
}
|
||||
};
|
||||
new Argument<String>("PlayerName", "<player | *>") {
|
||||
@Override
|
||||
public String parse(String in) {
|
||||
return in.length() <= 16 ? in : null;
|
||||
}
|
||||
};
|
||||
public static final Argument<PlotId> PlotID =
|
||||
new Argument<PlotId>("PlotID", PlotId.of(-6, 3)) {
|
||||
@Override public PlotId parse(String in) {
|
||||
return PlotId.fromString(in);
|
||||
}
|
||||
};
|
||||
new Argument<PlotId>("PlotID", PlotId.of(-6, 3)) {
|
||||
@Override
|
||||
public PlotId parse(String in) {
|
||||
return PlotId.fromString(in);
|
||||
}
|
||||
};
|
||||
private final String name;
|
||||
private final T example;
|
||||
|
||||
@ -79,7 +84,8 @@ public abstract class Argument<T> {
|
||||
|
||||
public abstract T parse(String in);
|
||||
|
||||
@Override public final String toString() {
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
@ -90,4 +96,5 @@ public abstract class Argument<T> {
|
||||
public final T getExample() {
|
||||
return this.example;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,20 +52,20 @@ import com.plotsquared.core.util.task.AutoClaimFinishTask;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "auto",
|
||||
permission = "plots.auto",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
aliases = "a",
|
||||
usage = "/plot auto [length, width]")
|
||||
permission = "plots.auto",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
aliases = "a",
|
||||
usage = "/plot auto [length, width]")
|
||||
public class Auto extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
@ -73,10 +73,13 @@ public class Auto extends SubCommand {
|
||||
private final EconHandler econHandler;
|
||||
private final ServicePipeline servicePipeline;
|
||||
|
||||
@Inject public Auto(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final EconHandler econHandler,
|
||||
@Nonnull final ServicePipeline servicePipeline) {
|
||||
@Inject
|
||||
public Auto(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull EconHandler econHandler,
|
||||
final @NonNull ServicePipeline servicePipeline
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.econHandler = econHandler;
|
||||
@ -84,14 +87,18 @@ public class Auto extends SubCommand {
|
||||
this.servicePipeline.registerServiceType(TypeToken.of(AutoService.class), new AutoService.DefaultAutoService());
|
||||
final AutoService.MultiPlotService multiPlotService = new AutoService.MultiPlotService();
|
||||
this.servicePipeline.registerServiceImplementation(AutoService.class, multiPlotService,
|
||||
Collections.singletonList(multiPlotService));
|
||||
Collections.singletonList(multiPlotService)
|
||||
);
|
||||
final AutoService.SinglePlotService singlePlotService = new AutoService.SinglePlotService();
|
||||
this.servicePipeline.registerServiceImplementation(AutoService.class, singlePlotService,
|
||||
Collections.singletonList(singlePlotService));
|
||||
Collections.singletonList(singlePlotService)
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean checkAllowedPlots(PlotPlayer player, PlotArea plotarea,
|
||||
@Nullable Integer allowedPlots, int sizeX, int sizeZ) {
|
||||
public static boolean checkAllowedPlots(
|
||||
PlotPlayer player, PlotArea plotarea,
|
||||
@Nullable Integer allowedPlots, int sizeX, int sizeZ
|
||||
) {
|
||||
if (allowedPlots == null) {
|
||||
allowedPlots = player.getAllowedPlots();
|
||||
}
|
||||
@ -104,16 +111,20 @@ public class Auto extends SubCommand {
|
||||
int diff = allowedPlots - currentPlots;
|
||||
if (diff - sizeX * sizeZ < 0) {
|
||||
try (final MetaDataAccess<Integer> metaDataAccess = player.accessPersistentMetaData(
|
||||
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||
if (metaDataAccess.isPresent()) {
|
||||
int grantedPlots = metaDataAccess.get().orElse(0);
|
||||
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(diff + grantedPlots)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(diff + grantedPlots))
|
||||
);
|
||||
return false;
|
||||
} else if (diff >= 0 && grantedPlots + diff < sizeX * sizeZ) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(diff + grantedPlots)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(diff + grantedPlots))
|
||||
);
|
||||
return false;
|
||||
} else {
|
||||
int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
|
||||
@ -122,13 +133,17 @@ public class Auto extends SubCommand {
|
||||
} else {
|
||||
metaDataAccess.set(left);
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("economy.removed_granted_plot"),
|
||||
Template.of("usedGrants", String.valueOf(grantedPlots - left)),
|
||||
Template.of("remainingGrants", String.valueOf(left)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("economy.removed_granted_plot"),
|
||||
Template.of("usedGrants", String.valueOf(grantedPlots - left)),
|
||||
Template.of("remainingGrants", String.valueOf(left))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", "0"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", "0")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -136,10 +151,12 @@ public class Auto extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void claimSingle(@Nonnull final PlotPlayer<?> player, @Nonnull final Plot plot,
|
||||
@Nonnull final PlotArea plotArea, @Nullable final String schematic) {
|
||||
private void claimSingle(
|
||||
final @NonNull PlotPlayer<?> player, final @NonNull Plot plot,
|
||||
final @NonNull PlotArea plotArea, final @Nullable String schematic
|
||||
) {
|
||||
try (final MetaDataAccess<Boolean> metaDataAccess =
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||
metaDataAccess.set(true);
|
||||
}
|
||||
plot.setOwnerAbs(player.getUUID());
|
||||
@ -149,11 +166,13 @@ public class Auto extends SubCommand {
|
||||
this.value = plot;
|
||||
}
|
||||
|
||||
@Override public void run(final Plot plot) {
|
||||
@Override
|
||||
public void run(final Plot plot) {
|
||||
try {
|
||||
TaskManager.getPlatformImplementation().sync(
|
||||
new AutoClaimFinishTask(player, plot, plotArea, schematic,
|
||||
PlotSquared.get().getEventDispatcher()));
|
||||
new AutoClaimFinishTask(player, plot, plotArea, schematic,
|
||||
PlotSquared.get().getEventDispatcher()
|
||||
));
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -164,12 +183,13 @@ public class Auto extends SubCommand {
|
||||
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
PlotArea plotarea = player.getApplicablePlotArea();
|
||||
if (plotarea == null) {
|
||||
final PermissionHandler permissionHandler = PlotSquared.platform().permissionHandler();
|
||||
if (permissionHandler.hasCapability(
|
||||
PermissionHandler.PermissionHandlerCapability.PER_WORLD_PERMISSIONS)) {
|
||||
PermissionHandler.PermissionHandlerCapability.PER_WORLD_PERMISSIONS)) {
|
||||
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
||||
if (player.hasPermission(area.getWorldName(), "plots.auto")) {
|
||||
if (plotarea != null) {
|
||||
@ -228,11 +248,12 @@ public class Auto extends SubCommand {
|
||||
}
|
||||
}
|
||||
PlayerAutoPlotEvent event = this.eventDispatcher
|
||||
.callAuto(player, plotarea, schematic, size_x, size_z);
|
||||
.callAuto(player, plotarea, schematic, size_x, size_z);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Auto claim"));
|
||||
Template.of("value", "Auto claim")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
@ -240,19 +261,24 @@ public class Auto extends SubCommand {
|
||||
size_z = event.getSize_z();
|
||||
schematic = event.getSchematic();
|
||||
if (!force && mega && !Permissions.hasPermission(player, Permission.PERMISSION_AUTO_MEGA)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AUTO_MEGA)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_AUTO_MEGA))
|
||||
);
|
||||
}
|
||||
if (!force && size_x * size_z > Settings.Claim.MAX_AUTO_AREA) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots_num"),
|
||||
Template.of("amount", String.valueOf(Settings.Claim.MAX_AUTO_AREA)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots_num"),
|
||||
Template.of("amount", String.valueOf(Settings.Claim.MAX_AUTO_AREA))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final int allowed_plots = player.getAllowedPlots();
|
||||
try (final MetaDataAccess<Boolean> metaDataAccess =
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||
if (!force && (metaDataAccess.get().orElse(false) || !checkAllowedPlots(player,
|
||||
plotarea, allowed_plots, size_x, size_z))) {
|
||||
plotarea, allowed_plots, size_x, size_z
|
||||
))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -266,8 +292,11 @@ public class Auto extends SubCommand {
|
||||
);
|
||||
return true;
|
||||
}
|
||||
if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC.format(schematic)) && !Permissions
|
||||
.hasPermission(player, "plots.admin.command.schematic")) {
|
||||
if (!force && !Permissions.hasPermission(
|
||||
player,
|
||||
Permission.PERMISSION_CLAIM_SCHEMATIC.format(schematic)
|
||||
) && !Permissions
|
||||
.hasPermission(player, "plots.admin.command.schematic")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", "plots.claim.%s0")
|
||||
@ -278,8 +307,8 @@ public class Auto extends SubCommand {
|
||||
if (this.econHandler != null && plotarea.useEconomy()) {
|
||||
PlotExpression costExp = plotarea.getPrices().get("claim");
|
||||
double cost = costExp.evaluate(Settings.Limit.GLOBAL ?
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(plotarea.getWorldName()));
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(plotarea.getWorldName()));
|
||||
cost = (size_x * size_z) * cost;
|
||||
if (cost > 0d) {
|
||||
if (!force && this.econHandler.getMoney(player) < cost) {
|
||||
@ -299,9 +328,9 @@ public class Auto extends SubCommand {
|
||||
}
|
||||
|
||||
final List<Plot> plots = this.servicePipeline
|
||||
.pump(new AutoService.AutoQuery(player, null, size_x, size_z, plotarea))
|
||||
.through(AutoService.class)
|
||||
.getResult();
|
||||
.pump(new AutoService.AutoQuery(player, null, size_x, size_z, plotarea))
|
||||
.through(AutoService.class)
|
||||
.getResult();
|
||||
|
||||
if (plots.isEmpty()) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.no_free_plots"));
|
||||
@ -313,12 +342,14 @@ public class Auto extends SubCommand {
|
||||
while (plotIterator.hasNext()) {
|
||||
plotIterator.next().claim(player, !plotIterator.hasNext(), null);
|
||||
}
|
||||
final PlotAutoMergeEvent mergeEvent = this.eventDispatcher.callAutoMerge(plots.get(0),
|
||||
plots.stream().map(Plot::getId).collect(Collectors.toList()));
|
||||
final PlotAutoMergeEvent mergeEvent = this.eventDispatcher.callAutoMerge(
|
||||
plots.get(0),
|
||||
plots.stream().map(Plot::getId).collect(Collectors.toList())
|
||||
);
|
||||
if (!force && mergeEvent.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Auto merge")
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Auto merge")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@ -326,4 +357,5 @@ public class Auto extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.nio.file.Files;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
@ -57,15 +57,16 @@ import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@CommandDeclaration(command = "backup",
|
||||
usage = "/plot backup <save | list | load>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup")
|
||||
usage = "/plot backup <save | list | load>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup")
|
||||
public final class Backup extends Command {
|
||||
|
||||
private final BackupManager backupManager;
|
||||
|
||||
@Inject public Backup(@Nonnull final BackupManager backupManager) {
|
||||
@Inject
|
||||
public Backup(final @NonNull BackupManager backupManager) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.backupManager = backupManager;
|
||||
}
|
||||
@ -79,22 +80,25 @@ public final class Backup extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
if (args.length == 0 || !Arrays.asList("save", "list", "load")
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||
return CompletableFuture.completedFuture(sendMessage(player));
|
||||
}
|
||||
return super.execute(player, args, confirm, whenDone);
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
||||
if (args.length == 1) {
|
||||
return Stream.of("save", "list", "load")
|
||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
} else if (args[0].equalsIgnoreCase("load")) {
|
||||
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
@ -102,17 +106,18 @@ public final class Backup extends Command {
|
||||
final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
|
||||
if (backupProfile instanceof PlayerBackupProfile) {
|
||||
final CompletableFuture<List<com.plotsquared.core.backup.Backup>> backupList =
|
||||
backupProfile.listBackups();
|
||||
backupProfile.listBackups();
|
||||
if (backupList.isDone()) {
|
||||
final List<com.plotsquared.core.backup.Backup> backups =
|
||||
backupList.getNow(new ArrayList<>());
|
||||
backupList.getNow(new ArrayList<>());
|
||||
if (backups.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return IntStream.range(1, 1 + backups.size()).mapToObj(
|
||||
i -> new Command(null, false, Integer.toString(i), "",
|
||||
RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
i -> new Command(null, false, Integer.toString(i), "",
|
||||
RequiredType.NONE, null
|
||||
) {
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
}
|
||||
@ -122,13 +127,15 @@ public final class Backup extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "save",
|
||||
usage = "/plot backup save",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup.save")
|
||||
public void save(final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
usage = "/plot backup save",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup.save")
|
||||
public void save(
|
||||
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||
@ -145,7 +152,7 @@ public final class Backup extends Command {
|
||||
Template.of("plot", "generic.generic_merged")
|
||||
);
|
||||
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
||||
@ -174,13 +181,15 @@ public final class Backup extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "list",
|
||||
usage = "/plot backup list",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup.list")
|
||||
public void list(final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
usage = "/plot backup list",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup.list")
|
||||
public void list(
|
||||
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||
@ -195,7 +204,7 @@ public final class Backup extends Command {
|
||||
Template.of("plot", "generic.generic_merged")
|
||||
);
|
||||
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
||||
@ -227,7 +236,8 @@ public final class Backup extends Command {
|
||||
Template.of("number", Integer.toString(i + 1)),
|
||||
Template.of("value", DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.ofInstant(
|
||||
Instant.ofEpochMilli(backups.get(i).getCreationTime()),
|
||||
ZoneId.systemDefault())))
|
||||
ZoneId.systemDefault()
|
||||
)))
|
||||
);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
@ -240,13 +250,15 @@ public final class Backup extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "load",
|
||||
usage = "/plot backup load <#>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup.load")
|
||||
public void load(final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
usage = "/plot backup load <#>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.backup.load")
|
||||
public void load(
|
||||
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||
@ -265,7 +277,7 @@ public final class Backup extends Command {
|
||||
Template.of("plot", "generic.generic_merged")
|
||||
);
|
||||
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
||||
@ -308,26 +320,27 @@ public final class Backup extends Command {
|
||||
);
|
||||
} else {
|
||||
final com.plotsquared.core.backup.Backup backup =
|
||||
backups.get(number - 1);
|
||||
backups.get(number - 1);
|
||||
if (backup == null || backup.getFile() == null || !Files
|
||||
.exists(backup.getFile())) {
|
||||
.exists(backup.getFile())) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("backup_impossible"),
|
||||
Template.of("plot", "generic.generic_invalid_choice")
|
||||
);
|
||||
} else {
|
||||
CmdConfirm.addPending(player, "/plot backup load " + number,
|
||||
() -> backupProfile.restoreBackup(backup, player)
|
||||
.whenComplete((n, error) -> {
|
||||
if (error != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("backups.backup_load_failure"),
|
||||
Template.of("reason", error.getMessage())
|
||||
);
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("backups.backup_load_success"));
|
||||
}
|
||||
}));
|
||||
() -> backupProfile.restoreBackup(backup, player)
|
||||
.whenComplete((n, error) -> {
|
||||
if (error != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("backups.backup_load_failure"),
|
||||
Template.of("reason", error.getMessage())
|
||||
);
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("backups.backup_load_success"));
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,26 +39,32 @@ import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "setbiome",
|
||||
permission = "plots.set.biome",
|
||||
usage = "/plot biome [biome]",
|
||||
aliases = {"biome", "sb", "setb", "b"},
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.NONE)
|
||||
permission = "plots.set.biome",
|
||||
usage = "/plot biome [biome]",
|
||||
aliases = {"biome", "sb", "setb", "b"},
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Biome extends SetCommand {
|
||||
|
||||
@Override public boolean set(final PlotPlayer player, final Plot plot, final String value) {
|
||||
@Override
|
||||
public boolean set(final PlotPlayer player, final Plot plot, final String value) {
|
||||
BiomeType biome = null;
|
||||
try {
|
||||
biome = BiomeTypes.get(value.toLowerCase());
|
||||
} catch (final Exception ignore) {
|
||||
}
|
||||
if (biome == null) {
|
||||
String biomes = StringMan.join(BiomeType.REGISTRY.values(),
|
||||
MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("blocklist.block_list_separator").getComponent(player))));
|
||||
String biomes = StringMan.join(
|
||||
BiomeType.REGISTRY.values(),
|
||||
MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption
|
||||
.of("blocklist.block_list_separator")
|
||||
.getComponent(player)))
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("biome.need_biome"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.subcommand_set_options_header"),
|
||||
Template.of("values", biomes));
|
||||
Template.of("values", biomes)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (plot.getRunning() > 0) {
|
||||
@ -83,10 +89,10 @@ public class Biome extends SetCommand {
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
return SuggestionHelper.getNamespacedRegistrySuggestions(BiomeType.REGISTRY, args[0])
|
||||
.map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", ""))
|
||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
.map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", ""))
|
||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,32 +40,37 @@ import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "buy",
|
||||
usage = "/plot buy",
|
||||
permission = "plots.buy",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE)
|
||||
usage = "/plot buy",
|
||||
permission = "plots.buy",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Buy extends Command {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final EconHandler econHandler;
|
||||
|
||||
@Inject public Buy(@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final EconHandler econHandler) {
|
||||
@Inject
|
||||
public Buy(
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull EconHandler econHandler
|
||||
) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.econHandler = econHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
|
||||
PlotArea area = player.getPlotAreaAbs();
|
||||
check(area, TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
@ -83,17 +88,21 @@ public class Buy extends Command {
|
||||
checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
|
||||
checkTrue(!plot.isOwner(player.getUUID()), TranslatableCaption.of("economy.cannot_buy_own"));
|
||||
Set<Plot> plots = plot.getConnectedPlots();
|
||||
checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(player.getAllowedPlots())));
|
||||
checkTrue(
|
||||
player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(player.getAllowedPlots()))
|
||||
);
|
||||
double price = plot.getFlag(PriceFlag.class);
|
||||
if (price <= 0) {
|
||||
throw new CommandException(TranslatableCaption.of("economy.not_for_sale"));
|
||||
}
|
||||
checkTrue(this.econHandler.getMoney(player) >= price,
|
||||
checkTrue(
|
||||
this.econHandler.getMoney(player) >= price,
|
||||
TranslatableCaption.of("economy.cannot_afford_plot"),
|
||||
Template.of("money", this.econHandler.format(price)),
|
||||
Template.of("balance", this.econHandler.format(this.econHandler.getMoney(player))));
|
||||
Template.of("balance", this.econHandler.format(this.econHandler.getMoney(player)))
|
||||
);
|
||||
this.econHandler.withdrawMoney(player, price);
|
||||
// Failure
|
||||
// Success
|
||||
@ -128,4 +137,5 @@ public class Buy extends Command {
|
||||
});
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,21 +47,23 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
|
||||
@CommandDeclaration(command = "caps",
|
||||
category = CommandCategory.INFO,
|
||||
usage = "/plot caps")
|
||||
category = CommandCategory.INFO,
|
||||
usage = "/plot caps")
|
||||
public class Caps extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||
return false;
|
||||
}
|
||||
if (!plot.isAdded(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_CAPS_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_CAPS_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_CAPS_OTHER)));
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_CAPS_OTHER))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (plot.getVolume() > Integer.MAX_VALUE) {
|
||||
@ -79,9 +81,11 @@ public class Caps extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
private <T extends PlotFlag<Integer, T>> void sendFormatted(final Plot plot,
|
||||
final PlotPlayer<?> player, final Class<T> capFlag, final int[] countedEntities,
|
||||
final String name, final int type) {
|
||||
private <T extends PlotFlag<Integer, T>> void sendFormatted(
|
||||
final Plot plot,
|
||||
final PlotPlayer<?> player, final Class<T> capFlag, final int[] countedEntities,
|
||||
final String name, final int type
|
||||
) {
|
||||
final int current = countedEntities[type];
|
||||
final int max = plot.getFlag(capFlag);
|
||||
final String percentage = String.format("%.1f", 100 * ((float) current / max));
|
||||
@ -90,6 +94,8 @@ public class Caps extends SubCommand {
|
||||
Template.of("cap", name),
|
||||
Template.of("current", String.valueOf(current)),
|
||||
Template.of("limit", String.valueOf(max)),
|
||||
Template.of("percentage", percentage));
|
||||
Template.of("percentage", percentage)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,13 +29,14 @@ import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
|
||||
@CommandDeclaration(command = "chat",
|
||||
usage = "/plot chat",
|
||||
permission = "plots.chat",
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
usage = "/plot chat",
|
||||
permission = "plots.chat",
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Chat extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (player.getPlotAreaAbs().isForcingPlotChat()) {
|
||||
player.sendMessage(TranslatableCaption.of("chat.plot_chat_forced"));
|
||||
return true;
|
||||
@ -43,4 +44,5 @@ public class Chat extends SubCommand {
|
||||
MainCommand.getInstance().toggle.chat(this, player, args, null, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,11 +46,10 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotExpression;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "claim",
|
||||
aliases = "c",
|
||||
@ -60,18 +59,22 @@ import javax.annotation.Nonnull;
|
||||
public class Claim extends SubCommand {
|
||||
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger("P2/" + Claim.class.getSimpleName());
|
||||
LoggerFactory.getLogger("P2/" + Claim.class.getSimpleName());
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final EconHandler econHandler;
|
||||
|
||||
@Inject public Claim(@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final EconHandler econHandler) {
|
||||
@Inject
|
||||
public Claim(
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull EconHandler econHandler
|
||||
) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.econHandler = econHandler;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
String schematic = null;
|
||||
if (args.length >= 1) {
|
||||
schematic = args[0];
|
||||
@ -87,13 +90,14 @@ public class Claim extends SubCommand {
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Claim"));
|
||||
Template.of("value", "Claim")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
int currentPlots = Settings.Limit.GLOBAL ?
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(location.getWorldName());
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(location.getWorldName());
|
||||
|
||||
final PlotArea area = plot.getArea();
|
||||
|
||||
@ -104,12 +108,16 @@ public class Claim extends SubCommand {
|
||||
grants = metaDataAccess.get().orElse(0);
|
||||
if (grants <= 0) {
|
||||
metaDataAccess.remove();
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(grants)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(grants))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(grants)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||
Template.of("amount", String.valueOf(grants))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,51 +129,54 @@ public class Claim extends SubCommand {
|
||||
if (area.isSchematicClaimSpecify()) {
|
||||
if (!area.hasSchematic(schematic)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("schematics.schematic_invalid_named"),
|
||||
Template.of("schemname", schematic),
|
||||
Template.of("reason", "non-existant")
|
||||
);
|
||||
}
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC
|
||||
.format(schematic)) && !Permissions.hasPermission(player, "plots.admin.command.schematic") && !force) {
|
||||
TranslatableCaption.of("schematics.schematic_invalid_named"),
|
||||
Template.of("schemname", schematic),
|
||||
Template.of("reason", "non-existant")
|
||||
);
|
||||
}
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC
|
||||
.format(schematic)) && !Permissions.hasPermission(
|
||||
player,
|
||||
"plots.admin.command.schematic"
|
||||
) && !force) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_schematic_permission"),
|
||||
Template.of("value", schematic)
|
||||
);
|
||||
TranslatableCaption.of("permission.no_schematic_permission"),
|
||||
Template.of("value", schematic)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.econHandler.isEnabled(area) && !force) {
|
||||
PlotExpression costExr = area.getPrices().get("claim");
|
||||
double cost = costExr.evaluate(currentPlots);
|
||||
if (cost > 0d) {
|
||||
if (this.econHandler.getMoney(player) < cost) {
|
||||
if (this.econHandler.isEnabled(area) && !force) {
|
||||
PlotExpression costExr = area.getPrices().get("claim");
|
||||
double cost = costExr.evaluate(currentPlots);
|
||||
if (cost > 0d) {
|
||||
if (this.econHandler.getMoney(player) < cost) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("economy.cannot_afford_plot"),
|
||||
Template.of("money", this.econHandler.format(cost)),
|
||||
Template.of("balance", this.econHandler.format(this.econHandler.getMoney(player)))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
this.econHandler.withdrawMoney(player, cost);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("economy.cannot_afford_plot"),
|
||||
TranslatableCaption.of("economy.removed_balance"),
|
||||
Template.of("money", this.econHandler.format(cost)),
|
||||
Template.of("balance", this.econHandler.format(this.econHandler.getMoney(player)))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
this.econHandler.withdrawMoney(player, cost);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("economy.removed_balance"),
|
||||
Template.of("money", this.econHandler.format(cost)),
|
||||
Template.of("balance", this.econHandler.format(this.econHandler.getMoney(player)))
|
||||
);
|
||||
}
|
||||
}
|
||||
if (grants > 0) {
|
||||
if (grants == 1) {
|
||||
metaDataAccess.remove();
|
||||
if (grants > 0) {
|
||||
if (grants == 1) {
|
||||
metaDataAccess.remove();
|
||||
} else {
|
||||
metaDataAccess.set(grants - 1);
|
||||
}
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("economy.removed_granted_plot"),
|
||||
Template.of("usedGrants", String.valueOf((grants -1))),
|
||||
Template.of("remainingGrants", String.valueOf(grants))
|
||||
);
|
||||
TranslatableCaption.of("economy.removed_granted_plot"),
|
||||
Template.of("usedGrants", String.valueOf((grants - 1))),
|
||||
Template.of("remainingGrants", String.valueOf(grants))
|
||||
);
|
||||
}
|
||||
}
|
||||
int border = area.getBorder();
|
||||
@ -184,14 +195,20 @@ public class Claim extends SubCommand {
|
||||
plot.setOwnerAbs(null);
|
||||
} else if (area.isAutoMerge()) {
|
||||
PlotMergeEvent mergeEvent = Claim.this.eventDispatcher
|
||||
.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player);
|
||||
.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player);
|
||||
if (mergeEvent.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Auto merge on claim")
|
||||
);
|
||||
} else {
|
||||
plot.getPlotModificationManager().autoMerge(mergeEvent.getDir(), mergeEvent.getMax(), player.getUUID(), player, true);
|
||||
plot.getPlotModificationManager().autoMerge(
|
||||
mergeEvent.getDir(),
|
||||
mergeEvent.getMax(),
|
||||
player.getUUID(),
|
||||
player,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -206,4 +223,5 @@ public class Claim extends SubCommand {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,34 +42,40 @@ import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import javax.annotation.Nonnull;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "clear",
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.clear",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
usage = "/plot clear",
|
||||
aliases = "reset",
|
||||
confirmation = true)
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.clear",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
usage = "/plot clear",
|
||||
aliases = "reset",
|
||||
confirmation = true)
|
||||
public class Clear extends Command {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
|
||||
@Inject public Clear(@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final GlobalBlockQueue blockQueue) {
|
||||
@Inject
|
||||
public Clear(
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull GlobalBlockQueue blockQueue
|
||||
) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.blockQueue = blockQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
if (args.length != 0) {
|
||||
sendUsage(player);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
@ -79,7 +85,8 @@ public class Clear extends Command {
|
||||
if (eventResult == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Clear"));
|
||||
Template.of("value", "Clear")
|
||||
);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
if (plot.getVolume() > Integer.MAX_VALUE) {
|
||||
@ -87,12 +94,14 @@ public class Clear extends Command {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
boolean force = eventResult == Result.FORCE;
|
||||
checkTrue(force || plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, "plots.admin.command.clear"),
|
||||
TranslatableCaption.of("permission.no_plot_perms"));
|
||||
checkTrue(
|
||||
force || plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, "plots.admin.command.clear"),
|
||||
TranslatableCaption.of("permission.no_plot_perms")
|
||||
);
|
||||
checkTrue(plot.getRunning() == 0, TranslatableCaption.of("errors.wait_for_timer"));
|
||||
checkTrue(force || !Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot) || Permissions
|
||||
.hasPermission(player, "plots.continue"), TranslatableCaption.of("done.done_already_done"));
|
||||
.hasPermission(player, "plots.continue"), TranslatableCaption.of("done.done_already_done"));
|
||||
confirm.run(this, () -> {
|
||||
if (Settings.Teleport.ON_CLEAR) {
|
||||
plot.teleportPlayer(player, TeleportCause.COMMAND, result -> {
|
||||
@ -107,18 +116,18 @@ public class Clear extends Command {
|
||||
// If the state changes, then mark it as no longer done
|
||||
if (DoneFlag.isDone(plot)) {
|
||||
PlotFlag<?, ?> plotFlag =
|
||||
plot.getFlagContainer().getFlag(DoneFlag.class);
|
||||
plot.getFlagContainer().getFlag(DoneFlag.class);
|
||||
PlotFlagRemoveEvent event = this.eventDispatcher
|
||||
.callFlagRemove(plotFlag, plot);
|
||||
.callFlagRemove(plotFlag, plot);
|
||||
if (event.getEventResult() != Result.DENY) {
|
||||
plot.removeFlag(event.getFlag());
|
||||
}
|
||||
}
|
||||
if (!plot.getFlag(AnalysisFlag.class).isEmpty()) {
|
||||
PlotFlag<?, ?> plotFlag =
|
||||
plot.getFlagContainer().getFlag(AnalysisFlag.class);
|
||||
plot.getFlagContainer().getFlag(AnalysisFlag.class);
|
||||
PlotFlagRemoveEvent event = this.eventDispatcher
|
||||
.callFlagRemove(plotFlag, plot);
|
||||
.callFlagRemove(plotFlag, plot);
|
||||
if (event.getEventResult() != Result.DENY) {
|
||||
plot.removeFlag(event.getFlag());
|
||||
}
|
||||
@ -139,4 +148,5 @@ public class Clear extends Command {
|
||||
}, null);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,6 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
@ -34,6 +33,7 @@ import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.location.BlockLoc;
|
||||
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.plot.PlotArea;
|
||||
@ -55,13 +55,14 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "cluster",
|
||||
aliases = "clusters",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.cluster")
|
||||
aliases = "clusters",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.cluster")
|
||||
public class Cluster extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
||||
if (args.length == 0) {
|
||||
@ -146,8 +147,8 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
int currentClusters = Settings.Limit.GLOBAL ?
|
||||
player.getClusterCount() :
|
||||
player.getPlotCount(player.getLocation().getWorldName());
|
||||
player.getClusterCount() :
|
||||
player.getPlotCount(player.getLocation().getWorldName());
|
||||
if (currentClusters >= player.getAllowedPlots()) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_clusters"));
|
||||
}
|
||||
@ -192,7 +193,7 @@ public class Cluster extends SubCommand {
|
||||
Set<Plot> plots = area.getPlotSelectionOwned(pos1, pos2);
|
||||
if (!plots.isEmpty()) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_CREATE_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_CREATE_OTHER)) {
|
||||
UUID uuid = player.getUUID();
|
||||
for (Plot plot : plots) {
|
||||
if (!plot.isOwner(uuid)) {
|
||||
@ -214,8 +215,9 @@ public class Cluster extends SubCommand {
|
||||
current = player.getPlayerClusterCount(player.getLocation().getWorldName());
|
||||
}
|
||||
int allowed = Permissions
|
||||
.hasPermissionRange(player, Permission.PERMISSION_CLUSTER_SIZE,
|
||||
Settings.Limit.MAX_PLOTS);
|
||||
.hasPermissionRange(player, Permission.PERMISSION_CLUSTER_SIZE,
|
||||
Settings.Limit.MAX_PLOTS
|
||||
);
|
||||
if (current + cluster.getArea() > allowed) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
@ -280,10 +282,11 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.owner.equals(player.getUUID())) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_DELETE_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_DELETE_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_DELETE_OTHER)));
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_DELETE_OTHER))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -296,7 +299,8 @@ public class Cluster extends SubCommand {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_RESIZE)));
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_RESIZE))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 3) {
|
||||
@ -333,10 +337,11 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_RESIZE_OTHER)));
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_RESIZE_OTHER))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -358,7 +363,7 @@ public class Cluster extends SubCommand {
|
||||
// Check expand / shrink
|
||||
if (!removed.isEmpty()) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE_SHRINK)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE_SHRINK)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_RESIZE_SHRINK))
|
||||
@ -369,7 +374,7 @@ public class Cluster extends SubCommand {
|
||||
newPlots.removeAll(existing);
|
||||
if (!newPlots.isEmpty()) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE_EXPAND)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE_EXPAND)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_CLUSTER_RESIZE_EXPAND))
|
||||
@ -386,7 +391,8 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
current -= cluster.getArea() + (1 + pos2.getX() - pos1.getX()) * (1 + pos2.getY() - pos1.getY());
|
||||
int allowed = Permissions.hasPermissionRange(player, Permission.PERMISSION_CLUSTER,
|
||||
Settings.Limit.MAX_PLOTS);
|
||||
Settings.Limit.MAX_PLOTS
|
||||
);
|
||||
if (current + cluster.getArea() > allowed) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
@ -428,7 +434,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_INVITE_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_INVITE_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_CLUSTER_INVITE_OTHER.toString())
|
||||
@ -438,31 +444,31 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(args[1], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (throwable != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[1])
|
||||
);
|
||||
} else {
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
// add the user if not added
|
||||
cluster.invited.add(uuid);
|
||||
DBFunc.setInvited(cluster, uuid);
|
||||
final PlotPlayer otherPlayer =
|
||||
PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
||||
if (otherPlayer != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("cluster.cluster_invited"),
|
||||
Template.of("cluster", cluster.getName())
|
||||
);
|
||||
.getSingle(args[1], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (throwable != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[1])
|
||||
);
|
||||
} else {
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
// add the user if not added
|
||||
cluster.invited.add(uuid);
|
||||
DBFunc.setInvited(cluster, uuid);
|
||||
final PlotPlayer otherPlayer =
|
||||
PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
||||
if (otherPlayer != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("cluster.cluster_invited"),
|
||||
Template.of("cluster", cluster.getName())
|
||||
);
|
||||
}
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_added_user"));
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_added_user"));
|
||||
}
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "k":
|
||||
@ -493,7 +499,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_KICK_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_KICK_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_CLUSTER_KICK_OTHER.toString())
|
||||
@ -503,49 +509,49 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
// check uuid
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(args[1], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (throwable != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[1])
|
||||
);
|
||||
} else {
|
||||
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
||||
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner)
|
||||
|| !cluster.isAdded(uuid)) {
|
||||
.getSingle(args[1], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (throwable != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("cluster.cannot_kick_player"),
|
||||
Template.of("value", cluster.getName())
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[1])
|
||||
);
|
||||
} else {
|
||||
if (cluster.helpers.contains(uuid)) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
}
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
|
||||
final PlotPlayer player2 =
|
||||
PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
||||
if (player2 != null) {
|
||||
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
||||
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner)
|
||||
|| !cluster.isAdded(uuid)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("cluster.cluster_removed"),
|
||||
Template.of("cluster", cluster.getName())
|
||||
TranslatableCaption.of("cluster.cannot_kick_player"),
|
||||
Template.of("value", cluster.getName())
|
||||
);
|
||||
}
|
||||
for (final Plot plot : PlotQuery.newQuery().inWorld(player2.getLocation()
|
||||
.getWorldName()).ownedBy(uuid)) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
plot.unclaim();
|
||||
} else {
|
||||
if (cluster.helpers.contains(uuid)) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
}
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
|
||||
final PlotPlayer player2 =
|
||||
PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
||||
if (player2 != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("cluster.cluster_removed"),
|
||||
Template.of("cluster", cluster.getName())
|
||||
);
|
||||
}
|
||||
for (final Plot plot : PlotQuery.newQuery().inWorld(player2.getLocation()
|
||||
.getWorldName()).ownedBy(uuid)) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_kicked_user"));
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_kicked_user"));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "quit":
|
||||
@ -605,7 +611,7 @@ public class Cluster extends SubCommand {
|
||||
Template.of("cluster", cluster.getName())
|
||||
);
|
||||
for (final Plot plot : PlotQuery.newQuery().inWorld(player.getLocation().getWorldName())
|
||||
.ownedBy(uuid)) {
|
||||
.ownedBy(uuid)) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
plot.unclaim();
|
||||
@ -639,31 +645,31 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(args[2], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (throwable != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[2])
|
||||
);
|
||||
} else {
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
cluster.helpers.add(uuid);
|
||||
DBFunc.setHelper(cluster, uuid);
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_added_helper"));
|
||||
} else if (args[1].equalsIgnoreCase("remove")) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_removed_helper"));
|
||||
} else {
|
||||
.getSingle(args[2], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (throwable != null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot cluster members <add | remove> <player>")
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[2])
|
||||
);
|
||||
} else {
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
cluster.helpers.add(uuid);
|
||||
DBFunc.setHelper(cluster, uuid);
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_added_helper"));
|
||||
} else if (args[1].equalsIgnoreCase("remove")) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_removed_helper"));
|
||||
} else {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot cluster members <add | remove> <player>")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "spawn":
|
||||
@ -752,29 +758,36 @@ public class Cluster extends SubCommand {
|
||||
String id = cluster.toString();
|
||||
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(cluster.owner, (username, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else {
|
||||
final String owner;
|
||||
if (username == null) {
|
||||
owner = "unknown";
|
||||
.getSingle(cluster.owner, (username, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else {
|
||||
owner = username;
|
||||
final String owner;
|
||||
if (username == null) {
|
||||
owner = "unknown";
|
||||
} else {
|
||||
owner = username;
|
||||
}
|
||||
String name = cluster.getName();
|
||||
String size = (cluster.getP2().getX() - cluster.getP1().getX() + 1) + "x" + (
|
||||
cluster.getP2().getY() - cluster.getP1().getY() + 1);
|
||||
String rights = cluster.isAdded(player.getUUID()) + "";
|
||||
Caption message = TranslatableCaption.of("cluster.cluster_info");
|
||||
Template idTemplate = Template.of("id", id);
|
||||
Template ownerTemplate = Template.of("owner", owner);
|
||||
Template nameTemplate = Template.of("name", name);
|
||||
Template sizeTemplate = Template.of("size", size);
|
||||
Template rightsTemplate = Template.of("rights", rights);
|
||||
player.sendMessage(
|
||||
message,
|
||||
idTemplate,
|
||||
ownerTemplate,
|
||||
nameTemplate,
|
||||
sizeTemplate,
|
||||
rightsTemplate
|
||||
);
|
||||
}
|
||||
String name = cluster.getName();
|
||||
String size = (cluster.getP2().getX() - cluster.getP1().getX() + 1) + "x" + (
|
||||
cluster.getP2().getY() - cluster.getP1().getY() + 1);
|
||||
String rights = cluster.isAdded(player.getUUID()) + "";
|
||||
Caption message = TranslatableCaption.of("cluster.cluster_info");
|
||||
Template idTemplate = Template.of("id", id);
|
||||
Template ownerTemplate = Template.of("owner", owner);
|
||||
Template nameTemplate = Template.of("name", name);
|
||||
Template sizeTemplate = Template.of("size", size);
|
||||
Template rightsTemplate = Template.of("rights", rights);
|
||||
player.sendMessage(message, idTemplate, ownerTemplate, nameTemplate, sizeTemplate, rightsTemplate);
|
||||
}
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "sh":
|
||||
@ -805,7 +818,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_SETHOME_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_CLUSTER_SETHOME_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_CLUSTER_SETHOME_OTHER.toString())
|
||||
@ -817,13 +830,16 @@ public class Cluster extends SubCommand {
|
||||
Location relative = player.getLocation().subtract(base.getX(), 0, base.getZ());
|
||||
BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
||||
cluster.settings.setPosition(blockloc);
|
||||
DBFunc.setPosition(cluster,
|
||||
relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||
DBFunc.setPosition(
|
||||
cluster,
|
||||
relative.getX() + "," + relative.getY() + "," + relative.getZ()
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("position.position_set"));
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_available_args"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
@ -861,8 +877,17 @@ public class Cluster extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_SETHOME)) {
|
||||
completions.add("sethome");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(
|
||||
null,
|
||||
true,
|
||||
completion,
|
||||
"",
|
||||
RequiredType.NONE,
|
||||
CommandCategory.ADMINISTRATION
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
@ -871,4 +896,5 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,27 +32,28 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class CmdConfirm {
|
||||
|
||||
@Nullable public static CmdInstance getPending(PlotPlayer<?> player) {
|
||||
public @Nullable static CmdInstance getPending(PlotPlayer<?> player) {
|
||||
try (final MetaDataAccess<CmdInstance> metaDataAccess = player.accessTemporaryMetaData(
|
||||
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||
return metaDataAccess.get().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removePending(PlotPlayer<?> player) {
|
||||
try (final MetaDataAccess<CmdInstance> metaDataAccess = player.accessTemporaryMetaData(
|
||||
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||
metaDataAccess.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPending(final PlotPlayer<?> player, String commandStr,
|
||||
final Runnable runnable) {
|
||||
public static void addPending(
|
||||
final PlotPlayer<?> player, String commandStr,
|
||||
final Runnable runnable
|
||||
) {
|
||||
removePending(player);
|
||||
if (commandStr != null) {
|
||||
player.sendMessage(
|
||||
@ -64,9 +65,10 @@ public class CmdConfirm {
|
||||
TaskManager.runTaskLater(() -> {
|
||||
CmdInstance cmd = new CmdInstance(runnable);
|
||||
try (final MetaDataAccess<CmdInstance> metaDataAccess = player.accessTemporaryMetaData(
|
||||
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||
metaDataAccess.set(cmd);
|
||||
}
|
||||
}, TaskTime.ticks(1L));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
public class CmdInstance {
|
||||
|
||||
public final Runnable command;
|
||||
public final long timestamp;
|
||||
|
||||
@ -33,4 +34,5 @@ public class CmdInstance {
|
||||
this.command = command;
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@ -77,8 +77,10 @@ public abstract class Command {
|
||||
private CommandCategory category;
|
||||
private Argument[] arguments;
|
||||
|
||||
public Command(Command parent, boolean isStatic, String id, String permission,
|
||||
RequiredType required, CommandCategory category) {
|
||||
public Command(
|
||||
Command parent, boolean isStatic, String id, String permission,
|
||||
RequiredType required, CommandCategory category
|
||||
) {
|
||||
this.parent = parent;
|
||||
this.isStatic = isStatic;
|
||||
this.id = id;
|
||||
@ -104,13 +106,15 @@ public abstract class Command {
|
||||
// final PlotPlayer<?> player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult>
|
||||
// whenDone
|
||||
if (types.length == 5 && types[0] == Command.class && types[1] == PlotPlayer.class
|
||||
&& types[2] == String[].class && types[3] == RunnableVal3.class
|
||||
&& types[4] == RunnableVal2.class) {
|
||||
&& types[2] == String[].class && types[3] == RunnableVal3.class
|
||||
&& types[4] == RunnableVal2.class) {
|
||||
Command tmp = new Command(this, true) {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
try {
|
||||
method.invoke(Command.this, this, player, args, confirm, whenDone);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
@ -242,8 +246,10 @@ public abstract class Command {
|
||||
return "plots." + getFullId();
|
||||
}
|
||||
|
||||
public <T> void paginate(PlotPlayer<?> player, List<T> c, int size, int page,
|
||||
RunnableVal3<Integer, T, CaptionHolder> add, String baseCommand, Caption header) {
|
||||
public <T> void paginate(
|
||||
PlotPlayer<?> player, List<T> c, int size, int page,
|
||||
RunnableVal3<Integer, T, CaptionHolder> add, String baseCommand, Caption header
|
||||
) {
|
||||
// Calculate pages & index
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
@ -299,11 +305,13 @@ public abstract class Command {
|
||||
* @param confirm Instance, Success, Failure
|
||||
* @param whenDone task to run when done
|
||||
* @return CompletableFuture true if the command executed fully, false in
|
||||
* any other case
|
||||
* any other case
|
||||
*/
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
if (args.length == 0 || args[0] == null) {
|
||||
if (this.parent == null) {
|
||||
MainCommand.getInstance().help.displayHelp(player, null, 0);
|
||||
@ -338,8 +346,10 @@ public abstract class Command {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.not_valid_subcommand"));
|
||||
List<Command> commands = getCommands(player);
|
||||
if (commands.isEmpty()) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of("value", MainCommand.getInstance().help.getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of("value", MainCommand.getInstance().help.getUsage())
|
||||
);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
HashSet<String> setArgs = new HashSet<>(args.length);
|
||||
@ -357,8 +367,10 @@ public abstract class Command {
|
||||
if (cmd == null) {
|
||||
cmd = new StringComparison<>(args[0], this.allCommands).getMatchObject();
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of("value", cmd.getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of("value", cmd.getUsage())
|
||||
);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
@ -391,8 +403,10 @@ public abstract class Command {
|
||||
}
|
||||
if (failed) {
|
||||
// TODO improve or remove the Argument system
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", StringMan.join(fullSplit, " ")));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", StringMan.join(fullSplit, " "))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -402,7 +416,7 @@ public abstract class Command {
|
||||
public int getMatch(String[] args, Command cmd, PlotPlayer<?> player) {
|
||||
String perm = cmd.getPermission();
|
||||
int count = cmd.getAliases().stream().filter(alias -> alias.startsWith(args[0]))
|
||||
.mapToInt(alias -> 5).sum();
|
||||
.mapToInt(alias -> 5).sum();
|
||||
HashSet<String> desc = new HashSet<>();
|
||||
Collections.addAll(desc, cmd.getDescription().getComponent(player).split(" "));
|
||||
for (String arg : args) {
|
||||
@ -478,8 +492,10 @@ public abstract class Command {
|
||||
}
|
||||
} else if (!Permissions.hasPermission(player, getPermission())) {
|
||||
if (message) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", getPermission()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", getPermission())
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
@ -501,8 +517,10 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public void sendUsage(PlotPlayer<?> player) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", getUsage())
|
||||
);
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
@ -524,8 +542,10 @@ public abstract class Command {
|
||||
return getCommandString() + " " + args + "]";
|
||||
}
|
||||
|
||||
public Collection<Command> tabOf(PlotPlayer<?> player, String[] input, boolean space,
|
||||
String... args) {
|
||||
public Collection<Command> tabOf(
|
||||
PlotPlayer<?> player, String[] input, boolean space,
|
||||
String... args
|
||||
) {
|
||||
if (!space) {
|
||||
return null;
|
||||
}
|
||||
@ -562,7 +582,7 @@ public abstract class Command {
|
||||
Set<Command> commands = new HashSet<>();
|
||||
for (Map.Entry<String, Command> entry : this.staticCommands.entrySet()) {
|
||||
if (entry.getKey().startsWith(arg) && entry.getValue()
|
||||
.canExecute(player, false)) {
|
||||
.canExecute(player, false)) {
|
||||
commands.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
@ -578,11 +598,13 @@ public abstract class Command {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return !this.aliases.isEmpty() ? this.aliases.get(0) : this.id;
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object obj) {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
@ -596,7 +618,8 @@ public abstract class Command {
|
||||
return this.getFullId().equals(other.getFullId());
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getFullId().hashCode();
|
||||
}
|
||||
|
||||
@ -615,7 +638,8 @@ public abstract class Command {
|
||||
|
||||
|
||||
public enum CommandResult {
|
||||
FAILURE, SUCCESS
|
||||
FAILURE,
|
||||
SUCCESS
|
||||
}
|
||||
|
||||
|
||||
@ -624,15 +648,17 @@ public abstract class Command {
|
||||
private final Template[] args;
|
||||
private final Caption message;
|
||||
|
||||
public CommandException(@Nullable final Caption message, final Template... args) {
|
||||
public CommandException(final @Nullable Caption message, final Template... args) {
|
||||
this.message = message;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public void perform(@Nullable final PlotPlayer<?> player) {
|
||||
public void perform(final @Nullable PlotPlayer<?> player) {
|
||||
if (player != null && message != null) {
|
||||
player.sendMessage(message, args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Any entity that is able to execute commands, receive messages & and have
|
||||
@ -42,7 +41,7 @@ public interface CommandCaller {
|
||||
* @param caption Caption to send
|
||||
* @param replacements Variable replacements
|
||||
*/
|
||||
void sendMessage(@Nonnull Caption caption, @Nonnull Template... replacements);
|
||||
void sendMessage(@NonNull Caption caption, @NonNull Template... replacements);
|
||||
|
||||
/**
|
||||
* Check the player's permissions. <i>Will be cached if permission caching is enabled.</i>
|
||||
@ -50,7 +49,7 @@ public interface CommandCaller {
|
||||
* @param permission the name of the permission
|
||||
* @return if permission is had
|
||||
*/
|
||||
boolean hasPermission(@Nonnull String permission);
|
||||
boolean hasPermission(@NonNull String permission);
|
||||
|
||||
/**
|
||||
* Get the type of the caller
|
||||
|
@ -28,8 +28,7 @@ package com.plotsquared.core.command;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.LocaleHolder;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* CommandCategory.
|
||||
@ -85,13 +84,15 @@ public enum CommandCategory implements Caption {
|
||||
}
|
||||
|
||||
// TODO this method shouldn't be invoked
|
||||
@Deprecated @Override public String toString() {
|
||||
@Deprecated
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.caption.getComponent(LocaleHolder.console());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NonNull
|
||||
@Override
|
||||
public String getComponent(@Nonnull LocaleHolder localeHolder) {
|
||||
public String getComponent(@NonNull LocaleHolder localeHolder) {
|
||||
return this.caption.getComponent(localeHolder);
|
||||
}
|
||||
}
|
||||
|
@ -49,4 +49,5 @@ public @interface CommandDeclaration {
|
||||
CommandCategory category() default CommandCategory.INFO;
|
||||
|
||||
boolean confirmation() default false;
|
||||
|
||||
}
|
||||
|
@ -40,13 +40,14 @@ import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandDeclaration(command = "comment",
|
||||
aliases = {"msg"},
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.comment")
|
||||
aliases = {"msg"},
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.comment")
|
||||
public class Comment extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("comment.comment_syntax"),
|
||||
@ -95,8 +96,9 @@ public class Comment extends SubCommand {
|
||||
|
||||
String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
|
||||
PlotComment comment =
|
||||
new PlotComment(player.getLocation().getWorldName(), plot.getId(), message,
|
||||
player.getName(), inbox.toString(), System.currentTimeMillis());
|
||||
new PlotComment(player.getLocation().getWorldName(), plot.getId(), message,
|
||||
player.getName(), inbox.toString(), System.currentTimeMillis()
|
||||
);
|
||||
boolean result = inbox.addComment(plot, comment);
|
||||
if (!result) {
|
||||
player.sendMessage(TranslatableCaption.of("comment.no_plot_inbox"));
|
||||
@ -117,4 +119,5 @@ public class Comment extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("comment.comment_added"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -49,10 +49,10 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@CommandDeclaration(command = "condense",
|
||||
permission = "plots.admin",
|
||||
usage = "/plot condense <area> <start|stop|info> [radius]",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.CONSOLE)
|
||||
permission = "plots.admin",
|
||||
usage = "/plot condense <area> <start|stop|info> [radius]",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.CONSOLE)
|
||||
public class Condense extends SubCommand {
|
||||
|
||||
public static boolean TASK = false;
|
||||
@ -60,13 +60,17 @@ public class Condense extends SubCommand {
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Condense(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public Condense(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull WorldUtil worldUtil
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
@ -157,7 +161,8 @@ public class Condense extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("condense.task_started"));
|
||||
Condense.TASK = true;
|
||||
Runnable run = new Runnable() {
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!Condense.TASK) {
|
||||
player.sendMessage(TranslatableCaption.of("condense.task_cancelled"));
|
||||
}
|
||||
@ -274,10 +279,11 @@ public class Condense extends SubCommand {
|
||||
HashSet<PlotId> outside = new HashSet<>();
|
||||
for (Plot plot : plots) {
|
||||
if (plot.getId().getX() > radius || plot.getId().getX() < -radius || plot.getId().getY() > radius
|
||||
|| plot.getId().getY() < -radius) {
|
||||
|| plot.getId().getY() < -radius) {
|
||||
outside.add(plot.getId());
|
||||
}
|
||||
}
|
||||
return outside;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,11 +31,12 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
|
||||
@CommandDeclaration(command = "confirm",
|
||||
permission = "plots.confirm",
|
||||
category = CommandCategory.INFO)
|
||||
permission = "plots.confirm",
|
||||
category = CommandCategory.INFO)
|
||||
public class Confirm extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
CmdInstance command = CmdConfirm.getPending(player);
|
||||
if (command == null) {
|
||||
player.sendMessage(TranslatableCaption.of("confirm.failed_confirm"));
|
||||
@ -43,11 +44,12 @@ public class Confirm extends SubCommand {
|
||||
}
|
||||
CmdConfirm.removePending(player);
|
||||
if ((System.currentTimeMillis() - command.timestamp)
|
||||
> Settings.Confirmation.CONFIRMATION_TIMEOUT_SECONDS * 1000) {
|
||||
> Settings.Confirmation.CONFIRMATION_TIMEOUT_SECONDS * 1000) {
|
||||
player.sendMessage(TranslatableCaption.of("confirm.expired_confirm"));
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTaskAsync(command.command);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,11 +26,11 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.PlotFlagRemoveEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
@ -38,29 +38,30 @@ import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@CommandDeclaration(command = "continue",
|
||||
permission = "plots.continue",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.continue",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Continue extends SubCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Continue(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
|
||||
@Inject
|
||||
public Continue(final @NonNull EventDispatcher eventDispatcher) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Plot plot = player.getCurrentPlot();
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_CONTINUE)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_CONTINUE)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", TranslatableCaption.of("permission.no_plot_perms").getComponent(player))
|
||||
@ -73,7 +74,7 @@ public class Continue extends SubCommand {
|
||||
}
|
||||
int size = plot.getConnectedPlots().size();
|
||||
if (Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots()
|
||||
< player.getPlotCount() + size)) {
|
||||
< player.getPlotCount() + size)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_COMMAND_CONTINUE.toString())
|
||||
@ -86,15 +87,17 @@ public class Continue extends SubCommand {
|
||||
}
|
||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class);
|
||||
PlotFlagRemoveEvent event =
|
||||
this.eventDispatcher.callFlagRemove(plotFlag, plot);
|
||||
this.eventDispatcher.callFlagRemove(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Done flag removal"));
|
||||
Template.of("value", "Done flag removal")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
plot.removeFlag(event.getFlag());
|
||||
player.sendMessage(TranslatableCaption.of("done.done_removed"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,23 +25,24 @@
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
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.Permissions;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
@CommandDeclaration(command = "copy",
|
||||
permission = "plots.copy",
|
||||
aliases = {"copypaste"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
usage = "/plot copy <X;Z>",
|
||||
requiredType = RequiredType.NONE)
|
||||
permission = "plots.copy",
|
||||
aliases = {"copypaste"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
usage = "/plot copy <X;Z>",
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Copy extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot1 = location.getPlotAbs();
|
||||
if (plot1 == null) {
|
||||
@ -49,7 +50,7 @@ public class Copy extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot1.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN.toString())) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN.toString())) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
@ -87,4 +88,5 @@ public class Copy extends SubCommand {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,24 +33,25 @@ import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@CommandDeclaration(command = "createroadschematic",
|
||||
aliases = {"crs"},
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.createroadschematic",
|
||||
usage = "/plot createroadschematic")
|
||||
aliases = {"crs"},
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
permission = "plots.createroadschematic",
|
||||
usage = "/plot createroadschematic")
|
||||
public class CreateRoadSchematic extends SubCommand {
|
||||
|
||||
private final HybridUtils hybridUtils;
|
||||
|
||||
@Inject public CreateRoadSchematic(@Nonnull final HybridUtils hybridUtils) {
|
||||
@Inject
|
||||
public CreateRoadSchematic(final @NonNull HybridUtils hybridUtils) {
|
||||
this.hybridUtils = hybridUtils;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -61,8 +62,11 @@ public class CreateRoadSchematic extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
}
|
||||
this.hybridUtils.setupRoadSchematic(plot);
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_road_created"),
|
||||
Template.of("command", "/plot debugroadregen"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("schematics.schematic_road_created"),
|
||||
Template.of("command", "/plot debugroadregen")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@ -59,11 +59,11 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@CommandDeclaration(command = "database",
|
||||
aliases = {"convert"},
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
permission = "plots.database",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
usage = "/plot database [area] <sqlite | mysql | import>")
|
||||
aliases = {"convert"},
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
permission = "plots.database",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
usage = "/plot database [area] <sqlite | mysql | import>")
|
||||
public class DatabaseCommand extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
@ -71,18 +71,23 @@ public class DatabaseCommand extends SubCommand {
|
||||
private final PlotListener plotListener;
|
||||
private final YamlConfiguration worldConfiguration;
|
||||
|
||||
@Inject public DatabaseCommand(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final PlotListener plotListener,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration) {
|
||||
@Inject
|
||||
public DatabaseCommand(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull PlotListener plotListener,
|
||||
@WorldConfig final @NonNull YamlConfiguration worldConfiguration
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.plotListener = plotListener;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
}
|
||||
|
||||
public static void insertPlots(final SQLManager manager, final List<Plot> plots,
|
||||
final PlotPlayer player) {
|
||||
public static void insertPlots(
|
||||
final SQLManager manager, final List<Plot> plots,
|
||||
final PlotPlayer player
|
||||
) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
ArrayList<Plot> ps = new ArrayList<>(plots);
|
||||
@ -98,7 +103,8 @@ public class DatabaseCommand extends SubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
@ -134,8 +140,10 @@ public class DatabaseCommand extends SubCommand {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
File file = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
args[1].endsWith(".db") ? args[1] : args[1] + ".db");
|
||||
File file = FileUtils.getFile(
|
||||
PlotSquared.platform().getDirectory(),
|
||||
args[1].endsWith(".db") ? args[1] : args[1] + ".db"
|
||||
);
|
||||
if (!file.exists()) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("database.does_not_exist"),
|
||||
@ -146,7 +154,8 @@ public class DatabaseCommand extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("database.starting_conversion"));
|
||||
implementation = new SQLite(file);
|
||||
SQLManager manager = new SQLManager(implementation, args.length == 3 ? args[2] : "",
|
||||
this.eventDispatcher, this.plotListener, this.worldConfiguration);
|
||||
this.eventDispatcher, this.plotListener, this.worldConfiguration
|
||||
);
|
||||
HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots();
|
||||
plots = new ArrayList<>();
|
||||
for (Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
|
||||
@ -162,12 +171,16 @@ public class DatabaseCommand extends SubCommand {
|
||||
PlotId newId = newPlot.getId();
|
||||
PlotId id = plot.getId();
|
||||
File worldFile =
|
||||
new File(PlotSquared.platform().worldContainer(),
|
||||
id.toCommaSeparatedString());
|
||||
new File(
|
||||
PlotSquared.platform().worldContainer(),
|
||||
id.toCommaSeparatedString()
|
||||
);
|
||||
if (worldFile.exists()) {
|
||||
File newFile =
|
||||
new File(PlotSquared.platform().worldContainer(),
|
||||
newId.toCommaSeparatedString());
|
||||
new File(
|
||||
PlotSquared.platform().worldContainer(),
|
||||
newId.toCommaSeparatedString()
|
||||
);
|
||||
worldFile.renameTo(newFile);
|
||||
}
|
||||
plot.setId(newId.copy());
|
||||
@ -188,16 +201,19 @@ public class DatabaseCommand extends SubCommand {
|
||||
}
|
||||
} else {
|
||||
HashMap<PlotId, Plot> plotMap = PlotSquared.get().plots_tmp
|
||||
.computeIfAbsent(areaName, k -> new HashMap<>());
|
||||
.computeIfAbsent(areaName, k -> new HashMap<>());
|
||||
plotMap.putAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
DBFunc.createPlotsAndData(plots,
|
||||
() -> player.sendMessage(TranslatableCaption.of("database.conversion_done")));
|
||||
DBFunc.createPlotsAndData(
|
||||
plots,
|
||||
() -> player.sendMessage(TranslatableCaption.of("database.conversion_done"))
|
||||
);
|
||||
return true;
|
||||
case "mysql":
|
||||
if (args.length < 6) {
|
||||
player.sendMessage(StaticCaption.of("/plot database mysql [host] [port] [username] [password] [database] {prefix}"));
|
||||
player.sendMessage(StaticCaption.of(
|
||||
"/plot database mysql [host] [port] [username] [password] [database] {prefix}"));
|
||||
}
|
||||
String host = args[1];
|
||||
String port = args[2];
|
||||
@ -214,7 +230,7 @@ public class DatabaseCommand extends SubCommand {
|
||||
player.sendMessage(StaticCaption.of("/plot database sqlite [file]"));
|
||||
}
|
||||
File sqliteFile =
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), args[1] + ".db");
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), args[1] + ".db");
|
||||
implementation = new SQLite(sqliteFile);
|
||||
break;
|
||||
default:
|
||||
@ -222,7 +238,13 @@ public class DatabaseCommand extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
SQLManager manager = new SQLManager(implementation, prefix, this.eventDispatcher, this.plotListener, this.worldConfiguration);
|
||||
SQLManager manager = new SQLManager(
|
||||
implementation,
|
||||
prefix,
|
||||
this.eventDispatcher,
|
||||
this.plotListener,
|
||||
this.worldConfiguration
|
||||
);
|
||||
DatabaseCommand.insertPlots(manager, plots, player);
|
||||
return true;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
@ -242,4 +264,5 @@ public class DatabaseCommand extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,19 +44,19 @@ import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandDeclaration(command = "debug",
|
||||
category = CommandCategory.DEBUG,
|
||||
usage = "/plot debug [msg]",
|
||||
permission = "plots.admin")
|
||||
category = CommandCategory.DEBUG,
|
||||
usage = "/plot debug [msg]",
|
||||
permission = "plots.admin")
|
||||
public class Debug extends SubCommand {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + Debug.class.getSimpleName());
|
||||
@ -64,21 +64,29 @@ public class Debug extends SubCommand {
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Debug(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public Debug(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull WorldUtil worldUtil
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0 ) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot debug <loadedchunks | debug-players | logging | entitytypes | msg>"));
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot debug <loadedchunks | debug-players | logging | entitytypes | msg>")
|
||||
);
|
||||
}
|
||||
if (args.length > 0) {
|
||||
if ("player".equalsIgnoreCase(args[0])) {
|
||||
for (Map.Entry<String, Object> meta : player.getMeta().entrySet()) {
|
||||
player.sendMessage(StaticCaption.of("Key: " + meta.getKey() + " Value: " + meta.getValue().toString() + " , "));
|
||||
player.sendMessage(StaticCaption.of("Key: " + meta.getKey() + " Value: " + meta
|
||||
.getValue()
|
||||
.toString() + " , "));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,8 +94,10 @@ public class Debug extends SubCommand {
|
||||
final long start = System.currentTimeMillis();
|
||||
player.sendMessage(TranslatableCaption.of("debug.fetching_loaded_chunks"));
|
||||
TaskManager.runTaskAsync(() -> player.sendMessage(StaticCaption
|
||||
.of("Loaded chunks: " + this.worldUtil.getChunkChunks(player.getLocation().getWorldName()).size() + " (" + (System.currentTimeMillis()
|
||||
- start) + "ms) using thread: " + Thread.currentThread().getName())));
|
||||
.of("Loaded chunks: " + this.worldUtil
|
||||
.getChunkChunks(player.getLocation().getWorldName())
|
||||
.size() + " (" + (System.currentTimeMillis()
|
||||
- start) + "ms) using thread: " + Thread.currentThread().getName())));
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && "uuids".equalsIgnoreCase(args[0])) {
|
||||
@ -120,25 +130,29 @@ public class Debug extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("debug.entity_categories"));
|
||||
EntityCategory.REGISTRY.forEach(category -> {
|
||||
final StringBuilder builder =
|
||||
new StringBuilder("§7- §6").append(category.getId()).append("§7: §6");
|
||||
new StringBuilder("§7- §6").append(category.getId()).append("§7: §6");
|
||||
for (final EntityType entityType : category.getAll()) {
|
||||
builder.append(entityType.getId()).append(" ");
|
||||
}
|
||||
player.sendMessage(StaticCaption.of("<prefix>" + builder.toString()));
|
||||
});
|
||||
EntityType.REGISTRY.values().stream().sorted(Comparator.comparing(EntityType::getId))
|
||||
.forEach(entityType -> {
|
||||
long categoryCount = EntityCategory.REGISTRY.values().stream()
|
||||
.filter(category -> category.contains(entityType)).count();
|
||||
if (categoryCount > 0) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(StaticCaption.of("<prefix>" + entityType.getName() + " is in "
|
||||
+ categoryCount + " categories"));
|
||||
});
|
||||
.forEach(entityType -> {
|
||||
long categoryCount = EntityCategory.REGISTRY.values().stream()
|
||||
.filter(category -> category.contains(entityType)).count();
|
||||
if (categoryCount > 0) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(StaticCaption.of("<prefix>" + entityType.getName() + " is in "
|
||||
+ categoryCount + " categories"));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
Set<TranslatableCaption> captions = PlotSquared.get().getCaptionMap(TranslatableCaption.DEFAULT_NAMESPACE).getCaptions().keySet();
|
||||
Set<TranslatableCaption> captions = PlotSquared
|
||||
.get()
|
||||
.getCaptionMap(TranslatableCaption.DEFAULT_NAMESPACE)
|
||||
.getCaptions()
|
||||
.keySet();
|
||||
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (Caption caption : captions) {
|
||||
@ -154,13 +168,30 @@ public class Debug extends SubCommand {
|
||||
information.append(header);
|
||||
information.append(MINI_MESSAGE.parse(section, Template.of("val", "PlotArea")));
|
||||
information.append(MINI_MESSAGE
|
||||
.parse(line, Template.of("var", "Plot Worlds"), Template.of("val", StringMan.join(this.plotAreaManager.getAllPlotAreas(), ", "))));
|
||||
.parse(
|
||||
line,
|
||||
Template.of("var", "Plot Worlds"),
|
||||
Template.of("val", StringMan.join(this.plotAreaManager.getAllPlotAreas(), ", "))
|
||||
));
|
||||
information.append(
|
||||
MINI_MESSAGE.parse(line, Template.of("var", "Owned Plots"), Template.of("val", String.valueOf(PlotQuery.newQuery().allPlots().count()))));
|
||||
MINI_MESSAGE.parse(
|
||||
line,
|
||||
Template.of("var", "Owned Plots"),
|
||||
Template.of("val", String.valueOf(PlotQuery.newQuery().allPlots().count()))
|
||||
));
|
||||
information.append(MINI_MESSAGE.parse(section, Template.of("val", "Messages")));
|
||||
information.append(MINI_MESSAGE.parse(line, Template.of("var", "Total Messages"), Template.of("val", String.valueOf(captions.size()))));
|
||||
information.append(MINI_MESSAGE.parse(line, Template.of("var", "View all captions"), Template.of("val", "/plot debug msg")));
|
||||
information.append(MINI_MESSAGE.parse(
|
||||
line,
|
||||
Template.of("var", "Total Messages"),
|
||||
Template.of("val", String.valueOf(captions.size()))
|
||||
));
|
||||
information.append(MINI_MESSAGE.parse(
|
||||
line,
|
||||
Template.of("var", "View all captions"),
|
||||
Template.of("val", "/plot debug msg")
|
||||
));
|
||||
player.sendMessage(StaticCaption.of(information.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,15 +33,16 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "debugallowunsafe",
|
||||
usage = "/plot debugallowunsafe",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.debugallowunsafe")
|
||||
usage = "/plot debugallowunsafe",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.debugallowunsafe")
|
||||
public class DebugAllowUnsafe extends SubCommand {
|
||||
|
||||
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
if (unsafeAllowed.contains(player.getUUID())) {
|
||||
unsafeAllowed.remove(player.getUUID());
|
||||
|
@ -28,7 +28,6 @@ package com.plotsquared.core.command;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.CaptionHolder;
|
||||
import com.plotsquared.core.configuration.caption.StaticCaption;
|
||||
@ -38,6 +37,7 @@ import com.plotsquared.core.events.PlotFlagRemoveEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.generator.HybridUtils;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
@ -67,11 +67,11 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
@ -88,9 +88,9 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "debugexec",
|
||||
permission = "plots.admin",
|
||||
aliases = {"exec", "$"},
|
||||
category = CommandCategory.DEBUG)
|
||||
permission = "plots.admin",
|
||||
aliases = {"exec", "$"},
|
||||
category = CommandCategory.DEBUG)
|
||||
public class DebugExec extends SubCommand {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + DebugExec.class.getSimpleName());
|
||||
@ -109,16 +109,19 @@ public class DebugExec extends SubCommand {
|
||||
private ScriptEngine engine;
|
||||
private Bindings scope;
|
||||
|
||||
@Inject public DebugExec(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nullable final WorldEdit worldEdit,
|
||||
@Nonnull final GlobalBlockQueue blockQueue,
|
||||
@Nonnull final SchematicHandler schematicHandler,
|
||||
@Nonnull final EconHandler econHandler,
|
||||
@Nonnull final ChunkManager chunkManager,
|
||||
@Nonnull final WorldUtil worldUtil,
|
||||
@Nonnull final SetupUtils setupUtils,
|
||||
@Nonnull final HybridUtils hybridUtils) {
|
||||
@Inject
|
||||
public DebugExec(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @Nullable WorldEdit worldEdit,
|
||||
final @NonNull GlobalBlockQueue blockQueue,
|
||||
final @NonNull SchematicHandler schematicHandler,
|
||||
final @NonNull EconHandler econHandler,
|
||||
final @NonNull ChunkManager chunkManager,
|
||||
final @NonNull WorldUtil worldUtil,
|
||||
final @NonNull SetupUtils setupUtils,
|
||||
final @NonNull HybridUtils hybridUtils
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.worldEdit = worldEdit;
|
||||
@ -202,11 +205,13 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
List<String> allowed_params = Arrays
|
||||
.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire",
|
||||
"seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync",
|
||||
"run", "allcmd", "all");
|
||||
.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire",
|
||||
"seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync",
|
||||
"run", "allcmd", "all"
|
||||
);
|
||||
if (args.length > 0) {
|
||||
String arg = args[0].toLowerCase();
|
||||
String script;
|
||||
@ -228,7 +233,8 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("debugexec.starting_task"));
|
||||
this.hybridUtils.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||
@Override public void run(PlotAnalysis value) {
|
||||
@Override
|
||||
public void run(PlotAnalysis value) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugexec.analyze_done"),
|
||||
Template.of("command", "/plot debugexec analyze")
|
||||
@ -257,7 +263,10 @@ public class DebugExec extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("debugexec.threshold_default_double"));
|
||||
return false;
|
||||
}
|
||||
PlotAnalysis.calcOptimalModifiers(() -> player.sendMessage(TranslatableCaption.of("debugexec.calibration_done")), threshold);
|
||||
PlotAnalysis.calcOptimalModifiers(
|
||||
() -> player.sendMessage(TranslatableCaption.of("debugexec.calibration_done")),
|
||||
threshold
|
||||
);
|
||||
return true;
|
||||
case "stop-expire":
|
||||
if (ExpireManager.IMP == null || !ExpireManager.IMP.cancelTask()) {
|
||||
@ -274,11 +283,11 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
String flag = args[1];
|
||||
final PlotFlag<?, ?> flagInstance =
|
||||
GlobalFlagContainer.getInstance().getFlagFromString(flag);
|
||||
GlobalFlagContainer.getInstance().getFlagFromString(flag);
|
||||
if (flagInstance != null) {
|
||||
for (Plot plot : PlotQuery.newQuery().whereBasePlot()) {
|
||||
PlotFlagRemoveEvent event = this.eventDispatcher
|
||||
.callFlagRemove(flagInstance, plot);
|
||||
.callFlagRemove(flagInstance, plot);
|
||||
if (event.getEventResult() != Result.DENY) {
|
||||
plot.removeFlag(event.getFlag());
|
||||
}
|
||||
@ -335,20 +344,26 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
case "?":
|
||||
case "help":
|
||||
player.sendMessage(StaticCaption.of("<prefix><gold>Possible sub commands: </gray>/plot debugexec <" + StringMan.join(allowed_params, " | ") + "></gray>"));
|
||||
player.sendMessage(StaticCaption.of("<prefix><gold>Possible sub commands: </gray>/plot debugexec <" + StringMan
|
||||
.join(allowed_params, " | ") + "></gray>"));
|
||||
return false;
|
||||
case "addcmd":
|
||||
try {
|
||||
final String cmd = StringMan.join(Files.readLines(FileUtils.getFile(new File(
|
||||
PlotSquared.platform().getDirectory() + File.separator
|
||||
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
final String cmd = StringMan.join(
|
||||
Files.readLines(FileUtils.getFile(new File(
|
||||
PlotSquared.platform().getDirectory() + File.separator
|
||||
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator")
|
||||
);
|
||||
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null,
|
||||
RequiredType.NONE, CommandCategory.DEBUG) {
|
||||
RequiredType.NONE, CommandCategory.DEBUG
|
||||
) {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player,
|
||||
String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player,
|
||||
String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
try {
|
||||
DebugExec.this.scope.put("PlotPlayer", player);
|
||||
DebugExec.this.scope.put("args", args);
|
||||
@ -373,10 +388,12 @@ public class DebugExec extends SubCommand {
|
||||
async = true;
|
||||
case "run":
|
||||
try {
|
||||
script = StringMan.join(Files.readLines(FileUtils.getFile(new File(
|
||||
PlotSquared.platform().getDirectory() + File.separator
|
||||
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
script = StringMan.join(
|
||||
Files.readLines(FileUtils.getFile(new File(
|
||||
PlotSquared.platform().getDirectory() + File.separator
|
||||
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator")
|
||||
);
|
||||
if (args.length > 2) {
|
||||
HashMap<String, String> replacements = new HashMap<>();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
@ -391,7 +408,7 @@ public class DebugExec extends SubCommand {
|
||||
break;
|
||||
case "list-scripts":
|
||||
String path = PlotSquared.platform().getDirectory() + File.separator
|
||||
+ Settings.Paths.SCRIPTS;
|
||||
+ Settings.Paths.SCRIPTS;
|
||||
File folder = new File(path);
|
||||
File[] filesArray = folder.listFiles();
|
||||
|
||||
@ -415,12 +432,17 @@ public class DebugExec extends SubCommand {
|
||||
|
||||
List<File> allFiles = Arrays.asList(filesArray);
|
||||
paginate(player, allFiles, 8, page, new RunnableVal3<Integer, File, CaptionHolder>() {
|
||||
@Override public void run(Integer i, File file, CaptionHolder message) {
|
||||
@Override
|
||||
public void run(Integer i, File file, CaptionHolder message) {
|
||||
String name = file.getName();
|
||||
Template numTemplate = Template.of("number", String.valueOf(i));
|
||||
Template nameTemplate = Template.of("name", name);
|
||||
message.set(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("debugexec.script_list_item").getComponent(player), numTemplate, nameTemplate))));
|
||||
.parse(
|
||||
TranslatableCaption.of("debugexec.script_list_item").getComponent(player),
|
||||
numTemplate,
|
||||
nameTemplate
|
||||
))));
|
||||
}
|
||||
}, "/plot debugexec list-scripts", TranslatableCaption.of("scripts.script_list"));
|
||||
return true;
|
||||
@ -433,9 +455,9 @@ public class DebugExec extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
script =
|
||||
"_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if("
|
||||
+ args[1] + "){" + StringMan
|
||||
.join(Arrays.copyOfRange(args, 2, args.length), " ") + "}}";
|
||||
"_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if("
|
||||
+ args[1] + "){" + StringMan
|
||||
.join(Arrays.copyOfRange(args, 2, args.length), " ") + "}}";
|
||||
|
||||
break;
|
||||
default:
|
||||
@ -473,4 +495,5 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,32 +37,37 @@ import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "debugimportworlds",
|
||||
permission = "plots.admin",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.TELEPORT)
|
||||
permission = "plots.admin",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.TELEPORT)
|
||||
public class DebugImportWorlds extends Command {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public DebugImportWorlds(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public DebugImportWorlds(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull WorldUtil worldUtil
|
||||
) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
// UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
|
||||
if (!(this.plotAreaManager instanceof SinglePlotAreaManager)) {
|
||||
player.sendMessage(TranslatableCaption.of("debugimportworlds.single_plot_area"));
|
||||
@ -87,7 +92,7 @@ public class DebugImportWorlds extends Command {
|
||||
}
|
||||
if (uuid == null) {
|
||||
uuid =
|
||||
UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
while (new File(container, id.toCommaSeparatedString()).exists()) {
|
||||
id = id.getNextId();
|
||||
@ -101,4 +106,5 @@ public class DebugImportWorlds extends Command {
|
||||
player.sendMessage(TranslatableCaption.of("players.done"));
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,14 +30,16 @@ import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
|
||||
@CommandDeclaration(command = "debugloadtest",
|
||||
permission = "plots.debugloadtest",
|
||||
usage = "/plot debugloadtest",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE)
|
||||
permission = "plots.debugloadtest",
|
||||
usage = "/plot debugloadtest",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE)
|
||||
public class DebugLoadTest extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
PlotSquared.get().plots_tmp = DBFunc.getPlots();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.PremiumVerification;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
@ -60,13 +60,17 @@ public class DebugPaste extends SubCommand {
|
||||
private final File configFile;
|
||||
private final File worldfile;
|
||||
|
||||
@Inject public DebugPaste(@ConfigFile @Nonnull final File configFile,
|
||||
@WorldFile @Nonnull final File worldFile) {
|
||||
@Inject
|
||||
public DebugPaste(
|
||||
@ConfigFile final @NonNull File configFile,
|
||||
@WorldFile final @NonNull File worldFile
|
||||
) {
|
||||
this.configFile = configFile;
|
||||
this.worldfile = worldFile;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
StringBuilder b = new StringBuilder();
|
||||
@ -121,7 +125,8 @@ public class DebugPaste extends SubCommand {
|
||||
final File logFile =
|
||||
new File(PlotSquared.platform().getDirectory(), "../../logs/latest.log");
|
||||
if (Files.size(logFile.toPath()) > 14_000_000) {
|
||||
throw new IOException("The latest.log is larger than 14MB. Please reboot your server and submit a new paste.");
|
||||
throw new IOException(
|
||||
"The latest.log is larger than 14MB. Please reboot your server and submit a new paste.");
|
||||
}
|
||||
incendoPaster
|
||||
.addFile(logFile);
|
||||
@ -129,29 +134,38 @@ public class DebugPaste extends SubCommand {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugpaste.latest_log"),
|
||||
Template.of("file", "latest.log"),
|
||||
Template.of("size", "14MB"));
|
||||
Template.of("size", "14MB")
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
incendoPaster.addFile(this.configFile);
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
player.sendMessage(TranslatableCaption.of("debugpaste.empty_file"),
|
||||
Template.of("file", "settings.yml"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugpaste.empty_file"),
|
||||
Template.of("file", "settings.yml")
|
||||
);
|
||||
}
|
||||
try {
|
||||
incendoPaster.addFile(this.worldfile);
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
player.sendMessage(TranslatableCaption.of("debugpaste.empty_file"),
|
||||
Template.of("file", "worlds.yml"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugpaste.empty_file"),
|
||||
Template.of("file", "worlds.yml")
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
final File MultiverseWorlds = new File(PlotSquared.platform().getDirectory(),
|
||||
"../Multiverse-Core/worlds.yml");
|
||||
final File MultiverseWorlds = new File(
|
||||
PlotSquared.platform().getDirectory(),
|
||||
"../Multiverse-Core/worlds.yml"
|
||||
);
|
||||
incendoPaster.addFile(MultiverseWorlds, "Multiverse-Core/worlds.yml");
|
||||
} catch (final IOException ignored) {
|
||||
player.sendMessage(TranslatableCaption.of("debugpaste.skip_multiverse"),
|
||||
Template.of("file", "worlds.yml"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugpaste.skip_multiverse"),
|
||||
Template.of("file", "worlds.yml")
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -187,4 +201,5 @@ public class DebugPaste extends SubCommand {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,28 +34,30 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
@CommandDeclaration(command = "debugroadregen",
|
||||
usage = DebugRoadRegen.USAGE,
|
||||
requiredType = RequiredType.NONE,
|
||||
category = CommandCategory.DEBUG,
|
||||
permission = "plots.debugroadregen")
|
||||
usage = DebugRoadRegen.USAGE,
|
||||
requiredType = RequiredType.NONE,
|
||||
category = CommandCategory.DEBUG,
|
||||
permission = "plots.debugroadregen")
|
||||
public class DebugRoadRegen extends SubCommand {
|
||||
|
||||
public static final String USAGE = "/plot debugroadregen <plot | region [height]>";
|
||||
|
||||
private final HybridUtils hybridUtils;
|
||||
|
||||
@Inject public DebugRoadRegen(@Nonnull final HybridUtils hybridUtils) {
|
||||
@Inject
|
||||
public DebugRoadRegen(final @NonNull HybridUtils hybridUtils) {
|
||||
this.hybridUtils = hybridUtils;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
@ -97,10 +99,14 @@ public class DebugRoadRegen extends SubCommand {
|
||||
manager.createRoadSouthEast(plot, queue);
|
||||
queue.setCompleteTask(() -> {
|
||||
;
|
||||
player.sendMessage(TranslatableCaption.of("debugroadregen.regen_done"),
|
||||
Template.of("value", String.valueOf(plot.getId())));
|
||||
player.sendMessage(TranslatableCaption.of("debugroadregen.regen_all"),
|
||||
Template.of("value", "/plot regenallroads"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugroadregen.regen_done"),
|
||||
Template.of("value", String.valueOf(plot.getId()))
|
||||
);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugroadregen.regen_all"),
|
||||
Template.of("value", "/plot regenallroads")
|
||||
);
|
||||
});
|
||||
queue.enqueue();
|
||||
}
|
||||
@ -142,10 +148,14 @@ public class DebugRoadRegen extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_plot_world"));
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("debugroadregen.schematic"),
|
||||
Template.of("command", "/plot createroadschematic"));
|
||||
player.sendMessage(TranslatableCaption.of("debugroadregen.regenallroads"),
|
||||
Template.of("command", "/plot regenallroads"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugroadregen.schematic"),
|
||||
Template.of("command", "/plot createroadschematic")
|
||||
);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugroadregen.regenallroads"),
|
||||
Template.of("command", "/plot regenallroads")
|
||||
);
|
||||
boolean result = this.hybridUtils.scheduleSingleRegionRoadUpdate(plot, height);
|
||||
if (!result) {
|
||||
player.sendMessage(TranslatableCaption.of("debugexec.mass_schematic_update_in_progress"));
|
||||
@ -153,4 +163,5 @@ public class DebugRoadRegen extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,17 +34,21 @@ import com.plotsquared.core.util.query.PlotQuery;
|
||||
import java.util.List;
|
||||
|
||||
@CommandDeclaration(command = "debugsavetest",
|
||||
permission = "plots.debugsavetest",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
usage = "/plot debugsavetest")
|
||||
permission = "plots.debugsavetest",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
usage = "/plot debugsavetest")
|
||||
public class DebugSaveTest extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
final List<Plot> plots = PlotQuery.newQuery().allPlots().asList();
|
||||
player.sendMessage(TranslatableCaption.of("debugsavetest.starting"));
|
||||
DBFunc.createPlotsAndData(plots,
|
||||
() -> player.sendMessage(TranslatableCaption.of("debugsavetest.done")));
|
||||
DBFunc.createPlotsAndData(
|
||||
plots,
|
||||
() -> player.sendMessage(TranslatableCaption.of("debugsavetest.done"))
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,29 +41,32 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotExpression;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
|
||||
@CommandDeclaration(command = "delete",
|
||||
permission = "plots.delete",
|
||||
usage = "/plot delete",
|
||||
aliases = {"dispose", "del"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
confirmation = true)
|
||||
permission = "plots.delete",
|
||||
usage = "/plot delete",
|
||||
aliases = {"dispose", "del"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
confirmation = true)
|
||||
public class Delete extends SubCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final EconHandler econHandler;
|
||||
|
||||
@Inject public Delete(@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final EconHandler econHandler) {
|
||||
@Inject
|
||||
public Delete(
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull EconHandler econHandler
|
||||
) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.econHandler = econHandler;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -82,20 +85,21 @@ public class Delete extends SubCommand {
|
||||
if (eventResult == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Delete"));
|
||||
Template.of("value", "Delete")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
boolean force = eventResult == Result.FORCE;
|
||||
if (!force && !plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DELETE)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DELETE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
final PlotArea plotArea = plot.getArea();
|
||||
final java.util.Set<Plot> plots = plot.getConnectedPlots();
|
||||
final int currentPlots = Settings.Limit.GLOBAL ?
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(location.getWorldName());
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(location.getWorldName());
|
||||
Runnable run = () -> {
|
||||
if (plot.getRunning() > 0) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
|
||||
@ -138,4 +142,5 @@ public class Delete extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
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.plot.world.PlotAreaManager;
|
||||
@ -41,34 +41,38 @@ import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "deny",
|
||||
aliases = {"d", "ban"},
|
||||
usage = "/plot deny <player | *>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
aliases = {"d", "ban"},
|
||||
usage = "/plot deny <player | *>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Deny extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Deny(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public Deny(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull WorldUtil worldUtil
|
||||
) {
|
||||
super(Argument.PlayerName);
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
@ -83,13 +87,20 @@ public class Deny extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DENY)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DENY)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(player.hasPermission("plots.deny." + size) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DENY)))
|
||||
player.sendMessage(TranslatableCaption.of("members.plot_max_members_denied"), Template.of("amount", String.valueOf(size)));
|
||||
if (!(player.hasPermission("plots.deny." + size) || Permissions.hasPermission(
|
||||
player,
|
||||
Permission.PERMISSION_ADMIN_COMMAND_DENY
|
||||
))) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("members.plot_max_members_denied"),
|
||||
Template.of("amount", String.valueOf(size))
|
||||
);
|
||||
}
|
||||
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
@ -102,8 +113,8 @@ public class Deny extends SubCommand {
|
||||
} else {
|
||||
for (UUID uuid : uuids) {
|
||||
if (uuid == DBFunc.EVERYONE && !(
|
||||
Permissions.hasPermission(player, Permission.PERMISSION_DENY_EVERYONE) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DENY))) {
|
||||
Permissions.hasPermission(player, Permission.PERMISSION_DENY_EVERYONE) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DENY))) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[0])
|
||||
@ -144,7 +155,8 @@ public class Deny extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
@ -176,4 +188,5 @@ public class Deny extends SubCommand {
|
||||
player.teleport(spawn);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,41 +35,49 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.implementations.DescriptionFlag;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@CommandDeclaration(command = "setdescription",
|
||||
permission = "plots.set.desc",
|
||||
usage = "/plot desc <description>",
|
||||
aliases = {"desc", "setdesc", "setd", "description"},
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.set.desc",
|
||||
usage = "/plot desc <description>",
|
||||
aliases = {"desc", "setdesc", "setd", "description"},
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Desc extends SetCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Desc(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
|
||||
@Inject
|
||||
public Desc(final @NonNull EventDispatcher eventDispatcher) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override public boolean set(PlotPlayer player, Plot plot, String desc) {
|
||||
|
||||
@Override
|
||||
public boolean set(PlotPlayer player, Plot plot, String desc) {
|
||||
if (desc.isEmpty()) {
|
||||
PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plot.getFlagContainer().getFlag(DescriptionFlag.class), plot);
|
||||
PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plot
|
||||
.getFlagContainer()
|
||||
.getFlag(DescriptionFlag.class), plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Description removal"));
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Description removal")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
plot.removeFlag(event.getFlag());
|
||||
player.sendMessage(TranslatableCaption.of("desc.desc_unset"));
|
||||
return true;
|
||||
}
|
||||
PlotFlagAddEvent event = this.eventDispatcher.callFlagAdd(plot.getFlagContainer().getFlag(DescriptionFlag.class).createFlagInstance(desc), plot);
|
||||
PlotFlagAddEvent event = this.eventDispatcher.callFlagAdd(plot
|
||||
.getFlagContainer()
|
||||
.getFlag(DescriptionFlag.class)
|
||||
.createFlagInstance(desc), plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Description set"));
|
||||
Template.of("value", "Description set")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
boolean result = plot.setFlag(event.getFlag());
|
||||
@ -80,4 +88,5 @@ public class Desc extends SetCommand {
|
||||
player.sendMessage(TranslatableCaption.of("desc.desc_set"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
@ -39,19 +39,21 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "dislike",
|
||||
permission = "plots.dislike",
|
||||
usage = "/plot dislike [next|purge]",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.dislike",
|
||||
usage = "/plot dislike [next|purge]",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Dislike extends SubCommand {
|
||||
|
||||
private final Like like;
|
||||
|
||||
@Inject public Dislike(@Nonnull final Like like) {
|
||||
@Inject
|
||||
public Dislike(final @NonNull Like like) {
|
||||
this.like = like;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
return this.like.handleLike(player, args, false);
|
||||
}
|
||||
|
||||
@ -62,7 +64,9 @@ public class Dislike extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS)) {
|
||||
completions.add("purge");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
|
||||
|
@ -26,7 +26,6 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.PlotDoneEvent;
|
||||
@ -34,6 +33,7 @@ import com.plotsquared.core.events.PlotFlagAddEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.generator.HybridUtils;
|
||||
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.plot.expiration.ExpireManager;
|
||||
@ -44,26 +44,29 @@ import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@CommandDeclaration(command = "done",
|
||||
aliases = {"submit"},
|
||||
permission = "plots.done",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE)
|
||||
aliases = {"submit"},
|
||||
permission = "plots.done",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Done extends SubCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final HybridUtils hybridUtils;
|
||||
|
||||
@Inject public Done(@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final HybridUtils hybridUtils) {
|
||||
@Inject
|
||||
public Done(
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull HybridUtils hybridUtils
|
||||
) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.hybridUtils = hybridUtils;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
@ -74,12 +77,13 @@ public class Done extends SubCommand {
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Done"));
|
||||
Template.of("value", "Done")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
if (!force && !plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DONE)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DONE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
@ -99,10 +103,11 @@ public class Done extends SubCommand {
|
||||
plot.removeRunning();
|
||||
} else {
|
||||
this.hybridUtils.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||
@Override public void run(PlotAnalysis value) {
|
||||
@Override
|
||||
public void run(PlotAnalysis value) {
|
||||
plot.removeRunning();
|
||||
boolean result =
|
||||
value.getComplexity(doneRequirements) <= doneRequirements.THRESHOLD;
|
||||
value.getComplexity(doneRequirements) <= doneRequirements.THRESHOLD;
|
||||
finish(plot, player, result);
|
||||
}
|
||||
});
|
||||
@ -117,7 +122,7 @@ public class Done extends SubCommand {
|
||||
}
|
||||
long flagValue = System.currentTimeMillis() / 1000;
|
||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class)
|
||||
.createFlagInstance(Long.toString(flagValue));
|
||||
.createFlagInstance(Long.toString(flagValue));
|
||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(TranslatableCaption.of("events.event_denied"));
|
||||
@ -126,4 +131,5 @@ public class Done extends SubCommand {
|
||||
plot.setFlag(plotFlag);
|
||||
player.sendMessage(TranslatableCaption.of("done.done_success"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -52,29 +52,34 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(usage = "/plot download [schem | world]",
|
||||
command = "download",
|
||||
aliases = {"dl"},
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.download")
|
||||
command = "download",
|
||||
aliases = {"dl"},
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.download")
|
||||
public class Download extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final PlotUploader plotUploader;
|
||||
@Nonnull private final SchematicHandler schematicHandler;
|
||||
@NonNull
|
||||
private final SchematicHandler schematicHandler;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Download(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final PlotUploader plotUploader,
|
||||
@Nonnull final SchematicHandler schematicHandler,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public Download(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull PlotUploader plotUploader,
|
||||
final @NonNull SchematicHandler schematicHandler,
|
||||
final @NonNull WorldUtil worldUtil
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.plotUploader = plotUploader;
|
||||
this.schematicHandler = schematicHandler;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
String world = player.getLocation().getWorldName();
|
||||
if (!this.plotAreaManager.hasPlotArea(world)) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
@ -90,12 +95,12 @@ public class Download extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!DoneFlag.isDone(plot))) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) {
|
||||
player.sendMessage(TranslatableCaption.of("done.done_not_done"));
|
||||
return false;
|
||||
}
|
||||
if ((!plot.isOwner(player.getUUID())) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN.toString())) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN.toString())) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
@ -104,7 +109,7 @@ public class Download extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0 || (args.length == 1 && StringMan
|
||||
.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) {
|
||||
.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) {
|
||||
if (plot.getVolume() > Integer.MAX_VALUE) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
|
||||
return false;
|
||||
@ -112,7 +117,7 @@ public class Download extends SubCommand {
|
||||
plot.addRunning();
|
||||
upload(player, plot);
|
||||
} else if (args.length == 1 && StringMan
|
||||
.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) {
|
||||
.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_DOWNLOAD_WORLD)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
@ -124,10 +129,14 @@ public class Download extends SubCommand {
|
||||
plot.addRunning();
|
||||
this.worldUtil.saveWorld(world);
|
||||
this.worldUtil.upload(plot, null, null, new RunnableVal<URL>() {
|
||||
@Override public void run(URL url) {
|
||||
@Override
|
||||
public void run(URL url) {
|
||||
plot.removeRunning();
|
||||
if (url == null) {
|
||||
player.sendMessage(TranslatableCaption.of("web.generating_link_failed"), Template.of("plot", String.valueOf(plot.getId())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("web.generating_link_failed"),
|
||||
Template.of("plot", String.valueOf(plot.getId()))
|
||||
);
|
||||
return;
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("web.generation_link_success"), Template.of("url", url.toString()));
|
||||
@ -151,8 +160,17 @@ public class Download extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_DOWNLOAD_WORLD)) {
|
||||
completions.add("world");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(
|
||||
null,
|
||||
true,
|
||||
completion,
|
||||
"",
|
||||
RequiredType.NONE,
|
||||
CommandCategory.ADMINISTRATION
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_DOWNLOAD) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
@ -173,7 +191,8 @@ public class Download extends SubCommand {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("web.generation_link_success"),
|
||||
Template.of("download", value.toString()),
|
||||
Template.of("delete", "Not available"));
|
||||
Template.of("delete", "Not available")
|
||||
);
|
||||
player.sendMessage(StaticCaption.of(value.toString()));
|
||||
}
|
||||
});
|
||||
@ -184,13 +203,18 @@ public class Download extends SubCommand {
|
||||
this.plotUploader.upload(plot)
|
||||
.whenComplete((result, throwable) -> {
|
||||
if (throwable != null || !result.isSuccess()) {
|
||||
player.sendMessage(TranslatableCaption.of("web.generating_link_failed"), Template.of("plot", String.valueOf(plot.getId())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("web.generating_link_failed"),
|
||||
Template.of("plot", String.valueOf(plot.getId()))
|
||||
);
|
||||
} else {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("web.generation_link_success"),
|
||||
Template.of("download", result.getDownloadUrl()),
|
||||
Template.of("delete", result.getDeletionUrl()));
|
||||
Template.of("delete", result.getDeletionUrl())
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -70,11 +70,11 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@CommandDeclaration(command = "flag",
|
||||
aliases = {"f", "flag"},
|
||||
usage = "/plot flag <set | remove | add | list | info> <flag> <value>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag")
|
||||
aliases = {"f", "flag"},
|
||||
usage = "/plot flag <set | remove | add | list | info> <flag> <value>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag")
|
||||
@SuppressWarnings("unused")
|
||||
public final class FlagCommand extends Command {
|
||||
|
||||
@ -90,8 +90,10 @@ public final class FlagCommand extends Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkPermValue(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnull final PlotFlag<?, ?> flag, @Nonnull String key, @Nonnull String value) {
|
||||
private static boolean checkPermValue(
|
||||
final @NonNull PlotPlayer<?> player,
|
||||
final @NonNull PlotFlag<?, ?> flag, @NonNull String key, @NonNull String value
|
||||
) {
|
||||
key = key.toLowerCase();
|
||||
value = value.toLowerCase();
|
||||
String perm = Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase());
|
||||
@ -101,12 +103,17 @@ public final class FlagCommand extends Command {
|
||||
perm = perm.substring(0, perm.length() - value.length() - 1);
|
||||
if (numeric > 0) {
|
||||
int checkRange = PlotSquared.get().getPlatform().equalsIgnoreCase("bukkit") ?
|
||||
numeric :
|
||||
Settings.Limit.MAX_PLOTS;
|
||||
numeric :
|
||||
Settings.Limit.MAX_PLOTS;
|
||||
final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric;
|
||||
if (!result) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of(
|
||||
"node",
|
||||
Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase())
|
||||
)
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -117,7 +124,10 @@ public final class FlagCommand extends Command {
|
||||
try {
|
||||
PlotFlag<? extends List<?>, ?> parsedFlag = listFlag.parse(value);
|
||||
for (final Object entry : parsedFlag.getValue()) {
|
||||
final String permission = Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), entry.toString().toLowerCase());
|
||||
final String permission = Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(
|
||||
key.toLowerCase(),
|
||||
entry.toString().toLowerCase()
|
||||
);
|
||||
final boolean result = Permissions.hasPermission(player, permission);
|
||||
if (!result) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", permission));
|
||||
@ -149,7 +159,7 @@ public final class FlagCommand extends Command {
|
||||
*
|
||||
* @return true if the player is allowed to modify the flags at their current location
|
||||
*/
|
||||
private static boolean checkRequirements(@Nonnull final PlotPlayer<?> player) {
|
||||
private static boolean checkRequirements(final @NonNull PlotPlayer<?> player) {
|
||||
final Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -161,7 +171,7 @@ public final class FlagCommand extends Command {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_SET_FLAG_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_SET_FLAG_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_SET_FLAG_OTHER))
|
||||
@ -179,16 +189,21 @@ public final class FlagCommand extends Command {
|
||||
* @param arg String to extract flag from
|
||||
* @return The flag, if found, else null
|
||||
*/
|
||||
@Nullable private static PlotFlag<?, ?> getFlag(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnull final String arg) {
|
||||
@Nullable
|
||||
private static PlotFlag<?, ?> getFlag(
|
||||
final @NonNull PlotPlayer<?> player,
|
||||
final @NonNull String arg
|
||||
) {
|
||||
if (arg.length() > 0) {
|
||||
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(arg);
|
||||
if (flag instanceof InternalFlag || flag == null) {
|
||||
boolean suggested = false;
|
||||
try {
|
||||
final StringComparison<PlotFlag<?, ?>> stringComparison =
|
||||
new StringComparison<>(arg,
|
||||
GlobalFlagContainer.getInstance().getFlagMap().values());
|
||||
new StringComparison<>(
|
||||
arg,
|
||||
GlobalFlagContainer.getInstance().getFlagMap().values()
|
||||
);
|
||||
final String best = stringComparison.getBestMatch();
|
||||
if (best != null) {
|
||||
player.sendMessage(
|
||||
@ -209,41 +224,45 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
if (args.length == 0 || !Arrays
|
||||
.asList("set", "s", "list", "l", "delete", "remove", "r", "add", "a", "info", "i")
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||
.asList("set", "s", "list", "l", "delete", "remove", "r", "add", "a", "info", "i")
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||
new HelpMenu(player).setCategory(CommandCategory.SETTINGS)
|
||||
.setCommands(this.getCommands()).generateMaxPages()
|
||||
.generatePage(0, getParent().toString(), player).render();
|
||||
.setCommands(this.getCommands()).generateMaxPages()
|
||||
.generatePage(0, getParent().toString(), player).render();
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
return super.execute(player, args, confirm, whenDone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args,
|
||||
final boolean space) {
|
||||
public Collection<Command> tab(
|
||||
final PlotPlayer<?> player, final String[] args,
|
||||
final boolean space
|
||||
) {
|
||||
if (args.length == 1) {
|
||||
return Stream
|
||||
.of("set", "add", "remove", "delete", "info", "list")
|
||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
.of("set", "add", "remove", "delete", "info", "list")
|
||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
} else if (Arrays.asList("set", "add", "remove", "delete", "info")
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 2) {
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 2) {
|
||||
return GlobalFlagContainer.getInstance().getRecognizedPlotFlags().stream()
|
||||
.filter(flag -> !(flag instanceof InternalFlag))
|
||||
.filter(flag -> flag.getName().startsWith(args[1].toLowerCase(Locale.ENGLISH)))
|
||||
.map(flag -> new Command(null, false, flag.getName(), "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
.filter(flag -> !(flag instanceof InternalFlag))
|
||||
.filter(flag -> flag.getName().startsWith(args[1].toLowerCase(Locale.ENGLISH)))
|
||||
.map(flag -> new Command(null, false, flag.getName(), "", RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
} else if (Arrays.asList("set", "add", "remove", "delete")
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 3) {
|
||||
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 3) {
|
||||
try {
|
||||
final PlotFlag<?, ?> flag =
|
||||
GlobalFlagContainer.getInstance().getFlagFromString(args[1]);
|
||||
GlobalFlagContainer.getInstance().getFlagFromString(args[1]);
|
||||
if (flag != null) {
|
||||
Stream<String> stream = flag.getTabCompletions().stream();
|
||||
if (flag instanceof ListFlag && args[2].contains(",")) {
|
||||
@ -261,16 +280,18 @@ public final class FlagCommand extends Command {
|
||||
cmp = "";
|
||||
}
|
||||
return stream
|
||||
.filter(value -> value.startsWith(cmp.toLowerCase(Locale.ENGLISH))).map(
|
||||
value -> new Command(null, false, prefix + value, "",
|
||||
RequiredType.NONE, null) {
|
||||
}).collect(Collectors.toList());
|
||||
.filter(value -> value.startsWith(cmp.toLowerCase(Locale.ENGLISH))).map(
|
||||
value -> new Command(null, false, prefix + value, "",
|
||||
RequiredType.NONE, null
|
||||
) {
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
return stream
|
||||
.filter(value -> value.startsWith(args[2].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE,
|
||||
null) {
|
||||
}).collect(Collectors.toList());
|
||||
.filter(value -> value.startsWith(args[2].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE,
|
||||
null
|
||||
) {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
@ -280,14 +301,16 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "set",
|
||||
aliases = {"s", "set"},
|
||||
usage = "/plot flag set <flag> <value>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.set.flag")
|
||||
public void set(final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
aliases = {"s", "set"},
|
||||
usage = "/plot flag set <flag> <value>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.set.flag")
|
||||
public void set(
|
||||
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (!checkRequirements(player)) {
|
||||
return;
|
||||
}
|
||||
@ -307,7 +330,8 @@ public final class FlagCommand extends Command {
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Flag set"));
|
||||
Template.of("value", "Flag set")
|
||||
);
|
||||
return;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
@ -332,14 +356,16 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "add",
|
||||
aliases = {"a", "add"},
|
||||
usage = "/plot flag add <flag> <value>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.add")
|
||||
public void add(final Command command, PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
aliases = {"a", "add"},
|
||||
usage = "/plot flag add <flag> <value>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.add")
|
||||
public void add(
|
||||
final Command command, PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (!checkRequirements(player)) {
|
||||
return;
|
||||
}
|
||||
@ -359,12 +385,13 @@ public final class FlagCommand extends Command {
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Flag add"));
|
||||
Template.of("value", "Flag add")
|
||||
);
|
||||
return;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
final PlotFlag localFlag = player.getLocation().getPlotAbs().getFlagContainer()
|
||||
.getFlag(event.getFlag().getClass());
|
||||
.getFlag(event.getFlag().getClass());
|
||||
if (!force) {
|
||||
for (String entry : args[1].split(",")) {
|
||||
if (!checkPermValue(player, event.getFlag(), args[0], entry)) {
|
||||
@ -386,7 +413,7 @@ public final class FlagCommand extends Command {
|
||||
return;
|
||||
}
|
||||
boolean result =
|
||||
player.getLocation().getPlotAbs().setFlag(localFlag.merge(parsed.getValue()));
|
||||
player.getLocation().getPlotAbs().setFlag(localFlag.merge(parsed.getValue()));
|
||||
if (!result) {
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_not_added"));
|
||||
return;
|
||||
@ -395,14 +422,16 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "remove",
|
||||
aliases = {"r", "remove", "delete"},
|
||||
usage = "/plot flag remove <flag> [values]",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.remove")
|
||||
public void remove(final Command command, PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
aliases = {"r", "remove", "delete"},
|
||||
usage = "/plot flag remove <flag> [values]",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.remove")
|
||||
public void remove(
|
||||
final Command command, PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (!checkRequirements(player)) {
|
||||
return;
|
||||
}
|
||||
@ -422,15 +451,18 @@ public final class FlagCommand extends Command {
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Flag remove"));
|
||||
Template.of("value", "Flag remove")
|
||||
);
|
||||
return;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
flag = event.getFlag();
|
||||
if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_SET_FLAG_KEY.format(args[0].toLowerCase()))) {
|
||||
if (args.length != 2) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_SET_FLAG_KEY.format(args[0].toLowerCase())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_SET_FLAG_KEY.format(args[0].toLowerCase()))
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -438,7 +470,7 @@ public final class FlagCommand extends Command {
|
||||
String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
||||
final ListFlag listFlag = (ListFlag) flag;
|
||||
final List list =
|
||||
new ArrayList(plot.getFlag((Class<? extends ListFlag<?, ?>>) listFlag.getClass()));
|
||||
new ArrayList(plot.getFlag((Class<? extends ListFlag<?, ?>>) listFlag.getClass()));
|
||||
final PlotFlag parsedFlag;
|
||||
try {
|
||||
parsedFlag = listFlag.parse(value);
|
||||
@ -498,14 +530,16 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "list",
|
||||
aliases = {"l", "list", "flags"},
|
||||
usage = "/plot flag list",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.list")
|
||||
public void list(final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
aliases = {"l", "list", "flags"},
|
||||
usage = "/plot flag list",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.list")
|
||||
public void list(
|
||||
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (!checkRequirements(player)) {
|
||||
return;
|
||||
}
|
||||
@ -517,36 +551,43 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
final String category = MINI_MESSAGE.stripTokens(plotFlag.getFlagCategory().getComponent(player));
|
||||
final Collection<String> flagList =
|
||||
flags.computeIfAbsent(category, k -> new ArrayList<>());
|
||||
flags.computeIfAbsent(category, k -> new ArrayList<>());
|
||||
flagList.add(plotFlag.getName());
|
||||
}
|
||||
|
||||
for (final Map.Entry<String, ArrayList<String>> entry : flags.entrySet()) {
|
||||
Collections.sort(entry.getValue());
|
||||
Component category =
|
||||
MINI_MESSAGE.parse(TranslatableCaption.of("flag.flag_list_categories").getComponent(player),
|
||||
Template.of("category", entry.getKey()));
|
||||
MINI_MESSAGE.parse(
|
||||
TranslatableCaption.of("flag.flag_list_categories").getComponent(player),
|
||||
Template.of("category", entry.getKey())
|
||||
);
|
||||
TextComponent.Builder builder = Component.text().append(category);
|
||||
final Iterator<String> flagIterator = entry.getValue().iterator();
|
||||
while (flagIterator.hasNext()) {
|
||||
final String flag = flagIterator.next();
|
||||
builder.append(MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("flag.flag_list_flag").getComponent(player), Template.of("command", "/plot flag info " + flag),
|
||||
Template.of("flag", flag), Template.of("suffix", flagIterator.hasNext() ? ", " : "")));
|
||||
.parse(TranslatableCaption.of("flag.flag_list_flag").getComponent(player),
|
||||
Template.of("command", "/plot flag info " + flag),
|
||||
Template.of("flag", flag),
|
||||
Template.of("suffix", flagIterator.hasNext() ? ", " : "")
|
||||
));
|
||||
}
|
||||
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.build())));
|
||||
}
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "info",
|
||||
aliases = {"i", "info"},
|
||||
usage = "/plot flag info <flag>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.info")
|
||||
public void info(final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
aliases = {"i", "info"},
|
||||
usage = "/plot flag info <flag>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag.info")
|
||||
public void info(
|
||||
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (!checkRequirements(player)) {
|
||||
return;
|
||||
}
|
||||
@ -563,21 +604,27 @@ public final class FlagCommand extends Command {
|
||||
// Flag name
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_name"), Template.of("flag", plotFlag.getName()));
|
||||
// Flag category
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_category"),
|
||||
Templates.of(player, "value", plotFlag.getFlagCategory()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("flag.flag_info_category"),
|
||||
Templates.of(player, "value", plotFlag.getFlagCategory())
|
||||
);
|
||||
// Flag description
|
||||
// TODO maybe merge and \n instead?
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_description"));
|
||||
player.sendMessage(plotFlag.getFlagDescription());
|
||||
// Flag example
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_example"),
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("flag.flag_info_example"),
|
||||
Template.of("flag", plotFlag.getName()),
|
||||
Template.of("value", plotFlag.getExample()));
|
||||
Template.of("value", plotFlag.getExample())
|
||||
);
|
||||
// Default value
|
||||
final String defaultValue = player.getLocation().getPlotArea().getFlagContainer()
|
||||
.getFlagErased(plotFlag.getClass()).toString();
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_default_value"),
|
||||
Template.of("value", defaultValue));
|
||||
.getFlagErased(plotFlag.getClass()).toString();
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("flag.flag_info_default_value"),
|
||||
Template.of("value", defaultValue)
|
||||
);
|
||||
// Footer. Done this way to prevent the duplicate-message-thingy from catching it
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_footer"));
|
||||
}
|
||||
|
@ -39,23 +39,23 @@ import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "grant",
|
||||
category = CommandCategory.CLAIMING,
|
||||
usage = "/plot grant <check | add> [player]",
|
||||
permission = "plots.grant",
|
||||
requiredType = RequiredType.NONE)
|
||||
category = CommandCategory.CLAIMING,
|
||||
usage = "/plot grant <check | add> [player]",
|
||||
permission = "plots.grant",
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Grant extends Command {
|
||||
|
||||
public Grant() {
|
||||
@ -63,17 +63,25 @@ public class Grant extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
checkTrue(args.length >= 1 && args.length <= 2, TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot grant <check | add> [player]"));
|
||||
public CompletableFuture<Boolean> execute(
|
||||
final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
checkTrue(
|
||||
args.length >= 1 && args.length <= 2,
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot grant <check | add> [player]")
|
||||
);
|
||||
final String arg0 = args[0].toLowerCase();
|
||||
switch (arg0) {
|
||||
case "add":
|
||||
case "check":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_GRANT.format(arg0))) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_GRANT.format(arg0)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_GRANT.format(arg0))
|
||||
);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
if (args.length > 2) {
|
||||
@ -92,17 +100,20 @@ public class Grant extends Command {
|
||||
PlotPlayer<?> pp = PlotSquared.platform().playerManager().getPlayerIfExists(uuid.getUuid());
|
||||
if (pp != null) {
|
||||
try (final MetaDataAccess<Integer> access = pp.accessPersistentMetaData(
|
||||
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||
if (args[0].equalsIgnoreCase("check")) {
|
||||
player.sendMessage(TranslatableCaption.of("grants.granted_plots"),
|
||||
Template.of("amount", String.valueOf(access.get().orElse(0))));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("grants.granted_plots"),
|
||||
Template.of("amount", String.valueOf(access.get().orElse(0)))
|
||||
);
|
||||
} else {
|
||||
access.set(access.get().orElse(0) + 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DBFunc.getPersistentMeta(uuid.getUuid(), new RunnableVal<Map<String, byte[]>>() {
|
||||
@Override public void run(Map<String, byte[]> value) {
|
||||
@Override
|
||||
public void run(Map<String, byte[]> value) {
|
||||
final byte[] array = value.get("grantedPlots");
|
||||
if (arg0.equals("check")) { // check
|
||||
int granted;
|
||||
@ -112,9 +123,9 @@ public class Grant extends Command {
|
||||
granted = Ints.fromByteArray(array);
|
||||
}
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("grants.granted_plots"),
|
||||
Template.of("amount", String.valueOf(granted))
|
||||
);
|
||||
TranslatableCaption.of("grants.granted_plots"),
|
||||
Template.of("amount", String.valueOf(granted))
|
||||
);
|
||||
} else { // add
|
||||
int amount;
|
||||
if (array == null) {
|
||||
@ -127,8 +138,8 @@ public class Grant extends Command {
|
||||
byte[] rawData = Ints.toByteArray(amount);
|
||||
DBFunc.addPersistentMeta(uuid.getUuid(), key, rawData, replace);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("grants.added"),
|
||||
Template.of("grants", String.valueOf(amount))
|
||||
TranslatableCaption.of("grants.added"),
|
||||
Template.of("grants", String.valueOf(amount))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -141,7 +152,9 @@ public class Grant extends Command {
|
||||
sendUsage(player);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
@Override public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
final List<String> completions = new LinkedList<>();
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_GRANT_ADD)) {
|
||||
@ -150,13 +163,24 @@ public class Grant extends Command {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_GRANT_CHECK)) {
|
||||
completions.add("check");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(
|
||||
null,
|
||||
true,
|
||||
completion,
|
||||
"",
|
||||
RequiredType.NONE,
|
||||
CommandCategory.ADMINISTRATION
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_GRANT_SINGLE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
} return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,23 +40,27 @@ import net.kyori.adventure.text.minimessage.Template;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "help",
|
||||
aliases = "?",
|
||||
category = CommandCategory.INFO,
|
||||
usage = "help [category|#]",
|
||||
permission = "plots.use")
|
||||
aliases = "?",
|
||||
category = CommandCategory.INFO,
|
||||
usage = "help [category|#]",
|
||||
permission = "plots.use")
|
||||
public class Help extends Command {
|
||||
|
||||
public Help(Command parent) {
|
||||
super(parent, true);
|
||||
}
|
||||
|
||||
@Override public boolean canExecute(PlotPlayer player, boolean message) {
|
||||
@Override
|
||||
public boolean canExecute(PlotPlayer player, boolean message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
return displayHelp(player, null, 0);
|
||||
@ -85,8 +89,10 @@ public class Help extends Command {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> displayHelp(final PlotPlayer player, final String catRaw,
|
||||
final int page) {
|
||||
public CompletableFuture<Boolean> displayHelp(
|
||||
final PlotPlayer player, final String catRaw,
|
||||
final int page
|
||||
) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
String cat = catRaw;
|
||||
|
||||
@ -110,19 +116,30 @@ public class Help extends Command {
|
||||
builder.append(MINI_MESSAGE.parse(TranslatableCaption.of("help.help_header").getComponent(player)));
|
||||
for (CommandCategory c : CommandCategory.values()) {
|
||||
builder.append(Component.newline()).append(MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("help.help_info_item").getComponent(player), Template.of("category", c.name().toLowerCase()),
|
||||
Template.of("category_desc", c.getComponent(player))));
|
||||
.parse(TranslatableCaption.of("help.help_info_item").getComponent(player),
|
||||
Template.of("category", c.name().toLowerCase()),
|
||||
Template.of("category_desc", c.getComponent(player))
|
||||
));
|
||||
}
|
||||
builder.append(Component.newline()).append(MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("help.help_info_item").getComponent(player), Template.of("category", "all"),
|
||||
Template.of("category_desc", "Display all commands")));
|
||||
builder.append(Component.newline()).append(MINI_MESSAGE.parse(TranslatableCaption.of("help.help_footer").getComponent(player)));
|
||||
.parse(TranslatableCaption.of("help.help_info_item").getComponent(player),
|
||||
Template.of("category", "all"),
|
||||
Template.of("category_desc", "Display all commands")
|
||||
));
|
||||
builder.append(Component.newline()).append(MINI_MESSAGE.parse(TranslatableCaption
|
||||
.of("help.help_footer")
|
||||
.getComponent(player)));
|
||||
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.asComponent())));
|
||||
return true;
|
||||
}
|
||||
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(page - 1, getParent().toString(), player)
|
||||
.render();
|
||||
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(
|
||||
page - 1,
|
||||
getParent().toString(),
|
||||
player
|
||||
)
|
||||
.render();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,9 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
@ -42,32 +42,35 @@ import com.plotsquared.core.util.query.SortingStrategy;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "home",
|
||||
permission = "plots.home",
|
||||
usage = "/plot home [<page> | <alias> | <area;x;y> | <area> <x;y> | <area> <page>]",
|
||||
aliases = {"h"},
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.TELEPORT)
|
||||
permission = "plots.home",
|
||||
usage = "/plot home [<page> | <alias> | <area;x;y> | <area> <x;y> | <area> <page>]",
|
||||
aliases = {"h"},
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.TELEPORT)
|
||||
public class HomeCommand extends Command {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
@Inject public HomeCommand(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
@Inject
|
||||
public HomeCommand(final @NonNull PlotAreaManager plotAreaManager) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
private void home(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnull final PlotQuery query, final int page,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
private void home(
|
||||
final @NonNull PlotPlayer<?> player,
|
||||
final @NonNull PlotQuery query, final int page,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
List<Plot> plots = query.asList();
|
||||
if (plots.isEmpty()) {
|
||||
player.sendMessage(TranslatableCaption.of("invalid.found_no_plots"));
|
||||
@ -90,14 +93,18 @@ public class HomeCommand extends Command {
|
||||
}), () -> whenDone.run(HomeCommand.this, CommandResult.FAILURE));
|
||||
}
|
||||
|
||||
@Nonnull private PlotQuery query(@Nonnull final PlotPlayer<?> player) {
|
||||
@NonNull
|
||||
private PlotQuery query(final @NonNull PlotPlayer<?> player) {
|
||||
// everything plots need to have in common here
|
||||
return PlotQuery.newQuery().thatPasses(plot -> plot.isOwner(player.getUUID()));
|
||||
}
|
||||
|
||||
@Override public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
// /plot home <number> (or page, whatever it's called)
|
||||
// /plot home <alias>
|
||||
// /plot home <[area;]x;y>
|
||||
@ -229,4 +236,5 @@ public class HomeCommand extends Command {
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,10 +51,10 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "inbox",
|
||||
usage = "/plot inbox [inbox] [delete <index> | clear | page]",
|
||||
permission = "plots.inbox",
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
usage = "/plot inbox [inbox] [delete <index> | clear | page]",
|
||||
permission = "plots.inbox",
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Inbox extends SubCommand {
|
||||
|
||||
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
|
||||
@ -79,8 +79,9 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
TextComponent.Builder builder = Component.text();
|
||||
builder.append(MINI_MESSAGE.parse(TranslatableCaption.of("list.comment_list_header_paged").getComponent(player) + '\n',
|
||||
Template.of("amount", String.valueOf(comments.length)), Template.of("cur", String.valueOf(page + 1)),
|
||||
Template.of("max", String.valueOf(totalPages + 1)), Template.of("word", "all")));
|
||||
Template.of("amount", String.valueOf(comments.length)), Template.of("cur", String.valueOf(page + 1)),
|
||||
Template.of("max", String.valueOf(totalPages + 1)), Template.of("word", "all")
|
||||
));
|
||||
|
||||
// This might work xD
|
||||
for (int x = page * 12; x < max; x++) {
|
||||
@ -88,10 +89,16 @@ public class Inbox extends SubCommand {
|
||||
Component commentColored;
|
||||
if (player.getName().equals(comment.senderName)) {
|
||||
commentColored = MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("list.comment_list_by_lister").getComponent(player), Template.of("comment", comment.comment));
|
||||
.parse(
|
||||
TranslatableCaption.of("list.comment_list_by_lister").getComponent(player),
|
||||
Template.of("comment", comment.comment)
|
||||
);
|
||||
} else {
|
||||
commentColored = MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("list.comment_list_by_other").getComponent(player), Template.of("comment", comment.comment));
|
||||
.parse(
|
||||
TranslatableCaption.of("list.comment_list_by_other").getComponent(player),
|
||||
Template.of("comment", comment.comment)
|
||||
);
|
||||
}
|
||||
Template number = Template.of("number", String.valueOf(x));
|
||||
Template world = Template.of("world", comment.world);
|
||||
@ -99,12 +106,20 @@ public class Inbox extends SubCommand {
|
||||
Template commenter = Template.of("commenter", comment.senderName);
|
||||
Template commentTemplate = Template.of("comment", commentColored);
|
||||
builder.append(MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("list.comment_list_comment").getComponent(player), number, world, plot_id, commenter, commentTemplate));
|
||||
.parse(
|
||||
TranslatableCaption.of("list.comment_list_comment").getComponent(player),
|
||||
number,
|
||||
world,
|
||||
plot_id,
|
||||
commenter,
|
||||
commentTemplate
|
||||
));
|
||||
}
|
||||
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.build())));
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||
@ -119,14 +134,15 @@ public class Inbox extends SubCommand {
|
||||
for (final CommentInbox inbox : CommentManager.inboxes.values()) {
|
||||
if (inbox.canRead(plot, player)) {
|
||||
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
@Override
|
||||
public void run(List<PlotComment> value) {
|
||||
if (value != null) {
|
||||
int total = 0;
|
||||
int unread = 0;
|
||||
for (PlotComment comment : value) {
|
||||
total++;
|
||||
if (comment.timestamp > CommentManager
|
||||
.getTimestamp(player, inbox.toString())) {
|
||||
.getTimestamp(player, inbox.toString())) {
|
||||
unread++;
|
||||
}
|
||||
}
|
||||
@ -167,7 +183,11 @@ public class Inbox extends SubCommand {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final MetaDataKey<Long> metaDataKey = MetaDataKey.of(String.format("inbox:%s", inbox.toString()), new TypeLiteral<Long>() {});
|
||||
final MetaDataKey<Long> metaDataKey = MetaDataKey.of(
|
||||
String.format("inbox:%s", inbox.toString()),
|
||||
new TypeLiteral<Long>() {
|
||||
}
|
||||
);
|
||||
try (final MetaDataAccess<Long> metaDataAccess = player.accessTemporaryMetaData(metaDataKey)) {
|
||||
metaDataAccess.set(System.currentTimeMillis());
|
||||
}
|
||||
@ -204,7 +224,8 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
|
||||
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
@Override
|
||||
public void run(List<PlotComment> value) {
|
||||
if (index > value.size()) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("comment.not_valid_inbox_index"),
|
||||
@ -262,7 +283,8 @@ public class Inbox extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
@Override
|
||||
public void run(List<PlotComment> value) {
|
||||
displayComments(player, value, page);
|
||||
}
|
||||
})) {
|
||||
@ -271,6 +293,7 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
@ -284,7 +307,9 @@ public class Inbox extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_INBOX_READ_REPORT)) {
|
||||
completions.add("report");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.CHAT) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_INBOX) && args[0].length() > 0) {
|
||||
@ -294,4 +319,5 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,24 +25,25 @@
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.StaticCaption;
|
||||
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.plot.flag.implementations.HideInfoFlag;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
@CommandDeclaration(command = "info",
|
||||
aliases = "i",
|
||||
usage = "/plot info <id> [-f to force info]",
|
||||
category = CommandCategory.INFO)
|
||||
aliases = "i",
|
||||
usage = "/plot info <id> [-f to force info]",
|
||||
category = CommandCategory.INFO)
|
||||
public class Info extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Plot plot;
|
||||
String arg;
|
||||
if (args.length > 0) {
|
||||
@ -89,7 +90,7 @@ public class Info extends SubCommand {
|
||||
if (args.length == 1) {
|
||||
args = new String[0];
|
||||
} else {
|
||||
args = new String[] {args[1]};
|
||||
args = new String[]{args[1]};
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +100,7 @@ public class Info extends SubCommand {
|
||||
for (final String argument : args) {
|
||||
if (argument.equalsIgnoreCase("-f")) {
|
||||
if (!player
|
||||
.hasPermission(Permission.PERMISSION_AREA_INFO_FORCE.toString())) {
|
||||
.hasPermission(Permission.PERMISSION_AREA_INFO_FORCE.toString())) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_AREA_INFO_FORCE.toString())
|
||||
@ -134,11 +135,13 @@ public class Info extends SubCommand {
|
||||
info = getCaption(arg);
|
||||
if (info == null) {
|
||||
if (Settings.Ratings.USE_LIKES) {
|
||||
player.sendMessage(StaticCaption.of("&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
||||
+ "&aowner&7, " + " &alikes"));
|
||||
player.sendMessage(StaticCaption.of(
|
||||
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
||||
+ "&aowner&7, " + " &alikes"));
|
||||
} else {
|
||||
player.sendMessage(StaticCaption.of("&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
||||
+ "&aowner&7, " + " &arating"));
|
||||
player.sendMessage(StaticCaption.of(
|
||||
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
||||
+ "&aowner&7, " + " &arating"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -182,4 +185,5 @@ public class Info extends SubCommand {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
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.plot.world.PlotAreaManager;
|
||||
@ -39,8 +39,8 @@ import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -49,24 +49,28 @@ import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "kick",
|
||||
aliases = "k",
|
||||
permission = "plots.kick",
|
||||
usage = "/plot kick <player | *>",
|
||||
category = CommandCategory.TELEPORT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
aliases = "k",
|
||||
permission = "plots.kick",
|
||||
usage = "/plot kick <player | *>",
|
||||
category = CommandCategory.TELEPORT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Kick extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Kick(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public Kick(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull WorldUtil worldUtil
|
||||
) {
|
||||
super(Argument.PlayerName);
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
@ -74,7 +78,7 @@ public class Kick extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if ((!plot.hasOwner() || !plot.isOwner(player.getUUID())) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_KICK)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_KICK)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"));
|
||||
return false;
|
||||
}
|
||||
@ -93,7 +97,7 @@ public class Kick extends SubCommand {
|
||||
if (uuid == DBFunc.EVERYONE) {
|
||||
for (PlotPlayer<?> pp : plot.getPlayersInPlot()) {
|
||||
if (pp == player || Permissions
|
||||
.hasPermission(pp, Permission.PERMISSION_ADMIN_ENTRY_DENIED)) {
|
||||
.hasPermission(pp, Permission.PERMISSION_ADMIN_ENTRY_DENIED)) {
|
||||
continue;
|
||||
}
|
||||
players.add(pp);
|
||||
@ -148,13 +152,16 @@ public class Kick extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return TabCompletions.completePlayersInPlot(plot, String.join(",", args).trim(),
|
||||
Collections.singletonList(player.getName()));
|
||||
Collections.singletonList(player.getName())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,29 +33,32 @@ import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "leave",
|
||||
permission = "plots.leave",
|
||||
usage = "/plot leave",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.leave",
|
||||
usage = "/plot leave",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Leave extends Command {
|
||||
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Leave(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
|
||||
@Inject
|
||||
public Leave(final @NonNull EventDispatcher eventDispatcher) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
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.isAdded(player.getUUID()), TranslatableCaption.of("members.not_added_trusted"));
|
||||
@ -84,4 +87,5 @@ public class Leave extends Command {
|
||||
}
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,12 +26,12 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.events.PlotRateEvent;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.Rating;
|
||||
@ -42,8 +42,8 @@ import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -53,20 +53,50 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "like",
|
||||
permission = "plots.like",
|
||||
usage = "/plot like [next | purge]",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.like",
|
||||
usage = "/plot like [next | purge]",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Like extends SubCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Like(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
|
||||
@Inject
|
||||
public Like(final @NonNull EventDispatcher eventDispatcher) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
protected boolean handleLike(final PlotPlayer<?> player, String[] args,
|
||||
final boolean like) {
|
||||
|
||||
/**
|
||||
* Get the likes to dislike ratio of a plot as a percentage (in decimal form)
|
||||
*
|
||||
* @param plot plot
|
||||
* @return likes to dislike ratio, returns zero if the plot has no likes
|
||||
*/
|
||||
public static double getLikesPercentage(final Plot plot) {
|
||||
if (!plot.hasRatings()) {
|
||||
return 0;
|
||||
}
|
||||
final Collection<Boolean> reactions = plot.getLikes().values();
|
||||
double numLikes = 0, numDislikes = 0;
|
||||
for (final boolean reaction : reactions) {
|
||||
if (reaction) {
|
||||
numLikes += 1;
|
||||
} else {
|
||||
numDislikes += 1;
|
||||
}
|
||||
}
|
||||
if (numLikes == 0 && numDislikes == 0) {
|
||||
return 0D;
|
||||
} else if (numDislikes == 0) {
|
||||
return 1.0D;
|
||||
}
|
||||
return numLikes / (numLikes + numDislikes);
|
||||
}
|
||||
|
||||
protected boolean handleLike(
|
||||
final PlotPlayer<?> player, String[] args,
|
||||
final boolean like
|
||||
) {
|
||||
final UUID uuid = player.getUUID();
|
||||
if (args.length == 1) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
@ -82,7 +112,7 @@ public class Like extends SubCommand {
|
||||
});
|
||||
for (final Plot plot : plots) {
|
||||
if ((!Settings.Done.REQUIRED_FOR_RATINGS || DoneFlag.isDone(plot)) && plot
|
||||
.isBasePlot() && (!plot.getLikes().containsKey(uuid))) {
|
||||
.isBasePlot() && (!plot.getLikes().containsKey(uuid))) {
|
||||
plot.teleportPlayer(player, TeleportCause.COMMAND, result -> {
|
||||
});
|
||||
player.sendMessage(TranslatableCaption.of("tutorial.rate_this"));
|
||||
@ -99,7 +129,7 @@ public class Like extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS, true)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS, true)) {
|
||||
return false;
|
||||
}
|
||||
plot.clearRatings();
|
||||
@ -142,7 +172,7 @@ public class Like extends SubCommand {
|
||||
}
|
||||
plot.addRating(uuid, new Rating(rating));
|
||||
final PlotRateEvent event =
|
||||
this.eventDispatcher.callRating(player, plot, new Rating(rating));
|
||||
this.eventDispatcher.callRating(player, plot, new Rating(rating));
|
||||
if (event.getRating() != null) {
|
||||
plot.addRating(uuid, event.getRating());
|
||||
if (like) {
|
||||
@ -172,34 +202,8 @@ public class Like extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the likes to dislike ratio of a plot as a percentage (in decimal form)
|
||||
*
|
||||
* @param plot plot
|
||||
* @return likes to dislike ratio, returns zero if the plot has no likes
|
||||
*/
|
||||
public static double getLikesPercentage(final Plot plot) {
|
||||
if (!plot.hasRatings()) {
|
||||
return 0;
|
||||
}
|
||||
final Collection<Boolean> reactions = plot.getLikes().values();
|
||||
double numLikes = 0, numDislikes = 0;
|
||||
for (final boolean reaction : reactions) {
|
||||
if (reaction) {
|
||||
numLikes += 1;
|
||||
} else {
|
||||
numDislikes += 1;
|
||||
}
|
||||
}
|
||||
if (numLikes == 0 && numDislikes == 0) {
|
||||
return 0D;
|
||||
} else if (numDislikes == 0) {
|
||||
return 1.0D;
|
||||
}
|
||||
return numLikes / (numLikes + numDislikes);
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
return handleLike(player, args, true);
|
||||
}
|
||||
|
||||
@ -210,7 +214,9 @@ public class Like extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS)) {
|
||||
completions.add("purge");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
|
||||
|
@ -54,8 +54,8 @@ import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -71,16 +71,17 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "list",
|
||||
aliases = {"l", "find", "search"},
|
||||
permission = "plots.list",
|
||||
category = CommandCategory.INFO,
|
||||
usage = "/plot list <forsale | mine | shared | world | top | all | unowned | player | world | done | fuzzy <search...>> [#]")
|
||||
aliases = {"l", "find", "search"},
|
||||
permission = "plots.list",
|
||||
category = CommandCategory.INFO,
|
||||
usage = "/plot list <forsale | mine | shared | world | top | all | unowned | player | world | done | fuzzy <search...>> [#]")
|
||||
public class ListCmd extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final EconHandler econHandler;
|
||||
|
||||
@Inject public ListCmd(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EconHandler econHandler) {
|
||||
@Inject
|
||||
public ListCmd(final @NonNull PlotAreaManager plotAreaManager, final @NonNull EconHandler econHandler) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.econHandler = econHandler;
|
||||
}
|
||||
@ -127,11 +128,14 @@ public class ListCmd extends SubCommand {
|
||||
}
|
||||
|
||||
public void noArgs(PlotPlayer<?> player) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.subcommand_set_options_header"),
|
||||
Templates.of("values", Arrays.toString(getArgumentList(player))));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.subcommand_set_options_header"),
|
||||
Templates.of("values", Arrays.toString(getArgumentList(player)))
|
||||
);
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
noArgs(player);
|
||||
return false;
|
||||
@ -156,12 +160,17 @@ public class ListCmd extends SubCommand {
|
||||
String world = player.getLocation().getWorldName();
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
String arg = args[0].toLowerCase();
|
||||
final boolean[] sort = new boolean[] {true};
|
||||
final boolean[] sort = new boolean[]{true};
|
||||
|
||||
final Consumer<PlotQuery> plotConsumer = query -> {
|
||||
if (query == null) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of("value", new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"}).getBestMatch()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of(
|
||||
"value",
|
||||
new StringComparison<>(args[0], new String[]{"mine", "shared", "world", "all"}).getBestMatch()
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -185,33 +194,55 @@ public class ListCmd extends SubCommand {
|
||||
switch (arg) {
|
||||
case "mine":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_MINE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.mine"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.mine")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().ownedBy(player).whereBasePlot().withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
plotConsumer.accept(PlotQuery
|
||||
.newQuery()
|
||||
.ownedBy(player)
|
||||
.whereBasePlot()
|
||||
.withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
break;
|
||||
case "shared":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_SHARED)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.shared"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.shared")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().withMember(player.getUUID()).thatPasses(plot -> !plot.isOwnerAbs(player.getUUID())));
|
||||
plotConsumer.accept(PlotQuery
|
||||
.newQuery()
|
||||
.withMember(player.getUUID())
|
||||
.thatPasses(plot -> !plot.isOwnerAbs(player.getUUID())));
|
||||
break;
|
||||
case "world":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_WORLD)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.world")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.list.world." + world)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world." + world));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.world." + world)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().inWorld(world));
|
||||
break;
|
||||
case "expired":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_EXPIRED)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.expired"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.expired")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (ExpireManager.IMP == null) {
|
||||
@ -222,11 +253,17 @@ public class ListCmd extends SubCommand {
|
||||
break;
|
||||
case "area":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_AREA)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.area"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.area")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.list.world." + world)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world." + world));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.world." + world)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (area == null) {
|
||||
@ -237,22 +274,35 @@ public class ListCmd extends SubCommand {
|
||||
break;
|
||||
case "all":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_ALL)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.all"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.all")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots());
|
||||
break;
|
||||
case "done":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_DONE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.done"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.done")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(DoneFlag::isDone).withSortingStrategy(SortingStrategy.SORT_BY_DONE));
|
||||
plotConsumer.accept(PlotQuery
|
||||
.newQuery()
|
||||
.allPlots()
|
||||
.thatPasses(DoneFlag::isDone)
|
||||
.withSortingStrategy(SortingStrategy.SORT_BY_DONE));
|
||||
break;
|
||||
case "top":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_TOP)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.top"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.top")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
sort[0] = false;
|
||||
@ -260,7 +310,10 @@ public class ListCmd extends SubCommand {
|
||||
break;
|
||||
case "forsale":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_FOR_SALE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.forsale"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.forsale")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (this.econHandler.isSupported()) {
|
||||
@ -270,19 +323,27 @@ public class ListCmd extends SubCommand {
|
||||
break;
|
||||
case "unowned":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_UNOWNED)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.unowned"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.unowned")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getOwner() == null));
|
||||
break;
|
||||
case "fuzzy":
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_FUZZY)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.fuzzy"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.fuzzy")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (args.length < (page == -1 ? 2 : 3)) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot list fuzzy <search...> [#]"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", "/plot list fuzzy <search...> [#]")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
String term;
|
||||
@ -297,11 +358,17 @@ public class ListCmd extends SubCommand {
|
||||
default:
|
||||
if (this.plotAreaManager.hasPlotArea(args[0])) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_WORLD)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.world")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.list.world." + args[0])) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world." + args[0]));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.world." + args[0])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().inWorld(args[0]));
|
||||
@ -323,10 +390,16 @@ public class ListCmd extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Templates.of("value", args[0]));
|
||||
} else {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_PLAYER)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.player"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.list.player")
|
||||
);
|
||||
} else {
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().ownedBy(uuid).withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
plotConsumer.accept(PlotQuery
|
||||
.newQuery()
|
||||
.ownedBy(uuid)
|
||||
.withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -339,7 +412,8 @@ public class ListCmd extends SubCommand {
|
||||
// Header
|
||||
plots.removeIf(plot -> !plot.isBasePlot());
|
||||
this.paginate(player, plots, pageSize, page, new RunnableVal3<Integer, Plot, CaptionHolder>() {
|
||||
@Override public void run(Integer i, Plot plot, CaptionHolder caption) {
|
||||
@Override
|
||||
public void run(Integer i, Plot plot, CaptionHolder caption) {
|
||||
Caption color;
|
||||
if (plot.getOwner() == null) {
|
||||
color = TranslatableCaption.of("info.plot_list_no_owner");
|
||||
@ -352,16 +426,31 @@ public class ListCmd extends SubCommand {
|
||||
} else {
|
||||
color = TranslatableCaption.of("info.plot_list_default");
|
||||
}
|
||||
Component trusted = MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_trusted").getComponent(player),
|
||||
Template.of("trusted", PlayerManager.getPlayerList(plot.getTrusted(), player)));
|
||||
Component members = MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_members").getComponent(player),
|
||||
Template.of("members", PlayerManager.getPlayerList(plot.getMembers(), player)));
|
||||
Component trusted = MINI_MESSAGE.parse(
|
||||
TranslatableCaption.of("info.plot_info_trusted").getComponent(player),
|
||||
Template.of("trusted", PlayerManager.getPlayerList(plot.getTrusted(), player))
|
||||
);
|
||||
Component members = MINI_MESSAGE.parse(
|
||||
TranslatableCaption.of("info.plot_info_members").getComponent(player),
|
||||
Template.of("members", PlayerManager.getPlayerList(plot.getMembers(), player))
|
||||
);
|
||||
Template command_tp = Template.of("command_tp", "/plot visit " + plot.getArea() + ";" + plot.getId());
|
||||
Template command_info = Template.of("command_info", "/plot info " + plot.getArea() + ";" + plot.getId());
|
||||
Template hover_info =
|
||||
Template.of("hover_info", MINI_MESSAGE.serialize(Component.text().append(trusted).append(Component.newline()).append(members).asComponent()));
|
||||
Template.of(
|
||||
"hover_info",
|
||||
MINI_MESSAGE.serialize(Component
|
||||
.text()
|
||||
.append(trusted)
|
||||
.append(Component.newline())
|
||||
.append(members)
|
||||
.asComponent())
|
||||
);
|
||||
Template numberTemplate = Template.of("number", String.valueOf(i));
|
||||
Template plotTemplate = Template.of("plot", MINI_MESSAGE.parse(color.getComponent(player), Template.of("plot", plot.toString())));
|
||||
Template plotTemplate = Template.of(
|
||||
"plot",
|
||||
MINI_MESSAGE.parse(color.getComponent(player), Template.of("plot", plot.toString()))
|
||||
);
|
||||
|
||||
String prefix = "";
|
||||
String online = TranslatableCaption.of("info.plot_list_player_online").getComponent(player);
|
||||
@ -369,7 +458,7 @@ public class ListCmd extends SubCommand {
|
||||
TextComponent.Builder builder = Component.text();
|
||||
try {
|
||||
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners())
|
||||
.get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
.get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
for (final UUIDMapping uuidMapping : names) {
|
||||
PlotPlayer<?> pp = PlotSquared.platform().playerManager().getPlayerIfExists(uuidMapping.getUuid());
|
||||
Template prefixTemplate = Template.of("prefix", prefix);
|
||||
@ -391,7 +480,10 @@ public class ListCmd extends SubCommand {
|
||||
playerBuilder.append(", ");
|
||||
}
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Templates.of("value", playerBuilder.toString()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Templates.of("value", playerBuilder.toString())
|
||||
);
|
||||
} catch (TimeoutException e) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
}
|
||||
@ -402,7 +494,8 @@ public class ListCmd extends SubCommand {
|
||||
}, "/plot list " + args[0], TranslatableCaption.of("list.plot_list_header_paged"));
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
||||
final List<String> completions = new LinkedList<>();
|
||||
if (this.econHandler.isSupported() && Permissions.hasPermission(player, Permission.PERMISSION_LIST_FOR_SALE)) {
|
||||
completions.add("forsale");
|
||||
@ -432,9 +525,11 @@ public class ListCmd extends SubCommand {
|
||||
completions.add("expired");
|
||||
}
|
||||
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.TELEPORT) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.TELEPORT) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_LIST_PLAYER) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
|
@ -43,31 +43,35 @@ import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandDeclaration(command = "load",
|
||||
aliases = "restore",
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.load",
|
||||
usage = "/plot load")
|
||||
aliases = "restore",
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.load",
|
||||
usage = "/plot load")
|
||||
public class Load extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final SchematicHandler schematicHandler;
|
||||
|
||||
@Inject public Load(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final SchematicHandler schematicHandler) {
|
||||
@Inject
|
||||
public Load(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull SchematicHandler schematicHandler
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.schematicHandler = schematicHandler;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
final String world = player.getLocation().getWorldName();
|
||||
if (!this.plotAreaManager.hasPlotArea(world)) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
@ -83,7 +87,7 @@ public class Load extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_LOAD)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_LOAD)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
@ -93,7 +97,7 @@ public class Load extends SubCommand {
|
||||
}
|
||||
|
||||
try (final MetaDataAccess<List<String>> metaDataAccess =
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
|
||||
if (args.length != 0) {
|
||||
if (args.length == 1) {
|
||||
List<String> schematics = metaDataAccess.get().orElse(null);
|
||||
@ -111,9 +115,9 @@ public class Load extends SubCommand {
|
||||
} catch (Exception ignored) {
|
||||
// use /plot load <index>
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("invalid.not_valid_number"),
|
||||
Template.of("value", "(1, " + schematics.size() + ')')
|
||||
);
|
||||
TranslatableCaption.of("invalid.not_valid_number"),
|
||||
Template.of("value", "(1, " + schematics.size() + ')')
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final URL url;
|
||||
@ -131,30 +135,40 @@ public class Load extends SubCommand {
|
||||
if (taskSchematic == null) {
|
||||
plot.removeRunning();
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("schematics.schematic_invalid"),
|
||||
Template.of("reason", "non-existent or not in gzip format")
|
||||
);
|
||||
TranslatableCaption.of("schematics.schematic_invalid"),
|
||||
Template.of("reason", "non-existent or not in gzip format")
|
||||
);
|
||||
return;
|
||||
}
|
||||
PlotArea area = plot.getArea();
|
||||
this.schematicHandler.paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false, player, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
plot.removeRunning();
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
this.schematicHandler.paste(
|
||||
taskSchematic,
|
||||
plot,
|
||||
0,
|
||||
area.getMinBuildHeight(),
|
||||
0,
|
||||
false,
|
||||
player,
|
||||
new RunnableVal<Boolean>() {
|
||||
@Override
|
||||
public void run(Boolean value) {
|
||||
plot.removeRunning();
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
plot.removeRunning();
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot load <index>")
|
||||
);
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "/plot load <index>")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -182,7 +196,7 @@ public class Load extends SubCommand {
|
||||
|
||||
public void displaySaves(PlotPlayer<?> player) {
|
||||
try (final MetaDataAccess<List<String>> metaDataAccess =
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
|
||||
List<String> schematics = metaDataAccess.get().orElse(Collections.emptyList());
|
||||
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
|
||||
try {
|
||||
@ -197,7 +211,7 @@ public class Load extends SubCommand {
|
||||
String size = split[4];
|
||||
String color = "<dark_aqua>";
|
||||
player.sendMessage(StaticCaption.of("<dark_gray>[</dark_gray><gray>" + (i + 1) + "</gray><dark_aqua>] </dark_aqua>" + color + time + "<dark_gray> | </dark_gray>" + color + world + ';' + id
|
||||
+ "<dark_gray> | </dark_gray>" + color + size + 'x' + size));
|
||||
+ "<dark_gray> | </dark_gray>" + color + size + 'x' + size));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -241,4 +255,5 @@ public class Load extends SubCommand {
|
||||
}
|
||||
return toreturn.toString().trim();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.SinglePlot;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
@ -56,7 +55,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
* PlotSquared command class.
|
||||
*/
|
||||
@CommandDeclaration(command = "plot",
|
||||
aliases = {"plots", "p", "plotsquared", "plot2", "p2", "ps", "2", "plotme", "plotz", "ap"})
|
||||
aliases = {"plots", "p", "plotsquared", "plot2", "p2", "ps", "2", "plotme", "plotz", "ap"})
|
||||
public class MainCommand extends Command {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + MainCommand.class.getSimpleName());
|
||||
@ -193,7 +192,7 @@ public class MainCommand extends Command {
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
if (area != null && econHandler.isEnabled(area)) {
|
||||
PlotExpression priceEval =
|
||||
area.getPrices().get(cmd.getFullId());
|
||||
area.getPrices().get(cmd.getFullId());
|
||||
double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||
if (econHandler.getMoney(player) < price) {
|
||||
if (failure != null) {
|
||||
@ -224,7 +223,8 @@ public class MainCommand extends Command {
|
||||
}
|
||||
}
|
||||
}, new RunnableVal2<Command, CommandResult>() {
|
||||
@Override public void run(Command cmd, CommandResult result) {
|
||||
@Override
|
||||
public void run(Command cmd, CommandResult result) {
|
||||
// Post command stuff!?
|
||||
}
|
||||
}).thenAccept(result -> {
|
||||
@ -238,9 +238,11 @@ public class MainCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
// Optional command scope //
|
||||
Location location = null;
|
||||
Plot plot = null;
|
||||
@ -249,9 +251,9 @@ public class MainCommand extends Command {
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
Plot newPlot = Plot.fromString(area, args[0]);
|
||||
if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea()
|
||||
.equals(area) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN)
|
||||
|| Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_AREA_SUDO))
|
||||
&& !newPlot.isDenied(player.getUUID())) {
|
||||
.equals(area) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN)
|
||||
|| Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_AREA_SUDO))
|
||||
&& !newPlot.isDenied(player.getUUID())) {
|
||||
final Location newLoc;
|
||||
if (newPlot.getArea() instanceof SinglePlotArea) {
|
||||
newLoc = newPlot.isLoaded() ? newPlot.getCenterSynchronous() : Location.at("", 0, 0, 0);
|
||||
@ -261,12 +263,12 @@ public class MainCommand extends Command {
|
||||
if (player.canTeleport(newLoc)) {
|
||||
// Save meta
|
||||
try (final MetaDataAccess<Location> locationMetaDataAccess
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||
location = locationMetaDataAccess.get().orElse(null);
|
||||
locationMetaDataAccess.set(newLoc);
|
||||
}
|
||||
try (final MetaDataAccess<Plot> plotMetaDataAccess
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||
plot = plotMetaDataAccess.get().orElse(null);
|
||||
plotMetaDataAccess.set(newPlot);
|
||||
}
|
||||
@ -280,13 +282,14 @@ public class MainCommand extends Command {
|
||||
if (args.length >= 2 && !args[0].isEmpty() && args[0].charAt(0) == '-') {
|
||||
if ("f".equals(args[0].substring(1))) {
|
||||
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
|
||||
@Override public void run(Command cmd, Runnable success, Runnable failure) {
|
||||
@Override
|
||||
public void run(Command cmd, Runnable success, Runnable failure) {
|
||||
if (area != null && PlotSquared.platform().econHandler().isEnabled(area)) {
|
||||
PlotExpression priceEval =
|
||||
area.getPrices().get(cmd.getFullId());
|
||||
area.getPrices().get(cmd.getFullId());
|
||||
double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||
if (price != 0d
|
||||
&& PlotSquared.platform().econHandler().getMoney(player) < price) {
|
||||
&& PlotSquared.platform().econHandler().getMoney(player) < price) {
|
||||
if (failure != null) {
|
||||
failure.run();
|
||||
}
|
||||
@ -313,8 +316,10 @@ public class MainCommand extends Command {
|
||||
e.printStackTrace();
|
||||
String message = e.getMessage();
|
||||
if (message != null) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.error"),
|
||||
net.kyori.adventure.text.minimessage.Template.of("value", message));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.error"),
|
||||
net.kyori.adventure.text.minimessage.Template.of("value", message)
|
||||
);
|
||||
} else {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.error_console"));
|
||||
@ -323,7 +328,7 @@ public class MainCommand extends Command {
|
||||
// Reset command scope //
|
||||
if (tp && !(player instanceof ConsolePlayer)) {
|
||||
try (final MetaDataAccess<Location> locationMetaDataAccess
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||
if (location == null) {
|
||||
locationMetaDataAccess.remove();
|
||||
} else {
|
||||
@ -331,7 +336,7 @@ public class MainCommand extends Command {
|
||||
}
|
||||
}
|
||||
try (final MetaDataAccess<Plot> plotMetaDataAccess
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||
if (plot == null) {
|
||||
plotMetaDataAccess.remove();
|
||||
} else {
|
||||
@ -342,7 +347,9 @@ public class MainCommand extends Command {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
@Override public boolean canExecute(PlotPlayer player, boolean message) {
|
||||
@Override
|
||||
public boolean canExecute(PlotPlayer player, boolean message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,31 +43,34 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotExpression;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "merge",
|
||||
aliases = "m",
|
||||
permission = "plots.merge",
|
||||
usage = "/plot merge <all | n | e | s | w> [removeroads]",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
confirmation = true)
|
||||
aliases = "m",
|
||||
permission = "plots.merge",
|
||||
usage = "/plot merge <all | n | e | s | w> [removeroads]",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
confirmation = true)
|
||||
public class Merge extends SubCommand {
|
||||
|
||||
public static final String[] values = new String[] {"north", "east", "south", "west"};
|
||||
public static final String[] aliases = new String[] {"n", "e", "s", "w"};
|
||||
public static final String[] values = new String[]{"north", "east", "south", "west"};
|
||||
public static final String[] aliases = new String[]{"n", "e", "s", "w"};
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final EconHandler econHandler;
|
||||
|
||||
@Inject public Merge(@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final EconHandler econHandler) {
|
||||
@Inject
|
||||
public Merge(
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull EconHandler econHandler
|
||||
) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.econHandler = econHandler;
|
||||
}
|
||||
|
||||
|
||||
public static String direction(float yaw) {
|
||||
yaw = yaw / 90;
|
||||
int i = Math.round(yaw);
|
||||
@ -90,7 +93,8 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocationFull();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -125,7 +129,7 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
}
|
||||
if (direction == null && (args[0].equalsIgnoreCase("all") || args[0]
|
||||
.equalsIgnoreCase("auto"))) {
|
||||
.equalsIgnoreCase("auto"))) {
|
||||
direction = Direction.ALL;
|
||||
}
|
||||
}
|
||||
@ -143,11 +147,12 @@ public class Merge extends SubCommand {
|
||||
final int size = plot.getConnectedPlots().size();
|
||||
int max = Permissions.hasPermissionRange(player, "plots.merge", Settings.Limit.MAX_PLOTS);
|
||||
PlotMergeEvent event =
|
||||
this.eventDispatcher.callMerge(plot, direction, max, player);
|
||||
this.eventDispatcher.callMerge(plot, direction, max, player);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Merge"));
|
||||
Template.of("value", "Merge")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
@ -172,11 +177,11 @@ public class Merge extends SubCommand {
|
||||
terrain = "true".equalsIgnoreCase(args[1]);
|
||||
}
|
||||
if (!force && !terrain && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_MERGE_KEEP_ROAD)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_MERGE_KEEP_ROAD))
|
||||
);
|
||||
.hasPermission(player, Permission.PERMISSION_MERGE_KEEP_ROAD)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_MERGE_KEEP_ROAD))
|
||||
);
|
||||
return true;
|
||||
}
|
||||
if (plot.getPlotModificationManager().autoMerge(Direction.ALL, maxSize, uuid, player, terrain)) {
|
||||
@ -203,7 +208,7 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
}
|
||||
if (!force && this.econHandler.isEnabled(plotArea) && price > 0d
|
||||
&& this.econHandler.getMoney(player) < price) {
|
||||
&& this.econHandler.getMoney(player) < price) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("economy.cannot_afford_merge"),
|
||||
Template.of("money", this.econHandler.format(price))
|
||||
@ -217,7 +222,7 @@ public class Merge extends SubCommand {
|
||||
terrain = true;
|
||||
}
|
||||
if (!force && !terrain && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_MERGE_KEEP_ROAD)) {
|
||||
.hasPermission(player, Permission.PERMISSION_MERGE_KEEP_ROAD)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_MERGE_KEEP_ROAD))
|
||||
@ -237,7 +242,7 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
Plot adjacent = plot.getRelative(direction);
|
||||
if (adjacent == null || !adjacent.hasOwner() || adjacent
|
||||
.isMerged((direction.getIndex() + 2) % 4) || (!force && adjacent.isOwner(uuid))) {
|
||||
.isMerged((direction.getIndex() + 2) % 4) || (!force && adjacent.isOwner(uuid))) {
|
||||
player.sendMessage(TranslatableCaption.of("merge.no_available_automerge"));
|
||||
return false;
|
||||
}
|
||||
@ -283,8 +288,12 @@ public class Merge extends SubCommand {
|
||||
};
|
||||
if (!force && hasConfirmation(player)) {
|
||||
CmdConfirm.addPending(accepter, MINI_MESSAGE.serialize(MINI_MESSAGE
|
||||
.parse(TranslatableCaption.of("merge.merge_request_confirm").getComponent(player), Template.of("player", player.getName()))),
|
||||
run);
|
||||
.parse(
|
||||
TranslatableCaption.of("merge.merge_request_confirm").getComponent(player),
|
||||
Template.of("player", player.getName())
|
||||
)),
|
||||
run
|
||||
);
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
@ -296,4 +305,5 @@ public class Merge extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("merge.merge_requested"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,13 +35,14 @@ import com.plotsquared.core.plot.Plot;
|
||||
* @author manuelgu, altered by Citymonstret
|
||||
*/
|
||||
@CommandDeclaration(command = "middle",
|
||||
aliases = {"center", "centre"},
|
||||
usage = "/plot middle",
|
||||
category = CommandCategory.TELEPORT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
aliases = {"center", "centre"},
|
||||
usage = "/plot middle",
|
||||
category = CommandCategory.TELEPORT,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Middle extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
@ -52,4 +53,5 @@ public class Middle extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,9 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
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.plot.PlotArea;
|
||||
@ -37,27 +37,30 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(usage = "/plot move <X;Z>",
|
||||
command = "move",
|
||||
permission = "plots.move",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
command = "move",
|
||||
permission = "plots.move",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Move extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
@Inject public Move(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
@Inject
|
||||
public Move(final @NonNull PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot1 = location.getPlotAbs();
|
||||
if (plot1 == null) {
|
||||
@ -65,13 +68,13 @@ public class Move extends SubCommand {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
if (!plot1.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
boolean override = false;
|
||||
if (args.length == 2 && args[1].equalsIgnoreCase("-f")) {
|
||||
args = new String[] {args[0]};
|
||||
args = new String[]{args[0]};
|
||||
override = true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
@ -97,7 +100,7 @@ public class Move extends SubCommand {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
if (!plot1.getArea().isCompatible(plot2.getArea()) && (!override || !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN))) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN))) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.plotworld_incompatible"));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
@ -118,7 +121,8 @@ public class Move extends SubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,31 +42,34 @@ import com.plotsquared.core.util.InventoryUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandDeclaration(command = "music",
|
||||
permission = "plots.music",
|
||||
usage = "/plot music",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.music",
|
||||
usage = "/plot music",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Music extends SubCommand {
|
||||
|
||||
private static final Collection<String> DISCS = Arrays
|
||||
.asList("music_disc_13", "music_disc_cat", "music_disc_blocks", "music_disc_chirp",
|
||||
"music_disc_far", "music_disc_mall", "music_disc_mellohi", "music_disc_stal",
|
||||
"music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait", "music_disc_pigstep");
|
||||
.asList("music_disc_13", "music_disc_cat", "music_disc_blocks", "music_disc_chirp",
|
||||
"music_disc_far", "music_disc_mall", "music_disc_mellohi", "music_disc_stal",
|
||||
"music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait", "music_disc_pigstep"
|
||||
);
|
||||
|
||||
private final InventoryUtil inventoryUtil;
|
||||
|
||||
@Inject public Music(@Nullable final InventoryUtil inventoryUtil) {
|
||||
@Inject
|
||||
public Music(final @Nullable InventoryUtil inventoryUtil) {
|
||||
this.inventoryUtil = inventoryUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -74,38 +77,42 @@ public class Music extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isAdded(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_MUSIC_OTHER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_MUSIC_OTHER)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_MUSIC_OTHER)));
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_MUSIC_OTHER))
|
||||
);
|
||||
return true;
|
||||
}
|
||||
PlotInventory inv = new PlotInventory(this.inventoryUtil, player, 2, "Plot Jukebox") {
|
||||
@Override public boolean onClick(int index) {
|
||||
@Override
|
||||
public boolean onClick(int index) {
|
||||
PlotItemStack item = getItem(index);
|
||||
if (item == null) {
|
||||
return true;
|
||||
}
|
||||
if (item.getType() == ItemTypes.BEDROCK) {
|
||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
|
||||
.createFlagInstance(item.getType());
|
||||
.createFlagInstance(item.getType());
|
||||
PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
getPlayer().sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Music removal"));
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Music removal")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
plot.removeFlag(event.getFlag());
|
||||
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_removed"));
|
||||
} else if (item.getName().toLowerCase(Locale.ENGLISH).contains("disc")) {
|
||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
|
||||
.createFlagInstance(item.getType());
|
||||
.createFlagInstance(item.getType());
|
||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
getPlayer().sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Music addition"));
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Music addition")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
plot.setFlag(event.getFlag());
|
||||
@ -135,4 +142,5 @@ public class Music extends SubCommand {
|
||||
inv.openInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,19 +36,22 @@ import net.kyori.adventure.text.minimessage.Template;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "near",
|
||||
aliases = "n",
|
||||
usage = "/plot near",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
aliases = "n",
|
||||
usage = "/plot near",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Near extends Command {
|
||||
|
||||
public Near() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
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"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("near.plot_near"),
|
||||
@ -56,4 +59,5 @@ public class Near extends Command {
|
||||
);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.PlotChangeOwnerEvent;
|
||||
import com.plotsquared.core.events.PlotUnlinkEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
@ -41,8 +41,8 @@ import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
@ -50,21 +50,23 @@ import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@CommandDeclaration(command = "setowner",
|
||||
permission = "plots.set.owner",
|
||||
usage = "/plot setowner <player>",
|
||||
aliases = {"owner", "so", "seto"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
confirmation = true)
|
||||
permission = "plots.set.owner",
|
||||
usage = "/plot setowner <player>",
|
||||
aliases = {"owner", "so", "seto"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
confirmation = true)
|
||||
public class Owner extends SetCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Owner(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
|
||||
@Inject
|
||||
public Owner(final @NonNull EventDispatcher eventDispatcher) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override public boolean set(final PlotPlayer player, final Plot plot, String value) {
|
||||
|
||||
@Override
|
||||
public boolean set(final PlotPlayer player, final Plot plot, String value) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
player.sendMessage(TranslatableCaption.of("owner.set_owner_missing_player"));
|
||||
player.sendMessage(
|
||||
@ -77,34 +79,47 @@ public class Owner extends SetCommand {
|
||||
|
||||
final Consumer<UUID> uuidConsumer = uuid -> {
|
||||
if (uuid == null && !value.equalsIgnoreCase("none") && !value.equalsIgnoreCase("null")
|
||||
&& !value.equalsIgnoreCase("-")) {
|
||||
&& !value.equalsIgnoreCase("-")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", value)
|
||||
);
|
||||
return;
|
||||
}
|
||||
PlotChangeOwnerEvent event = this.eventDispatcher.callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid,
|
||||
plot.hasOwner());
|
||||
PlotChangeOwnerEvent event = this.eventDispatcher.callOwnerChange(player,
|
||||
plot,
|
||||
plot.hasOwner() ? plot.getOwnerAbs() : null,
|
||||
uuid,
|
||||
plot.hasOwner()
|
||||
);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Owner change"));
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Owner change")
|
||||
);
|
||||
return;
|
||||
}
|
||||
uuid = event.getNewOwner();
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
if (uuid == null) {
|
||||
if (!force && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SET_OWNER,
|
||||
true)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SET_OWNER,
|
||||
true
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
PlotUnlinkEvent unlinkEvent = this.eventDispatcher.callUnlink(plot.getArea(), plot, false, false, PlotUnlinkEvent.REASON.NEW_OWNER);
|
||||
PlotUnlinkEvent unlinkEvent = this.eventDispatcher.callUnlink(
|
||||
plot.getArea(),
|
||||
plot,
|
||||
false,
|
||||
false,
|
||||
PlotUnlinkEvent.REASON.NEW_OWNER
|
||||
);
|
||||
if (unlinkEvent.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Unlink on owner change"));
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Unlink on owner change")
|
||||
);
|
||||
return;
|
||||
}
|
||||
plot.getPlotModificationManager().unlinkPlot(unlinkEvent.isCreateRoad(), unlinkEvent.isCreateRoad());
|
||||
@ -125,7 +140,7 @@ public class Owner extends SetCommand {
|
||||
return;
|
||||
}
|
||||
if (!force && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SET_OWNER)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SET_OWNER)) {
|
||||
if (other == null) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("invalid_player_offline"),
|
||||
@ -135,8 +150,8 @@ public class Owner extends SetCommand {
|
||||
}
|
||||
int size = plots.size();
|
||||
int currentPlots = (Settings.Limit.GLOBAL ?
|
||||
other.getPlotCount() :
|
||||
other.getPlotCount(plot.getWorldName())) + size;
|
||||
other.getPlotCount() :
|
||||
other.getPlotCount(plot.getWorldName())) + size;
|
||||
if (currentPlots > other.getAllowedPlots()) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_transfer_more_plots"));
|
||||
return;
|
||||
@ -147,8 +162,9 @@ public class Owner extends SetCommand {
|
||||
final boolean removeDenied = plot.isDenied(finalUUID);
|
||||
Runnable run = () -> {
|
||||
if (plot.setOwner(finalUUID, player)) {
|
||||
if (removeDenied)
|
||||
if (removeDenied) {
|
||||
plot.removeDenied(finalUUID);
|
||||
}
|
||||
plot.getPlotModificationManager().setSign(finalName);
|
||||
player.sendMessage(TranslatableCaption.of("owner.set_owner"));
|
||||
if (other != null) {
|
||||
@ -179,7 +195,10 @@ public class Owner extends SetCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,21 +33,27 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
@CommandDeclaration(command = "plugin",
|
||||
permission = "plots.use",
|
||||
usage = "/plot plugin",
|
||||
aliases = "version",
|
||||
category = CommandCategory.INFO)
|
||||
permission = "plots.use",
|
||||
usage = "/plot plugin",
|
||||
aliases = "version",
|
||||
category = CommandCategory.INFO)
|
||||
public class PluginCmd extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
TaskManager.getPlatformImplementation().taskAsync(() -> {
|
||||
player.sendMessage(
|
||||
StaticCaption.of("<gray>>> </gray><gold><bold>" + PlotSquared.platform().pluginName() + " <reset><gray>(<gold>Version</gold><gray>: </gray><gold><version></gold><gray>)</gray>"),
|
||||
StaticCaption.of("<gray>>> </gray><gold><bold>" + PlotSquared
|
||||
.platform()
|
||||
.pluginName() + " <reset><gray>(<gold>Version</gold><gray>: </gray><gold><version></gold><gray>)</gray>"),
|
||||
Template.of("version", String.valueOf(PlotSquared.get().getVersion()))
|
||||
);
|
||||
player.sendMessage(StaticCaption.of("<gray>>> </gray><gold><bold>Authors<reset><gray>: </gray><gold>Citymonstret </gold><gray>& </gray><gold>Empire92 </gold><gray>& </gray><gold>MattBDev </gold><gray>& </gray><gold>dordsor21 </gold><gray>& </gray><gold>NotMyFault </gold><gray>& </gray><gold>SirYwell</gold>"));
|
||||
player.sendMessage(StaticCaption.of("<gray>>> </gray><gold><bold>Wiki<reset><gray>: </gray><gold><click:open_url:https://wiki.intellectualsites.com/plotsquared/home>https://wiki.intellectualsites.com/plotsquared/home</gold>"));
|
||||
player.sendMessage(StaticCaption.of("<gray>>> </gray><gold><bold>Discord<reset><gray>: </gray><gold><click:open_url:https://discord.gg/KxkjDVg>https://discord.gg/KxkjDVg</gold>"));
|
||||
player.sendMessage(StaticCaption.of(
|
||||
"<gray>>> </gray><gold><bold>Authors<reset><gray>: </gray><gold>Citymonstret </gold><gray>& </gray><gold>Empire92 </gold><gray>& </gray><gold>MattBDev </gold><gray>& </gray><gold>dordsor21 </gold><gray>& </gray><gold>NotMyFault </gold><gray>& </gray><gold>SirYwell</gold>"));
|
||||
player.sendMessage(StaticCaption.of(
|
||||
"<gray>>> </gray><gold><bold>Wiki<reset><gray>: </gray><gold><click:open_url:https://wiki.intellectualsites.com/plotsquared/home>https://wiki.intellectualsites.com/plotsquared/home</gold>"));
|
||||
player.sendMessage(StaticCaption.of(
|
||||
"<gray>>> </gray><gold><bold>Discord<reset><gray>: </gray><gold><click:open_url:https://discord.gg/KxkjDVg>https://discord.gg/KxkjDVg</gold>"));
|
||||
player.sendMessage(
|
||||
StaticCaption.of("<gray>>> </gray><gold><bold>Premium<reset><gray>: <gold><value></gold>"),
|
||||
Template.of("value", String.valueOf(PremiumVerification.isPremium()))
|
||||
@ -55,4 +61,5 @@ public class PluginCmd extends SubCommand {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,10 +41,10 @@ import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -53,11 +53,11 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@CommandDeclaration(usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true | false] clear:[true | false]",
|
||||
command = "purge",
|
||||
permission = "plots.admin",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
confirmation = true)
|
||||
command = "purge",
|
||||
permission = "plots.admin",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
confirmation = true)
|
||||
public class Purge extends SubCommand {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + Purge.class.getSimpleName());
|
||||
@ -65,13 +65,17 @@ public class Purge extends SubCommand {
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final PlotListener plotListener;
|
||||
|
||||
@Inject public Purge(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final PlotListener plotListener) {
|
||||
@Inject
|
||||
public Purge(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull PlotListener plotListener
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.plotListener = plotListener;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendUsage(player);
|
||||
return false;
|
||||
@ -174,7 +178,7 @@ public class Purge extends SubCommand {
|
||||
}
|
||||
if (PlotSquared.get().plots_tmp != null) {
|
||||
for (Entry<String, HashMap<PlotId, Plot>> entry : PlotSquared.get().plots_tmp
|
||||
.entrySet()) {
|
||||
.entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
if (world != null && !world.equalsIgnoreCase(worldName)) {
|
||||
continue;
|
||||
@ -199,7 +203,7 @@ public class Purge extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
String cmd =
|
||||
"/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)";
|
||||
"/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)";
|
||||
boolean finalClear = clear;
|
||||
Runnable run = () -> {
|
||||
if (Settings.DEBUG) {
|
||||
@ -209,7 +213,8 @@ public class Purge extends SubCommand {
|
||||
Iterator<Plot> iterator = toDelete.iterator();
|
||||
AtomicBoolean cleared = new AtomicBoolean(true);
|
||||
Runnable runasync = new Runnable() {
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (iterator.hasNext() && cleared.get()) {
|
||||
cleared.set(false);
|
||||
Plot plot = iterator.next();
|
||||
@ -231,7 +236,7 @@ public class Purge extends SubCommand {
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
logger.error("NullPointer during purge detected. This is likely"
|
||||
+ " because you are deleting a world that has been removed", e);
|
||||
+ " because you are deleting a world that has been removed", e);
|
||||
}
|
||||
}
|
||||
cleared.set(true);
|
||||
@ -258,4 +263,5 @@ public class Purge extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,12 +26,12 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.events.PlotRateEvent;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotInventory;
|
||||
@ -46,8 +46,8 @@ import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -58,23 +58,27 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "rate",
|
||||
permission = "plots.rate",
|
||||
usage = "/plot rate [# | next | purge]",
|
||||
aliases = "rt",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.rate",
|
||||
usage = "/plot rate [# | next | purge]",
|
||||
aliases = "rt",
|
||||
category = CommandCategory.INFO,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Rate extends SubCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final InventoryUtil inventoryUtil;
|
||||
|
||||
@Inject public Rate(@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final InventoryUtil inventoryUtil) {
|
||||
|
||||
@Inject
|
||||
public Rate(
|
||||
final @NonNull EventDispatcher eventDispatcher,
|
||||
final @NonNull InventoryUtil inventoryUtil
|
||||
) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.inventoryUtil = inventoryUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "next": {
|
||||
@ -100,8 +104,8 @@ public class Rate extends SubCommand {
|
||||
UUID uuid = player.getUUID();
|
||||
for (Plot p : plots) {
|
||||
if ((!Settings.Done.REQUIRED_FOR_RATINGS || DoneFlag.isDone(p)) && p
|
||||
.isBasePlot() && (!p.getRatings().containsKey(uuid)) && !p
|
||||
.isAdded(uuid)) {
|
||||
.isBasePlot() && (!p.getRatings().containsKey(uuid)) && !p
|
||||
.isAdded(uuid)) {
|
||||
p.teleportPlayer(player, TeleportCause.COMMAND, result -> {
|
||||
});
|
||||
player.sendMessage(TranslatableCaption.of("tutorial.rate_this"));
|
||||
@ -118,7 +122,7 @@ public class Rate extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS, true)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS, true)) {
|
||||
return false;
|
||||
}
|
||||
plot.clearRatings();
|
||||
@ -146,7 +150,8 @@ public class Rate extends SubCommand {
|
||||
}
|
||||
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
|
||||
final Runnable run = new Runnable() {
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plot.getRatings().containsKey(player.getUUID())) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("ratings.rating_already_exists"),
|
||||
@ -158,13 +163,14 @@ public class Rate extends SubCommand {
|
||||
final MutableInt rating = new MutableInt(0);
|
||||
String title = Settings.Ratings.CATEGORIES.get(0);
|
||||
PlotInventory inventory = new PlotInventory(inventoryUtil, player, 1, title) {
|
||||
@Override public boolean onClick(int i) {
|
||||
@Override
|
||||
public boolean onClick(int i) {
|
||||
rating.add((i + 1) * Math.pow(10, index.getValue()));
|
||||
index.increment();
|
||||
if (index.getValue() >= Settings.Ratings.CATEGORIES.size()) {
|
||||
int rV = rating.getValue();
|
||||
PlotRateEvent event = Rate.this.eventDispatcher
|
||||
.callRating(this.getPlayer(), plot, new Rating(rV));
|
||||
.callRating(this.getPlayer(), plot, new Rating(rV));
|
||||
if (event.getRating() != null) {
|
||||
plot.addRating(this.getPlayer().getUUID(), event.getRating());
|
||||
getPlayer().sendMessage(
|
||||
@ -172,9 +178,9 @@ public class Rate extends SubCommand {
|
||||
Template.of("plot", plot.getId().toString())
|
||||
);
|
||||
if (Permissions
|
||||
.hasPermission(this.getPlayer(), Permission.PERMISSION_COMMENT)) {
|
||||
.hasPermission(this.getPlayer(), Permission.PERMISSION_COMMENT)) {
|
||||
Command command =
|
||||
MainCommand.getInstance().getCommand(Comment.class);
|
||||
MainCommand.getInstance().getCommand(Comment.class);
|
||||
if (command != null) {
|
||||
getPlayer().sendMessage(
|
||||
TranslatableCaption.of("tutorial.comment_this"),
|
||||
@ -240,7 +246,7 @@ public class Rate extends SubCommand {
|
||||
return;
|
||||
}
|
||||
PlotRateEvent event =
|
||||
this.eventDispatcher.callRating(player, plot, new Rating(rating));
|
||||
this.eventDispatcher.callRating(player, plot, new Rating(rating));
|
||||
if (event.getRating() != null) {
|
||||
plot.addRating(uuid, event.getRating());
|
||||
player.sendMessage(
|
||||
@ -263,6 +269,29 @@ public class Rate extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
final List<String> completions = new LinkedList<>();
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE)) {
|
||||
completions.add("1 - 10");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS)) {
|
||||
completions.add("purge");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
private class MutableInt {
|
||||
|
||||
private int value;
|
||||
@ -286,26 +315,7 @@ public class Rate extends SubCommand {
|
||||
void add(Number v) {
|
||||
this.value += v.intValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
final List<String> completions = new LinkedList<>();
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE)) {
|
||||
completions.add("1 - 10");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS)) {
|
||||
completions.add("purge");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
@ -34,27 +34,30 @@ import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@CommandDeclaration(command = "regenallroads",
|
||||
aliases = {"rgar"},
|
||||
usage = "/plot regenallroads <world> [height]",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
permission = "plots.regenallroads")
|
||||
aliases = {"rgar"},
|
||||
usage = "/plot regenallroads <world> [height]",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
permission = "plots.regenallroads")
|
||||
public class RegenAllRoads extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final HybridUtils hybridUtils;
|
||||
|
||||
@Inject public RegenAllRoads(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final HybridUtils hybridUtils) {
|
||||
@Inject
|
||||
public RegenAllRoads(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull HybridUtils hybridUtils
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.hybridUtils = hybridUtils;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
int height = 0;
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
@ -91,8 +94,10 @@ public class RegenAllRoads extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_plot_world"));
|
||||
return false;
|
||||
}
|
||||
player.sendMessage(TranslatableCaption.of("debugroadregen.schematic"),
|
||||
Template.of("command", "/plot createroadschematic"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("debugroadregen.schematic"),
|
||||
Template.of("command", "/plot createroadschematic")
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("debugroadregen.regenallroads_started"));
|
||||
boolean result = this.hybridUtils.scheduleRoadUpdate(area, height);
|
||||
if (!result) {
|
||||
@ -101,4 +106,5 @@ public class RegenAllRoads extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,31 +36,35 @@ import com.plotsquared.core.inject.annotations.WorldFile;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
@CommandDeclaration(command = "reload",
|
||||
aliases = "rl",
|
||||
permission = "plots.admin.command.reload",
|
||||
usage = "/plot reload",
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
aliases = "rl",
|
||||
permission = "plots.admin.command.reload",
|
||||
usage = "/plot reload",
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
public class Reload extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final YamlConfiguration worldConfiguration;
|
||||
private final File worldFile;
|
||||
|
||||
@Inject public Reload(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile) {
|
||||
@Inject
|
||||
public Reload(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
@WorldConfig final @NonNull YamlConfiguration worldConfiguration,
|
||||
@WorldFile final @NonNull File worldFile
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
this.worldFile = worldFile;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
try {
|
||||
// The following won't affect world generation, as that has to be
|
||||
// loaded during startup unfortunately.
|
||||
@ -68,7 +72,7 @@ public class Reload extends SubCommand {
|
||||
PlotSquared.get().loadCaptionMap();
|
||||
this.plotAreaManager.forEachPlotArea(area -> {
|
||||
ConfigurationSection worldSection = this.worldConfiguration
|
||||
.getConfigurationSection("worlds." + area.getWorldName());
|
||||
.getConfigurationSection("worlds." + area.getWorldName());
|
||||
if (worldSection == null) {
|
||||
return;
|
||||
}
|
||||
@ -77,7 +81,7 @@ public class Reload extends SubCommand {
|
||||
area.loadDefaultConfiguration(worldSection);
|
||||
} else {
|
||||
ConfigurationSection areaSection = worldSection.getConfigurationSection(
|
||||
"areas." + area.getId() + "-" + area.getMin() + "-" + area.getMax());
|
||||
"areas." + area.getId() + "-" + area.getMin() + "-" + area.getMax());
|
||||
YamlConfiguration clone = new YamlConfiguration();
|
||||
for (String key : areaSection.getKeys(true)) {
|
||||
if (areaSection.get(key) instanceof MemorySection) {
|
||||
@ -121,4 +125,5 @@ public class Reload extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,10 +26,10 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
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.EventDispatcher;
|
||||
@ -37,29 +37,31 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "remove",
|
||||
aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"},
|
||||
usage = "/plot remove <player | *>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.remove")
|
||||
aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"},
|
||||
usage = "/plot remove <player | *>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.remove")
|
||||
public class Remove extends SubCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Remove(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
@Inject
|
||||
public Remove(final @NonNull EventDispatcher eventDispatcher) {
|
||||
super(Argument.PlayerName);
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -71,7 +73,7 @@ public class Remove extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_REMOVE)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_REMOVE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return true;
|
||||
}
|
||||
@ -133,14 +135,16 @@ public class Remove extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return TabCompletions.completeAddedPlayers(plot, String.join(",", args).trim(),
|
||||
Collections.singletonList(player.getName()));
|
||||
Collections.singletonList(player.getName())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,8 +28,7 @@ package com.plotsquared.core.command;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.StaticCaption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public enum RequiredType {
|
||||
CONSOLE(TranslatableCaption.of("console.not_console")),
|
||||
@ -49,7 +48,7 @@ public enum RequiredType {
|
||||
return this == player.getSuperCaller();
|
||||
}
|
||||
|
||||
@Nonnull public Caption getErrorMessage() {
|
||||
public @NonNull Caption getErrorMessage() {
|
||||
return this.caption;
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.MetaDataAccess;
|
||||
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -39,29 +39,32 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "save",
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.save")
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.save")
|
||||
public class Save extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final SchematicHandler schematicHandler;
|
||||
|
||||
@Inject public Save(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final SchematicHandler schematicHandler) {
|
||||
@Inject
|
||||
public Save(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull SchematicHandler schematicHandler
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.schematicHandler = schematicHandler;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
final String world = player.getLocation().getWorldName();
|
||||
if (!this.plotAreaManager.hasPlotArea(world)) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
@ -77,7 +80,7 @@ public class Save extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SAVE)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SAVE)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
@ -118,4 +121,5 @@ public class Save extends SubCommand {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -56,23 +56,27 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "schematic",
|
||||
permission = "plots.schematic",
|
||||
aliases = {"sch", "schem"},
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
usage = "/plot schematic <save | saveall | paste>")
|
||||
permission = "plots.schematic",
|
||||
aliases = {"sch", "schem"},
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
usage = "/plot schematic <save | saveall | paste>")
|
||||
public class SchematicCmd extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final SchematicHandler schematicHandler;
|
||||
private boolean running = false;
|
||||
|
||||
@Inject public SchematicCmd(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final SchematicHandler schematicHandler) {
|
||||
@Inject
|
||||
public SchematicCmd(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull SchematicHandler schematicHandler
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.schematicHandler = schematicHandler;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
@ -108,7 +112,7 @@ public class SchematicCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, "plots.admin.command.schematic.paste")) {
|
||||
.hasPermission(player, "plots.admin.command.schematic.paste")) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
@ -150,16 +154,26 @@ public class SchematicCmd extends SubCommand {
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.schematicHandler.paste(schematic, plot, 0, plot.getArea().getMinBuildHeight(), 0, false, player, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
SchematicCmd.this.running = false;
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
this.schematicHandler.paste(
|
||||
schematic,
|
||||
plot,
|
||||
0,
|
||||
plot.getArea().getMinBuildHeight(),
|
||||
0,
|
||||
false,
|
||||
player,
|
||||
new RunnableVal<Boolean>() {
|
||||
@Override
|
||||
public void run(Boolean value) {
|
||||
SchematicCmd.this.running = false;
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
});
|
||||
break;
|
||||
}
|
||||
@ -195,7 +209,8 @@ public class SchematicCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
boolean result = this.schematicHandler.exportAll(plots, null, null,
|
||||
() -> player.sendMessage(TranslatableCaption.of("schematics.schematic_exportall_finished")));
|
||||
() -> player.sendMessage(TranslatableCaption.of("schematics.schematic_exportall_finished"))
|
||||
);
|
||||
if (!result) {
|
||||
player.sendMessage(TranslatableCaption.of("error.task_in_process"));
|
||||
return false;
|
||||
@ -232,7 +247,7 @@ public class SchematicCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, "plots.admin.command.schematic.save")) {
|
||||
.hasPermission(player, "plots.admin.command.schematic.save")) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
@ -272,6 +287,7 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
@ -285,8 +301,17 @@ public class SchematicCmd extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_SCHEMATIC_PASTE)) {
|
||||
completions.add("paste");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(
|
||||
null,
|
||||
true,
|
||||
completion,
|
||||
"",
|
||||
RequiredType.NONE,
|
||||
CommandCategory.ADMINISTRATION
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_SCHEMATIC) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
@ -295,4 +320,5 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ import com.sk89q.worldedit.world.block.BlockCategory;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -61,26 +61,29 @@ import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "set",
|
||||
aliases = {"s"},
|
||||
usage = "/plot set <biome | alias | home | flag> <value...>",
|
||||
permission = "plots.set",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.NONE)
|
||||
aliases = {"s"},
|
||||
usage = "/plot set <biome | alias | home | flag> <value...>",
|
||||
permission = "plots.set",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Set extends SubCommand {
|
||||
|
||||
public static final String[] values = new String[] {"biome", "alias", "home"};
|
||||
public static final String[] aliases = new String[] {"b", "w", "wf", "a", "h"};
|
||||
public static final String[] values = new String[]{"biome", "alias", "home"};
|
||||
public static final String[] aliases = new String[]{"b", "w", "wf", "a", "h"};
|
||||
|
||||
private final SetCommand component;
|
||||
|
||||
@Inject public Set(@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public Set(final @NonNull WorldUtil worldUtil) {
|
||||
this.component = new SetCommand() {
|
||||
|
||||
@Override public String getId() {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "set.component";
|
||||
}
|
||||
|
||||
@Override public boolean set(PlotPlayer player, final Plot plot, String value) {
|
||||
@Override
|
||||
public boolean set(PlotPlayer player, final Plot plot, String value) {
|
||||
final PlotArea plotArea = player.getLocation().getPlotArea();
|
||||
if (plotArea == null) {
|
||||
return false;
|
||||
@ -91,17 +94,17 @@ public class Set extends SubCommand {
|
||||
|
||||
String[] args = value.split(" ");
|
||||
String material =
|
||||
StringMan.join(Arrays.copyOfRange(args, 1, args.length), ",").trim();
|
||||
StringMan.join(Arrays.copyOfRange(args, 1, args.length), ",").trim();
|
||||
|
||||
final List<String> forbiddenTypes = new ArrayList<>(Settings.General.INVALID_BLOCKS);
|
||||
|
||||
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
||||
forbiddenTypes.addAll(worldUtil.getTileEntityTypes().stream().map(
|
||||
BlockType::getName).collect(Collectors.toList()));
|
||||
BlockType::getName).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_ALLOW_UNSAFE) &&
|
||||
!forbiddenTypes.isEmpty()) {
|
||||
!forbiddenTypes.isEmpty()) {
|
||||
for (String forbiddenType : forbiddenTypes) {
|
||||
forbiddenType = forbiddenType.toLowerCase(Locale.ENGLISH);
|
||||
if (forbiddenType.startsWith("minecraft:")) {
|
||||
@ -116,7 +119,7 @@ public class Set extends SubCommand {
|
||||
if (blockType.startsWith("##")) {
|
||||
try {
|
||||
final BlockCategory category = BlockCategory.REGISTRY.get(blockType.substring(2)
|
||||
.replaceAll("[*^|]+", "").toLowerCase(Locale.ENGLISH));
|
||||
.replaceAll("[*^|]+", "").toLowerCase(Locale.ENGLISH));
|
||||
if (category == null || !category.contains(BlockTypes.get(forbiddenType))) {
|
||||
continue;
|
||||
}
|
||||
@ -137,8 +140,10 @@ public class Set extends SubCommand {
|
||||
for (String component : components) {
|
||||
if (component.equalsIgnoreCase(args[0])) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_SET_COMPONENT.format(component))) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_SET_COMPONENT.format(component)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_SET_COMPONENT.format(component))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
@ -161,11 +166,18 @@ public class Set extends SubCommand {
|
||||
}
|
||||
queue.setCompleteTask(() -> {
|
||||
plot.removeRunning();
|
||||
player.sendMessage(TranslatableCaption.of("working.component_complete"), Template.of("plot", String.valueOf(plot.getId())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("working.component_complete"),
|
||||
Template.of("plot", String.valueOf(plot.getId()))
|
||||
);
|
||||
});
|
||||
if (Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(
|
||||
PlotSquared.platform().injector().getInstance(ProgressSubscriberFactory.class).createWithActor(player));
|
||||
PlotSquared
|
||||
.platform()
|
||||
.injector()
|
||||
.getInstance(ProgressSubscriberFactory.class)
|
||||
.createWithActor(player));
|
||||
}
|
||||
queue.enqueue();
|
||||
player.sendMessage(TranslatableCaption.of("working.generating_component"));
|
||||
@ -177,8 +189,10 @@ public class Set extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer player, final String[] args,
|
||||
final boolean space) {
|
||||
public Collection<Command> tab(
|
||||
final PlotPlayer player, final String[] args,
|
||||
final boolean space
|
||||
) {
|
||||
return TabCompletions.completePatterns(StringMan.join(args, ","));
|
||||
}
|
||||
};
|
||||
@ -190,12 +204,15 @@ public class Set extends SubCommand {
|
||||
if (plot != null) {
|
||||
newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
|
||||
}
|
||||
player.sendMessage(StaticCaption.of(TranslatableCaption.of("commandconfig.subcommand_set_options_header_only").getComponent(player) + StringMan
|
||||
.join(newValues, TranslatableCaption.of("blocklist.block_list_separator").getComponent(player))));
|
||||
player.sendMessage(StaticCaption.of(TranslatableCaption
|
||||
.of("commandconfig.subcommand_set_options_header_only")
|
||||
.getComponent(player) + StringMan
|
||||
.join(newValues, TranslatableCaption.of("blocklist.block_list_separator").getComponent(player))));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return noArgs(player);
|
||||
}
|
||||
@ -215,7 +232,7 @@ public class Set extends SubCommand {
|
||||
}
|
||||
// components
|
||||
HashSet<String> components =
|
||||
new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
|
||||
new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
|
||||
if (components.contains(args[0].toLowerCase())) {
|
||||
return this.component.onCommand(player, Arrays.copyOfRange(args, 0, args.length));
|
||||
}
|
||||
@ -260,9 +277,11 @@ public class Set extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_MIDDLE)) {
|
||||
completions.add("middle");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.APPEARANCE) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.APPEARANCE) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_SET) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
@ -288,11 +307,12 @@ public class Set extends SubCommand {
|
||||
|
||||
// components
|
||||
HashSet<String> components =
|
||||
new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
|
||||
new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
|
||||
if (components.contains(args[0].toLowerCase())) {
|
||||
return this.component.tab(player, newArgs, space);
|
||||
}
|
||||
}
|
||||
return tabOf(player, args, space);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
public abstract class SetCommand extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -45,16 +46,20 @@ public abstract class SetCommand extends SubCommand {
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId())));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))
|
||||
);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
|
@ -33,14 +33,15 @@ import com.plotsquared.core.plot.Plot;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
@CommandDeclaration(command = "sethome",
|
||||
permission = "plots.set.home",
|
||||
usage = "/plot sethome [none]",
|
||||
aliases = {"sh", "seth"},
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.set.home",
|
||||
usage = "/plot sethome [none]",
|
||||
aliases = {"sh", "seth"},
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class SetHome extends SetCommand {
|
||||
|
||||
@Override public boolean set(PlotPlayer player, Plot plot, String value) {
|
||||
@Override
|
||||
public boolean set(PlotPlayer player, Plot plot, String value) {
|
||||
switch (value.toLowerCase()) {
|
||||
case "unset":
|
||||
case "reset":
|
||||
@ -55,7 +56,8 @@ public class SetHome extends SetCommand {
|
||||
Location bottom = base.getBottomAbs();
|
||||
Location location = player.getLocationFull();
|
||||
BlockLoc rel = new BlockLoc(location.getX() - bottom.getX(), location.getY(),
|
||||
location.getZ() - bottom.getZ(), location.getYaw(), location.getPitch());
|
||||
location.getZ() - bottom.getZ(), location.getYaw(), location.getPitch()
|
||||
);
|
||||
base.setHome(rel);
|
||||
player.sendMessage(TranslatableCaption.of("position.position_set"));
|
||||
default:
|
||||
@ -66,4 +68,5 @@ public class SetHome extends SetCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ import com.plotsquared.core.setup.SetupProcess;
|
||||
import com.plotsquared.core.setup.SetupStep;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -46,15 +46,16 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@CommandDeclaration(command = "setup",
|
||||
permission = "plots.admin.command.setup",
|
||||
usage = "/plot setup",
|
||||
aliases = {"create"},
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
permission = "plots.admin.command.setup",
|
||||
usage = "/plot setup",
|
||||
aliases = {"create"},
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
public class Setup extends SubCommand {
|
||||
|
||||
private final SetupUtils setupUtils;
|
||||
|
||||
@Inject public Setup(@Nonnull final SetupUtils setupUtils) {
|
||||
@Inject
|
||||
public Setup(final @NonNull SetupUtils setupUtils) {
|
||||
this.setupUtils = setupUtils;
|
||||
}
|
||||
|
||||
@ -63,7 +64,8 @@ public class Setup extends SubCommand {
|
||||
message.append("<gold>What generator do you want?</gold>");
|
||||
for (Entry<String, GeneratorWrapper<?>> entry : SetupUtils.generators.entrySet()) {
|
||||
if (entry.getKey().equals(PlotSquared.platform().pluginName())) {
|
||||
message.append("\n<dark_gray> - </dark_gray><dark_green>").append(entry.getKey()).append(" (Default Generator)</dark_green>");
|
||||
message.append("\n<dark_gray> - </dark_gray><dark_green>").append(entry.getKey()).append(
|
||||
" (Default Generator)</dark_green>");
|
||||
} else if (entry.getValue().isFull()) {
|
||||
message.append("\n<dark_gray> - </dark_gray><gray>").append(entry.getKey()).append(" (Plot Generator)</gray>");
|
||||
} else {
|
||||
@ -73,21 +75,22 @@ public class Setup extends SubCommand {
|
||||
player.sendMessage(StaticCaption.of(message.toString()));
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
try (final MetaDataAccess<SetupProcess> metaDataAccess =
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SETUP)) {
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SETUP)) {
|
||||
SetupProcess process = metaDataAccess.get().orElse(null);
|
||||
if (process == null) {
|
||||
if (args.length > 0) {
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_not_started"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "Use /plot setup to start a setup process.")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
process = new SetupProcess();
|
||||
metaDataAccess.set(process);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", "Use /plot setup to start a setup process.")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
process = new SetupProcess();
|
||||
metaDataAccess.set(process);
|
||||
this.setupUtils.updateGenerators();
|
||||
SetupStep step = process.getCurrentStep();
|
||||
step.announce(player);
|
||||
@ -114,10 +117,11 @@ public class Setup extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
SetupProcess process;
|
||||
try (final MetaDataAccess<SetupProcess> metaDataAccess =
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SETUP)) {
|
||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SETUP)) {
|
||||
process = metaDataAccess.get().orElse(null);
|
||||
}
|
||||
if (process == null) {
|
||||
@ -136,7 +140,9 @@ public class Setup extends SubCommand {
|
||||
|
||||
private void tryAddSubCommand(String subCommand, String argument, List<Command> suggestions) {
|
||||
if (!argument.isEmpty() && subCommand.startsWith(argument)) {
|
||||
suggestions.add(new Command(null, false, subCommand, "", RequiredType.NONE, null) {});
|
||||
suggestions.add(new Command(null, false, subCommand, "", RequiredType.NONE, null) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,10 +34,11 @@ import java.util.concurrent.CompletableFuture;
|
||||
/**
|
||||
* SubCommand class
|
||||
*
|
||||
* @see Command#Command(Command, boolean)
|
||||
* @deprecated In favor of normal Command class
|
||||
* @see Command#Command(Command, boolean)
|
||||
*/
|
||||
public abstract class SubCommand extends Command {
|
||||
|
||||
public SubCommand() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
@ -48,11 +49,14 @@ public abstract class SubCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
return CompletableFuture.completedFuture(onCommand(player, args));
|
||||
}
|
||||
|
||||
public abstract boolean onCommand(PlotPlayer<?> player, String[] args);
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,9 @@
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
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.Permissions;
|
||||
@ -38,16 +38,18 @@ import net.kyori.adventure.text.minimessage.Template;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(usage = "/plot swap <X;Z>",
|
||||
command = "swap",
|
||||
aliases = {"switch"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
command = "swap",
|
||||
aliases = {"switch"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Swap extends SubCommand {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot1 = location.getPlotAbs();
|
||||
if (plot1 == null) {
|
||||
@ -55,7 +57,7 @@ public class Swap extends SubCommand {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
if (!plot1.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
@ -96,7 +98,9 @@ public class Swap extends SubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,28 +30,27 @@ import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@CommandDeclaration(command = "target",
|
||||
usage = "/plot target <<X;Z> | nearest>",
|
||||
permission = "plots.target",
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.INFO)
|
||||
usage = "/plot target <<X;Z> | nearest>",
|
||||
permission = "plots.target",
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.INFO)
|
||||
public class Target extends SubCommand {
|
||||
|
||||
public Target() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
if (!location.isPlotArea()) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
@ -85,10 +84,13 @@ public class Target extends SubCommand {
|
||||
player.sendMessage(TranslatableCaption.of("compass.compass_target"));
|
||||
return true;
|
||||
}
|
||||
@Override public Collection<Command> tab(final PlotPlayer<?> player, String[] args, boolean space) {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, String[] args, boolean space) {
|
||||
return Stream.of("<X;Z>", "nearest")
|
||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||
.map(value -> new Command(null, false, value, "plots.target", RequiredType.PLAYER, null) {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,16 +27,16 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.inject.annotations.WorldConfig;
|
||||
import com.plotsquared.core.inject.annotations.WorldFile;
|
||||
import com.plotsquared.core.configuration.ConfigurationNode;
|
||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.configuration.InvalidConfigurationException;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.inject.annotations.WorldConfig;
|
||||
import com.plotsquared.core.inject.annotations.WorldFile;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
@ -51,16 +51,16 @@ import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
@ -68,9 +68,9 @@ import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@CommandDeclaration(command = "template",
|
||||
permission = "plots.admin",
|
||||
usage = "/plot template [import | export] <world> <template>",
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
permission = "plots.admin",
|
||||
usage = "/plot template [import | export] <world> <template>",
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
public class Template extends SubCommand {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
@ -79,11 +79,14 @@ public class Template extends SubCommand {
|
||||
private final SetupUtils setupUtils;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Template(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile,
|
||||
@Nonnull final SetupUtils setupUtils,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject
|
||||
public Template(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
@WorldConfig final @NonNull YamlConfiguration worldConfiguration,
|
||||
@WorldFile final @NonNull File worldFile,
|
||||
final @NonNull SetupUtils setupUtils,
|
||||
final @NonNull WorldUtil worldUtil
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
this.worldFile = worldFile;
|
||||
@ -94,7 +97,7 @@ public class Template extends SubCommand {
|
||||
public static boolean extractAllFiles(String world, String template) {
|
||||
try {
|
||||
File folder =
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES);
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES);
|
||||
if (!folder.exists()) {
|
||||
return false;
|
||||
}
|
||||
@ -109,9 +112,9 @@ public class Template extends SubCommand {
|
||||
while (ze != null) {
|
||||
if (!ze.isDirectory()) {
|
||||
String name = ze.getName().replace('\\', File.separatorChar)
|
||||
.replace('/', File.separatorChar);
|
||||
.replace('/', File.separatorChar);
|
||||
File newFile = new File(
|
||||
(output + File.separator + name).replaceAll("__TEMP_DIR__", world));
|
||||
(output + File.separator + name).replaceAll("__TEMP_DIR__", world));
|
||||
File parent = newFile.getParentFile();
|
||||
if (parent != null) {
|
||||
parent.mkdirs();
|
||||
@ -135,7 +138,10 @@ public class Template extends SubCommand {
|
||||
}
|
||||
|
||||
public static byte[] getBytes(PlotArea plotArea) {
|
||||
ConfigurationSection section = PlotSquared.get().getWorldConfiguration().getConfigurationSection("worlds." + plotArea.getWorldName());
|
||||
ConfigurationSection section = PlotSquared
|
||||
.get()
|
||||
.getWorldConfiguration()
|
||||
.getConfigurationSection("worlds." + plotArea.getWorldName());
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
String generator = PlotSquared.platform().setupUtils().getGenerator(plotArea);
|
||||
if (generator != null) {
|
||||
@ -151,8 +157,8 @@ public class Template extends SubCommand {
|
||||
File output = FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES);
|
||||
output.mkdirs();
|
||||
try (FileOutputStream fos = new FileOutputStream(
|
||||
output + File.separator + world + ".template");
|
||||
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||
output + File.separator + world + ".template");
|
||||
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||
|
||||
for (FileBytes file : files) {
|
||||
ZipEntry ze = new ZipEntry(file.path);
|
||||
@ -163,7 +169,8 @@ public class Template extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("export")) {
|
||||
@ -208,8 +215,10 @@ public class Template extends SubCommand {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
File worldFile = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
Settings.Paths.TEMPLATES + File.separator + "tmp-data.yml");
|
||||
File worldFile = FileUtils.getFile(
|
||||
PlotSquared.platform().getDirectory(),
|
||||
Settings.Paths.TEMPLATES + File.separator + "tmp-data.yml"
|
||||
);
|
||||
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
|
||||
this.worldConfiguration.set("worlds." + world, worldConfig.get(""));
|
||||
try {
|
||||
@ -219,7 +228,7 @@ public class Template extends SubCommand {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String manager =
|
||||
worldConfig.getString("generator.plugin", PlotSquared.platform().pluginName());
|
||||
worldConfig.getString("generator.plugin", PlotSquared.platform().pluginName());
|
||||
String generator = worldConfig.getString("generator.init", manager);
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder()
|
||||
.plotAreaType(ConfigurationUtil.getType(worldConfig))
|
||||
@ -246,8 +255,10 @@ public class Template extends SubCommand {
|
||||
}
|
||||
final PlotArea area = this.plotAreaManager.getPlotAreaByString(world);
|
||||
if (area == null) {
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"),
|
||||
net.kyori.adventure.text.minimessage.Template.of("value", args[1]));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.not_valid_plot_world"),
|
||||
net.kyori.adventure.text.minimessage.Template.of("value", args[1])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final PlotManager manager = area.getPlotManager();
|
||||
@ -270,7 +281,9 @@ public class Template extends SubCommand {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
if (args.length == 1) {
|
||||
final List<String> completions = new LinkedList<>();
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_TEMPLATE_EXPORT)) {
|
||||
@ -279,13 +292,24 @@ public class Template extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_TEMPLATE_IMPORT)) {
|
||||
completions.add("import");
|
||||
}
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||
.toLowerCase()
|
||||
.startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(
|
||||
null,
|
||||
true,
|
||||
completion,
|
||||
"",
|
||||
RequiredType.NONE,
|
||||
CommandCategory.ADMINISTRATION
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_TEMPLATE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
} return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,22 +32,25 @@ import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
@CommandDeclaration(command = "toggle",
|
||||
aliases = {"attribute"},
|
||||
permission = "plots.toggle",
|
||||
usage = "/plot toggle <chat | chatspy | clear-confirmation | time | titles | worldedit>",
|
||||
requiredType = RequiredType.NONE,
|
||||
category = CommandCategory.SETTINGS)
|
||||
aliases = {"attribute"},
|
||||
permission = "plots.toggle",
|
||||
usage = "/plot toggle <chat | chatspy | clear-confirmation | time | titles | worldedit>",
|
||||
requiredType = RequiredType.NONE,
|
||||
category = CommandCategory.SETTINGS)
|
||||
public class Toggle extends Command {
|
||||
|
||||
public Toggle() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "chatspy",
|
||||
aliases = {"spy"},
|
||||
permission = "plots.admin.command.chatspy")
|
||||
public void chatspy(Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
aliases = {"spy"},
|
||||
permission = "plots.admin.command.chatspy")
|
||||
public void chatspy(
|
||||
Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (toggle(player, "chatspy")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("toggle.toggle_disabled"),
|
||||
@ -62,11 +65,13 @@ public class Toggle extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "worldedit",
|
||||
aliases = {"we", "wea"},
|
||||
permission = "plots.worldedit.bypass")
|
||||
public void worldedit(Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
aliases = {"we", "wea"},
|
||||
permission = "plots.worldedit.bypass")
|
||||
public void worldedit(
|
||||
Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (toggle(player, "worldedit")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("toggle.toggle_disabled"),
|
||||
@ -81,10 +86,12 @@ public class Toggle extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "chat",
|
||||
permission = "plots.toggle.chat")
|
||||
public void chat(Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
permission = "plots.toggle.chat")
|
||||
public void chat(
|
||||
Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (toggle(player, "chat")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("toggle.toggle_disabled"),
|
||||
@ -99,10 +106,12 @@ public class Toggle extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "clear-confirmation",
|
||||
permission = "plots.admin.command.autoclear")
|
||||
public void clearConfirmation(Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
permission = "plots.admin.command.autoclear")
|
||||
public void clearConfirmation(
|
||||
Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (toggle(player, "ignoreExpireTask")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("toggle.toggle_disabled"),
|
||||
@ -117,10 +126,12 @@ public class Toggle extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "titles",
|
||||
permission = "plots.toggle.titles")
|
||||
public void titles(Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
permission = "plots.toggle.titles")
|
||||
public void titles(
|
||||
Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (toggle(player, "disabletitles")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("toggle.toggle_disabled"),
|
||||
@ -135,10 +146,12 @@ public class Toggle extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "time",
|
||||
permission = "plots.toggle.time")
|
||||
public void time(Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
permission = "plots.toggle.time")
|
||||
public void time(
|
||||
Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (toggle(player, "disabletime")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("toggle.toggle_disabled"),
|
||||
@ -153,10 +166,12 @@ public class Toggle extends Command {
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "debug",
|
||||
permission = "plots.toggle.debug")
|
||||
public void debug(Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
permission = "plots.toggle.debug")
|
||||
public void debug(
|
||||
Command command, PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) {
|
||||
if (!toggle(player, "debug")) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("toggle.toggle_disabled"),
|
||||
@ -180,4 +195,5 @@ public class Toggle extends Command {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,20 +46,20 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandDeclaration(command = "trim",
|
||||
permission = "plots.admin",
|
||||
usage = "/plot trim <world> [regenerate]",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
permission = "plots.admin",
|
||||
usage = "/plot trim <world> [regenerate]",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
public class Trim extends SubCommand {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + Trim.class.getSimpleName());
|
||||
@ -70,10 +70,13 @@ public class Trim extends SubCommand {
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
private final RegionManager regionManager;
|
||||
|
||||
@Inject public Trim(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final WorldUtil worldUtil,
|
||||
@Nonnull final GlobalBlockQueue blockQueue,
|
||||
@Nonnull final RegionManager regionManager) {
|
||||
@Inject
|
||||
public Trim(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull WorldUtil worldUtil,
|
||||
final @NonNull GlobalBlockQueue blockQueue,
|
||||
final @NonNull RegionManager regionManager
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldUtil = worldUtil;
|
||||
this.blockQueue = blockQueue;
|
||||
@ -87,8 +90,10 @@ public class Trim extends SubCommand {
|
||||
* @param result (viable = .mcr to trim, nonViable = .mcr keep)
|
||||
* @return success or not
|
||||
*/
|
||||
public static boolean getTrimRegions(String world,
|
||||
final RunnableVal2<Set<BlockVector2>, Set<BlockVector2>> result) {
|
||||
public static boolean getTrimRegions(
|
||||
String world,
|
||||
final RunnableVal2<Set<BlockVector2>, Set<BlockVector2>> result
|
||||
) {
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
@ -103,7 +108,8 @@ public class Trim extends SubCommand {
|
||||
StaticCaption.of(" - CHUNKS: " + (result.value1.size() * 1024) + " (max)");
|
||||
StaticCaption.of(" - TIME ESTIMATE: 12 Parsecs");
|
||||
TaskManager.getPlatformImplementation().objectTask(plots, new RunnableVal<Plot>() {
|
||||
@Override public void run(Plot plot) {
|
||||
@Override
|
||||
public void run(Plot plot) {
|
||||
Location pos1 = plot.getCorners()[0];
|
||||
Location pos2 = plot.getCorners()[1];
|
||||
int ccx1 = pos1.getX() >> 9;
|
||||
@ -120,11 +126,12 @@ public class Trim extends SubCommand {
|
||||
}
|
||||
}
|
||||
}).thenAccept(ignore ->
|
||||
TaskManager.getPlatformImplementation().taskLater(result, TaskTime.ticks(1L)));
|
||||
TaskManager.getPlatformImplementation().taskLater(result, TaskTime.ticks(1L)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendUsage(player);
|
||||
return false;
|
||||
@ -141,14 +148,16 @@ public class Trim extends SubCommand {
|
||||
Trim.TASK = true;
|
||||
final boolean regen = args.length == 2 && Boolean.parseBoolean(args[1]);
|
||||
getTrimRegions(world, new RunnableVal2<Set<BlockVector2>, Set<BlockVector2>>() {
|
||||
@Override public void run(Set<BlockVector2> viable, final Set<BlockVector2> nonViable) {
|
||||
@Override
|
||||
public void run(Set<BlockVector2> viable, final Set<BlockVector2> nonViable) {
|
||||
Runnable regenTask;
|
||||
if (regen) {
|
||||
logger.info("Starting regen task");
|
||||
logger.info(" - This is a VERY slow command");
|
||||
logger.info(" - It will say 'Trim done!' when complete");
|
||||
regenTask = new Runnable() {
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (nonViable.isEmpty()) {
|
||||
Trim.TASK = false;
|
||||
player.sendMessage(TranslatableCaption.of("trim.trim_done"));
|
||||
@ -171,12 +180,12 @@ public class Trim extends SubCommand {
|
||||
int bx = cbx << 4;
|
||||
int bz = cbz << 4;
|
||||
CuboidRegion region =
|
||||
RegionUtil.createRegion(bx, bx + 511, bz, bz + 511);
|
||||
RegionUtil.createRegion(bx, bx + 511, bz, bz + 511);
|
||||
for (Plot plot : PlotQuery.newQuery().inWorld(world)) {
|
||||
Location bot = plot.getBottomAbs();
|
||||
Location top = plot.getExtendedTopAbs();
|
||||
CuboidRegion plotReg = RegionUtil
|
||||
.createRegion(bot.getX(), top.getX(), bot.getZ(), top.getZ());
|
||||
.createRegion(bot.getX(), top.getX(), bot.getZ(), top.getZ());
|
||||
if (!RegionUtil.intersects(region, plotReg)) {
|
||||
continue;
|
||||
}
|
||||
@ -191,11 +200,12 @@ public class Trim extends SubCommand {
|
||||
}
|
||||
final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
|
||||
TaskManager.getPlatformImplementation().objectTask(chunks, new RunnableVal<BlockVector2>() {
|
||||
@Override public void run(BlockVector2 value) {
|
||||
@Override
|
||||
public void run(BlockVector2 value) {
|
||||
queue.regenChunk(value.getX(), value.getZ());
|
||||
}
|
||||
}).thenAccept(ignore -> TaskManager.getPlatformImplementation()
|
||||
.taskLater(this, TaskTime.ticks(1L)));
|
||||
.taskLater(this, TaskTime.ticks(1L)));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@ -211,4 +221,5 @@ public class Trim extends SubCommand {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.Templates;
|
||||
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;
|
||||
@ -40,8 +40,8 @@ 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.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@ -50,34 +50,40 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "trust",
|
||||
aliases = {"t"},
|
||||
requiredType = RequiredType.PLAYER,
|
||||
usage = "/plot trust <player | *>",
|
||||
category = CommandCategory.SETTINGS)
|
||||
aliases = {"t"},
|
||||
requiredType = RequiredType.PLAYER,
|
||||
usage = "/plot trust <player | *>",
|
||||
category = CommandCategory.SETTINGS)
|
||||
public class Trust extends Command {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Trust(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
|
||||
@Inject
|
||||
public Trust(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 {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
final Plot currentPlot = player.getCurrentPlot();
|
||||
if (currentPlot == null) {
|
||||
throw new CommandException(TranslatableCaption.of("errors.not_in_plot"));
|
||||
}
|
||||
checkTrue(currentPlot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
|
||||
checkTrue(currentPlot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||
TranslatableCaption.of("permission.no_plot_perms"));
|
||||
checkTrue(
|
||||
currentPlot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||
TranslatableCaption.of("permission.no_plot_perms")
|
||||
);
|
||||
|
||||
checkTrue(args.length == 1, TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage()));
|
||||
Templates.of("value", getUsage())
|
||||
);
|
||||
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
@ -94,15 +100,16 @@ public class Trust extends Command {
|
||||
return;
|
||||
} else {
|
||||
checkTrue(!uuids.isEmpty(), TranslatableCaption.of("errors.invalid_player"),
|
||||
Templates.of("value", args[0]));
|
||||
Templates.of("value", args[0])
|
||||
);
|
||||
|
||||
Iterator<UUID> iterator = uuids.iterator();
|
||||
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
|
||||
while (iterator.hasNext()) {
|
||||
UUID uuid = iterator.next();
|
||||
if (uuid == DBFunc.EVERYONE && !(
|
||||
Permissions.hasPermission(player, Permission.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
Permissions.hasPermission(player, Permission.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", PlayerManager.getName(uuid))
|
||||
@ -131,7 +138,10 @@ public class Trust extends Command {
|
||||
checkTrue(!uuids.isEmpty(), null);
|
||||
int maxTrustSize = Permissions.hasPermissionRange(player, Permission.PERMISSION_TRUST, Settings.Limit.MAX_PLOTS);
|
||||
if (size > maxTrustSize) {
|
||||
player.sendMessage(TranslatableCaption.of("members.plot_max_members_trusted"), Template.of("amount", String.valueOf(size - 1)));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("members.plot_max_members_trusted"),
|
||||
Template.of("amount", String.valueOf(size - 1))
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Success
|
||||
@ -155,7 +165,8 @@ public class Trust extends Command {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,11 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.PlotUnlinkEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
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.EventDispatcher;
|
||||
@ -38,24 +38,25 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@CommandDeclaration(command = "unlink",
|
||||
aliases = {"u", "unmerge"},
|
||||
usage = "/plot unlink [createroads]",
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.SETTINGS,
|
||||
confirmation = true)
|
||||
aliases = {"u", "unmerge"},
|
||||
usage = "/plot unlink [createroads]",
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.SETTINGS,
|
||||
confirmation = true)
|
||||
public class Unlink extends SubCommand {
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject public Unlink(@Nonnull final EventDispatcher eventDispatcher) {
|
||||
|
||||
@Inject
|
||||
public Unlink(final @NonNull EventDispatcher eventDispatcher) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -81,17 +82,19 @@ public class Unlink extends SubCommand {
|
||||
}
|
||||
|
||||
PlotUnlinkEvent event = this.eventDispatcher
|
||||
.callUnlink(plot.getArea(), plot, createRoad, createRoad,
|
||||
PlotUnlinkEvent.REASON.PLAYER_COMMAND);
|
||||
.callUnlink(plot.getArea(), plot, createRoad, createRoad,
|
||||
PlotUnlinkEvent.REASON.PLAYER_COMMAND
|
||||
);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Unlink"));
|
||||
Template.of("value", "Unlink")
|
||||
);
|
||||
return true;
|
||||
}
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
if (!force && !plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_UNLINK)) {
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_UNLINK)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
}
|
||||
Runnable runnable = () -> {
|
||||
@ -108,4 +111,5 @@ public class Unlink extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.caption.Templates;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
@ -45,8 +45,8 @@ import com.plotsquared.core.util.query.SortingStrategy;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -56,22 +56,25 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "visit",
|
||||
permission = "plots.visit",
|
||||
usage = "/plot visit <player> | <alias> | <plot> [area]|[#] [#]",
|
||||
aliases = {"v", "tp", "teleport", "goto", "warp"},
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.TELEPORT)
|
||||
permission = "plots.visit",
|
||||
usage = "/plot visit <player> | <alias> | <plot> [area]|[#] [#]",
|
||||
aliases = {"v", "tp", "teleport", "goto", "warp"},
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.TELEPORT)
|
||||
public class Visit extends Command {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
@Inject public Visit(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
|
||||
@Inject
|
||||
public Visit(final @NonNull PlotAreaManager plotAreaManager) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
private void visit(@Nonnull final PlotPlayer player, @Nonnull final PlotQuery query, final PlotArea sortByArea,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone, int page) {
|
||||
private void visit(
|
||||
final @NonNull PlotPlayer player, final @NonNull PlotQuery query, final PlotArea sortByArea,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone, int page
|
||||
) {
|
||||
// We get the query once,
|
||||
// then we get it another time further on
|
||||
final List<Plot> unsorted = query.asList();
|
||||
@ -106,40 +109,52 @@ public class Visit extends Command {
|
||||
final Plot plot = plots.get(page - 1);
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_VISIT_UNOWNED)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.unowned"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.unowned")
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else if (plot.isOwner(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_VISIT_OWNED) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_HOME)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.owned"));
|
||||
.hasPermission(player, Permission.PERMISSION_HOME)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.owned")
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else if (plot.isAdded(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_SHARED)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.shared"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.shared")
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_VISIT_OTHER)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.other"));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.visit.other")
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!plot.getFlag(UntrustedVisitFlag.class) && !Permissions
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_VISIT_UNTRUSTED)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.admin.visit.untrusted"));
|
||||
.hasPermission(player, Permission.PERMISSION_ADMIN_VISIT_UNTRUSTED)) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Templates.of("node", "plots.admin.visit.untrusted")
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (plot.isDenied(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_VISIT_DENIED)) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_VISIT_DENIED)));
|
||||
return;
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_VISIT_DENIED))
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -154,10 +169,12 @@ public class Visit extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player,
|
||||
String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
public CompletableFuture<Boolean> execute(
|
||||
final PlotPlayer<?> player,
|
||||
String[] args,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone
|
||||
) throws CommandException {
|
||||
if (args.length == 1 && args[0].contains(":")) {
|
||||
args = args[0].split(":");
|
||||
}
|
||||
@ -170,23 +187,31 @@ public class Visit extends Command {
|
||||
// /p v <user> <area> <page>
|
||||
case 3:
|
||||
if (!MathMan.isInteger(args[2])) {
|
||||
player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"),
|
||||
Templates.of("value", "(1, ∞)"));
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("invalid.not_valid_number"),
|
||||
Templates.of("value", "(1, ∞)")
|
||||
);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage())
|
||||
);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
page = Integer.parseInt(args[2]);
|
||||
// /p v <name> <area> [page]
|
||||
// /p v <name> [page]
|
||||
// /p v <name> <area> [page]
|
||||
// /p v <name> [page]
|
||||
case 2:
|
||||
if (page != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) {
|
||||
sortByArea = this.plotAreaManager.getPlotAreaByString(args[1]);
|
||||
if (sortByArea == null) {
|
||||
player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"),
|
||||
Templates.of("value", "(1, ∞)"));
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("invalid.not_valid_number"),
|
||||
Templates.of("value", "(1, ∞)")
|
||||
);
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage())
|
||||
);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
@ -196,20 +221,29 @@ public class Visit extends Command {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (throwable != null || uuids.size() != 1) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage())
|
||||
);
|
||||
} else {
|
||||
final UUID uuid = uuids.toArray(new UUID[0])[0];
|
||||
this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), finalSortByArea, confirm, whenDone, finalPage1);
|
||||
this.visit(
|
||||
player,
|
||||
PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(),
|
||||
finalSortByArea,
|
||||
confirm,
|
||||
whenDone,
|
||||
finalPage1
|
||||
);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
page = Integer.parseInt(args[1]);
|
||||
// /p v <name> [page]
|
||||
// /p v <uuid> [page]
|
||||
// /p v <plot> [page]
|
||||
// /p v <alias>
|
||||
// /p v <name> [page]
|
||||
// /p v <uuid> [page]
|
||||
// /p v <plot> [page]
|
||||
// /p v <alias>
|
||||
case 1:
|
||||
final String[] finalArgs = args;
|
||||
int finalPage = page;
|
||||
@ -224,7 +258,14 @@ public class Visit extends Command {
|
||||
} else if (uuid == null) {
|
||||
// player not found, so we assume it's an alias if no page was provided
|
||||
if (finalPage == Integer.MIN_VALUE) {
|
||||
this.visit(player, PlotQuery.newQuery().withAlias(finalArgs[0]), player.getApplicablePlotArea(), confirm, whenDone, 1);
|
||||
this.visit(
|
||||
player,
|
||||
PlotQuery.newQuery().withAlias(finalArgs[0]),
|
||||
player.getApplicablePlotArea(),
|
||||
confirm,
|
||||
whenDone,
|
||||
1
|
||||
);
|
||||
} else {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("errors.invalid_player"),
|
||||
@ -232,7 +273,14 @@ public class Visit extends Command {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), null, confirm, whenDone, finalPage);
|
||||
this.visit(
|
||||
player,
|
||||
PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(),
|
||||
null,
|
||||
confirm,
|
||||
whenDone,
|
||||
finalPage
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@ -245,8 +293,10 @@ public class Visit extends Command {
|
||||
break;
|
||||
case 0:
|
||||
// /p v is invalid
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage()));
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Templates.of("value", getUsage())
|
||||
);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
default:
|
||||
}
|
||||
@ -254,7 +304,8 @@ public class Visit extends Command {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
@Override
|
||||
public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
final List<Command> completions = new ArrayList<>();
|
||||
switch (args.length - 1) {
|
||||
case 0:
|
||||
@ -294,7 +345,9 @@ public class Visit extends Command {
|
||||
continue;
|
||||
}
|
||||
commands.add(new Command(this, false, command, "",
|
||||
RequiredType.NONE, CommandCategory.TELEPORT) {});
|
||||
RequiredType.NONE, CommandCategory.TELEPORT
|
||||
) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,7 +358,9 @@ public class Visit extends Command {
|
||||
continue;
|
||||
}
|
||||
commands.add(new Command(this, false, area.getWorldName() + ";" + area.getId(), "",
|
||||
RequiredType.NONE, CommandCategory.TELEPORT) {});
|
||||
RequiredType.NONE, CommandCategory.TELEPORT
|
||||
) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,15 +28,16 @@ package com.plotsquared.core.command;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
|
||||
@CommandDeclaration(command = "weanywhere",
|
||||
permission = "plots.worldedit.bypass",
|
||||
aliases = {"wea"},
|
||||
usage = "/plot weanywhere",
|
||||
requiredType = RequiredType.NONE,
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
permission = "plots.worldedit.bypass",
|
||||
aliases = {"wea"},
|
||||
usage = "/plot weanywhere",
|
||||
requiredType = RequiredType.NONE,
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
@Deprecated
|
||||
public class WE_Anywhere extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
|
||||
MainCommand.getInstance().toggle.worldedit(this, player, new String[0], null, null);
|
||||
return true;
|
||||
}
|
||||
|
@ -33,11 +33,11 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.PlotInventory;
|
||||
|
||||
@CommandDeclaration(command = "components",
|
||||
permission = "plots.components",
|
||||
description = "Open the component preset GUI",
|
||||
usage = "/plot components",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
permission = "plots.components",
|
||||
description = "Open the component preset GUI",
|
||||
usage = "/plot components",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class ComponentCommand extends SubCommand {
|
||||
|
||||
private final ComponentPresetManager componentPresetManager;
|
||||
@ -46,7 +46,8 @@ public class ComponentCommand extends SubCommand {
|
||||
this.componentPresetManager = componentPresetManager;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
final PlotInventory inventory = componentPresetManager.buildInventory(player);
|
||||
if (inventory != null) {
|
||||
inventory.openInventory();
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user