i dont have a github yet, so this is the only java file
package ZpknTr;
import com.google.inject.Inject;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.spongepowered.api.Game;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.UniqueAccount;
import java.io.*;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;
/**
* Created by zpkn on 18.8.2016.
*/
@Plugin(id="timeismoney", name="TimeIsMoney", version="1.0")
public class TimeIsMoney {
@Inject
private Logger getLogger()
{
return logger;
}
private int counter=0;
private int ginterval=10;
private int greward;
public static int money;
public static int glimit;
public static String limitfcom;
public static String earnedmoney;
private String grewardmessage;
private String glimitreached;
public static String tamad;
String path;
private EconomyService economyService;
@Listener
public void onChangeServiceProvider(ChangeServiceProviderEvent event) {
if (event.getService().equals(EconomyService.class)) {
economyService = (EconomyService) event.getNewProviderRegistration().getProvider();
}
}
@Inject
Game game;
@Inject
Logger logger;
@Inject
@DefaultConfig(sharedRoot = true)
public File configuration = null;
@Inject
@DefaultConfig(sharedRoot = true)
public ConfigurationLoader<CommentedConfigurationNode> configurationLoader = null;
public CommentedConfigurationNode configurationNode = null;
Timer timer = new Timer();
@Listener
public void onInit(GameStoppingServerEvent e){
getLogger().info("Stopping:TimeIsMoney... TIM is made by ZpknTr");
timer.cancel();
}
@Listener
public void onInit(GameInitializationEvent e){
getLogger().info("Loading:TimeIsMoney... TIM is made by ZpknTr");
try {
if (!configuration.exists()) {
configuration.createNewFile();
configurationNode = configurationLoader.load();
configurationNode.getNode("Variables").setComment("These are the actual values.");
configurationNode.getNode("Variables","IntervalInSeconds").setValue(60);
configurationNode.getNode("Variables","Reward").setValue(20);
configurationNode.getNode("Variables","DailyLimit").setValue(2400);
configurationNode.getNode("WarningMsg").setComment("These are the messages.");
configurationNode.getNode("WarningMsg","RewardMessage").setValue("Reward given for being online: ");
configurationNode.getNode("WarningMsg","LimitReached").setValue("You have reached daily reward limit.");
configurationNode.getNode("WarningMsg","LimitForCommand").setValue("Today's reward limit is: ");
configurationNode.getNode("WarningMsg","EarnedMoney").setValue("You have earned: ");
configurationLoader.save(configurationNode);
}
configurationNode = configurationLoader.load();
ginterval = configurationNode.getNode("Variables","IntervalInSeconds").getInt();
greward = configurationNode.getNode("Variables","Reward").getInt();
glimit = configurationNode.getNode("Variables","DailyLimit").getInt();
grewardmessage=configurationNode.getNode("WarningMsg","RewardMessage").getString();
glimitreached = configurationNode.getNode("WarningMsg","LimitReached").getString();
limitfcom = configurationNode.getNode("WarningMsg","LimitForCommand").getString();
earnedmoney = configurationNode.getNode("WarningMsg","EarnedMoney").getString();
configurationNode =configurationLoader.load();
}catch(IOException exception){
exception.printStackTrace();
}
path = configuration.getAbsolutePath();
path= path.substring(0,path.length()-17);
timer.schedule(new TimerTask() {
@Override
public void run() {
try {
if (configuration.exists()) {
configurationNode = configurationLoader.load();
ginterval = configurationNode.getNode("Variables", "IntervalInSeconds").getInt();
greward = configurationNode.getNode("Variables", "Reward").getInt();
glimit = configurationNode.getNode("Variables", "DailyLimit").getInt();
grewardmessage = configurationNode.getNode("WarningMsg", "RewardMessage").getString();
glimitreached = configurationNode.getNode("WarningMsg", "LimitReached").getString();
limitfcom = configurationNode.getNode("WarningMsg", "LimitForCommand").getString();
earnedmoney = configurationNode.getNode("WarningMsg", "EarnedMoney").getString();
configurationNode = configurationLoader.load();
}
}catch(IOException exception){
exception.printStackTrace();
}
if (counter>=ginterval) {
counter = 0;
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = new Date();
String tarih = dateFormat.format(date); //2014/08/06 15:59:48
tamad = Text.of(path, "\\TimeIsMoneyLogs\\", tarih, ".log").toPlain();
File theDir = new File(Text.of(path, "\\TimeIsMoneyLogs").toPlain());
// if the directory does not exist, create it
if (!theDir.exists()) {
try {
theDir.mkdir();
} catch (SecurityException se) {
//handle it
se.printStackTrace();
}
}
File f = new File(tamad);
if (!f.exists() && !f.isDirectory()) {
File file = new File(tamad);
FileWriter writer;
try {
writer = new FileWriter(file, true);
PrintWriter printer = new PrintWriter(writer);
printer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Boolean testingflag = false;
Integer moneyb = 0;
money = 0;
String line;
Integer kayitlinerow = 0;
List<String> kayit = new ArrayList<String>();
Integer linerow = 0;
for (Player player : game.getServer().getOnlinePlayers()) {
if (player != null) {
BufferedReader fr;
try {
fr = new BufferedReader(new InputStreamReader(new FileInputStream(new File(tamad))));
kayit.clear();
String aname;
testingflag = false;
linerow = 0;
while ((line = fr.readLine()) != null) {
kayit.add(linerow, line);
String[] parts = line.split(" ");
aname = parts[0]; // 004
moneyb = Integer.parseInt(parts[1]); // 034556
if (Objects.equals(aname, player.getName())) {
testingflag = true;
money = moneyb;
kayitlinerow = linerow;
}
linerow += 1;
}
} catch (IOException e) {
e.printStackTrace();
}
if (testingflag) {
if (glimit > money) {
if (money + greward > glimit) {
long x = glimit - money;
Optional<UniqueAccount> uOpt = economyService.getOrCreateAccount(player.getUniqueId());
if (uOpt.isPresent()) {
UniqueAccount acc = uOpt.get();
acc.deposit(economyService.getDefaultCurrency(), BigDecimal.valueOf(x), Cause.source(this).build());
}
player.sendMessage(Text.of(TextColors.GREEN, grewardmessage, TextColors.GOLD, x, economyService.getDefaultCurrency().getSymbol()));
player.sendMessage(Text.of(TextColors.GREEN, earnedmoney, TextColors.GOLD, money));
player.sendMessage(Text.of(TextColors.BLUE, glimitreached));
File file = new File(tamad);
FileWriter writer;
try {
writer = new FileWriter(file, false);
PrintWriter printer = new PrintWriter(writer);
for (int i = 0; i < linerow; i++) {
if (i == kayitlinerow) {
printer.println(Text.of(player.getName(), " ", glimit).toPlain());
} else {
printer.println(kayit.get(i));
}
}
printer.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
Optional<UniqueAccount> uOpt = economyService.getOrCreateAccount(player.getUniqueId());
if (uOpt.isPresent()) {
UniqueAccount acc = uOpt.get();
long x = greward;
acc.deposit(economyService.getDefaultCurrency(), BigDecimal.valueOf(x), Cause.source(this).build());
}
player.sendMessage(Text.of(TextColors.GREEN, grewardmessage, TextColors.GOLD, greward, economyService.getDefaultCurrency().getSymbol()));
player.sendMessage(Text.of(TextColors.GREEN, earnedmoney, TextColors.GOLD, money));
player.sendMessage(Text.of(TextColors.BLUE, limitfcom, TextColors.GOLD, glimit));
File file = new File(tamad);
FileWriter writer;
try {
writer = new FileWriter(file, false);
PrintWriter printer = new PrintWriter(writer);
for (int i = 0; i < linerow; i++) {
if (i == kayitlinerow) {
printer.println(Text.of(player.getName(), " ", (money + greward)).toPlain());
} else {
printer.println(kayit.get(i));
}
}
printer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} else {
Optional<UniqueAccount> uOpt = economyService.getOrCreateAccount(player.getUniqueId());
if (uOpt.isPresent()) {
UniqueAccount acc = uOpt.get();
long x = greward;
acc.deposit(economyService.getDefaultCurrency(), BigDecimal.valueOf(x), Cause.source(this).build());
}
player.sendMessage(Text.of(TextColors.GREEN, grewardmessage, TextColors.GOLD, greward, economyService.getDefaultCurrency().getSymbol()));
player.sendMessage(Text.of(TextColors.GREEN, earnedmoney, TextColors.GOLD, money));
player.sendMessage(Text.of(TextColors.BLUE, limitfcom, TextColors.GOLD, glimit));
File file = new File(tamad);
FileWriter writer;
try {
writer = new FileWriter(file, true);
PrintWriter printer = new PrintWriter(writer);
printer.append(Text.of(player.getName(), " ", greward).toPlain());
printer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}else {
counter+=1;
}
}
}, 1000, 1000);
}
}