use of org.spongepowered.api.service.permission.SubjectReference in project LanternServer by LanternPowered.
the class ProxySubject method resolveNullableSubject.
@Nullable
default Subject resolveNullableSubject() {
SubjectReference reference = getInternalSubject();
if (reference == null) {
final Optional<PermissionService> optService = Lantern.getGame().getServiceManager().provide(PermissionService.class);
if (optService.isPresent()) {
// Try to update the internal subject
SubjectSettingCallback.apply(this, optService.get());
// Get the new subject reference, can be null if failed
reference = getInternalSubject();
}
}
return reference == null ? null : reference.resolve().join();
}
use of org.spongepowered.api.service.permission.SubjectReference in project UltimateChat by FabioZumbi12.
the class UCPerms78 method getGroupAndTag.
public Subject getGroupAndTag(User player) throws InterruptedException, ExecutionException {
HashMap<Integer, Subject> subs = new HashMap<>();
for (SubjectReference sub : player.getParents()) {
if (sub.getCollectionIdentifier().equals(getGroups().getIdentifier()) && (sub.getSubjectIdentifier() != null)) {
Subject subj = sub.resolve().get();
subs.put(subj.getParents().size(), subj);
}
}
return subs.isEmpty() ? null : subs.get(Collections.max(subs.keySet()));
}
use of org.spongepowered.api.service.permission.SubjectReference in project Nucleus by NucleusPowered.
the class ListGroupTests method testWeightsAreBeingAppliedCorrectly.
// Make 2 groups, example one admin group and another ace
//
// Set the order on nucleus config for them to show admin first then ace
// group-order=[ admin, ace ]
//
// Set weight of admin to some number higher than ace
//
// Reloadable or restart server then /list to see if it worked
@Test
@SuppressWarnings("all")
public void testWeightsAreBeingAppliedCorrectly() {
// Create two groups.
Subject admin = createSubjectWithWeight("admin", 1);
Subject ace = createSubjectWithWeight("ace", 0);
// The player is in both groups. Also, order is important.
List<Subject> parents = Lists.newArrayList(admin, ace);
Player player = Mockito.mock(Player.class);
List<SubjectReference> lsr = getSubjectReferences(parents);
Mockito.when(player.getParents()).thenReturn(lsr);
Mockito.when(player.getParents(Mockito.anySet())).thenReturn(lsr);
// Create our map.
Map<Player, List<String>> map = Maps.newHashMap();
map.put(player, Lists.newArrayList("admin", "ace"));
// No aliases.
Map<String, String> aliases = Maps.newHashMap();
// Now, let's run it through our method.
Map<String, List<Player>> result = ListPlayerCommand.linkPlayersToGroups(parents, aliases, map);
Assert.assertEquals("There should only be one entry", 1, result.size());
List<Player> players = result.get("admin");
Assert.assertNotNull("Players is null", players);
Assert.assertEquals("There should only be one player!", 1, players.size());
Assert.assertTrue("map is not empty", map.isEmpty());
}
use of org.spongepowered.api.service.permission.SubjectReference in project Nucleus by NucleusPowered.
the class ListGroupTests method createSubject.
private static Subject createSubject(String name, Subject... parents) {
Subject subject = Mockito.mock(Subject.class);
List<Subject> ls = Arrays.asList(parents);
Mockito.when(subject.getIdentifier()).thenReturn(name);
Mockito.when(subject.getOption(Mockito.anySetOf(Context.class), Mockito.eq("nucleus.list.weight"))).then(x -> ls.stream().map(y -> y.getOption("nucleus.list.weight")).filter(Optional::isPresent).findFirst().orElse(Optional.empty()));
Mockito.when(subject.getOption(Mockito.eq("nucleus.list.weight"))).then(x -> ls.stream().map(y -> y.getOption("nucleus.list.weight")).filter(Optional::isPresent).findFirst().orElse(Optional.empty()));
List<SubjectReference> lsr = getSubjectReferences(Arrays.asList(parents));
Mockito.when(subject.getParents()).thenReturn(lsr);
Mockito.when(subject.getParents(Mockito.anySetOf(Context.class))).thenReturn(lsr);
return subject;
}
use of org.spongepowered.api.service.permission.SubjectReference in project Nucleus by NucleusPowered.
the class ListGroupTests method testWeightsAreBeingAppliedCorrectlyWithAliases.
@Test
@SuppressWarnings("all")
public void testWeightsAreBeingAppliedCorrectlyWithAliases() {
// Create two groups.
Subject admin = createSubjectWithWeight("admin", 1);
Subject ace = createSubjectWithWeight("ace", 0);
// The player is in both groups. Also, order is important.
List<Subject> parents = Lists.newArrayList(admin, ace);
Player player = Mockito.mock(Player.class);
List<SubjectReference> lsr = getSubjectReferences(parents);
Mockito.when(player.getParents()).thenReturn(lsr);
Mockito.when(player.getParents(Mockito.anySet())).thenReturn(lsr);
// Create our map.
Map<Player, List<String>> map = Maps.newHashMap();
map.put(player, Lists.newArrayList("admin", "ace"));
// No aliases.
Map<String, String> aliases = Maps.newHashMap();
aliases.put("admin", "Admin");
aliases.put("ace", "Ace");
// Now, let's run it through our method.
Map<String, List<Player>> result = ListPlayerCommand.linkPlayersToGroups(parents, aliases, map);
Assert.assertEquals("There should only be one entry", 1, result.size());
List<Player> players = result.get("Admin");
Assert.assertNotNull("Players is null", players);
Assert.assertEquals("There should only be one player!", 1, players.size());
Assert.assertTrue("map is not empty", map.isEmpty());
}
Aggregations