Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Added ability to disable payment on join
Browse files Browse the repository at this point in the history
Resolved #2
  • Loading branch information
Flibio committed May 4, 2017
1 parent cdbc363 commit 7c1a961
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A configuration file (`payday.conf`) is located in the Sponge configuration dire

```
timeamount="1"
payonjoin="true"
timeunit=Hours
payamounts={
"players"= {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'eclipse'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0.0'
version = '1.1.0'

jar {
manifest {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/io/github/hsyyid/payday/PayDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
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
{

public static ConfigurationNode config;
public static ConfigurationLoader<CommentedConfigurationNode> configurationManager;
public static EconomyService economyService;
private static PayDay instance;
private Task task;
private boolean functional = false;

@Inject private Logger logger;

Expand Down Expand Up @@ -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<String, BigDecimal> entry : Utils.getPaymentAmounts().entrySet())
Expand Down Expand Up @@ -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<String, BigDecimal> entry : Utils.getPaymentAmounts().entrySet())
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/io/github/hsyyid/payday/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, BigDecimal> getPaymentAmounts()
{
Map<String, BigDecimal> payments = new HashMap<>();
Expand Down

0 comments on commit 7c1a961

Please sign in to comment.