Fix various command issues

This commit is contained in:
Alexander Söderberg 2020-02-18 20:32:24 +01:00
parent 43e94de897
commit 7dcecde8ad
7 changed files with 54 additions and 29 deletions

View File

@ -247,7 +247,7 @@ import java.util.zip.ZipInputStream;
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
try {
if (this.IMP.initWorldEdit()) {
PlotSquared.log(Captions.PREFIX + "&6" + IMP.getPluginName()
PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + IMP.getPluginName()
+ " hooked into WorldEdit.");
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WESubscriber());

View File

@ -35,11 +35,22 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "flag", aliases = {"f",
"flag"}, usage = "/plot flag <set|remove|add|list|info> <flag> <value>", description = "Manage plot flags", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag")
@SuppressWarnings("unused") public final class FlagCommand extends SubCommand {
@SuppressWarnings("unused") public final class FlagCommand extends Command {
public FlagCommand() {
super(MainCommand.getInstance(), true);
}
private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) {
message.send(player, args);
return true;
}
private static boolean checkPermValue(@Nonnull final PlotPlayer player,
@NotNull final PlotFlag<?, ?> flag, @NotNull String key, @NotNull String value) {
@ -156,10 +167,17 @@ import java.util.Map;
return null;
}
@Override public boolean onCommand(final PlotPlayer player, final String[] args) {
@Override 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))) {
new HelpMenu(player).setCategory(CommandCategory.SETTINGS).setCommands(this.getCommands())
.generateMaxPages().generatePage(0, getParent().toString()).render();
return true;
return CompletableFuture.completedFuture(true);
}
return super.execute(player, args, confirm, whenDone);
}
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args,
@ -268,7 +286,7 @@ import java.util.Map;
String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
final ListFlag listFlag = (ListFlag) flag;
final List list =
plot.getFlag((Class<? extends ListFlag<?, ?>>) listFlag.getClass());
new ArrayList(plot.getFlag((Class<? extends ListFlag<?, ?>>) listFlag.getClass()));
final PlotFlag parsedFlag;
try {
parsedFlag = listFlag.parse(value);
@ -382,7 +400,8 @@ import java.util.Map;
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
// Flag example
new PlotMessage(Captions.FLAG_INFO_EXAMPLE.getTranslated())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(plotFlag.getExample())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text("/plot flag set " +
plotFlag.getName() + " " + plotFlag.getExample())
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated())
.suggest("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample())
.send(player);
@ -392,8 +411,8 @@ import java.util.Map;
new PlotMessage(Captions.FLAG_INFO_DEFAULT_VALUE.getTranslated())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(defaultValue)
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
// Footer
Captions.FLAG_INFO_FOOTER.send(player);
// Footer. Done this way to prevent the duplicate-message-thingy from catching it
MainUtil.sendMessage(player, "&r" + Captions.FLAG_INFO_FOOTER.getTranslated());
}
}

View File

@ -850,4 +850,8 @@ public enum Captions implements Caption {
return this.category;
}
@Override public String toString() {
return this.getTranslated();
}
}

View File

@ -52,7 +52,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Notif
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlaceFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlayerInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.WeatherFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PveFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PvpFlag;
@ -145,7 +145,7 @@ public final class GlobalFlagContainer extends FlagContainer {
this.addFlag(InvincibleFlag.INVINCIBLE_FALSE);
// Enum Flags
this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF);
this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF);
this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE);
this.addFlag(TitlesFlag.TITLES_NONE);

View File

@ -5,25 +5,25 @@ import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.util.PlotWeather;
import org.jetbrains.annotations.NotNull;
public class PlotWeatherFlag extends PlotFlag<PlotWeather, PlotWeatherFlag> {
public class WeatherFlag extends PlotFlag<PlotWeather, WeatherFlag> {
public static final PlotWeatherFlag PLOT_WEATHER_FLAG_RAIN =
new PlotWeatherFlag(PlotWeather.RAIN);
public static final PlotWeatherFlag PLOT_WEATHER_FLAG_CLEAR =
new PlotWeatherFlag(PlotWeather.CLEAR);
public static final PlotWeatherFlag PLOT_WEATHER_FLAG_OFF =
new PlotWeatherFlag(PlotWeather.RESET);
public static final WeatherFlag PLOT_WEATHER_FLAG_RAIN =
new WeatherFlag(PlotWeather.RAIN);
public static final WeatherFlag PLOT_WEATHER_FLAG_CLEAR =
new WeatherFlag(PlotWeather.CLEAR);
public static final WeatherFlag PLOT_WEATHER_FLAG_OFF =
new WeatherFlag(PlotWeather.RESET);
/**
* Construct a new flag instance.
*
* @param value Flag value
*/
protected PlotWeatherFlag(@NotNull PlotWeather value) {
protected WeatherFlag(@NotNull PlotWeather value) {
super(value, Captions.FLAG_CATEGORY_WEATHER, Captions.FLAG_DESCRIPTION_WEATHER);
}
@Override public PlotWeatherFlag parse(@NotNull String input) {
@Override public WeatherFlag parse(@NotNull String input) {
switch (input.toLowerCase()) {
case "rain":
case "storm":
@ -40,7 +40,7 @@ public class PlotWeatherFlag extends PlotFlag<PlotWeather, PlotWeatherFlag> {
}
}
@Override public PlotWeatherFlag merge(@NotNull PlotWeather newValue) {
@Override public WeatherFlag merge(@NotNull PlotWeather newValue) {
return flagOf(newValue);
}
@ -52,7 +52,7 @@ public class PlotWeatherFlag extends PlotFlag<PlotWeather, PlotWeatherFlag> {
return "storm";
}
@Override protected PlotWeatherFlag flagOf(@NotNull PlotWeather value) {
@Override protected WeatherFlag flagOf(@NotNull PlotWeather value) {
switch (value) {
case RAIN:
return PLOT_WEATHER_FLAG_RAIN;

View File

@ -11,7 +11,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Guest
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyEnterFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.WeatherFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TimeFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TitlesFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
@ -135,7 +135,7 @@ public class PlotListener {
}
}
player.setWeather(plot.getFlag(PlotWeatherFlag.class));
player.setWeather(plot.getFlag(WeatherFlag.class));
ItemType musicFlag = plot.getFlag(MusicFlag.class);
if (musicFlag != null) {
@ -267,9 +267,9 @@ public class PlotListener {
player.setTime(Long.MAX_VALUE);
}
final PlotWeather plotWeather = plot.getFlag(PlotWeatherFlag.class);
final PlotWeather plotWeather = plot.getFlag(WeatherFlag.class);
if (plotWeather != PlotWeather.RESET) {
player.setWeather(plotWeather);
player.setWeather(PlotWeather.RESET);
}
Location lastLoc = player.getMeta("music");

View File

@ -789,9 +789,11 @@ public class MainUtil {
} else {
String prefix = "";
for (final PlotFlag<?, ?> flag : flagCollection) {
Object value = flag.getValue();
Object value;
if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) {
value = FLAG_DECIMAL_FORMAT.format(value);
value = FLAG_DECIMAL_FORMAT.format(flag.getValue());
} else {
value = flag.toString();
}
flags.append(prefix).append(CaptionUtility.format(Captions.PLOT_FLAG_LIST.getTranslated(),
flag.getName(), value));