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

82 lines
2.3 KiB
Java
Raw Normal View History

2015-07-30 16:25:16 +02:00
package com.plotsquared.sponge.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
2015-09-06 03:53:56 +02:00
import org.spongepowered.api.entity.player.Player;
2015-07-30 16:25:16 +02:00
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.CommandCallable;
import org.spongepowered.api.util.command.CommandException;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.sponge.SpongeMain;
2015-09-11 12:09:22 +02:00
public class SpongeCommand implements CommandCallable
{
2015-07-30 16:25:16 +02:00
@Override
2015-09-11 12:09:22 +02:00
public CommandResult process(final CommandSource cmd, final String string) throws CommandException
{
final String id = cmd.getIdentifier();
2015-07-30 16:25:16 +02:00
PlotPlayer pp;
2015-09-11 12:09:22 +02:00
try
{
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-11 12:09:22 +02:00
catch (final Exception e)
{
2015-07-30 16:25:16 +02:00
pp = ConsolePlayer.getConsole();
}
2015-09-11 12:09:22 +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-11 12:09:22 +02:00
else
{
2015-07-30 16:25:16 +02:00
return CommandResult.empty();
}
}
@Override
2015-09-11 12:09:22 +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<>(Arrays.asList("TEST"));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean testPermission(final CommandSource cmd)
{
2015-07-30 16:25:16 +02:00
return true;
}
@Override
2015-09-11 12:09:22 +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"));
}
@Override
2015-09-11 12:09:22 +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"));
}
@Override
2015-09-11 12:09:22 +02:00
public Text getUsage(final CommandSource cmd)
{
2015-07-30 16:25:16 +02:00
return Texts.of("/plot <command>");
}
2015-09-11 12:09:22 +02:00
2015-07-30 16:25:16 +02:00
}