use of org.spongepowered.api.service.permission.PermissionService in project SpongeCommon by SpongePowered.
the class MixinDedicatedPlayerList method onBypassPlayerLimit.
@Inject(method = "bypassesPlayerLimit", at = @At("HEAD"), cancellable = true)
private void onBypassPlayerLimit(GameProfile profile, CallbackInfoReturnable<Boolean> ci) {
final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
final Subject subject = permissionService.getUserSubjects().getSubject(profile.getId().toString()).orElse(permissionService.getDefaults());
final Tristate tristate = subject.getPermissionValue(SubjectData.GLOBAL_CONTEXT, LoginPermissions.BYPASS_PLAYER_LIMIT_PERMISSION);
// if we are still using the default permission service
if (tristate == Tristate.UNDEFINED && permissionService instanceof SpongePermissionService) {
return;
}
ci.setReturnValue(tristate.asBoolean());
}
use of org.spongepowered.api.service.permission.PermissionService in project SpongeCommon by SpongePowered.
the class MixinServerCommandManager method registerDefaultPermissions.
private void registerDefaultPermissions(Game game, MinecraftCommandWrapper cmd) {
Optional<PermissionService> perms = game.getServiceManager().provide(PermissionService.class);
if (perms.isPresent()) {
PermissionService service = perms.get();
int opLevel = cmd.getPermissionLevel();
if (opLevel == -1) {
return;
}
if (service instanceof SpongePermissionService) {
((SpongePermissionService) service).getGroupForOpLevel(opLevel).getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, cmd.getCommandPermission(), Tristate.TRUE);
} else if (opLevel == 0) {
service.getDefaults().getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, cmd.getCommandPermission(), Tristate.TRUE);
}
}
}
use of org.spongepowered.api.service.permission.PermissionService in project Nucleus by NucleusPowered.
the class SetupPermissionsCommand method setupGroups.
private void setupGroups(CommandSource src) throws Exception {
String ownerGroup = "owner";
String adminGroup = "admin";
String modGroup = "mod";
String defaultGroup = "default";
MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
// Create groups
PermissionService permissionService = Sponge.getServiceManager().provide(PermissionService.class).orElseThrow(() -> ReturnMessageException.fromKey("args.permissiongroup.noservice"));
// check for admin
Subject owner = getSubject(ownerGroup, src, permissionService, messageProvider);
Subject admin = getSubject(adminGroup, src, permissionService, messageProvider);
Subject mod = getSubject(modGroup, src, permissionService, messageProvider);
Subject defaults = getSubject(defaultGroup, src, permissionService, messageProvider);
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", adminGroup, ownerGroup));
owner.getSubjectData().addParent(ImmutableSet.of(), admin.asSubjectReference());
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", modGroup, adminGroup));
admin.getSubjectData().addParent(ImmutableSet.of(), mod.asSubjectReference());
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", defaultGroup, modGroup));
mod.getSubjectData().addParent(ImmutableSet.of(), defaults.asSubjectReference());
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.perms"));
setupPerms(src, owner, SuggestedLevel.OWNER, false, false);
setupPerms(src, admin, SuggestedLevel.ADMIN, false, false);
setupPerms(src, mod, SuggestedLevel.MOD, false, false);
setupPerms(src, defaults, SuggestedLevel.USER, false, false);
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.completegroups"));
}
use of org.spongepowered.api.service.permission.PermissionService in project SpongeCommon by SpongePowered.
the class MixinDedicatedPlayerList method onCanJoin.
@Inject(method = "canJoin", at = @At("HEAD"), cancellable = true)
private void onCanJoin(GameProfile profile, CallbackInfoReturnable<Boolean> ci) {
if (!isWhiteListEnabled() || getWhitelistedPlayers().isWhitelisted(profile)) {
ci.setReturnValue(true);
return;
}
final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
final Subject subject = permissionService.getUserSubjects().getSubject(profile.getId().toString()).orElse(permissionService.getDefaults());
ci.setReturnValue(subject.hasPermission(LoginPermissions.BYPASS_WHITELIST_PERMISSION));
}
use of org.spongepowered.api.service.permission.PermissionService in project LanternServer by LanternPowered.
the class DefaultCommandsCollection method load.
public void load() {
final Multimap<PluginContainer, CommandProvider> commandProviders = HashMultimap.create();
// Minecraft Commands
commandProviders.put(this.minecraft, new CommandBan());
commandProviders.put(this.minecraft, new CommandBanIp());
commandProviders.put(this.minecraft, new CommandBorder());
commandProviders.put(this.minecraft, new CommandDeop());
commandProviders.put(this.minecraft, new CommandDifficulty());
commandProviders.put(this.minecraft, new CommandGameMode());
commandProviders.put(this.minecraft, new CommandGameRule());
commandProviders.put(this.minecraft, new CommandHelp());
commandProviders.put(this.minecraft, new CommandKick());
commandProviders.put(this.minecraft, new CommandListBans());
commandProviders.put(this.minecraft, new CommandListPlayers());
commandProviders.put(this.minecraft, new CommandMe());
commandProviders.put(this.minecraft, new CommandOp());
commandProviders.put(this.minecraft, new CommandPardon());
commandProviders.put(this.minecraft, new CommandPardonIp());
commandProviders.put(this.minecraft, new CommandParticle());
commandProviders.put(this.implementation, new CommandParticleEffect());
commandProviders.put(this.minecraft, new CommandPlaySound());
commandProviders.put(this.minecraft, new CommandSay());
commandProviders.put(this.minecraft, new CommandScoreboard());
commandProviders.put(this.implementation, new CommandSetData());
commandProviders.put(this.minecraft, new CommandSetIdleTimeout());
commandProviders.put(this.minecraft, new CommandSetSpawn());
commandProviders.put(this.minecraft, new CommandStop());
commandProviders.put(this.minecraft, new CommandStopSound());
commandProviders.put(this.minecraft, new CommandTeleport());
commandProviders.put(this.minecraft, new CommandTell());
commandProviders.put(this.minecraft, new CommandTime());
commandProviders.put(this.minecraft, new CommandTitle());
commandProviders.put(this.minecraft, new CommandToggleDownfall());
commandProviders.put(this.minecraft, new CommandTp());
commandProviders.put(this.implementation, new CommandVersion());
commandProviders.put(this.minecraft, new CommandWeather());
commandProviders.put(this.minecraft, new CommandWhitelist());
// Testing Commands
commandProviders.put(this.implementation, new CommandOpenTestContainer());
for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
final PluginContainer plugin = entry.getKey();
this.commandManager.register(plugin, entry.getValue().buildSpecFor(plugin), entry.getValue().getAliases());
}
final PermissionService permissionService = this.permissionService.get();
if (permissionService instanceof LanternPermissionService) {
final LanternPermissionService lanternPermissionService = (LanternPermissionService) permissionService;
// noinspection Convert2streamapi
for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
entry.getValue().getOpPermissionLevel().ifPresent(level -> lanternPermissionService.getGroupForOpLevel(level).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE));
}
} else {
// noinspection Convert2streamapi
for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
if (entry.getValue().getOpPermissionLevel().orElse(0) == 0) {
permissionService.getDefaults().getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE);
}
}
}
}
Aggregations