Java Code Examples for org.spongepowered.api.entity.living.player.User#getName()
The following examples show how to use
org.spongepowered.api.entity.living.player.User#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandClaimFlagPlayer.java From GriefDefender with MIT License | 6 votes |
@CommandCompletion("@gdplayers @gdflags @gdmcids @gdtristates @gdcontexts @gddummy") @CommandAlias("cfp") @Description("Gets/Sets flag permission for a player in claim you are standing in.") @Syntax("<player> <flag> <target> <value> [context[key=value]]") @Subcommand("flag player") public void execute(Player player, User user, @Optional String[] args) throws InvalidCommandArgument { this.subject = PermissionHolderCache.getInstance().getOrCreateUser(user); this.friendlySubjectName = user.getName(); if (user.hasPermission(GDPermissions.COMMAND_ADMIN_CLAIMS) && !player.hasPermission(GDPermissions.SET_ADMIN_FLAGS)) { GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().PERMISSION_PLAYER_ADMIN_FLAGS); return; } super.execute(player, args); }
Example 2
Source File: RemoveCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("player").isPresent() && args.getOne("amount").isPresent()) { User target = args.<User>getOne("player").get(); String targetName = target.getName(); BigDecimal toRemove = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent()) { UniqueAccount targetAccount = uOpt.get(); if (targetAccount.withdraw(EconomyLite.getCurrencyService().getCurrentCurrency(), toRemove, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.removesuccess", "name", targetName)); attemptNotify(target); } else { src.sendMessage(messageStorage.getMessage("command.econ.removefail", "name", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example 3
Source File: SetCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("player").isPresent() && args.getOne("balance").isPresent()) { User target = args.<User>getOne("player").get(); String targetName = target.getName(); BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("balance").get()); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent()) { UniqueAccount targetAccount = uOpt.get(); if (targetAccount.setBalance(EconomyLite.getCurrencyService().getCurrentCurrency(), newBal, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetName)); attemptNotify(target); } else { src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example 4
Source File: AddCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("player").isPresent() && args.getOne("amount").isPresent()) { User target = args.<User>getOne("player").get(); String targetName = target.getName(); BigDecimal toAdd = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent()) { UniqueAccount targetAccount = uOpt.get(); if (targetAccount.deposit(EconomyLite.getCurrencyService().getCurrentCurrency(), toAdd, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.addsuccess", "name", targetName)); attemptNotify(target); } else { src.sendMessage(messageStorage.getMessage("command.econ.addfail", "name", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example 5
Source File: CommandClaimOptionPlayer.java From GriefDefender with MIT License | 5 votes |
@CommandCompletion("@gdplayers @gdoptions @gdcontexts @gddummy") @CommandAlias("cop") @Description("Gets/Sets option for a player in claim you are standing in.") @Syntax("<player> <option> <value> [context[key=value]]") @Subcommand("option player") public void execute(Player src, User player, @Optional String[] args) throws InvalidCommandArgument { this.subject = PermissionHolderCache.getInstance().getOrCreateUser(player); this.friendlySubjectName = player.getName(); super.execute(src, args); }
Example 6
Source File: CachedPlayer.java From Web-API with MIT License | 5 votes |
public CachedPlayer(User user) { super(null); this.uuid = UUID.fromString(user.getUniqueId().toString()); this.name = user.getName(); this.isOnline = false; }
Example 7
Source File: PayCommand.java From EconomyLite with MIT License | 5 votes |
private void pay(User target, BigDecimal amount, Player src) { String targetName = target.getName(); if (!target.getUniqueId().equals(src.getUniqueId())) { Optional<UniqueAccount> uOpt = ecoService.getOrCreateAccount(src.getUniqueId()); Optional<UniqueAccount> tOpt = ecoService.getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent() && tOpt.isPresent()) { if (uOpt.get() .transfer(tOpt.get(), ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), (EconomyLite.getInstance()))) .getResult().equals(ResultType.SUCCESS)) { Text label = ecoService.getDefaultCurrency().getPluralDisplayName(); if (amount.equals(BigDecimal.ONE)) { label = ecoService.getDefaultCurrency().getDisplayName(); } src.sendMessage(messageStorage.getMessage("command.pay.success", "target", targetName, "amountandlabel", String.format(Locale.ENGLISH, "%,.2f", amount) + " " + label.toPlain())); final Text curLabel = label; Sponge.getServer().getPlayer(target.getUniqueId()).ifPresent(p -> { p.sendMessage(messageStorage.getMessage("command.pay.target", "amountandlabel", String.format(Locale.ENGLISH, "%,.2f", amount) + " " + curLabel.toPlain(), "sender", uOpt.get().getDisplayName().toPlain())); }); } else { src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.pay.notyou")); } }
Example 8
Source File: CommandClaimFlagPlayer.java From GriefPrevention with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { Player player; try { player = GriefPreventionPlugin.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } User user = ctx.<User>getOne("player").get(); String name = user.getName(); String flag = ctx.<String>getOne("flag").orElse(null); String source = ctx.<String>getOne("source").orElse(null); String target = null; // Workaround command API issue not handling onlyOne arguments with sequences properly List<String> targetValues = new ArrayList<>(ctx.<String>getAll("target")); if (targetValues.size() > 0) { if (targetValues.size() > 1) { target = targetValues.get(1); } else { target = targetValues.get(0); } } if (source != null && source.equalsIgnoreCase("any")) { source = null; } this.subject = user; this.friendlySubjectName = user.getName(); Tristate value = ctx.<Tristate>getOne("value").orElse(null); String context = ctx.<String>getOne("context").orElse(null); GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation()); String reason = ctx.<String>getOne("reason").orElse(null); Text reasonText = null; if (reason != null) { reasonText = TextSerializers.FORMATTING_CODE.deserialize(reason); } if (flag == null && value == null) { showFlagPermissions(src, claim, FlagType.ALL, source); return CommandResult.success(); } if (!ClaimFlag.contains(flag)) { src.sendMessage(Text.of(TextColors.RED, "Flag not found.")); return CommandResult.success(); } Context claimContext = claim.getContext(); if (context != null) { claimContext = CommandHelper.validateCustomContext(src, claim, context); if (claimContext == null) { final Text message = GriefPreventionPlugin.instance.messageData.flagInvalidContext .apply(ImmutableMap.of( "context", context, "flag", flag)).build(); GriefPreventionPlugin.sendMessage(src, message); return CommandResult.success(); } } if (user.hasPermission(GPPermissions.COMMAND_ADMIN_CLAIMS) && !src.hasPermission(GPPermissions.SET_ADMIN_FLAGS)) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionSetAdminFlags.toText()); return CommandResult.success(); } try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().pushCause(src); claim.setPermission(user, name, ClaimFlag.getEnum(flag), source, target, value, claimContext, reasonText); } return CommandResult.success(); }
Example 9
Source File: UltimateUser.java From UltimateCore with MIT License | 4 votes |
public UltimateUser(User user) { this.uuid = user.getUniqueId(); this.name = user.getName(); }