From 7c1a961aebb64bd138081b4438ec5d1d76afe0aa Mon Sep 17 00:00:00 2001 From: Flibio Date: Thu, 4 May 2017 16:31:54 -0600 Subject: [PATCH] Added ability to disable payment on join Resolved #2 --- README.md | 1 + build.gradle | 2 +- .../java/io/github/hsyyid/payday/PayDay.java | 11 ++++++++-- .../io/github/hsyyid/payday/utils/Utils.java | 21 +++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4be8cfe..e364b52 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ A configuration file (`payday.conf`) is located in the Sponge configuration dire ``` timeamount="1" +payonjoin="true" timeunit=Hours payamounts={ "players"= { diff --git a/build.gradle b/build.gradle index 6901406..6fcedda 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'eclipse' sourceCompatibility = 1.8 targetCompatibility = 1.8 -version = '1.0.0' +version = '1.1.0' jar { manifest { diff --git a/src/main/java/io/github/hsyyid/payday/PayDay.java b/src/main/java/io/github/hsyyid/payday/PayDay.java index 96ae32e..cf962eb 100644 --- a/src/main/java/io/github/hsyyid/payday/PayDay.java +++ b/src/main/java/io/github/hsyyid/payday/PayDay.java @@ -28,7 +28,7 @@ import java.util.Map.Entry; import java.util.Optional; -@Plugin(id = "payday", name = "PayDay", version = "1.0.0", description = "Pay your players as they play.") +@Plugin(id = "payday", name = "PayDay", version = "1.1.0", description = "Pay your players as they play.") public class PayDay { @@ -36,6 +36,8 @@ public class PayDay public static ConfigurationLoader configurationManager; public static EconomyService economyService; private static PayDay instance; + private Task task; + private boolean functional = false; @Inject private Logger logger; @@ -72,7 +74,7 @@ public void onGameInit(GameInitializationEvent event) Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder(); - taskBuilder.execute(task -> + task = taskBuilder.execute(task -> { for (Player player : Sponge.getServer().getOnlinePlayers()) { for (Entry entry : Utils.getPaymentAmounts().entrySet()) @@ -112,16 +114,21 @@ public void onGamePostInit(GamePostInitializationEvent event) if (econService.isPresent()) { economyService = econService.get(); + functional = true; } else { getLogger().error("Error! There is no Economy plugin found on this server, PayDay will not work correctly!"); + task.cancel(); + functional = false; } } @Listener public void onPlayerJoin(ClientConnectionEvent.Join event) { + if (!Utils.getJoinPay() || !functional) + return; Player player = event.getTargetEntity(); for (Entry entry : Utils.getPaymentAmounts().entrySet()) diff --git a/src/main/java/io/github/hsyyid/payday/utils/Utils.java b/src/main/java/io/github/hsyyid/payday/utils/Utils.java index d373652..f425ae4 100644 --- a/src/main/java/io/github/hsyyid/payday/utils/Utils.java +++ b/src/main/java/io/github/hsyyid/payday/utils/Utils.java @@ -77,6 +77,27 @@ public static int getTimeAmount() } } + public static boolean getJoinPay() + { + ConfigurationNode valueNode = PayDay.config.getNode((Object[]) ("payonjoin").split("\\.")); + + try { + String value = valueNode.getString(); + if(value == null) + { + Utils.setConfig("payonjoin", Boolean.toString(true)); + return true; + } + else { + return Boolean.getBoolean(value); + } + } catch (RuntimeException e) + { + Utils.setConfig("payonjoin", Boolean.toString(true)); + return true; + } + } + public static Map getPaymentAmounts() { Map payments = new HashMap<>();