From e9131f729ab9a1e2f0c0991a57d27ab2789e3023 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 11 Nov 2016 22:54:09 +0000 Subject: [PATCH] add methods for older sponge api versions --- .../lucko/luckperms/sponge/SpongeCommand.java | 1 + .../sponge/migration/MigrationUtils.java | 39 +++++++++++-------- .../service/persisted/PersistedSubject.java | 5 +-- .../sponge/service/simple/SimpleSubject.java | 5 +-- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java index d9aa60da..a0524460 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java @@ -70,6 +70,7 @@ class SpongeCommand extends CommandManager implements CommandCallable { } } + // For API 4 public List getSuggestions(CommandSource source, String s) throws CommandException { try (Timing ignored = plugin.getTimings().time(LPTiming.COMMAND_TAB_COMPLETE)) { return onTabComplete(plugin.getSenderFactory().wrap(source), Splitter.on(' ').splitToList(s)); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java index befa4575..f0855f56 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java @@ -60,29 +60,34 @@ public class MigrationUtils { } // Migrate options - Map, Map> opts = subject.getSubjectData().getAllOptions(); - for (Map.Entry, Map> e : opts.entrySet()) { - ContextSet context = LuckPermsService.convertContexts(e.getKey()); + try { + Map, Map> opts = subject.getSubjectData().getAllOptions(); + for (Map.Entry, Map> e : opts.entrySet()) { + ContextSet context = LuckPermsService.convertContexts(e.getKey()); - MutableContextSet contexts = MutableContextSet.fromSet(context); - String server = contexts.getValues("server").stream().findAny().orElse(null); - String world = contexts.getValues("world").stream().findAny().orElse(null); - contexts.removeAll("server"); - contexts.removeAll("world"); + MutableContextSet contexts = MutableContextSet.fromSet(context); + String server = contexts.getValues("server").stream().findAny().orElse(null); + String world = contexts.getValues("world").stream().findAny().orElse(null); + contexts.removeAll("server"); + contexts.removeAll("world"); - for (Map.Entry opt : e.getValue().entrySet()) { - if (opt.getKey().equalsIgnoreCase("prefix") || opt.getKey().equalsIgnoreCase("suffix")) { - try { - holder.setPermission(new NodeBuilder(opt.getKey().toLowerCase() + ".100." + opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) {} - } else { - try { - holder.setPermission(new NodeBuilder("meta." + opt.getKey() + "." + opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) {} + for (Map.Entry opt : e.getValue().entrySet()) { + if (opt.getKey().equalsIgnoreCase("prefix") || opt.getKey().equalsIgnoreCase("suffix")) { + try { + holder.setPermission(new NodeBuilder(opt.getKey().toLowerCase() + ".100." + opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); + } catch (ObjectAlreadyHasException ignored) {} + } else { + try { + holder.setPermission(new NodeBuilder("meta." + opt.getKey() + "." + opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); + } catch (ObjectAlreadyHasException ignored) {} + } } } + } catch (Throwable ignored) { + // Ignore. This is just so older versions of Sponge API can be used. } + // Migrate parents Map, List> parents = subject.getSubjectData().getAllParents(); for (Map.Entry, List> e : parents.entrySet()) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java index 8503e814..e0d320b1 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java @@ -34,7 +34,6 @@ import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.MemorySubjectData; import org.spongepowered.api.service.permission.Subject; -import org.spongepowered.api.service.permission.SubjectCollection; import org.spongepowered.api.util.Tristate; import java.io.IOException; @@ -51,7 +50,7 @@ public class PersistedSubject implements Subject { private final String identifier; private final LuckPermsService service; - private final SubjectCollection containingCollection; + private final PersistedCollection containingCollection; private final PersistedSubjectData subjectData; private final MemorySubjectData transientSubjectData; private final BufferedRequest saveBuffer = new BufferedRequest(1000L, r -> PersistedSubject.this.service.getPlugin().doAsync(r)) { @@ -68,7 +67,7 @@ public class PersistedSubject implements Subject { } }; - public PersistedSubject(String identifier, LuckPermsService service, SubjectCollection containingCollection) { + public PersistedSubject(String identifier, LuckPermsService service, PersistedCollection containingCollection) { this.identifier = identifier; this.service = service; this.containingCollection = containingCollection; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java index ef25a4fd..4b90da8d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java @@ -33,7 +33,6 @@ import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.MemorySubjectData; import org.spongepowered.api.service.permission.Subject; -import org.spongepowered.api.service.permission.SubjectCollection; import org.spongepowered.api.service.permission.SubjectData; import org.spongepowered.api.util.Tristate; @@ -50,10 +49,10 @@ public class SimpleSubject implements Subject { private final String identifier; private final LuckPermsService service; - private final SubjectCollection containingCollection; + private final SimpleCollection containingCollection; private final MemorySubjectData subjectData; - public SimpleSubject(String identifier, LuckPermsService service, SubjectCollection containingCollection) { + public SimpleSubject(String identifier, LuckPermsService service, SimpleCollection containingCollection) { this.identifier = identifier; this.service = service; this.containingCollection = containingCollection;