本文整理汇总了Java中org.spongepowered.api.command.args.CommandContext.getOne方法的典型用法代码示例。如果您正苦于以下问题:Java CommandContext.getOne方法的具体用法?Java CommandContext.getOne怎么用?Java CommandContext.getOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.command.args.CommandContext
的用法示例。
在下文中一共展示了CommandContext.getOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的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();
}
示例2: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的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();
}
示例3: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
Optional<Player> optionalSelectedPlayer = context.<Player>getOne("player");
Optional<String> optionalPower = context.<String>getOne("power");
if (optionalSelectedPlayer.isPresent() && optionalPower.isPresent())
{
if (source instanceof Player)
{
Player player = (Player) source;
if (EagleFactions.AdminList.contains(player.getUniqueId().toString()))
{
BigDecimal newPower = new BigDecimal(optionalPower.get());
PowerService.setPower(optionalSelectedPlayer.get().getUniqueId(), newPower);
player.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.GREEN, "Player's power has been changed!"));
return CommandResult.success();
}
else
{
player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You need to toggle faction admin mode to do this!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Wrong command arguments!"));
source.sendMessage(Text.of(TextColors.RED, "Usage: /f setpower <player> <power>"));
}
return CommandResult.success();
}
示例4: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
Optional<Player> optionalSelectedPlayer = context.<Player>getOne(Text.of("player"));
Optional<String> optionalPower = context.<String>getOne(Text.of("power"));
if (optionalSelectedPlayer.isPresent() && optionalPower.isPresent())
{
if (source instanceof Player)
{
Player player = (Player) source;
if (EagleFactions.AdminList.contains(player.getUniqueId().toString()))
{
BigDecimal newPower = new BigDecimal(optionalPower.get());
PowerService.setMaxPower(optionalSelectedPlayer.get().getUniqueId(), newPower);
player.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.GREEN, "Player's maxpower has been changed!"));
return CommandResult.success();
}
else
{
player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You need to toggle faction admin mode to do this!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Wrong command arguments!"));
source.sendMessage(Text.of(TextColors.RED, "Usage: /f maxpower <player> <power>"));
}
return CommandResult.success();
}
示例5: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
Optional<Player> player = commandContext.getOne("player");
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();
}
if (!player.isPresent()) {
commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
return CommandResult.empty();
}
ItemStack keyItemStack = virtualCrate.getCrateKey(quantity);
InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(keyItemStack.copy()).getType();
if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(keyItemStack.copy()).getType();
if (!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
commandSource.sendMessage(Text.of("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest"));
HuskyCrates.instance.logger.info("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest");
} else {
if (player.isPresent()) {
player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
} else {
commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
}
}
}
}else{
commandSource.sendMessage(Text.of("Usage: /crate key <id> [player] [count]"));
}
return CommandResult.success();
}
示例6: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
Optional<User> user = commandContext.getOne("player");
if (!user.isPresent()) {
commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
return CommandResult.empty();
}
if (commandSource.hasPermission("huskycrates.keybal.others") && user.get() != commandSource) {
commandSource.sendMessage(Text.of(TextColors.GREEN,user.get().getName() + "'s Key Balance"));
}else{
commandSource.sendMessage(Text.of(TextColors.GREEN,"Your Key Balance"));
}
boolean atleastOne = false;
for(String vcid : HuskyCrates.instance.crateUtilities.getCrateTypes()) {
VirtualCrate vc = HuskyCrates.instance.crateUtilities.getVirtualCrate(vcid);
int keys = vc.getVirtualKeyBalance(user.get());
if(keys > 0){
atleastOne = true;
commandSource.sendMessage(Text.of(" ", TextSerializers.FORMATTING_CODE.deserialize(vc.displayName), ": " + keys + " (id: " + vc.id + ") "));
}
}
if(!atleastOne){
if (commandSource.hasPermission("huskycrates.keybal.others") && user.get() != commandSource) {
commandSource.sendMessage(Text.of(TextColors.GRAY, TextStyles.ITALIC,user.get().getName() + " currently has no virtual keys."));
}else{
commandSource.sendMessage(Text.of(TextColors.GRAY, TextStyles.ITALIC,"You currently have no virtual keys."));
}
}
return CommandResult.success();
}
示例7: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
Optional<Player> player = commandContext.getOne("player");
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();
}
if (!player.isPresent()) {
commandSource.sendMessage(Text.of("You need to either specify a player or be in game"));
return CommandResult.empty();
}
ItemStack chestItemStack = virtualCrate.getCrateItem(quantity);
InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(chestItemStack.copy()).getType();
if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(chestItemStack.copy()).getType();
if(!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
commandSource.sendMessage(Text.of("Couldn't give chest to " + player.get().getName() + " because of a full inventory and enderchest"));
HuskyCrates.instance.logger.info("Couldn't give chest to " + player.get().getName() + " because of a full inventory and enderchest");
}else{
if(player.isPresent()) {
player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName) ," crate(s), but some have been placed in your Ender Chest."));
}else{
commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName) ," crate(s), but some have been placed in your Ender Chest."));
}
}
}
}else{
commandSource.sendMessage(Text.of("Usage: /crate chest <id> [player]"));
}
return CommandResult.success();
}
示例8: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的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();
if (IPLog.getPlugin().getStorage().isPresent(ip, user.getUniqueId())) {
throw new CommandException(Text.of(TextColors.RED, "This connection already exists in the database."));
}
Sponge.getScheduler().createAsyncExecutor(IPLog.getPlugin()).execute(() -> IPLog.getPlugin().getStorage().addConnection(ip, user.getUniqueId(), LocalDateTime.now()));
src.sendMessage(Text.of(TextColors.YELLOW, "You have successfully added the specified connection to the database."));
return CommandResult.success();
}
示例9: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
String id = args.<String>getOne("id").orElseThrow(() -> new CommandException(Text.of("No Camera Id")));
Location<World> location;
if(src instanceof Player){
location = args.<Location<World>>getOne("location").orElse(((Player) src).getLocation());
}else{
location = args.<Location<World>>getOne("location").orElseThrow(() -> new CommandException(Text.of("No Location")));
}
Camera camera = new Camera(location, id);
Optional<String> name = args.getOne("name");
if(name.isPresent()){
camera.setName(Text.of(name.get()));
}
Optional<String> permission = args.getOne("permission");
if(permission.isPresent()){
camera.setPermission(permission.get());
}
plugin.getCameras().put(id, camera);
plugin.getConfig().saveCameras();
src.sendMessage(plugin.translations.CAMERA_CREATED, camera.templateVariables());
if(camera.canUseCamera(src)){
src.sendMessage(plugin.translations.CAMERA_CREATED_HAS_PERMISSIONS.apply(camera.templateVariables())
.onClick(TextActions.runCommand("/vigilate view " + camera.getId())).build());
}
return CommandResult.success();
}
示例10: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Optional<Player> optPlayer = args.getOne("player");
if (!optPlayer.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "No such player!"));
return CommandResult.empty();
}
Player player = optPlayer.get();
val mutedPlayers = RPChat.get().getMutedPlayers();
if (mute) {
if (mutedPlayers.contains(player)) {
src.sendMessage(Text.of(TextColors.RED, "This player is already muted! Use /unmute to unmute them."));
return CommandResult.empty();
}
mutedPlayers.add(player);
src.sendMessage(Text.of(
TextColors.GREEN, "Player ", TextColors.YELLOW, player.getName(), TextColors.GREEN, " has been muted."
));
} else {
if (!mutedPlayers.contains(player)) {
src.sendMessage(Text.of(TextColors.RED, "This player has not been muted!"));
return CommandResult.empty();
}
mutedPlayers.remove(player);
src.sendMessage(Text.of(
TextColors.GREEN, "Player ", TextColors.YELLOW, player.getName(), TextColors.GREEN, " has been unmuted."
));
}
return CommandResult.success();
}
示例11: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
Optional<String> optionalFactionName = context.<String>getOne("faction name");
if (optionalFactionName.isPresent())
{
if(source instanceof Player)
{
Player player = (Player)source;
String playerFactionName = FactionLogic.getFactionName(player.getUniqueId());
String rawFactionName = optionalFactionName.get();
String removedFaction = FactionLogic.getRealFactionName(rawFactionName);
if (removedFaction == null)
{
player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "There is no faction called ", TextColors.GOLD, rawFactionName + "!"));
return CommandResult.success();
}
else
{
if(playerFactionName != null)
{
if(EagleFactions.AdminList.contains(player.getUniqueId().toString()))
{
if(!FactionLogic.getAlliances(playerFactionName).contains(removedFaction))
{
FactionLogic.removeAlly(playerFactionName, removedFaction);
player.sendMessage(Text.of(PluginInfo.PluginPrefix,TextColors.GREEN, "You disbanded your alliance with ", TextColors.GOLD, removedFaction, TextColors.GREEN, "!"));
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Your faction is not in the alliance with ", TextColors.GOLD, removedFaction + "!"));
}
return CommandResult.success();
}
if(FactionLogic.getLeader(playerFactionName).equals(player.getUniqueId().toString()) || FactionLogic.getOfficers(playerFactionName).contains(player.getUniqueId().toString()))
{
if(FactionLogic.getAlliances(playerFactionName).contains(removedFaction))
{
FactionLogic.removeAlly(playerFactionName, removedFaction);
player.sendMessage(Text.of(PluginInfo.PluginPrefix,TextColors.GREEN, "You disbanded your alliance with ", TextColors.GOLD, removedFaction, TextColors.GREEN, "!"));
return CommandResult.success();
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Your faction is not in the alliance with ", TextColors.GOLD, removedFaction + "!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You must be the faction leader or officer to do this!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You must be in a faction in order to use this command!"));
}
}
}
else
{
source.sendMessage (Text.of (PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Wrong command arguments!"));
source.sendMessage(Text.of(TextColors.RED, "Usage: /f ally remove <faction name>"));
}
return CommandResult.success();
}
示例12: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
Optional<Player> optionalSelectedPlayer = context.<Player>getOne(Text.of("player"));
if (optionalSelectedPlayer.isPresent())
{
if(source instanceof Player)
{
Player player = (Player)source;
String playerFactionName = FactionLogic.getFactionName(player.getUniqueId());
if(playerFactionName != null)
{
if(FactionLogic.getLeader(playerFactionName).equals(player.getUniqueId().toString()) || FactionLogic.getOfficers(playerFactionName).contains(player.getUniqueId().toString()))
{
if(optionalSelectedPlayer.isPresent())
{
Player selectedPlayer = optionalSelectedPlayer.get();
if(FactionLogic.getFactionName(selectedPlayer.getUniqueId()).equals(playerFactionName))
{
if(!FactionLogic.getLeader(playerFactionName).equals(selectedPlayer.getUniqueId().toString()))
{
if(!FactionLogic.getOfficers(playerFactionName).contains(selectedPlayer.getUniqueId().toString()) || FactionLogic.getLeader(playerFactionName).equals(player.getUniqueId().toString()))
{
FactionLogic.kickPlayer(selectedPlayer.getUniqueId(), playerFactionName);
//TODO: Add listener that will inform players in a faction that someone has left their faction.
source.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.GREEN, "You kicked ", TextColors.GOLD, selectedPlayer.getName(), TextColors.GREEN, " from the faction."));
selectedPlayer.sendMessage(Text.of(PluginInfo.PluginPrefix, "You were kicked from faction ", TextColors.GOLD, playerFactionName));
if(EagleFactions.AutoClaimList.contains(selectedPlayer.getUniqueId().toString())) EagleFactions.AutoClaimList.remove(selectedPlayer.getUniqueId().toString());
return CommandResult.success();
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You can't kick this player!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You can't kick this player!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "This player is not in your faction!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "There is no such player."));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You needs to be the leader or an officer to kick players from the faction."));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You are not in a faction!"));
}
}
else
{
source.sendMessage (Text.of (PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Wrong command arguments!"));
source.sendMessage(Text.of(TextColors.RED, "Usage: /f kick <player>"));
}
return CommandResult.success();
}
示例13: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
Optional<ChatEnum> optionalChatType = context.<ChatEnum>getOne("chat");
if(source instanceof Player)
{
Player player = (Player)source;
if (FactionLogic.getFactionName(player.getUniqueId()) != null)
{
if(optionalChatType.isPresent())
{
if(EagleFactions.ChatList.containsKey(player.getUniqueId()))
{
if (optionalChatType.get().equals(ChatEnum.Global))
{
EagleFactions.ChatList.remove(player.getUniqueId());
player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Changed chat to ", TextColors.GOLD, "Global", TextColors.RESET, "!"));
}
else
{
EagleFactions.ChatList.replace(player.getUniqueId(), EagleFactions.ChatList.get(player.getUniqueId()), optionalChatType.get());
player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Changed chat to ", TextColors.GOLD, optionalChatType.get(), TextColors.RESET, "!"));
}
}
else
{
EagleFactions.ChatList.put(player.getUniqueId(), optionalChatType.get());
player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Changed chat to ", TextColors.GOLD, optionalChatType.get(), TextColors.RESET, "!"));
}
}
else
{
//If player is in alliance chat or faction chat.
if(EagleFactions.ChatList.containsKey(player.getUniqueId()))
{
if(EagleFactions.ChatList.get(player.getUniqueId()).equals(ChatEnum.Alliance))
{
EagleFactions.ChatList.replace(player.getUniqueId(), ChatEnum.Alliance, ChatEnum.Faction);
player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Changed chat to ", TextColors.GOLD, "Faction", TextColors.RESET, "!"));
}
else
{
EagleFactions.ChatList.remove(player.getUniqueId());
player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Changed chat to ", TextColors.GOLD, "Global", TextColors.RESET, "!"));
}
}
else
{
EagleFactions.ChatList.put(player.getUniqueId(), ChatEnum.Alliance);
player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Changed chat to ", TextColors.GOLD, "Alliance", TextColors.RESET, "!"));
}
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You must be in a faction in order to do this!"));
}
}
else
{
source.sendMessage (Text.of (PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
}
return CommandResult.success();
}
示例14: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
Optional<Player> optionalNewLeaderPlayer = context.<Player>getOne("player");
if (optionalNewLeaderPlayer.isPresent())
{
if(source instanceof Player)
{
Player player = (Player)source;
Player newLeaderPlayer = optionalNewLeaderPlayer.get();
String playerFactionName = FactionLogic.getFactionName(player.getUniqueId());
if(playerFactionName != null)
{
if(EagleFactions.AdminList.contains(player.getUniqueId().toString()))
{
if(FactionLogic.getFactionName(newLeaderPlayer.getUniqueId()).equals(playerFactionName))
{
if(!FactionLogic.getLeader(playerFactionName).equals(newLeaderPlayer.getUniqueId().toString()))
{
FactionLogic.setLeader(newLeaderPlayer.getUniqueId(), playerFactionName);
source.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.WHITE, "You set ", TextColors.GOLD, newLeaderPlayer.getName(), TextColors.WHITE, " as your new ", TextColors.BLUE, "Leader", TextColors.WHITE, "!"));
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You are already a leader of this faction!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "This player is not in your team!"));
}
return CommandResult.success();
}
if(FactionLogic.getLeader(playerFactionName).equals(player.getUniqueId().toString()))
{
if(FactionLogic.getFactionName(newLeaderPlayer.getUniqueId()).equals(playerFactionName))
{
if(!FactionLogic.getLeader(playerFactionName).equals(newLeaderPlayer.getUniqueId().toString()))
{
FactionLogic.setLeader(newLeaderPlayer.getUniqueId(), playerFactionName);
source.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.WHITE, "You set ", TextColors.GOLD, newLeaderPlayer.getName(), TextColors.WHITE, " as your new ", TextColors.BLUE, "Leader", TextColors.WHITE, "!"));
return CommandResult.success();
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You are already a leader of this faction!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "This player is not in your team!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You must be the faction leader to do this!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You must be in a faction in order to use this command!"));
}
}
else
{
source.sendMessage (Text.of (PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Wrong command arguments!"));
source.sendMessage(Text.of(TextColors.RED, "Usage: /f setleader <player>"));
}
return CommandResult.success();
}
示例15: execute
import org.spongepowered.api.command.args.CommandContext; //导入方法依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("operation").isPresent()) {
if (commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
Optional<User> player = commandContext.getOne("player");
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();
}
if (!player.isPresent()) {
commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
return CommandResult.empty();
}
Integer oldBal = virtualCrate.getVirtualKeyBalance(player.get());
String operation = commandContext.<String>getOne("operation").get();
if(operation.equalsIgnoreCase("add")) {
virtualCrate.giveVirtualKeys(player.get(), quantity);
commandSource.sendMessage(Text.of("Gave " + player.get().getName() + " " + quantity + " vkeys."));
if (commandSource != player.get() && player.get() instanceof Player) {
((Player) player.get()).sendMessage(Text.of(TextColors.GREEN, "You received " + quantity + " virtual keys for a ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), "."));
}
} else if(operation.equalsIgnoreCase("set")) {
virtualCrate.setVirtualKeys(player.get(), quantity);
commandSource.sendMessage(Text.of("Set " + player.get().getName() + " " + quantity + " vkeys."));
if (commandSource != player.get() && player.get() instanceof Player) {
((Player) player.get()).sendMessage(Text.of(TextColors.GREEN, "Your virtual key balance was set to " + quantity + " for a ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), "."));
}
} else if(operation.equalsIgnoreCase("remove")) {
virtualCrate.takeVirtualKeys(player.get(), quantity);
commandSource.sendMessage(Text.of("Took " + player.get().getName() + " " + quantity + " vkeys."));
if (commandSource != player.get() && player.get() instanceof Player) {
((Player) player.get()).sendMessage(Text.of(TextColors.GREEN, "You lost " + quantity + " virtual keys for a ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), "."));
}
} else {
//invalid operation
}
fireEvent(player.get(), virtualCrate.id, oldBal, virtualCrate.getVirtualKeyBalance(player.get()));
} else {
printUsage(commandSource);
}
} else {
printUsage(commandSource);
}
return CommandResult.success();
}