use of com.iCo6.IO.mini.Arguments in project Core by iConomy.
the class Set method perform.
@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
if (!hasPermissions(sender, "set"))
throw new InvalidUsage("You do not have permission to do that.");
String name = arguments.get("name").getStringValue();
String tag = template.color(Template.Node.TAG_MONEY);
Double amount;
if (name.equals("0"))
throw new InvalidUsage("Missing <white>name<rose>: /money set <name> <amount>");
if (arguments.get("amount").getStringValue().equals("empty"))
throw new InvalidUsage("Missing <white>amount<rose>: /money set <name> <amount>");
try {
amount = arguments.get("amount").getDoubleValue();
} catch (NumberFormatException e) {
throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
}
if (Double.isInfinite(amount) || Double.isNaN(amount))
throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
if (!Accounts.exists(name)) {
template.set(Template.Node.ERROR_ACCOUNT);
template.add("name", name);
Messaging.send(sender, tag + template.parse());
return false;
}
Account account = new Account(name);
account.getHoldings().setBalance(amount);
template.set(Template.Node.PLAYER_SET);
template.add("name", name);
template.add("amount", account.getHoldings().toString());
Messaging.send(sender, tag + template.parse());
return false;
}
use of com.iCo6.IO.mini.Arguments in project Core by iConomy.
the class Take method perform.
@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
if (!hasPermissions(sender, "take"))
throw new InvalidUsage("You do not have permission to do that.");
String name = arguments.get("name").getStringValue();
String tag = template.color(Template.Node.TAG_MONEY);
Double amount;
if (name.equals("0"))
throw new InvalidUsage("Missing name parameter: /money take <name> <amount>");
if (arguments.get("amount").getStringValue().equals("empty"))
throw new InvalidUsage("Missing amount parameter: /money take <name> <amount>");
try {
amount = arguments.get("amount").getDoubleValue();
} catch (NumberFormatException e) {
throw new InvalidUsage("Invalid amount parameter, must be double.");
}
if (Double.isInfinite(amount) || Double.isNaN(amount))
throw new InvalidUsage("Invalid amount parameter, must be double.");
if (!Accounts.exists(name)) {
template.set(Template.Node.ERROR_ACCOUNT);
template.add("name", name);
Messaging.send(sender, tag + template.parse());
return false;
}
Account account = new Account(name);
account.getHoldings().subtract(amount);
template.set(Template.Node.PLAYER_DEBIT);
template.add("name", name);
template.add("amount", iConomy.format(amount));
Messaging.send(sender, tag + template.parse());
return false;
}
use of com.iCo6.IO.mini.Arguments in project Core by iConomy.
the class Create method perform.
@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
if (!hasPermissions(sender, "create"))
throw new InvalidUsage("You do not have permission to do that.");
String name = arguments.get("name").getStringValue();
String tag = template.color(Template.Node.TAG_MONEY);
if (name.equals("0"))
throw new InvalidUsage("Missing <white>name<rose>: /money create <name>");
if (Accounts.exists(name)) {
template.set(Template.Node.ERROR_EXISTS);
Messaging.send(sender, tag + template.parse());
return false;
}
if (!Accounts.create(name)) {
template.set(Template.Node.ERROR_CREATE);
template.add("name", name);
Messaging.send(sender, tag + template.parse());
return false;
}
template.set(Template.Node.ACCOUNTS_CREATE);
template.add("name", name);
Messaging.send(sender, tag + template.parse());
return false;
}
use of com.iCo6.IO.mini.Arguments in project Core by iConomy.
the class Empty method perform.
@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
if (!hasPermissions(sender, "empty"))
throw new InvalidUsage("You do not have permission to do that.");
Accounts.empty();
String tag = template.color(Template.Node.TAG_MONEY);
template.set(Template.Node.ACCOUNTS_EMPTY);
Messaging.send(sender, tag + template.parse());
return false;
}
use of com.iCo6.IO.mini.Arguments in project Core by iConomy.
the class Payment method perform.
@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
if (!hasPermissions(sender, "pay"))
return false;
if (isConsole(sender)) {
Messaging.send(sender, "`rCannot remove money from a non-living organism.");
return false;
}
Player from = (Player) sender;
String name = arguments.get("name").getStringValue();
String tag = template.color(Template.Node.TAG_MONEY);
Double amount;
if (name.equals("0"))
throw new InvalidUsage("Missing <white>name<rose>: /money pay <name> <amount>");
if (arguments.get("amount").getStringValue().equals("empty"))
throw new InvalidUsage("Missing <white>amount<rose>: /money pay <name> <amount>");
try {
amount = arguments.get("amount").getDoubleValue();
} catch (NumberFormatException e) {
throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
}
if (Double.isInfinite(amount) || Double.isNaN(amount))
throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
if (amount < 0.1)
throw new InvalidUsage("Invalid <white>amount<rose>, cannot be less than 0.1");
if (Common.matches(from.getName(), name)) {
template.set(Template.Node.PAYMENT_SELF);
Messaging.send(sender, template.parse());
return false;
}
if (!Accounts.exists(name)) {
template.set(Template.Node.ERROR_ACCOUNT);
template.add("name", name);
Messaging.send(sender, tag + template.parse());
return false;
}
Account holder = new Account(from.getName());
Holdings holdings = holder.getHoldings();
if (holdings.getBalance() < amount) {
template.set(Template.Node.ERROR_FUNDS);
Messaging.send(sender, tag + template.parse());
return false;
}
Account account = new Account(name);
holdings.subtract(amount);
account.getHoldings().add(amount);
template.set(Template.Node.PAYMENT_TO);
template.add("name", name);
template.add("amount", iConomy.format(amount));
Messaging.send(sender, tag + template.parse());
Player to = iConomy.Server.getPlayer(name);
if (to != null) {
template.set(Template.Node.PAYMENT_FROM);
template.add("name", from.getName());
template.add("amount", iConomy.format(amount));
Messaging.send(to, tag + template.parse());
}
return false;
}
Aggregations