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();
}
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();
}
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();
}
Aggregations