From b37fdd361901eb095f21c492aaaa341511141326 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 30 Aug 2016 13:23:48 +0100 Subject: [PATCH] Add user to group instead of failing in setprimarygroup command --- .../commands/user/subcommands/UserSetPrimaryGroup.java | 7 +++++-- .../main/java/me/lucko/luckperms/constants/Message.java | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java index a154a6b42..fafe2acc2 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java @@ -30,6 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.data.LogEntry; +import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; @@ -55,8 +56,10 @@ public class UserSetPrimaryGroup extends SubCommand { } if (!user.isInGroup(group)) { - Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, label); - return CommandResult.STATE_ERROR; + Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getName(), group.getName()); + try { + user.addGroup(group); + } catch (ObjectAlreadyHasException ignored) {} } user.setPrimaryGroup(group.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/constants/Message.java b/common/src/main/java/me/lucko/luckperms/constants/Message.java index 64e865aad..0eba3f02e 100644 --- a/common/src/main/java/me/lucko/luckperms/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/constants/Message.java @@ -235,7 +235,7 @@ public enum Message { USER_REMOVEGROUP_ERROR_PRIMARY("You cannot remove a user from their primary group.", true), USER_PRIMARYGROUP_SUCCESS("&b%s&a's primary group was set to &b%s&a.", true), USER_PRIMARYGROUP_ERROR_ALREADYHAS("The user already has this group set as their primary group.", true), - USER_PRIMARYGROUP_ERROR_NOTMEMBER("The user must be a member of the group first! Use &4/%s user addgroup ", true), + USER_PRIMARYGROUP_ERROR_NOTMEMBER("&b%s&a was not already a member of &b%s&a, adding them now.", true), USER_SHOWTRACKS_INFO("&aShowing tracks that contain the group '&b%s&a' (%s's primary group)", true), USER_PROMOTE_SUCCESS_PROMOTE("&aPromoting user along track &b%s&a from &b%s&a to &b%s&a.", true), USER_PROMOTE_SUCCESS_REMOVE("&b%s&a was removed from &b%s&a, added to &b%s&a, and their primary group was set to &b%s&a.", true),