use of org.spongepowered.api.command.CommandResult in project Skree by Skelril.
the class RegionListMembersCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
Region ref = optRef.get();
UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Text> result = ref.getMembers().stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Members")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandResult in project SpongeCommon by SpongePowered.
the class MixinServerCommandManager method executeCommand.
/**
* @author zml
*
* Purpose: Reroute MC command handling through Sponge
* Reasoning: All commands should go through one system -- we need none of the MC handling code
*/
@Override
public int executeCommand(ICommandSender sender, String command) {
command = command.trim();
if (command.startsWith("/")) {
command = command.substring(1);
}
CommandSource source = WrapperCommandSource.of(sender);
CommandResult result = SpongeImpl.getGame().getCommandManager().process(source, command);
updateStat(sender, CommandResultStats.Type.AFFECTED_BLOCKS, result.getAffectedBlocks());
updateStat(sender, CommandResultStats.Type.AFFECTED_ENTITIES, result.getAffectedEntities());
updateStat(sender, CommandResultStats.Type.AFFECTED_ITEMS, result.getAffectedItems());
updateStat(sender, CommandResultStats.Type.QUERY_RESULT, result.getQueryResult());
updateStat(sender, CommandResultStats.Type.SUCCESS_COUNT, result.getSuccessCount());
return result.getSuccessCount().orElse(0);
// return super.executeCommand(sender, command); // Try Vanilla instead
}
use of org.spongepowered.api.command.CommandResult in project AtherysCore by Atherys-Horizons.
the class PartyInviteCommand method execute.
@Nonnull
@Override
public CommandResult execute(@Nonnull User user, @Nonnull CommandContext args) throws CommandException {
Optional<Player> invitee = args.getOne("invitedPlayer");
if (!invitee.isPresent())
return CommandResult.empty();
// if invitee is already in another party, don't invite
if (PartyManager.getInstance().hasPlayerParty(invitee.get())) {
PartyMsg.error(user, "That player is already in another party.");
return CommandResult.success();
}
Optional<Party> playerParty = PartyManager.getInstance().getPlayerParty(user);
if (playerParty.isPresent() && playerParty.get().isLeader(user)) {
// If player has party and is leader of that party, invitee will be invited to player's party
Party party = playerParty.get();
Question q = Question.of(Text.of(user.getName(), " has invited you to their party. Would you like to join?")).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_GREEN, "Yes"), (respondent) -> {
party.addPlayer(respondent);
PartyMsg.info(party, respondent.getName(), " has joined your party!");
})).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_RED, "No"), (respondent) -> PartyMsg.error(user, respondent.getName(), " has refused to join your party."))).build();
q.pollChat(invitee.get());
} else {
// If player does not have a party, and neither does invitee, then the party will be created when invitee accepts party invite
Question q = Question.of(Text.of(user.getName(), " has invited you to their party. Would you like to join?")).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_GREEN, "Yes"), (respondent) -> {
if (!user.isOnline()) {
// If when party invite is accepted, player is offline, party will not be created.
PartyMsg.error(respondent, user.getName(), " has gone offline since sending you that invite. Party could not be created. Sorry!");
return;
}
Party party = Party.of(user, invitee.get());
PartyMsg.info(party, "Your party has been created! Do ", TextColors.GREEN, TextStyles.BOLD, "/party", TextColors.DARK_AQUA, TextStyles.RESET, " for a list of members.");
})).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_RED, "No"), (respondent) -> PartyMsg.error(user, respondent.getName(), " has refused to join your party."))).build();
q.pollChat(invitee.get());
}
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandResult in project ProjectWorlds by trentech.
the class CommandLoad method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("load")) {
throw new CommandException(getHelp().getUsageText());
}
if (arguments.equalsIgnoreCase("--help")) {
help.execute(source);
return CommandResult.success();
}
Optional<WorldProperties> optionalWorld = Sponge.getServer().getWorldProperties(arguments);
if (!optionalWorld.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, arguments, " does not exist"), false);
}
WorldProperties world = optionalWorld.get();
if (Sponge.getServer().getWorld(world.getUniqueId()).isPresent()) {
throw new CommandException(Text.of(TextColors.RED, world.getWorldName(), " is already loaded"), false);
}
WorldData worldData = new WorldData(world.getWorldName());
if (!worldData.exists()) {
throw new CommandException(Text.of(TextColors.RED, world.getWorldName(), " does not exist"), false);
}
SpongeData spongeData = new SpongeData(world.getWorldName());
if (!spongeData.exists()) {
source.sendMessage(Text.of(TextColors.RED, "Foriegn world detected"));
source.sendMessage(Text.builder().color(TextColors.YELLOW).onHover(TextActions.showText(Text.of("Click command for more information "))).onClick(TextActions.runCommand("/pjw:world import")).append(Text.of(" /world import")).build());
return CommandResult.success();
}
source.sendMessage(Text.of(TextColors.YELLOW, "Preparing spawn area. This may take a minute."));
Task.builder().delayTicks(20).execute(c -> {
Optional<World> load = Sponge.getServer().loadWorld(world);
if (!load.isPresent()) {
source.sendMessage(Text.of(TextColors.RED, "Could not load ", world.getWorldName()));
return;
}
if (CommandCreate.worlds.contains(world.getWorldName())) {
Utils.createPlatform(load.get().getSpawnLocation().getRelative(Direction.DOWN));
CommandCreate.worlds.remove(world.getWorldName());
}
source.sendMessage(Text.of(TextColors.DARK_GREEN, world.getWorldName(), " loaded successfully"));
}).submit(Main.getPlugin());
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandResult in project ProjectWorlds by trentech.
the class CommandRegen method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("regen")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
getHelp().execute(source);
return CommandResult.success();
}
String worldName;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<WorldProperties> optionalProperties = Sponge.getServer().getWorldProperties(worldName);
if (!optionalProperties.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " does not exist"), false);
}
WorldProperties properties = optionalProperties.get();
if (Sponge.getServer().getWorld(properties.getWorldName()).isPresent()) {
throw new CommandException(Text.of(TextColors.RED, properties.getWorldName(), " must be unloaded before you can regenerate"), false);
}
WorldArchetype.Builder builder = WorldArchetype.builder().from(properties);
String bool;
try {
bool = args[1];
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
source.sendMessage(Text.of(TextColors.YELLOW, bool, " is not a valid Boolean"));
throw new CommandException(getHelp().getUsageText());
}
String seed;
try {
seed = args[2];
try {
Long s = Long.parseLong(seed);
builder.seed(s);
} catch (Exception e) {
builder.seed(seed.hashCode());
}
} catch (Exception e) {
builder.randomSeed();
}
} catch (Exception e) {
}
try {
CompletableFuture<Boolean> delete = Sponge.getServer().deleteWorld(properties);
while (!delete.isDone()) {
}
if (!delete.get()) {
throw new CommandException(Text.of(TextColors.RED, "Could not delete ", properties.getWorldName()), false);
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Regenerating world.."));
WorldArchetype settings = builder.enabled(true).loadsOnStartup(true).build(properties.getWorldName() + "_" + (ThreadLocalRandom.current().nextInt(100) + 1), properties.getWorldName());
WorldProperties newProperties;
try {
newProperties = Sponge.getServer().createWorldProperties(properties.getWorldName(), settings);
} catch (IOException e) {
e.printStackTrace();
throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
}
Task.builder().delayTicks(20).execute(c -> {
Optional<World> load = Sponge.getServer().loadWorld(newProperties);
if (!load.isPresent()) {
source.sendMessage(Text.of(TextColors.RED, "Could not load ", properties.getWorldName()));
return;
}
Utils.createPlatform(load.get().getSpawnLocation().getRelative(Direction.DOWN));
source.sendMessage(Text.of(TextColors.DARK_GREEN, properties.getWorldName(), " regenerated successfully"));
}).submit(Main.getPlugin());
return CommandResult.success();
}
Aggregations