Search in sources :

Example 21 with GameMode

use of org.spongepowered.api.entity.living.player.gamemode.GameMode in project Nucleus by NucleusPowered.

the class SetGamemodeWorldCommand method executeCommand.

@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
    GameMode gamemodeInput = args.<GameMode>getOne(gamemode).get();
    WorldProperties worldProperties = getWorldFromUserOrArgs(src, world, args);
    worldProperties.setGameMode(gamemodeInput);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setgamemode.success", worldProperties.getWorldName(), Util.getTranslatableIfPresent(gamemodeInput)));
    return CommandResult.success();
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 22 with GameMode

use of org.spongepowered.api.entity.living.player.gamemode.GameMode in project Nucleus by NucleusPowered.

the class HatCommand method executeWithPlayer.

@Override
protected CommandResult executeWithPlayer(CommandSource player, Player pl, CommandContext args, boolean isSelf) throws Exception {
    Optional<ItemStack> helmetOptional = pl.getHelmet();
    ItemStack stack = pl.getItemInHand(HandTypes.MAIN_HAND).orElseThrow(() -> ReturnMessageException.fromKey("command.generalerror.handempty"));
    ItemStack hand = stack.copy();
    hand.setQuantity(1);
    pl.setHelmet(hand);
    Text itemName = hand.get(Keys.DISPLAY_NAME).orElseGet(() -> Text.of(stack));
    GameMode gameMode = pl.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET);
    if (gameMode != GameModes.CREATIVE) {
        if (stack.getQuantity() > 1) {
            stack.setQuantity(stack.getQuantity() - 1);
            pl.setItemInHand(HandTypes.MAIN_HAND, stack);
        } else {
            pl.setItemInHand(HandTypes.MAIN_HAND, null);
        }
    }
    // If the old item can't be placed back in the subject inventory, drop the item.
    helmetOptional.ifPresent(itemStack -> Util.getStandardInventory(pl).offer(itemStack.copy()).getRejectedItems().forEach(x -> Util.dropItemOnFloorAtLocation(x, pl.getWorld(), pl.getLocation().getPosition())));
    if (!isSelf) {
        player.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.hat.success", plugin.getNameUtil().getName(pl), itemName));
    }
    pl.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.hat.successself", itemName));
    return CommandResult.success();
}
Also used : NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) Keys(org.spongepowered.api.data.key.Keys) CommandSource(org.spongepowered.api.command.CommandSource) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ItemStack(org.spongepowered.api.item.inventory.ItemStack) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) EssentialsEquivalent(io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent) Util(io.github.nucleuspowered.nucleus.Util) Player(org.spongepowered.api.entity.living.player.Player) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 23 with GameMode

use of org.spongepowered.api.entity.living.player.gamemode.GameMode in project Skree by Skelril.

the class GameModeCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The player state service is not currently running."));
        return CommandResult.empty();
    }
    PlayerStateService service = optService.get();
    GameMode mode = args.<GameMode>getOne("mode").get();
    Player target = args.<Player>getOne("target").get();
    if (service.hasInventoryStored(target) && !args.hasAny("f")) {
        src.sendMessage(Text.of(TextColors.RED, "Player has an omni-state stored, action denied."));
        src.sendMessage(Text.of(TextColors.RED, "This can be overwritten using -f."));
        return CommandResult.empty();
    }
    service.save(target, target.get(Keys.GAME_MODE).get().getId());
    target.offer(Keys.FALL_DISTANCE, 0F);
    target.offer(Keys.GAME_MODE, mode);
    service.load(target, mode.getId());
    target.sendMessage(Text.of(TextColors.YELLOW, "Changed game mode to " + mode.getName() + '.'));
    return CommandResult.success();
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Player(org.spongepowered.api.entity.living.player.Player) PlayerStateService(com.skelril.skree.service.PlayerStateService)

Aggregations

GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)23 Player (org.spongepowered.api.entity.living.player.Player)5 Optional (java.util.Optional)4 LanternGameMode (org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode)4 Entity (org.spongepowered.api.entity.Entity)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)2 Instant (java.time.Instant)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 CauseStack (org.lanternpowered.server.event.CauseStack)2 Keys (org.spongepowered.api.data.key.Keys)2 GameModes (org.spongepowered.api.entity.living.player.gamemode.GameModes)2