Search in sources :

Example 16 with ModularUserService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.

the class InvulnerabilityService method setInvulnerable.

@Override
public void setInvulnerable(User user, boolean invulnerable) throws NucleusException {
    ModularUserService mus = Nucleus.getNucleus().getUserDataManager().get(user).orElseThrow(() -> new NucleusException(Text.of("User does not have a data file available"), NucleusException.ExceptionType.DOES_NOT_EXIST));
    mus.get(InvulnerabilityUserDataModule.class).setInvulnerable(invulnerable);
    user.getPlayer().ifPresent(x -> this.invulnerabilityCache.put(user.getUniqueId(), invulnerable));
    if (!mus.save()) {
        throw new NucleusException(Text.of("Could not save data"), NucleusException.ExceptionType.UNKNOWN_ERROR);
    }
}
Also used : InvulnerabilityUserDataModule(io.github.nucleuspowered.nucleus.modules.invulnerability.datamodules.InvulnerabilityUserDataModule) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) NucleusException(io.github.nucleuspowered.nucleus.api.exceptions.NucleusException)

Example 17 with ModularUserService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.

the class TeleportHereCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    boolean beQuiet = args.<Boolean>getOne("q").orElse(this.isDefaultQuiet);
    User target = args.<User>getOne(playerKey).get();
    if (target.getPlayer().isPresent()) {
        handler.getBuilder().setFrom(target.getPlayer().get()).setTo(src).setSilentSource(beQuiet).startTeleport();
    } else {
        permissions.checkSuffix(src, "offline", () -> ReturnMessageException.fromKey("command.tphere.noofflineperms"));
        // Update the offline player's next location
        ModularUserService mus = plugin.getUserDataManager().get(target).orElseThrow(() -> ReturnMessageException.fromKey("command.tphere.couldnotset", target.getName()));
        mus.get(CoreUserDataModule.class).sendToLocationOnLogin(src.getLocation());
        mus.save();
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tphere.offlinesuccess", target.getName()));
    }
    return CommandResult.success();
}
Also used : User(org.spongepowered.api.entity.living.player.User) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule)

Aggregations

ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)17 CoreUserDataModule (io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule)6 User (org.spongepowered.api.entity.living.player.User)5 Player (org.spongepowered.api.entity.living.player.Player)4 Listener (org.spongepowered.api.event.Listener)4 Text (org.spongepowered.api.text.Text)4 NamedLocation (io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)3 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)3 JailData (io.github.nucleuspowered.nucleus.modules.jail.data.JailData)3 JailUserDataModule (io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule)3 Duration (java.time.Duration)3 Instant (java.time.Instant)3 ServiceChangeListener (io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener)2 FlyUserDataModule (io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule)2 JailEvent (io.github.nucleuspowered.nucleus.modules.jail.events.JailEvent)2 NicknameUserDataModule (io.github.nucleuspowered.nucleus.modules.nickname.datamodules.NicknameUserDataModule)2 Optional (java.util.Optional)2 Subject (org.spongepowered.api.service.permission.Subject)2 UserStorageService (org.spongepowered.api.service.user.UserStorageService)2 Location (org.spongepowered.api.world.Location)2