mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Merge branch 'v6' into feature/v6/platform
# Conflicts: # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
This commit is contained in:
202
Core/src/main/java/com/plotsquared/core/command/HomeCommand.java
Normal file
202
Core/src/main/java/com/plotsquared/core/command/HomeCommand.java
Normal file
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.query.SortingStrategy;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "home",
|
||||
description = "Teleport to your plot(s)",
|
||||
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 {
|
||||
public HomeCommand() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
private void home(@NotNull final PlotPlayer<?> player,
|
||||
@NotNull final PlotQuery query, final int page,
|
||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
List<Plot> plots = query.asList();
|
||||
if (plots.isEmpty()) {
|
||||
Captions.FOUND_NO_PLOTS.send(player);
|
||||
return;
|
||||
} else if (plots.size() < page) {
|
||||
MainUtil.sendMessage(player,
|
||||
String.format(Captions.NUMBER_NOT_IN_RANGE.getTranslated(), "1", plots.size()));
|
||||
return;
|
||||
}
|
||||
Plot plot = plots.get(page - 1);
|
||||
confirm.run(this, () -> plot.teleportPlayer(player, TeleportCause.COMMAND, result -> {
|
||||
if (result) {
|
||||
whenDone.run(this, CommandResult.SUCCESS);
|
||||
} else {
|
||||
whenDone.run(HomeCommand.this, CommandResult.FAILURE);
|
||||
}
|
||||
}), () -> whenDone.run(HomeCommand.this, CommandResult.FAILURE));
|
||||
}
|
||||
|
||||
@NotNull private PlotQuery query(@NotNull final PlotPlayer<?> player) {
|
||||
// everything plots need to have in common here
|
||||
return PlotQuery.newQuery().ownedBy(player).whereBasePlot();
|
||||
}
|
||||
|
||||
@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>
|
||||
// /plot home <area> <x;y>
|
||||
// /plot home <area> <page>
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_HOME)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
if (args.length > 2) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
PlotQuery query = query(player);
|
||||
int page = 1; // page = index + 1
|
||||
String identifier;
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
identifier = args[0];
|
||||
if (MathMan.isInteger(identifier)) {
|
||||
try {
|
||||
page = Integer.parseInt(identifier);
|
||||
} catch (NumberFormatException ignored) {
|
||||
Captions.NOT_A_NUMBER.send(player, identifier);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
|
||||
break;
|
||||
}
|
||||
// either plot id or alias
|
||||
Plot fromId = MainUtil.getPlotFromString(player, identifier, false);
|
||||
if (fromId != null && fromId.isOwner(player.getUUID())) {
|
||||
// it was a valid plot id
|
||||
query.withPlot(fromId);
|
||||
break;
|
||||
}
|
||||
// it wasn't a valid plot id, trying to find plot by alias
|
||||
query.withAlias(identifier);
|
||||
break;
|
||||
case 2:
|
||||
// we assume args[0] is a plot area and args[1] an identifier
|
||||
PlotArea plotArea = PlotSquared.get().getPlotAreaByString(args[0]);
|
||||
identifier = args[1];
|
||||
if (plotArea == null) {
|
||||
// invalid command, therefore no plots
|
||||
query.noPlots();
|
||||
break;
|
||||
}
|
||||
query.inArea(plotArea);
|
||||
if (MathMan.isInteger(identifier)) {
|
||||
// identifier is a page number
|
||||
try {
|
||||
page = Integer.parseInt(identifier);
|
||||
} catch (NumberFormatException ignored) {
|
||||
Captions.NOT_A_NUMBER.send(player, identifier);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
|
||||
break;
|
||||
}
|
||||
// identifier needs to be a plot id then
|
||||
PlotId id = PlotId.fromStringOrNull(identifier);
|
||||
if (id == null) {
|
||||
// invalid command, therefore no plots
|
||||
query.noPlots();
|
||||
break;
|
||||
}
|
||||
// we can try to get this plot
|
||||
Plot plot = plotArea.getPlot(id);
|
||||
if (plot == null) {
|
||||
query.noPlots();
|
||||
break;
|
||||
}
|
||||
// as the query already filters by owner, this is fine
|
||||
query.withPlot(plot);
|
||||
break;
|
||||
case 0:
|
||||
query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
|
||||
break;
|
||||
}
|
||||
home(player, query, page, confirm, whenDone);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
final List<Command> completions = new ArrayList<>();
|
||||
switch (args.length - 1) {
|
||||
case 0:
|
||||
completions.addAll(
|
||||
TabCompletions.completeAreas(args[0]));
|
||||
if (args[0].isEmpty()) {
|
||||
// if no input is given, only suggest 1 - 3
|
||||
completions.addAll(
|
||||
TabCompletions.asCompletions("1", "2", "3"));
|
||||
break;
|
||||
}
|
||||
// complete more numbers from the already given input
|
||||
completions.addAll(
|
||||
TabCompletions.completeNumbers(args[0], 10, 999));
|
||||
break;
|
||||
case 1:
|
||||
completions.addAll(
|
||||
TabCompletions.completeNumbers(args[1], 10, 999));
|
||||
break;
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
@ -77,6 +77,7 @@ public class MainCommand extends Command {
|
||||
new RegenAllRoads();
|
||||
new Claim();
|
||||
new Auto();
|
||||
new HomeCommand();
|
||||
new Visit();
|
||||
new Set();
|
||||
new Clear();
|
||||
|
@ -40,12 +40,11 @@ import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.query.SortingStrategy;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -54,8 +53,8 @@ import java.util.concurrent.TimeoutException;
|
||||
@CommandDeclaration(command = "visit",
|
||||
permission = "plots.visit",
|
||||
description = "Visit someones plot",
|
||||
usage = "/plot visit [<player>|<alias>|<world>|<id>] [#]",
|
||||
aliases = {"v", "tp", "teleport", "goto", "home", "h", "warp"},
|
||||
usage = "/plot visit <player>|<alias>|<plot> [area]|[#] [#]",
|
||||
aliases = {"v", "tp", "teleport", "goto", "warp"},
|
||||
requiredType = RequiredType.PLAYER,
|
||||
category = CommandCategory.TELEPORT)
|
||||
public class Visit extends Command {
|
||||
@ -153,9 +152,9 @@ public class Visit extends Command {
|
||||
int page = Integer.MIN_VALUE;
|
||||
|
||||
switch (args.length) {
|
||||
// /p v [...] [...] <page>
|
||||
// /p v <user> <area> <page>
|
||||
case 3:
|
||||
if (!MathMan.isInteger(args[1])) {
|
||||
if (!MathMan.isInteger(args[2])) {
|
||||
Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)");
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
@ -188,24 +187,13 @@ public class Visit extends Command {
|
||||
}
|
||||
page = Integer.parseInt(args[1]);
|
||||
// /p v <name> [page]
|
||||
// /p v <page> [page]
|
||||
// /p v <uuid> [page]
|
||||
// /p v <plot> [page]
|
||||
// /p v <alias>
|
||||
case 1:
|
||||
final String[] finalArgs = args;
|
||||
int finalPage = page;
|
||||
// Try to determine whether the given argument is a username
|
||||
// or an ordinal
|
||||
boolean isNumber = false;
|
||||
if (args[0].length() < 2) {
|
||||
isNumber = true;
|
||||
} else if (args[0].length() <= 4 && MathMan.isInteger(args[0])) {
|
||||
// Check if it's an all-digit username that is stored in cache
|
||||
final UUIDMapping mapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(args[0]);
|
||||
// If no UUID could be found, then we assume it's a number and not a username
|
||||
isNumber = mapping == null;
|
||||
}
|
||||
if (!isNumber && args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) {
|
||||
if (args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
// The request timed out
|
||||
@ -214,79 +202,61 @@ public class Visit extends Command {
|
||||
// It was a valid UUID but the player has no plots
|
||||
MainUtil.sendMessage(player, Captions.PLAYER_NO_PLOTS);
|
||||
} else if (uuid == null) {
|
||||
if (finalPage == Integer.MIN_VALUE && MathMan.isInteger(finalArgs[0])) {
|
||||
// The argument was a number, so we assume it's the page number
|
||||
int parsedPage;
|
||||
try {
|
||||
parsedPage = Integer.parseInt(finalArgs[0]);
|
||||
} catch (final Throwable t) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_A_NUMBER, finalArgs[0]);
|
||||
return;
|
||||
}
|
||||
this.visit(player, PlotQuery.newQuery().ownedBy(player).whereBasePlot(), null,
|
||||
confirm, whenDone, parsedPage);
|
||||
// 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);
|
||||
} else {
|
||||
// Try to parse a plot
|
||||
final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
|
||||
if (plot == null) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID);
|
||||
return;
|
||||
}
|
||||
this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1);
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, finalArgs[0]);
|
||||
}
|
||||
} else {
|
||||
this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), null, confirm, whenDone, finalPage);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (finalPage == Integer.MIN_VALUE && MathMan.isInteger(finalArgs[0])) {
|
||||
// The argument was a number, so we assume it's the page number
|
||||
int parsedPage;
|
||||
try {
|
||||
parsedPage = Integer.parseInt(finalArgs[0]);
|
||||
this.visit(player, PlotQuery.newQuery().ownedBy(player).whereBasePlot(), null, confirm,
|
||||
whenDone, parsedPage);
|
||||
} catch (final Throwable throwable) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_A_NUMBER, finalArgs[0]);
|
||||
}
|
||||
} else {
|
||||
// Try to parse a plot
|
||||
final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
|
||||
if (plot != null) {
|
||||
this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1);
|
||||
}
|
||||
// Try to parse a plot
|
||||
final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
|
||||
if (plot != null) {
|
||||
this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
// /p v
|
||||
this.visit(player, PlotQuery.newQuery().ownedBy(player), null, confirm, whenDone);
|
||||
break;
|
||||
// /p v is invalid
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
default:
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
final List<Command> completions = new LinkedList<>();
|
||||
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
final List<Command> completions = new ArrayList<>();
|
||||
switch (args.length - 1) {
|
||||
case 0:
|
||||
this.completeNumbers(completions, args[0], 0);
|
||||
completions.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
break;
|
||||
break;
|
||||
case 1:
|
||||
if (MathMan.isInteger(args[0])) {
|
||||
completions.addAll(
|
||||
TabCompletions.completeAreas(args[1]));
|
||||
if (args[1].isEmpty()) {
|
||||
// if no input is given, only suggest 1 - 3
|
||||
completions.addAll(
|
||||
TabCompletions.asCompletions("1", "2", "3"));
|
||||
break;
|
||||
}
|
||||
this.completeNumbers(completions, args[1], 0);
|
||||
this.completeAreas(completions, args[1]);
|
||||
completions.addAll(
|
||||
TabCompletions.completeNumbers(args[1], 10, 999));
|
||||
break;
|
||||
case 2:
|
||||
if (MathMan.isInteger(args[1])) {
|
||||
if (args[2].isEmpty()) {
|
||||
// if no input is given, only suggest 1 - 3
|
||||
completions.addAll(
|
||||
TabCompletions.asCompletions("1", "2", "3"));
|
||||
break;
|
||||
}
|
||||
this.completeNumbers(completions, args[2], 0);
|
||||
completions.addAll(
|
||||
TabCompletions.completeNumbers(args[2], 10, 999));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,7 @@ public abstract class PlotArea {
|
||||
@Getter private GameMode gameMode = GameModes.CREATIVE;
|
||||
@Getter private Map<String, Expression<Double>> prices = new HashMap<>();
|
||||
@Getter(AccessLevel.PROTECTED) private List<String> schematics = new ArrayList<>();
|
||||
@Getter private boolean roadFlags = false;
|
||||
private boolean worldBorder = false;
|
||||
private boolean useEconomy = false;
|
||||
private int hash;
|
||||
@ -127,7 +128,9 @@ public abstract class PlotArea {
|
||||
/**
|
||||
* Area flag container
|
||||
*/
|
||||
@Getter private FlagContainer flagContainer =
|
||||
@Getter private final FlagContainer flagContainer =
|
||||
new FlagContainer(GlobalFlagContainer.getInstance());
|
||||
@Getter private final FlagContainer roadFlagContainer =
|
||||
new FlagContainer(GlobalFlagContainer.getInstance());
|
||||
|
||||
public PlotArea(@NotNull final String worldName, @Nullable final String id,
|
||||
@ -370,6 +373,40 @@ public abstract class PlotArea {
|
||||
this.spawnEggs = config.getBoolean("event.spawn.egg");
|
||||
this.spawnCustom = config.getBoolean("event.spawn.custom");
|
||||
this.spawnBreeding = config.getBoolean("event.spawn.breeding");
|
||||
|
||||
List<String> roadflags = config.getStringList("flags.default");
|
||||
if (roadflags.isEmpty()) {
|
||||
roadflags = config.getStringList("road.flags");
|
||||
if (roadflags.isEmpty()) {
|
||||
roadflags = new ArrayList<>();
|
||||
ConfigurationSection section = config.getConfigurationSection("road.flags");
|
||||
Set<String> keys = section.getKeys(false);
|
||||
for (String key : keys) {
|
||||
if (!"default".equals(key)) {
|
||||
roadflags.add(key + ';' + section.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.getRoadFlagContainer().addAll(parseFlags(roadflags));
|
||||
|
||||
StringBuilder roadFlagBuilder = new StringBuilder();
|
||||
Collection<PlotFlag<?, ?>> roadFlagCollection = this.getFlagContainer().getFlagMap().values();
|
||||
if (roadFlagCollection.isEmpty()) {
|
||||
roadFlagBuilder.append(Captions.NONE.getTranslated());
|
||||
} else {
|
||||
roadFlags = true;
|
||||
String prefix = " ";
|
||||
for (final PlotFlag<?, ?> flag : roadFlagCollection) {
|
||||
Object value = flag.toString();
|
||||
roadFlagBuilder.append(prefix).append(CaptionUtility
|
||||
.format(null, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(),
|
||||
CaptionUtility.formatRaw(null, value.toString(), "")));
|
||||
prefix = ", ";
|
||||
}
|
||||
}
|
||||
PlotSquared.log(Captions.PREFIX + "&3 - road flags: &7" + roadFlagBuilder.toString());
|
||||
|
||||
loadConfiguration(config);
|
||||
}
|
||||
|
||||
@ -413,6 +450,7 @@ public abstract class PlotArea {
|
||||
options.put("world.max_height", this.getMaxBuildHeight());
|
||||
options.put("world.min_height", this.getMinBuildHeight());
|
||||
options.put("world.gamemode", this.getGameMode().getName().toLowerCase());
|
||||
options.put("road.flags.default", null);
|
||||
|
||||
if (this.getType() != PlotAreaType.NORMAL) {
|
||||
options.put("generator.terrain", this.getTerrain());
|
||||
@ -434,6 +472,9 @@ public abstract class PlotArea {
|
||||
config.set("flags.use",
|
||||
"63,64,68,69,71,77,96,143,167,193,194,195,196,197,77,143,69,70,72,147,148,107,183,184,185,186,187,132");
|
||||
}
|
||||
if (!config.contains("road.flags")) {
|
||||
config.set("road.flags.liquid-flow", false);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull @Override public String toString() {
|
||||
@ -1069,4 +1110,52 @@ public abstract class PlotArea {
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value associated with the specified flag. This will look at
|
||||
* the default values stored in {@link GlobalFlagContainer}.
|
||||
*
|
||||
* @param flagClass The flag type (Class)
|
||||
* @return The flag value
|
||||
*/
|
||||
public <T> T getFlag(final Class<? extends PlotFlag<T, ?>> flagClass) {
|
||||
return this.flagContainer.getFlag(flagClass).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value associated with the specified flag. This will look at
|
||||
* the default values stored in {@link GlobalFlagContainer}.
|
||||
*
|
||||
* @param flag The flag type (Any instance of the flag)
|
||||
* @return The flag value
|
||||
*/
|
||||
public <T, V extends PlotFlag<T, ?>> T getFlag(final V flag) {
|
||||
final Class<?> flagClass = flag.getClass();
|
||||
final PlotFlag<?, ?> flagInstance = this.flagContainer.getFlagErased(flagClass);
|
||||
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value associated with the specified road flag. This will look at
|
||||
* the default values stored in {@link GlobalFlagContainer}.
|
||||
*
|
||||
* @param flagClass The flag type (Class)
|
||||
* @return The flag value
|
||||
*/
|
||||
public <T> T getRoadFlag(final Class<? extends PlotFlag<T, ?>> flagClass) {
|
||||
return this.roadFlagContainer.getFlag(flagClass).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value associated with the specified road flag. This will look at
|
||||
* the default values stored in {@link GlobalFlagContainer}.
|
||||
*
|
||||
* @param flag The flag type (Any instance of the flag)
|
||||
* @return The flag value
|
||||
*/
|
||||
public <T, V extends PlotFlag<T, ?>> T getRoadFlag(final V flag) {
|
||||
final Class<?> flagClass = flag.getClass();
|
||||
final PlotFlag<?, ?> flagInstance = this.roadFlagContainer.getFlagErased(flagClass);
|
||||
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import com.plotsquared.core.command.RequiredType;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -136,6 +137,65 @@ public class TabCompletions {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of integer numbers matching the given input. If the input string
|
||||
* is empty, nothing will be returned. The list is unmodifiable.
|
||||
*
|
||||
* @param input Input to filter with
|
||||
* @param amountLimit Maximum amount of suggestions
|
||||
* @param highestLimit Highest number to include
|
||||
* @return Unmodifiable list of number completions
|
||||
*/
|
||||
@NotNull public List<Command> completeNumbers(@NotNull final String input,
|
||||
final int amountLimit, final int highestLimit) {
|
||||
if (input.isEmpty() || input.length() > highestLimit || !MathMan.isInteger(input)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
int offset;
|
||||
try {
|
||||
offset = Integer.parseInt(input) * 10;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<String> commands = new ArrayList<>();
|
||||
for (int i = offset; i < highestLimit && (offset - i + amountLimit) > 0; i++) {
|
||||
commands.add(String.valueOf(i));
|
||||
}
|
||||
return asCompletions(commands.toArray(new String[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of plot areas matching the given input.
|
||||
* The list is unmodifiable.
|
||||
*
|
||||
* @param input Input to filter with
|
||||
* @return Unmodifiable list of area completions
|
||||
*/
|
||||
@NotNull public List<Command> completeAreas(@NotNull final String input) {
|
||||
final List<Command> completions = new ArrayList<>();
|
||||
for (final PlotArea area : PlotSquared.get().getPlotAreas()) {
|
||||
String areaName = area.getWorldName();
|
||||
if (area.getId() != null) {
|
||||
areaName += ";" + area.getId();
|
||||
}
|
||||
if (!areaName.toLowerCase().startsWith(input.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
completions.add(new Command(null, false, areaName, "",
|
||||
RequiredType.NONE, null) {});
|
||||
}
|
||||
return Collections.unmodifiableList(completions);
|
||||
}
|
||||
|
||||
@NotNull public List<Command> asCompletions(String... toFilter) {
|
||||
final List<Command> completions = new ArrayList<>();
|
||||
for (String completion : toFilter) {
|
||||
completions.add(new Command(null, false, completion, "",
|
||||
RequiredType.NONE, null) {});
|
||||
}
|
||||
return Collections.unmodifiableList(completions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cacheIdentifier Cache key
|
||||
* @param input Command input
|
||||
|
Reference in New Issue
Block a user