diff --git a/pom.xml b/pom.xml index 018b741..c5a6ff0 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 EconomyLite EconomyLite - 1.1.4 + 1.1.5 jar EconomyLite An economy plugin for Sponge @@ -19,6 +19,19 @@ 1.8 + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + + package + + shade + + + + @@ -33,6 +46,14 @@ true + + minecrell + http://repo.minecrell.net/releases + + + jitpack.io + https://jitpack.io + @@ -42,5 +63,16 @@ 3.1.0-SNAPSHOT provided + + com.github.Flibio + Updatifier + RELEASE + + + net.minecrell.mcstats + statslite-sponge + 0.2.1 + compile + \ No newline at end of file diff --git a/src/me/Flibio/EconomyLite/Commands/PayCommand.java b/src/me/Flibio/EconomyLite/Commands/PayCommand.java index a383303..15638ee 100644 --- a/src/me/Flibio/EconomyLite/Commands/PayCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/PayCommand.java @@ -5,6 +5,7 @@ import me.Flibio.EconomyLite.Utils.PlayerManager; import me.Flibio.EconomyLite.Utils.TextUtils; +import org.spongepowered.api.Sponge; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; @@ -135,7 +136,14 @@ private void payBusiness(String uuid, int amount, Player player, String business if(account.withdraw(currency,BigDecimal.valueOf(amount),Cause.of("EconomyLite")).getResult().equals(ResultType.SUCCESS)&& businessManager.setBusinessBalance(businessName, newBalance)) { //Success - player.sendMessage(textUtils.paySuccess(businessName, amount)); + player.sendMessage(textUtils.paySuccess(businessName, amount)); + for(String owner : businessManager.getBusinessOwners(businessName)) { + Sponge.getServer().getOnlinePlayers().forEach(p -> { + if(p.getName().equalsIgnoreCase(owner)) { + p.sendMessage(textUtils.bPayed(player.getName(), amount, businessName)); + } + }); + } return; } else { //Error @@ -175,6 +183,11 @@ private void payPlayer(String uuid, int amount, Player player, String playerName targetAccount.setBalance(currency,BigDecimal.valueOf(newBalance),Cause.of("EconomyLite")).getResult().equals(ResultType.SUCCESS)) { //Success player.sendMessage(textUtils.paySuccess(playerName, amount)); + for(Player oPlayer : Sponge.getServer().getOnlinePlayers()) { + if(oPlayer.getUniqueId().toString().equals(targetUUID)) { + oPlayer.sendMessage(textUtils.payed(player.getName(),amount)); + } + } return; } else { //Error diff --git a/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java b/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java index a3b5444..4b0d3b1 100644 --- a/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java +++ b/src/me/Flibio/EconomyLite/Commands/PayOverrideCommand.java @@ -5,6 +5,7 @@ import me.Flibio.EconomyLite.Utils.PlayerManager; import me.Flibio.EconomyLite.Utils.TextUtils; +import org.spongepowered.api.Sponge; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; @@ -130,6 +131,13 @@ private void payBusiness(String uuid, int amount, Player player, String business businessManager.setBusinessBalance(businessName, newBalance)) { //Success player.sendMessage(textUtils.paySuccess(businessName, amount)); + for(String owner : businessManager.getBusinessOwners(businessName)) { + Sponge.getServer().getOnlinePlayers().forEach(p -> { + if(p.getName().equalsIgnoreCase(owner)) { + p.sendMessage(textUtils.bPayed(player.getName(), amount, businessName)); + } + }); + } return; } else { //Error @@ -169,6 +177,11 @@ private void payPlayer(String uuid, int amount, Player player, String playerName targetAccount.setBalance(currency,BigDecimal.valueOf(newBalance),Cause.of("EconomyLite")).getResult().equals(ResultType.SUCCESS)) { //Success player.sendMessage(textUtils.paySuccess(playerName, amount)); + for(Player oPlayer : Sponge.getServer().getOnlinePlayers()) { + if(oPlayer.getUniqueId().toString().equals(targetUUID)) { + oPlayer.sendMessage(textUtils.payed(player.getName(),amount)); + } + } return; } else { //Error diff --git a/src/me/Flibio/EconomyLite/Commands/PlayerBalanceCommand.java b/src/me/Flibio/EconomyLite/Commands/PlayerBalanceCommand.java new file mode 100644 index 0000000..2ed95ee --- /dev/null +++ b/src/me/Flibio/EconomyLite/Commands/PlayerBalanceCommand.java @@ -0,0 +1,70 @@ +package me.Flibio.EconomyLite.Commands; + +import me.Flibio.EconomyLite.EconomyLite; +import me.Flibio.EconomyLite.Utils.PlayerManager; +import me.Flibio.EconomyLite.Utils.TextUtils; + +import org.spongepowered.api.command.CommandException; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.command.args.CommandContext; +import org.spongepowered.api.command.spec.CommandExecutor; +import org.spongepowered.api.scheduler.Task.Builder; +import org.spongepowered.api.service.economy.Currency; +import org.spongepowered.api.service.economy.EconomyService; +import org.spongepowered.api.service.economy.account.UniqueAccount; +import org.spongepowered.api.text.format.TextColors; + +import java.math.RoundingMode; +import java.util.Optional; +import java.util.UUID; + +public class PlayerBalanceCommand implements CommandExecutor { + + private TextUtils textUtils = new TextUtils(); + private EconomyService economyService = EconomyLite.getService(); + private Currency currency = EconomyLite.getService().getDefaultCurrency(); + private PlayerManager playerManager = new PlayerManager(); + private Builder taskBuilder = EconomyLite.access.game.getScheduler().createTaskBuilder(); + + @Override + public CommandResult execute(CommandSource source, CommandContext args) + throws CommandException { + //Run in a seperate thread + taskBuilder.execute(new Runnable() { + public void run() { + + Optional target = args.getOne("player"); + if(target.isPresent()) { + //Check if player has permission + if(!source.hasPermission("econ.playerbalance")) { + source.sendMessage(textUtils.basicText("You do not have permission to use this command!", TextColors.RED)); + return; + } + //Player wants to view another player's balance + String targetName = target.get(); + String uuid = playerManager.getUUID(targetName); + Optional oAct = economyService.getAccount(UUID.fromString(uuid)); + if(oAct.isPresent()) { + int balance = oAct.get().getBalance(currency).setScale(0, RoundingMode.HALF_UP).intValue(); + if(balance<0) { + source.sendMessage(textUtils.basicText("An internal error has occurred!", TextColors.RED)); + return; + } else { + source.sendMessage(textUtils.playerBalanceText(balance, targetName)); + return; + } + } else { + source.sendMessage(textUtils.basicText("An internal error has occurred!", TextColors.RED)); + return; + } + } else { + source.sendMessage(textUtils.basicText("You need to specify a player to get the balance of!", TextColors.RED)); + return; + } + } + }).submit(EconomyLite.access); + return CommandResult.success(); + } + +} diff --git a/src/me/Flibio/EconomyLite/EconomyLite.java b/src/me/Flibio/EconomyLite/EconomyLite.java index 74bd062..620fbaa 100644 --- a/src/me/Flibio/EconomyLite/EconomyLite.java +++ b/src/me/Flibio/EconomyLite/EconomyLite.java @@ -14,6 +14,7 @@ import me.Flibio.EconomyLite.Commands.BusinessTransferCommand; import me.Flibio.EconomyLite.Commands.PayCommand; import me.Flibio.EconomyLite.Commands.PayOverrideCommand; +import me.Flibio.EconomyLite.Commands.PlayerBalanceCommand; import me.Flibio.EconomyLite.Commands.RemoveCommand; import me.Flibio.EconomyLite.Commands.SetCommand; import me.Flibio.EconomyLite.Listeners.BalanceChangeListener; @@ -21,10 +22,9 @@ import me.Flibio.EconomyLite.Utils.BusinessManager; import me.Flibio.EconomyLite.Utils.FileManager; import me.Flibio.EconomyLite.Utils.FileManager.FileType; -import me.Flibio.EconomyLite.Utils.HttpUtils; -import me.Flibio.EconomyLite.Utils.JsonUtils; import me.Flibio.EconomyLite.Utils.MySQLManager; -import me.Flibio.EconomyLite.Utils.TextUtils; +import me.flibio.updatifier.Updatifier; +import net.minecrell.mcstats.SpongeStatsLite; import ninja.leaping.configurate.ConfigurationNode; import org.slf4j.Logger; @@ -33,7 +33,6 @@ 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.event.game.state.GameStartedServerEvent; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.service.economy.Currency; import org.spongepowered.api.service.economy.EconomyService; @@ -45,7 +44,8 @@ import java.util.HashMap; import java.util.Optional; -@Plugin(id = "EconomyLite", name = "EconomyLite", version = "1.1.4") +@Updatifier(repoName = "EconomyLite", repoOwner = "Flibio", version = "v1.1.5") +@Plugin(id = "EconomyLite", name = "EconomyLite", version = "1.1.5") public class EconomyLite { @Inject @@ -54,6 +54,8 @@ public class EconomyLite { @Inject public Game game; + @Inject + private SpongeStatsLite statsLite; private FileManager fileManager; private BusinessManager businessManager; private static EconomyService economyService; @@ -75,6 +77,7 @@ public class EconomyLite { @Listener public void onServerInitialize(GameInitializationEvent event) { logger.info("EconomyLite v"+version+" by Flibio initializing!"); + this.statsLite.start(); //Set the access access = this; @@ -102,13 +105,6 @@ public void onServerInitialize(GameInitializationEvent event) { economyService = new LiteEconomyService(); game.getServiceManager().setProvider(this, EconomyService.class, economyService); logger.info("API registered successfully!"); - //Start Metrics - if(optionEnabled("statistics")) { - logger.info("Started EconomyLite Statistics!"); - game.getEventManager().registerListeners(this, new Statistics()); - } else { - logger.info("EconomyLite Statistics are disabled!"); - } //Reset business confirmations game.getScheduler().createTaskBuilder().execute(new Runnable() { public void run() { @@ -121,42 +117,6 @@ public void run() { }).async().submit(this); } - @Listener - public void onServerStarted(GameStartedServerEvent event) { - if(optionEnabled("updates")) { - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - HttpUtils httpUtils = new HttpUtils(); - JsonUtils jsonUtils = new JsonUtils(); - TextUtils textUtils = new TextUtils(); - //Check for an update - String latest = httpUtils.requestData("https://api.github.com/repos/Flibio/EconomyLite/releases/latest"); - String version = jsonUtils.getVersion(latest).replace("v", ""); - String changes = httpUtils.requestData("https://flibio.github.io/EconomyLite/changelogs/"+version.replaceAll("\\.", "-")+".txt"); - String[] iChanges = changes.split(";"); - String url = jsonUtils.getUrl(latest); - boolean prerelease = jsonUtils.isPreRelease(latest); - //Make sure the latest update is not a prerelease - if(!prerelease) { - //Check if the latest update is newer than the current one - String currentVersion = EconomyLite.access.version; - if(textUtils.versionCompare(version, currentVersion)>0) { - logger.info("EconomyLite v"+version+" is now available to download!"); - logger.info(url); - for(String change : iChanges) { - if(!change.trim().isEmpty()) { - logger.info("+ "+change); - } - } - } - } - } - }); - thread.start(); - } - } - private void registerEvents() { game.getEventManager().registerListeners(this, new PlayerJoinListener()); game.getEventManager().registerListeners(this, new BalanceChangeListener()); @@ -169,6 +129,12 @@ private void registerCommands() { .executor(new BalanceCommand()) .build(); game.getCommandManager().register(this, balanceCommand, "balance", "bal"); + CommandSpec pBalanceCommand = CommandSpec.builder() + .description(Text.of("View EconomyLite balance of another player")) + .arguments(GenericArguments.string(Text.of("player"))) + .executor(new PlayerBalanceCommand()) + .build(); + game.getCommandManager().register(this, pBalanceCommand, "playerbalance", "pbal"); //Add Child Command CommandSpec addCommand = CommandSpec.builder() .description(Text.of("Add currency to a player's balance")) @@ -292,7 +258,6 @@ private void initializeFiles() { fileManager.testDefault("Scoreboard", "disabled"); fileManager.testDefault("Businesses", "enabled"); fileManager.testDefault("Plugin-Statistics", "enabled"); - fileManager.testDefault("Update-Notifications", "enabled"); fileManager.testDefault("MySQL.Enabled", "disabled"); fileManager.testDefault("MySQL.Hostname", "hostname"); fileManager.testDefault("MySQL.Port", 3306); @@ -311,7 +276,6 @@ private void loadConfigurationOptions() { configOptions.put("scoreboard", fileManager.getConfigValue("Scoreboard")); configOptions.put("businesses", fileManager.getConfigValue("Businesses")); configOptions.put("statistics", fileManager.getConfigValue("Plugin-Statistics")); - configOptions.put("updates", fileManager.getConfigValue("Update-Notifications")); configOptions.put("mysql.enabled", fileManager.getConfigValue("MySQL.Enabled")); configOptions.put("mysql.hostname", fileManager.getConfigValue("MySQL.Hostname")); configOptions.put("mysql.port", fileManager.getConfigValue("MySQL.Port")); diff --git a/src/me/Flibio/EconomyLite/Gson/PlayerPojo.java b/src/me/Flibio/EconomyLite/Gson/PlayerPojo.java deleted file mode 100644 index c9a4286..0000000 --- a/src/me/Flibio/EconomyLite/Gson/PlayerPojo.java +++ /dev/null @@ -1,17 +0,0 @@ -package me.Flibio.EconomyLite.Gson; - -public class PlayerPojo { - - private String id; - private String name; - - - public String getID() { - return id; - } - - public String getName() { - return name; - } - -} diff --git a/src/me/Flibio/EconomyLite/Gson/ReleasePojo.java b/src/me/Flibio/EconomyLite/Gson/ReleasePojo.java deleted file mode 100644 index 980bada..0000000 --- a/src/me/Flibio/EconomyLite/Gson/ReleasePojo.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.Flibio.EconomyLite.Gson; - -public class ReleasePojo { - - private String tag_name; - private boolean prerelease; - private String html_url; - - public String getName() { - return tag_name; - } - - public String getUrl() { - return html_url; - } - - public boolean isPreRelease() { - return prerelease; - } - -} diff --git a/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java b/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java index 8089ebf..5ba0eaf 100644 --- a/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java +++ b/src/me/Flibio/EconomyLite/Listeners/PlayerJoinListener.java @@ -1,7 +1,6 @@ package me.Flibio.EconomyLite.Listeners; import me.Flibio.EconomyLite.EconomyLite; -import me.Flibio.EconomyLite.Runnables.UpdateRunnable; import me.Flibio.EconomyLite.Utils.BusinessManager; import me.Flibio.EconomyLite.Utils.FileManager; import me.Flibio.EconomyLite.Utils.FileManager.FileType; @@ -67,9 +66,7 @@ public void onPlayerJoin(ClientConnectionEvent.Join event) { player.setScoreboard(scoreboardUtils.createScoreboard("EconomyLite", displayName, objectiveValues)); } } - - //Check if an update is available - taskBuilder.execute(new UpdateRunnable(player)).async().submit(EconomyLite.access); + //Check if the player has any invites taskBuilder.execute(new Runnable() { public void run() { diff --git a/src/me/Flibio/EconomyLite/Runnables/UpdateRunnable.java b/src/me/Flibio/EconomyLite/Runnables/UpdateRunnable.java deleted file mode 100644 index a36331c..0000000 --- a/src/me/Flibio/EconomyLite/Runnables/UpdateRunnable.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.Flibio.EconomyLite.Runnables; - -import me.Flibio.EconomyLite.EconomyLite; -import me.Flibio.EconomyLite.Utils.HttpUtils; -import me.Flibio.EconomyLite.Utils.JsonUtils; -import me.Flibio.EconomyLite.Utils.TextUtils; - -import org.spongepowered.api.entity.living.player.Player; - -public class UpdateRunnable implements Runnable{ - - private HttpUtils httpUtils = new HttpUtils(); - private JsonUtils jsonUtils = new JsonUtils(); - private TextUtils textUtils = new TextUtils(); - private Player player; - - public UpdateRunnable(Player player) { - this.player = player; - } - - public void run() { - //Check if the player has permission - if(player.hasPermission("econ.admin.updates")&&EconomyLite.optionEnabled("updates")) { - //Get the data - String latest = httpUtils.requestData("https://api.github.com/repos/Flibio/EconomyLite/releases/latest"); - String version = jsonUtils.getVersion(latest).replace("v", ""); - String changes = httpUtils.requestData("https://flibio.github.io/EconomyLite/changelogs/"+version.replaceAll("\\.", "-")+".txt"); - String[] iChanges = changes.split(";"); - String url = jsonUtils.getUrl(latest); - boolean prerelease = jsonUtils.isPreRelease(latest); - //Make sure the latest update is not a prerelease - if(!prerelease) { - //Check if the latest update is newer than the current one - String currentVersion = EconomyLite.access.version; - if(textUtils.versionCompare(version, currentVersion)>0) { - player.sendMessage(textUtils.updateAvailable(version, url)); - for(String change : iChanges) { - if(!change.trim().isEmpty()) { - player.sendMessage(textUtils.change(change)); - } - } - } - } - } - } - -} diff --git a/src/me/Flibio/EconomyLite/Statistics.java b/src/me/Flibio/EconomyLite/Statistics.java deleted file mode 100644 index f4ff9d5..0000000 --- a/src/me/Flibio/EconomyLite/Statistics.java +++ /dev/null @@ -1,93 +0,0 @@ -package me.Flibio.EconomyLite; - -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.game.state.GameStoppingServerEvent; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.InetSocketAddress; -import java.net.URL; -import java.net.URLConnection; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -public class Statistics { - - private final String USER_AGENT = "EconomyLite/2.0"; - private String ip; - private boolean working = false; - - private String accessKey = ""; - - public Statistics() { - Optional addrOptional = EconomyLite.access.game.getServer().getBoundAddress(); - EconomyLite.access.game.getScheduler().createTaskBuilder().execute(r -> { - String ipAddrResponse = ""; - try { - ipAddrResponse = post("http://checkip.amazonaws.com",""); - } catch(Exception e) { - EconomyLite.access.logger.error(e.getMessage()); - } - if(addrOptional.isPresent()&&!ipAddrResponse.isEmpty()) { - InetSocketAddress addr = addrOptional.get(); - this.ip = ipAddrResponse+":"+addr.getPort(); - //Register the server as started - this.working = true; - try { - String response = post("http://api.flibio.net/serverStarted.php","ip="+ip); - if(!response.contains("error")&&response.length()>10) { - accessKey = response; - EconomyLite.access.game.getScheduler().createTaskBuilder().execute(t -> { - try { - System.out.println(post("http://api.flibio.net/pinger.php","key="+accessKey+"&ip="+this.ip+"&pl="+ - EconomyLite.access.game.getServer().getOnlinePlayers().size())); - } catch(Exception e) { - EconomyLite.access.logger.error(e.getMessage()); - } - }).async().interval(15, TimeUnit.MINUTES).delay(15, TimeUnit.MINUTES).submit(EconomyLite.access); - } - } catch(Exception e) { - EconomyLite.access.logger.error(e.getMessage()); - } - } else { - this.ip = ""; - } - }).async().submit(EconomyLite.access); - } - - @Listener - public void onServerStop(GameStoppingServerEvent event) { - if(!working) return; - try { - post("http://api.flibio.net/stopped.php","key="+accessKey+"&ip="+this.ip); - } catch (Exception e) { - EconomyLite.access.logger.error(e.getMessage()); - } - } - - private String post(String urlString, String urlParameters) throws Exception { - // Send data - URL url = new URL(urlString); - URLConnection conn = url.openConnection(); - conn.setConnectTimeout(5000); - conn.setRequestProperty("User-Agent", USER_AGENT); - conn.setDoOutput(true); - OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); - wr.write(urlParameters); - wr.flush(); - - // Get the response - BufferedReader rd = new BufferedReader( - new InputStreamReader(conn.getInputStream())); - - String line; - while ((line = rd.readLine()) != null) { - return line; - } - wr.close(); - rd.close(); - return ""; - } - -} diff --git a/src/me/Flibio/EconomyLite/Utils/HttpUtils.java b/src/me/Flibio/EconomyLite/Utils/HttpUtils.java deleted file mode 100644 index 47ec4cd..0000000 --- a/src/me/Flibio/EconomyLite/Utils/HttpUtils.java +++ /dev/null @@ -1,68 +0,0 @@ -package me.Flibio.EconomyLite.Utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.ProtocolException; -import java.net.URL; - -public class HttpUtils { - - private final String USER_AGENT = "Mozilla/5.0"; - - public HttpUtils() { - - } - - public String requestData(String url) { - URL obj; - try { - obj = new URL(url); - } catch (MalformedURLException e) { - return ""; - } - HttpURLConnection con; - try { - con = (HttpURLConnection) obj.openConnection(); - } catch (IOException e) { - return ""; - } - - // optional default is GET - try { - con.setRequestMethod("GET"); - } catch (ProtocolException e) { - return ""; - } - - //add request header - con.setRequestProperty("User-Agent", USER_AGENT); - - BufferedReader in; - try { - in = new BufferedReader(new InputStreamReader(con.getInputStream())); - } catch (IOException e) { - return ""; - } - String inputLine; - StringBuffer response = new StringBuffer(); - - try { - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - } catch (IOException e) { - return ""; - } - try { - in.close(); - } catch (IOException e) { - return ""; - } - con.disconnect(); - //return result - return response.toString(); - } -} diff --git a/src/me/Flibio/EconomyLite/Utils/JsonGitHubData.java b/src/me/Flibio/EconomyLite/Utils/JsonGitHubData.java deleted file mode 100644 index e5518ed..0000000 --- a/src/me/Flibio/EconomyLite/Utils/JsonGitHubData.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.Flibio.EconomyLite.Utils; - -public class JsonGitHubData { - - private String tag_name; - private boolean prerelease; - private String html_url; - - public String getName() { - return tag_name; - } - - public String getUrl() { - return html_url; - } - - public boolean isPreRelease() { - return prerelease; - } - -} diff --git a/src/me/Flibio/EconomyLite/Utils/JsonPlayerData.java b/src/me/Flibio/EconomyLite/Utils/JsonPlayerData.java deleted file mode 100644 index b667349..0000000 --- a/src/me/Flibio/EconomyLite/Utils/JsonPlayerData.java +++ /dev/null @@ -1,17 +0,0 @@ -package me.Flibio.EconomyLite.Utils; - -public class JsonPlayerData { - - private String id; - private String name; - - - public String getID() { - return id; - } - - public String getName() { - return name; - } - -} diff --git a/src/me/Flibio/EconomyLite/Utils/JsonUtils.java b/src/me/Flibio/EconomyLite/Utils/JsonUtils.java deleted file mode 100644 index 6a641cc..0000000 --- a/src/me/Flibio/EconomyLite/Utils/JsonUtils.java +++ /dev/null @@ -1,62 +0,0 @@ -package me.Flibio.EconomyLite.Utils; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -public class JsonUtils { - - public JsonUtils() { - - } - - public String parseToUUID(String json) { - Gson gson = new GsonBuilder().create(); - JsonPlayerData data = gson.fromJson(json, JsonPlayerData.class); - if(data==null) return ""; - if(data.getID()==null) return ""; - String uuid = data.getID(); - return insertDashUUID(uuid); - } - - public String getVersion(String json) { - Gson gson = new GsonBuilder().create(); - JsonGitHubData data = gson.fromJson(json, JsonGitHubData.class); - if(data==null) return ""; - if(data.getName()==null) return ""; - String version = data.getName(); - return version; - } - - public String getUrl(String json) { - Gson gson = new GsonBuilder().create(); - JsonGitHubData data = gson.fromJson(json, JsonGitHubData.class); - if(data==null) return ""; - if(data.getUrl()==null) return ""; - String url = data.getUrl(); - return url; - } - - public boolean isPreRelease(String json) { - Gson gson = new GsonBuilder().create(); - JsonGitHubData data = gson.fromJson(json, JsonGitHubData.class); - if(data==null) return true; - boolean isPre = data.isPreRelease(); - return isPre; - } - - private String insertDashUUID(String uuid) { - StringBuffer sb = new StringBuffer(uuid); - sb.insert(8, "-"); - - sb = new StringBuffer(sb.toString()); - sb.insert(13, "-"); - - sb = new StringBuffer(sb.toString()); - sb.insert(18, "-"); - - sb = new StringBuffer(sb.toString()); - sb.insert(23, "-"); - - return sb.toString(); - } -} diff --git a/src/me/Flibio/EconomyLite/Utils/TextUtils.java b/src/me/Flibio/EconomyLite/Utils/TextUtils.java index c32a2e8..3da902a 100644 --- a/src/me/Flibio/EconomyLite/Utils/TextUtils.java +++ b/src/me/Flibio/EconomyLite/Utils/TextUtils.java @@ -36,6 +36,18 @@ public Text playerBalanceText(int balance) { return balanceText; } + public Text playerBalanceText(int balance, String who) { + Text balanceText = Text.builder("EconomyLite » ").color(TextColors.GOLD).build(); + String label = EconomyLite.access.currencyPlural; + if(balance==1) label = EconomyLite.access.currencySingular; + + balanceText = balanceText.toBuilder().append(basicText(who+"'s balance: ",TextColors.YELLOW)).build(); + balanceText = balanceText.toBuilder().append(basicText(balance+" ",TextColors.GREEN)).build(); + balanceText = balanceText.toBuilder().append(basicText(label+"!",TextColors.DARK_GREEN)).build(); + + return balanceText; + } + public Text businessBalanceText(String businessName, int balance) { Text balanceText = Text.builder("EconomyLite » ").color(TextColors.GOLD).build(); String label = EconomyLite.access.currencyPlural; @@ -155,6 +167,34 @@ public Text paySuccess(String who, int amount) { return text; } + public Text payed(String from, int amount) { + Text text = Text.builder("EconomyLite » ").color(TextColors.GOLD).build(); + String label = EconomyLite.access.currencyPlural; + if(amount==1) label = EconomyLite.access.currencySingular; + + text = text.toBuilder().append(basicText("You have received ",TextColors.YELLOW)).build(); + text = text.toBuilder().append(basicText(amount+" ",TextColors.GREEN)).build(); + text = text.toBuilder().append(basicText(label,TextColors.DARK_GREEN)).build(); + text = text.toBuilder().append(basicText(" from ",TextColors.YELLOW)).build(); + text = text.toBuilder().append(basicText(from+"!",TextColors.GREEN)).build(); + + return text; + } + + public Text bPayed(String from, int amount, String business) { + Text text = Text.builder("EconomyLite » ").color(TextColors.GOLD).build(); + String label = EconomyLite.access.currencyPlural; + if(amount==1) label = EconomyLite.access.currencySingular; + + text = text.toBuilder().append(basicText(business+" has received ",TextColors.YELLOW)).build(); + text = text.toBuilder().append(basicText(amount+" ",TextColors.GREEN)).build(); + text = text.toBuilder().append(basicText(label,TextColors.DARK_GREEN)).build(); + text = text.toBuilder().append(basicText(" from ",TextColors.YELLOW)).build(); + text = text.toBuilder().append(basicText(from+"!",TextColors.GREEN)).build(); + + return text; + } + public Text leaveSuccess(String business) { Text text = Text.builder("EconomyLite » ").color(TextColors.GOLD).build();