本文整理汇总了Java中org.spongepowered.api.command.CommandSource类的典型用法代码示例。如果您正苦于以下问题:Java CommandSource类的具体用法?Java CommandSource怎么用?Java CommandSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandSource类属于org.spongepowered.api.command包,在下文中一共展示了CommandSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseValue
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Nullable
@Override
protected Object parseValue(CommandSource src, CommandArgs args) throws ArgumentParseException {
String arg = args.next().toLowerCase();
if(plugin.getCameras().containsKey(arg)){
Camera cam = plugin.getCameras().get(arg);
if(cam.canUseCamera(src)){
return cam;
}
}
throw args.createError(
plugin.translations.UNKNOWN_CAMERA_ID.apply(
ImmutableMap.of("camera.id", arg)
).build()
);
}
示例2: execute
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Override
public boolean execute(CommandSource source, String[] args) {
if (args.length != 2) {
source.sendMessage(TextUtil.of("§c/" + McrmbPluginInfo.config.command + " setup <SID> <KEY>"));
return true;
}
String sid = args[0];
String key = args[1];
McrmbPluginInfo.config.sid = sid;
McrmbPluginInfo.config.key = key;
McrmbPluginInfo.save();
source.sendMessages(
TextUtil.of("§2已将SID设置为§a" + sid + ", §2KEY设置为§a" + key + "."),
TextUtil.of("§2正在为您重新获取卡种...")
);
Task.builder().name("reload-card-types").execute(() -> {
CardTypesManager.init();
source.sendMessage(TextUtil.of("§2卡种重新获取完成, 详情请查看后台输出."));
}).submit(McrmbCoreMain.instance());
return true;
}
示例3: execute
import org.spongepowered.api.command.CommandSource; //导入依赖的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();
}
示例4: accumulateContexts
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Override
public void accumulateContexts(Subject calculable, Set<Context> accumulator)
{
Optional<CommandSource> sourceOptional = calculable.getCommandSource();
if (sourceOptional.isPresent())
{
CommandSource source = sourceOptional.get();
if (source instanceof Identifiable)
{
UUID uuid = ((Identifiable) source).getUniqueId();
if (this.plugin.getVirtualChestActions().isPlayerActivated(uuid))
{
accumulator.add(this.contextInAction);
SubjectData data = source.getTransientSubjectData();
Map<String, Boolean> permissions = data.getPermissions(Collections.singleton(this.contextInAction));
this.logger.debug("Ignored {} permission(s) for {} (context):", permissions.size(), uuid);
permissions.forEach((permission, state) -> this.logger.debug("- {} ({})", permission, state));
}
else
{
accumulator.add(this.contextNotInAction);
}
}
}
}
示例5: execute
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of(TextColors.RED, "Only players can use this command!"));
return CommandResult.empty();
}
LookupResult result = LookupResultManager.instance().getLookupResult((Player) src);
if (result == null) {
src.sendMessage(Text.of(TextColors.DARK_AQUA, "[AS] ", TextColors.YELLOW, "You have no lookup history!"));
return CommandResult.empty();
}
int page = result.getLastSeenPage() + 1;
if (page > result.getPages(LookupResultManager.instance().getLinesPerPage())) {
src.sendMessage(Text.of(TextColors.DARK_AQUA, "[AS] ", TextColors.YELLOW, "Already on the last page!"));
return CommandResult.empty();
}
result.showPage((Player) src, page);
return CommandResult.success();
}
示例6: complete
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
try {
String arg = args.peek().toLowerCase();
return Sponge.getRegistry().getAllOf(this.type).stream()
.filter(x ->
x.getId().startsWith(arg)
|| x.getId().startsWith("happytrails:" + arg)
)
.filter(x -> {
final String trimmedId = x.getId().contains(":") ? x.getId().split(":")[1] : x.getId();
return src.hasPermission(this.permissionPrefix + trimmedId);
})
.map(CatalogType::getId)
.collect(Collectors.toList());
} catch (Exception e) {
return Sponge.getRegistry().getAllOf(this.type).stream().map(CatalogType::getId).collect(Collectors.toList());
}
}
示例7: complete
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
/**
* Fetch completions for command arguments.
*
* @param src The source requesting tab completions
* @param args The arguments currently provided
* @param context The context to store state in
* @return Any relevant completions
*/
@Override
@NonnullByDefault
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
try {
String type = args.peek().toLowerCase();
return LoadedRegion.ChunkType.asMap().entrySet().stream()
.filter(s -> s.getKey().startsWith(type))
.filter(s -> Permissions.hasPermission(src, s.getKey()))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
} catch (ArgumentParseException e) {
e.printStackTrace();
}
return Lists.newArrayList();
}
示例8: clanRemoveCommand
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Command(name = "remove", description = "Изгнать игрока из клана", isPlayerOnly = true, isClanOnly = true, clanPermission = "remove", spongePermission = "mcclans.user.remove")
public void clanRemoveCommand(CommandSource commandSource, ClanPlayerImpl clanPlayer, @Parameter(name = "playerName") String removeName) {
ClanImpl clan = clanPlayer.getClan();
ClanPlayerImpl toBeRemovedClanPlayer = ClansImpl.getInstance().getClanPlayer(removeName);
if (toBeRemovedClanPlayer == null || !clan.equals(toBeRemovedClanPlayer.getClan())) {
toBeRemovedClanPlayer = clan.getMember(removeName);
}
if (toBeRemovedClanPlayer == null) {
Messages.sendPlayerNotAMemberOfThisClan(commandSource, removeName);
return;
}
if (toBeRemovedClanPlayer.equals(clan.getOwner())) {
Messages.sendWarningMessage(commandSource, Messages.YOU_CANNOT_REMOVE_THE_OWNER_FROM_THE_CLAN);
} else {
ClanMemberLeaveEvent.User clanMemberLeaveEvent = EventDispatcher.getInstance().dispatchUserClanMemberLeaveEvent(clan, toBeRemovedClanPlayer);
if (clanMemberLeaveEvent.isCancelled()) {
Messages.sendWarningMessage(commandSource, clanMemberLeaveEvent.getCancelMessage());
} else {
clan.removeMember(toBeRemovedClanPlayer);
Messages.sendClanBroadcastMessagePlayerRemovedFromTheClanBy(clan, toBeRemovedClanPlayer.getName(), clanPlayer.getName());
Messages.sendYouHaveBeenRemovedFromClan(toBeRemovedClanPlayer, clan.getName());
}
}
}
示例9: allyInviteCommand
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Command(name = "invite", description = "Пригласить другой клан в альянс", isPlayerOnly = true, isClanOnly = true, clanPermission = "ally", spongePermission = "mcclans.user.ally.invite")
public void allyInviteCommand(CommandSource commandSource, ClanPlayerImpl clanPlayer, @Parameter(name = "clanTag") ClanImpl invitedClan) {
ClanImpl invitingClan = clanPlayer.getClan();
if (invitingClan.equals(invitedClan)) {
Messages.sendWarningMessage(commandSource, Messages.YOU_CANNOT_BECOME_ALLIES_WITH_YOUR_OWN_CLAN);
} else if (invitingClan.equals(invitedClan)) {
Messages.sendWarningMessage(commandSource, Messages.YOUR_CLANS_ARE_ALREADY_ALLIES);
} else if (!invitedClan.isAllowingAllyInvites()) {
Messages.sendWarningMessage(commandSource, Messages.THIS_CLAN_IS_NOT_ACCEPTING_ALLY_INVITES);
} else if (invitedClan.getInvitingAlly() != null) {
Messages.sendThisClanHasAlreadyBeenInvitedToBecomeAlliesWithClan(commandSource, invitedClan.getInvitingAlly().getName());
} else {
invitedClan.setInvitingAlly(invitingClan);
Messages.sendClanBroadcastMessageClanHasBeenInvitedToBecomeAlliesBy(invitingClan, invitedClan.getName(), clanPlayer.getName(),
"ally");
Messages.sendClanBroadcastMessageYourClanHasBeenInvitedToBecomeAlliesWithClan(invitedClan, invitingClan.getName(),
invitingClan.getTagColored(), "ally");
}
}
示例10: execute
import org.spongepowered.api.command.CommandSource; //导入依赖的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();
}
示例11: execute
import org.spongepowered.api.command.CommandSource; //导入依赖的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();
}
示例12: execute
import org.spongepowered.api.command.CommandSource; //导入依赖的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();
}
}
示例13: parseValue
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Override
public ParseResult<String> parseValue(CommandSource commandSource, String value, NormalFilledParameter parameter) {
ParameterConstraint constraint = parameter.getConstraint();
if ("".equals(constraint.getRegex()) || value.matches(constraint.getRegex())) {
if (constraint.getMaximalLength() == -1 || value.length() <= constraint.getMaximalLength()) {
if (constraint.getMinimalLength() == -1 || value.length() >= constraint.getMinimalLength()) {
return ParseResult.newSuccessResult(value);
} else {
return ParseResult.newErrorResult("The supplied parameter is too small");
}
} else {
return ParseResult.newErrorResult("The supplied parameter is too long");
}
} else {
return ParseResult.newErrorResult(String.format("Value should match regex \'%s\'", constraint.getRegex()));
}
}
示例14: execute
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of(TextColors.RED, "Lookups can only be performed by players"));
return CommandResult.empty();
}
Player p = (Player) src;
Collection<String> filters = args.getAll("filter");
FilterSet filterSet = new FilterSet(plugin, p, true);
FilterParser.parse(filters, filterSet, p);
new RollbackJob(plugin, p, filterSet, false);
return CommandResult.success();
}
示例15: parseValue
import org.spongepowered.api.command.CommandSource; //导入依赖的package包/类
@Override
public ParseResult<Float> parseValue(CommandSource commandSource, String value, NormalFilledParameter parameter) {
try {
float floatValue = Float.parseFloat(value);
ParameterConstraint constraint = parameter.getConstraint();
if (constraint.getMinimalLength() == -1 || floatValue >= constraint.getMinimalLength()) {
if (constraint.getMaximalLength() == -1 || floatValue <= constraint.getMaximalLength()) {
return ParseResult.newSuccessResult(floatValue);
} else {
return ParseResult.newErrorResult(String.format("The supplied parameter is too high (%s/%s)", floatValue, constraint.getMaximalLength()));
}
} else {
return ParseResult.newErrorResult(String.format("The supplied parameter is too low (%s/%s)", floatValue, constraint.getMinimalLength()));
}
} catch (NumberFormatException e) {
return ParseResult.newErrorResult("The supplied parameter is not a decimal number");
}
}