Add logging, prepare for import/export system
This commit is contained in:
@@ -26,19 +26,21 @@ import com.google.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
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.constants.Permission;
|
||||
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.SpongeUserManager;
|
||||
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.slf4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@@ -57,10 +59,7 @@ import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -80,6 +79,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
private Scheduler scheduler = Sponge.getScheduler();
|
||||
|
||||
private final Set<UUID> ignoringLogs = new HashSet<>();
|
||||
private LPConfiguration configuration;
|
||||
private UserManager userManager;
|
||||
private GroupManager groupManager;
|
||||
@@ -90,7 +90,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
@Listener
|
||||
public void onEnable(GamePreInitializationEvent event) {
|
||||
log = LogUtil.wrap(logger);
|
||||
log = LogFactory.wrap(logger);
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new SpongeConfig(this);
|
||||
@@ -102,7 +102,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
getLog().info("Registering commands...");
|
||||
CommandManager cmdService = Sponge.getCommandManager();
|
||||
cmdService.register(this, new SpongeCommand(this), "luckperms", "perms", "lp", "permissions", "p", "perm");
|
||||
registerPermissions();
|
||||
|
||||
getLog().info("Detecting storage method...");
|
||||
final String storageMethod = configuration.getStorageMethod();
|
||||
@@ -143,6 +142,8 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
.submit(LPSpongePlugin.this);
|
||||
}
|
||||
|
||||
scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get()).submit(this);
|
||||
|
||||
getLog().info("Registering API...");
|
||||
final ApiProvider provider = new ApiProvider(this);
|
||||
LuckPerms.registerProvider(provider);
|
||||
@@ -162,7 +163,24 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
@Listener
|
||||
public void onPostInit(GamePostInitializationEvent event) {
|
||||
registerPermissions();
|
||||
// register permissions
|
||||
Optional<PermissionService> ps = game.getServiceManager().provide(PermissionService.class);
|
||||
if (!ps.isPresent()) {
|
||||
getLog().warn("Unable to register all LuckPerms permissions. PermissionService not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
final PermissionService p = ps.get();
|
||||
|
||||
Optional<PermissionDescription.Builder> builder = p.newDescriptionBuilder(this);
|
||||
if (!builder.isPresent()) {
|
||||
getLog().warn("Unable to register all LuckPerms permissions. Description Builder not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (Permission perm : Permission.values()) {
|
||||
registerPermission(p, perm.getNode());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@@ -193,6 +211,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
return game.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sender> getSenders() {
|
||||
return game.getServer().getOnlinePlayers().stream().map(s -> SpongeSenderFactory.get().wrap(s)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPossiblePermissions() {
|
||||
Optional<PermissionService> p = game.getServiceManager().provide(PermissionService.class);
|
||||
@@ -217,70 +240,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
scheduler.createTaskBuilder().execute(r).submit(LPSpongePlugin.this);
|
||||
}
|
||||
|
||||
private void registerPermissions() {
|
||||
Optional<PermissionService> ps = game.getServiceManager().provide(PermissionService.class);
|
||||
if (!ps.isPresent()) {
|
||||
getLog().warn("Unable to register all LuckPerms permissions. PermissionService not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
final PermissionService p = ps.get();
|
||||
|
||||
Optional<PermissionDescription.Builder> builder = p.newDescriptionBuilder(this);
|
||||
if (!builder.isPresent()) {
|
||||
getLog().warn("Unable to register all LuckPerms permissions. Description Builder not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
registerPermission(p, "luckperms.sync");
|
||||
registerPermission(p, "luckperms.info");
|
||||
registerPermission(p, "luckperms.debug");
|
||||
registerPermission(p, "luckperms.creategroup");
|
||||
registerPermission(p, "luckperms.deletegroup");
|
||||
registerPermission(p, "luckperms.listgroups");
|
||||
registerPermission(p, "luckperms.createtrack");
|
||||
registerPermission(p, "luckperms.deletetrack");
|
||||
registerPermission(p, "luckperms.listtracks");
|
||||
registerPermission(p, "luckperms.user.info");
|
||||
registerPermission(p, "luckperms.user.getuuid");
|
||||
registerPermission(p, "luckperms.user.listnodes");
|
||||
registerPermission(p, "luckperms.user.haspermission");
|
||||
registerPermission(p, "luckperms.user.inheritspermission");
|
||||
registerPermission(p, "luckperms.user.setpermission");
|
||||
registerPermission(p, "luckperms.user.unsetpermission");
|
||||
registerPermission(p, "luckperms.user.addgroup");
|
||||
registerPermission(p, "luckperms.user.removegroup");
|
||||
registerPermission(p, "luckperms.user.settemppermission");
|
||||
registerPermission(p, "luckperms.user.unsettemppermission");
|
||||
registerPermission(p, "luckperms.user.addtempgroup");
|
||||
registerPermission(p, "luckperms.user.removetempgroup");
|
||||
registerPermission(p, "luckperms.user.setprimarygroup");
|
||||
registerPermission(p, "luckperms.user.showtracks");
|
||||
registerPermission(p, "luckperms.user.promote");
|
||||
registerPermission(p, "luckperms.user.demote");
|
||||
registerPermission(p, "luckperms.user.showpos");
|
||||
registerPermission(p, "luckperms.user.clear");
|
||||
registerPermission(p, "luckperms.group.info");
|
||||
registerPermission(p, "luckperms.group.listnodes");
|
||||
registerPermission(p, "luckperms.group.haspermission");
|
||||
registerPermission(p, "luckperms.group.inheritspermission");
|
||||
registerPermission(p, "luckperms.group.setpermission");
|
||||
registerPermission(p, "luckperms.group.unsetpermission");
|
||||
registerPermission(p, "luckperms.group.setinherit");
|
||||
registerPermission(p, "luckperms.group.unsetinherit");
|
||||
registerPermission(p, "luckperms.group.settemppermission");
|
||||
registerPermission(p, "luckperms.group.unsettemppermission");
|
||||
registerPermission(p, "luckperms.group.settempinherit");
|
||||
registerPermission(p, "luckperms.group.unsettempinherit");
|
||||
registerPermission(p, "luckperms.group.showtracks");
|
||||
registerPermission(p, "luckperms.group.clear");
|
||||
registerPermission(p, "luckperms.track.info");
|
||||
registerPermission(p, "luckperms.track.append");
|
||||
registerPermission(p, "luckperms.track.insert");
|
||||
registerPermission(p, "luckperms.track.remove");
|
||||
registerPermission(p, "luckperms.track.clear");
|
||||
}
|
||||
|
||||
private void registerPermission(PermissionService p, String node) {
|
||||
Optional<PermissionDescription.Builder> builder = p.newDescriptionBuilder(this);
|
||||
if (!builder.isPresent()) return;
|
||||
|
||||
@@ -22,37 +22,35 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.SenderFactory;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import org.spongepowered.api.command.CommandCallable;
|
||||
import org.spongepowered.api.command.CommandException;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
private static final Factory FACTORY = new Factory();
|
||||
|
||||
SpongeCommand(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult process(CommandSource source, String s) throws CommandException {
|
||||
onCommand(FACTORY.wrap(source), "perms", Arrays.asList(Patterns.SPACE.split(s)));
|
||||
onCommand(SpongeSenderFactory.get().wrap(source), "perms", Arrays.asList(Patterns.SPACE.split(s)), Callback.empty());
|
||||
return CommandResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String s) throws CommandException {
|
||||
// TODO: fix this so it actually works
|
||||
return onTabComplete(FACTORY.wrap(source), Arrays.asList(Patterns.SPACE.split(s)));
|
||||
return onTabComplete(SpongeSenderFactory.get().wrap(source), Arrays.asList(Patterns.SPACE.split(s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,18 +72,4 @@ class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
public Text getUsage(CommandSource source) {
|
||||
return Text.of("/perms");
|
||||
}
|
||||
|
||||
private static class Factory extends SenderFactory<CommandSource> {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void sendMessage(CommandSource source, String s) {
|
||||
source.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSource source, String node) {
|
||||
return source.hasPermission(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class SpongeListener extends AbstractListener {
|
||||
@Listener
|
||||
public void onClientLogin(ClientConnectionEvent.Login e) {
|
||||
final GameProfile player = e.getProfile();
|
||||
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.setCancelled(true);
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class SpongeSenderFactory extends SenderFactory<CommandSource> {
|
||||
private static SpongeSenderFactory instance = null;
|
||||
public static SpongeSenderFactory get() {
|
||||
if (instance == null){
|
||||
instance = new SpongeSenderFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(CommandSource source) {
|
||||
if (source instanceof Player) {
|
||||
return source.getName();
|
||||
}
|
||||
return Constants.getConsoleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID getUuid(CommandSource source) {
|
||||
if (source instanceof Player) {
|
||||
return ((Player) source).getUniqueId();
|
||||
}
|
||||
return Constants.getConsoleUUID();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void sendMessage(CommandSource source, String s) {
|
||||
source.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSource source, String node) {
|
||||
return source.hasPermission(node);
|
||||
}
|
||||
}
|
||||
@@ -37,31 +37,31 @@ public class SpongeUserManager extends UserManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadUser(User user) {
|
||||
public void unload(User user) {
|
||||
if (user != null) {
|
||||
Optional<Player> p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid()));
|
||||
if (p.isPresent()) {
|
||||
p.get().getSubjectData().clearParents();
|
||||
p.get().getSubjectData().clearPermissions();
|
||||
}
|
||||
getUsers().remove(user.getUuid());
|
||||
getAll().remove(user.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(User user) {
|
||||
public void cleanup(User user) {
|
||||
if (plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())).isPresent()) {
|
||||
unloadUser(user);
|
||||
unload(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User makeUser(UUID uuid) {
|
||||
public User make(UUID uuid) {
|
||||
return new SpongeUser(uuid, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User makeUser(UUID uuid, String username) {
|
||||
public User make(UUID uuid, String username) {
|
||||
return new SpongeUser(uuid, username, plugin);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class VersionUtil extends ClassTransformer {
|
||||
attribute.setAnnotation(annotation);
|
||||
|
||||
CtMethod getVersionMethod = clazz.getDeclaredMethod("getVersion");
|
||||
CtMethod hackedVersionMethod = CtNewMethod.make("public String getVersion() { return \"" + this.version + "\"; }", clazz);
|
||||
CtMethod hackedVersionMethod = CtNewMethod.make("public String getVersion() { return \"" + version + "\"; }", clazz);
|
||||
clazz.removeMethod(getVersionMethod);
|
||||
clazz.addMethod(hackedVersionMethod);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user