2015-07-30 16:25:16 +02:00
|
|
|
package com.plotsquared.sponge.util;
|
|
|
|
|
2016-02-14 02:01:18 +01:00
|
|
|
import com.intellectualcrafters.plot.commands.MainCommand;
|
|
|
|
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2016-02-25 10:13:07 +01:00
|
|
|
import com.intellectualcrafters.plot.util.TaskManager;
|
2016-02-14 02:01:18 +01:00
|
|
|
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;
|
|
|
|
|
2016-04-02 07:30:26 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class SpongeCommand implements CommandCallable {
|
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2016-06-03 01:38:35 +02:00
|
|
|
public CommandResult process(CommandSource source, String arguments) throws CommandException {
|
2016-03-26 20:47:34 +01:00
|
|
|
TaskManager.runTask(() -> {
|
2016-06-03 01:38:35 +02:00
|
|
|
String id = source.getIdentifier();
|
|
|
|
PlotPlayer plotPlayer = null;
|
2016-03-26 20:47:34 +01:00
|
|
|
try {
|
2016-04-02 07:30:26 +02:00
|
|
|
UUID uuid = UUID.fromString(id);
|
2016-06-03 01:38:35 +02:00
|
|
|
|
|
|
|
Optional<Player> player = SpongeMain.THIS.getServer().getPlayer(uuid);
|
|
|
|
if (player.isPresent()) {
|
|
|
|
plotPlayer = SpongeUtil.getPlayer(player.get());
|
|
|
|
}
|
2016-05-12 23:09:35 +02:00
|
|
|
} catch (Exception ignored) {
|
2016-06-03 01:38:35 +02:00
|
|
|
plotPlayer = ConsolePlayer.getConsole();
|
2016-02-25 10:13:07 +01:00
|
|
|
}
|
2016-06-03 01:38:35 +02:00
|
|
|
MainCommand.onCommand(plotPlayer, arguments.isEmpty() ? new String[]{} : arguments.split(" "));
|
2016-02-25 10:13:07 +01:00
|
|
|
});
|
|
|
|
return CommandResult.success();
|
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
|
2016-06-03 01:38:35 +02:00
|
|
|
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
|
2016-02-23 19:12:07 +01:00
|
|
|
if (!(source instanceof Player)) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-02 07:30:26 +02:00
|
|
|
PlotPlayer player = SpongeUtil.getPlayer((Player) source);
|
2016-06-03 01:38:35 +02:00
|
|
|
String[] args = arguments.split(" ");
|
2016-03-26 20:47:34 +01:00
|
|
|
if (args.length == 0) {
|
|
|
|
return Collections.singletonList(MainCommand.getInstance().toString());
|
2016-02-23 19:12:07 +01:00
|
|
|
}
|
2016-06-03 01:38:35 +02:00
|
|
|
Collection objects = MainCommand.getInstance().tab(player, args, arguments.endsWith(" "));
|
2016-03-26 20:47:34 +01:00
|
|
|
if (objects == null) {
|
|
|
|
return null;
|
2016-02-23 19:12:07 +01:00
|
|
|
}
|
2016-03-26 20:47:34 +01:00
|
|
|
List<String> result = new ArrayList<>();
|
|
|
|
for (Object o : objects) {
|
|
|
|
result.add(o.toString());
|
2016-02-23 19:12:07 +01:00
|
|
|
}
|
2016-04-02 07:30:26 +02:00
|
|
|
return result.isEmpty() ? null : result;
|
2016-02-23 19:12:07 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2016-06-03 01:38:35 +02:00
|
|
|
public boolean testPermission(CommandSource source) {
|
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
|
2016-06-03 01:38:35 +02:00
|
|
|
public Optional<Text> getShortDescription(CommandSource source) {
|
2016-02-19 18:45:43 +01:00
|
|
|
return Optional.of(Text.of("Shows plot help"));
|
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
|
2016-06-03 01:38:35 +02:00
|
|
|
public Optional<Text> getHelp(CommandSource source) {
|
2016-03-26 20:47:34 +01:00
|
|
|
return Optional.of(Text.of("/plot"));
|
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
|
2016-06-03 01:38:35 +02:00
|
|
|
public Text getUsage(CommandSource source) {
|
2016-02-19 18:45:43 +01:00
|
|
|
return Text.of("/plot <command>");
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|