port over remaining flag commands

This commit is contained in:
Alexander Söderberg 2024-01-01 10:07:17 +01:00
parent 2ac2f6648e
commit b62a237dab
No known key found for this signature in database
18 changed files with 591 additions and 19 deletions

View File

@ -1,10 +1,26 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.bukkit.inject;
import cloud.commandframework.CloudCapability;
import cloud.commandframework.CommandManager;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.minecraft.extras.AudienceProvider;
import cloud.commandframework.execution.ExecutionCoordinator;
import cloud.commandframework.minecraft.extras.MinecraftExceptionHandler;
import cloud.commandframework.paper.PaperCommandManager;
import com.google.inject.AbstractModule;
@ -54,7 +70,7 @@ public class CloudModule extends AbstractModule {
try {
final PaperCommandManager<PlotPlayer<?>> commandManager = new PaperCommandManager<PlotPlayer<?>>(
this.bukkitPlatform,
AsynchronousCommandExecutionCoordinator.<PlotPlayer<?>>builder().withAsynchronousParsing().build(),
ExecutionCoordinator.asyncCoordinator(),
CloudModule::convert,
CloudModule::convert
);

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands;
import cloud.commandframework.context.CommandContext;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands;
import cloud.commandframework.context.CommandContext;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands;
import cloud.commandframework.captions.Caption;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands;
import cloud.commandframework.Command;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands;
import cloud.commandframework.CommandManager;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands;
import cloud.commandframework.keys.CloudKey;

View File

@ -0,0 +1,120 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.command.setting.flag;
import cloud.commandframework.Command;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.keys.CloudKey;
import com.google.inject.Inject;
import com.plotsquared.core.commands.parser.PlotFlagParser;
import com.plotsquared.core.commands.suggestions.FlagValueSuggestionProvider;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.util.EventDispatcher;
import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import static cloud.commandframework.arguments.standard.StringParser.greedyStringParser;
import static com.plotsquared.core.commands.parser.PlotFlagParser.plotFlagParser;
public final class FlagAddCommand extends FlagCommandBean {
private static final CloudKey<PlotFlag<?, ?>> COMPONENT_FLAG = CloudKey.of("flag", new TypeToken<PlotFlag<?, ?>>() {});
private static final CloudKey<String> COMPONENT_VALUE = CloudKey.of("value", String.class);
private final EventDispatcher eventDispatcher;
@Inject
public FlagAddCommand(final @NonNull EventDispatcher eventDispatcher) {
this.eventDispatcher = eventDispatcher;
}
@Override
protected Command.@NonNull Builder<PlotPlayer<?>> configurePlotCommand(
final Command.@NonNull Builder<PlotPlayer<?>> builder
) {
return builder.literal("add")
.required(COMPONENT_FLAG, plotFlagParser(PlotFlagParser.FlagSource.GLOBAL))
.required(COMPONENT_VALUE, greedyStringParser(), new FlagValueSuggestionProvider(COMPONENT_FLAG));
}
@Override
public void execute(final @NonNull CommandContext<PlotPlayer<?>> commandContext) {
final PlotPlayer<?> player = commandContext.sender();
final Plot plot = commandContext.inject(Plot.class).orElseThrow();
final PlotFlag<?, ?> flag = commandContext.get(COMPONENT_FLAG);
final String flagValue = commandContext.get(COMPONENT_VALUE);
final PlotFlagAddEvent event = this.eventDispatcher.callFlagAdd(flag, plot);
if (event.getEventResult() == Result.DENY) {
player.sendMessage(
TranslatableCaption.of("events.event_denied"),
TagResolver.resolver("value", Tag.inserting(Component.text("Flag set")))
);
return;
}
if (event.getEventResult() != Result.FORCE) {
final String[] split = flagValue.split(",");
for (final String entry : split) {
if (!checkPermValue(player, flag, flag.getName(), entry)) {
return;
}
}
}
final String sanitizedValue = CaptionUtility.stripClickEvents(flag, flagValue);
final PlotFlag<?, ?> parsedFlag;
try {
parsedFlag = flag.parse(flagValue);
} catch (final FlagParseException e) {
player.sendMessage(
TranslatableCaption.of("flag.flag_parse_error"),
TagResolver.builder()
.tag("flag_name", Tag.inserting(Component.text(flag.getName())))
.tag("flag_value", Tag.inserting(Component.text(e.getValue())))
.tag("error", Tag.inserting(e.getErrorMessage().toComponent(player)))
.build()
);
return;
}
final boolean result = plot.setFlag(plot.getFlagContainer().getFlag(flag.getClass()).merge(parsedFlag.getValue()));
if (!result) {
player.sendMessage(TranslatableCaption.of("flag.flag_not_added"));
return;
}
player.sendMessage(
TranslatableCaption.of("flag.flag_added"),
TagResolver.builder()
.tag("flag", Tag.inserting(Component.text(flag.getName())))
.tag("value", Tag.inserting(Component.text(parsedFlag.toString())))
.build()
);
}
}

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.command.setting.flag;
import cloud.commandframework.Command;

View File

@ -0,0 +1,88 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.command.setting.flag;
import cloud.commandframework.Command;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.keys.CloudKey;
import com.plotsquared.core.commands.parser.PlotFlagParser;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.flag.PlotFlag;
import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import static com.plotsquared.core.commands.parser.PlotFlagParser.plotFlagParser;
public final class FlagInfoCommand extends FlagCommandBean {
private static final CloudKey<PlotFlag<?, ?>> COMPONENT_FLAG = CloudKey.of("flag", new TypeToken<PlotFlag<?, ?>>() {});
@Override
protected Command.@NonNull Builder<PlotPlayer<?>> configurePlotCommand(final Command.@NonNull Builder<PlotPlayer<?>> builder) {
return builder.literal("info")
.required(COMPONENT_FLAG, plotFlagParser(PlotFlagParser.FlagSource.GLOBAL));
}
@Override
public void execute(final @NonNull CommandContext<PlotPlayer<?>> commandContext) {
final PlotFlag<?, ?> plotFlag = commandContext.get(COMPONENT_FLAG);
final PlotPlayer<?> player = commandContext.sender();
player.sendMessage(TranslatableCaption.of("flag.flag_info_header"));
// Flag name
player.sendMessage(
TranslatableCaption.of("flag.flag_info_name"),
TagResolver.resolver("flag", Tag.inserting(Component.text(plotFlag.getName())))
);
// Flag category
player.sendMessage(
TranslatableCaption.of("flag.flag_info_category"),
TagResolver.resolver(
"value",
Tag.inserting(plotFlag.getFlagCategory().toComponent(player))
)
);
// 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"),
TagResolver.builder()
.tag("command", Tag.preProcessParsed("/plot flag set"))
.tag("flag", Tag.preProcessParsed(plotFlag.getName()))
.tag("value", Tag.preProcessParsed(plotFlag.getExample()))
.build()
);
// Default value
final String defaultValue = player.getLocation().getPlotArea().getFlagContainer()
.getFlagErased(plotFlag.getClass()).toString();
player.sendMessage(
TranslatableCaption.of("flag.flag_info_default_value"),
TagResolver.resolver("value", Tag.inserting(Component.text(defaultValue)))
);
// Footer. Done this way to prevent the duplicate-message-thingy from catching it
player.sendMessage(TranslatableCaption.of("flag.flag_info_footer"));
}
}

View File

@ -0,0 +1,93 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.command.setting.flag;
import cloud.commandframework.Command;
import cloud.commandframework.context.CommandContext;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.InternalFlag;
import com.plotsquared.core.plot.flag.PlotFlag;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public final class FlagListCommand extends FlagCommandBean {
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
@Override
protected Command.@NonNull Builder<PlotPlayer<?>> configurePlotCommand(
final Command.@NonNull Builder<PlotPlayer<?>> builder
) {
return builder.literal("list");
}
@Override
public void execute(final @NonNull CommandContext<PlotPlayer<?>> commandContext) {
final PlotPlayer<?> player = commandContext.sender();
final Map<Component, ArrayList<String>> flags = new HashMap<>();
for (PlotFlag<?, ?> plotFlag : GlobalFlagContainer.getInstance().getRecognizedPlotFlags()) {
if (plotFlag instanceof InternalFlag) {
continue;
}
final Component category = plotFlag.getFlagCategory().toComponent(player);
final Collection<String> flagList = flags.computeIfAbsent(category, k -> new ArrayList<>());
flagList.add(plotFlag.getName());
}
for (final Map.Entry<Component, ArrayList<String>> entry : flags.entrySet()) {
Collections.sort(entry.getValue());
Component category =
MINI_MESSAGE.deserialize(
TranslatableCaption.of("flag.flag_list_categories").getComponent(player),
TagResolver.resolver("category", Tag.inserting(entry.getKey().style(Style.empty())))
);
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
.deserialize(
TranslatableCaption.of("flag.flag_list_flag").getComponent(player),
TagResolver.builder()
.tag("command", Tag.preProcessParsed("/plat flag info " + flag))
.tag("flag", Tag.inserting(Component.text(flag)))
.tag("suffix", Tag.inserting(Component.text(flagIterator.hasNext() ? ", " : "")))
.build()
));
}
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.build())));
}
}
}

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.command.setting.flag;
import cloud.commandframework.Command;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.command.setting.flag;
import cloud.commandframework.Command;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.injection;
import cloud.commandframework.annotations.AnnotationAccessor;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.parser;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
@ -20,7 +38,6 @@ import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.ComponentMessageThrowable;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.function.Function;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.processing;
import cloud.commandframework.execution.postprocessor.CommandPostprocessingContext;

View File

@ -1,3 +1,21 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.commands.suggestions;
import cloud.commandframework.arguments.suggestion.BlockingSuggestionProvider;
@ -9,10 +27,8 @@ import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.types.ListFlag;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
* Suggestion provider that provides context-aware {@link PlotFlag plot flag} value suggestions using
@ -43,21 +59,21 @@ public final class FlagValueSuggestionProvider implements BlockingSuggestionProv
final Collection<String> completions = plotFlag.getTabCompletions();
if (plotFlag instanceof ListFlag<?,?> && input.peekString().contains(",")) {
final String[] split = input.peekString().split(",");
final StringBuilder prefix = new StringBuilder();
for (int i = 0; i < split.length - i; i++) {
prefix.append(split[i]).append(",");
}
final List<String> existingValues = new ArrayList<>(Arrays.asList(split));
final String cmp;
final String completingValue;
if (!input.peekString().endsWith(",")) {
cmp = split[split.length - 1];
// In this case we want to complete the value we're currently typing.
completingValue = split[split.length - 1];
existingValues.remove(existingValues.size() - 1);
} else {
prefix.append(split[split.length - 1]).append(",");
cmp = "";
completingValue = null;
}
final String prefix = existingValues.stream().collect(Collectors.joining(",", "", ","));
return completions.stream()
.filter(value -> value.startsWith(cmp.toLowerCase(Locale.ENGLISH)))
.filter(value -> !existingValues.contains(value))
.filter(value -> completingValue == null || value.startsWith(completingValue))
.map(value -> prefix + value)
.toList();
}

View File

@ -1,9 +1,30 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.inject.modules;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.multibindings.Multibinder;
import com.plotsquared.core.commands.PlotSquaredCommandBean;
import com.plotsquared.core.commands.command.setting.flag.FlagAddCommand;
import com.plotsquared.core.commands.command.setting.flag.FlagInfoCommand;
import com.plotsquared.core.commands.command.setting.flag.FlagListCommand;
import com.plotsquared.core.commands.command.setting.flag.FlagRemoveCommand;
import com.plotsquared.core.commands.command.setting.flag.FlagSetCommand;
@ -16,7 +37,10 @@ public final class CommandModule extends AbstractModule {
PlotSquaredCommandBean.class
);
commands.addBinding().to(FlagSetCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(FlagAddCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(FlagInfoCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(FlagListCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(FlagRemoveCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(FlagSetCommand.class).in(Scopes.SINGLETON);
}
}