diff --git a/CHANGELOG.md b/CHANGELOG.md index b7a182fe..993f0d3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +v1.5.2 + ++ CHANGE: Changed output for when an error occurs during the reloading of configuration files ++ FIX: Baltop command now sorts balances in descending order + +v1.5.1 + ++ CHANGE: Accounts configuration file now saves while the server is in the process of stopping ++ CHANGE: Changed the way display names are retrieved ++ CHANGE: Changed the way block ids are handled ++ CHANGE: Admin pay command can now be used to remove money (/adminpay [PLAYER] -[VALUE]) ++ FIX: EconomyTransactionEvent no longer encounters a cast exception ++ FIX: Kills with bows are now properly handled + v 1.5.0 + Balance Top command (/balancetop, /baltop) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..052d3911 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,34 @@ +# Contributing to Total Economy +Thanks for your interest in contributing to Total Economy. There are a few guidelines that I would like contributors to follow to make the process as easy as possible. + +### Contributing Issues +* Be as descriptive as possible +* Include a complete error log +* 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 +* Follow the same format/style as the rest of the code +* Add comments for new functions: +``` java +/** + * Description of the function + * + * @param firstArg description of argument + * @param secondArg description of argument + * @return int player's balance + */ +``` +* Test the change/addition and make sure nothing was accidently broken +* Make sure your commit message clearly describes the change/addition and includes the issue number if one exists +* Submit a pull request + +### Git Commit Message +* Keep length of first line to 72 characters or less +* Use present tense (e.g. “Update” instead of “Updated”) +* Include any new commands/permissions/nodes/etc. and a description for each for easy addition to documentation. New line for each one. diff --git a/LICENSE.md b/LICENSE.md index c9f0e944..6a5e9f39 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,7 @@ The MIT License (MIT) -Copyright (c) 2016 Eric +Copyright (c) Eric Grandt +Copyright (c) contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f7ab2ddb..60ff0007 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ All in one economy plugin for Minecraft and Sponge. /job - Display information about your current job as well as a job list /job set [jobName] - Set your job /job toggle - Toggle job reward notifications on/off +/job info - Displays a paginated list of all items/blocks/mobs that reward exp/money for the player's current job /setbalance [player] [amount] - Set a player's balance (/setbal) /adminpay [player] [amount] - Pay a player without having money removed from your balance /viewbalance [player] - View the balance of another player (/vbal) @@ -20,10 +21,12 @@ All in one economy plugin for Minecraft and Sponge. ``` totaleconomy.command.pay totaleconomy.command.balance +totaleconomy.command.job totaleconomy.command.jobset totaleconomy.command.jobtoggle -totaleconomy.command.job +totaleconomy.command.jobinfo totaleconomy.command.setbalance totaleconomy.command.adminpay totaleconomy.command.viewbalance -``` \ No newline at end of file +totaleconomy.command.balancetop +``` diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 02394e53..70b87b9e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Aug 14 12:35:04 CDT 2016 +#Thu Sep 29 10:15:08 CDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip diff --git a/src/main/java/com/erigitic/commands/AdminPayCommand.java b/src/main/java/com/erigitic/commands/AdminPayCommand.java index a247944f..57e62466 100644 --- a/src/main/java/com/erigitic/commands/AdminPayCommand.java +++ b/src/main/java/com/erigitic/commands/AdminPayCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -20,9 +45,6 @@ import java.math.BigDecimal; -/** - * Created by Eric on 9/7/2015. - */ public class AdminPayCommand implements CommandExecutor { private Logger logger; private TotalEconomy totalEconomy; @@ -44,24 +66,29 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm Player recipient = args.getOne("player").get(); if (TotalEconomy.isNumeric(strAmount)) { - if (!strAmount.contains("-")) { - BigDecimal amount = new BigDecimal((String) args.getOne("amount").get()).setScale(2, BigDecimal.ROUND_DOWN); - TEAccount recipientAccount = (TEAccount) accountManager.getOrCreateAccount(recipient.getUniqueId()).get(); + 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(accountManager.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, ".")); - if (transactionResult.getResult() == ResultType.SUCCESS) { - src.sendMessage(Text.of(TextColors.GRAY, "You have sent ", TextColors.GOLD, defaultCurrency.format(amount), - TextColors.GRAY, " to ", TextColors.GOLD, recipient.getName())); + recipient.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.GRAY, "You have received ", TextColors.GOLD, defaultCurrency.format(amount), - TextColors.GRAY, " from ", TextColors.GOLD, src.getName(), ".")); + recipient.sendMessage(Text.of(TextColors.GOLD, amountText, TextColors.GRAY, " has been removed from your account by ", + TextColors.GOLD, src.getName(), TextColors.GRAY, ".")); } - } else { - src.sendMessage(Text.of(TextColors.RED, "The amount must be positive.")); } } else { - src.sendMessage(Text.of(TextColors.RED, "The amount must only contain numbers and a single decimal point if needed.")); + src.sendMessage(Text.of(TextColors.RED, "The amount must be numeric.")); } return CommandResult.success(); diff --git a/src/main/java/com/erigitic/commands/BalanceCommand.java b/src/main/java/com/erigitic/commands/BalanceCommand.java index 5dfed3e0..00d66887 100644 --- a/src/main/java/com/erigitic/commands/BalanceCommand.java +++ b/src/main/java/com/erigitic/commands/BalanceCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -14,9 +39,6 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.text.format.TextColors; -/** - * Created by Eric on 5/4/2015. - */ public class BalanceCommand implements CommandExecutor { private Logger logger; private TotalEconomy totalEconomy; diff --git a/src/main/java/com/erigitic/commands/BalanceTopCommand.java b/src/main/java/com/erigitic/commands/BalanceTopCommand.java index 5b82096a..ba421dbf 100644 --- a/src/main/java/com/erigitic/commands/BalanceTopCommand.java +++ b/src/main/java/com/erigitic/commands/BalanceTopCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -21,13 +46,9 @@ import org.spongepowered.api.text.format.TextColor; import org.spongepowered.api.text.format.TextColors; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.math.BigDecimal; +import java.util.*; -/** - * Created by Eric on 6/2/2016. - */ public class BalanceTopCommand implements CommandExecutor { private Logger logger; private TotalEconomy totalEconomy; @@ -47,20 +68,26 @@ public BalanceTopCommand(TotalEconomy totalEconomy) { public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { ConfigurationNode accountNode = accountManager.getAccountConfig(); List accountBalances = new ArrayList<>(); + Map accountBalancesMap = new HashMap<>(); + Currency defaultCurrency = accountManager.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(); - Currency defaultCurrency = accountManager.getDefaultCurrency(); Text playerName = playerAccount.getDisplayName(); - Text playerBalance = defaultCurrency.format(playerAccount.getBalance(defaultCurrency)); - accountBalances.add(Text.of(TextColors.GRAY, playerName.toPlain(), ": ", TextColors.GOLD, playerBalance.toPlain())); + accountBalancesMap.put(playerName.toPlain(), playerAccount.getBalance(defaultCurrency)); }); - builder.reset().title(Text.of(TextColors.GOLD, "Top Balances")) + List> unsortedList = new LinkedList<>(accountBalancesMap.entrySet()); + unsortedList.sort((Map.Entry o1, Map.Entry 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()))); + + builder.title(Text.of(TextColors.GOLD, "Top Balances")) .contents(accountBalances) - .padding(Text.of(TextColors.GRAY, "-")) .sendTo(src); return CommandResult.success(); diff --git a/src/main/java/com/erigitic/commands/JobCommand.java b/src/main/java/com/erigitic/commands/JobCommand.java index bd161549..70f70c1d 100644 --- a/src/main/java/com/erigitic/commands/JobCommand.java +++ b/src/main/java/com/erigitic/commands/JobCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -12,9 +37,6 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.text.format.TextColors; -/** - * Created by Eric on 5/5/2015. - */ public class JobCommand implements CommandExecutor { private AccountManager accountManager; private TEJobs teJobs; diff --git a/src/main/java/com/erigitic/commands/JobInfoCommand.java b/src/main/java/com/erigitic/commands/JobInfoCommand.java index 74c451ff..55cc9828 100644 --- a/src/main/java/com/erigitic/commands/JobInfoCommand.java +++ b/src/main/java/com/erigitic/commands/JobInfoCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -21,9 +46,6 @@ import java.util.ArrayList; import java.util.List; -/** - * Created by Eric on 11/3/2015. - */ public class JobInfoCommand implements CommandExecutor { private TEJobs teJobs; private AccountManager accountManager; @@ -79,9 +101,14 @@ private List getJobValues(String jobName, String nodeName, String title) { jobsConfig.getNode(jobName, nodeName).getChildrenMap().keySet().forEach(value -> { if (value instanceof String) { - String valueFormatted = WordUtils.capitalize(((String) value).replaceAll("_", " ")); String expReward = jobsConfig.getNode(jobName, nodeName, value, "expreward").getString(); String moneyReward = jobsConfig.getNode(jobName, nodeName, value, "pay").getString(); + String valueFormatted; + + if (((String) value).contains(":")) + value = ((String) value).split(":")[1]; + + valueFormatted = WordUtils.capitalize(((String) value).replaceAll("_", " ")); jobValues.add(Text.of(TextColors.LIGHT_PURPLE, WordUtils.capitalize(nodeName + ": "), TextColors.GRAY, valueFormatted, " | ", TextColors.GREEN, expReward, " exp", TextColors.GRAY, " | ", TextColors.GOLD, diff --git a/src/main/java/com/erigitic/commands/JobToggleCommand.java b/src/main/java/com/erigitic/commands/JobToggleCommand.java index 525904fe..ef891864 100644 --- a/src/main/java/com/erigitic/commands/JobToggleCommand.java +++ b/src/main/java/com/erigitic/commands/JobToggleCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -9,9 +34,6 @@ import org.spongepowered.api.command.spec.CommandExecutor; import org.spongepowered.api.entity.living.player.Player; -/** - * Created by Eric on 5/29/2015. - */ public class JobToggleCommand implements CommandExecutor { private AccountManager accountManager; diff --git a/src/main/java/com/erigitic/commands/PayCommand.java b/src/main/java/com/erigitic/commands/PayCommand.java index 3269ee01..c07630c6 100644 --- a/src/main/java/com/erigitic/commands/PayCommand.java +++ b/src/main/java/com/erigitic/commands/PayCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -23,9 +48,6 @@ import java.math.BigDecimal; -/** - * Created by Eric on 5/3/2015. - */ public class PayCommand implements CommandExecutor { private Logger logger; private TotalEconomy totalEconomy; @@ -63,10 +85,10 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm if (transferResult.getResult() == ResultType.SUCCESS) { sender.sendMessage(Text.of(TextColors.GRAY, "You have sent ", TextColors.GOLD, defaultCurrency.format(amount), - TextColors.GRAY, " to ", TextColors.GOLD, recipient.getName(), ".")); + TextColors.GRAY, " to ", TextColors.GOLD, recipient.getName(), TextColors.GRAY, ".")); recipient.sendMessage(Text.of(TextColors.GRAY, "You have received ", TextColors.GOLD, defaultCurrency.format(amount), - TextColors.GRAY, " from ", TextColors.GOLD, sender.getName(), ".")); + TextColors.GRAY, " from ", TextColors.GOLD, sender.getName(), TextColors.GRAY, ".")); } else if (transferResult.getResult() == ResultType.ACCOUNT_NO_FUNDS) { sender.sendMessage(Text.of(TextColors.RED, "Insufficient funds.")); } diff --git a/src/main/java/com/erigitic/commands/SetBalanceCommand.java b/src/main/java/com/erigitic/commands/SetBalanceCommand.java index 80a3108d..25368fd2 100644 --- a/src/main/java/com/erigitic/commands/SetBalanceCommand.java +++ b/src/main/java/com/erigitic/commands/SetBalanceCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -17,9 +42,6 @@ import java.math.BigDecimal; -/** - * Created by Eric on 8/7/2015. - */ public class SetBalanceCommand implements CommandExecutor { private TotalEconomy totalEconomy; private AccountManager accountManager; diff --git a/src/main/java/com/erigitic/commands/ViewBalanceCommand.java b/src/main/java/com/erigitic/commands/ViewBalanceCommand.java index c1531134..c3250f8a 100644 --- a/src/main/java/com/erigitic/commands/ViewBalanceCommand.java +++ b/src/main/java/com/erigitic/commands/ViewBalanceCommand.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.commands; import com.erigitic.config.AccountManager; @@ -16,9 +41,6 @@ import java.math.BigDecimal; -/** - * Created by Eric on 12/22/2015. - */ public class ViewBalanceCommand implements CommandExecutor { private TotalEconomy totalEconomy; private AccountManager accountManager; diff --git a/src/main/java/com/erigitic/config/AccountManager.java b/src/main/java/com/erigitic/config/AccountManager.java index f8d5e672..ecf4cb5f 100644 --- a/src/main/java/com/erigitic/config/AccountManager.java +++ b/src/main/java/com/erigitic/config/AccountManager.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.config; import com.erigitic.main.TotalEconomy; @@ -22,9 +47,6 @@ import java.util.Set; import java.util.UUID; -/** - * Created by Eric on 5/2/2015. - */ public class AccountManager implements EconomyService { private TotalEconomy totalEconomy; private Logger logger; @@ -32,9 +54,6 @@ public class AccountManager implements EconomyService { private ConfigurationLoader loader; private ConfigurationNode accountConfig; - /** - * Default Constructor so we can access this class from elsewhere - */ public AccountManager(TotalEconomy totalEconomy) { this.totalEconomy = totalEconomy; logger = totalEconomy.getLogger(); @@ -43,7 +62,7 @@ public AccountManager(TotalEconomy totalEconomy) { } /** - * Setup the config file that will contain the user accounts. These accounts will contain the users money amount. + * Setup the config file that will contain the user accounts. */ public void setupConfig() { accountsFile = new File(totalEconomy.getConfigDir(), "accounts.conf"); @@ -60,19 +79,24 @@ public void setupConfig() { } } - /** - * Creates a new account for the player. - * - * @param uuid object representing the UUID of a player + * Reload the account config */ + public void reloadConfig() { + try { + accountConfig = loader.load(); + logger.info("Reloading account configuration file."); + } catch (IOException e) { + logger.warn("Could not reload account configuration file!"); + } + } + @Override public Optional getOrCreateAccount(UUID uuid) { String currencyName = getDefaultCurrency().getDisplayName().toPlain().toLowerCase(); TEAccount playerAccount = new TEAccount(totalEconomy, this, uuid); try { -// if (accountConfig.getNode(uuid.toString(), currencyName + "-balance").getValue() == null) { if (!hasAccount(uuid)) { accountConfig.getNode(uuid.toString(), currencyName + "-balance").setValue(playerAccount.getDefaultBalance(getDefaultCurrency())); accountConfig.getNode(uuid.toString(), "job").setValue("Unemployed"); @@ -107,7 +131,6 @@ public Optional getOrCreateAccount(String identifier) { @Override public boolean hasAccount(UUID uuid) { - //accountConfig.getNode(uuid.toString(), getDefaultCurrency() + "-balance").getValue() != null return accountConfig.getNode(uuid.toString()).getValue() != null; } @@ -121,7 +144,6 @@ public Currency getDefaultCurrency() { return totalEconomy.getDefaultCurrency(); } - //TODO: Possibly implement multiple currencies. Need some input on it. Up to the users. @Override public Set getCurrencies() { return new HashSet(); @@ -132,6 +154,11 @@ public void registerContextCalculator(ContextCalculator calculator) { } + /** + * Toggle a player's exp/money notifications for jobs + * + * @param player an object representing the player toggling notifications + */ public void toggleNotifications(Player player) { boolean notify = accountConfig.getNode(player.getUniqueId().toString(), "jobnotifications").getBoolean(); @@ -156,6 +183,9 @@ public void toggleNotifications(Player player) { } } + /** + * Save the account configuration file + */ public void saveAccountConfig() { try { loader.save(accountConfig); @@ -167,7 +197,7 @@ public void saveAccountConfig() { /** * Get the account configuration file * - * @return ConfigurationNode + * @return ConfigurationNode the account configuration */ public ConfigurationNode getAccountConfig() { return accountConfig; @@ -176,7 +206,7 @@ public ConfigurationNode getAccountConfig() { /** * Get the configuration manager * - * @return ConfigurationLoader + * @return ConfigurationLoader the configuration loader for the account config */ public ConfigurationLoader getConfigManager() { return loader; diff --git a/src/main/java/com/erigitic/config/TEAccount.java b/src/main/java/com/erigitic/config/TEAccount.java index 3d303a3c..8740f5a8 100644 --- a/src/main/java/com/erigitic/config/TEAccount.java +++ b/src/main/java/com/erigitic/config/TEAccount.java @@ -1,7 +1,33 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.config; import com.erigitic.main.TotalEconomy; import ninja.leaping.configurate.ConfigurationNode; +import org.slf4j.Logger; import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.economy.Currency; @@ -13,14 +39,12 @@ import java.math.BigDecimal; import java.util.*; -/** - * Created by Eric on 1/1/2016. - */ public class TEAccount implements UniqueAccount { private TotalEconomy totalEconomy; private AccountManager accountManager; private UUID uuid; + private Logger logger; private ConfigurationNode accountConfig; @@ -34,7 +58,10 @@ public TEAccount(TotalEconomy totalEconomy, AccountManager accountManager, UUID @Override public Text getDisplayName() { - return Text.of(totalEconomy.getServer().getPlayer(uuid).get().getName()); + if (totalEconomy.getUserStorageService().get(uuid).isPresent()) + return Text.of(totalEconomy.getUserStorageService().get(uuid).get().getName()); + + return Text.of("PLAYER NAME"); } @Override diff --git a/src/main/java/com/erigitic/config/TECurrency.java b/src/main/java/com/erigitic/config/TECurrency.java index 5515923f..287c429d 100644 --- a/src/main/java/com/erigitic/config/TECurrency.java +++ b/src/main/java/com/erigitic/config/TECurrency.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.config; import org.spongepowered.api.service.economy.Currency; @@ -7,9 +32,6 @@ import java.text.NumberFormat; import java.util.Locale; -/** - * Created by Eric on 1/1/2016. - */ public class TECurrency implements Currency { private Text singular; diff --git a/src/main/java/com/erigitic/config/TEEconomyTransactionEvent.java b/src/main/java/com/erigitic/config/TEEconomyTransactionEvent.java index 8d0e8a3b..742a8126 100644 --- a/src/main/java/com/erigitic/config/TEEconomyTransactionEvent.java +++ b/src/main/java/com/erigitic/config/TEEconomyTransactionEvent.java @@ -1,15 +1,38 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.config; import org.spongepowered.api.Sponge; import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.event.cause.NamedCause; import org.spongepowered.api.event.economy.EconomyTransactionEvent; +import org.spongepowered.api.event.impl.AbstractEvent; import org.spongepowered.api.service.economy.transaction.TransactionResult; -/** - * Created by Eric on 1/16/2016. - */ -public class TEEconomyTransactionEvent implements EconomyTransactionEvent { +public class TEEconomyTransactionEvent extends AbstractEvent implements EconomyTransactionEvent { private TransactionResult transactionResult; diff --git a/src/main/java/com/erigitic/config/TETransactionResult.java b/src/main/java/com/erigitic/config/TETransactionResult.java index 56af15fe..4a6fe67f 100644 --- a/src/main/java/com/erigitic/config/TETransactionResult.java +++ b/src/main/java/com/erigitic/config/TETransactionResult.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.config; import org.spongepowered.api.service.context.Context; @@ -10,9 +35,6 @@ import java.math.BigDecimal; import java.util.Set; -/** - * Created by Eric on 1/2/2016. - */ public class TETransactionResult implements TransactionResult { private Account account; private Currency currency; diff --git a/src/main/java/com/erigitic/config/TETransferResult.java b/src/main/java/com/erigitic/config/TETransferResult.java index 1f058387..0b96d479 100644 --- a/src/main/java/com/erigitic/config/TETransferResult.java +++ b/src/main/java/com/erigitic/config/TETransferResult.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.config; import org.spongepowered.api.service.context.Context; @@ -10,9 +35,6 @@ import java.math.BigDecimal; import java.util.Set; -/** - * Created by Eric on 1/2/2016. - */ public class TETransferResult implements TransferResult { private Account account; diff --git a/src/main/java/com/erigitic/config/TEVirtualAccount.java b/src/main/java/com/erigitic/config/TEVirtualAccount.java index 16d2fc64..ba1a6e7c 100644 --- a/src/main/java/com/erigitic/config/TEVirtualAccount.java +++ b/src/main/java/com/erigitic/config/TEVirtualAccount.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.config; import com.erigitic.main.TotalEconomy; @@ -16,9 +41,6 @@ import java.math.BigDecimal; import java.util.*; -/** - * Created by Eric on 1/30/2016. - */ public class TEVirtualAccount implements VirtualAccount { private TotalEconomy totalEconomy; private AccountManager accountManager; @@ -39,7 +61,6 @@ public Text getDisplayName() { return Text.of(identifier); } - //TODO: Allow the starting balance for virtual accounts to be set/changed from config @Override public BigDecimal getDefaultBalance(Currency currency) { return BigDecimal.ZERO; @@ -174,7 +195,6 @@ public TransferResult transfer(Account to, Currency currency, BigDecimal amount, BigDecimal curBalance = getBalance(currency, contexts); BigDecimal newBalance = curBalance.subtract(amount); - //TODO: Might not need to check if the balance is greater then zero here since it is being done in the withdraw function if (newBalance.compareTo(BigDecimal.ZERO) >= 0) { withdraw(currency, amount, cause, contexts); diff --git a/src/main/java/com/erigitic/jobs/Job.java b/src/main/java/com/erigitic/jobs/Job.java index f3d0059c..c8e7a120 100644 --- a/src/main/java/com/erigitic/jobs/Job.java +++ b/src/main/java/com/erigitic/jobs/Job.java @@ -1,10 +1,32 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.jobs; import ninja.leaping.configurate.ConfigurationNode; -/** - * Created by Eric on 10/29/2015. - */ public interface Job { void setupJobValues(ConfigurationNode jobsConfig); } diff --git a/src/main/java/com/erigitic/jobs/TEJobs.java b/src/main/java/com/erigitic/jobs/TEJobs.java index fe7c1ca1..5e2c38c1 100644 --- a/src/main/java/com/erigitic/jobs/TEJobs.java +++ b/src/main/java/com/erigitic/jobs/TEJobs.java @@ -1,3 +1,28 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.jobs; import com.erigitic.config.AccountManager; @@ -12,6 +37,7 @@ import ninja.leaping.configurate.hocon.HoconConfigurationLoader; import ninja.leaping.configurate.loader.ConfigurationLoader; import org.slf4j.Logger; +import org.spongepowered.api.Sponge; import org.spongepowered.api.block.tileentity.Sign; import org.spongepowered.api.block.tileentity.TileEntity; import org.spongepowered.api.data.Transaction; @@ -41,17 +67,12 @@ import java.util.*; import java.util.concurrent.TimeUnit; -/** - * Created by Eric on 5/5/2015. - */ public class TEJobs { private TotalEconomy totalEconomy; private AccountManager accountManager; private ConfigurationNode accountConfig; private Logger logger; - private Task task; - private File jobsFile; private ConfigurationLoader loader; private ConfigurationNode jobsConfig; @@ -61,15 +82,9 @@ public class TEJobs { private WarriorJob warrior; private FishermanJob fisherman; - /** - * Constructor - * - * @param totalEconomy object representing this plugin - */ public TEJobs(TotalEconomy totalEconomy) { this.totalEconomy = totalEconomy; - //Initialize each job miner = new MinerJob(); lumberjack = new LumberjackJob(); warrior = new WarriorJob(); @@ -85,11 +100,14 @@ public TEJobs(TotalEconomy totalEconomy) { startSalaryTask(); } + /** + * Start the timer that pays out the salary to each player after a specified time in seconds + */ private void startSalaryTask() { Scheduler scheduler = totalEconomy.getGame().getScheduler(); Task.Builder payTask = scheduler.createTaskBuilder(); - task = payTask.execute(() -> { + payTask.execute(() -> { for (Player player : totalEconomy.getServer().getOnlinePlayers()) { BigDecimal salary = new BigDecimal(jobsConfig.getNode(getPlayerJob(player), "salary").getString()); boolean salaryDisabled = jobsConfig.getNode(getPlayerJob(player), "disablesalary").getBoolean(); @@ -135,11 +153,15 @@ public void setupConfig() { } } + /** + * Reload the jobs config + */ public void reloadConfig() { try { jobsConfig = loader.load(); + logger.info("Reloading jobs configuration file."); } catch (IOException e) { - logger.warn("Could not reload jobs config file!"); + logger.warn("Could not reload jobs configuration file!"); } } @@ -202,6 +224,12 @@ public boolean jobExists(String jobName) { return false; } + /** + * Convert strings to titles (title -> Title) + * + * @param input the string to be titleized + * @return String the titileized version of the input + */ public String convertToTitle(String input) { return input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase(); } @@ -217,7 +245,7 @@ public void setJob(Player player, String jobName) { boolean jobPermissions = totalEconomy.isJobPermissions(); if (jobExists(jobName)) { - if ((jobPermissions && player.hasPermission("main.job." + jobName)) || !jobPermissions) { + if ((jobPermissions && player.hasPermission("totaleconomy.job." + jobName)) || !jobPermissions) { jobName = convertToTitle(jobName); accountConfig.getNode(playerUUID.toString(), "job").setValue(jobName); @@ -300,10 +328,20 @@ public String getJobList() { return jobsConfig.getNode("jobs").getString(); } + /** + * Getter for the jobs configuration + * + * @return ConfigurationNode the jobs configuration + */ public ConfigurationNode getJobsConfig() { return jobsConfig; } + /** + * Checks sign contents and converts it to a "Job Changing" sign if conditions are met + * + * @param event ChangeSignEvent + */ @Listener public void onJobSignCheck(ChangeSignEvent event) { SignData data = event.getText(); @@ -330,6 +368,12 @@ public void onJobSignCheck(ChangeSignEvent event) { } } + /** + * Called when a player clicks a sign. If the clicked sign is a "Job Changing" sign then the player's job will + * be changed on click. + * + * @param event InteractBlockEvent + */ @Listener public void onSignInteract(InteractBlockEvent event) { if (event.getCause().first(Player.class).isPresent()) { @@ -367,7 +411,7 @@ public void onSignInteract(InteractBlockEvent event) { * block that was broken is present in the config of the player's job. If it is, it will grab the job exp reward as * well as the pay. * - * @param event PlayerBlockBreakEvent + * @param event ChangeBlockEvent.Break */ @Listener public void onPlayerBlockBreak(ChangeBlockEvent.Break event) { @@ -375,45 +419,49 @@ public void onPlayerBlockBreak(ChangeBlockEvent.Break event) { Player player = event.getCause().first(Player.class).get(); UUID playerUUID = player.getUniqueId(); String playerJob = getPlayerJob(player); + String blockName = event.getTransactions().get(0).getOriginal().getState().getType().getName(); + Optional blockCreator = event.getTransactions().get(0).getOriginal().getCreator(); - if (event.getTransactions().get(0).getOriginal().getState().getType().getName().split(":").length >= 2) { - String blockName = event.getTransactions().get(0).getOriginal().getState().getType().getName().split(":")[1]; - Optional blockCreator = event.getTransactions().get(0).getOriginal().getCreator(); - - // Checks if the users current job has the break node. - boolean hasBreakNode = (jobsConfig.getNode(playerJob, "break").getValue() != null); + // Checks if the users current job has the break node. + boolean hasBreakNode = (jobsConfig.getNode(playerJob, "break").getValue() != null); - if (jobsConfig.getNode(playerJob).getValue() != null) { - if (hasBreakNode && jobsConfig.getNode(playerJob, "break", blockName).getValue() != null) { - if (!blockCreator.isPresent()) { - int expAmount = jobsConfig.getNode(playerJob, "break", blockName, "expreward").getInt(); - boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean(); - - BigDecimal payAmount = new BigDecimal(jobsConfig.getNode(playerJob, "break", blockName, "pay").getString()).setScale(2, BigDecimal.ROUND_DOWN); + if (jobsConfig.getNode(playerJob).getValue() != null) { + if (hasBreakNode && jobsConfig.getNode(playerJob, "break", blockName).getValue() != null) { + if (!blockCreator.isPresent()) { + int expAmount = jobsConfig.getNode(playerJob, "break", blockName, "expreward").getInt(); + boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean(); - TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get(); + BigDecimal payAmount = new BigDecimal(jobsConfig.getNode(playerJob, "break", blockName, "pay").getString()).setScale(2, BigDecimal.ROUND_DOWN); - if (notify) { - player.sendMessage(Text.of(TextColors.GOLD, accountManager.getDefaultCurrency().getSymbol(), payAmount, TextColors.GRAY, " has been added to your balance.")); - } + TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get(); - addExp(player, expAmount); - playerAccount.deposit(accountManager.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer()))); - checkForLevel(player); + if (notify) { + player.sendMessage(Text.of(TextColors.GOLD, accountManager.getDefaultCurrency().getSymbol(), payAmount, TextColors.GRAY, " has been added to your balance.")); } + + addExp(player, expAmount); + playerAccount.deposit(accountManager.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer()))); + checkForLevel(player); } } } } } + /** + * Used for the place option in jobs. Will check if the job has the place node and if it does it will check if the + * block that was placed is present in the config of the player's job. If it is, it will grab the job exp reward as + * well as the pay. + * + * @param event ChangeBlockEvent.Place + */ @Listener public void onPlayerPlaceBlock(ChangeBlockEvent.Place event) { if (event.getCause().first(Player.class).isPresent()) { Player player = event.getCause().first(Player.class).get(); UUID playerUUID = player.getUniqueId(); String playerJob = getPlayerJob(player); - String blockName = event.getTransactions().get(0).getFinal().getState().getType().getName().split(":")[1]; + String blockName = event.getTransactions().get(0).getFinal().getState().getType().getName(); //Checks if the users current job has the place node. boolean hasPlaceNode = (jobsConfig.getNode(playerJob, "place").getValue() != null); @@ -439,6 +487,13 @@ public void onPlayerPlaceBlock(ChangeBlockEvent.Place event) { } } + /** + * Used for the break option in jobs. Will check if the job has the break node and if it does it will check if the + * block that was broken is present in the config of the player's job. If it is, it will grab the job exp reward as + * well as the pay. + * + * @param event DestructEntityEvent.Death + */ @Listener public void onPlayerKillEntity(DestructEntityEvent.Death event) { Optional optDamageSource = event.getCause().first(EntityDamageSource.class); @@ -448,6 +503,14 @@ public void onPlayerKillEntity(DestructEntityEvent.Death event) { Entity killer = damageSource.getSource(); Entity victim = event.getTargetEntity(); + if (!(killer instanceof Player)) { + // If a projectile was shot to kill an entity, this will grab the player who shot it + Optional damageCreator = damageSource.getSource().getCreator(); + + if (damageCreator.isPresent()) + killer = Sponge.getServer().getPlayer(damageCreator.get()).get(); + } + if (killer instanceof Player) { Player player = (Player) killer; UUID playerUUID = player.getUniqueId(); @@ -478,6 +541,13 @@ public void onPlayerKillEntity(DestructEntityEvent.Death event) { } } + /** + * Used for the catch option in jobs. Will check if the job has the catch node and if it does it will check if the + * item that was caught is present in the config of the player's job. If it is, it will grab the job exp reward as + * well as the pay. + * + * @param event FishingEvent.Stop + */ @Listener public void onPlayerFish(FishingEvent.Stop event) { if (event.getCause().first(Player.class).isPresent()) { diff --git a/src/main/java/com/erigitic/jobs/jobs/FishermanJob.java b/src/main/java/com/erigitic/jobs/jobs/FishermanJob.java index eb27d324..59e65a84 100644 --- a/src/main/java/com/erigitic/jobs/jobs/FishermanJob.java +++ b/src/main/java/com/erigitic/jobs/jobs/FishermanJob.java @@ -1,11 +1,33 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.jobs.jobs; import com.erigitic.jobs.Job; import ninja.leaping.configurate.ConfigurationNode; -/** - * Created by Eric on 11/3/2015. - */ public class FishermanJob implements Job { public void setupJobValues(ConfigurationNode jobsConfig) { String[][] catchValues = {{"cod", "25", "50.00"}, {"salmon", "100", "150.00"}, {"pufferfish", "250", "300.00"}}; diff --git a/src/main/java/com/erigitic/jobs/jobs/LumberjackJob.java b/src/main/java/com/erigitic/jobs/jobs/LumberjackJob.java index 4b7deab8..3888a941 100644 --- a/src/main/java/com/erigitic/jobs/jobs/LumberjackJob.java +++ b/src/main/java/com/erigitic/jobs/jobs/LumberjackJob.java @@ -1,15 +1,37 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.jobs.jobs; import com.erigitic.jobs.Job; import ninja.leaping.configurate.ConfigurationNode; -/** - * Created by Eric on 10/29/2015. - */ public class LumberjackJob implements Job { public void setupJobValues(ConfigurationNode jobsConfig) { - String[][] breakValues = {{"log", "10", "1.00"}, {"leaves", "1", "0.01"}}; - String[][] placeValue = {{"sapling", "1", "0.10"}}; + String[][] breakValues = {{"minecraft:log", "10", "1.00"}, {"minecraft:leaves", "1", "0.01"}}; + String[][] placeValue = {{"minecraft:sapling", "1", "0.10"}}; for (int i = 0; i < breakValues.length; i++) { jobsConfig.getNode("Lumberjack", "break", breakValues[i][0], "expreward").setValue(breakValues[i][1]); diff --git a/src/main/java/com/erigitic/jobs/jobs/MinerJob.java b/src/main/java/com/erigitic/jobs/jobs/MinerJob.java index 3b932fd0..2ae70939 100644 --- a/src/main/java/com/erigitic/jobs/jobs/MinerJob.java +++ b/src/main/java/com/erigitic/jobs/jobs/MinerJob.java @@ -1,16 +1,38 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.jobs.jobs; import com.erigitic.jobs.Job; import ninja.leaping.configurate.ConfigurationNode; -/** - * Created by Eric on 10/29/2015. - */ public class MinerJob implements Job { public void setupJobValues(ConfigurationNode jobsConfig) { - String[][] breakValues = {{"coal_ore", "5", "0.25"}, {"iron_ore", "10", "0.50"}, {"lapis_ore", "20", "4.00"}, - {"gold_ore", "40", "5.00"}, {"diamond_ore", "100", "25.00"}, {"redstone_ore", "25", "2.00"}, - {"emerald_ore", "50", "12.50"}, {"quartz_ore", "5", "0.15"}}; + String[][] breakValues = {{"minecraft:coal_ore", "5", "0.25"}, {"minecraft:iron_ore", "10", "0.50"}, {"minecraft:lapis_ore", "20", "4.00"}, + {"minecraft:gold_ore", "40", "5.00"}, {"minecraft:diamond_ore", "100", "25.00"}, {"minecraft:redstone_ore", "25", "2.00"}, + {"minecraft:emerald_ore", "50", "12.50"}, {"minecraft:quartz_ore", "5", "0.15"}}; for (int i = 0; i < breakValues.length; i++) { jobsConfig.getNode("Miner", "break", breakValues[i][0], "expreward").setValue(breakValues[i][1]); diff --git a/src/main/java/com/erigitic/jobs/jobs/WarriorJob.java b/src/main/java/com/erigitic/jobs/jobs/WarriorJob.java index 43dac63b..38dd3a3e 100644 --- a/src/main/java/com/erigitic/jobs/jobs/WarriorJob.java +++ b/src/main/java/com/erigitic/jobs/jobs/WarriorJob.java @@ -1,11 +1,33 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.jobs.jobs; import com.erigitic.jobs.Job; import ninja.leaping.configurate.ConfigurationNode; -/** - * Created by Eric on 10/29/2015. - */ public class WarriorJob implements Job { public void setupJobValues(ConfigurationNode jobsConfig) { String[][] killValues = {{"skeleton", "10", "1.00"}, {"zombie", "10", "1.00"}, {"creeper", "10", "1.00"}, {"spider", "10", "1.00"}}; diff --git a/src/main/java/com/erigitic/main/TotalEconomy.java b/src/main/java/com/erigitic/main/TotalEconomy.java index 4cae50c0..06597176 100644 --- a/src/main/java/com/erigitic/main/TotalEconomy.java +++ b/src/main/java/com/erigitic/main/TotalEconomy.java @@ -1,10 +1,34 @@ +/* + * This file is part of Total Economy, licensed under the MIT License (MIT). + * + * Copyright (c) Eric Grandt + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.erigitic.main; import com.erigitic.commands.*; import com.erigitic.config.AccountManager; import com.erigitic.config.TECurrency; import com.erigitic.jobs.TEJobs; -import com.erigitic.shops.ShopKeeper; import com.google.inject.Inject; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.commented.CommentedConfigurationNode; @@ -25,6 +49,7 @@ import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.economy.Currency; import org.spongepowered.api.service.economy.EconomyService; +import org.spongepowered.api.service.user.UserStorageService; import org.spongepowered.api.text.Text; import java.io.File; @@ -32,8 +57,9 @@ import java.math.BigDecimal; import java.text.NumberFormat; import java.text.ParsePosition; +import java.util.Optional; -@Plugin(id = "totaleconomy", name = "Total Economy", version = "1.5.0", description = "All in one economy plugin for Minecraft/Sponge") +@Plugin(id = "totaleconomy", name = "Total Economy", version = "1.5.2", description = "All in one economy plugin for Minecraft/Sponge") public class TotalEconomy { @Inject @@ -57,29 +83,24 @@ public class TotalEconomy { @Inject private PluginContainer pluginContainer; + private UserStorageService userStorageService; + private ConfigurationNode config = null; private Currency defaultCurrency; private AccountManager accountManager; + private TEJobs teJobs; - private ShopKeeper shopKeeper; private boolean loadJobs = true; private boolean loadSalary = true; private boolean jobPermissions = false; private boolean jobNotifications = true; - - private boolean loadShopKeeper = true; private boolean loadMoneyCap = false; private BigDecimal moneyCap; - /** - * Setup all config files - * - * @param event - */ @Listener public void preInit(GamePreInitializationEvent event) { setupConfig(); @@ -92,7 +113,6 @@ public void preInit(GamePreInitializationEvent event) { jobPermissions = config.getNode("features", "jobs", "permissions").getBoolean(); jobNotifications = config.getNode("features", "jobs", "notifications").getBoolean(); - loadShopKeeper = config.getNode("features", "shopkeeper").getBoolean(); loadMoneyCap = config.getNode("features", "moneycap", "enable").getBoolean(); accountManager = new AccountManager(this); @@ -104,21 +124,12 @@ public void preInit(GamePreInitializationEvent event) { teJobs = new TEJobs(this); } - if (loadShopKeeper == true) { - shopKeeper = new ShopKeeper(this); - } - if (loadMoneyCap == true) { moneyCap = BigDecimal.valueOf(config.getNode("features", "moneycap", "amount").getFloat()) .setScale(2, BigDecimal.ROUND_DOWN); } } - /** - * Create and register all commands. - * - * @param event - */ @Listener public void init(GameInitializationEvent event) { createAndRegisterCommands(); @@ -134,9 +145,17 @@ public void postInit(GamePostInitializationEvent event) { @Listener public void onServerStart(GameStartedServerEvent event) { + userStorageService = game.getServiceManager().provideUnchecked(UserStorageService.class); + logger.info("Total Economy Started"); } + @Listener + public void onServerStopping(GameStoppingServerEvent event) { + logger.info("Total Economy Stopping"); + accountManager.saveAccountConfig(); + } + @Listener public void onServerStop(GameStoppedServerEvent event) { logger.info("Total Economy Stopped"); @@ -159,10 +178,11 @@ public void onPlayerJoin(ClientConnectionEvent.Join event) { @Listener public void onGameReload(GameReloadEvent event) { teJobs.reloadConfig(); + accountManager.reloadConfig(); } /** - * Setup the default config file, TotalEconomy.conf. + * Setup the default config file, totaleconomy.conf. */ private void setupConfig() { try { @@ -175,31 +195,17 @@ private void setupConfig() { config.getNode("features", "jobs", "notifications").setValue(true); config.getNode("features", "moneycap", "enable").setValue(loadMoneyCap); config.getNode("features", "moneycap", "amount").setValue(10000000); - config.getNode("features", "shopkeeper").setValue(loadShopKeeper); config.getNode("startbalance").setValue(100); config.getNode("currency-singular").setValue("Dollar"); config.getNode("currency-plural").setValue("Dollars"); config.getNode("symbol").setValue("$"); loader.save(config); } - - // TODO: Make this into its own function that will update ALL values - // Change job notifaction state for pre existing configuration files - ConfigurationNode jobNotificationState = config.getNode("features", "jobs", "notifications"); - if (jobNotificationState.isVirtual()) { - jobNotificationState.setValue(true); - - loader.save(config); - } - } catch (IOException e) { logger.warn("Main config could not be loaded/created/changed!"); } } - /** - * Creates and registers commands - */ private void createAndRegisterCommands() { CommandSpec payCommand = CommandSpec.builder() .description(Text.of("Pay another player")) @@ -259,7 +265,6 @@ private void createAndRegisterCommands() { .executor(new JobToggleCommand(this)) .build(); - //TODO: Implement later? CommandSpec jobInfoCmd = CommandSpec.builder() .description(Text.of("Prints out a list of items that reward exp and money for the current job")) .permission("totaleconomy.command.jobinfo") @@ -351,4 +356,8 @@ public BigDecimal getMoneyCap() { public boolean hasJobNotifications() { return jobNotifications; } + public UserStorageService getUserStorageService() { + return userStorageService; + } + } \ No newline at end of file diff --git a/src/main/java/com/erigitic/shops/ShopKeeper.java b/src/main/java/com/erigitic/shops/ShopKeeper.java deleted file mode 100644 index 54e1e61e..00000000 --- a/src/main/java/com/erigitic/shops/ShopKeeper.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.erigitic.shops; - -import com.erigitic.main.TotalEconomy; - -/** - * Created by Eric on 5/29/2015. - */ -public class ShopKeeper { - - private TotalEconomy totalEconomy; - - public ShopKeeper(TotalEconomy totalEconomy) { - this.totalEconomy = totalEconomy; - } - - -}