本文整理汇总了Java中org.spongepowered.api.command.CommandException类的典型用法代码示例。如果您正苦于以下问题:Java CommandException类的具体用法?Java CommandException怎么用?Java CommandException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandException类属于org.spongepowered.api.command包,在下文中一共展示了CommandException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
try
{
MainConfig.getConfig().load();
FactionsConfig.getConfig().load();
source.sendMessage(Text.of(PluginInfo.PluginPrefix, "Configs have been reloaded!"));
}
catch (Exception exception)
{
exception.printStackTrace();
}
return CommandResult.success();
}
示例2: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
HashSet<Faction> factionsList = new HashSet<>(FactionLogic.getFactions());
List<Text> helpList = new ArrayList<>();
for(Faction faction: factionsList)
{
String tag = "";
if(faction.Tag != null && !faction.Tag.equals("")) tag = "[" + faction.Tag + "] ";
Text factionHelp = Text.builder()
.append(Text.builder()
.append(Text.of(TextColors.AQUA, "- " + tag + faction.Name + " (" + faction.Power + "/" + PowerService.getFactionMaxPower(faction) + ")"))
.build())
.build();
helpList.add(factionHelp);
}
PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
PaginationList.Builder paginationBuilder = paginationService.builder().title(Text.of(TextColors.GREEN, "Factions List")).padding(Text.of("-")).contents(helpList);
paginationBuilder.sendTo(source);
return CommandResult.success();
}
示例3: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
/**
* Callback for the execution of a command.
*
* @param src The commander who is executing this command
* @param args The parsed command arguments for this command
* @return the result of executing this command
* @throws CommandException If a user-facing error occurs while executing this command
*/
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player))
return execServer(src, args);
Player player = (Player) src;
Region region = new Region(player.getLocation());
LoadedRegion.ChunkType type = args.<LoadedRegion.ChunkType>getOne("type").orElse(LoadedRegion.ChunkType.WORLD);
LoadedRegion loadedRegion = new LoadedRegion(region, player, type);
if (dataStore.isRegionLoaded(loadedRegion))
throw new CommandException(Text.of(TextColors.RED, "You've already allocated this region."));
loadedRegion.assignTicket();
if (loadedRegion.isValid())
throw new CommandException(Text.of(TextColors.RED, "Failed to allocate a loading ticket and force region."));
dataStore.addPlayerRegion(player, loadedRegion);
loadedRegion.forceChunks();
database.saveRegionData(loadedRegion);
player.sendMessage(Text.of(TextColors.GREEN, "Successfully loaded the region."));
return CommandResult.success();
}
示例4: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
if (virtualCrate == null) {
commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
return CommandResult.empty();
}
commandSource.sendMessage(Text.of("Gave everyone " + quantity + " vkeys."));
virtualCrate.givePlayersVirtualKeys(Sponge.getServer().getOnlinePlayers(),quantity);
for(Player e: Sponge.getServer().getOnlinePlayers()){
if(commandSource != e) {
e.sendMessage(Text.of(TextColors.GREEN,"You received " + quantity + " virtual keys for a ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),"."));
}
}
}else{
commandSource.sendMessage(Text.of("Usage: /crate vkeyall <id> [count]"));
}
return CommandResult.success();
}
示例5: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if (!(commandSource instanceof Player)) {
commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
return CommandResult.empty();
}
Player plr = (Player)commandSource;
if(!plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
commandSource.sendMessage(Text.of("You must be holding an item to deposit a key."));
return CommandResult.empty();
}
ItemStack key = plr.getItemInHand(HandTypes.MAIN_HAND).get();
if(HuskyCrates.instance.crateUtilities.vcFromKey(key) == null){
commandSource.sendMessage(Text.of(TextColors.RED,"Not a valid key."));
return CommandResult.empty();
}
VirtualCrate virtualCrate = HuskyCrates.instance.crateUtilities.vcFromKey(plr.getItemInHand(HandTypes.MAIN_HAND).get());
int keyCount = key.getQuantity();
plr.setItemInHand(HandTypes.MAIN_HAND,null);
virtualCrate.giveVirtualKeys(plr,keyCount);
//commandSource.sendMessage(Text.of(TextColors.GREEN,"Successfully deposited " + keyCount + " ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),TextColors.GREEN," Key(s)."));
commandSource.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(
virtualCrate.getLangData().formatter(virtualCrate.getLangData().depositSuccess,null,plr,virtualCrate,null,null,keyCount)
));
return CommandResult.success();
}
示例6: backpackcheck
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
private void backpackcheck(Player player) throws CommandException {
Path file = Paths.get(this.vt.getConfigPath() + File.separator + "backpacks" + File.separator + player.getUniqueId().toString() + ".backpack");
if (!Files.exists(file)) {
throw new CommandPermissionException(Text.of("Sorry there is no backpack data for " + player.getName()));
} else {
String content = null;
try {
content = new String(Files.readAllBytes(file), "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
if (content == "{}") {
throw new CommandPermissionException(Text.of("Sorry there is no backpack data for " + player.getName()));
}
}
}
示例7: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
final Optional<User> optionalUser = args.getOne("player");
if (!optionalUser.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, "You must specify an existing user."));
}
final Optional<InetAddress> optionalIP = args.getOne("ip");
if (!optionalIP.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, "You must specify a proper IP address."));
}
final User user = optionalUser.get();
final InetAddress ip = optionalIP.get();
Sponge.getScheduler().createAsyncExecutor(IPLog.getPlugin()).execute(() -> IPLog.getPlugin().getStorage().purgeConnection(ip, user.getUniqueId()));
src.sendMessage(Text.of(TextColors.YELLOW, "You have successfully removed the specified connection from the database."));
return CommandResult.success();
}
示例8: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src.hasPermission("*") || src.hasPermission("listener.admin"))
{
Boolean clear = SwitchSQL.Clearqueue();
if(clear){
src.sendMessage(Text.of("Cleared successful"));
return CommandResult.success();
}
else{
src.sendMessage(Text.of("Cleared fail"));
return CommandResult.empty();
}
}else{
src.sendMessage(Text.of("You don't have permission"));
return CommandResult.empty();
}
}
示例9: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if ((src.hasPermission("*")) || (src.hasPermission("listener.admin")))
{
String player = args.<String>getOne("player").get();
int vote = args.<Integer>getOne("vote").get();
long CurrentMiliseconde = System.currentTimeMillis();
boolean succes = SwitchSQL.Voted(player, vote, CurrentMiliseconde);
if(succes){
src.sendMessage(Text.of("Vote set for "+player+" : "+String.valueOf(vote)));
return CommandResult.success();
}else{
src.sendMessage(Text.of("an error has occurred"));
return CommandResult.success();
}
}else{
src.sendMessage(Text.of("You don't have permission"));
return CommandResult.empty();
}
}
示例10: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src.hasPermission("*") || src.hasPermission("listener.admin"))
{
List<String> player = SwitchSQL.QueuePlayer();
for(int i = 0; i < player.size(); i++)
{
String username = player.get(i);
List<String> service = SwitchSQL.QueueReward(username);
for(int x = 0; x < service.size(); x++)
{
RewardsTask.Notonline(username, service.get(x));
SwitchSQL.removeQueue(username, service.get(x));
}
}
}
return CommandResult.success();
}
示例11: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src.hasPermission("*") || src.hasPermission("listener.admin"))
{
Boolean clear = SwitchSQL.Cleartotals();
if(clear){
src.sendMessage(Text.of("Cleared successful"));
return CommandResult.success();
}
else{
src.sendMessage(Text.of("Cleared fail"));
return CommandResult.empty();
}
}else{
src.sendMessage(Text.of("You don't have permission"));
return CommandResult.empty();
}
}
示例12: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource sender, CommandContext arguments) throws CommandException {
Optional<String> optionalArg1 = arguments.getOne("arg1");
if (optionalArg1.isPresent()) {
List<String> subCmdArgs = new ArrayList<>();
arguments.<String>getOne("arg2").ifPresent(subCmdArgs::add);
for (Cmd subCmd : subCmds) {
if (subCmd.getCommand().equalsIgnoreCase(optionalArg1.get())) {
subCmd.run(sender, subCmdArgs.toArray(new String[subCmdArgs.size()]));
return CommandResult.success();
}
}
sendHelp(sender);
} else {
sendHelp(sender);
}
return CommandResult.success();
}
示例13: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
List<Camera> cams = new ArrayList<>(plugin.getCameras().values());
cams.removeIf((cam)-> !cam.canUseCamera(src));
Iterable<Text> texts = cams.parallelStream().map((cam)->
plugin.translations.CAMERA_LIST_ITEM.apply(cam.templateVariables())
.onHover(TextActions.showText(
plugin.translations.CAMERA_LIST_ITEM_HOVER.apply(cam.templateVariables()).build()
))
.onClick(TextActions.runCommand("/camera view " + cam.getId())).build()
).collect(Collectors.toList());
PaginationList.builder()
.title(plugin.translations.CAMERA_LIST_TITLE)
.contents(texts)
.sendTo(src);
return CommandResult.success();
}
示例14: execute
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException {
//https://docs.spongepowered.org/stable/zh-CN/plugin/commands/arguments.html?highlight=commandcontext
if (context.hasAny("arg")) {
String[] args = context.<String>getOne("arg").get().split(" ");
for (CommandHandler handler : this.handlerList) {
if (args[0].equalsIgnoreCase(handler.getName()) && handler.hasPermission(source)) {
if (!handler.hasPermission(source)) {//如果命令已禁用后台执行并且执行者是后台
if (source instanceof Player) {
source.sendMessage(TextUtil.of("§c你没有执行该命令的权限."));
} else {
source.sendMessage(TextUtil.of("§c后台无法执行该命令."));
}
} else {//否则
handler.execute(source, args.length == 1 ? new String[0] : Util.subArray(args, 1, args.length - 1));
return CommandResult.success();
}
}
}
}
source.sendMessage(TextUtil.of("§2输入/" + McrmbPluginInfo.config.command + " help §2来查看帮助"));
return CommandResult.success();
}
示例15: process
import org.spongepowered.api.command.CommandException; //导入依赖的package包/类
@Override public CommandResult process(CommandSource source, String arguments) throws CommandException {
// Get the first argument, is it a child?
final CommandArgs args = new CommandArgs(arguments, tokenizer.tokenize(arguments, false));
Optional<CommandSpec> optionalSpec = getSpec(args);
if (optionalSpec.isPresent()) {
CommandSpec spec = optionalSpec.get();
CommandContext context = new CommandContext();
spec.checkPermission(source);
spec.populateContext(source, args, context);
return spec.getExecutor().execute(source, context);
}
if (testPermission(source)) {
// Else, what do we want to do here?
source.sendMessage(Text.of("Phonon from Nucleus."));
return CommandResult.success();
}
throw new CommandPermissionException();
}