Fix TabComplete suggesting online player names instead of nothing

This commit is contained in:
Christian Koop 2021-07-12 16:13:45 +02:00
parent a53dab9e18
commit 55cf082a57
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
5 changed files with 57 additions and 27 deletions

View File

@ -5,13 +5,11 @@ import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.voucher.Voucher; import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class CommandForce extends AbstractCommand { public class CommandForce extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
@ -49,14 +47,23 @@ public class CommandForce extends AbstractCommand {
@Override @Override
protected List<String> onTab(CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
List<String> result = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList()); for (Player online : Bukkit.getOnlinePlayers()) {
result.add(online.getName());
}
} else if (args.length == 2) { } else if (args.length == 2) {
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList()); for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey());
}
} else if (args.length == 3) { } else if (args.length == 3) {
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); for (int i = 0; i < 10; ++i) {
result.add(String.valueOf(i + 1));
}
} }
return null;
return result;
} }
@Override @Override

View File

@ -7,9 +7,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class CommandForceAll extends AbstractCommand { public class CommandForceAll extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
@ -41,12 +39,19 @@ public class CommandForceAll extends AbstractCommand {
@Override @Override
protected List<String> onTab(CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
List<String> result = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList()); for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey());
}
} else if (args.length == 2) { } else if (args.length == 2) {
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); for (int i = 0; i < 10; ++i) {
result.add(String.valueOf(i + 1));
}
} }
return null;
return result;
} }
@Override @Override

View File

@ -5,13 +5,11 @@ import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.voucher.Voucher; import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class CommandGive extends AbstractCommand { public class CommandGive extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
@ -44,14 +42,23 @@ public class CommandGive extends AbstractCommand {
@Override @Override
protected List<String> onTab(CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
List<String> result = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList()); for (Player online : Bukkit.getOnlinePlayers()) {
result.add(online.getName());
}
} else if (args.length == 2) { } else if (args.length == 2) {
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList()); for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey());
}
} else if (args.length == 3) { } else if (args.length == 3) {
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); for (int i = 0; i < 10; ++i) {
result.add(String.valueOf(i + 1));
}
} }
return null;
return result;
} }
@Override @Override

View File

@ -5,9 +5,8 @@ import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.voucher.Voucher; import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.Arrays; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class CommandGiveAll extends AbstractCommand { public class CommandGiveAll extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
@ -34,12 +33,19 @@ public class CommandGiveAll extends AbstractCommand {
@Override @Override
protected List<String> onTab(CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
List<String> result = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList()); for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey());
}
} else if (args.length == 2) { } else if (args.length == 2) {
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); for (int i = 0; i < 10; ++i) {
result.add(String.valueOf(i + 1));
}
} }
return null;
return result;
} }
@Override @Override

View File

@ -6,7 +6,7 @@ import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.StringJoiner;
public class CommandList extends AbstractCommand { public class CommandList extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
@ -18,10 +18,15 @@ public class CommandList extends AbstractCommand {
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
StringJoiner joiner = new StringJoiner(", ");
for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
joiner.add(voucher.getKey());
}
instance.getLocale().getMessage("command.list.list") instance.getLocale().getMessage("command.list.list")
.processPlaceholder("list", .processPlaceholder("list", joiner.toString())
instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.joining(", ")))
.sendPrefixedMessage(sender); .sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }