Search in sources :

Example 1 with VanishUserDataModule

use of io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule in project Nucleus by NucleusPowered.

the class VanishCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    User ou = getUserFromArgs(User.class, src, player, args);
    if (ou.getPlayer().isPresent()) {
        return onPlayer(src, args, ou.getPlayer().get());
    }
    if (!permissions.testSuffix(ou, "persist")) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.vanish.noperm", ou.getName()));
    }
    VanishUserDataModule uss = Nucleus.getNucleus().getUserDataManager().getUnchecked(ou).get(VanishUserDataModule.class);
    uss.setVanished(args.<Boolean>getOne(b).orElse(!uss.isVanished()));
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.vanish.successuser", ou.getName(), uss.isVanished() ? plugin.getMessageProvider().getMessageWithFormat("command.vanish.vanished") : plugin.getMessageProvider().getMessageWithFormat("command.vanish.visible")));
    return CommandResult.success();
}
Also used : User(org.spongepowered.api.entity.living.player.User) VanishUserDataModule(io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Example 2 with VanishUserDataModule

use of io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule in project Nucleus by NucleusPowered.

the class VanishService method vanishPlayerInternal.

private void vanishPlayerInternal(Player player) {
    VanishUserDataModule service = Nucleus.getNucleus().getUserDataManager().getUnchecked(player).get(VanishUserDataModule.class);
    if (service.isVanished()) {
        player.offer(Keys.VANISH, true);
        player.offer(Keys.VANISH_IGNORES_COLLISION, true);
        player.offer(Keys.VANISH_PREVENTS_TARGETING, true);
        if (this.isAlter) {
            Sponge.getServer().getOnlinePlayers().stream().filter(x -> !player.equals(x) || !x.hasPermission(this.canseePerm)).forEach(x -> x.getTabList().removeEntry(player.getUniqueId()));
        }
    }
}
Also used : Nucleus(io.github.nucleuspowered.nucleus.Nucleus) Keys(org.spongepowered.api.data.key.Keys) VanishCommand(io.github.nucleuspowered.nucleus.modules.vanish.commands.VanishCommand) Collection(java.util.Collection) VanishConfigAdapter(io.github.nucleuspowered.nucleus.modules.vanish.config.VanishConfigAdapter) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) Maps(com.google.common.collect.Maps) VanishUserDataModule(io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule) TabList(org.spongepowered.api.entity.living.player.tab.TabList) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) List(java.util.List) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) Map(java.util.Map) Task(org.spongepowered.api.scheduler.Task) Player(org.spongepowered.api.entity.living.player.Player) TabListEntry(org.spongepowered.api.entity.living.player.tab.TabListEntry) VanishUserDataModule(io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule)

Example 3 with VanishUserDataModule

use of io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule in project Nucleus by NucleusPowered.

the class VanishService method vanishPlayer.

public void vanishPlayer(Player player, boolean delay) {
    VanishUserDataModule service = Nucleus.getNucleus().getUserDataManager().getUnchecked(player).get(VanishUserDataModule.class);
    service.setVanished(true);
    if (delay) {
        Task.builder().execute(() -> vanishPlayerInternal(player)).delayTicks(0).name("Nucleus Vanish runnable").submit(Nucleus.getNucleus());
    } else {
        vanishPlayerInternal(player);
    }
}
Also used : VanishUserDataModule(io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule)

Example 4 with VanishUserDataModule

use of io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule in project Nucleus by NucleusPowered.

the class VanishService method unvanishPlayer.

public void unvanishPlayer(Player player) {
    VanishUserDataModule service = Nucleus.getNucleus().getUserDataManager().getUnchecked(player).get(VanishUserDataModule.class);
    service.setVanished(false);
    player.offer(Keys.VANISH, false);
    player.offer(Keys.VANISH_IGNORES_COLLISION, false);
    player.offer(Keys.VANISH_PREVENTS_TARGETING, false);
    if (this.isAlter) {
        Sponge.getServer().getOnlinePlayers().forEach(x -> {
            if (!x.getTabList().getEntry(player.getUniqueId()).isPresent()) {
                x.getTabList().addEntry(TabListEntry.builder().displayName(Text.of(player.getName())).profile(player.getProfile()).gameMode(player.gameMode().get()).latency(player.getConnection().getLatency()).list(x.getTabList()).build());
            }
        });
    }
}
Also used : VanishUserDataModule(io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule)

Aggregations

VanishUserDataModule (io.github.nucleuspowered.nucleus.modules.vanish.datamodules.VanishUserDataModule)4 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)1 VanishCommand (io.github.nucleuspowered.nucleus.modules.vanish.commands.VanishCommand)1 VanishConfigAdapter (io.github.nucleuspowered.nucleus.modules.vanish.config.VanishConfigAdapter)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Sponge (org.spongepowered.api.Sponge)1 Keys (org.spongepowered.api.data.key.Keys)1 Player (org.spongepowered.api.entity.living.player.Player)1 User (org.spongepowered.api.entity.living.player.User)1 TabList (org.spongepowered.api.entity.living.player.tab.TabList)1 TabListEntry (org.spongepowered.api.entity.living.player.tab.TabListEntry)1 Task (org.spongepowered.api.scheduler.Task)1 Text (org.spongepowered.api.text.Text)1