Untitled diff

Created Diff never expires
15 removals
114 lines
13 additions
112 lines
package me.plisov.payday.listeners;
package me.plisov.payday.listeners;


import java.io.File;
import java.io.File;
import java.io.IOException;
import java.io.IOException;


import org.bukkit.Bukkit;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitRunnable;


import me.plisov.payday.Enable;
import me.plisov.payday.Enable;
import ru.tehkode.permissions.bukkit.PermissionsEx;
import ru.tehkode.permissions.bukkit.PermissionsEx;


public class onPlayerJoin implements Listener {
public class onPlayerJoin implements Listener {


Enable plugin;
Enable plugin;
public onPlayerJoin(Enable plugin){
public onPlayerJoin(Enable plugin){
this.plugin = plugin;
this.plugin = plugin;
}
}
int amount;
@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
@EventHandler
@EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent event) throws IOException {
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player player = (Player) event.getPlayer();
Player player = (Player) event.getPlayer();

final int amount; //Moving "int amount" into here allows only this method to access this variable (which makes it be recreated for every player that joins, then gets put away in a config, and forgotten about in RAM, as opposed to being one value that gets modified and perhaps used again for a different player
if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("Peasant")) {
String groupName = PermissionsEx.getUser(player).getGroups()[0].getName(); //Saves typing effort, centralizes meaning
if(groupName.equalsIgnoreCase("Peasant")) {
amount = 50;
amount = 50;
} else if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("Serf")) {
} else if(groupName.equalsIgnoreCase("Serf")) {
amount = 75;
amount = 75;
} else if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("Merchant")) {
} else if(groupName.equalsIgnoreCase("Merchant")) {
amount = 100;
amount = 100;
} else if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("Knight")) {
} else if(groupName.equalsIgnoreCase("Knight")) {
amount = 150;
amount = 150;
} else if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("Noble")) {
} else if(groupName.equalsIgnoreCase("Noble")) {
amount = 200;
amount = 200;
} else if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("King")) {
} else if(groupName.equalsIgnoreCase("King")) {
amount = 250;
amount = 250;
} else if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("DemiGod")) {
} else if(groupName.equalsIgnoreCase("DemiGod")) {
amount = 300;
amount = 300;
} else if(PermissionsEx.getUser(player).getGroups()[0].getName().equalsIgnoreCase("Immortal")) {
} else if(groupName.equalsIgnoreCase("Immortal")) {
amount = 400;
amount = 400;
}
} else amount = 0;


FileConfiguration config = null;
FileConfiguration config = null;
File file = new File("plugins" + File.separator + "PayDay" + File.separator + "users" + File.separator + player.getUniqueId() + " (" + player.getName() + ")" + ".yml");
File file = new File("plugins" + File.separator + "PayDay" + File.separator + "users" + File.separator + player.getUniqueId() + " (" + player.getName() + ")" + ".yml");
if(!file.exists()) {
if(!file.exists()) {
System.out.println("File Created: " + event.getPlayer().getUniqueId() + ".yml" + " (" + event.getPlayer().getName() + ")");
System.out.println("File Created: " + event.getPlayer().getUniqueId() + ".yml" + " (" + event.getPlayer().getName() + ")");
try {
try {
file.createNewFile();
file.createNewFile();
} catch (IOException e) {
} catch (IOException e) {
//e.printStackTrace();
//e.printStackTrace();
}
}
config = YamlConfiguration.loadConfiguration(file);
config = YamlConfiguration.loadConfiguration(file);
config.set("Player.Name", event.getPlayer().getName());
config.set("Player.Name", event.getPlayer().getName());
config.set("Player.Rank", PermissionsEx.getUser(player).getGroups()[0].getName());
config.set("Player.Rank", groupName);
config.set("Player.Time-Left", 900);
config.set("Player.Time-Left", 900);
config.set("Player.Time-Max", 900);
config.set("Player.Time-Max", 900);
config.set("Player.Amount-Recieved", amount);
config.set("Player.Amount-Recieved", amount);


try {
try {
config.save(file);
config.save(file);
} catch (IOException e) {
} catch (IOException e) {
}
}
}
}
config = YamlConfiguration.loadConfiguration(file);
config = YamlConfiguration.loadConfiguration(file);


String prefix = ChatColor.BLUE + "" + ChatColor.BOLD + "(" + ChatColor.GREEN + "PayDay" + ChatColor.BLUE + "" + ChatColor.BOLD + ") " + ChatColor.GRAY;
String prefix = ChatColor.BLUE + "" + ChatColor.BOLD + "(" + ChatColor.GREEN + "PayDay" + ChatColor.BLUE + "" + ChatColor.BOLD + ") " + ChatColor.GRAY;
new BukkitRunnable() {
new BukkitRunnable() {
public void run() {
public void run() {
FileConfiguration config = null;
FileConfiguration config = null;
File file = new File("plugins" + File.separator + "PayDay" + File.separator + "users" + File.separator + player.getUniqueId() + " (" + player.getName() + ")" + ".yml");
File file = new File("plugins" + File.separator + "PayDay" + File.separator + "users" + File.separator + player.getUniqueId() + " (" + player.getName() + ")" + ".yml");
config = YamlConfiguration.loadConfiguration(file);
config = YamlConfiguration.loadConfiguration(file);


int timeLeft = config.getInt("Player.Time-Left"); //Consideration: Cache these values in a hashmap, then when the player logs off, save their final value
int timeLeft = config.getInt("Player.Time-Left"); //Consideration: Cache these values in a hashmap, then when the player logs off, save their final value
int timeMax = config.getInt("Player.Time-Max");
int timeMax = config.getInt("Player.Time-Max");
String groupName = PermissionsEx.getUser(player).getGroups()[0].getName();
String groupName = PermissionsEx.getUser(player).getGroups()[0].getName();
if(config.getInt("Player.Time-Left") <= 0) {
if(config.getInt("Player.Time-Left") <= 0) {
if(groupName.equalsIgnoreCase("Peasant") || groupName.equalsIgnoreCase("Serf") || groupName.equalsIgnoreCase("Merchant")
if(groupName.equalsIgnoreCase("Peasant") || groupName.equalsIgnoreCase("Serf") || groupName.equalsIgnoreCase("Merchant")
|| groupName.equalsIgnoreCase("Knight") || groupName.equalsIgnoreCase("Noble") || groupName.equalsIgnoreCase("King")
|| groupName.equalsIgnoreCase("Knight") || groupName.equalsIgnoreCase("Noble") || groupName.equalsIgnoreCase("King")
|| groupName.equalsIgnoreCase("Demigod") || groupName.equalsIgnoreCase("Immortal")) {
|| groupName.equalsIgnoreCase("Demigod") || groupName.equalsIgnoreCase("Immortal")) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "eco give " + player.getName() + " " + amount);
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "eco give " + player.getName() + " " + amount);
player.sendMessage(prefix + "You have recieved your paycheck of " + ChatColor.GREEN + "$" + amount);
player.sendMessage(prefix + "You have recieved your paycheck of " + ChatColor.GREEN + "$" + amount);
config.set("Player.Time-Left", timeMax);
config.set("Player.Time-Left", timeMax);
try {
try {
config.save(file);
config.save(file);
} catch (IOException e) {
} catch (IOException e) {
}
}
}
}
} else {
} else {
if(player.isOnline()) {
if(player.isOnline()) {
config.set("Player.Time-Left", --timeLeft);
config.set("Player.Time-Left", --timeLeft);
try {
try {
config.save(file);
config.save(file);
} catch (IOException e) {
} catch (IOException e) {
}
}
} else {
} else {
this.cancel();
this.cancel();
}
}
}
}
}
}
}.runTaskTimer(plugin, 20, 20);
}.runTaskTimer(plugin, 20, 20);
}
}
}
}