Skip to content
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
merged 6 commits into from
Jul 5, 2017
Merged

#499 - Adds banlist command #518

merged 6 commits into from
Jul 5, 2017

Conversation

FlorentClarret
Copy link
Member

Hi,

This PR relates to this issues : #499. It doesn't close it, but contributes to :)

It reimplements the vanilla banlist command line.

@CLAassistant
Copy link

CLAassistant commented Jul 5, 2017

CLA assistant check
All committers have signed the CLA.

@gdude2002 gdude2002 requested a review from aramperes July 5, 2017 06:52
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], BAN_TYPES, new ArrayList(BAN_TYPES_SIZE));
}
return super.tabComplete(sender, alias, args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should return Collections.emptyList() if args.length is over 1 (this will remove player auto-completion, which is not necessary here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point.

int index = 0, size = banEntries.size();
final StringBuilder banList = new StringBuilder(200);

for (final BanEntry banEntry : banEntries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Didn't see that one. Thanks

banType = BanList.Type.NAME;
break;
default:
sender.sendMessage(ChatColor.RED + "Invalid parameter '" + parameter + "'. Usage : " + usageMessage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space before : ("Usage : ")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

French guy here, don't blame me.


private static final int BAN_TYPES_SIZE;

static {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for a static initialization block here? I think you could just to:

private static final List<String> BAN_TYPES = Arrays.asList("ips", "players");

No need to store BAN_TYPES_SIZE in a variable, just use BAN_TYPES.size() when needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, no need to store it in this case.

sender.sendMessage("There are no banned players");
} else {
int index = 0, size = banEntries.size();
final StringBuilder banList = new StringBuilder(200);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a need for an initial capacity value here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. No need in this case.

++index;
}

sender.sendMessage("There are " + size + " banned players : ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space before : (" banned players : ")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

French guy here again, don't blame me.


if (args.length > 0) {
final String parameter = args[0];
switch (parameter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this non case-sensitive?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem

default:
sender.sendMessage(ChatColor.RED + "Invalid parameter '" + parameter + "'. Usage : " + usageMessage);
return false;
if ("ips".equalsIgnoreCase(args[0])) {
Copy link
Member

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.

Copy link
Member Author

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

} 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()])));
Copy link
Contributor

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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

Copy link
Contributor

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

if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], BAN_TYPES, new ArrayList(BAN_TYPES.size()));
} else {
return Collections.emptyList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should still return super.[...] if args.length == 0 (sorry if I wasn't clear in my previous review). For example: return args.length == 0 ? super.[...] : Collections.emptyList();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. I updated it too quickly

@@ -55,10 +55,6 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
if (args.length == 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No... you still need that check :)

if (args.length == 1) {
    return StringUtil.copyPartialMatches(args[0], BAN_TYPES, new ArrayList(BAN_TYPES.size()));
}
return args.length == 0 ? super.tabComplete(sender, alias, args) : Collections.emptyList();

@aramperes aramperes merged commit 771eb2a into GlowstoneMC:master Jul 5, 2017
@aramperes
Copy link
Member

Thank you for your contribution! :)

@aramperes aramperes mentioned this pull request Jul 8, 2017
53 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants