PlotSquared/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java

68 lines
2.3 KiB
Java
Raw Normal View History

2015-07-30 16:25:16 +02:00
package com.plotsquared.sponge.util;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.sponge.SpongeMain;
2015-12-19 20:30:06 +01:00
import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
2015-10-07 08:33:33 +02:00
import org.spongepowered.api.entity.living.player.Player;
2015-07-30 16:25:16 +02:00
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
2015-07-30 16:25:16 +02:00
2015-09-13 06:04:31 +02:00
public class SpongeCommand implements CommandCallable {
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public CommandResult process(final CommandSource cmd, final String string) throws CommandException {
2015-09-11 12:09:22 +02:00
final String id = cmd.getIdentifier();
2015-07-30 16:25:16 +02:00
PlotPlayer pp;
2015-09-13 06:04:31 +02:00
try {
2015-09-11 12:09:22 +02:00
final UUID uuid = UUID.fromString(id);
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
2015-07-30 16:25:16 +02:00
pp = SpongeUtil.getPlayer(player);
2015-09-13 06:04:31 +02:00
} catch (final Exception e) {
2015-07-30 16:25:16 +02:00
pp = ConsolePlayer.getConsole();
}
2015-09-13 06:04:31 +02:00
if (MainCommand.onCommand(pp, cmd.getName(), string.length() == 0 ? new String[] {} : string.split(" "))) {
2015-07-30 16:25:16 +02:00
return CommandResult.success();
2015-09-13 06:04:31 +02:00
} else {
2015-07-30 16:25:16 +02:00
return CommandResult.empty();
}
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public List<String> getSuggestions(final CommandSource cmd, final String string) throws CommandException {
2015-07-30 16:25:16 +02:00
// TODO Auto-generated method stub
return new ArrayList<>(Collections.singletonList("TEST"));
2015-07-30 16:25:16 +02:00
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public boolean testPermission(final CommandSource cmd) {
2015-07-30 16:25:16 +02:00
return true;
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public Optional<? extends Text> getShortDescription(final CommandSource cmd) {
2015-07-30 16:25:16 +02:00
return Optional.of(Texts.of("Shows plot help"));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public Optional<? extends Text> getHelp(final CommandSource cmd) {
2015-07-30 16:25:16 +02:00
return Optional.of(Texts.of("/plot help"));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public Text getUsage(final CommandSource cmd) {
2015-07-30 16:25:16 +02:00
return Texts.of("/plot <command>");
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
}