Add tab completion to like/dislike and fix more messages

This commit is contained in:
N0tMyFaultOG 2020-12-07 12:51:14 +01:00
parent 60859de0bd
commit a4dd5bb62f
No known key found for this signature in database
GPG Key ID: 823348042DA95A81
3 changed files with 50 additions and 3 deletions

View File

@ -26,9 +26,17 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@CommandDeclaration(command = "dislike", @CommandDeclaration(command = "dislike",
permission = "plots.dislike", permission = "plots.dislike",
@ -47,4 +55,22 @@ public class Dislike extends SubCommand {
return this.like.handleLike(player, args, false); return this.like.handleLike(player, args, false);
} }
@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_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());
}
} }

View File

@ -38,15 +38,19 @@ import com.plotsquared.core.plot.Rating;
import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.Permissions; 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.PlotQuery;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@CommandDeclaration(command = "like", @CommandDeclaration(command = "like",
permission = "plots.like", permission = "plots.like",
@ -126,7 +130,7 @@ public class Like extends SubCommand {
if (oldRating != null) { if (oldRating != null) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("ratings.rating_already_exists"), TranslatableCaption.of("ratings.rating_already_exists"),
Template.of("value", plot.getId().toString()) Template.of("plot", plot.getId().toString())
); );
return; return;
} }
@ -199,4 +203,22 @@ public class Like extends SubCommand {
return handleLike(player, args, true); return handleLike(player, args, 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_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());
}
} }

View File

@ -48,7 +48,6 @@ import com.plotsquared.core.util.task.TaskManager;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -236,7 +235,7 @@ public class Rate extends SubCommand {
if (plot.getRatings().containsKey(uuid)) { if (plot.getRatings().containsKey(uuid)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("ratings.rating_already_exists"), TranslatableCaption.of("ratings.rating_already_exists"),
Template.of("value", plot.getId().toString()) Template.of("plot", plot.getId().toString())
); );
return; return;
} }