Search in sources :

Example 6 with GameMode

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

the class IgniteCommand method executeWithPlayer.

@Override
protected CommandResult executeWithPlayer(CommandSource pl, Player target, CommandContext args, boolean isSelf) throws Exception {
    int ticksInput = args.<Integer>getOne(ticks).get();
    GameMode gm = target.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL);
    if (gm == GameModes.CREATIVE || gm == GameModes.SPECTATOR) {
        pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ignite.gamemode", target.getName()));
        return CommandResult.empty();
    }
    if (target.offer(Keys.FIRE_TICKS, ticksInput).isSuccessful()) {
        pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ignite.success", target.getName(), String.valueOf(ticksInput)));
        return CommandResult.success();
    } else {
        pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ignite.error", target.getName()));
        return CommandResult.empty();
    }
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode)

Example 7 with GameMode

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

the class GamemodeCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Player user;
    if (args.hasAny(MarkerArgument.MARKER)) {
        user = this.getUserFromArgs(Player.class, src, userKey, args);
    } else {
        user = this.getUserFromArgs(Player.class, src, "thisisjunk", args);
    }
    Optional<GameMode> ogm = args.getOne(gamemodeKey);
    if (!ogm.isPresent()) {
        String mode = user.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).getName();
        if (src.equals(user)) {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.gamemode.get.base", mode));
        } else {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.gamemode.get.other", user.getName(), mode));
        }
        return CommandResult.success();
    }
    GameMode gm = ogm.get();
    return baseCommand(src, user, gm);
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Player(org.spongepowered.api.entity.living.player.Player)

Example 8 with GameMode

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

the class SuicideCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    GameMode gm = src.gameMode().getDirect().orElse(src.gameMode().getDefault());
    if (gm != GameModes.SURVIVAL && gm != GameModes.NOT_SET) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.suicide.wronggm"));
        return CommandResult.empty();
    }
    src.offer(Keys.HEALTH, 0d);
    return CommandResult.success();
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode)

Example 9 with GameMode

use of org.spongepowered.api.entity.living.player.gamemode.GameMode in project SpongeCommon by SpongePowered.

the class LevelStemMixin method bridge$populateFromLevelData.

@Override
public void bridge$populateFromLevelData(final PrimaryLevelData levelData) {
    final PrimaryLevelDataBridge levelDataBridge = (PrimaryLevelDataBridge) levelData;
    this.impl$gameMode = (ResourceLocation) (Object) RegistryTypes.GAME_MODE.get().valueKey((GameMode) (Object) levelData.getGameType());
    this.impl$difficulty = (ResourceLocation) (Object) RegistryTypes.DIFFICULTY.get().valueKey((Difficulty) (Object) levelData.getDifficulty());
    this.impl$serializationBehavior = levelDataBridge.bridge$serializationBehavior().orElse(null);
    this.impl$displayName = levelDataBridge.bridge$displayName().orElse(null);
    this.impl$viewDistance = levelDataBridge.bridge$viewDistance().orElse(null);
    this.impl$spawnPosition = new Vector3i(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn());
    this.impl$loadOnStartup = levelDataBridge.bridge$loadOnStartup();
    this.impl$performsSpawnLogic = levelDataBridge.bridge$performsSpawnLogic();
    this.impl$hardcore = levelData.isHardcore();
    this.impl$commands = levelData.getAllowCommands();
    this.impl$pvp = levelDataBridge.bridge$pvp().orElse(null);
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) Vector3i(org.spongepowered.math.vector.Vector3i) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)

Example 10 with GameMode

use of org.spongepowered.api.entity.living.player.gamemode.GameMode in project SpongeCommon by SpongePowered.

the class SpongeTabList method addEntry.

private void addEntry(final ClientboundPlayerInfoPacket.PlayerUpdate entry) {
    final GameProfile profile = entry.getProfile();
    if (!this.entries.containsKey(profile.getId())) {
        final net.minecraft.network.chat.Component displayName = entry.getDisplayName();
        this.addEntry(new SpongeTabListEntry(this, SpongeGameProfile.of(profile), displayName == null ? null : SpongeAdventure.asAdventure(displayName), entry.getLatency(), (GameMode) (Object) entry.getGameMode()), false);
    }
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) GameProfile(com.mojang.authlib.GameProfile) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile)

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