From 04db7948a3adcec2892fba04794d1d431852913d Mon Sep 17 00:00:00 2001 From: HassanS6000 Date: Fri, 28 Aug 2015 17:14:41 -0400 Subject: [PATCH] Added project --- README.txt | 4 + .../java/io/github/hsyyid/payday/Main.java | 90 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 README.txt create mode 100644 src/main/java/io/github/hsyyid/payday/Main.java diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..e26563b --- /dev/null +++ b/README.txt @@ -0,0 +1,4 @@ +PayDay is a Sponge plugin made by HassanS6000. + +You can check out PayDay's forum posting on Sponge: https://forums.spongepowered.org/ +And the developer's website, NEGAFINITY: http://negafinity.com \ No newline at end of file diff --git a/src/main/java/io/github/hsyyid/payday/Main.java b/src/main/java/io/github/hsyyid/payday/Main.java new file mode 100644 index 0000000..5834580 --- /dev/null +++ b/src/main/java/io/github/hsyyid/payday/Main.java @@ -0,0 +1,90 @@ +package io.github.hsyyid.payday; + +import java.io.File; +import java.math.BigDecimal; +import java.util.concurrent.TimeUnit; + +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.loader.ConfigurationLoader; + +import org.slf4j.Logger; +import org.spongepowered.api.Game; +import org.spongepowered.api.entity.player.Player; +import org.spongepowered.api.event.Subscribe; +import org.spongepowered.api.event.state.ServerStartedEvent; +import org.spongepowered.api.plugin.Plugin; +import org.spongepowered.api.service.config.DefaultConfig; +import org.spongepowered.api.service.permission.Subject; +import org.spongepowered.api.service.permission.option.OptionSubject; +import org.spongepowered.api.service.scheduler.SchedulerService; +import org.spongepowered.api.service.scheduler.TaskBuilder; +import org.spongepowered.api.text.Texts; +import org.spongepowered.api.text.format.TextColors; + +import com.erigitic.config.AccountManager; +import com.erigitic.main.TotalEconomy; +import com.google.inject.Inject; + +@Plugin(id = "PayDay", name = "PayDay", version = "0.1", dependencies = "required-after:TotalEconomy") +public class Main +{ + public static Game game = null; + + @Inject + private Logger logger; + + public Logger getLogger() + { + return logger; + } + + @Inject + @DefaultConfig(sharedRoot = true) + private File dConfig; + + @Inject + @DefaultConfig(sharedRoot = true) + private ConfigurationLoader confManager; + + @Subscribe + public void onServerStart(ServerStartedEvent event) + { + getLogger().info("PayDay loading..."); + + game = event.getGame(); + + SchedulerService scheduler = game.getScheduler(); + TaskBuilder taskBuilder = scheduler.createTaskBuilder(); + + taskBuilder.execute(new Runnable() + { + public void run() + { + for(Player player : game.getServer().getOnlinePlayers()) + { + Subject subject = player.getContainingCollection().get(player.getIdentifier()); + + if (subject instanceof OptionSubject) + { + OptionSubject optionSubject = (OptionSubject) subject; + double pay = Double.parseDouble(optionSubject.getOption("pay").or("")); + + player.sendMessage(Texts.of(TextColors.GOLD, "[PayDay]: ", TextColors.GRAY, "It's PayDay! Here is your salary of " + pay + " dollars! Enjoy!")); + + TotalEconomy totalEconomy = (TotalEconomy) game.getPluginManager().getPlugin("TotalEconomy").get().getInstance(); + AccountManager accountManager = totalEconomy.getAccountManager(); + BigDecimal amount = new BigDecimal(pay); + accountManager.addToBalance(player.getUniqueId(), amount, true); + } + } + } + }).interval(1, TimeUnit.HOURS).name("PayDay - Pay").submit(game.getPluginManager().getPlugin("PayDay").get().getInstance()); + + getLogger().info("-----------------------------"); + getLogger().info("PayDay was made by HassanS6000!"); + 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!"); + } +} \ No newline at end of file