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

Commit

Permalink
Reformat code and various other updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Flibio committed Apr 14, 2017
1 parent 552c3c4 commit cdbc363
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 124 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
PayDay is a Sponge plugin that pays players at set intervals.

## Usage

A configuration file (`payday.conf`) is located in the Sponge configuration directory, and allows you to modify how the plugin functions.

```
timeamount="1"
timeunit=Hours
payamounts={
"players"= {
"permission"= "*",
"amount"= 50.0
}
}
```

Valid time units are:

- `Nanoseconds`
- `Microseconds`
- `Milliseconds`
- `Seconds`
- `Minutes`
- `Hours`
- `Days`

Pay amounts are assigned using the following format:

```
payamounts={
"my group"= {
"permission"= "*",
"amount"= 50.0
},
"my group 2"= {
"permission"= "requires.this.permission",
"amount"= 19.99
}
}
```

If the permission is set to `*`, it will pay all players.

---

## Credit

PayDay was originally created by HassanS6000 of [NEGAFINITY](http://negafinity.com).
4 changes: 0 additions & 4 deletions README.txt

This file was deleted.

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 = '0.6'
version = '1.0.0'

jar {
manifest {
Expand Down
222 changes: 121 additions & 101 deletions src/main/java/io/github/hsyyid/payday/PayDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,116 +19,136 @@
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.UniqueAccount;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map.Entry;
import java.util.Optional;

@Plugin(id = "payday", name = "PayDay", version = "0.6", description = "Pay your players as they play.")
@Plugin(id = "payday", name = "PayDay", version = "1.0.0", description = "Pay your players as they play.")
public class PayDay
{
public static ConfigurationNode config;
public static ConfigurationLoader<CommentedConfigurationNode> configurationManager;
public static EconomyService economyService;

@Inject
private Logger logger;

public Logger getLogger()
{
return logger;
}

@Inject
@DefaultConfig(sharedRoot = true)
private File dConfig;

@Inject
@DefaultConfig(sharedRoot = true)
private ConfigurationLoader<CommentedConfigurationNode> confManager;

@Listener
public void onGameInit(GameInitializationEvent event)
{
getLogger().info("PayDay loading...");

try
{
if (!dConfig.exists())
{
dConfig.createNewFile();
config = confManager.load();
confManager.save(config);
}

configurationManager = confManager;
config = confManager.load();
}
catch (IOException exception)
{
getLogger().error("The default configuration could not be loaded or created!");
}

Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();

taskBuilder.execute(task ->
{
for (Player player : Sponge.getServer().getOnlinePlayers()) {
Subject subject = player.getContainingCollection().get(player.getIdentifier());

if (subject.getOption("pay").isPresent()) {
BigDecimal pay = new BigDecimal(Double.parseDouble(subject.getOption("pay").get()));
player.sendMessage(Text.of(TextColors.GOLD, "[PayDay]: ", TextColors.GRAY, "It's PayDay! Here is your salary of " + pay + " dollars! Enjoy!"));
UniqueAccount uniqueAccount = economyService.getOrCreateAccount(player.getUniqueId()).get();
uniqueAccount.deposit(economyService.getDefaultCurrency(), pay, Cause.of(NamedCause.owner(this)));
}
}
}).interval(Utils.getTimeAmount(), Utils.getTimeUnit()).name("PayDay - Pay").submit(this);

getLogger().info("-----------------------------");
getLogger().info("PayDay was made by HassanS6000!");

public static ConfigurationNode config;
public static ConfigurationLoader<CommentedConfigurationNode> configurationManager;
public static EconomyService economyService;
private static PayDay instance;

@Inject private Logger logger;

public Logger getLogger()
{
return logger;
}

@Inject @DefaultConfig(sharedRoot = true) private File dConfig;

@Inject @DefaultConfig(sharedRoot = true) private ConfigurationLoader<CommentedConfigurationNode> confManager;

@Listener
public void onGameInit(GameInitializationEvent event)
{
instance = this;
getLogger().info("PayDay loading...");

try
{
if (!dConfig.exists())
{
dConfig.createNewFile();
config = confManager.load();
confManager.save(config);
}

configurationManager = confManager;
config = confManager.load();
} catch (IOException exception)
{
getLogger().error("The default configuration could not be loaded or created!");
}

Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();

taskBuilder.execute(task ->
{
for (Player player : Sponge.getServer().getOnlinePlayers()) {
for (Entry<String, BigDecimal> entry : Utils.getPaymentAmounts().entrySet())
{
if (entry.getKey().equals("*") || player.hasPermission(entry.getKey()))
{
BigDecimal pay = entry.getValue();
String name = economyService.getDefaultCurrency().getDisplayName().toPlain();
if (pay.compareTo(BigDecimal.ONE) != 0)
{
name = economyService.getDefaultCurrency().getPluralDisplayName().toPlain();
}
player.sendMessage(Text.of(TextColors.GOLD, "[PayDay]: ", TextColors.GRAY, "It's PayDay! Here is your salary of "
+ pay + " " + name + "! Enjoy!"));
UniqueAccount uniqueAccount = economyService.getOrCreateAccount(player.getUniqueId()).get();
uniqueAccount.deposit(economyService.getDefaultCurrency(), pay, Cause.of(NamedCause.owner(this)));
}
}
}
}).interval(Utils.getTimeAmount(), Utils.getTimeUnit()).name("PayDay - Pay").submit(this);

getLogger().info("-----------------------------");
getLogger().info("PayDay was made by HassanS6000!");
getLogger().info("Patched to APIv5 by Kostronor from the Minecolonies team!");
getLogger().info("Please post all errors on the Sponge Thread or on GitHub!");
getLogger().info("Have fun, and enjoy! :D");
getLogger().info("-----------------------------");
getLogger().info("PayDay loaded!");
}

@Listener
public void onGamePostInit(GamePostInitializationEvent event)
{
Optional<EconomyService> econService = Sponge.getServiceManager().provide(EconomyService.class);

if (econService.isPresent())
{
economyService = econService.get();
}
else
{
getLogger().error("Error! There is no Economy plugin found on this server, PayDay will not work correctly!");
}
}

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event)
{
Player player = event.getTargetEntity();

Subject subject = player.getContainingCollection().get(player.getIdentifier());
if (subject.getOption("startingbalance").isPresent()) {
BigDecimal pay = new BigDecimal(Double.parseDouble(subject.getOption("startingbalance").get()));
player.sendMessage(Text.of(TextColors.GOLD, "[PayDay]: ", TextColors.GRAY, "Welcome to the server! Here is " + pay + " dollars! Enjoy!"));
UniqueAccount uniqueAccount = economyService.getOrCreateAccount(player.getUniqueId()).get();
uniqueAccount.deposit(economyService.getDefaultCurrency(), pay, Cause.of(NamedCause.owner(this)));
}
}

public static ConfigurationLoader<CommentedConfigurationNode> getConfigManager()
{
return configurationManager;
}
getLogger().info("Further updated by Flibio!");
getLogger().info("Please post all errors on the Sponge Thread or on GitHub!");
getLogger().info("Have fun, and enjoy! :D");
getLogger().info("-----------------------------");
getLogger().info("PayDay loaded!");
}

@Listener
public void onGamePostInit(GamePostInitializationEvent event)
{
Optional<EconomyService> econService = Sponge.getServiceManager().provide(EconomyService.class);

if (econService.isPresent())
{
economyService = econService.get();
}
else
{
getLogger().error("Error! There is no Economy plugin found on this server, PayDay will not work correctly!");
}
}

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event)
{
Player player = event.getTargetEntity();

for (Entry<String, BigDecimal> entry : Utils.getPaymentAmounts().entrySet())
{
if (entry.getKey().equals("*") || player.hasPermission(entry.getKey()))
{
BigDecimal pay = entry.getValue();
String name = economyService.getDefaultCurrency().getDisplayName().toPlain();
if (pay.compareTo(BigDecimal.ONE) != 0)
{
name = economyService.getDefaultCurrency().getPluralDisplayName().toPlain();
}
player.sendMessage(Text.of(TextColors.GOLD, "[PayDay]: ", TextColors.GRAY, "Welcome to the server! Here is " + pay + " " + name
+ "! Enjoy!"));
UniqueAccount uniqueAccount = economyService.getOrCreateAccount(player.getUniqueId()).get();
uniqueAccount.deposit(economyService.getDefaultCurrency(), pay, Cause.of(NamedCause.owner(this)));
}
}
}

public static PayDay getInstance()
{
return instance;
}

public static ConfigurationLoader<CommentedConfigurationNode> getConfigManager()
{
return configurationManager;
}
}
Loading

0 comments on commit cdbc363

Please sign in to comment.