-
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
Merged
aramperes
merged 6 commits into
GlowstoneMC:master
from
FlorentClarret:499_banlist_commandline
Jul 5, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bd7e388
Ignore .DS_Store files generated by macOS
FlorentClarret 946cda8
Implement the banlist command
FlorentClarret 779d13e
Improve the banlist commandline
FlorentClarret 0dee0fd
Fix the tabComplete for the banlist command
FlorentClarret 7f87b60
Remove unused imports
FlorentClarret 7f9e386
Fix tabComplete in banlist when args length is equal to 1
FlorentClarret File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ dependency-reduced-pom.xml | |
.project | ||
.settings | ||
.db | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/net/glowstone/command/minecraft/BanListCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()]))); | ||
} | ||
|
||
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 args.length == 0 ? super.tabComplete(sender, alias, args) : Collections.emptyList(); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@Mystiflow That check is done here: https://github.com/GlowstoneMC/Glowstone/pull/518/files/946cda8cadfbdf72f3a29d6a4fae84f80276bb56..779d13ed59cef62cd218cdc6d6fed30cb814e40f#diff-d9df5a37e1afb33765f601eec8d00d0aL55
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.
Yup, the check is done
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.
Ah, whoops, completely skimmed over it