-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#499 - Adds banlist command #518
Changes from 3 commits
bd7e388
946cda8
779d13e
0dee0fd
7f87b60
7f9e386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ dependency-reduced-pom.xml | |
.project | ||
.settings | ||
.db | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.glowstone.command.minecraft; | ||
|
||
import net.glowstone.command.CommandUtils; | ||
import org.bukkit.BanEntry; | ||
import org.bukkit.BanList; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.defaults.VanillaCommand; | ||
import org.bukkit.util.StringUtil; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class BanListCommand extends VanillaCommand { | ||
|
||
private static final List<String> BAN_TYPES = Arrays.asList("ips", "players"); | ||
|
||
public BanListCommand() { | ||
super("banlist", "Displays the server's blacklist.", "/banlist [ips|players]", Collections.emptyList()); | ||
setPermission("minecraft.command.ban.list"); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String commandLabel, String[] args) { | ||
if (!testPermission(sender)) return false; | ||
|
||
BanList.Type banType; | ||
|
||
if (args.length > 0) { | ||
if ("ips".equalsIgnoreCase(args[0])) { | ||
banType = BanList.Type.IP; | ||
} else if ("players".equalsIgnoreCase(args[0])) { | ||
banType = BanList.Type.NAME; | ||
} else { | ||
sender.sendMessage(ChatColor.RED + "Invalid parameter '" + args[0] + "'. Usage: " + usageMessage); | ||
return false; | ||
} | ||
} else { | ||
banType = BanList.Type.NAME; | ||
} | ||
|
||
final Set<BanEntry> banEntries = Bukkit.getBanList(banType).getBanEntries(); | ||
|
||
if (banEntries.isEmpty()) { | ||
sender.sendMessage("There are no banned players"); | ||
} else { | ||
final List<String> targets = banEntries.stream().map(BanEntry::getTarget).collect(Collectors.toList()); | ||
sender.sendMessage("There are " + banEntries.size() + " banned players: "); | ||
sender.sendMessage(CommandUtils.prettyPrint(targets.toArray(new String[targets.size()]))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps check if there are no banned players here so an empty message isn't sent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, the check is done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, whoops, completely skimmed over it |
||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { | ||
if (args.length == 1) { | ||
return StringUtil.copyPartialMatches(args[0], BAN_TYPES, new ArrayList(BAN_TYPES.size())); | ||
} else { | ||
return Collections.emptyList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should still return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad. I updated it too quickly |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A switch can still be used. Just make the first argument lowercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, less modifications would have been performed