From 03b61e6d3826b4150a0d39b7455a7de19a47a531 Mon Sep 17 00:00:00 2001 From: Flibio Date: Tue, 8 Mar 2016 07:31:56 -0700 Subject: [PATCH] Refactored for API 4.0.0 --- pom.xml | 4 +-- .../EconomyLite/API/LiteEconomyService.java | 33 +++++++------------ .../EconomyLite/API/LiteUniqueAccount.java | 8 ++--- .../EconomyLite/Commands/AddCommand.java | 2 +- .../EconomyLite/Commands/BalanceCommand.java | 2 +- .../Commands/BusinessDeleteCommand.java | 2 +- .../Commands/BusinessTransferCommand.java | 2 +- .../EconomyLite/Commands/PayCommand.java | 8 ++--- .../Commands/PayOverrideCommand.java | 6 ++-- .../Commands/PlayerBalanceCommand.java | 2 +- .../EconomyLite/Commands/RemoveCommand.java | 2 +- .../EconomyLite/Commands/SetCommand.java | 2 +- src/me/Flibio/EconomyLite/EconomyLite.java | 5 +-- .../Listeners/BalanceChangeListener.java | 2 +- .../Listeners/PlayerJoinListener.java | 4 +-- 15 files changed, 38 insertions(+), 46 deletions(-) diff --git a/pom.xml b/pom.xml index a5bd618..338aea5 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 EconomyLite EconomyLite - 1.1.8 + 1.1.9 jar EconomyLite An economy plugin for Sponge @@ -60,7 +60,7 @@ org.spongepowered spongeapi - 3.1.0-SNAPSHOT + 4.0.0-SNAPSHOT provided diff --git a/src/me/Flibio/EconomyLite/API/LiteEconomyService.java b/src/me/Flibio/EconomyLite/API/LiteEconomyService.java index 638b023..66a7033 100644 --- a/src/me/Flibio/EconomyLite/API/LiteEconomyService.java +++ b/src/me/Flibio/EconomyLite/API/LiteEconomyService.java @@ -9,7 +9,6 @@ import org.spongepowered.api.service.economy.EconomyService; import org.spongepowered.api.service.economy.account.Account; import org.spongepowered.api.service.economy.account.UniqueAccount; -import org.spongepowered.api.service.economy.account.VirtualAccount; import java.util.HashSet; import java.util.Optional; @@ -27,7 +26,7 @@ public void registerContextCalculator(ContextCalculator arg0) { } @Override - public Optional createAccount(UUID uuid) { + public Optional getOrCreateAccount(UUID uuid) { if(playerManager.playerExists(uuid.toString())) { return Optional.of(new LiteUniqueAccount(uuid)); } else { @@ -40,7 +39,7 @@ public Optional createAccount(UUID uuid) { } @Override - public Optional createVirtualAccount(String id) { + public Optional getOrCreateAccount(String id) { if(businessManager.businessExists(id)) { return Optional.of(new LiteVirtualAccount(id)); } else { @@ -52,24 +51,6 @@ public Optional createVirtualAccount(String id) { } } - @Override - public Optional getAccount(UUID uuid) { - if(playerManager.playerExists(uuid.toString())) { - return Optional.of(new LiteUniqueAccount(uuid)); - } else { - return Optional.empty(); - } - } - - @Override - public Optional getAccount(String id) { - if(businessManager.businessExists(id)) { - return Optional.of(new LiteVirtualAccount(id)); - } else { - return Optional.empty(); - } - } - @Override public Set getCurrencies() { HashSet set = new HashSet(); @@ -82,4 +63,14 @@ public Currency getDefaultCurrency() { return EconomyLite.getCurrency(); } + @Override + public boolean hasAccount(UUID uuid) { + return playerManager.playerExists(uuid.toString()); + } + + @Override + public boolean hasAccount(String id) { + return businessManager.businessExists(id); + } + } diff --git a/src/me/Flibio/EconomyLite/API/LiteUniqueAccount.java b/src/me/Flibio/EconomyLite/API/LiteUniqueAccount.java index c628de7..a2f1c18 100644 --- a/src/me/Flibio/EconomyLite/API/LiteUniqueAccount.java +++ b/src/me/Flibio/EconomyLite/API/LiteUniqueAccount.java @@ -161,9 +161,9 @@ public String getIdentifier() { return this.uuid.toString(); } - @Override - public UUID getUUID() { - return this.uuid; - } + @Override + public UUID getUniqueId() { + return this.uuid; + } } diff --git a/src/me/Flibio/EconomyLite/Commands/AddCommand.java b/src/me/Flibio/EconomyLite/Commands/AddCommand.java index 885af28..2959f11 100644 --- a/src/me/Flibio/EconomyLite/Commands/AddCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/AddCommand.java @@ -47,7 +47,7 @@ public void run() { //Get the players UUID String uuid = playerManager.getUUID(playerName); if(!uuid.isEmpty()) { - Optional uOpt = economyService.getAccount(UUID.fromString(uuid)); + Optional uOpt = economyService.getOrCreateAccount(UUID.fromString(uuid)); if(!uOpt.isPresent()) { //Account is not present source.sendMessage(textUtils.basicText("An internal error has occured!", TextColors.RED)); diff --git a/src/me/Flibio/EconomyLite/Commands/BalanceCommand.java b/src/me/Flibio/EconomyLite/Commands/BalanceCommand.java index 125a322..ddfd6a0 100644 --- a/src/me/Flibio/EconomyLite/Commands/BalanceCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/BalanceCommand.java @@ -77,7 +77,7 @@ public void run() { } } else { //Player wants to view their balance - Optional uOpt = economyService.getAccount(player.getUniqueId()); + Optional uOpt = economyService.getOrCreateAccount(player.getUniqueId()); if(!uOpt.isPresent()) { //Account is not present source.sendMessage(textUtils.basicText("An internal error has occured!", TextColors.RED)); diff --git a/src/me/Flibio/EconomyLite/Commands/BusinessDeleteCommand.java b/src/me/Flibio/EconomyLite/Commands/BusinessDeleteCommand.java index 3257a82..bd958c5 100644 --- a/src/me/Flibio/EconomyLite/Commands/BusinessDeleteCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/BusinessDeleteCommand.java @@ -88,7 +88,7 @@ public void run() { player.sendMessage(textUtils.deleteSuccess(correctName)); //Distribute funds to all owners for(String uuid : owners) { - Optional uOpt = economyService.getAccount(UUID.fromString(uuid)); + Optional uOpt = economyService.getOrCreateAccount(UUID.fromString(uuid)); if(!uOpt.isPresent()) { //Account is not present source.sendMessage(textUtils.basicText("An internal error has occured!", TextColors.RED)); diff --git a/src/me/Flibio/EconomyLite/Commands/BusinessTransferCommand.java b/src/me/Flibio/EconomyLite/Commands/BusinessTransferCommand.java index 29e9aec..1838cac 100644 --- a/src/me/Flibio/EconomyLite/Commands/BusinessTransferCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/BusinessTransferCommand.java @@ -51,7 +51,7 @@ public void run() { int amount = rawAmount.get(); String businessName = rawBusiness.get().trim(); String correctName = businessManager.getCorrectBusinessName(businessName); - Optional uOpt = economyService.getAccount(player.getUniqueId()); + Optional uOpt = economyService.getOrCreateAccount(player.getUniqueId()); if(!uOpt.isPresent()) { //Account is not present source.sendMessage(textUtils.basicText("An internal error has occured!", TextColors.RED)); diff --git a/src/me/Flibio/EconomyLite/Commands/PayCommand.java b/src/me/Flibio/EconomyLite/Commands/PayCommand.java index 15638ee..d238e82 100644 --- a/src/me/Flibio/EconomyLite/Commands/PayCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/PayCommand.java @@ -75,7 +75,7 @@ public void run() { //Get the UUID and check if it exists String targetUuid = playerManager.getUUID(who); //Check if the uuid is a registered player - if(economyService.getAccount(UUID.fromString(targetUuid)).isPresent()) { + if(economyService.getOrCreateAccount(UUID.fromString(targetUuid)).isPresent()) { //It is a player, is it also a business? if(businessManager.businessExists(who)) { //Present them with an option @@ -115,7 +115,7 @@ public void run() { } private void payBusiness(String uuid, int amount, Player player, String businessName) { - UniqueAccount account = economyService.getAccount(UUID.fromString(uuid)).get(); + UniqueAccount account = economyService.getOrCreateAccount(UUID.fromString(uuid)).get(); int balance = account.getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue(); //Check for an error if(balance>-1) { @@ -160,8 +160,8 @@ private void payBusiness(String uuid, int amount, Player player, String business } private void payPlayer(String uuid, int amount, Player player, String playerName, String targetUUID) { - UniqueAccount account = economyService.getAccount(UUID.fromString(uuid)).get(); - UniqueAccount targetAccount = economyService.getAccount(UUID.fromString(targetUUID)).get(); + UniqueAccount account = economyService.getOrCreateAccount(UUID.fromString(uuid)).get(); + UniqueAccount targetAccount = economyService.getOrCreateAccount(UUID.fromString(targetUUID)).get(); int balance = account.getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue(); //Check for an error if(balance>-1) { diff --git a/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java b/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java index 4b0d3b1..ca64fe0 100644 --- a/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java @@ -109,7 +109,7 @@ public void run() { } private void payBusiness(String uuid, int amount, Player player, String businessName) { - UniqueAccount account = economyService.getAccount(UUID.fromString(uuid)).get(); + UniqueAccount account = economyService.getOrCreateAccount(UUID.fromString(uuid)).get(); int balance = account.getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue(); //Check for an error if(balance>-1) { @@ -154,8 +154,8 @@ private void payBusiness(String uuid, int amount, Player player, String business } private void payPlayer(String uuid, int amount, Player player, String playerName, String targetUUID) { - UniqueAccount account = economyService.getAccount(UUID.fromString(uuid)).get(); - UniqueAccount targetAccount = economyService.getAccount(UUID.fromString(targetUUID)).get(); + UniqueAccount account = economyService.getOrCreateAccount(UUID.fromString(uuid)).get(); + UniqueAccount targetAccount = economyService.getOrCreateAccount(UUID.fromString(targetUUID)).get(); int balance = account.getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue(); //Check for an error if(balance>-1) { diff --git a/src/me/Flibio/EconomyLite/Commands/PlayerBalanceCommand.java b/src/me/Flibio/EconomyLite/Commands/PlayerBalanceCommand.java index 2ed95ee..f239402 100644 --- a/src/me/Flibio/EconomyLite/Commands/PlayerBalanceCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/PlayerBalanceCommand.java @@ -44,7 +44,7 @@ public void run() { //Player wants to view another player's balance String targetName = target.get(); String uuid = playerManager.getUUID(targetName); - Optional oAct = economyService.getAccount(UUID.fromString(uuid)); + Optional oAct = economyService.getOrCreateAccount(UUID.fromString(uuid)); if(oAct.isPresent()) { int balance = oAct.get().getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue(); if(balance<0) { diff --git a/src/me/Flibio/EconomyLite/Commands/RemoveCommand.java b/src/me/Flibio/EconomyLite/Commands/RemoveCommand.java index bf918dc..8ef2724 100644 --- a/src/me/Flibio/EconomyLite/Commands/RemoveCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/RemoveCommand.java @@ -48,7 +48,7 @@ public void run() { //Get the players UUID String uuid = playerManager.getUUID(playerName); if(!uuid.isEmpty()) { - Optional uOpt = economyService.getAccount(UUID.fromString(uuid)); + Optional uOpt = economyService.getOrCreateAccount(UUID.fromString(uuid)); if(!uOpt.isPresent()) { //Account is not present source.sendMessage(textUtils.basicText("An internal error has occured!", TextColors.RED)); diff --git a/src/me/Flibio/EconomyLite/Commands/SetCommand.java b/src/me/Flibio/EconomyLite/Commands/SetCommand.java index 94402ed..6a8081b 100644 --- a/src/me/Flibio/EconomyLite/Commands/SetCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/SetCommand.java @@ -47,7 +47,7 @@ public void run() { //Get the players UUID String uuid = playerManager.getUUID(playerName); if(!uuid.isEmpty()) { - Optional uOpt = economyService.getAccount(UUID.fromString(uuid)); + Optional uOpt = economyService.getOrCreateAccount(UUID.fromString(uuid)); if(!uOpt.isPresent()) { //Account is not present source.sendMessage(textUtils.basicText("An internal error has occured!", TextColors.RED)); diff --git a/src/me/Flibio/EconomyLite/EconomyLite.java b/src/me/Flibio/EconomyLite/EconomyLite.java index dc90fba..424e1d6 100644 --- a/src/me/Flibio/EconomyLite/EconomyLite.java +++ b/src/me/Flibio/EconomyLite/EconomyLite.java @@ -33,6 +33,7 @@ import org.spongepowered.api.command.spec.CommandSpec; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.game.state.GameInitializationEvent; +import org.spongepowered.api.plugin.Dependency; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.service.economy.Currency; import org.spongepowered.api.service.economy.EconomyService; @@ -44,8 +45,8 @@ import java.util.HashMap; import java.util.Optional; -@Updatifier(repoName = "EconomyLite", repoOwner = "Flibio", version = "v1.1.8") -@Plugin(id = "EconomyLite", name = "EconomyLite", version = "1.1.8", dependencies = "after: Updatifier") +@Updatifier(repoName = "EconomyLite", repoOwner = "Flibio", version = "v1.1.9") +@Plugin(id = "EconomyLite", name = "EconomyLite", version = "1.1.9", dependencies = @Dependency(id = "Updatifier", optional = true)) public class EconomyLite { @Inject diff --git a/src/me/Flibio/EconomyLite/Listeners/BalanceChangeListener.java b/src/me/Flibio/EconomyLite/Listeners/BalanceChangeListener.java index 689d343..4d72444 100644 --- a/src/me/Flibio/EconomyLite/Listeners/BalanceChangeListener.java +++ b/src/me/Flibio/EconomyLite/Listeners/BalanceChangeListener.java @@ -34,7 +34,7 @@ public void onPlayerBalanceChange(BalanceChangeEvent event) { Text balanceLabel = Text.builder("Balance: ").color(TextColors.GREEN).build(); HashMap objectiveValues = new HashMap(); - Optional uOpt = economyService.getAccount(uuid); + Optional uOpt = economyService.getOrCreateAccount(uuid); if(uOpt.isPresent()) { UniqueAccount account = uOpt.get(); objectiveValues.put(balanceLabel, account.getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue()); diff --git a/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java b/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java index dddc625..dcb9058 100644 --- a/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java +++ b/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java @@ -31,7 +31,7 @@ public class PlayerJoinListener { public void onPlayerJoin(ClientConnectionEvent.Join event) { Player player = (Player) event.getTargetEntity(); - economyService.createAccount(player.getUniqueId()); + economyService.getOrCreateAccount(player.getUniqueId()); //Show scoreboard if it is enabled if(EconomyLite.optionEnabled("scoreboard")) { @@ -39,7 +39,7 @@ public void onPlayerJoin(ClientConnectionEvent.Join event) { Text balanceLabel = Text.builder("Balance: ").color(TextColors.GREEN).build(); HashMap objectiveValues = new HashMap(); - Optional uOpt = economyService.getAccount(player.getUniqueId()); + Optional uOpt = economyService.getOrCreateAccount(player.getUniqueId()); if(uOpt.isPresent()) { UniqueAccount account = uOpt.get(); objectiveValues.put(balanceLabel, account.getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue());