Add temporary permissions
This commit is contained in:
parent
24ff465679
commit
cdf8a4ce18
@ -1,8 +1,10 @@
|
|||||||
= LuckPerms
|
= LuckPerms
|
||||||
A (fairly bad) permissions implementation for Bukkit/BungeeCord.
|
A (fairly bad) permissions implementation for Bukkit/BungeeCord.
|
||||||
|
|
||||||
=== Features
|
== Features
|
||||||
* **Group inheritance** - users can be members of multiple groups, groups can inherit other groups
|
* **Group inheritance** - users can be members of multiple groups, groups can inherit other groups
|
||||||
|
* **Temporary permissions** - users/groups can be given permissions that expire after a given time
|
||||||
|
* **Temporary groups** - users/groups can be added to/inherit other groups temporarily
|
||||||
* **Multi-server support** - data is synced across all servers/platforms
|
* **Multi-server support** - data is synced across all servers/platforms
|
||||||
* **Per-server permissions/groups** - define user/group permissions that only apply on certain servers
|
* **Per-server permissions/groups** - define user/group permissions that only apply on certain servers
|
||||||
* **Server-specific groups** - define groups that only apply on certain servers
|
* **Server-specific groups** - define groups that only apply on certain servers
|
||||||
@ -17,16 +19,37 @@ A (fairly bad) permissions implementation for Bukkit/BungeeCord.
|
|||||||
* Currently only supports MySQL, SQLite & Flatfile (JSON) (support for more methods might come in the future)
|
* Currently only supports MySQL, SQLite & Flatfile (JSON) (support for more methods might come in the future)
|
||||||
* Not at all tested and could produce unexpected/buggy results and errors
|
* Not at all tested and could produce unexpected/buggy results and errors
|
||||||
|
|
||||||
=== Setup
|
== Setup
|
||||||
All configuration options are in the **config.yml** file, which is generated automagically when the plugin first starts.
|
All configuration options are in the **config.yml** file, which is generated automagically when the plugin first starts.
|
||||||
|
|
||||||
You can define the settings for per-server permissions, the storage method and credentials within this file.
|
You can define the settings for per-server permissions, the storage method and credentials within this file.
|
||||||
|
|
||||||
=== Commands
|
== Info
|
||||||
|
=== Permission Calculation
|
||||||
|
Permissions are calculated based on a priority system as follows.
|
||||||
|
|
||||||
|
* Temporary permissions will override non-temporary permissions.
|
||||||
|
|
||||||
|
Example: if a user has a false permission set for "test.node", and a temporary true permission set for "test.node", the temporary permission will override the permanent one, and the user will be granted the true node.
|
||||||
|
|
||||||
|
* Server specific permissions will override generic/global permissions.
|
||||||
|
|
||||||
|
Example: if a user has a global "fly.use" permission, and then has a negated "fly.use" permission on the "factions" server, the server specific permission will override the globally defined one, and the user will be granted the negated node.
|
||||||
|
|
||||||
|
* Inherited permissions will be overridden by an objects own permissions.
|
||||||
|
|
||||||
|
Example: A user is a member of the default group, which grants "some.thing.perm", but the users own permissions has "some.thing.perm" set to false. The inherited permission will be overridden by the users own permissions, and the user will be granted the negative node.
|
||||||
|
|
||||||
|
=== Temporary Permissions
|
||||||
|
Temporary permissions are checked each time a user/group is loaded, and when the sync task runs. This means if you set a temporary permission to expire after 30 seconds, it won't actually be removed until the sync task runs.
|
||||||
|
|
||||||
|
The only way around this is to decrease the sync interval.
|
||||||
|
|
||||||
|
== Commands
|
||||||
|
|
||||||
Command usage is printed to the console/chat whenever invalid arguments are provided. Simply typing /perms will list all commands a user has permission to use.
|
Command usage is printed to the console/chat whenever invalid arguments are provided. Simply typing /perms will list all commands a user has permission to use.
|
||||||
|
|
||||||
==== Aliases
|
=== Aliases
|
||||||
| Bukkit | /luckperms |
|
| Bukkit | /luckperms |
|
||||||
| | /perms |
|
| | /perms |
|
||||||
| | /permissions |
|
| | /permissions |
|
||||||
@ -78,6 +101,10 @@ Additionally, you can use wildcards to grant users access to a selection of comm
|
|||||||
| /perms user <user> unset <node> [server] | Unsets a permission for the user | luckperms.user.unsetpermission |
|
| /perms user <user> unset <node> [server] | Unsets a permission for the user | luckperms.user.unsetpermission |
|
||||||
| /perms user <user> addgroup <group> [server] | Adds the user to a group | luckperms.user.addgroup |
|
| /perms user <user> addgroup <group> [server] | Adds the user to a group | luckperms.user.addgroup |
|
||||||
| /perms user <user> removegroup <group> [server] | Removes the user from a group | luckperms.user.removegroup |
|
| /perms user <user> removegroup <group> [server] | Removes the user from a group | luckperms.user.removegroup |
|
||||||
|
| /perms user <user> settemp <node> <true/false> <duration> [server]| Sets a temporary permission for the user | luckperms.user.settemppermission |
|
||||||
|
| /perms user <user> unsettemp <node> [server] | Unsets a temporary permission for the user | luckperms.user.unsettemppermission |
|
||||||
|
| /perms user <user> addtempgroup <group> <duration> [server] | Adds the user to a group temporarily | luckperms.user.addtempgroup |
|
||||||
|
| /perms user <user> removetempgroup <group> [server] | Removes the user from a temporary group | luckperms.user.removetempgroup |
|
||||||
| /perms user <user> setprimarygroup <group> | Sets the users primary group | luckperms.user.setprimarygroup |
|
| /perms user <user> setprimarygroup <group> | Sets the users primary group | luckperms.user.setprimarygroup |
|
||||||
| /perms user <user> showtracks | Shows a list of the tracks the user can be promoted/demoted on | luckperms.user.showtracks |
|
| /perms user <user> showtracks | Shows a list of the tracks the user can be promoted/demoted on | luckperms.user.showtracks |
|
||||||
| /perms user <user> promote <track> | Promotes the user along a given track | luckperms.user.promote |
|
| /perms user <user> promote <track> | Promotes the user along a given track | luckperms.user.promote |
|
||||||
@ -94,7 +121,11 @@ Additionally, you can use wildcards to grant users access to a selection of comm
|
|||||||
| /perms group <group> set <node> <true/false> [server]| Sets a permission for the group | luckperms.group.setpermission |
|
| /perms group <group> set <node> <true/false> [server]| Sets a permission for the group | luckperms.group.setpermission |
|
||||||
| /perms group <group> unset <node> [server] | Unsets a permission for the group | luckperms.group.unsetpermission |
|
| /perms group <group> unset <node> [server] | Unsets a permission for the group | luckperms.group.unsetpermission |
|
||||||
| /perms group <group> setinherit <group> [server]| Sets the group to inherit all permissions from another group | luckperms.group.setinherit |
|
| /perms group <group> setinherit <group> [server]| Sets the group to inherit all permissions from another group | luckperms.group.setinherit |
|
||||||
| /perms group <group> unsetinherit <group> [server] | Unsets a perviously defined inheritance rule | luckperms.group.unsetinherit |
|
| /perms group <group> unsetinherit <group> [server] | Unsets a previously defined inheritance rule | luckperms.group.unsetinherit |
|
||||||
|
| /perms group <group> settemp <node> <true/false> <duration> [server] | Sets a temporary permission for the group | luckperms.group.settemppermission |
|
||||||
|
| /perms group <group> unsettemp <node> [server] | Unsets a temporary permission for the group | luckperms.group.unsettemppermission |
|
||||||
|
| /perms group <group> settempinherit <group> <duration> [server] | Sets the group to inherit all permissions from another group temporarily | luckperms.group.settempinherit |
|
||||||
|
| /perms group <group> unsettempinherit <group> [server] | Unsets a previously defined temporary inheritance rule | luckperms.group.unsettempinherit |
|
||||||
| /perms group <group> showtracks | Shows a list of the tracks that the users in the group can be promoted/demoted on | luckperms.group.showtracks |
|
| /perms group <group> showtracks | Shows a list of the tracks that the users in the group can be promoted/demoted on | luckperms.group.showtracks |
|
||||||
| /perms group <group> clear | Clears all permissions the group has | luckperms.group.clear |
|
| /perms group <group> clear | Clears all permissions the group has | luckperms.group.clear |
|
||||||
| | | |
|
| | | |
|
||||||
@ -107,5 +138,5 @@ Additionally, you can use wildcards to grant users access to a selection of comm
|
|||||||
| /perms track <track> clear | Clears all groups on the track | luckperms.track.clear |
|
| /perms track <track> clear | Clears all groups on the track | luckperms.track.clear |
|
||||||
|
|
||||||
|
|
||||||
=== License
|
== License
|
||||||
See LICENSE.md.
|
See LICENSE.md.
|
@ -2,17 +2,17 @@ package me.lucko.luckperms.commands;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.lucko.luckperms.LuckPermsPlugin;
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.commands.group.CreateGroupCommand;
|
import me.lucko.luckperms.commands.group.CreateGroup;
|
||||||
import me.lucko.luckperms.commands.group.DeleteGroupCommand;
|
import me.lucko.luckperms.commands.group.DeleteGroup;
|
||||||
import me.lucko.luckperms.commands.group.GroupMainCommand;
|
import me.lucko.luckperms.commands.group.GroupMainCommand;
|
||||||
import me.lucko.luckperms.commands.group.ListGroupsCommand;
|
import me.lucko.luckperms.commands.group.ListGroups;
|
||||||
import me.lucko.luckperms.commands.group.subcommands.*;
|
import me.lucko.luckperms.commands.group.subcommands.*;
|
||||||
import me.lucko.luckperms.commands.misc.DebugCommand;
|
import me.lucko.luckperms.commands.misc.DebugCommand;
|
||||||
import me.lucko.luckperms.commands.misc.InfoCommand;
|
import me.lucko.luckperms.commands.misc.InfoCommand;
|
||||||
import me.lucko.luckperms.commands.misc.SyncCommand;
|
import me.lucko.luckperms.commands.misc.SyncCommand;
|
||||||
import me.lucko.luckperms.commands.track.CreateTrackCommand;
|
import me.lucko.luckperms.commands.track.CreateTrack;
|
||||||
import me.lucko.luckperms.commands.track.DeleteTrackCommand;
|
import me.lucko.luckperms.commands.track.DeleteTrack;
|
||||||
import me.lucko.luckperms.commands.track.ListTracksCommand;
|
import me.lucko.luckperms.commands.track.ListTracks;
|
||||||
import me.lucko.luckperms.commands.track.TrackMainCommand;
|
import me.lucko.luckperms.commands.track.TrackMainCommand;
|
||||||
import me.lucko.luckperms.commands.track.subcommands.*;
|
import me.lucko.luckperms.commands.track.subcommands.*;
|
||||||
import me.lucko.luckperms.commands.user.UserMainCommand;
|
import me.lucko.luckperms.commands.user.UserMainCommand;
|
||||||
@ -37,52 +37,60 @@ public class CommandManager {
|
|||||||
|
|
||||||
UserMainCommand userCommand = new UserMainCommand();
|
UserMainCommand userCommand = new UserMainCommand();
|
||||||
this.registerMainCommand(userCommand);
|
this.registerMainCommand(userCommand);
|
||||||
userCommand.registerSubCommand(new UserAddGroupCommand());
|
userCommand.registerSubCommand(new UserInfo());
|
||||||
userCommand.registerSubCommand(new UserClearCommand());
|
userCommand.registerSubCommand(new UserGetUUID());
|
||||||
userCommand.registerSubCommand(new UserDemoteCommand());
|
userCommand.registerSubCommand(new UserListNodes());
|
||||||
userCommand.registerSubCommand(new UserGetUUIDCommand());
|
userCommand.registerSubCommand(new UserHasPerm());
|
||||||
userCommand.registerSubCommand(new UserHasPermCommand());
|
userCommand.registerSubCommand(new UserInheritsPerm());
|
||||||
userCommand.registerSubCommand(new UserInfoCommand());
|
userCommand.registerSubCommand(new UserSetPermission());
|
||||||
userCommand.registerSubCommand(new UserInheritsPermCommand());
|
userCommand.registerSubCommand(new UserUnSetPermission());
|
||||||
userCommand.registerSubCommand(new UserListNodesCommand());
|
userCommand.registerSubCommand(new UserAddGroup());
|
||||||
userCommand.registerSubCommand(new UserPromoteCommand());
|
userCommand.registerSubCommand(new UserRemoveGroup());
|
||||||
userCommand.registerSubCommand(new UserRemoveGroupCommand());
|
userCommand.registerSubCommand(new UserSetTempPermission());
|
||||||
userCommand.registerSubCommand(new UserSetPermissionCommand());
|
userCommand.registerSubCommand(new UserUnsetTempPermission());
|
||||||
userCommand.registerSubCommand(new UserSetPrimaryGroupCommand());
|
userCommand.registerSubCommand(new UserAddTempGroup());
|
||||||
userCommand.registerSubCommand(new UserShowPosCommand());
|
userCommand.registerSubCommand(new UserRemoveTempGroup());
|
||||||
userCommand.registerSubCommand(new UserShowTracksCommand());
|
userCommand.registerSubCommand(new UserSetPrimaryGroup());
|
||||||
userCommand.registerSubCommand(new UserUnSetPermissionCommand());
|
userCommand.registerSubCommand(new UserShowTracks());
|
||||||
|
userCommand.registerSubCommand(new UserPromote());
|
||||||
|
userCommand.registerSubCommand(new UserDemote());
|
||||||
|
userCommand.registerSubCommand(new UserShowPos());
|
||||||
|
userCommand.registerSubCommand(new UserClear());
|
||||||
|
|
||||||
GroupMainCommand groupCommand = new GroupMainCommand();
|
GroupMainCommand groupCommand = new GroupMainCommand();
|
||||||
this.registerMainCommand(groupCommand);
|
this.registerMainCommand(groupCommand);
|
||||||
groupCommand.registerSubCommand(new GroupClearCommand());
|
groupCommand.registerSubCommand(new GroupInfo());
|
||||||
groupCommand.registerSubCommand(new GroupHasPermCommand());
|
groupCommand.registerSubCommand(new GroupListNodes());
|
||||||
groupCommand.registerSubCommand(new GroupInfoCommand());
|
groupCommand.registerSubCommand(new GroupHasPerm());
|
||||||
groupCommand.registerSubCommand(new GroupInheritsPermCommand());
|
groupCommand.registerSubCommand(new GroupInheritsPerm());
|
||||||
groupCommand.registerSubCommand(new GroupListNodesCommand());
|
groupCommand.registerSubCommand(new GroupSetPermission());
|
||||||
groupCommand.registerSubCommand(new GroupSetInheritCommand());
|
groupCommand.registerSubCommand(new GroupUnSetPermission());
|
||||||
groupCommand.registerSubCommand(new GroupSetPermissionCommand());
|
groupCommand.registerSubCommand(new GroupSetInherit());
|
||||||
groupCommand.registerSubCommand(new GroupShowTracksCommand());
|
groupCommand.registerSubCommand(new GroupUnsetInherit());
|
||||||
groupCommand.registerSubCommand(new GroupUnsetInheritCommand());
|
groupCommand.registerSubCommand(new GroupSetTempPermission());
|
||||||
groupCommand.registerSubCommand(new GroupUnSetPermissionCommand());
|
groupCommand.registerSubCommand(new GroupUnsetTempPermission());
|
||||||
|
groupCommand.registerSubCommand(new GroupSetTempInherit());
|
||||||
|
groupCommand.registerSubCommand(new GroupUnsetTempInherit());
|
||||||
|
groupCommand.registerSubCommand(new GroupShowTracks());
|
||||||
|
groupCommand.registerSubCommand(new GroupClear());
|
||||||
|
|
||||||
TrackMainCommand trackCommand = new TrackMainCommand();
|
TrackMainCommand trackCommand = new TrackMainCommand();
|
||||||
this.registerMainCommand(trackCommand);
|
this.registerMainCommand(trackCommand);
|
||||||
trackCommand.registerSubCommand(new TrackAppendCommand());
|
trackCommand.registerSubCommand(new TrackInfo());
|
||||||
trackCommand.registerSubCommand(new TrackClearCommand());
|
trackCommand.registerSubCommand(new TrackAppend());
|
||||||
trackCommand.registerSubCommand(new TrackInfoCommand());
|
trackCommand.registerSubCommand(new TrackInsert());
|
||||||
trackCommand.registerSubCommand(new TrackInsertCommand());
|
trackCommand.registerSubCommand(new TrackRemove());
|
||||||
trackCommand.registerSubCommand(new TrackRemoveCommand());
|
trackCommand.registerSubCommand(new TrackClear());
|
||||||
|
|
||||||
this.registerMainCommand(new CreateGroupCommand());
|
|
||||||
this.registerMainCommand(new DeleteGroupCommand());
|
|
||||||
this.registerMainCommand(new ListGroupsCommand());
|
|
||||||
this.registerMainCommand(new CreateTrackCommand());
|
|
||||||
this.registerMainCommand(new DeleteTrackCommand());
|
|
||||||
this.registerMainCommand(new ListTracksCommand());
|
|
||||||
this.registerMainCommand(new DebugCommand());
|
|
||||||
this.registerMainCommand(new InfoCommand());
|
|
||||||
this.registerMainCommand(new SyncCommand());
|
this.registerMainCommand(new SyncCommand());
|
||||||
|
this.registerMainCommand(new InfoCommand());
|
||||||
|
this.registerMainCommand(new DebugCommand());
|
||||||
|
this.registerMainCommand(new CreateGroup());
|
||||||
|
this.registerMainCommand(new DeleteGroup());
|
||||||
|
this.registerMainCommand(new ListGroups());
|
||||||
|
this.registerMainCommand(new CreateTrack());
|
||||||
|
this.registerMainCommand(new DeleteTrack());
|
||||||
|
this.registerMainCommand(new ListTracks());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.lucko.luckperms.commands;
|
package me.lucko.luckperms.commands;
|
||||||
|
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.utils.DateUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -86,7 +87,7 @@ public class Util {
|
|||||||
return sb.delete(sb.length() - 6, sb.length()).toString();
|
return sb.delete(sb.length() - 6, sb.length()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String nodesToString(Map<String, Boolean> nodes) {
|
public static String permNodesToString(Map<String, Boolean> nodes) {
|
||||||
if (nodes.isEmpty()) return "&6None";
|
if (nodes.isEmpty()) return "&6None";
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@ -102,6 +103,24 @@ public class Util {
|
|||||||
return sb.delete(sb.length() - 2, sb.length()).toString();
|
return sb.delete(sb.length() - 2, sb.length()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String tempNodesToString(Map<Map.Entry<String, Boolean>, Long> nodes) {
|
||||||
|
if (nodes.isEmpty()) return "&6None";
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for (Map.Entry<Map.Entry<String, Boolean>, Long> e : nodes.entrySet()) {
|
||||||
|
if (e.getKey().getValue()) {
|
||||||
|
sb.append("&a").append(e.getKey().getKey()).append("&6 - expires in ")
|
||||||
|
.append(DateUtil.formatDateDiff(e.getValue())).append("\n");
|
||||||
|
} else {
|
||||||
|
sb.append("&c").append(e.getKey().getKey()).append("&6 - expires in ")
|
||||||
|
.append(DateUtil.formatDateDiff(e.getValue())).append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static UUID parseUuid(String s) {
|
public static UUID parseUuid(String s) {
|
||||||
try {
|
try {
|
||||||
return UUID.fromString(s);
|
return UUID.fromString(s);
|
||||||
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.utils.Patterns;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CreateGroupCommand extends MainCommand {
|
public class CreateGroup extends MainCommand {
|
||||||
public CreateGroupCommand() {
|
public CreateGroup() {
|
||||||
super("CreateGroup", "/%s creategroup <group>", 1);
|
super("CreateGroup", "/%s creategroup <group>", 1);
|
||||||
}
|
}
|
||||||
|
|
@ -13,8 +13,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DeleteGroupCommand extends MainCommand {
|
public class DeleteGroup extends MainCommand {
|
||||||
public DeleteGroupCommand() {
|
public DeleteGroup() {
|
||||||
super("DeleteGroup", "/%s deletegroup <group>", 1);
|
super("DeleteGroup", "/%s deletegroup <group>", 1);
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ListGroupsCommand extends MainCommand {
|
public class ListGroups extends MainCommand {
|
||||||
public ListGroupsCommand() {
|
public ListGroups() {
|
||||||
super("ListGroups", "/%s listgroups", 0);
|
super("ListGroups", "/%s listgroups", 0);
|
||||||
}
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupClearCommand extends GroupSubCommand {
|
public class GroupClear extends GroupSubCommand {
|
||||||
public GroupClearCommand() {
|
public GroupClear() {
|
||||||
super("clear", "Clears a groups permissions", "/%s group <group> clear", Permission.GROUP_CLEAR);
|
super("clear", "Clears a groups permissions", "/%s group <group> clear", Permission.GROUP_CLEAR);
|
||||||
}
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupHasPermCommand extends GroupSubCommand {
|
public class GroupHasPerm extends GroupSubCommand {
|
||||||
public GroupHasPermCommand() {
|
public GroupHasPerm() {
|
||||||
super("haspermission", "Checks to see if a group has a certain permission node",
|
super("haspermission", "Checks to see if a group has a certain permission node",
|
||||||
"/%s group <group> haspermission <node> [server]", Permission.GROUP_HASPERMISSION);
|
"/%s group <group> haspermission <node> [server]", Permission.GROUP_HASPERMISSION);
|
||||||
}
|
}
|
@ -9,14 +9,15 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupInfoCommand extends GroupSubCommand {
|
public class GroupInfo extends GroupSubCommand {
|
||||||
public GroupInfoCommand() {
|
public GroupInfo() {
|
||||||
super("info", "Gives info about the group", "/%s group <group> info", Permission.GROUP_INFO);
|
super("info", "Gives info about the group", "/%s group <group> info", Permission.GROUP_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
Message.GROUP_INFO.send(sender, group.getName(), group.getNodes().keySet().size(), label, group.getName());
|
Message.GROUP_INFO.send(sender, group.getName(), group.getPermanentNodes().keySet().size(),
|
||||||
|
group.getTemporaryNodes().keySet().size(), label, group.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupInheritsPermCommand extends GroupSubCommand {
|
public class GroupInheritsPerm extends GroupSubCommand {
|
||||||
public GroupInheritsPermCommand() {
|
public GroupInheritsPerm() {
|
||||||
super("inheritspermission", "Checks to see if a group inherits a certain permission node",
|
super("inheritspermission", "Checks to see if a group inherits a certain permission node",
|
||||||
"/%s group <group> inheritspermission <node> [server]", Permission.GROUP_INHERITSPERMISSION);
|
"/%s group <group> inheritspermission <node> [server]", Permission.GROUP_INHERITSPERMISSION);
|
||||||
}
|
}
|
@ -10,15 +10,16 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupListNodesCommand extends GroupSubCommand {
|
public class GroupListNodes extends GroupSubCommand {
|
||||||
public GroupListNodesCommand() {
|
public GroupListNodes() {
|
||||||
super("listnodes", "Lists the permission nodes the group has", "/%s group <group> listnodes",
|
super("listnodes", "Lists the permission nodes the group has", "/%s group <group> listnodes",
|
||||||
Permission.GROUP_LISTNODES);
|
Permission.GROUP_LISTNODES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
Message.LISTNODES.send(sender, group.getName(), Util.nodesToString(group.getNodes()));
|
Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(group.getPermanentNodes()));
|
||||||
|
Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getTemporaryNodes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -10,8 +10,8 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupSetInheritCommand extends GroupSubCommand {
|
public class GroupSetInherit extends GroupSubCommand {
|
||||||
public GroupSetInheritCommand() {
|
public GroupSetInherit() {
|
||||||
super("setinherit", "Sets another group for this group to inherit permissions from",
|
super("setinherit", "Sets another group for this group to inherit permissions from",
|
||||||
"/%s group <group> setinherit <group> [server]", Permission.GROUP_SETINHERIT);
|
"/%s group <group> setinherit <group> [server]", Permission.GROUP_SETINHERIT);
|
||||||
}
|
}
|
||||||
@ -20,6 +20,11 @@ public class GroupSetInheritCommand extends GroupSubCommand {
|
|||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
String groupName = args.get(0).toLowerCase();
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Message.GROUP_LOAD_ERROR.send(sender);
|
Message.GROUP_LOAD_ERROR.send(sender);
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.utils.Patterns;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupSetPermissionCommand extends GroupSubCommand {
|
public class GroupSetPermission extends GroupSubCommand {
|
||||||
public GroupSetPermissionCommand() {
|
public GroupSetPermission() {
|
||||||
super("set", "Sets a permission for a group", "/%s group <group> set <node> <true|false> [server]",
|
super("set", "Sets a permission for a group", "/%s group <group> set <node> <true|false> [server]",
|
||||||
Permission.GROUP_SETPERMISSION);
|
Permission.GROUP_SETPERMISSION);
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ public class GroupSetPermissionCommand extends GroupSubCommand {
|
|||||||
String node = args.get(0);
|
String node = args.get(0);
|
||||||
String bool = args.get(1).toLowerCase();
|
String bool = args.get(1).toLowerCase();
|
||||||
|
|
||||||
if (node.contains("/")) {
|
if (node.contains("/") || node.contains("$")) {
|
||||||
sendUsage(sender, label);
|
sendUsage(sender, label);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package me.lucko.luckperms.commands.group.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
|
import me.lucko.luckperms.groups.Group;
|
||||||
|
import me.lucko.luckperms.utils.DateUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GroupSetTempInherit extends GroupSubCommand {
|
||||||
|
public GroupSetTempInherit() {
|
||||||
|
super("settempinherit", "Sets another group for this group to inherit permissions from temporarily",
|
||||||
|
"/%s group <group> settempinherit <group> <duration> [server]", Permission.GROUP_SET_TEMP_INHERIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long duration;
|
||||||
|
try {
|
||||||
|
duration = DateUtil.parseDateDiff(args.get(1), true);
|
||||||
|
} catch (DateUtil.IllegalDateException e) {
|
||||||
|
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(1));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DateUtil.shouldExpire(duration)) {
|
||||||
|
Message.PAST_DATE_ERROR.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||||
|
if (!success) {
|
||||||
|
Message.GROUP_LOAD_ERROR.send(sender);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (args.size() == 3) {
|
||||||
|
final String server = args.get(2).toLowerCase();
|
||||||
|
group.setPermission("group." + groupName, true, server, duration);
|
||||||
|
Message.GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server,
|
||||||
|
DateUtil.formatDateDiff(duration));
|
||||||
|
} else {
|
||||||
|
group.setPermission("group." + groupName, true, duration);
|
||||||
|
Message.GROUP_SET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName, DateUtil.formatDateDiff(duration));
|
||||||
|
}
|
||||||
|
|
||||||
|
saveGroup(group, sender, plugin);
|
||||||
|
} catch (ObjectAlreadyHasException e) {
|
||||||
|
Message.GROUP_ALREADY_TEMP_INHERITS.send(sender, group.getName(), groupName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||||
|
return getGroupTabComplete(args, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return argLength != 2 && argLength != 3;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package me.lucko.luckperms.commands.group.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
|
import me.lucko.luckperms.groups.Group;
|
||||||
|
import me.lucko.luckperms.utils.DateUtil;
|
||||||
|
import me.lucko.luckperms.utils.Patterns;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GroupSetTempPermission extends GroupSubCommand {
|
||||||
|
public GroupSetTempPermission() {
|
||||||
|
super("settemp", "Sets a temporary permission for a group", "/%s group <group> settemp <node> <true|false> <duration> [server]",
|
||||||
|
Permission.GROUP_SET_TEMP_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
|
String node = args.get(0);
|
||||||
|
String bool = args.get(1).toLowerCase();
|
||||||
|
|
||||||
|
if (node.contains("/") || node.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||||
|
Message.GROUP_USE_INHERIT.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean b = Boolean.parseBoolean(bool);
|
||||||
|
|
||||||
|
long duration;
|
||||||
|
try {
|
||||||
|
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||||
|
} catch (DateUtil.IllegalDateException e) {
|
||||||
|
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DateUtil.shouldExpire(duration)) {
|
||||||
|
Message.PAST_DATE_ERROR.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.size() == 4) {
|
||||||
|
final String server = args.get(3).toLowerCase();
|
||||||
|
group.setPermission(node, b, server, duration);
|
||||||
|
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server, DateUtil.formatDateDiff(duration));
|
||||||
|
} else {
|
||||||
|
group.setPermission(node, b, duration);
|
||||||
|
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getName(), DateUtil.formatDateDiff(duration));
|
||||||
|
}
|
||||||
|
|
||||||
|
saveGroup(group, sender, plugin);
|
||||||
|
} catch (ObjectAlreadyHasException e) {
|
||||||
|
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, group.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||||
|
return getBoolTabComplete(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return argLength != 3 && argLength != 4;
|
||||||
|
}
|
||||||
|
}
|
@ -12,8 +12,8 @@ import me.lucko.luckperms.tracks.Track;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class GroupShowTracksCommand extends GroupSubCommand {
|
public class GroupShowTracks extends GroupSubCommand {
|
||||||
public GroupShowTracksCommand() {
|
public GroupShowTracks() {
|
||||||
super("showtracks", "Lists the tracks that this group features on", "/%s group <group> showtracks", Permission.GROUP_SHOWTRACKS);
|
super("showtracks", "Lists the tracks that this group features on", "/%s group <group> showtracks", Permission.GROUP_SHOWTRACKS);
|
||||||
}
|
}
|
||||||
|
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.utils.Patterns;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupUnSetPermissionCommand extends GroupSubCommand {
|
public class GroupUnSetPermission extends GroupSubCommand {
|
||||||
public GroupUnSetPermissionCommand() {
|
public GroupUnSetPermission() {
|
||||||
super("unset", "Unsets a permission for a group",
|
super("unset", "Unsets a permission for a group",
|
||||||
"/%s group <group> unset <node> [server]", Permission.GROUP_UNSETPERMISSION);
|
"/%s group <group> unset <node> [server]", Permission.GROUP_UNSETPERMISSION);
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ public class GroupUnSetPermissionCommand extends GroupSubCommand {
|
|||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
String node = args.get(0);
|
String node = args.get(0);
|
||||||
|
|
||||||
if (node.contains("/")) {
|
if (node.contains("/") || node.contains("$")) {
|
||||||
sendUsage(sender, label);
|
sendUsage(sender, label);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -10,8 +10,8 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupUnsetInheritCommand extends GroupSubCommand {
|
public class GroupUnsetInherit extends GroupSubCommand {
|
||||||
public GroupUnsetInheritCommand() {
|
public GroupUnsetInherit() {
|
||||||
super("unsetinherit", "Unsets another group for this group to inherit permissions from",
|
super("unsetinherit", "Unsets another group for this group to inherit permissions from",
|
||||||
"/%s group <group> unsetinherit <group> [server]", Permission.GROUP_UNSETINHERIT);
|
"/%s group <group> unsetinherit <group> [server]", Permission.GROUP_UNSETINHERIT);
|
||||||
}
|
}
|
||||||
@ -20,6 +20,11 @@ public class GroupUnsetInheritCommand extends GroupSubCommand {
|
|||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
String groupName = args.get(0).toLowerCase();
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.size() == 2) {
|
if (args.size() == 2) {
|
||||||
final String server = args.get(1).toLowerCase();
|
final String server = args.get(1).toLowerCase();
|
@ -0,0 +1,53 @@
|
|||||||
|
package me.lucko.luckperms.commands.group.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
import me.lucko.luckperms.groups.Group;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GroupUnsetTempInherit extends GroupSubCommand {
|
||||||
|
public GroupUnsetTempInherit() {
|
||||||
|
super("unsettempinherit", "Unsets another group for this group to inherit permissions from",
|
||||||
|
"/%s group <group> unsettempinherit <group> [server]", Permission.GROUP_UNSET_TEMP_INHERIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.size() == 2) {
|
||||||
|
final String server = args.get(1).toLowerCase();
|
||||||
|
group.unsetPermission("group." + groupName, server, true);
|
||||||
|
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
|
||||||
|
} else {
|
||||||
|
group.unsetPermission("group." + groupName, true);
|
||||||
|
Message.GROUP_UNSET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveGroup(group, sender, plugin);
|
||||||
|
} catch (ObjectLacksException e) {
|
||||||
|
Message.GROUP_DOES_NOT_TEMP_INHERIT.send(sender, group.getName(), groupName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||||
|
return getGroupTabComplete(args, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return argLength != 1 && argLength != 2;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package me.lucko.luckperms.commands.group.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
import me.lucko.luckperms.groups.Group;
|
||||||
|
import me.lucko.luckperms.utils.Patterns;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GroupUnsetTempPermission extends GroupSubCommand {
|
||||||
|
public GroupUnsetTempPermission() {
|
||||||
|
super("unsettemp", "Unsets a temporary permission for a group",
|
||||||
|
"/%s group <group> unsettemp <node> [server]", Permission.GROUP_UNSET_TEMP_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||||
|
String node = args.get(0);
|
||||||
|
|
||||||
|
if (node.contains("/") || node.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||||
|
Message.GROUP_USE_UNINHERIT.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.size() == 2) {
|
||||||
|
final String server = args.get(1).toLowerCase();
|
||||||
|
group.unsetPermission(node, server);
|
||||||
|
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server, true);
|
||||||
|
} else {
|
||||||
|
group.unsetPermission(node, true);
|
||||||
|
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
saveGroup(group, sender, plugin);
|
||||||
|
} catch (ObjectLacksException e) {
|
||||||
|
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, group.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return argLength != 1 && argLength != 2;
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.utils.Patterns;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CreateTrackCommand extends MainCommand {
|
public class CreateTrack extends MainCommand {
|
||||||
public CreateTrackCommand() {
|
public CreateTrack() {
|
||||||
super("CreateTrack", "/%s createtrack <track>", 1);
|
super("CreateTrack", "/%s createtrack <track>", 1);
|
||||||
}
|
}
|
||||||
|
|
@ -13,8 +13,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DeleteTrackCommand extends MainCommand {
|
public class DeleteTrack extends MainCommand {
|
||||||
public DeleteTrackCommand() {
|
public DeleteTrack() {
|
||||||
super("DeleteTrack", "/%s deletetrack <track>", 1);
|
super("DeleteTrack", "/%s deletetrack <track>", 1);
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ListTracksCommand extends MainCommand {
|
public class ListTracks extends MainCommand {
|
||||||
public ListTracksCommand() {
|
public ListTracks() {
|
||||||
super("ListTracks", "/%s listtracks", 0);
|
super("ListTracks", "/%s listtracks", 0);
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,8 @@ import me.lucko.luckperms.tracks.Track;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrackAppendCommand extends TrackSubCommand {
|
public class TrackAppend extends TrackSubCommand {
|
||||||
public TrackAppendCommand() {
|
public TrackAppend() {
|
||||||
super("append", "Appends a group onto the end of the track", "/%s track <track> append <group>", Permission.TRACK_APPEND);
|
super("append", "Appends a group onto the end of the track", "/%s track <track> append <group>", Permission.TRACK_APPEND);
|
||||||
}
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.tracks.Track;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrackClearCommand extends TrackSubCommand {
|
public class TrackClear extends TrackSubCommand {
|
||||||
public TrackClearCommand() {
|
public TrackClear() {
|
||||||
super("clear", "Clears the groups on the track", "/%s track <track> clear", Permission.TRACK_CLEAR);
|
super("clear", "Clears the groups on the track", "/%s track <track> clear", Permission.TRACK_CLEAR);
|
||||||
}
|
}
|
||||||
|
|
@ -10,8 +10,8 @@ import me.lucko.luckperms.tracks.Track;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrackInfoCommand extends TrackSubCommand {
|
public class TrackInfo extends TrackSubCommand {
|
||||||
public TrackInfoCommand() {
|
public TrackInfo() {
|
||||||
super("info", "Gives info about the track", "/%s track <track> info", Permission.TRACK_INFO);
|
super("info", "Gives info about the track", "/%s track <track> info", Permission.TRACK_INFO);
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,8 @@ import me.lucko.luckperms.tracks.Track;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrackInsertCommand extends TrackSubCommand {
|
public class TrackInsert extends TrackSubCommand {
|
||||||
public TrackInsertCommand() {
|
public TrackInsert() {
|
||||||
super("insert", "Inserts a group at a given position along the track",
|
super("insert", "Inserts a group at a given position along the track",
|
||||||
"/%s track <track> insert <group> <position>", Permission.TRACK_INSERT);
|
"/%s track <track> insert <group> <position>", Permission.TRACK_INSERT);
|
||||||
}
|
}
|
@ -10,8 +10,8 @@ import me.lucko.luckperms.tracks.Track;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrackRemoveCommand extends TrackSubCommand {
|
public class TrackRemove extends TrackSubCommand {
|
||||||
public TrackRemoveCommand() {
|
public TrackRemove() {
|
||||||
super("remove", "Removes a group from the track", "/%s track <track> remove <group>", Permission.TRACK_REMOVE);
|
super("remove", "Removes a group from the track", "/%s track <track> remove <group>", Permission.TRACK_REMOVE);
|
||||||
}
|
}
|
||||||
|
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserAddGroupCommand extends UserSubCommand {
|
public class UserAddGroup extends UserSubCommand {
|
||||||
public UserAddGroupCommand() {
|
public UserAddGroup() {
|
||||||
super("addgroup", "Adds the user to a group", "/%s user <user> addgroup <group> [server]", Permission.USER_ADDGROUP);
|
super("addgroup", "Adds the user to a group", "/%s user <user> addgroup <group> [server]", Permission.USER_ADDGROUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +20,11 @@ public class UserAddGroupCommand extends UserSubCommand {
|
|||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
String groupName = args.get(0).toLowerCase();
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
@ -0,0 +1,81 @@
|
|||||||
|
package me.lucko.luckperms.commands.user.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.user.UserSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
|
import me.lucko.luckperms.groups.Group;
|
||||||
|
import me.lucko.luckperms.users.User;
|
||||||
|
import me.lucko.luckperms.utils.DateUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserAddTempGroup extends UserSubCommand {
|
||||||
|
public UserAddTempGroup() {
|
||||||
|
super("addtempgroup", "Adds the user to a group temporarily", "/%s user <user> addtempgroup <group> <duration> [server]",
|
||||||
|
Permission.USER_ADDTEMPGROUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long duration;
|
||||||
|
try {
|
||||||
|
duration = DateUtil.parseDateDiff(args.get(1), true);
|
||||||
|
} catch (DateUtil.IllegalDateException e) {
|
||||||
|
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(1));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DateUtil.shouldExpire(duration)) {
|
||||||
|
Message.PAST_DATE_ERROR.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||||
|
if (!success) {
|
||||||
|
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||||
|
} else {
|
||||||
|
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||||
|
if (group == null) {
|
||||||
|
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.size() == 3) {
|
||||||
|
final String server = args.get(2).toLowerCase();
|
||||||
|
user.addGroup(group, server, duration);
|
||||||
|
Message.USER_ADDTEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server,
|
||||||
|
DateUtil.formatDateDiff(duration));
|
||||||
|
} else {
|
||||||
|
user.addGroup(group, duration);
|
||||||
|
Message.USER_ADDTEMPGROUP_SUCCESS.send(sender, user.getName(), groupName, DateUtil.formatDateDiff(duration));
|
||||||
|
}
|
||||||
|
|
||||||
|
saveUser(user, sender, plugin);
|
||||||
|
} catch (ObjectAlreadyHasException e) {
|
||||||
|
Message.USER_ALREADY_TEMP_MEMBER_OF.send(sender, user.getName(), group.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||||
|
return getGroupTabComplete(args, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return (argLength != 2 && argLength != 3);
|
||||||
|
}
|
||||||
|
}
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserClearCommand extends UserSubCommand {
|
public class UserClear extends UserSubCommand {
|
||||||
public UserClearCommand() {
|
public UserClear() {
|
||||||
super("clear", "Clears a users permissions and groups", "/%s user <user> clear", Permission.USER_CLEAR);
|
super("clear", "Clears a users permissions and groups", "/%s user <user> clear", Permission.USER_CLEAR);
|
||||||
}
|
}
|
||||||
|
|
@ -14,8 +14,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserDemoteCommand extends UserSubCommand {
|
public class UserDemote extends UserSubCommand {
|
||||||
public UserDemoteCommand() {
|
public UserDemote() {
|
||||||
super("demote", "Demotes a user along a track", "/%s user <user> demote <track>", Permission.USER_DEMOTE);
|
super("demote", "Demotes a user along a track", "/%s user <user> demote <track>", Permission.USER_DEMOTE);
|
||||||
}
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserGetUUIDCommand extends UserSubCommand {
|
public class UserGetUUID extends UserSubCommand {
|
||||||
public UserGetUUIDCommand() {
|
public UserGetUUID() {
|
||||||
super("getuuid", "Get the UUID of a user", "/%s user <user> getuuid", Permission.USER_GETUUID);
|
super("getuuid", "Get the UUID of a user", "/%s user <user> getuuid", Permission.USER_GETUUID);
|
||||||
}
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserHasPermCommand extends UserSubCommand {
|
public class UserHasPerm extends UserSubCommand {
|
||||||
public UserHasPermCommand() {
|
public UserHasPerm() {
|
||||||
super("haspermission", "Checks to see if a user has a certain permission node",
|
super("haspermission", "Checks to see if a user has a certain permission node",
|
||||||
"/%s user <user> haspermission <node> [server]", Permission.USER_HASPERMISSION);
|
"/%s user <user> haspermission <node> [server]", Permission.USER_HASPERMISSION);
|
||||||
}
|
}
|
@ -10,8 +10,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserInfoCommand extends UserSubCommand {
|
public class UserInfo extends UserSubCommand {
|
||||||
public UserInfoCommand() {
|
public UserInfo() {
|
||||||
super("info", "Gives info about the user", "/%s user <user> info", Permission.USER_INFO);
|
super("info", "Gives info about the user", "/%s user <user> info", Permission.USER_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ public class UserInfoCommand extends UserSubCommand {
|
|||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
Message.USER_INFO.send(sender, user.getName(), user.getUuid(), plugin.getPlayerStatus(user.getUuid()),
|
Message.USER_INFO.send(sender, user.getName(), user.getUuid(), plugin.getPlayerStatus(user.getUuid()),
|
||||||
Util.listToCommaSep(user.getGroupNames()), user.getPrimaryGroup(),
|
Util.listToCommaSep(user.getGroupNames()), user.getPrimaryGroup(),
|
||||||
(user.getNodes().keySet().size() - user.getGroupNames().size()), label, user.getName()
|
user.getPermanentNodes().keySet().size(), user.getTemporaryNodes().keySet().size(), label, user.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserInheritsPermCommand extends UserSubCommand {
|
public class UserInheritsPerm extends UserSubCommand {
|
||||||
public UserInheritsPermCommand() {
|
public UserInheritsPerm() {
|
||||||
super("inheritspermission", "Checks to see if a user inherits a certain permission node",
|
super("inheritspermission", "Checks to see if a user inherits a certain permission node",
|
||||||
"/%s user <user> inheritspermission <node> [server]", Permission.USER_INHERITSPERMISSION);
|
"/%s user <user> inheritspermission <node> [server]", Permission.USER_INHERITSPERMISSION);
|
||||||
}
|
}
|
@ -10,14 +10,15 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserListNodesCommand extends UserSubCommand {
|
public class UserListNodes extends UserSubCommand {
|
||||||
public UserListNodesCommand() {
|
public UserListNodes() {
|
||||||
super("listnodes", "Lists the permission nodes the user has", "/%s user <user> listnodes", Permission.USER_LISTNODES);
|
super("listnodes", "Lists the permission nodes the user has", "/%s user <user> listnodes", Permission.USER_LISTNODES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
Message.LISTNODES.send(sender, user.getName(), Util.nodesToString(user.getNodes()));
|
Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(user.getPermanentNodes()));
|
||||||
|
Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getTemporaryNodes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -14,8 +14,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserPromoteCommand extends UserSubCommand {
|
public class UserPromote extends UserSubCommand {
|
||||||
public UserPromoteCommand() {
|
public UserPromote() {
|
||||||
super("promote", "Promotes the user along a track", "/%s user <user> promote <track>", Permission.USER_PROMOTE);
|
super("promote", "Promotes the user along a track", "/%s user <user> promote <track>", Permission.USER_PROMOTE);
|
||||||
}
|
}
|
||||||
|
|
@ -10,8 +10,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserRemoveGroupCommand extends UserSubCommand {
|
public class UserRemoveGroup extends UserSubCommand {
|
||||||
public UserRemoveGroupCommand() {
|
public UserRemoveGroup() {
|
||||||
super("removegroup", "Removes a user from a group", "/%s user <user> removegroup <group> [server]", Permission.USER_REMOVEGROUP);
|
super("removegroup", "Removes a user from a group", "/%s user <user> removegroup <group> [server]", Permission.USER_REMOVEGROUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,6 +19,11 @@ public class UserRemoveGroupCommand extends UserSubCommand {
|
|||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
String groupName = args.get(0).toLowerCase();
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((args.size() == 1 || (args.size() == 2 && args.get(1).equalsIgnoreCase("global")))
|
if ((args.size() == 1 || (args.size() == 2 && args.get(1).equalsIgnoreCase("global")))
|
||||||
&& user.getPrimaryGroup().equalsIgnoreCase(groupName)) {
|
&& user.getPrimaryGroup().equalsIgnoreCase(groupName)) {
|
||||||
Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
|
Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
|
@ -0,0 +1,52 @@
|
|||||||
|
package me.lucko.luckperms.commands.user.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.user.UserSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
import me.lucko.luckperms.users.User;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserRemoveTempGroup extends UserSubCommand {
|
||||||
|
public UserRemoveTempGroup() {
|
||||||
|
super("removetempgroup", "Removes a user from a temporary group", "/%s user <user> removetempgroup <group> [server]", Permission.USER_REMOVETEMPGROUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
|
String groupName = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
if (groupName.contains("/") || groupName.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.size() == 2) {
|
||||||
|
final String server = args.get(1).toLowerCase();
|
||||||
|
user.unsetPermission("group." + groupName, server, true);
|
||||||
|
Message.USER_REMOVETEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
|
||||||
|
} else {
|
||||||
|
user.unsetPermission("group." + groupName, true);
|
||||||
|
Message.USER_REMOVETEMPGROUP_SUCCESS.send(sender, user.getName(), groupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveUser(user, sender, plugin);
|
||||||
|
} catch (ObjectLacksException e) {
|
||||||
|
Message.USER_NOT_TEMP_MEMBER_OF.send(sender, user.getName(), groupName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||||
|
return getGroupTabComplete(args, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return (argLength != 1 && argLength != 2);
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.utils.Patterns;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserSetPermissionCommand extends UserSubCommand {
|
public class UserSetPermission extends UserSubCommand {
|
||||||
public UserSetPermissionCommand() {
|
public UserSetPermission() {
|
||||||
super("set", "Sets a permission for a user",
|
super("set", "Sets a permission for a user",
|
||||||
"/%s user <user> set <node> <true|false> [server]", Permission.USER_SETPERMISSION);
|
"/%s user <user> set <node> <true|false> [server]", Permission.USER_SETPERMISSION);
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ public class UserSetPermissionCommand extends UserSubCommand {
|
|||||||
String node = args.get(0);
|
String node = args.get(0);
|
||||||
String bool = args.get(1).toLowerCase();
|
String bool = args.get(1).toLowerCase();
|
||||||
|
|
||||||
if (node.contains("/")) {
|
if (node.contains("/") || node.contains("$")) {
|
||||||
sendUsage(sender, label);
|
sendUsage(sender, label);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -10,8 +10,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserSetPrimaryGroupCommand extends UserSubCommand {
|
public class UserSetPrimaryGroup extends UserSubCommand {
|
||||||
public UserSetPrimaryGroupCommand() {
|
public UserSetPrimaryGroup() {
|
||||||
super("setprimarygroup", "Sets a users primary group",
|
super("setprimarygroup", "Sets a users primary group",
|
||||||
"/%s user <user> setprimarygroup <group>", Permission.USER_SETPRIMARYGROUP);
|
"/%s user <user> setprimarygroup <group>", Permission.USER_SETPRIMARYGROUP);
|
||||||
}
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package me.lucko.luckperms.commands.user.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.user.UserSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
|
import me.lucko.luckperms.users.User;
|
||||||
|
import me.lucko.luckperms.utils.DateUtil;
|
||||||
|
import me.lucko.luckperms.utils.Patterns;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserSetTempPermission extends UserSubCommand {
|
||||||
|
public UserSetTempPermission() {
|
||||||
|
super("settemp", "Sets a temporary permission for a user",
|
||||||
|
"/%s user <user> settemp <node> <true|false> <duration> [server]", Permission.USER_SET_TEMP_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
|
String node = args.get(0);
|
||||||
|
String bool = args.get(1).toLowerCase();
|
||||||
|
|
||||||
|
if (node.contains("/") || node.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||||
|
Message.USER_USE_ADDGROUP.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean b = Boolean.parseBoolean(bool);
|
||||||
|
|
||||||
|
long duration;
|
||||||
|
try {
|
||||||
|
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||||
|
} catch (DateUtil.IllegalDateException e) {
|
||||||
|
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DateUtil.shouldExpire(duration)) {
|
||||||
|
Message.PAST_DATE_ERROR.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.size() == 4) {
|
||||||
|
final String server = args.get(3).toLowerCase();
|
||||||
|
user.setPermission(node, b, server, duration);
|
||||||
|
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server, DateUtil.formatDateDiff(duration));
|
||||||
|
} else {
|
||||||
|
user.setPermission(node, b, duration);
|
||||||
|
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, user.getName(), DateUtil.formatDateDiff(duration));
|
||||||
|
}
|
||||||
|
|
||||||
|
saveUser(user, sender, plugin);
|
||||||
|
} catch (ObjectAlreadyHasException e) {
|
||||||
|
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, user.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||||
|
return getBoolTabComplete(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return argLength != 3 && argLength != 4;
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserShowPosCommand extends UserSubCommand {
|
public class UserShowPos extends UserSubCommand {
|
||||||
public UserShowPosCommand() {
|
public UserShowPos() {
|
||||||
super("showpos", "Shows a users position on a track", "/%s user <user> showpos <track>", Permission.USER_SHOWPOS);
|
super("showpos", "Shows a users position on a track", "/%s user <user> showpos <track>", Permission.USER_SHOWPOS);
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,8 @@ import me.lucko.luckperms.users.User;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UserShowTracksCommand extends UserSubCommand {
|
public class UserShowTracks extends UserSubCommand {
|
||||||
public UserShowTracksCommand() {
|
public UserShowTracks() {
|
||||||
super("showtracks", "Lists the tracks that this user's primary group features on", "/%s user <user> showtracks",
|
super("showtracks", "Lists the tracks that this user's primary group features on", "/%s user <user> showtracks",
|
||||||
Permission.USER_SHOWTRACKS);
|
Permission.USER_SHOWTRACKS);
|
||||||
}
|
}
|
@ -11,8 +11,8 @@ import me.lucko.luckperms.utils.Patterns;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserUnSetPermissionCommand extends UserSubCommand {
|
public class UserUnSetPermission extends UserSubCommand {
|
||||||
public UserUnSetPermissionCommand() {
|
public UserUnSetPermission() {
|
||||||
super("unset", "Unsets a permission for a user",
|
super("unset", "Unsets a permission for a user",
|
||||||
"/%s user <user> unset <node> [server]", Permission.USER_UNSETPERMISSION);
|
"/%s user <user> unset <node> [server]", Permission.USER_UNSETPERMISSION);
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ public class UserUnSetPermissionCommand extends UserSubCommand {
|
|||||||
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
String node = args.get(0);
|
String node = args.get(0);
|
||||||
|
|
||||||
if (node.contains("/")) {
|
if (node.contains("/") || node.contains("$")) {
|
||||||
sendUsage(sender, label);
|
sendUsage(sender, label);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package me.lucko.luckperms.commands.user.subcommands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.user.UserSubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Message;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
import me.lucko.luckperms.users.User;
|
||||||
|
import me.lucko.luckperms.utils.Patterns;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserUnsetTempPermission extends UserSubCommand {
|
||||||
|
public UserUnsetTempPermission() {
|
||||||
|
super("unsettemp", "Unsets a temporary permission for a user",
|
||||||
|
"/%s user <user> unsettemp <node> [server]", Permission.USER_UNSET_TEMP_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||||
|
String node = args.get(0);
|
||||||
|
|
||||||
|
if (node.contains("/") || node.contains("$")) {
|
||||||
|
sendUsage(sender, label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||||
|
Message.USER_USE_REMOVEGROUP.send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.size() == 2) {
|
||||||
|
final String server = args.get(1).toLowerCase();
|
||||||
|
user.unsetPermission(node, server, true);
|
||||||
|
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server);
|
||||||
|
} else {
|
||||||
|
user.unsetPermission(node, true);
|
||||||
|
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, user.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
saveUser(user, sender, plugin);
|
||||||
|
} catch (ObjectLacksException e) {
|
||||||
|
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, user.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArgLengthInvalid(int argLength) {
|
||||||
|
return argLength != 1 && argLength != 2;
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,8 @@ public enum Message {
|
|||||||
|
|
||||||
ALREADY_HASPERMISSION("%s already has this permission!", true),
|
ALREADY_HASPERMISSION("%s already has this permission!", true),
|
||||||
DOES_NOT_HAVEPERMISSION("%s does not have this permission set.", true),
|
DOES_NOT_HAVEPERMISSION("%s does not have this permission set.", true),
|
||||||
|
ALREADY_HAS_TEMP_PERMISSION("%s already has this permission set temporarily!", true),
|
||||||
|
DOES_NOT_HAVE_TEMP_PERMISSION("%s does not have this permission set temporarily.", true),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -65,6 +67,12 @@ public enum Message {
|
|||||||
USER_NOT_MEMBER_OF("%s is not a member of '%s'.", true),
|
USER_NOT_MEMBER_OF("%s is not a member of '%s'.", true),
|
||||||
GROUP_ALREADY_INHERITS("%s already inherits '%s'.", true),
|
GROUP_ALREADY_INHERITS("%s already inherits '%s'.", true),
|
||||||
GROUP_DOES_NOT_INHERIT("%s does not inherit '%s'.", true),
|
GROUP_DOES_NOT_INHERIT("%s does not inherit '%s'.", true),
|
||||||
|
|
||||||
|
USER_ALREADY_TEMP_MEMBER_OF("%s is already a temporary member of '%s'.", true),
|
||||||
|
USER_NOT_TEMP_MEMBER_OF("%s is not a temporary member of '%s'.", true),
|
||||||
|
GROUP_ALREADY_TEMP_INHERITS("%s already temporarily inherits '%s'.", true),
|
||||||
|
GROUP_DOES_NOT_TEMP_INHERIT("%s does not temporarily inherit '%s'.", true),
|
||||||
|
|
||||||
TRACK_ALREADY_CONTAINS("Track %s already contains the group '%s'.", true),
|
TRACK_ALREADY_CONTAINS("Track %s already contains the group '%s'.", true),
|
||||||
TRACK_DOES_NOT_CONTAIN("Track %s does not contain the group '%s'.", true),
|
TRACK_DOES_NOT_CONTAIN("Track %s does not contain the group '%s'.", true),
|
||||||
|
|
||||||
@ -107,11 +115,18 @@ public enum Message {
|
|||||||
TRACKS_LIST("&aTracks: %s", true),
|
TRACKS_LIST("&aTracks: %s", true),
|
||||||
|
|
||||||
LISTNODES("&e%s's Nodes:" + "\n" + "%s", true),
|
LISTNODES("&e%s's Nodes:" + "\n" + "%s", true),
|
||||||
|
LISTNODES_TEMP("&e%s's Temporary Nodes:" + "\n" + "%s", true),
|
||||||
SETPERMISSION_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a.", true),
|
SETPERMISSION_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a.", true),
|
||||||
SETPERMISSION_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a.", true),
|
SETPERMISSION_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a.", true),
|
||||||
|
SETPERMISSION_TEMP_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a for a duration of &b%s&a.", true),
|
||||||
|
SETPERMISSION_TEMP_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a for a duration of &b%s&a.", true),
|
||||||
UNSETPERMISSION_SUCCESS("&aUnset &b%s&a for &b%s&a.", true),
|
UNSETPERMISSION_SUCCESS("&aUnset &b%s&a for &b%s&a.", true),
|
||||||
UNSETPERMISSION_SERVER_SUCCESS("&aUnset &b%s&a for &b%s&a on server &b%$s&a.", true),
|
UNSETPERMISSION_SERVER_SUCCESS("&aUnset &b%s&a for &b%s&a on server &b%$s&a.", true),
|
||||||
|
UNSET_TEMP_PERMISSION_SUCCESS("&aUnset temporary permission &b%s&a for &b%s&a.", true),
|
||||||
|
UNSET_TEMP_PERMISSION_SERVER_SUCCESS("&aUnset temporary permission &b%s&a for &b%s&a on server &b%$s&a.", true),
|
||||||
CLEAR_SUCCESS("&b%s&a's permissions were cleared.", true),
|
CLEAR_SUCCESS("&b%s&a's permissions were cleared.", true),
|
||||||
|
ILLEGAL_DATE_ERROR("Could not parse date '%s'.", true),
|
||||||
|
PAST_DATE_ERROR("You cannot set a date in the past!", true),
|
||||||
|
|
||||||
USER_INFO(
|
USER_INFO(
|
||||||
PREFIX + "&d-> &eUser: &6%s" + "\n" +
|
PREFIX + "&d-> &eUser: &6%s" + "\n" +
|
||||||
@ -120,14 +135,19 @@ public enum Message {
|
|||||||
PREFIX + "&d-> &eGroups: &6%s" + "\n" +
|
PREFIX + "&d-> &eGroups: &6%s" + "\n" +
|
||||||
PREFIX + "&d-> &ePrimary Group: &6%s" + "\n" +
|
PREFIX + "&d-> &ePrimary Group: &6%s" + "\n" +
|
||||||
PREFIX + "&d-> &ePermissions: &6%s" + "\n" +
|
PREFIX + "&d-> &ePermissions: &6%s" + "\n" +
|
||||||
|
PREFIX + "&d-> &eTemporary Permissions: &6%s" + "\n" +
|
||||||
PREFIX + "&d-> &bUse &a/%s user %s listnodes &bto see all permissions.",
|
PREFIX + "&d-> &bUse &a/%s user %s listnodes &bto see all permissions.",
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
USER_GETUUID("&bThe UUID of &e%s&b is &e%s&b.", true),
|
USER_GETUUID("&bThe UUID of &e%s&b is &e%s&b.", true),
|
||||||
USER_ADDGROUP_SUCCESS("&b%s&a successfully added to group &b%s&a.", true),
|
USER_ADDGROUP_SUCCESS("&b%s&a successfully added to group &b%s&a.", true),
|
||||||
USER_ADDGROUP_SERVER_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a.", true),
|
USER_ADDGROUP_SERVER_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a.", true),
|
||||||
|
USER_ADDTEMPGROUP_SUCCESS("&b%s&a successfully added to group &b%s&a for a duration of &b%s&a.", true),
|
||||||
|
USER_ADDTEMPGROUP_SERVER_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a for a duration of &b%s&a.", true),
|
||||||
USER_REMOVEGROUP_SUCCESS("&b%s&a was removed from group &b%s&a.", true),
|
USER_REMOVEGROUP_SUCCESS("&b%s&a was removed from group &b%s&a.", true),
|
||||||
USER_REMOVEGROUP_SERVER_SUCCESS("&b%s&a was removed from group &b%s&a on server &b%s&a.", true),
|
USER_REMOVEGROUP_SERVER_SUCCESS("&b%s&a was removed from group &b%s&a on server &b%s&a.", true),
|
||||||
|
USER_REMOVETEMPGROUP_SUCCESS("&b%s&a was removed from temproary group &b%s&a.", true),
|
||||||
|
USER_REMOVETEMPGROUP_SERVER_SUCCESS("&b%s&a was removed from temporary group &b%s&a on server &b%s&a.", true),
|
||||||
USER_REMOVEGROUP_ERROR_PRIMARY("You cannot remove a user from their primary group.", true),
|
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_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_ALREADYHAS("The user already has this group set as their primary group.", true),
|
||||||
@ -156,13 +176,18 @@ public enum Message {
|
|||||||
GROUP_INFO(
|
GROUP_INFO(
|
||||||
PREFIX + "&d-> &eGroup: &6%s" + "\n" +
|
PREFIX + "&d-> &eGroup: &6%s" + "\n" +
|
||||||
PREFIX + "&d-> &ePermissions: &6%s" + "\n" +
|
PREFIX + "&d-> &ePermissions: &6%s" + "\n" +
|
||||||
|
PREFIX + "&d-> &eTemporary Permissions: &6%s" + "\n" +
|
||||||
PREFIX + "&d-> &bUse &a/%s group %s listnodes &bto see all permissions.",
|
PREFIX + "&d-> &bUse &a/%s group %s listnodes &bto see all permissions.",
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
GROUP_SETINHERIT_SUCCESS("&b%s&a now inherits permissions from &b%s&a.", true),
|
GROUP_SETINHERIT_SUCCESS("&b%s&a now inherits permissions from &b%s&a.", true),
|
||||||
GROUP_SETINHERIT_SERVER_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a.", true),
|
GROUP_SETINHERIT_SERVER_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a.", true),
|
||||||
|
GROUP_SET_TEMP_INHERIT_SUCCESS("&b%s&a now inherits permissions from &b%s&a for a duration of &b%s&a.", true),
|
||||||
|
GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a for a duration of &b%s&a.", true),
|
||||||
GROUP_UNSETINHERIT_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a.", true),
|
GROUP_UNSETINHERIT_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a.", true),
|
||||||
GROUP_UNSETINHERIT_SERVER_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a on server &b%s&a.", true),
|
GROUP_UNSETINHERIT_SERVER_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a on server &b%s&a.", true),
|
||||||
|
GROUP_UNSET_TEMP_INHERIT_SUCCESS("&b%s&a no longer temporarily inherits permissions from &b%s&a.", true),
|
||||||
|
GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS("&b%s&a no longer temporarily inherits permissions from &b%s&a on server &b%s&a.", true),
|
||||||
|
|
||||||
TRACK_INFO(
|
TRACK_INFO(
|
||||||
PREFIX + "&d-> &eTrack: &6%s" + "\n" +
|
PREFIX + "&d-> &eTrack: &6%s" + "\n" +
|
||||||
|
@ -29,6 +29,10 @@ public enum Permission {
|
|||||||
USER_UNSETPERMISSION("unsetpermission", PermissionGroup.USER),
|
USER_UNSETPERMISSION("unsetpermission", PermissionGroup.USER),
|
||||||
USER_ADDGROUP("addgroup", PermissionGroup.USER),
|
USER_ADDGROUP("addgroup", PermissionGroup.USER),
|
||||||
USER_REMOVEGROUP("removegroup", PermissionGroup.USER),
|
USER_REMOVEGROUP("removegroup", PermissionGroup.USER),
|
||||||
|
USER_SET_TEMP_PERMISSION("settemppermission", PermissionGroup.USER),
|
||||||
|
USER_UNSET_TEMP_PERMISSION("unsettemppermission", PermissionGroup.USER),
|
||||||
|
USER_ADDTEMPGROUP("addtempgroup", PermissionGroup.USER),
|
||||||
|
USER_REMOVETEMPGROUP("removetempgroup", PermissionGroup.USER),
|
||||||
USER_SETPRIMARYGROUP("setprimarygroup", PermissionGroup.USER),
|
USER_SETPRIMARYGROUP("setprimarygroup", PermissionGroup.USER),
|
||||||
USER_SHOWTRACKS("showtracks", PermissionGroup.USER),
|
USER_SHOWTRACKS("showtracks", PermissionGroup.USER),
|
||||||
USER_PROMOTE("promote", PermissionGroup.USER),
|
USER_PROMOTE("promote", PermissionGroup.USER),
|
||||||
@ -44,6 +48,10 @@ public enum Permission {
|
|||||||
GROUP_UNSETPERMISSION("unsetpermission", PermissionGroup.GROUP),
|
GROUP_UNSETPERMISSION("unsetpermission", PermissionGroup.GROUP),
|
||||||
GROUP_SETINHERIT("setinherit", PermissionGroup.GROUP),
|
GROUP_SETINHERIT("setinherit", PermissionGroup.GROUP),
|
||||||
GROUP_UNSETINHERIT("unsetinherit", PermissionGroup.GROUP),
|
GROUP_UNSETINHERIT("unsetinherit", PermissionGroup.GROUP),
|
||||||
|
GROUP_SET_TEMP_PERMISSION("settemppermission", PermissionGroup.GROUP),
|
||||||
|
GROUP_UNSET_TEMP_PERMISSION("unsettemppermission", PermissionGroup.GROUP),
|
||||||
|
GROUP_SET_TEMP_INHERIT("settempinherit", PermissionGroup.GROUP),
|
||||||
|
GROUP_UNSET_TEMP_INHERIT("unsettempinherit", PermissionGroup.GROUP),
|
||||||
GROUP_SHOWTRACKS("showtracks", PermissionGroup.GROUP),
|
GROUP_SHOWTRACKS("showtracks", PermissionGroup.GROUP),
|
||||||
GROUP_CLEAR("clear", PermissionGroup.GROUP),
|
GROUP_CLEAR("clear", PermissionGroup.GROUP),
|
||||||
|
|
||||||
|
@ -93,6 +93,31 @@ public abstract class User extends PermissionObject {
|
|||||||
setPermission("group." + group.getName(), true, server);
|
setPermission("group." + group.getName(), true, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a user to a group on a specific server
|
||||||
|
* @param group The group to add the user to
|
||||||
|
* @param expireAt when the group should expire
|
||||||
|
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||||
|
*/
|
||||||
|
public void addGroup(Group group, long expireAt) throws ObjectAlreadyHasException {
|
||||||
|
setPermission("group." + group.getName(), true, expireAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a user to a group on a specific server
|
||||||
|
* @param group The group to add the user to
|
||||||
|
* @param server The server to add the group on
|
||||||
|
* @param expireAt when the group should expire
|
||||||
|
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||||
|
*/
|
||||||
|
public void addGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException {
|
||||||
|
if (server == null) {
|
||||||
|
server = "global";
|
||||||
|
}
|
||||||
|
|
||||||
|
setPermission("group." + group.getName(), true, server, expireAt);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the user from a group
|
* Remove the user from a group
|
||||||
* @param group the group to remove the user from
|
* @param group the group to remove the user from
|
||||||
@ -102,6 +127,16 @@ public abstract class User extends PermissionObject {
|
|||||||
removeGroup(group, "global");
|
removeGroup(group, "global");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the user from a group
|
||||||
|
* @param group the group to remove the user from
|
||||||
|
* @param temporary if the group being removed is temporary
|
||||||
|
* @throws ObjectLacksException if the user isn't a member of the group
|
||||||
|
*/
|
||||||
|
public void removeGroup(Group group, boolean temporary) throws ObjectLacksException {
|
||||||
|
removeGroup(group, "global", temporary);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the user from a group
|
* Remove the user from a group
|
||||||
* @param group The group to remove the user from
|
* @param group The group to remove the user from
|
||||||
@ -116,6 +151,21 @@ public abstract class User extends PermissionObject {
|
|||||||
unsetPermission("group." + group.getName(), server);
|
unsetPermission("group." + group.getName(), server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the user from a group
|
||||||
|
* @param group The group to remove the user from
|
||||||
|
* @param server The server to remove the group on
|
||||||
|
* @param temporary if the group being removed is temporary
|
||||||
|
* @throws ObjectLacksException if the user isn't a member of the group
|
||||||
|
*/
|
||||||
|
public void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException {
|
||||||
|
if (server == null) {
|
||||||
|
server = "global";
|
||||||
|
}
|
||||||
|
|
||||||
|
unsetPermission("group." + group.getName(), server, temporary);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all of the users permission nodes
|
* Clear all of the users permission nodes
|
||||||
*/
|
*/
|
||||||
@ -172,10 +222,10 @@ public abstract class User extends PermissionObject {
|
|||||||
final Map<String, Boolean> groupNodes = new HashMap<>();
|
final Map<String, Boolean> groupNodes = new HashMap<>();
|
||||||
|
|
||||||
// Sorts the permissions and puts them into a priority order
|
// Sorts the permissions and puts them into a priority order
|
||||||
for (Map.Entry<String, Boolean> node : getNodes().entrySet()) {
|
for (Map.Entry<String, Boolean> node : convertTemporaryPerms().entrySet()) {
|
||||||
serverSpecific:
|
serverSpecific:
|
||||||
if (node.getKey().contains("/")) {
|
if (node.getKey().contains("/")) {
|
||||||
String[] parts = node.getKey().split("\\/", 2);
|
String[] parts = Patterns.SERVER_SPLIT.split(node.getKey(), 2);
|
||||||
|
|
||||||
if (parts[0].equalsIgnoreCase("global")) {
|
if (parts[0].equalsIgnoreCase("global")) {
|
||||||
// REGULAR
|
// REGULAR
|
||||||
|
170
common/src/main/java/me/lucko/luckperms/utils/DateUtil.java
Normal file
170
common/src/main/java/me/lucko/luckperms/utils/DateUtil.java
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
package me.lucko.luckperms.utils;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All credit to Essentials / EssentialsX for this class
|
||||||
|
* https://github.com/drtshock/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/utils/DateUtil.java
|
||||||
|
* https://github.com/essentials/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/utils/DateUtil.java
|
||||||
|
*/
|
||||||
|
public class DateUtil {
|
||||||
|
private static final Pattern TIME_PATTERN = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
|
||||||
|
private static final int MAX_YEARS = 100000;
|
||||||
|
|
||||||
|
private DateUtil() {}
|
||||||
|
|
||||||
|
public static boolean shouldExpire(long unixTime) {
|
||||||
|
return unixTime < (System.currentTimeMillis() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a time string to a unix timestamp
|
||||||
|
* @param time the time string
|
||||||
|
* @return a unix timestamp
|
||||||
|
* @throws IllegalDateException if the date input was invalid
|
||||||
|
*/
|
||||||
|
public static long parseDateDiff(String time, boolean future) throws IllegalDateException {
|
||||||
|
Matcher m = TIME_PATTERN.matcher(time);
|
||||||
|
int years = 0;
|
||||||
|
int months = 0;
|
||||||
|
int weeks = 0;
|
||||||
|
int days = 0;
|
||||||
|
int hours = 0;
|
||||||
|
int minutes = 0;
|
||||||
|
int seconds = 0;
|
||||||
|
boolean found = false;
|
||||||
|
while (m.find()) {
|
||||||
|
if (m.group() == null || m.group().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < m.groupCount(); i++) {
|
||||||
|
if (m.group(i) != null && !m.group(i).isEmpty()) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
if (m.group(1) != null && !m.group(1).isEmpty()) {
|
||||||
|
years = Integer.parseInt(m.group(1));
|
||||||
|
}
|
||||||
|
if (m.group(2) != null && !m.group(2).isEmpty()) {
|
||||||
|
months = Integer.parseInt(m.group(2));
|
||||||
|
}
|
||||||
|
if (m.group(3) != null && !m.group(3).isEmpty()) {
|
||||||
|
weeks = Integer.parseInt(m.group(3));
|
||||||
|
}
|
||||||
|
if (m.group(4) != null && !m.group(4).isEmpty()) {
|
||||||
|
days = Integer.parseInt(m.group(4));
|
||||||
|
}
|
||||||
|
if (m.group(5) != null && !m.group(5).isEmpty()) {
|
||||||
|
hours = Integer.parseInt(m.group(5));
|
||||||
|
}
|
||||||
|
if (m.group(6) != null && !m.group(6).isEmpty()) {
|
||||||
|
minutes = Integer.parseInt(m.group(6));
|
||||||
|
}
|
||||||
|
if (m.group(7) != null && !m.group(7).isEmpty()) {
|
||||||
|
seconds = Integer.parseInt(m.group(7));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
throw new IllegalDateException();
|
||||||
|
}
|
||||||
|
Calendar c = new GregorianCalendar();
|
||||||
|
if (years > 0) {
|
||||||
|
if (years > MAX_YEARS) {
|
||||||
|
years = MAX_YEARS;
|
||||||
|
}
|
||||||
|
c.add(Calendar.YEAR, years * (future ? 1 : -1));
|
||||||
|
}
|
||||||
|
if (months > 0) {
|
||||||
|
c.add(Calendar.MONTH, months * (future ? 1 : -1));
|
||||||
|
}
|
||||||
|
if (weeks > 0) {
|
||||||
|
c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1));
|
||||||
|
}
|
||||||
|
if (days > 0) {
|
||||||
|
c.add(Calendar.DAY_OF_MONTH, days * (future ? 1 : -1));
|
||||||
|
}
|
||||||
|
if (hours > 0) {
|
||||||
|
c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1));
|
||||||
|
}
|
||||||
|
if (minutes > 0) {
|
||||||
|
c.add(Calendar.MINUTE, minutes * (future ? 1 : -1));
|
||||||
|
}
|
||||||
|
if (seconds > 0) {
|
||||||
|
c.add(Calendar.SECOND, seconds * (future ? 1 : -1));
|
||||||
|
}
|
||||||
|
Calendar max = new GregorianCalendar();
|
||||||
|
max.add(Calendar.YEAR, 10);
|
||||||
|
if (c.after(max)) {
|
||||||
|
return (max.getTimeInMillis() / 1000) + 1;
|
||||||
|
}
|
||||||
|
return (c.getTimeInMillis() / 1000) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) {
|
||||||
|
int year = Calendar.YEAR;
|
||||||
|
|
||||||
|
int fromYear = fromDate.get(year);
|
||||||
|
int toYear = toDate.get(year);
|
||||||
|
if (Math.abs(fromYear - toYear) > MAX_YEARS) {
|
||||||
|
toDate.set(year, fromYear +
|
||||||
|
(future ? MAX_YEARS : -MAX_YEARS));
|
||||||
|
}
|
||||||
|
|
||||||
|
int diff = 0;
|
||||||
|
long savedDate = fromDate.getTimeInMillis();
|
||||||
|
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) {
|
||||||
|
savedDate = fromDate.getTimeInMillis();
|
||||||
|
fromDate.add(type, future ? 1 : -1);
|
||||||
|
diff++;
|
||||||
|
}
|
||||||
|
diff--;
|
||||||
|
fromDate.setTimeInMillis(savedDate);
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatDateDiff(long unixTime) {
|
||||||
|
Calendar c = new GregorianCalendar();
|
||||||
|
c.setTimeInMillis(unixTime * 1000);
|
||||||
|
Calendar now = new GregorianCalendar();
|
||||||
|
return DateUtil.formatDateDiff(now, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatDateDiff(Calendar fromDate, Calendar toDate) {
|
||||||
|
boolean future = false;
|
||||||
|
if (toDate.equals(fromDate)) {
|
||||||
|
return "now";
|
||||||
|
}
|
||||||
|
if (toDate.after(fromDate)) {
|
||||||
|
future = true;
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int[] types = new int[]{Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND};
|
||||||
|
String[] names = new String[]{"year", "years", "month", "months", "day", "days", "hour", "hours", "minute", "minutes", "second", "seconds"};
|
||||||
|
int accuracy = 0;
|
||||||
|
for (int i = 0; i < types.length; i++) {
|
||||||
|
if (accuracy > 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int diff = dateDiff(types[i], fromDate, toDate, future);
|
||||||
|
if (diff > 0) {
|
||||||
|
accuracy++;
|
||||||
|
sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sb.length() == 0) {
|
||||||
|
return "now";
|
||||||
|
}
|
||||||
|
return sb.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IllegalDateException extends Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import java.util.regex.Pattern;
|
|||||||
public class Patterns {
|
public class Patterns {
|
||||||
|
|
||||||
public static final Pattern SERVER_SPLIT = Pattern.compile("\\/");
|
public static final Pattern SERVER_SPLIT = Pattern.compile("\\/");
|
||||||
|
public static final Pattern TEMP_SPLIT = Pattern.compile("\\$");
|
||||||
public static final Pattern DOT_SPLIT = Pattern.compile("\\.");
|
public static final Pattern DOT_SPLIT = Pattern.compile("\\.");
|
||||||
public static final Pattern GROUP_MATCH = Pattern.compile("group\\..*");
|
public static final Pattern GROUP_MATCH = Pattern.compile("group\\..*");
|
||||||
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[^A-Za-z0-9]");
|
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[^A-Za-z0-9]");
|
||||||
|
@ -7,10 +7,8 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
|||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
import java.util.stream.Collectors;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an object that can hold permissions
|
* Represents an object that can hold permissions
|
||||||
@ -39,7 +37,6 @@ public abstract class PermissionObject {
|
|||||||
/**
|
/**
|
||||||
* The user/group's permissions
|
* The user/group's permissions
|
||||||
*/
|
*/
|
||||||
@Setter
|
|
||||||
private Map<String, Boolean> nodes = new HashMap<>();
|
private Map<String, Boolean> nodes = new HashMap<>();
|
||||||
|
|
||||||
protected PermissionObject(LuckPermsPlugin plugin, String objectName) {
|
protected PermissionObject(LuckPermsPlugin plugin, String objectName) {
|
||||||
@ -48,15 +45,43 @@ public abstract class PermissionObject {
|
|||||||
this.includeGlobalPermissions = plugin.getConfiguration().getIncludeGlobalPerms();
|
this.includeGlobalPermissions = plugin.getConfiguration().getIncludeGlobalPerms();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNodes(Map<String, Boolean> nodes) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
auditTemporaryPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method for checking if a map has a certain permission. Used by both #hasPermission and #inheritsPermission
|
||||||
|
*/
|
||||||
|
private static boolean hasPermission(Map<String, Boolean> toQuery, String node, boolean b) {
|
||||||
|
// Not temporary
|
||||||
|
if (!node.contains("$")) {
|
||||||
|
return b ? toQuery.containsKey(node) && toQuery.get(node) : toQuery.containsKey(node) && !toQuery.get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
node = Patterns.TEMP_SPLIT.split(node)[0];
|
||||||
|
|
||||||
|
for (Map.Entry<String, Boolean> e : toQuery.entrySet()) {
|
||||||
|
if (e.getKey().contains("$")) {
|
||||||
|
String[] parts = Patterns.TEMP_SPLIT.split(e.getKey());
|
||||||
|
if (parts[0].equalsIgnoreCase(node)) {
|
||||||
|
return b ? e.getValue() : !e.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the object has a certain permission
|
* Checks to see if the object has a certain permission
|
||||||
* @param node The permission node
|
* @param node The permission node
|
||||||
* @param b If the node is true/false(negated)
|
* @param b If the node is true/false(negated)
|
||||||
* @return true if the user has the permission
|
* @return true if the user has the permission
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(String node, Boolean b) {
|
public boolean hasPermission(String node, boolean b) {
|
||||||
if (node.startsWith("global/")) node = node.replace("global/", "");
|
if (node.startsWith("global/")) node = node.replace("global/", "");
|
||||||
return b ? getNodes().containsKey(node) && getNodes().get(node) : getNodes().containsKey(node) && !getNodes().get(node);
|
return hasPermission(getNodes(), node, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,17 +91,28 @@ public abstract class PermissionObject {
|
|||||||
* @param server The server
|
* @param server The server
|
||||||
* @return true if the user has the permission
|
* @return true if the user has the permission
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(String node, Boolean b, String server) {
|
public boolean hasPermission(String node, boolean b, String server) {
|
||||||
return hasPermission(server + "/" + node, b);
|
return hasPermission(server + "/" + node, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see the the object has a permission on a certain server
|
||||||
|
* @param node The permission node
|
||||||
|
* @param b If the node is true/false(negated)
|
||||||
|
* @param temporary if the permission is temporary
|
||||||
|
* @return true if the user has the permission
|
||||||
|
*/
|
||||||
|
public boolean hasPermission(String node, boolean b, boolean temporary) {
|
||||||
|
return hasPermission(node + (temporary ? "$a" : ""), b);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the object inherits a certain permission
|
* Checks to see if the object inherits a certain permission
|
||||||
* @param node The permission node
|
* @param node The permission node
|
||||||
* @param b If the node is true/false(negated)
|
* @param b If the node is true/false(negated)
|
||||||
* @return true if the user inherits the permission
|
* @return true if the user inherits the permission
|
||||||
*/
|
*/
|
||||||
public boolean inheritsPermission(String node, Boolean b) {
|
public boolean inheritsPermission(String node, boolean b) {
|
||||||
if (node.contains("/")) {
|
if (node.contains("/")) {
|
||||||
// Use other method
|
// Use other method
|
||||||
final String[] parts = Patterns.SERVER_SPLIT.split(node, 2);
|
final String[] parts = Patterns.SERVER_SPLIT.split(node, 2);
|
||||||
@ -93,9 +129,20 @@ public abstract class PermissionObject {
|
|||||||
* @param server The server
|
* @param server The server
|
||||||
* @return true if the user inherits the permission
|
* @return true if the user inherits the permission
|
||||||
*/
|
*/
|
||||||
public boolean inheritsPermission(String node, Boolean b, String server) {
|
public boolean inheritsPermission(String node, boolean b, String server) {
|
||||||
final Map<String, Boolean> local = getLocalPermissions(server, null);
|
final Map<String, Boolean> local = getLocalPermissions(server, null);
|
||||||
return b ? local.containsKey(node) && local.get(node) : local.containsKey(node) && !local.get(node);
|
return hasPermission(local, node, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if the object inherits a certain permission
|
||||||
|
* @param node The permission node
|
||||||
|
* @param b If the node is true/false(negated)
|
||||||
|
* @param temporary if the permission is temporary
|
||||||
|
* @return true if the user inherits the permission
|
||||||
|
*/
|
||||||
|
public boolean inheritsPermission(String node, boolean b, boolean temporary) {
|
||||||
|
return inheritsPermission(node + (temporary ? "$a" : ""), b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +151,7 @@ public abstract class PermissionObject {
|
|||||||
* @param value What to set the node to - true/false(negated)
|
* @param value What to set the node to - true/false(negated)
|
||||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||||
*/
|
*/
|
||||||
public void setPermission(String node, Boolean value) throws ObjectAlreadyHasException {
|
public void setPermission(String node, boolean value) throws ObjectAlreadyHasException {
|
||||||
if (node.startsWith("global/")) node = node.replace("global/", "");
|
if (node.startsWith("global/")) node = node.replace("global/", "");
|
||||||
if (hasPermission(node, value)) {
|
if (hasPermission(node, value)) {
|
||||||
throw new ObjectAlreadyHasException();
|
throw new ObjectAlreadyHasException();
|
||||||
@ -119,21 +166,73 @@ public abstract class PermissionObject {
|
|||||||
* @param server The server to set the permission on
|
* @param server The server to set the permission on
|
||||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||||
*/
|
*/
|
||||||
public void setPermission(String node, Boolean value, String server) throws ObjectAlreadyHasException {
|
public void setPermission(String node, boolean value, String server) throws ObjectAlreadyHasException {
|
||||||
setPermission(server + "/" + node, value);
|
setPermission(server + "/" + node, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a permission for the object
|
||||||
|
* @param node The node to set
|
||||||
|
* @param value What to set the node to - true/false(negated)
|
||||||
|
* @param expireAt The time in unixtime when the permission will expire
|
||||||
|
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||||
|
*/
|
||||||
|
public void setPermission(String node, boolean value, long expireAt) throws ObjectAlreadyHasException {
|
||||||
|
setPermission(node + "$" + expireAt, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a permission for the object
|
||||||
|
* @param node The node to set
|
||||||
|
* @param value What to set the node to - true/false(negated)
|
||||||
|
* @param server The server to set the permission on
|
||||||
|
* @param expireAt The time in unixtime when the permission will expire
|
||||||
|
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||||
|
*/
|
||||||
|
public void setPermission(String node, boolean value, String server, long expireAt) throws ObjectAlreadyHasException {
|
||||||
|
setPermission(node + "$" + expireAt, value, server);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsets a permission for the object
|
||||||
|
* @param node The node to be unset
|
||||||
|
* @param temporary if the permission being removed is temporary
|
||||||
|
* @throws ObjectLacksException if the node wasn't already set
|
||||||
|
*/
|
||||||
|
public void unsetPermission(String node, boolean temporary) throws ObjectLacksException {
|
||||||
|
if (node.startsWith("global/")) node = node.replace("global/", "");
|
||||||
|
String match = null;
|
||||||
|
|
||||||
|
if (!temporary) {
|
||||||
|
if (getNodes().containsKey(node)) {
|
||||||
|
match = node;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (String n : getNodes().keySet()) {
|
||||||
|
if (n.contains("$")) {
|
||||||
|
String[] parts = Patterns.TEMP_SPLIT.split(n);
|
||||||
|
if (parts[0].equalsIgnoreCase(node)) {
|
||||||
|
match = n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match != null) {
|
||||||
|
getNodes().remove(match);
|
||||||
|
} else {
|
||||||
|
throw new ObjectLacksException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets a permission for the object
|
* Unsets a permission for the object
|
||||||
* @param node The node to be unset
|
* @param node The node to be unset
|
||||||
* @throws ObjectLacksException if the node wasn't already set
|
* @throws ObjectLacksException if the node wasn't already set
|
||||||
*/
|
*/
|
||||||
public void unsetPermission(String node) throws ObjectLacksException {
|
public void unsetPermission(String node) throws ObjectLacksException {
|
||||||
if (node.startsWith("global/")) node = node.replace("global/", "");
|
unsetPermission(node, node.contains("$"));
|
||||||
if (!getNodes().containsKey(node)) {
|
|
||||||
throw new ObjectLacksException();
|
|
||||||
}
|
|
||||||
getNodes().remove(node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,6 +245,17 @@ public abstract class PermissionObject {
|
|||||||
unsetPermission(server + "/" + node);
|
unsetPermission(server + "/" + node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsets a permission for the object
|
||||||
|
* @param node The node to be unset
|
||||||
|
* @param server The server to unset the node on
|
||||||
|
* @param temporary if the permission being unset is temporary
|
||||||
|
* @throws ObjectLacksException if the node wasn't already set
|
||||||
|
*/
|
||||||
|
public void unsetPermission(String node, String server, boolean temporary) throws ObjectLacksException {
|
||||||
|
unsetPermission(server + "/" + node, temporary);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the permissions and inherited permissions that apply to a specific server
|
* Gets the permissions and inherited permissions that apply to a specific server
|
||||||
* @param server The server to get nodes for
|
* @param server The server to get nodes for
|
||||||
@ -156,6 +266,83 @@ public abstract class PermissionObject {
|
|||||||
return getPermissions(server, excludedGroups, includeGlobalPermissions);
|
return getPermissions(server, excludedGroups, includeGlobalPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the objects and returns the temporary ones.
|
||||||
|
* @return a map of temporary nodes
|
||||||
|
*/
|
||||||
|
public Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes() {
|
||||||
|
Map<Map.Entry<String, Boolean>, Long> temps = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Boolean> e : getNodes().entrySet()) {
|
||||||
|
if (!e.getKey().contains("$")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] parts = Patterns.TEMP_SPLIT.split(e.getKey());
|
||||||
|
final long expiry = Long.parseLong(parts[1]);
|
||||||
|
temps.put(new AbstractMap.SimpleEntry<>(parts[0], e.getValue()), expiry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return temps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the objects and returns the non-temporary ones.
|
||||||
|
* @return a map of permanent nodes
|
||||||
|
*/
|
||||||
|
public Map<String, Boolean> getPermanentNodes() {
|
||||||
|
Map<String, Boolean> permas = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Boolean> e : getNodes().entrySet()) {
|
||||||
|
if (e.getKey().contains("$")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
permas.put(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return permas;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes temporary permissions that have expired
|
||||||
|
* @return true if permissions had expired and had to be removed
|
||||||
|
*/
|
||||||
|
public boolean auditTemporaryPermissions() {
|
||||||
|
Set<String> toRemove = getNodes().keySet().stream()
|
||||||
|
.filter(s -> s.contains("$"))
|
||||||
|
.filter(s -> DateUtil.shouldExpire(Long.parseLong(Patterns.TEMP_SPLIT.split(s)[1])))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
toRemove.forEach(s -> getNodes().remove(s));
|
||||||
|
return !toRemove.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String stripTime(String s) {
|
||||||
|
if (s.contains("$")) {
|
||||||
|
return Patterns.TEMP_SPLIT.split(s)[0];
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Boolean> convertTemporaryPerms() {
|
||||||
|
auditTemporaryPermissions();
|
||||||
|
|
||||||
|
Map<String, Boolean> nodes = new HashMap<>();
|
||||||
|
Map<String, Boolean> tempNodes = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Boolean> e : getNodes().entrySet()) {
|
||||||
|
if (e.getKey().contains("$")) {
|
||||||
|
tempNodes.put(e.getKey(), e.getValue());
|
||||||
|
} else {
|
||||||
|
nodes.put(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// temporary permissions override non-temporary permissions
|
||||||
|
tempNodes.entrySet().forEach(e -> nodes.put(stripTime(e.getKey()), e.getValue()));
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, Boolean> getPermissions(String server, List<String> excludedGroups, boolean includeGlobal) {
|
private Map<String, Boolean> getPermissions(String server, List<String> excludedGroups, boolean includeGlobal) {
|
||||||
if (excludedGroups == null) {
|
if (excludedGroups == null) {
|
||||||
excludedGroups = new ArrayList<>();
|
excludedGroups = new ArrayList<>();
|
||||||
@ -183,7 +370,7 @@ public abstract class PermissionObject {
|
|||||||
final Map<String, Boolean> groupNodes = new HashMap<>();
|
final Map<String, Boolean> groupNodes = new HashMap<>();
|
||||||
|
|
||||||
// Sorts the permissions and puts them into a priority order
|
// Sorts the permissions and puts them into a priority order
|
||||||
for (Map.Entry<String, Boolean> node : getNodes().entrySet()) {
|
for (Map.Entry<String, Boolean> node : convertTemporaryPerms().entrySet()) {
|
||||||
serverSpecific:
|
serverSpecific:
|
||||||
if (node.getKey().contains("/")) {
|
if (node.getKey().contains("/")) {
|
||||||
String[] parts = Patterns.SERVER_SPLIT.split(node.getKey(), 2);
|
String[] parts = Patterns.SERVER_SPLIT.split(node.getKey(), 2);
|
||||||
|
17
common/src/test/DateTest.java
Normal file
17
common/src/test/DateTest.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import me.lucko.luckperms.utils.DateUtil;
|
||||||
|
|
||||||
|
public class DateTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("" + DateUtil.parseDateDiff("1m", true));
|
||||||
|
System.out.println(DateUtil.formatDateDiff(DateUtil.parseDateDiff("1 hour, 1 second", true)));
|
||||||
|
|
||||||
|
} catch (DateUtil.IllegalDateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user