Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgrandt committed Jun 17, 2017
2 parents fcf3ea2 + 3a26b00 commit 37fc2f1
Show file tree
Hide file tree
Showing 39 changed files with 3,117 additions and 1,161 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
v1.6.0

+ SQL Support
+ Reusable job sets that allow for easier job creation
+ Add option to change location of currency symbol (eg. $5 or 5$)
+ Add `growthTrait` node to `break` nodes to support crops (see the farmer job)
+ Add `farmer` to the default jobs
+ Add `/job set <job> <player>` command to set another players job
+ Virtual account support
+ CHANGE: Updated format of job info command
+ CHANGE: Commands now properly return as successful or unsuccessful
+ CHANGE: Baltop command now only shows a maximum of 10 balances
+ CHANGE: Added "/money" alias to balance command
+ CHANGE: Pay command no longer works from command blocks or console (Use adminpay)
+ CHANGE: In case of duplicate rewards in a job (across multiple sets) the one giving more exp is chosen rather than the last match
+ CHANGE: No gains from breaking a block placed by any player UNLESS the block is indicating to have a `growTrait`

v1.5.3

+ FIX: NullPointerException no longer occurs when reloading configuration files and not having jobs enabled
Expand Down
10 changes: 3 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ Thanks for your interest in contributing to Total Economy. There are a few guide

### Contributing Issues
* Be as descriptive as possible
* Include a complete error log
* Include a complete error log if applicable
* Include pictures if possible

### Contributing Code
* Fork the repository
* Create a new branch from ‘develop'. Use slash notation (e.g. feature/feature-name)
* Types:
* feature
* fix
* update
* Create a new branch from ‘develop'. Use slash notation (e.g. issue/issue#-short-issue-summary, issue/137-nfe-on-get-balance)
* Follow the same format/style as the rest of the code
* Add comments for new functions:
``` java
Expand All @@ -24,7 +20,7 @@ Thanks for your interest in contributing to Total Economy. There are a few guide
* @return int player's balance
*/
```
* Test the change/addition and make sure nothing was accidently broken
* Test the change/addition and make sure nothing was accidentally broken
* Make sure your commit message clearly describes the change/addition and includes the issue number if one exists
* Submit a pull request

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# TotalEconomy

All in one economy plugin for Minecraft and Sponge.

-

##Commands

## Commands
```
/pay [player] [amount] - Pay another player
/balance - Display your balance (/bal)
Expand All @@ -17,7 +18,7 @@ All in one economy plugin for Minecraft and Sponge.
/balancetop - Display a paginated list of top balances (/baltop)
```

##Permissions
## Permissions
```
totaleconomy.command.pay
totaleconomy.command.balance
Expand Down
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ repositories {
apply plugin: 'java'

dependencies {
compile 'org.spongepowered:spongeapi:5.1.0-SNAPSHOT'
compile 'org.spongepowered:spongeapi:6.0.0'
}

jar {
baseName="TotalEconomy"
version="1.6.0"
}
35 changes: 24 additions & 11 deletions src/main/java/com/erigitic/commands/AdminPayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.User;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.NamedCause;
import org.spongepowered.api.service.economy.Currency;
Expand All @@ -44,6 +45,8 @@
import org.spongepowered.api.text.format.TextColors;

import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AdminPayCommand implements CommandExecutor {
private Logger logger;
Expand All @@ -57,40 +60,50 @@ public AdminPayCommand(TotalEconomy totalEconomy) {

accountManager = totalEconomy.getAccountManager();

defaultCurrency = accountManager.getDefaultCurrency();
defaultCurrency = totalEconomy.getDefaultCurrency();
}

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
String strAmount = args.<String>getOne("amount").get();
Player recipient = args.<Player>getOne("player").get();
String strAmount = (String) args.getOne("amount").get();
User recipient = args.<User>getOne("player").get();

if (TotalEconomy.isNumeric(strAmount)) {

Pattern amountPattern = Pattern.compile("^[+-]?(\\d*\\.)?\\d+$");
Matcher m = amountPattern.matcher(strAmount);

if (m.matches()) {
BigDecimal amount = new BigDecimal((String) args.getOne("amount").get()).setScale(2, BigDecimal.ROUND_DOWN);
TEAccount recipientAccount = (TEAccount) accountManager.getOrCreateAccount(recipient.getUniqueId()).get();
Text amountText = Text.of(defaultCurrency.format(amount).toPlain().replace("-", ""));

TransactionResult transactionResult = recipientAccount.deposit(accountManager.getDefaultCurrency(), amount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
TransactionResult transactionResult = recipientAccount.deposit(totalEconomy.getDefaultCurrency(), amount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));

if (transactionResult.getResult() == ResultType.SUCCESS) {
if (!strAmount.contains("-")) {
src.sendMessage(Text.of(TextColors.GRAY, "You have sent ", TextColors.GOLD, amountText,
TextColors.GRAY, " to ", TextColors.GOLD, recipient.getName(), TextColors.GRAY, "."));

recipient.sendMessage(Text.of(TextColors.GRAY, "You have received ", TextColors.GOLD, amountText,
TextColors.GRAY, " from ", TextColors.GOLD, src.getName(), TextColors.GRAY, "."));
if (recipient.isOnline()) {
recipient.getPlayer().get().sendMessage(Text.of(TextColors.GRAY, "You have received ", TextColors.GOLD, amountText,
TextColors.GRAY, " from ", TextColors.GOLD, src.getName(), TextColors.GRAY, "."));
}
} else {
src.sendMessage(Text.of(TextColors.GRAY, "You have removed ", TextColors.GOLD, amountText,
TextColors.GRAY, " from ", TextColors.GOLD, recipient.getName(), "'s", TextColors.GRAY, " account."));

recipient.sendMessage(Text.of(TextColors.GOLD, amountText, TextColors.GRAY, " has been removed from your account by ",
TextColors.GOLD, src.getName(), TextColors.GRAY, "."));
if (recipient.isOnline()) {
recipient.getPlayer().get().sendMessage(Text.of(TextColors.GOLD, amountText, TextColors.GRAY, " has been removed from your account by ",
TextColors.GOLD, src.getName(), TextColors.GRAY, "."));
}
}

return CommandResult.success();
}
} else {
src.sendMessage(Text.of(TextColors.RED, "The amount must be numeric."));
throw new CommandException(Text.of("Invalid amount! Must be a number!"));
}

return CommandResult.success();
return CommandResult.empty();
}
}
6 changes: 4 additions & 2 deletions src/main/java/com/erigitic/commands/BalanceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
if (src instanceof Player) {
Player sender = (Player) src;
TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(sender.getUniqueId()).get();
Currency defaultCurrency = accountManager.getDefaultCurrency();
Currency defaultCurrency = totalEconomy.getDefaultCurrency();
Text playerBalance = defaultCurrency.format(playerAccount.getBalance(defaultCurrency));

sender.sendMessage(Text.of(TextColors.GRAY, "Balance: ", TextColors.GOLD, playerBalance));

return CommandResult.success();
}

return CommandResult.success();
return CommandResult.empty();
}
}
26 changes: 16 additions & 10 deletions src/main/java/com/erigitic/commands/BalanceTopCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,30 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
ConfigurationNode accountNode = accountManager.getAccountConfig();
List<Text> accountBalances = new ArrayList<>();
Map<String, BigDecimal> accountBalancesMap = new HashMap<>();
Currency defaultCurrency = accountManager.getDefaultCurrency();
Currency defaultCurrency = totalEconomy.getDefaultCurrency();

// TODO: Add customization to this (amount of accounts to show).
accountNode.getChildrenMap().keySet().forEach(accountUUID -> {
TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(UUID.fromString(accountUUID.toString())).get();
UUID uuid;

// Check if the account is virtual or not. If virtual, skip the rest of the execution and move on to next account.
try {
uuid = UUID.fromString(accountUUID.toString());
} catch (IllegalArgumentException e) {
return;
}

TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(uuid).get();
Text playerName = playerAccount.getDisplayName();

accountBalancesMap.put(playerName.toPlain(), playerAccount.getBalance(defaultCurrency));
});

List<Map.Entry<String, BigDecimal>> unsortedList = new LinkedList<>(accountBalancesMap.entrySet());
unsortedList.sort((Map.Entry<String, BigDecimal> o1, Map.Entry<String, BigDecimal> o2) -> (o1.getValue()).compareTo(o2.getValue()));

Collections.reverse(unsortedList);

unsortedList.forEach(entry -> accountBalances.add(Text.of(TextColors.GRAY, entry.getKey(), ": ", TextColors.GOLD, defaultCurrency.format(entry.getValue()).toPlain())));
accountBalancesMap.entrySet().stream()
.sorted(Map.Entry.<String, BigDecimal>comparingByValue().reversed())
.limit(10)
.forEach(entry -> accountBalances.add(Text.of(TextColors.GRAY, entry.getKey(), ": ", TextColors.GOLD, defaultCurrency.format(entry.getValue()).toPlain())));

builder.title(Text.of(TextColors.GOLD, "Top Balances"))
builder.title(Text.of(TextColors.GOLD, "Top 10 Balances"))
.contents(accountBalances)
.sendTo(src);

Expand Down
Loading

0 comments on commit 37fc2f1

Please sign in to comment.