mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 20:17:55 +01:00
Add logging, prepare for import/export system
This commit is contained in:
parent
fbf062933f
commit
e216c235ce
@ -17,6 +17,7 @@ A permissions implementation for Bukkit/Spigot, BungeeCord and Sponge.
|
||||
* **Tracks / paths / ladders** - users can be promoted/demoted along multiple group tracks
|
||||
* **Vault Support** - hooks into Vault to integrate with other plugins
|
||||
* **Developer API** - easily integrate LuckPerms into your own projects
|
||||
* **Advanced action logging** - keep track of permission changes over time
|
||||
* **Easy and simple setup and configuration using commands** - no editing yml files, yuck
|
||||
* **Negated permissions and groups** - define special rules for certain users/groups
|
||||
* **Regex permissions** - define special permissions using regex
|
||||
@ -237,5 +238,13 @@ Additionally, you can use wildcards to grant users access to a selection of comm
|
||||
* /perms track \<track\> remove \<group\> - luckperms.track.remove
|
||||
* /perms track \<track\> clear - luckperms.track.clear
|
||||
|
||||
### Log
|
||||
* /perms log recent [user] [page] - luckperms.log.recent
|
||||
* /perms log search \<query\> [page] - luckperms.log.search
|
||||
* /perms log notify [on|off] - luckperms.log.notify
|
||||
* /perms log userhistory \<user\> [page] - luckperms.log.userhistory
|
||||
* /perms log grouphistory \<group\> [page] - luckperms.log.grouphistory
|
||||
* /perms log trackhistory \<track\> [page] - luckperms.log.trackhistory
|
||||
|
||||
## License
|
||||
See LICENSE.md.
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.2</version>
|
||||
<version>2.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -40,8 +40,11 @@ public interface Datastore {
|
||||
|
||||
Async async();
|
||||
Sync sync();
|
||||
Future future();
|
||||
|
||||
interface Async {
|
||||
void logAction(LogEntry entry, Callback<Boolean> callback);
|
||||
void getLog(Callback<Log> callback);
|
||||
void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback);
|
||||
void loadUser(UUID uuid, Callback<Boolean> callback);
|
||||
void saveUser(User user, Callback<Boolean> callback);
|
||||
@ -60,6 +63,8 @@ public interface Datastore {
|
||||
}
|
||||
|
||||
interface Sync {
|
||||
boolean logAction(LogEntry entry);
|
||||
Log getLog();
|
||||
boolean loadOrCreateUser(UUID uuid, String username);
|
||||
boolean loadUser(UUID uuid);
|
||||
boolean saveUser(User user);
|
||||
@ -76,4 +81,24 @@ public interface Datastore {
|
||||
boolean saveUUIDData(String username, UUID uuid);
|
||||
UUID getUUID(String username);
|
||||
}
|
||||
|
||||
interface Future {
|
||||
java.util.concurrent.Future<Boolean> logAction(LogEntry entry);
|
||||
java.util.concurrent.Future<Log> getLog();
|
||||
java.util.concurrent.Future<Boolean> loadOrCreateUser(UUID uuid, String username);
|
||||
java.util.concurrent.Future<Boolean> loadUser(UUID uuid);
|
||||
java.util.concurrent.Future<Boolean> saveUser(User user);
|
||||
java.util.concurrent.Future<Boolean> createAndLoadGroup(String name);
|
||||
java.util.concurrent.Future<Boolean> loadGroup(String name);
|
||||
java.util.concurrent.Future<Boolean> loadAllGroups();
|
||||
java.util.concurrent.Future<Boolean> saveGroup(Group group);
|
||||
java.util.concurrent.Future<Boolean> deleteGroup(Group group);
|
||||
java.util.concurrent.Future<Boolean> createAndLoadTrack(String name);
|
||||
java.util.concurrent.Future<Boolean> loadTrack(String name);
|
||||
java.util.concurrent.Future<Boolean> loadAllTracks();
|
||||
java.util.concurrent.Future<Boolean> saveTrack(Track track);
|
||||
java.util.concurrent.Future<Boolean> deleteTrack(Track track);
|
||||
java.util.concurrent.Future<Boolean> saveUUIDData(String username, UUID uuid);
|
||||
java.util.concurrent.Future<UUID> getUUID(String username);
|
||||
}
|
||||
}
|
||||
|
64
api/src/main/java/me/lucko/luckperms/api/Log.java
Normal file
64
api/src/main/java/me/lucko/luckperms/api/Log.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents the internal LuckPerms log.
|
||||
* All content is immutable. You can add to the log using the {@link Datastore}, and then request an updated copy.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Log {
|
||||
|
||||
/**
|
||||
* @return a {@link SortedSet} of all of the {@link LogEntry} objects in this {@link Log}
|
||||
*/
|
||||
SortedSet<LogEntry> getContent();
|
||||
|
||||
SortedSet<LogEntry> getRecent();
|
||||
SortedMap<Integer, LogEntry> getRecent(int pageNo);
|
||||
int getRecentMaxPages();
|
||||
|
||||
SortedSet<LogEntry> getRecent(UUID actor);
|
||||
SortedMap<Integer, LogEntry> getRecent(int pageNo, UUID actor);
|
||||
int getRecentMaxPages(UUID actor);
|
||||
|
||||
SortedSet<LogEntry> getUserHistory(UUID uuid);
|
||||
SortedMap<Integer, LogEntry> getUserHistory(int pageNo, UUID uuid);
|
||||
int getUserHistoryMaxPages(UUID uuid);
|
||||
|
||||
SortedSet<LogEntry> getGroupHistory(String name);
|
||||
SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, String name);
|
||||
int getGroupHistoryMaxPages(String name);
|
||||
|
||||
SortedSet<LogEntry> getTrackHistory(String name);
|
||||
SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, String name);
|
||||
int getTrackHistoryMaxPages(String name);
|
||||
|
||||
SortedSet<LogEntry> getSearch(String query);
|
||||
SortedMap<Integer, LogEntry> getSearch(int pageNo, String query);
|
||||
int getSearchMaxPages(String query);
|
||||
}
|
64
api/src/main/java/me/lucko/luckperms/api/LogEntry.java
Normal file
64
api/src/main/java/me/lucko/luckperms/api/LogEntry.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public final class LogEntry implements Comparable<LogEntry> {
|
||||
private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s";
|
||||
|
||||
@NonNull private final long timestamp;
|
||||
@NonNull private final UUID actor;
|
||||
@NonNull private final String actorName;
|
||||
@NonNull private final char type;
|
||||
private final UUID acted;
|
||||
@NonNull private final String actedName;
|
||||
@NonNull private final String action;
|
||||
|
||||
@Override
|
||||
public int compareTo(LogEntry o) {
|
||||
return Long.compare(timestamp, o.getTimestamp());
|
||||
}
|
||||
|
||||
public boolean matchesSearch(String query) {
|
||||
query = query.toLowerCase();
|
||||
return actorName.toLowerCase().contains(query) || actedName.toLowerCase().contains(query)
|
||||
|| action.toLowerCase().contains(query);
|
||||
}
|
||||
|
||||
public String getFormatted() {
|
||||
return String.format(FORMAT,
|
||||
getActorName(),
|
||||
Character.toString(getType()),
|
||||
getActedName(),
|
||||
getAction()
|
||||
);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -82,7 +83,7 @@ public interface LuckPermsApi {
|
||||
/**
|
||||
* Gets a wrapped user object from the user storage
|
||||
* @param name the username of the user to get
|
||||
* @return a a {@link User} object, if one matching the uuid is loaded, or null if not
|
||||
* @return a {@link User} object, if one matching the uuid is loaded, or null if not
|
||||
*/
|
||||
User getUser(String name);
|
||||
|
||||
@ -93,6 +94,12 @@ public interface LuckPermsApi {
|
||||
*/
|
||||
Optional<User> getUserSafe(String name);
|
||||
|
||||
/**
|
||||
* Gets a set of all loaded users.
|
||||
* @return a {@link Set} of {@link User} objects
|
||||
*/
|
||||
Set<User> getUsers();
|
||||
|
||||
/**
|
||||
* Check if a user is loaded in memory
|
||||
* @param uuid the uuid to check for
|
||||
@ -114,6 +121,12 @@ public interface LuckPermsApi {
|
||||
*/
|
||||
Optional<Group> getGroupSafe(String name);
|
||||
|
||||
/**
|
||||
* Gets a set of all loaded groups.
|
||||
* @return a {@link Set} of {@link Group} objects
|
||||
*/
|
||||
Set<Group> getGroups();
|
||||
|
||||
/**
|
||||
* Check if a group is loaded in memory
|
||||
* @param name the name to check for
|
||||
@ -135,6 +148,12 @@ public interface LuckPermsApi {
|
||||
*/
|
||||
Optional<Track> getTrackSafe(String name);
|
||||
|
||||
/**
|
||||
* Gets a set of all loaded tracks.
|
||||
* @return a {@link Set} of {@link Track} objects
|
||||
*/
|
||||
Set<Track> getTracks();
|
||||
|
||||
/**
|
||||
* Check if a track is loaded in memory
|
||||
* @param name the name to check for
|
||||
|
@ -22,8 +22,24 @@
|
||||
|
||||
package me.lucko.luckperms.api.data;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface Callback<T> {
|
||||
|
||||
void onComplete(T t);
|
||||
|
||||
static <T> Callback<T> empty() {
|
||||
return t -> {};
|
||||
}
|
||||
|
||||
static <T> Callback<T> of(@NonNull Runnable runnable) {
|
||||
return t -> runnable.run();
|
||||
}
|
||||
|
||||
static <T> Callback<T> of(@NonNull Consumer<T> consumer) {
|
||||
return consumer::accept;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.2</version>
|
||||
<version>2.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.SenderFactory;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -33,33 +33,19 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class BukkitCommand extends CommandManager implements CommandExecutor, TabExecutor {
|
||||
private static final Factory FACTORY = new Factory();
|
||||
|
||||
BukkitCommand(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return onCommand(FACTORY.wrap(sender), label, Arrays.asList(args));
|
||||
onCommand(BukkitSenderFactory.get().wrap(sender), label, Arrays.asList(args), Callback.empty());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return onTabComplete(FACTORY.wrap(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
private static class Factory extends SenderFactory<CommandSender> {
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String s) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSender sender, String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
return onTabComplete(BukkitSenderFactory.get().wrap(sender), Arrays.asList(args));
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
|
@ -53,7 +53,7 @@ class BukkitListener extends AbstractListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
|
||||
if (user == null) {
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.toString());
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.lucko.luckperms.commands.SenderFactory;
|
||||
import me.lucko.luckperms.constants.Constants;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
||||
private static BukkitSenderFactory instance = null;
|
||||
public static BukkitSenderFactory get() {
|
||||
if (instance == null){
|
||||
instance = new BukkitSenderFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
return sender.getName();
|
||||
}
|
||||
return Constants.getConsoleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID getUuid(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
return ((Player) sender).getUniqueId();
|
||||
}
|
||||
return Constants.getConsoleUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String s) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSender sender, String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
}
|
@ -27,19 +27,20 @@ import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.api.vault.VaultHook;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.data.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.data.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.data.methods.SQLiteDatastore;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import me.lucko.luckperms.core.UuidCache;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.runnables.UpdateTask;
|
||||
import me.lucko.luckperms.storage.Datastore;
|
||||
import me.lucko.luckperms.storage.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.storage.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.storage.methods.SQLiteDatastore;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.BukkitUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.utils.LogUtil;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
import me.lucko.luckperms.utils.LogFactory;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -47,14 +48,12 @@ import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
private final Set<UUID> ignoringLogs = new HashSet<>();
|
||||
private LPConfiguration configuration;
|
||||
private UserManager userManager;
|
||||
private GroupManager groupManager;
|
||||
@ -65,7 +64,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log = LogUtil.wrap(getLogger());
|
||||
log = LogFactory.wrap(getLogger());
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new BukkitConfig(this);
|
||||
@ -121,6 +120,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new UpdateTask(this), ticks, ticks);
|
||||
}
|
||||
|
||||
getServer().getScheduler().runTaskTimer(this, BukkitSenderFactory.get(), 1L, 1L);
|
||||
|
||||
// Provide vault support
|
||||
getLog().info("Attempting to hook into Vault...");
|
||||
try {
|
||||
@ -183,6 +184,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
return getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sender> getSenders() {
|
||||
return getServer().getOnlinePlayers().stream().map(p -> BukkitSenderFactory.get().wrap(p)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPossiblePermissions() {
|
||||
final List<String> perms = new ArrayList<>();
|
||||
|
@ -25,11 +25,12 @@ package me.lucko.luckperms.api.vault;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.PermissionHolder;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
class VaultPermissionHook extends Permission {
|
||||
@ -95,54 +96,54 @@ class VaultPermissionHook extends Permission {
|
||||
private void objectSave(PermissionHolder t) {
|
||||
if (t instanceof User) {
|
||||
((User) t).refreshPermissions();
|
||||
plugin.getDatastore().saveUser(((User) t), aBoolean -> {});
|
||||
plugin.getDatastore().saveUser(((User) t), Callback.empty());
|
||||
}
|
||||
if (t instanceof Group) {
|
||||
plugin.getDatastore().saveGroup(((Group) t), aBoolean -> plugin.runUpdateTask());
|
||||
plugin.getDatastore().saveGroup(((Group) t), c -> plugin.runUpdateTask());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHas(String world, @NonNull String player, @NonNull String permission) {
|
||||
return objectHas(world, plugin.getUserManager().getUser(player), permission);
|
||||
return objectHas(world, plugin.getUserManager().get(player), permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAdd(String world, @NonNull String player, @NonNull String permission) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return objectAdd(world, user, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemove(String world, @NonNull String player, @NonNull String permission) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return objectRemove(world, user, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupHas(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
return objectHas(world, group, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupAdd(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
return objectAdd(world, group, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemove(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
return objectRemove(world, group, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, @NonNull String player, @NonNull String group) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group1 = plugin.getGroupManager().getGroup(group);
|
||||
final Group group1 = plugin.getGroupManager().get(group);
|
||||
if (group1 == null) return false;
|
||||
|
||||
if (world != null && !world.equals("")) {
|
||||
@ -154,10 +155,10 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
@ -173,10 +174,10 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
@ -192,7 +193,7 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, @NonNull String player) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return (user == null) ? new String[0] :
|
||||
world != null && !world.equals("") ? user.getLocalGroups("global", world).toArray(new String[0]) :
|
||||
user.getGroupNames().toArray(new String[0]);
|
||||
@ -200,13 +201,13 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(String world, @NonNull String player) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return (user == null) ? null : user.getPrimaryGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return plugin.getGroupManager().getGroups().keySet().toArray(new String[0]);
|
||||
return plugin.getGroupManager().getAll().keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,7 +38,7 @@ public class BukkitUserManager extends UserManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadUser(User user) {
|
||||
public void unload(User user) {
|
||||
if (user != null) {
|
||||
|
||||
if (user instanceof BukkitUser) {
|
||||
@ -54,24 +54,24 @@ public class BukkitUserManager extends UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
getUsers().remove(user.getUuid());
|
||||
getAll().remove(user.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(User user) {
|
||||
public void cleanup(User user) {
|
||||
if (plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())) == null) {
|
||||
unloadUser(user);
|
||||
unload(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User makeUser(UUID uuid) {
|
||||
public User make(UUID uuid) {
|
||||
return new BukkitUser(uuid, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User makeUser(UUID uuid, String username) {
|
||||
public User make(UUID uuid, String username) {
|
||||
return new BukkitUser(uuid, username, plugin);
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,13 @@ permissions:
|
||||
luckperms.track.insert: true
|
||||
luckperms.track.remove: true
|
||||
luckperms.track.clear: true
|
||||
luckperms.log.export: true
|
||||
luckperms.log.userhistory: true
|
||||
luckperms.log.grouphistory: true
|
||||
luckperms.log.trackhistory: true
|
||||
luckperms.log.notify: true
|
||||
luckperms.log.recent: true
|
||||
luckperms.log.search: true
|
||||
luckperms.user.*:
|
||||
description: Gives access to all LuckPerms user commands
|
||||
children:
|
||||
@ -105,4 +112,14 @@ permissions:
|
||||
luckperms.track.append: true
|
||||
luckperms.track.insert: true
|
||||
luckperms.track.remove: true
|
||||
luckperms.track.clear: true
|
||||
luckperms.track.clear: true
|
||||
luckperms.log.*:
|
||||
description: Gives access to all LuckPerms log commands
|
||||
children:
|
||||
luckperms.log.export: true
|
||||
luckperms.log.userhistory: true
|
||||
luckperms.log.grouphistory: true
|
||||
luckperms.log.trackhistory: true
|
||||
luckperms.log.notify: true
|
||||
luckperms.log.recent: true
|
||||
luckperms.log.search: true
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.2</version>
|
||||
<version>2.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -22,44 +22,29 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.SenderFactory;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
class BungeeCommand extends Command implements TabExecutor {
|
||||
private static final Factory FACTORY = new Factory();
|
||||
private final CommandManager manager;
|
||||
|
||||
public BungeeCommand(CommandManager manager) {
|
||||
BungeeCommand(CommandManager manager) {
|
||||
super("luckpermsbungee", null, "bperms", "lpb", "bpermissions", "bp", "bperm");
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
manager.onCommand(FACTORY.wrap(sender), "bperms", Arrays.asList(args));
|
||||
manager.onCommand(BungeeSenderFactory.get().wrap(sender), "bperms", Arrays.asList(args), Callback.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return manager.onTabComplete(FACTORY.wrap(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
private static class Factory extends SenderFactory<CommandSender> {
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String s) {
|
||||
sender.sendMessage(new TextComponent(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSender sender, String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
return manager.onTabComplete(BungeeSenderFactory.get().wrap(sender), Arrays.asList(args));
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
@ -23,9 +23,9 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.core.UuidCache;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.AbstractListener;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -55,7 +55,7 @@ class BungeeListener extends AbstractListener implements Listener {
|
||||
}
|
||||
|
||||
final ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
|
||||
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
if (user == null) return;
|
||||
|
||||
|
||||
@ -110,7 +110,7 @@ class BungeeListener extends AbstractListener implements Listener {
|
||||
final ProxiedPlayer player = e.getPlayer();
|
||||
final WeakReference<ProxiedPlayer> p = new WeakReference<>(player);
|
||||
|
||||
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
if (user == null) {
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
final ProxiedPlayer pl = p.get();
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.lucko.luckperms.commands.SenderFactory;
|
||||
import me.lucko.luckperms.constants.Constants;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class BungeeSenderFactory extends SenderFactory<CommandSender> {
|
||||
private static BungeeSenderFactory instance = null;
|
||||
public static BungeeSenderFactory get() {
|
||||
if (instance == null){
|
||||
instance = new BungeeSenderFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(CommandSender sender) {
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
return sender.getName();
|
||||
}
|
||||
return Constants.getConsoleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID getUuid(CommandSender sender) {
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
return ((ProxiedPlayer) sender).getUniqueId();
|
||||
}
|
||||
return Constants.getConsoleUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String s) {
|
||||
sender.sendMessage(new TextComponent(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSender sender, String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
}
|
@ -26,29 +26,29 @@ import lombok.Getter;
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.data.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.data.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import me.lucko.luckperms.core.UuidCache;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.runnables.UpdateTask;
|
||||
import me.lucko.luckperms.storage.Datastore;
|
||||
import me.lucko.luckperms.storage.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.storage.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.BungeeUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.utils.LogUtil;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
import me.lucko.luckperms.utils.LogFactory;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
private final Set<UUID> ignoringLogs = new HashSet<>();
|
||||
private LPConfiguration configuration;
|
||||
private UserManager userManager;
|
||||
private GroupManager groupManager;
|
||||
@ -59,7 +59,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log = LogUtil.wrap(getLogger());
|
||||
log = LogFactory.wrap(getLogger());
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new BungeeConfig(this);
|
||||
@ -109,6 +109,9 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
getProxy().getScheduler().schedule(this, new UpdateTask(this), mins, mins, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
// 20 times per second (once per "tick")
|
||||
getProxy().getScheduler().schedule(this, BungeeSenderFactory.get(), 50L, 50L, TimeUnit.MILLISECONDS);
|
||||
|
||||
getLog().info("Registering API...");
|
||||
LuckPerms.registerProvider(new ApiProvider(this));
|
||||
|
||||
@ -144,6 +147,11 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
return getProxy().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sender> getSenders() {
|
||||
return getProxy().getPlayers().stream().map(p -> BungeeSenderFactory.get().wrap(p)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPossiblePermissions() {
|
||||
// No such thing on Bungee. Wildcards are processed in the listener instead.
|
||||
|
@ -35,28 +35,28 @@ public class BungeeUserManager extends UserManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadUser(User user) {
|
||||
public void unload(User user) {
|
||||
if (user != null) {
|
||||
// Cannot clear the ProxiedPlayer's permission map, they're leaving so that will get GCed anyway
|
||||
// Calling getPermissions.clear() throws an UnsupportedOperationException
|
||||
getUsers().remove(user.getUuid());
|
||||
getAll().remove(user.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(User user) {
|
||||
public void cleanup(User user) {
|
||||
if (plugin.getProxy().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())) == null) {
|
||||
unloadUser(user);
|
||||
unload(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User makeUser(UUID uuid) {
|
||||
public User make(UUID uuid) {
|
||||
return new BungeeUser(uuid, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User makeUser(UUID uuid, String username) {
|
||||
public User make(UUID uuid, String username) {
|
||||
return new BungeeUser(uuid, username, plugin);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.2</version>
|
||||
<version>2.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -53,6 +53,13 @@
|
||||
<version>2.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- guava -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -23,15 +23,17 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import me.lucko.luckperms.core.UuidCache;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.storage.Datastore;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -106,12 +108,24 @@ public interface LuckPermsPlugin {
|
||||
*/
|
||||
List<String> getPlayerList();
|
||||
|
||||
/**
|
||||
* Gets a list of all Senders online on the platform
|
||||
* @return a {@link List} of senders
|
||||
*/
|
||||
List<Sender> getSenders();
|
||||
|
||||
/**
|
||||
* Gets all possible permission nodes, used for resolving wildcards
|
||||
* @return a {@link List} of permission nodes
|
||||
*/
|
||||
List<String> getPossiblePermissions();
|
||||
|
||||
/**
|
||||
* Gets a set of players ignoring logging output
|
||||
* @return a {@link Set} of uuids
|
||||
*/
|
||||
Set<UUID> getIgnoringLogs();
|
||||
|
||||
/**
|
||||
* Runs an update task
|
||||
*/
|
||||
|
@ -29,7 +29,9 @@ import me.lucko.luckperms.api.*;
|
||||
import me.lucko.luckperms.api.implementation.internal.*;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Provides static access to LuckPerms
|
||||
@ -70,7 +72,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull UUID uuid) {
|
||||
final me.lucko.luckperms.users.User user = plugin.getUserManager().getUser(uuid);
|
||||
final me.lucko.luckperms.users.User user = plugin.getUserManager().get(uuid);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
@ -85,7 +87,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull String name) {
|
||||
final me.lucko.luckperms.users.User user = plugin.getUserManager().getUser(name);
|
||||
final me.lucko.luckperms.users.User user = plugin.getUserManager().get(name);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
@ -98,6 +100,11 @@ public class ApiProvider implements LuckPermsApi {
|
||||
return Optional.ofNullable(getUser(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<User> getUsers() {
|
||||
return plugin.getUserManager().getAll().values().stream().map(UserLink::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserLoaded(@NonNull UUID uuid) {
|
||||
return plugin.getUserManager().isLoaded(uuid);
|
||||
@ -105,7 +112,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public Group getGroup(@NonNull String name) {
|
||||
final me.lucko.luckperms.groups.Group group = plugin.getGroupManager().getGroup(name);
|
||||
final me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(name);
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
@ -118,6 +125,11 @@ public class ApiProvider implements LuckPermsApi {
|
||||
return Optional.ofNullable(getGroup(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Group> getGroups() {
|
||||
return plugin.getGroupManager().getAll().values().stream().map(GroupLink::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGroupLoaded(@NonNull String name) {
|
||||
return plugin.getGroupManager().isLoaded(name);
|
||||
@ -125,7 +137,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public Track getTrack(@NonNull String name) {
|
||||
final me.lucko.luckperms.tracks.Track track = plugin.getTrackManager().getTrack(name);
|
||||
final me.lucko.luckperms.tracks.Track track = plugin.getTrackManager().get(name);
|
||||
if (track == null) {
|
||||
return null;
|
||||
}
|
||||
@ -138,6 +150,11 @@ public class ApiProvider implements LuckPermsApi {
|
||||
return Optional.ofNullable(getTrack(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Track> getTracks() {
|
||||
return plugin.getTrackManager().getAll().values().stream().map(TrackLink::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrackLoaded(@NonNull String name) {
|
||||
return plugin.getTrackManager().isLoaded(name);
|
||||
|
@ -22,41 +22,45 @@
|
||||
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Datastore;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.*;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static me.lucko.luckperms.api.implementation.internal.Utils.*;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link Datastore} and {@link me.lucko.luckperms.data.Datastore}
|
||||
* Provides a link between {@link Datastore} and {@link me.lucko.luckperms.storage.Datastore}
|
||||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class DatastoreLink implements Datastore {
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final me.lucko.luckperms.data.Datastore master;
|
||||
private final me.lucko.luckperms.storage.Datastore master;
|
||||
private final Async async;
|
||||
private final Sync sync;
|
||||
private final Future future;
|
||||
|
||||
public DatastoreLink(@NonNull LuckPermsPlugin plugin, @NonNull me.lucko.luckperms.data.Datastore master) {
|
||||
public DatastoreLink(@NonNull LuckPermsPlugin plugin, @NonNull me.lucko.luckperms.storage.Datastore master) {
|
||||
this.plugin = plugin;
|
||||
this.master = master;
|
||||
this.async = new Async(master);
|
||||
this.sync = new Sync(master);
|
||||
this.future = new Future(master);
|
||||
}
|
||||
|
||||
private static <T> Callback<T> checkCallback(Callback<T> c) {
|
||||
// If no callback was given, just send an empty one
|
||||
if (c == null) {
|
||||
c = t -> {};
|
||||
c = Callback.empty();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@ -72,18 +76,33 @@ public class DatastoreLink implements Datastore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Async async() {
|
||||
public Datastore.Async async() {
|
||||
return async;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sync sync() {
|
||||
public Datastore.Sync sync() {
|
||||
return sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Datastore.Future future() {
|
||||
return future;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Async implements Datastore.Async {
|
||||
private final me.lucko.luckperms.data.Datastore master;
|
||||
private final me.lucko.luckperms.storage.Datastore master;
|
||||
|
||||
@Override
|
||||
public void logAction(@NonNull LogEntry entry, Callback<Boolean> callback) {
|
||||
master.logAction(entry, checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getLog(Callback<Log> callback) {
|
||||
master.getLog(log -> callback.onComplete(new LogLink(log)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback<Boolean> callback) {
|
||||
@ -171,7 +190,17 @@ public class DatastoreLink implements Datastore {
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Sync implements Datastore.Sync {
|
||||
private final me.lucko.luckperms.data.Datastore master;
|
||||
private final me.lucko.luckperms.storage.Datastore master;
|
||||
|
||||
@Override
|
||||
public boolean logAction(@NonNull LogEntry entry) {
|
||||
return master.logAction(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Log getLog() {
|
||||
return new LogLink(master.getLog());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) {
|
||||
@ -257,4 +286,179 @@ public class DatastoreLink implements Datastore {
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Future implements Datastore.Future {
|
||||
private final me.lucko.luckperms.storage.Datastore master;
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> logAction(@NonNull LogEntry entry) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.logAction(entry, lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Log> getLog() {
|
||||
LPFuture<Log> lpf = new LPFuture<>();
|
||||
master.getLog(log -> lpf.onComplete(new LogLink(log)));
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadOrCreateUser(uuid, checkUsername(username), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadUser(@NonNull UUID uuid) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadUser(uuid, lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> saveUser(@NonNull User user) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
checkUser(user);
|
||||
master.saveUser(((UserLink) user).getMaster(), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> createAndLoadGroup(@NonNull String name) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.createAndLoadGroup(checkName(name), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadGroup(@NonNull String name) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadGroup(checkName(name), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadAllGroups() {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadAllGroups(lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> saveGroup(@NonNull Group group) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
checkGroup(group);
|
||||
master.saveGroup(((GroupLink) group).getMaster(), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> deleteGroup(@NonNull Group group) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
checkGroup(group);
|
||||
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
|
||||
throw new IllegalArgumentException("Cannot delete the default group.");
|
||||
}
|
||||
master.deleteGroup(((GroupLink) group).getMaster(), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> createAndLoadTrack(@NonNull String name) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.createAndLoadTrack(checkName(name), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadTrack(@NonNull String name) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadTrack(checkName(name), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadAllTracks() {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadAllTracks(lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> saveTrack(@NonNull Track track) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
checkTrack(track);
|
||||
master.saveTrack(((TrackLink) track).getMaster(), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> deleteTrack(@NonNull Track track) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
checkTrack(track);
|
||||
master.deleteTrack(((TrackLink) track).getMaster(), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.saveUUIDData(checkUsername(username), uuid, lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<UUID> getUUID(@NonNull String username) {
|
||||
LPFuture<UUID> lpf = new LPFuture<>();
|
||||
master.getUUID(checkUsername(username), lpf);
|
||||
return lpf;
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public static class LPFuture<T> implements Callback<T>, java.util.concurrent.Future<T> {
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
private T value;
|
||||
|
||||
@Override
|
||||
public void onComplete(T t) {
|
||||
value = t;
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
// Not supported
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return latch.getCount() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() throws InterruptedException {
|
||||
latch.await();
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
|
||||
if (latch.await(timeout, unit)) {
|
||||
return value;
|
||||
} else {
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
@ -36,20 +37,20 @@ import static me.lucko.luckperms.api.implementation.internal.Utils.*;
|
||||
/**
|
||||
* Provides a link between {@link Group} and {@link me.lucko.luckperms.groups.Group}
|
||||
*/
|
||||
@EqualsAndHashCode(of = {"name"}, callSuper = false)
|
||||
@SuppressWarnings("unused")
|
||||
public class GroupLink extends PermissionHolderLink implements Group {
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.groups.Group master;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
public GroupLink(@NonNull me.lucko.luckperms.groups.Group master) {
|
||||
super(master);
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return master.getName();
|
||||
this.name = master.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,11 +27,11 @@ import me.lucko.luckperms.api.LPConfiguration;
|
||||
import me.lucko.luckperms.api.data.MySQLConfiguration;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link LPConfiguration} and {@link me.lucko.luckperms.utils.LPConfiguration}
|
||||
* Provides a link between {@link LPConfiguration} and {@link me.lucko.luckperms.core.LPConfiguration}
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class LPConfigurationLink implements LPConfiguration {
|
||||
private final me.lucko.luckperms.utils.LPConfiguration master;
|
||||
private final me.lucko.luckperms.core.LPConfiguration master;
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
|
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Log;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import static me.lucko.luckperms.api.implementation.internal.Utils.checkName;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link Log} and {@link me.lucko.luckperms.data.Log}
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class LogLink implements Log {
|
||||
private final me.lucko.luckperms.data.Log master;
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getContent() {
|
||||
return master.getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent() {
|
||||
return master.getRecent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo) {
|
||||
return master.getRecent(pageNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecentMaxPages() {
|
||||
return master.getRecentMaxPages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent(@NonNull UUID actor) {
|
||||
return master.getRecent(actor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo, @NonNull UUID actor) {
|
||||
return master.getRecent(pageNo, actor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecentMaxPages(@NonNull UUID actor) {
|
||||
return master.getRecentMaxPages(actor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getUserHistory(@NonNull UUID uuid) {
|
||||
return master.getUserHistory(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @NonNull UUID uuid) {
|
||||
return master.getUserHistory(pageNo, uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserHistoryMaxPages(@NonNull UUID uuid) {
|
||||
return master.getUserHistoryMaxPages(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getGroupHistory(@NonNull String name) {
|
||||
return master.getGroupHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, @NonNull String name) {
|
||||
return master.getGroupHistory(pageNo, checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupHistoryMaxPages(@NonNull String name) {
|
||||
return master.getGroupHistoryMaxPages(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getTrackHistory(@NonNull String name) {
|
||||
return master.getTrackHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, @NonNull String name) {
|
||||
return master.getTrackHistory(pageNo, checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrackHistoryMaxPages(@NonNull String name) {
|
||||
return master.getTrackHistoryMaxPages(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getSearch(@NonNull String query) {
|
||||
return master.getSearch(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getSearch(int pageNo, @NonNull String query) {
|
||||
return master.getSearch(pageNo, query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchMaxPages(@NonNull String query) {
|
||||
return master.getSearchMaxPages(query);
|
||||
}
|
||||
}
|
@ -36,14 +36,14 @@ import java.util.Map;
|
||||
import static me.lucko.luckperms.api.implementation.internal.Utils.*;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link PermissionHolder} and {@link me.lucko.luckperms.utils.PermissionHolder}
|
||||
* Provides a link between {@link PermissionHolder} and {@link me.lucko.luckperms.core.PermissionHolder}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class PermissionHolderLink implements PermissionHolder {
|
||||
|
||||
@NonNull
|
||||
private final me.lucko.luckperms.utils.PermissionHolder master;
|
||||
private final me.lucko.luckperms.core.PermissionHolder master;
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
|
@ -23,7 +23,7 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
@ -38,17 +38,19 @@ import static me.lucko.luckperms.api.implementation.internal.Utils.checkGroup;
|
||||
/**
|
||||
* Provides a link between {@link Track} and {@link me.lucko.luckperms.tracks.Track}
|
||||
*/
|
||||
@EqualsAndHashCode(of = {"name"})
|
||||
@SuppressWarnings("unused")
|
||||
@AllArgsConstructor
|
||||
public class TrackLink implements Track {
|
||||
|
||||
@NonNull
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.tracks.Track master;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return master.getName();
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
public TrackLink(@NonNull me.lucko.luckperms.tracks.Track master) {
|
||||
this.master = master;
|
||||
this.name = master.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
@ -38,20 +39,20 @@ import static me.lucko.luckperms.api.implementation.internal.Utils.*;
|
||||
/**
|
||||
* Provides a link between {@link User} and {@link me.lucko.luckperms.users.User}
|
||||
*/
|
||||
@EqualsAndHashCode(of = {"uuid"}, callSuper = false)
|
||||
@SuppressWarnings("unused")
|
||||
public class UserLink extends PermissionHolderLink implements User {
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.users.User master;
|
||||
|
||||
@Getter
|
||||
private final UUID uuid;
|
||||
|
||||
public UserLink(@NonNull me.lucko.luckperms.users.User master) {
|
||||
super(master);
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return master.getUuid();
|
||||
this.uuid = master.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ class Utils {
|
||||
}
|
||||
|
||||
static String checkUsername(String s) {
|
||||
if (!ArgumentChecker.checkUsername(s)) {
|
||||
if (ArgumentChecker.checkUsername(s)) {
|
||||
throw new IllegalArgumentException("Invalid username entry '" + s + "'. Usernames must be less than 16 chars" +
|
||||
" and only contain 'a-z A-Z 1-9 _'.");
|
||||
}
|
||||
@ -58,7 +58,7 @@ class Utils {
|
||||
}
|
||||
|
||||
static String checkName(String s) {
|
||||
if (!ArgumentChecker.checkName(s)) {
|
||||
if (ArgumentChecker.checkName(s)) {
|
||||
throw new IllegalArgumentException("Invalid name entry '" + s + "'. Names must be less than 37 chars" +
|
||||
" and only contain 'a-z A-Z 1-9'.");
|
||||
}
|
||||
@ -66,21 +66,21 @@ class Utils {
|
||||
}
|
||||
|
||||
static String checkServer(String s) {
|
||||
if (!ArgumentChecker.checkServer(s)) {
|
||||
if (ArgumentChecker.checkServer(s)) {
|
||||
throw new IllegalArgumentException("Invalid server entry '" + s + "'. Server names can only contain alphanumeric characters.");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static String checkNode(String s) {
|
||||
if (!ArgumentChecker.checkNode(s)) {
|
||||
if (ArgumentChecker.checkNode(s)) {
|
||||
throw new IllegalArgumentException("Invalid node entry '" + s + "'. Nodes cannot contain '/' or '$' characters.");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static long checkTime(long l) {
|
||||
if (!ArgumentChecker.checkTime(l)) {
|
||||
if (ArgumentChecker.checkTime(l)) {
|
||||
throw new IllegalArgumentException("Unix time '" + l + "' is invalid, as it has already passed.");
|
||||
}
|
||||
return l;
|
||||
|
@ -28,11 +28,11 @@ import me.lucko.luckperms.api.UuidCache;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link UuidCache} and {@link me.lucko.luckperms.utils.UuidCache}
|
||||
* Provides a link between {@link UuidCache} and {@link me.lucko.luckperms.core.UuidCache}
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class UuidCacheLink implements UuidCache {
|
||||
private final me.lucko.luckperms.utils.UuidCache master;
|
||||
private final me.lucko.luckperms.core.UuidCache master;
|
||||
|
||||
@Override
|
||||
public UUID getUUID(UUID external) {
|
||||
|
@ -22,13 +22,16 @@
|
||||
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.group.CreateGroup;
|
||||
import me.lucko.luckperms.commands.group.DeleteGroup;
|
||||
import me.lucko.luckperms.commands.group.GroupMainCommand;
|
||||
import me.lucko.luckperms.commands.group.ListGroups;
|
||||
import me.lucko.luckperms.commands.group.subcommands.*;
|
||||
import me.lucko.luckperms.commands.log.LogMainCommand;
|
||||
import me.lucko.luckperms.commands.misc.DebugCommand;
|
||||
import me.lucko.luckperms.commands.misc.InfoCommand;
|
||||
import me.lucko.luckperms.commands.misc.SyncCommand;
|
||||
@ -36,9 +39,7 @@ import me.lucko.luckperms.commands.track.CreateTrack;
|
||||
import me.lucko.luckperms.commands.track.DeleteTrack;
|
||||
import me.lucko.luckperms.commands.track.ListTracks;
|
||||
import me.lucko.luckperms.commands.track.TrackMainCommand;
|
||||
import me.lucko.luckperms.commands.track.subcommands.*;
|
||||
import me.lucko.luckperms.commands.user.UserMainCommand;
|
||||
import me.lucko.luckperms.commands.user.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -47,71 +48,41 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class CommandManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
@Getter
|
||||
private final List<MainCommand> mainCommands = new ArrayList<>();
|
||||
private final List<MainCommand> mainCommands = ImmutableList.<MainCommand>builder()
|
||||
.add(new UserMainCommand())
|
||||
.add(new GroupMainCommand())
|
||||
.add(new TrackMainCommand())
|
||||
.add(new LogMainCommand())
|
||||
.add(new SyncCommand())
|
||||
.add(new InfoCommand())
|
||||
.add(new DebugCommand())
|
||||
.add(new CreateGroup())
|
||||
.add(new DeleteGroup())
|
||||
.add(new ListGroups())
|
||||
.add(new CreateTrack())
|
||||
.add(new DeleteTrack())
|
||||
.add(new ListTracks())
|
||||
.build();
|
||||
|
||||
public CommandManager(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
UserMainCommand userCommand = new UserMainCommand();
|
||||
this.registerMainCommand(userCommand);
|
||||
userCommand.registerSubCommand(new UserInfo());
|
||||
userCommand.registerSubCommand(new UserGetUUID());
|
||||
userCommand.registerSubCommand(new UserListNodes());
|
||||
userCommand.registerSubCommand(new UserHasPerm());
|
||||
userCommand.registerSubCommand(new UserInheritsPerm());
|
||||
userCommand.registerSubCommand(new UserSetPermission());
|
||||
userCommand.registerSubCommand(new UserUnSetPermission());
|
||||
userCommand.registerSubCommand(new UserAddGroup());
|
||||
userCommand.registerSubCommand(new UserRemoveGroup());
|
||||
userCommand.registerSubCommand(new UserSetTempPermission());
|
||||
userCommand.registerSubCommand(new UserUnsetTempPermission());
|
||||
userCommand.registerSubCommand(new UserAddTempGroup());
|
||||
userCommand.registerSubCommand(new UserRemoveTempGroup());
|
||||
userCommand.registerSubCommand(new UserSetPrimaryGroup());
|
||||
userCommand.registerSubCommand(new UserShowTracks());
|
||||
userCommand.registerSubCommand(new UserPromote());
|
||||
userCommand.registerSubCommand(new UserDemote());
|
||||
userCommand.registerSubCommand(new UserShowPos());
|
||||
userCommand.registerSubCommand(new UserClear());
|
||||
|
||||
GroupMainCommand groupCommand = new GroupMainCommand();
|
||||
this.registerMainCommand(groupCommand);
|
||||
groupCommand.registerSubCommand(new GroupInfo());
|
||||
groupCommand.registerSubCommand(new GroupListNodes());
|
||||
groupCommand.registerSubCommand(new GroupHasPerm());
|
||||
groupCommand.registerSubCommand(new GroupInheritsPerm());
|
||||
groupCommand.registerSubCommand(new GroupSetPermission());
|
||||
groupCommand.registerSubCommand(new GroupUnSetPermission());
|
||||
groupCommand.registerSubCommand(new GroupSetInherit());
|
||||
groupCommand.registerSubCommand(new GroupUnsetInherit());
|
||||
groupCommand.registerSubCommand(new GroupSetTempPermission());
|
||||
groupCommand.registerSubCommand(new GroupUnsetTempPermission());
|
||||
groupCommand.registerSubCommand(new GroupSetTempInherit());
|
||||
groupCommand.registerSubCommand(new GroupUnsetTempInherit());
|
||||
groupCommand.registerSubCommand(new GroupShowTracks());
|
||||
groupCommand.registerSubCommand(new GroupClear());
|
||||
|
||||
TrackMainCommand trackCommand = new TrackMainCommand();
|
||||
this.registerMainCommand(trackCommand);
|
||||
trackCommand.registerSubCommand(new TrackInfo());
|
||||
trackCommand.registerSubCommand(new TrackAppend());
|
||||
trackCommand.registerSubCommand(new TrackInsert());
|
||||
trackCommand.registerSubCommand(new TrackRemove());
|
||||
trackCommand.registerSubCommand(new TrackClear());
|
||||
|
||||
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());
|
||||
/**
|
||||
* Generic on command method to be called from the command executor object of the platform
|
||||
* Unlike {@link #onCommand(Sender, String, List)}, this method is called in a new thread
|
||||
* @param sender who sent the command
|
||||
* @param label the command label used
|
||||
* @param args the arguments provided
|
||||
* @param result the callback to be called when the command has fully executed
|
||||
*/
|
||||
public void onCommand(Sender sender, String label, List<String> args, Callback<CommandResult> result) {
|
||||
plugin.doAsync(() -> {
|
||||
CommandResult r = onCommand(sender, label, args);
|
||||
plugin.doSync(() -> result.onComplete(r));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,38 +92,48 @@ public class CommandManager {
|
||||
* @param args the arguments provided
|
||||
* @return if the command was successful
|
||||
*/
|
||||
public boolean onCommand(Sender sender, String label, List<String> args) {
|
||||
public CommandResult onCommand(Sender sender, String label, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
sendCommandUsage(sender, label);
|
||||
return true;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<MainCommand> o = mainCommands.stream().filter(m -> m.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny();
|
||||
Optional<MainCommand> o = mainCommands.stream()
|
||||
.filter(m -> m.getName().equalsIgnoreCase(args.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
sendCommandUsage(sender, label);
|
||||
return true;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final MainCommand main = o.get();
|
||||
if (!main.isAuthorized(sender)) {
|
||||
sendCommandUsage(sender, label);
|
||||
return true;
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (main.getRequiredArgsLength() == 0) {
|
||||
main.execute(plugin, sender, null, label);
|
||||
return true;
|
||||
try {
|
||||
return main.execute(plugin, sender, null, label);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
main.sendUsage(sender, label);
|
||||
return true;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
main.execute(plugin, sender, new ArrayList<>(args.subList(1, args.size())), label);
|
||||
return true;
|
||||
|
||||
try {
|
||||
return main.execute(plugin, sender, new ArrayList<>(args.subList(1, args.size())), label);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,11 +163,6 @@ public class CommandManager {
|
||||
return o.get().onTabComplete(sender, args.subList(1, args.size()), plugin);
|
||||
}
|
||||
|
||||
private void registerMainCommand(MainCommand command) {
|
||||
plugin.getLog().info("[CommandManager] Registered main command '" + command.getName() + "'");
|
||||
mainCommands.add(command);
|
||||
}
|
||||
|
||||
private void sendCommandUsage(Sender sender, String label) {
|
||||
Message.INFO_BRIEF.send(sender, plugin.getVersion());
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum CommandResult {
|
||||
SUCCESS(true),
|
||||
FAILURE(false),
|
||||
|
||||
LOADING_ERROR(false),
|
||||
STATE_ERROR(false),
|
||||
INVALID_ARGS(false),
|
||||
NO_PERMISSION(false);
|
||||
|
||||
private boolean booleanValue;
|
||||
|
||||
public boolean booleanValue() {
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
static CommandResult of(boolean b) {
|
||||
return b ? SUCCESS : FAILURE;
|
||||
}
|
||||
|
||||
}
|
@ -22,10 +22,10 @@
|
||||
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -35,7 +35,7 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public abstract class MainCommand<T> {
|
||||
|
||||
/**
|
||||
@ -57,7 +57,11 @@ public abstract class MainCommand<T> {
|
||||
* A list of the sub commands under this main command
|
||||
*/
|
||||
@Getter
|
||||
private final List<SubCommand<T>> subCommands = new ArrayList<>();
|
||||
private final List<SubCommand<T>> subCommands;
|
||||
|
||||
MainCommand(String name, String usage, int requiredArgsLength) {
|
||||
this(name, usage, requiredArgsLength, ImmutableList.of());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this main command is ran
|
||||
@ -66,37 +70,44 @@ public abstract class MainCommand<T> {
|
||||
* @param args the stripped arguments given
|
||||
* @param label the command label used
|
||||
*/
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() < 2) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() < requiredArgsLength) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<SubCommand<T>> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
|
||||
Optional<SubCommand<T>> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(requiredArgsLength - 1))).limit(1).findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final SubCommand<T> sub = o.get();
|
||||
if (!sub.isAuthorized(sender)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return;
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > 2) {
|
||||
strippedArgs.addAll(args.subList(2, args.size()));
|
||||
if (args.size() > requiredArgsLength) {
|
||||
strippedArgs.addAll(args.subList(requiredArgsLength, args.size()));
|
||||
}
|
||||
|
||||
if (sub.getIsArgumentInvalid().test(strippedArgs.size())) {
|
||||
sub.sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String name = args.get(0).toLowerCase();
|
||||
getTarget(name, plugin, sender, t -> sub.execute(plugin, sender, t, strippedArgs, label));
|
||||
T t = getTarget(name, plugin, sender);
|
||||
if (t != null) {
|
||||
CommandResult result = sub.execute(plugin, sender, t, strippedArgs, label);
|
||||
cleanup(t, plugin);
|
||||
return result;
|
||||
}
|
||||
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,9 +115,10 @@ public abstract class MainCommand<T> {
|
||||
* @param target the name of the object to be looked up
|
||||
* @param plugin a link to the main plugin instance
|
||||
* @param sender the user who send the command (used to send error messages if the lookup was unsuccessful)
|
||||
* @param onSuccess the callback to run when the lookup is completed
|
||||
*/
|
||||
protected abstract void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<T> onSuccess);
|
||||
protected abstract T getTarget(String target, LuckPermsPlugin plugin, Sender sender);
|
||||
|
||||
protected abstract void cleanup(T t, LuckPermsPlugin plugin);
|
||||
|
||||
/**
|
||||
* Get a list of objects for tab completion
|
||||
@ -174,10 +186,6 @@ public abstract class MainCommand<T> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return o.get().onTabComplete(sender, args.subList(2, args.size()), plugin);
|
||||
}
|
||||
|
||||
public void registerSubCommand(SubCommand<T> subCommand) {
|
||||
subCommands.add(subCommand);
|
||||
return o.get().onTabComplete(plugin, sender, args.subList(2, args.size()));
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
@UtilityClass
|
||||
public class Predicate {
|
||||
public static <T> java.util.function.Predicate<T> alwaysFalse() {
|
||||
|
@ -22,12 +22,18 @@
|
||||
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Wrapper class to represent a CommandSender in Bukkit/Bungee within the luckperms-common command implementations.
|
||||
* Wrapper interface to represent a CommandSender/CommandSource within the luckperms-common command implementations.
|
||||
*/
|
||||
public interface Sender {
|
||||
|
||||
String getName();
|
||||
UUID getUuid();
|
||||
void sendMessage(String s);
|
||||
boolean hasPermission(String node);
|
||||
boolean hasPermission(Permission permission);
|
||||
|
||||
}
|
||||
|
@ -22,31 +22,69 @@
|
||||
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class SenderFactory<T> {
|
||||
/**
|
||||
* Factory class to make a thread-safe sender instance
|
||||
* @param <T> the command sender type
|
||||
*/
|
||||
public abstract class SenderFactory<T> implements Runnable {
|
||||
// Ensures messages are sent in order, etc.
|
||||
private final List<Runnable> tasks = new ArrayList<>();
|
||||
|
||||
private final SenderFactory<T> factory = this;
|
||||
|
||||
protected abstract String getName(T t);
|
||||
protected abstract UUID getUuid(T t);
|
||||
protected abstract void sendMessage(T t, String s);
|
||||
protected abstract boolean hasPermission(T t, String node);
|
||||
|
||||
public Sender wrap(T t) {
|
||||
final SenderFactory<T> factory = this;
|
||||
public final Sender wrap(T t) {
|
||||
return new Sender() {
|
||||
final WeakReference<T> cs = new WeakReference<>(t);
|
||||
final WeakReference<T> tRef = new WeakReference<>(t);
|
||||
|
||||
// Cache these permissions, so they can be accessed async
|
||||
final Map<Permission, Boolean> perms = Arrays.stream(Permission.values())
|
||||
.map(p -> new AbstractMap.SimpleEntry<>(p, factory.hasPermission(t, p.getNode())))
|
||||
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
|
||||
|
||||
@Getter
|
||||
final String name = factory.getName(t);
|
||||
|
||||
@Getter
|
||||
final UUID uuid = factory.getUuid(t);
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final T c = cs.get();
|
||||
if (c != null) {
|
||||
factory.sendMessage(c, s);
|
||||
final T t = tRef.get();
|
||||
if (t != null) {
|
||||
synchronized (tasks) {
|
||||
tasks.add(() -> factory.sendMessage(t, s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
final T c = cs.get();
|
||||
return c != null && factory.hasPermission(c, node);
|
||||
public boolean hasPermission(Permission permission) {
|
||||
synchronized (perms) {
|
||||
return perms.get(permission);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
synchronized (tasks) {
|
||||
if (!tasks.isEmpty()) {
|
||||
tasks.forEach(Runnable::run);
|
||||
tasks.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -41,13 +40,19 @@ public class SingleMainCommand extends MainCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
// Do nothing, allow the implementation to override this
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback onSuccess) {
|
||||
// Do nothing, don't run callback
|
||||
protected Object getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup(Object o, LuckPermsPlugin plugin) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,7 +78,19 @@ public abstract class SubCommand<T> {
|
||||
* @param args the stripped arguments given
|
||||
* @param label the command label used
|
||||
*/
|
||||
public abstract void execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label);
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label);
|
||||
|
||||
/**
|
||||
* Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override
|
||||
* this method to give their own list.
|
||||
* @param plugin the plugin instance
|
||||
* @param sender who is tab completing
|
||||
* @param args the arguments so far
|
||||
* @return a list of suggestions
|
||||
*/
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the command usage to a sender
|
||||
@ -98,18 +110,6 @@ public abstract class SubCommand<T> {
|
||||
return permission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override
|
||||
* this method to give their own list.
|
||||
* @param sender who is tab completing
|
||||
* @param args the arguments so far
|
||||
* @param plugin the plugin instance
|
||||
* @return a list of suggestions
|
||||
*/
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------
|
||||
Utility methods used by #onTabComplete and #execute implementations in sub classes
|
||||
@ -117,11 +117,11 @@ public abstract class SubCommand<T> {
|
||||
*/
|
||||
|
||||
protected static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()), args);
|
||||
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getAll().keySet()), args);
|
||||
}
|
||||
|
||||
protected static List<String> getTrackTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getTrackManager().getTracks().keySet()), args);
|
||||
return getTabComplete(new ArrayList<>(plugin.getTrackManager().getAll().keySet()), args);
|
||||
}
|
||||
|
||||
protected static List<String> getBoolTabComplete(List<String> args) {
|
||||
@ -144,7 +144,7 @@ public abstract class SubCommand<T> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected static void saveUser(User user, Sender sender, LuckPermsPlugin plugin) {
|
||||
protected static void save(User user, Sender sender, LuckPermsPlugin plugin) {
|
||||
user.refreshPermissions();
|
||||
|
||||
plugin.getDatastore().saveUser(user, success -> {
|
||||
@ -156,7 +156,7 @@ public abstract class SubCommand<T> {
|
||||
});
|
||||
}
|
||||
|
||||
protected static void saveGroup(Group group, Sender sender, LuckPermsPlugin plugin) {
|
||||
protected static void save(Group group, Sender sender, LuckPermsPlugin plugin) {
|
||||
plugin.getDatastore().saveGroup(group, success -> {
|
||||
if (success) {
|
||||
Message.GROUP_SAVE_SUCCESS.send(sender);
|
||||
@ -168,7 +168,7 @@ public abstract class SubCommand<T> {
|
||||
});
|
||||
}
|
||||
|
||||
protected static void saveTrack(Track track, Sender sender, LuckPermsPlugin plugin) {
|
||||
protected static void save(Track track, Sender sender, LuckPermsPlugin plugin) {
|
||||
plugin.getDatastore().saveTrack(track, success -> {
|
||||
if (success) {
|
||||
Message.TRACK_SAVE_SUCCESS.send(sender);
|
||||
|
@ -24,6 +24,7 @@ package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
@ -55,12 +56,16 @@ public class Util {
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
public static String stripColor(String s) {
|
||||
return s == null ? null : Patterns.STRIP_COLOR_PATTERN.matcher(s).replaceAll("");
|
||||
}
|
||||
|
||||
public static String formatBoolean(boolean b) {
|
||||
return b ? "&atrue" : "&cfalse";
|
||||
}
|
||||
|
||||
public static void sendBoolean(Sender sender, String node, boolean b) {
|
||||
if (b) {
|
||||
sender.sendMessage(Util.color("&b" + node + ": &atrue"));
|
||||
} else {
|
||||
sender.sendMessage(Util.color("&b" + node + ": &cfalse"));
|
||||
}
|
||||
sender.sendMessage(Util.color("&b" + node + ": " + formatBoolean(b)));
|
||||
}
|
||||
|
||||
public static String listToCommaSep(List<String> strings) {
|
||||
|
@ -23,10 +23,12 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
@ -37,31 +39,31 @@ public class CreateGroup extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
if (!ArgumentChecker.checkName(groupName)) {
|
||||
if (ArgumentChecker.checkName(groupName)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (success) {
|
||||
Message.GROUP_ALREADY_EXISTS.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().createAndLoadGroup(groupName, success1 -> {
|
||||
if (!success1) {
|
||||
Message.CREATE_GROUP_ERROR.send(sender);
|
||||
} else {
|
||||
Message.CREATE_SUCCESS.send(sender, groupName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_ALREADY_EXISTS.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().createAndLoadGroup(groupName)) {
|
||||
Message.CREATE_GROUP_ERROR.send(sender);
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Message.CREATE_SUCCESS.send(sender, groupName);
|
||||
LogEntryBuilder.get().actor(sender).actedName(groupName).type('G').action("create").submit(plugin);
|
||||
plugin.runUpdateTask();
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,12 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
@ -41,49 +43,49 @@ public class DeleteGroup extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
|
||||
Message.DELETE_GROUP_ERROR_DEFAULT.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!ArgumentChecker.checkName(groupName)) {
|
||||
if (ArgumentChecker.checkName(groupName)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().deleteGroup(group, success1 -> {
|
||||
if (!success1) {
|
||||
Message.DELETE_GROUP_ERROR.send(sender);
|
||||
} else {
|
||||
Message.DELETE_SUCCESS.send(sender, groupName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Group group = plugin.getGroupManager().get(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().deleteGroup(group)) {
|
||||
Message.DELETE_GROUP_ERROR.send(sender);
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Message.DELETE_SUCCESS.send(sender, groupName);
|
||||
LogEntryBuilder.get().actor(sender).actedName(groupName).type('G').action("delete").submit(plugin);
|
||||
plugin.runUpdateTask();
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> groups = new ArrayList<>(plugin.getGroupManager().getGroups().keySet());
|
||||
final List<String> groups = new ArrayList<>(plugin.getGroupManager().getAll().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
|
@ -22,10 +22,12 @@
|
||||
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.group.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -35,34 +37,53 @@ import java.util.List;
|
||||
|
||||
public class GroupMainCommand extends MainCommand<Group> {
|
||||
public GroupMainCommand() {
|
||||
super("Group", "/%s group <group>", 2);
|
||||
super("Group", "/%s group <group>", 2, ImmutableList.<SubCommand<Group>>builder()
|
||||
.add(new GroupInfo())
|
||||
.add(new GroupListNodes())
|
||||
.add(new GroupHasPerm())
|
||||
.add(new GroupInheritsPerm())
|
||||
.add(new GroupSetPermission())
|
||||
.add(new GroupUnSetPermission())
|
||||
.add(new GroupSetInherit())
|
||||
.add(new GroupUnsetInherit())
|
||||
.add(new GroupSetTempPermission())
|
||||
.add(new GroupUnsetTempPermission())
|
||||
.add(new GroupSetTempInherit())
|
||||
.add(new GroupUnsetTempInherit())
|
||||
.add(new GroupShowTracks())
|
||||
.add(new GroupClear())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<Group> onSuccess) {
|
||||
if (!ArgumentChecker.checkName(target)) {
|
||||
protected Group getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
if (ArgumentChecker.checkName(target)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(target, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDatastore().loadGroup(target)) {
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
Group group = plugin.getGroupManager().getGroup(target);
|
||||
if (group == null) {
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
Group group = plugin.getGroupManager().get(target);
|
||||
|
||||
if (group == null) {
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup(Group group, LuckPermsPlugin plugin) {
|
||||
|
||||
onSuccess.onComplete(group);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getObjects(LuckPermsPlugin plugin) {
|
||||
return new ArrayList<>(plugin.getGroupManager().getGroups().keySet());
|
||||
return new ArrayList<>(plugin.getGroupManager().getAll().keySet());
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
@ -38,13 +39,13 @@ public class ListGroups extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
plugin.getDatastore().loadAllGroups(success -> {
|
||||
if (!success) {
|
||||
Message.GROUPS_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
Message.GROUPS_LIST.send(sender, Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getGroups().keySet())));
|
||||
}
|
||||
});
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (!plugin.getDatastore().loadAllGroups()) {
|
||||
Message.GROUPS_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
Message.GROUPS_LIST.send(sender, Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getAll().keySet())));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,10 +41,11 @@ public class GroupClear extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
group.clearNodes();
|
||||
Message.CLEAR_SUCCESS.send(sender, group.getName());
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
LogEntryBuilder.get().actor(sender).acted(group).action("clear").submit(plugin);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
@ -42,11 +39,11 @@ public class GroupHasPerm extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (args.size() >= 2) {
|
||||
if (!ArgumentChecker.checkServer(args.get(1))) {
|
||||
if (ArgumentChecker.checkServer(args.get(1))) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
@ -58,5 +55,6 @@ public class GroupHasPerm extends SubCommand<Group> {
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global"));
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
@ -39,8 +40,14 @@ public class GroupInfo extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
Message.GROUP_INFO.send(sender, group.getName(), group.getPermanentNodes().keySet().size(),
|
||||
group.getTemporaryNodes().keySet().size(), label, group.getName());
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
Message.GROUP_INFO.send(sender,
|
||||
group.getName(),
|
||||
group.getPermanentNodes().keySet().size(),
|
||||
group.getTemporaryNodes().keySet().size(),
|
||||
label,
|
||||
group.getName()
|
||||
);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
@ -42,11 +39,11 @@ public class GroupInheritsPerm extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (args.size() >= 2) {
|
||||
if (!ArgumentChecker.checkServer(args.get(1))) {
|
||||
if (ArgumentChecker.checkServer(args.get(1))) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
@ -58,5 +55,6 @@ public class GroupInheritsPerm extends SubCommand<Group> {
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true));
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
@ -40,8 +37,9 @@ public class GroupListNodes extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(group.getPermanentNodes()));
|
||||
Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getTemporaryNodes()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -42,50 +44,66 @@ public class GroupSetInherit extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.setPermission("group." + groupName, true, server);
|
||||
Message.GROUP_SETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.setPermission("group." + groupName, true, server, world);
|
||||
Message.GROUP_SETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
|
||||
}
|
||||
Group group1 = plugin.getGroupManager().get(groupName);
|
||||
if (group1 == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission("group." + groupName, true);
|
||||
Message.GROUP_SETINHERIT_SUCCESS.send(sender, group.getName(), groupName);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.GROUP_ALREADY_INHERITS.send(sender, group.getName(), groupName);
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.setInheritGroup(group1, server);
|
||||
Message.GROUP_SETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), group1.getName(), server);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("setinherit " + group1.getName() + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.setInheritGroup(group1, server, world);
|
||||
Message.GROUP_SETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), group1.getName(), server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("setinherit " + group1.getName() + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setInheritGroup(group1);
|
||||
Message.GROUP_SETINHERIT_SUCCESS.send(sender, group.getName(), group1.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("setinherit " + group1.getName())
|
||||
.submit(plugin);
|
||||
}
|
||||
});
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.GROUP_ALREADY_INHERITS.send(sender, group.getName(), group1.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,17 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -42,23 +44,23 @@ public class GroupSetPermission extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(node)) {
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_INHERIT.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
boolean b = Boolean.parseBoolean(bool);
|
||||
@ -66,33 +68,44 @@ public class GroupSetPermission extends SubCommand<Group> {
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission(node, b, server);
|
||||
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("set " + node + " " + b + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission(node, b, server, world);
|
||||
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("set " + node + " " + b + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, b);
|
||||
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("set " + node + " " + b)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HASPERMISSION.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -43,12 +45,12 @@ public class GroupSetTempInherit extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
long duration;
|
||||
@ -56,52 +58,68 @@ public class GroupSetTempInherit extends SubCommand<Group> {
|
||||
duration = DateUtil.parseDateDiff(args.get(1), true);
|
||||
} catch (DateUtil.IllegalDateException e) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(1));
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
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();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission("group." + groupName, true, server, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server,
|
||||
DateUtil.formatDateDiff(duration));
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission("group." + groupName, true, server, world, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server,
|
||||
world, DateUtil.formatDateDiff(duration));
|
||||
}
|
||||
Group group1 = plugin.getGroupManager().get(groupName);
|
||||
if (group1 == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
} 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);
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setInheritGroup(group1, server, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), group1.getName(), server,
|
||||
DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("settempinherit " + group1.getName() + " " + duration + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setInheritGroup(group1, server, world, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), group1.getName(), server,
|
||||
world, DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("settempinherit " + group1.getName() + " " + duration + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setInheritGroup(group1, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), group1.getName(), DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("settempinherit " + group1.getName() + " " + duration)
|
||||
.submit(plugin);
|
||||
}
|
||||
});
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.USER_ALREADY_TEMP_MEMBER_OF.send(sender, group.getName(), group1.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,16 +23,18 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -44,23 +46,23 @@ public class GroupSetTempPermission extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(node)) {
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_INHERIT.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
boolean b = Boolean.parseBoolean(bool);
|
||||
@ -70,46 +72,57 @@ public class GroupSetTempPermission extends SubCommand<Group> {
|
||||
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||
} catch (DateUtil.IllegalDateException e) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 4) {
|
||||
final String server = args.get(3).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
group.setPermission(node, b, server, duration);
|
||||
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server,
|
||||
DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("settemp " + node + " " + b + " " + duration + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
group.setPermission(node, b, server, world, duration);
|
||||
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server,
|
||||
world, DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("settemp " + node + " " + b + " " + duration + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, b, duration);
|
||||
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getName(), DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("settemp " + node + " " + b + " " + duration)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
@ -42,15 +39,19 @@ public class GroupShowTracks extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
plugin.getDatastore().loadAllTracks(success -> {
|
||||
if (!success) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return;
|
||||
}
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (!plugin.getDatastore().loadAllTracks()) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
Message.TRACKS_LIST.send(sender, Util.listToCommaSep(
|
||||
plugin.getTrackManager().getApplicableTracks(group.getName()).stream().map(Track::getName).collect(Collectors.toList())));
|
||||
});
|
||||
Message.TRACKS_LIST.send(sender,
|
||||
Util.listToCommaSep(plugin.getTrackManager().getApplicableTracks(group.getName()).stream()
|
||||
.map(Track::getName)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
);
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,17 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -42,44 +44,55 @@ public class GroupUnSetPermission extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
|
||||
if (!ArgumentChecker.checkNode(node)) {
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_UNINHERIT.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission(node, server);
|
||||
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unset " + node + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission(node, server, world);
|
||||
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unset " + node + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node);
|
||||
Message.UNSETPERMISSION_SUCCESS.send(sender, node, group.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unset " + node)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVEPERMISSION.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -42,44 +44,55 @@ public class GroupUnsetInherit extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission("group." + groupName, server);
|
||||
Message.GROUP_UNSETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsetinherit " + groupName + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission("group." + groupName, server, world);
|
||||
Message.GROUP_UNSETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsetinherit " + groupName + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission("group." + groupName);
|
||||
Message.GROUP_UNSETINHERIT_SUCCESS.send(sender, group.getName(), groupName);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsetinherit " + groupName)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.GROUP_DOES_NOT_INHERIT.send(sender, group.getName(), groupName);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -42,44 +44,55 @@ public class GroupUnsetTempInherit extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission("group." + groupName, server, true);
|
||||
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsettempinherit " + groupName + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission("group." + groupName, server, world, true);
|
||||
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsettempinherit " + groupName + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission("group." + groupName, true);
|
||||
Message.GROUP_UNSET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsettempinherit " + groupName)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.GROUP_DOES_NOT_TEMP_INHERIT.send(sender, group.getName(), groupName);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,17 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -43,44 +45,55 @@ public class GroupUnsetTempPermission extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
|
||||
if (!ArgumentChecker.checkNode(node)) {
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_UNINHERIT.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission(node, server);
|
||||
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsettemp " + node + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission(node, server, world);
|
||||
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsettemp " + node + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node, true);
|
||||
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(group)
|
||||
.action("unsettemp " + node)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.log.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LogMainCommand extends MainCommand<Log> {
|
||||
public LogMainCommand() {
|
||||
super("Log", "/%s log", 1, ImmutableList.<SubCommand<Log>>builder()
|
||||
.add(new LogRecent())
|
||||
.add(new LogSearch())
|
||||
.add(new LogNotify())
|
||||
// .add(new LogExport())
|
||||
.add(new LogUserHistory())
|
||||
.add(new LogGroupHistory())
|
||||
.add(new LogTrackHistory())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Log getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
Log log = plugin.getDatastore().getLog();
|
||||
|
||||
if (log == null) {
|
||||
Message.LOG_LOAD_ERROR.send(sender);
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup(Log log, LuckPermsPlugin plugin) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getObjects(LuckPermsPlugin plugin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<SubCommand<Log>> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return subs.stream().map(SubCommand::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return subs.stream().map(SubCommand::getName).map(String::toLowerCase)
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<SubCommand<Log>> o = subs.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny();
|
||||
if (!o.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return o.get().onTabComplete(plugin, sender, args.subList(1, args.size()));
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LogExport extends SubCommand<Log> {
|
||||
public LogExport() {
|
||||
super("export", "Export the log to a file", "/%s log export <file>", Permission.LOG_EXPORT, Predicate.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
// TODO: implement this
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public class LogGroupHistory extends SubCommand<Log> {
|
||||
public LogGroupHistory() {
|
||||
super("grouphistory", "View an objects history", "/%s log grouphistory <group> [page]", Permission.LOG_GROUP_HISTORY,
|
||||
Predicate.notInRange(1, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
String group = args.get(0);
|
||||
int page = -999;
|
||||
|
||||
if (args.size() == 2) {
|
||||
try {
|
||||
page = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
// invalid page
|
||||
Message.LOG_INVALID_PAGE.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
if (ArgumentChecker.checkName(group)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
int maxPage = log.getGroupHistoryMaxPages(group);
|
||||
if (maxPage == 0) {
|
||||
Message.LOG_NO_ENTRIES.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (page == -999) {
|
||||
page = maxPage;
|
||||
}
|
||||
|
||||
if (page < 1 || page > maxPage) {
|
||||
Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
SortedMap<Integer, LogEntry> entries = log.getGroupHistory(page, group);
|
||||
String name = entries.values().stream().findAny().get().getActedName();
|
||||
Message.LOG_HISTORY_GROUP_HEADER.send(sender, name, page, maxPage);
|
||||
|
||||
for (Map.Entry<Integer, LogEntry> e : entries.entrySet()) {
|
||||
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted());
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogNotify extends SubCommand<Log> {
|
||||
public LogNotify() {
|
||||
super("notify", "Toggle notifications", "/%s log notify [on|off]", Permission.LOG_NOTIFY,
|
||||
Predicate.notInRange(0, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
final Set<UUID> ignoring = plugin.getIgnoringLogs();
|
||||
final UUID uuid = sender.getUuid();
|
||||
if (args.size() == 0) {
|
||||
if (ignoring.contains(uuid)) {
|
||||
// toggle on
|
||||
ignoring.remove(uuid);
|
||||
Message.LOG_NOTIFY_TOGGLE_ON.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
// toggle off
|
||||
ignoring.add(uuid);
|
||||
Message.LOG_NOTIFY_TOGGLE_OFF.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("on")) {
|
||||
if (!ignoring.contains(uuid)) {
|
||||
// already on
|
||||
Message.LOG_NOTIFY_ALREADY_ON.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
// toggle on
|
||||
ignoring.remove(uuid);
|
||||
Message.LOG_NOTIFY_TOGGLE_ON.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("off")) {
|
||||
if (ignoring.contains(uuid)) {
|
||||
// already off
|
||||
Message.LOG_NOTIFY_ALREADY_OFF.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
// toggle off
|
||||
ignoring.add(uuid);
|
||||
Message.LOG_NOTIFY_TOGGLE_OFF.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
// not recognised
|
||||
Message.LOG_NOTIFY_UNKNOWN.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogRecent extends SubCommand<Log> {
|
||||
public LogRecent() {
|
||||
super("recent", "View recent actions", "/%s log recent [user] [page]", Permission.LOG_RECENT,
|
||||
Predicate.notInRange(0, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
// No page or user
|
||||
return showLog(log.getRecentMaxPages(), null, sender, log);
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
// Page or user
|
||||
try {
|
||||
int p = Integer.parseInt(args.get(0));
|
||||
// page
|
||||
return showLog(p, null, sender, log);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
|
||||
// User and possibly page
|
||||
final String s = args.get(0);
|
||||
UUID u = null;
|
||||
|
||||
u = Util.parseUuid(s);
|
||||
if (u == null) {
|
||||
if (s.length() <= 16) {
|
||||
if (Patterns.NON_USERNAME.matcher(s).find()) {
|
||||
Message.USER_INVALID_ENTRY.send(sender, s);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Message.USER_ATTEMPTING_LOOKUP.send(sender);
|
||||
|
||||
UUID uuid = plugin.getDatastore().getUUID(s);
|
||||
|
||||
if (uuid == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() != 2) {
|
||||
// Just user
|
||||
return showLog(log.getRecentMaxPages(uuid), uuid, sender, log);
|
||||
}
|
||||
|
||||
try {
|
||||
int p = Integer.parseInt(args.get(1));
|
||||
// User and page
|
||||
return showLog(p, uuid, sender, log);
|
||||
} catch (NumberFormatException e) {
|
||||
// Invalid page
|
||||
return showLog(-1, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
Message.USER_INVALID_ENTRY.send(sender, s);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() != 2) {
|
||||
// Just user
|
||||
return showLog(log.getRecentMaxPages(u), u, sender, log);
|
||||
} else {
|
||||
try {
|
||||
int p = Integer.parseInt(args.get(1));
|
||||
// User and page
|
||||
return showLog(p, u, sender, log);
|
||||
} catch (NumberFormatException e) {
|
||||
// Invalid page
|
||||
return showLog(-1, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static CommandResult showLog(int page, UUID filter, Sender sender, Log log) {
|
||||
int maxPage = (filter != null) ? log.getRecentMaxPages(filter) : log.getRecentMaxPages();
|
||||
if (maxPage == 0) {
|
||||
Message.LOG_NO_ENTRIES.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (page < 1 || page > maxPage) {
|
||||
Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
SortedMap<Integer, LogEntry> entries = (filter != null) ? log.getRecent(page, filter) : log.getRecent(page);
|
||||
if (filter != null) {
|
||||
String name = entries.values().stream().findAny().get().getActorName();
|
||||
Message.LOG_RECENT_BY_HEADER.send(sender, name, page, maxPage);
|
||||
} else {
|
||||
Message.LOG_RECENT_HEADER.send(sender, page, maxPage);
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, LogEntry> e : entries.entrySet()) {
|
||||
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted());
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LogSearch extends SubCommand<Log> {
|
||||
public LogSearch() {
|
||||
super("search", "Search the log for an entry", "/%s log search <query> [page]", Permission.LOG_SEARCH,
|
||||
Predicate.is(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
int page = -999;
|
||||
if (args.size() > 1) {
|
||||
try {
|
||||
page = Integer.parseInt(args.get(args.size() - 1));
|
||||
args.remove(args.size() - 1);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
|
||||
final String query = args.stream().collect(Collectors.joining(" "));
|
||||
|
||||
int maxPage = log.getSearchMaxPages(query);
|
||||
if (maxPage == 0) {
|
||||
Message.LOG_NO_ENTRIES.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (page == -999) {
|
||||
page = maxPage;
|
||||
}
|
||||
|
||||
if (page < 1 || page > maxPage) {
|
||||
Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
SortedMap<Integer, LogEntry> entries = log.getSearch(page, query);
|
||||
Message.LOG_SEARCH_HEADER.send(sender, query, page, maxPage);
|
||||
|
||||
for (Map.Entry<Integer, LogEntry> e : entries.entrySet()) {
|
||||
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted());
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public class LogTrackHistory extends SubCommand<Log> {
|
||||
public LogTrackHistory() {
|
||||
super("trackhistory", "View an objects history", "/%s log trackhistory <track> [page]", Permission.LOG_TRACK_HISTORY,
|
||||
Predicate.notInRange(1, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
String track = args.get(0);
|
||||
int page = -999;
|
||||
|
||||
if (args.size() == 2) {
|
||||
try {
|
||||
page = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
// invalid page
|
||||
Message.LOG_INVALID_PAGE.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
if (ArgumentChecker.checkName(track)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
int maxPage = log.getTrackHistoryMaxPages(track);
|
||||
if (maxPage == 0) {
|
||||
Message.LOG_NO_ENTRIES.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (page == -999) {
|
||||
page = maxPage;
|
||||
}
|
||||
|
||||
if (page < 1 || page > maxPage) {
|
||||
Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
SortedMap<Integer, LogEntry> entries = log.getTrackHistory(page, track);
|
||||
String name = entries.values().stream().findAny().get().getActedName();
|
||||
Message.LOG_HISTORY_TRACK_HEADER.send(sender, name, page, maxPage);
|
||||
|
||||
for (Map.Entry<Integer, LogEntry> e : entries.entrySet()) {
|
||||
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted());
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.log.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.Log;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogUserHistory extends SubCommand<Log> {
|
||||
public LogUserHistory() {
|
||||
super("userhistory", "View an objects history", "/%s log userhistory <user> [page]", Permission.LOG_USER_HISTORY,
|
||||
Predicate.notInRange(1, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
String user = args.get(0);
|
||||
final int[] page = {-999};
|
||||
|
||||
if (args.size() == 2) {
|
||||
try {
|
||||
page[0] = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
// invalid page
|
||||
return showLog(-1, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
UUID uuid = Util.parseUuid(user);
|
||||
if (uuid != null) {
|
||||
if (page[0] == -999) {
|
||||
page[0] = log.getUserHistoryMaxPages(uuid);
|
||||
}
|
||||
|
||||
return showLog(page[0], uuid, sender, log);
|
||||
|
||||
}
|
||||
|
||||
if (user.length() <= 16) {
|
||||
if (Patterns.NON_USERNAME.matcher(user).find()) {
|
||||
Message.USER_INVALID_ENTRY.send(sender, user);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Message.USER_ATTEMPTING_LOOKUP.send(sender);
|
||||
|
||||
UUID uuid1 = plugin.getDatastore().getUUID(user);
|
||||
|
||||
if (uuid1 == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (page[0] == -999) {
|
||||
page[0] = log.getUserHistoryMaxPages(uuid1);
|
||||
}
|
||||
|
||||
return showLog(page[0], uuid1, sender, log);
|
||||
}
|
||||
|
||||
Message.USER_INVALID_ENTRY.send(sender, user);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
private static CommandResult showLog(int page, UUID user, Sender sender, Log log) {
|
||||
int maxPage = log.getUserHistoryMaxPages(user);
|
||||
if (maxPage == 0) {
|
||||
Message.LOG_NO_ENTRIES.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (page < 1 || page > maxPage) {
|
||||
Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
SortedMap<Integer, LogEntry> entries = log.getUserHistory(page, user);
|
||||
String name = entries.values().stream().findAny().get().getActedName();
|
||||
Message.LOG_HISTORY_USER_HEADER.send(sender, name, page, maxPage);
|
||||
|
||||
for (Map.Entry<Integer, LogEntry> e : entries.entrySet()) {
|
||||
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted());
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.commands.misc;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
@ -36,9 +37,13 @@ public class DebugCommand extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
Message.DEBUG.send(sender, plugin.getPlayerCount(), plugin.getUserManager().getUsers().size(),
|
||||
plugin.getGroupManager().getGroups().size(), plugin.getTrackManager().getTracks().size()
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
Message.DEBUG.send(sender,
|
||||
plugin.getPlayerCount(),
|
||||
plugin.getUserManager().getAll().size(),
|
||||
plugin.getGroupManager().getAll().size(),
|
||||
plugin.getTrackManager().getAll().size()
|
||||
);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,23 +23,38 @@
|
||||
package me.lucko.luckperms.commands.misc;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static me.lucko.luckperms.commands.Util.formatBoolean;
|
||||
|
||||
public class InfoCommand extends SingleMainCommand {
|
||||
public InfoCommand() {
|
||||
super("Info", "/%s info", 0, Permission.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
final LPConfiguration c = plugin.getConfiguration();
|
||||
Message.INFO.send(sender, plugin.getVersion(), plugin.getDatastore().getName(), c.getServer(),
|
||||
c.getDefaultGroupName(), c.getSyncTime(), c.getIncludeGlobalPerms(), c.getOnlineMode(), c.getApplyWildcards());
|
||||
Message.INFO.send(sender,
|
||||
plugin.getVersion(),
|
||||
plugin.getDatastore().getName(),
|
||||
c.getServer(),
|
||||
c.getDefaultGroupName(),
|
||||
c.getSyncTime(),
|
||||
formatBoolean(c.getIncludeGlobalPerms()),
|
||||
formatBoolean(c.getOnlineMode()),
|
||||
formatBoolean(c.getApplyWildcards()),
|
||||
formatBoolean(c.getApplyRegex()),
|
||||
formatBoolean(c.getApplyShorthand())
|
||||
);
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.commands.misc;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
@ -36,8 +37,9 @@ public class SyncCommand extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
Message.UPDATE_TASK_RUN.send(sender);
|
||||
plugin.runUpdateTask();
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,12 @@
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
@ -37,31 +39,31 @@ public class CreateTrack extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
String trackName = args.get(0).toLowerCase();
|
||||
if (!ArgumentChecker.checkName(trackName)) {
|
||||
if (ArgumentChecker.checkName(trackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadTrack(trackName, success -> {
|
||||
if (success) {
|
||||
Message.TRACK_ALREADY_EXISTS.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().createAndLoadTrack(trackName, success1 -> {
|
||||
if (!success1) {
|
||||
Message.CREATE_TRACK_ERROR.send(sender);
|
||||
} else {
|
||||
Message.CREATE_SUCCESS.send(sender, trackName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (plugin.getDatastore().loadTrack(trackName)) {
|
||||
Message.TRACK_ALREADY_EXISTS.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().createAndLoadTrack(trackName)) {
|
||||
Message.CREATE_TRACK_ERROR.send(sender);
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Message.CREATE_SUCCESS.send(sender, trackName);
|
||||
LogEntryBuilder.get().actor(sender).actedName(trackName).type('T').action("create").submit(plugin);
|
||||
plugin.runUpdateTask();
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,12 @@
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
@ -41,43 +43,43 @@ public class DeleteTrack extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
String trackName = args.get(0).toLowerCase();
|
||||
if (!ArgumentChecker.checkName(trackName)) {
|
||||
if (ArgumentChecker.checkName(trackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadTrack(trackName, success -> {
|
||||
if (!success) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
if (!plugin.getDatastore().loadTrack(trackName)) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Track track = plugin.getTrackManager().getTrack(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().deleteTrack(track, success1 -> {
|
||||
if (!success1) {
|
||||
Message.DELETE_TRACK_ERROR.send(sender);
|
||||
} else {
|
||||
Message.DELETE_SUCCESS.send(sender, trackName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Track track = plugin.getTrackManager().get(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().deleteTrack(track)) {
|
||||
Message.DELETE_TRACK_ERROR.send(sender);
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Message.DELETE_SUCCESS.send(sender, trackName);
|
||||
LogEntryBuilder.get().actor(sender).actedName(trackName).type('T').action("delete").submit(plugin);
|
||||
plugin.runUpdateTask();
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> tracks = new ArrayList<>(plugin.getTrackManager().getTracks().keySet());
|
||||
final List<String> tracks = new ArrayList<>(plugin.getTrackManager().getAll().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
@ -38,13 +39,13 @@ public class ListTracks extends SingleMainCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
plugin.getDatastore().loadAllTracks(success -> {
|
||||
if (!success) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
Message.TRACKS_LIST.send(sender, Util.listToCommaSep(new ArrayList<>(plugin.getTrackManager().getTracks().keySet())));
|
||||
}
|
||||
});
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (!plugin.getDatastore().loadAllTracks()) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
Message.TRACKS_LIST.send(sender, Util.listToCommaSep(new ArrayList<>(plugin.getTrackManager().getAll().keySet())));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,12 @@
|
||||
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.track.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -35,33 +37,44 @@ import java.util.List;
|
||||
|
||||
public class TrackMainCommand extends MainCommand<Track> {
|
||||
public TrackMainCommand() {
|
||||
super("Track", "/%s track <track>", 2);
|
||||
super("Track", "/%s track <track>", 2, ImmutableList.<SubCommand<Track>>builder()
|
||||
.add(new TrackInfo())
|
||||
.add(new TrackAppend())
|
||||
.add(new TrackInsert())
|
||||
.add(new TrackRemove())
|
||||
.add(new TrackClear())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<Track> onSuccess) {
|
||||
if (!ArgumentChecker.checkName(target)) {
|
||||
protected Track getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
if (ArgumentChecker.checkName(target)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
plugin.getDatastore().loadTrack(target, success -> {
|
||||
if (!success) {
|
||||
Message.TRACK_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Track track = plugin.getTrackManager().getTrack(target);
|
||||
if (track == null) {
|
||||
Message.TRACK_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDatastore().loadTrack(target)) {
|
||||
Message.TRACK_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
Track track = plugin.getTrackManager().get(target);
|
||||
if (track == null) {
|
||||
Message.TRACK_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup(Track track, LuckPermsPlugin plugin) {
|
||||
|
||||
onSuccess.onComplete(track);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getObjects(LuckPermsPlugin plugin) {
|
||||
return new ArrayList<>(plugin.getTrackManager().getTracks().keySet());
|
||||
return new ArrayList<>(plugin.getTrackManager().getAll().keySet());
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,14 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -42,33 +41,42 @@ public class TrackAppend extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
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;
|
||||
}
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
track.appendGroup(group);
|
||||
Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), track.getName());
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName()));
|
||||
saveTrack(track, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Group group = plugin.getGroupManager().get(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
track.appendGroup(group);
|
||||
Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), track.getName());
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName()));
|
||||
LogEntryBuilder.get().actor(sender).acted(track)
|
||||
.action("append " + group.getName())
|
||||
.submit(plugin);
|
||||
save(track, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,9 +41,11 @@ public class TrackClear extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
track.clearGroups();
|
||||
Message.TRACK_CLEAR.send(sender, track.getName());
|
||||
saveTrack(track, sender, plugin);
|
||||
LogEntryBuilder.get().actor(sender).acted(track).action("clear").submit(plugin);
|
||||
save(track, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
@ -40,7 +37,8 @@ public class TrackInfo extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
Message.TRACK_INFO.send(sender, track.getName(), Util.listToArrowSep(track.getGroups()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,14 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -42,42 +41,53 @@ public class TrackInsert extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
int pos;
|
||||
try {
|
||||
pos = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.TRACK_INSERT_ERROR_NUMBER.send(sender, args.get(1));
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
track.insertGroup(group, pos - 1);
|
||||
Message.TRACK_INSERT_SUCCESS.send(sender, group.getName(), track.getName(), pos);
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName()));
|
||||
saveTrack(track, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Message.TRACK_INSERT_ERROR_INVALID_POS.send(sender, pos);
|
||||
}
|
||||
}
|
||||
});
|
||||
Group group = plugin.getGroupManager().get(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
track.insertGroup(group, pos - 1);
|
||||
Message.TRACK_INSERT_SUCCESS.send(sender, group.getName(), track.getName(), pos);
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName()));
|
||||
LogEntryBuilder.get().actor(sender).acted(track)
|
||||
.action("insert " + group.getName() + " " + pos)
|
||||
.submit(plugin);
|
||||
save(track, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Message.TRACK_INSERT_ERROR_INVALID_POS.send(sender, pos);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,13 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -40,19 +40,31 @@ public class TrackRemove extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
track.removeGroup(groupName);
|
||||
Message.TRACK_REMOVE_SUCCESS.send(sender, groupName, track.getName());
|
||||
saveTrack(track, sender, plugin);
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups()));
|
||||
LogEntryBuilder.get().actor(sender).acted(track)
|
||||
.action("remove " + groupName)
|
||||
.submit(plugin);
|
||||
save(track, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -22,69 +22,105 @@
|
||||
|
||||
package me.lucko.luckperms.commands.user;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.user.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserMainCommand extends MainCommand<User> {
|
||||
public UserMainCommand() {
|
||||
super("User", "/%s user <user>", 2);
|
||||
super("User", "/%s user <user>", 2, ImmutableList.<SubCommand<User>>builder()
|
||||
.add(new UserInfo())
|
||||
.add(new UserGetUUID())
|
||||
.add(new UserListNodes())
|
||||
.add(new UserHasPerm())
|
||||
.add(new UserInheritsPerm())
|
||||
.add(new UserSetPermission())
|
||||
.add(new UserUnSetPermission())
|
||||
.add(new UserAddGroup())
|
||||
.add(new UserRemoveGroup())
|
||||
.add(new UserSetTempPermission())
|
||||
.add(new UserUnsetTempPermission())
|
||||
.add(new UserAddTempGroup())
|
||||
.add(new UserRemoveTempGroup())
|
||||
.add(new UserSetPrimaryGroup())
|
||||
.add(new UserShowTracks())
|
||||
.add(new UserPromote())
|
||||
.add(new UserDemote())
|
||||
.add(new UserShowPos())
|
||||
.add(new UserClear())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<User> onSuccess) {
|
||||
protected User getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
UUID u = Util.parseUuid(target);
|
||||
if (u != null) {
|
||||
runSub(plugin, sender, u, onSuccess);
|
||||
return;
|
||||
User user = getUser(plugin, u);
|
||||
if (user == null) {
|
||||
|
||||
Message.USER_NEVER_JOINED.send(sender);
|
||||
if (!plugin.getDatastore().loadOrCreateUser(u, "null")) {
|
||||
Message.USER_CREATE_FAIL.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
user = getUser(plugin, u);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
if (target.length() <= 16) {
|
||||
if (Patterns.NON_USERNAME.matcher(target).find()) {
|
||||
Message.USER_INVALID_ENTRY.send(sender, target);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
Message.USER_ATTEMPTING_LOOKUP.send(sender);
|
||||
|
||||
plugin.getDatastore().getUUID(target, uuid -> {
|
||||
if (uuid == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
UUID uuid = plugin.getDatastore().getUUID(target);
|
||||
if (uuid == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
runSub(plugin, sender, uuid, onSuccess);
|
||||
});
|
||||
return;
|
||||
User user = getUser(plugin, uuid);
|
||||
if (user == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
Message.USER_INVALID_ENTRY.send(sender, target);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void runSub(LuckPermsPlugin plugin, Sender sender, UUID uuid, Callback<User> onSuccess) {
|
||||
plugin.getDatastore().loadUser(uuid, success -> {
|
||||
if (!success) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected void cleanup(User user, LuckPermsPlugin plugin) {
|
||||
plugin.getUserManager().cleanup(user);
|
||||
}
|
||||
|
||||
User user = plugin.getUserManager().getUser(uuid);
|
||||
if (user == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
private User getUser(LuckPermsPlugin plugin, UUID uuid) {
|
||||
if (!plugin.getDatastore().loadUser(uuid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
onSuccess.onComplete(user);
|
||||
plugin.getUserManager().cleanupUser(user);
|
||||
});
|
||||
User user = plugin.getUserManager().get(uuid);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
@ -42,56 +44,66 @@ public class UserAddGroup extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Group group = plugin.getGroupManager().get(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
user.addGroup(group, server);
|
||||
Message.USER_ADDGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("addgroup " + group.getName() + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
user.addGroup(group, server, world);
|
||||
Message.USER_ADDGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("addgroup " + group.getName() + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
user.addGroup(group, server);
|
||||
Message.USER_ADDGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
user.addGroup(group, server, world);
|
||||
Message.USER_ADDGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.addGroup(group);
|
||||
Message.USER_ADDGROUP_SUCCESS.send(sender, user.getName(), groupName);
|
||||
}
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.USER_ALREADY_MEMBER_OF.send(sender, user.getName(), group.getName());
|
||||
}
|
||||
user.addGroup(group);
|
||||
Message.USER_ADDGROUP_SUCCESS.send(sender, user.getName(), groupName);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("addgroup " + group.getName())
|
||||
.submit(plugin);
|
||||
}
|
||||
});
|
||||
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.USER_ALREADY_MEMBER_OF.send(sender, user.getName(), group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
@ -44,12 +46,12 @@ public class UserAddTempGroup extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
long duration;
|
||||
@ -57,58 +59,68 @@ public class UserAddTempGroup extends SubCommand<User> {
|
||||
duration = DateUtil.parseDateDiff(args.get(1), true);
|
||||
} catch (DateUtil.IllegalDateException e) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(1));
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Group group = plugin.getGroupManager().get(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.addGroup(group, server, duration);
|
||||
Message.USER_ADDTEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server,
|
||||
DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("addtempgroup " + group.getName() + " " + duration + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.addGroup(group, server, world, duration);
|
||||
Message.USER_ADDTEMPGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server,
|
||||
world, DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("addtempgroup " + group.getName() + " " + duration + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} 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();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.addGroup(group, server, duration);
|
||||
Message.USER_ADDTEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server,
|
||||
DateUtil.formatDateDiff(duration));
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.addGroup(group, server, world, duration);
|
||||
Message.USER_ADDTEMPGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server,
|
||||
world, 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());
|
||||
}
|
||||
user.addGroup(group, duration);
|
||||
Message.USER_ADDTEMPGROUP_SUCCESS.send(sender, user.getName(), groupName, DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("addtempgroup " + group.getName() + " " + duration)
|
||||
.submit(plugin);
|
||||
}
|
||||
});
|
||||
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.USER_ALREADY_TEMP_MEMBER_OF.send(sender, user.getName(), group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,11 +41,13 @@ public class UserClear extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
user.clearNodes();
|
||||
plugin.getUserManager().giveDefaults(user);
|
||||
Message.CLEAR_SUCCESS.send(sender, user.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(user).action("clear").submit(plugin);
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,10 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
@ -45,73 +43,75 @@ public class UserDemote extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
final String trackName = args.get(0).toLowerCase();
|
||||
if (!ArgumentChecker.checkName(trackName)) {
|
||||
if (ArgumentChecker.checkName(trackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadTrack(trackName, success -> {
|
||||
if (!success) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
Track track = plugin.getTrackManager().getTrack(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDatastore().loadTrack(trackName)) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (track.getSize() <= 1) {
|
||||
Message.TRACK_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
Track track = plugin.getTrackManager().get(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
final String old = user.getPrimaryGroup();
|
||||
final String previous;
|
||||
try {
|
||||
previous = track.getPrevious(old);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), old);
|
||||
Message.USER_DEMOTE_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
||||
return;
|
||||
}
|
||||
if (track.getSize() <= 1) {
|
||||
Message.TRACK_EMPTY.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (previous == null) {
|
||||
Message.USER_DEMOTE_ERROR_ENDOFTRACK.send(sender, track.getName());
|
||||
return;
|
||||
}
|
||||
final String old = user.getPrimaryGroup();
|
||||
final String previous;
|
||||
try {
|
||||
previous = track.getPrevious(old);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), old);
|
||||
Message.USER_DEMOTE_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(previous, success1 -> {
|
||||
if (!success1) {
|
||||
Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous);
|
||||
} else {
|
||||
Group previousGroup = plugin.getGroupManager().getGroup(previous);
|
||||
if (previousGroup == null) {
|
||||
Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous);
|
||||
return;
|
||||
}
|
||||
if (previous == null) {
|
||||
Message.USER_DEMOTE_ERROR_ENDOFTRACK.send(sender, track.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
user.unsetPermission("group." + old);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
try {
|
||||
user.addGroup(previousGroup);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
user.setPrimaryGroup(previousGroup.getName());
|
||||
if (!plugin.getDatastore().loadGroup(previous)) {
|
||||
Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_DEMOTE_SUCCESS_PROMOTE.send(sender, track.getName(), old, previousGroup.getName());
|
||||
Message.USER_DEMOTE_SUCCESS_REMOVE.send(sender, user.getName(), old, previousGroup.getName(), previousGroup.getName());
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), previousGroup.getName(), old, true));
|
||||
saveUser(user, sender, plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Group previousGroup = plugin.getGroupManager().get(previous);
|
||||
if (previousGroup == null) {
|
||||
Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
user.unsetPermission("group." + old);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
try {
|
||||
user.addGroup(previousGroup);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
user.setPrimaryGroup(previousGroup.getName());
|
||||
|
||||
Message.USER_DEMOTE_SUCCESS_PROMOTE.send(sender, track.getName(), old, previousGroup.getName());
|
||||
Message.USER_DEMOTE_SUCCESS_REMOVE.send(sender, user.getName(), old, previousGroup.getName(), previousGroup.getName());
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), previousGroup.getName(), old, true));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("demote " + track.getName() + "(from " + old + " to " + previousGroup.getName() + ")")
|
||||
.submit(plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
@ -39,7 +40,8 @@ public class UserGetUUID extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
Message.USER_GETUUID.send(sender, user.getName(), user.getUuid().toString());
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.users.User;
|
||||
@ -42,11 +39,11 @@ public class UserHasPerm extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
if (args.size() >= 2) {
|
||||
if (!ArgumentChecker.checkServer(args.get(1))) {
|
||||
if (ArgumentChecker.checkServer(args.get(1))) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
@ -58,5 +55,6 @@ public class UserHasPerm extends SubCommand<User> {
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, "global"));
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.users.User;
|
||||
@ -39,10 +36,18 @@ public class UserInfo extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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()),
|
||||
Util.listToCommaSep(user.getGroupNames()), user.getPrimaryGroup(),
|
||||
user.getPermanentNodes().keySet().size(), user.getTemporaryNodes().keySet().size(), label, user.getName()
|
||||
public CommandResult 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()),
|
||||
Util.listToCommaSep(user.getGroupNames()),
|
||||
user.getPrimaryGroup(),
|
||||
user.getPermanentNodes().keySet().size(),
|
||||
user.getTemporaryNodes().keySet().size(),
|
||||
label,
|
||||
user.getName()
|
||||
);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.users.User;
|
||||
@ -42,11 +39,11 @@ public class UserInheritsPerm extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
if (args.size() >= 2) {
|
||||
if (!ArgumentChecker.checkServer(args.get(1))) {
|
||||
if (ArgumentChecker.checkServer(args.get(1))) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
@ -58,5 +55,6 @@ public class UserInheritsPerm extends SubCommand<User> {
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true));
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.users.User;
|
||||
@ -40,8 +37,9 @@ public class UserListNodes extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(user.getPermanentNodes()));
|
||||
Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getTemporaryNodes()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,10 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
@ -45,73 +43,75 @@ public class UserPromote extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
final String trackName = args.get(0).toLowerCase();
|
||||
if (!ArgumentChecker.checkName(trackName)) {
|
||||
if (ArgumentChecker.checkName(trackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadTrack(trackName, success -> {
|
||||
if (!success) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
Track track = plugin.getTrackManager().getTrack(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDatastore().loadTrack(trackName)) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (track.getSize() <= 1) {
|
||||
Message.TRACK_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
Track track = plugin.getTrackManager().get(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
final String old = user.getPrimaryGroup();
|
||||
final String next;
|
||||
try {
|
||||
next = track.getNext(old);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), old);
|
||||
Message.USER_PROMOTE_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
||||
return;
|
||||
}
|
||||
if (track.getSize() <= 1) {
|
||||
Message.TRACK_EMPTY.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (next == null) {
|
||||
Message.USER_PROMOTE_ERROR_ENDOFTRACK.send(sender, track.getName());
|
||||
return;
|
||||
}
|
||||
final String old = user.getPrimaryGroup();
|
||||
final String next;
|
||||
try {
|
||||
next = track.getNext(old);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), old);
|
||||
Message.USER_PROMOTE_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(next, success1 -> {
|
||||
if (!success1) {
|
||||
Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next);
|
||||
} else {
|
||||
Group nextGroup = plugin.getGroupManager().getGroup(next);
|
||||
if (nextGroup == null) {
|
||||
Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next);
|
||||
return;
|
||||
}
|
||||
if (next == null) {
|
||||
Message.USER_PROMOTE_ERROR_ENDOFTRACK.send(sender, track.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
user.unsetPermission("group." + old);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
try {
|
||||
user.addGroup(nextGroup);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
user.setPrimaryGroup(nextGroup.getName());
|
||||
if (!plugin.getDatastore().loadGroup(next)) {
|
||||
Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_PROMOTE_SUCCESS_PROMOTE.send(sender, track.getName(), old, nextGroup.getName());
|
||||
Message.USER_PROMOTE_SUCCESS_REMOVE.send(sender, user.getName(), old, nextGroup.getName(), nextGroup.getName());
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), old, nextGroup.getName(), false));
|
||||
saveUser(user, sender, plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Group nextGroup = plugin.getGroupManager().get(next);
|
||||
if (nextGroup == null) {
|
||||
Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
user.unsetPermission("group." + old);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
try {
|
||||
user.addGroup(nextGroup);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
user.setPrimaryGroup(nextGroup.getName());
|
||||
|
||||
Message.USER_PROMOTE_SUCCESS_PROMOTE.send(sender, track.getName(), old, nextGroup.getName());
|
||||
Message.USER_PROMOTE_SUCCESS_REMOVE.send(sender, user.getName(), old, nextGroup.getName(), nextGroup.getName());
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), old, nextGroup.getName(), false));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("promote " + track.getName() + "(from " + old + " to " + nextGroup.getName() + ")")
|
||||
.submit(plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -41,50 +43,61 @@ public class UserRemoveGroup extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if ((args.size() == 1 || (args.size() == 2 && args.get(1).equalsIgnoreCase("global")))
|
||||
&& user.getPrimaryGroup().equalsIgnoreCase(groupName)) {
|
||||
Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
|
||||
return;
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
user.unsetPermission("group." + groupName, server);
|
||||
Message.USER_REMOVEGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("removegroup " + groupName + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
user.unsetPermission("group." + groupName, server, world);
|
||||
Message.USER_REMOVEGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("removegroup " + groupName + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.unsetPermission("group." + groupName);
|
||||
Message.USER_REMOVEGROUP_SUCCESS.send(sender, user.getName(), groupName);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("removegroup " + groupName)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.USER_NOT_MEMBER_OF.send(sender, user.getName(), groupName);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
@ -42,44 +44,55 @@ public class UserRemoveTempGroup extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
user.unsetPermission("group." + groupName, server, true);
|
||||
Message.USER_REMOVETEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("removetempgroup " + groupName + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
user.unsetPermission("group." + groupName, server, world, true);
|
||||
Message.USER_REMOVETEMPGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("removetempgroup " + groupName + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.unsetPermission("group." + groupName, true);
|
||||
Message.USER_REMOVETEMPGROUP_SUCCESS.send(sender, user.getName(), groupName);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("removetempgroup " + groupName)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.USER_NOT_TEMP_MEMBER_OF.send(sender, user.getName(), groupName);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,17 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -43,23 +45,23 @@ public class UserSetPermission extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(node)) {
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.USER_USE_ADDGROUP.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
boolean b = Boolean.parseBoolean(bool);
|
||||
@ -67,33 +69,44 @@ public class UserSetPermission extends SubCommand<User> {
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.setPermission(node, b, server);
|
||||
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("set " + node + " " + b + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.setPermission(node, b, server, world);
|
||||
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world);
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("set " + node + " " + b + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.setPermission(node, b);
|
||||
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, user.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("set " + node + " " + b)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HASPERMISSION.send(sender, user.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
@ -40,31 +42,35 @@ public class UserSetPrimaryGroup extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
Group group = plugin.getGroupManager().getGroup(args.get(0).toLowerCase());
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
Group group = plugin.getGroupManager().get(args.get(0).toLowerCase());
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (user.getPrimaryGroup().equalsIgnoreCase(group.getName())) {
|
||||
Message.USER_PRIMARYGROUP_ERROR_ALREADYHAS.send(sender);
|
||||
return;
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (!user.isInGroup(group)) {
|
||||
Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, label);
|
||||
return;
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
user.setPrimaryGroup(group.getName());
|
||||
Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getName(), group.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("setprimarygroup " + group.getName())
|
||||
.submit(plugin);
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,16 +23,18 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -44,23 +46,23 @@ public class UserSetTempPermission extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (!ArgumentChecker.checkNode(node)) {
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.USER_USE_ADDGROUP.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
boolean b = Boolean.parseBoolean(bool);
|
||||
@ -70,44 +72,55 @@ public class UserSetTempPermission extends SubCommand<User> {
|
||||
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||
} catch (DateUtil.IllegalDateException e) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 4) {
|
||||
final String server = args.get(3).toLowerCase();
|
||||
if (!ArgumentChecker.checkServer(server)) {
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
user.setPermission(node, b, server, duration);
|
||||
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server, DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("settemp " + node + " " + b + " " + duration + " " + server)
|
||||
.submit(plugin);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
user.setPermission(node, b, server, world, duration);
|
||||
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("settemp " + node + " " + b + " " + duration + " " + server + " " + world)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.setPermission(node, b, duration);
|
||||
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, user.getName(), DateUtil.formatDateDiff(duration));
|
||||
LogEntryBuilder.get().actor(sender).acted(user)
|
||||
.action("settemp " + node + " " + b + " " + duration)
|
||||
.submit(plugin);
|
||||
}
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, user.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
@ -42,40 +39,40 @@ public class UserShowPos extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
final String trackName = args.get(0).toLowerCase();
|
||||
if (!ArgumentChecker.checkName(trackName)) {
|
||||
if (ArgumentChecker.checkName(trackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadTrack(trackName, success -> {
|
||||
if (!success) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
Track track = plugin.getTrackManager().getTrack(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDatastore().loadTrack(trackName)) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (track.getSize() <= 1) {
|
||||
Message.TRACK_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
Track track = plugin.getTrackManager().get(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
if (!track.containsGroup(user.getPrimaryGroup())) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), user.getPrimaryGroup());
|
||||
return;
|
||||
}
|
||||
if (track.getSize() <= 1) {
|
||||
Message.TRACK_EMPTY.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_SHOWPOS.send(sender, user.getName(), track.getName(), Util.listToArrowSep(track.getGroups(), user.getPrimaryGroup()));
|
||||
}
|
||||
});
|
||||
if (!track.containsGroup(user.getPrimaryGroup())) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), user.getPrimaryGroup());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_SHOWPOS.send(sender, user.getName(), track.getName(), Util.listToArrowSep(track.getGroups(), user.getPrimaryGroup()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
@ -42,16 +39,20 @@ public class UserShowTracks extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
plugin.getDatastore().loadAllTracks(success -> {
|
||||
if (!success) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return;
|
||||
}
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
if (!plugin.getDatastore().loadAllTracks()) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_SHOWTRACKS_INFO.send(sender, user.getPrimaryGroup(), user.getName());
|
||||
Message.TRACKS_LIST.send(sender, Util.listToCommaSep(
|
||||
plugin.getTrackManager().getApplicableTracks(user.getPrimaryGroup()).stream().map(Track::getName).collect(Collectors.toList())));
|
||||
});
|
||||
Message.USER_SHOWTRACKS_INFO.send(sender, user.getPrimaryGroup(), user.getName());
|
||||
Message.TRACKS_LIST.send(sender,
|
||||
Util.listToCommaSep(plugin.getTrackManager().getApplicableTracks(user.getPrimaryGroup()).stream()
|
||||
.map(Track::getName)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
);
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user