Dateien nach "src/main/java/craftersland/eco/bridge" hochladen
This commit is contained in:
59
src/main/java/craftersland/eco/bridge/BackgroundTask.java
Normal file
59
src/main/java/craftersland/eco/bridge/BackgroundTask.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package net.craftersland.eco.bridge;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class BackgroundTask {
|
||||||
|
|
||||||
|
private Eco m;
|
||||||
|
private long lastSave = System.currentTimeMillis();
|
||||||
|
|
||||||
|
public BackgroundTask(Eco m) {
|
||||||
|
this.m = m;
|
||||||
|
runTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runTask() {
|
||||||
|
if (m.getConfigHandler().getBoolean("General.saveDataTask.enabled") == true) {
|
||||||
|
Eco.log.info("Data save task is enabled.");
|
||||||
|
} else {
|
||||||
|
Eco.log.info("Data save task is disabled.");
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskTimerAsynchronously(m, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
m.getEcoDataHandler().updateBalanceMap();
|
||||||
|
runSaveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 20L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runSaveData() {
|
||||||
|
if (m.getConfigHandler().getBoolean("General.saveDataTask.enabled") == true) {
|
||||||
|
if (Bukkit.getOnlinePlayers().isEmpty() == false) {
|
||||||
|
if (System.currentTimeMillis() - lastSave >= m.getConfigHandler().getInteger("General.saveDataTask.interval") * 60 * 1000) {
|
||||||
|
List<Player> onlinePlayers = new ArrayList<Player>(Bukkit.getOnlinePlayers());
|
||||||
|
lastSave = System.currentTimeMillis();
|
||||||
|
if (m.getConfigHandler().getBoolean("General.saveDataTask.hideLogMessages") == false) {
|
||||||
|
Eco.log.info("Saving online players data...");
|
||||||
|
}
|
||||||
|
for (Player p : onlinePlayers) {
|
||||||
|
if (p.isOnline() == true) {
|
||||||
|
m.getEcoDataHandler().onDataSaveFunction(p, false, "false", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m.getConfigHandler().getBoolean("General.saveDataTask.hideLogMessages") == false) {
|
||||||
|
Eco.log.info("Data save complete for " + onlinePlayers.size() + " players.");
|
||||||
|
}
|
||||||
|
onlinePlayers.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
src/main/java/craftersland/eco/bridge/ConfigHandler.java
Normal file
60
src/main/java/craftersland/eco/bridge/ConfigHandler.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package net.craftersland.eco.bridge;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class ConfigHandler {
|
||||||
|
|
||||||
|
private Eco eco;
|
||||||
|
|
||||||
|
public ConfigHandler(Eco eco) {
|
||||||
|
this.eco = eco;
|
||||||
|
loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfig() {
|
||||||
|
File pluginFolder = new File("plugins" + System.getProperty("file.separator") + Eco.pluginName);
|
||||||
|
if (pluginFolder.exists() == false) {
|
||||||
|
pluginFolder.mkdir();
|
||||||
|
}
|
||||||
|
File configFile = new File("plugins" + System.getProperty("file.separator") + Eco.pluginName + System.getProperty("file.separator") + "config.yml");
|
||||||
|
if (configFile.exists() == false) {
|
||||||
|
Eco.log.info("No config file found! Creating new one...");
|
||||||
|
eco.saveDefaultConfig();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Eco.log.info("Loading the config file...");
|
||||||
|
eco.getConfig().load(configFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Eco.log.severe("Could not load the config file! You need to regenerate the config! Error: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String key) {
|
||||||
|
if (!eco.getConfig().contains(key)) {
|
||||||
|
eco.getLogger().severe("Could not locate " + key + " in the config.yml inside of the " + Eco.pluginName + " folder! (Try generating a new one by deleting the current)");
|
||||||
|
return "errorCouldNotLocateInConfigYml:" + key;
|
||||||
|
} else {
|
||||||
|
return eco.getConfig().getString(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getInteger(String key) {
|
||||||
|
if (!eco.getConfig().contains(key)) {
|
||||||
|
eco.getLogger().severe("Could not locate " + key + " in the config.yml inside of the " + Eco.pluginName + " folder! (Try generating a new one by deleting the current)");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return eco.getConfig().getInt(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getBoolean(String key) {
|
||||||
|
if (!eco.getConfig().contains(key)) {
|
||||||
|
eco.getLogger().severe("Could not locate " + key + " in the config.yml inside of the " + Eco.pluginName + " folder! (Try generating a new one by deleting the current)");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return eco.getConfig().getBoolean(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
97
src/main/java/craftersland/eco/bridge/Eco.java
Normal file
97
src/main/java/craftersland/eco/bridge/Eco.java
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package net.craftersland.eco.bridge;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.craftersland.eco.bridge.database.EcoMysqlHandler;
|
||||||
|
import net.craftersland.eco.bridge.database.MysqlSetup;
|
||||||
|
import net.craftersland.eco.bridge.events.PlayerDisconnect;
|
||||||
|
import net.craftersland.eco.bridge.events.PlayerJoin;
|
||||||
|
import net.craftersland.eco.bridge.events.handlers.EcoDataHandler;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class Eco extends JavaPlugin {
|
||||||
|
|
||||||
|
public static Logger log;
|
||||||
|
public static Economy vault = null;
|
||||||
|
public static String pluginName = "MysqlEcoBridge";
|
||||||
|
public Map<Player, Integer> syncCompleteTasks = new HashMap<Player, Integer>();
|
||||||
|
|
||||||
|
private static ConfigHandler configHandler;
|
||||||
|
private static MysqlSetup mysqlSetup;
|
||||||
|
private static EcoMysqlHandler ecoMysqlHandler;
|
||||||
|
private static EcoDataHandler edH;
|
||||||
|
private static BackgroundTask bt;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
log = getLogger();
|
||||||
|
//Setup Vault for economy
|
||||||
|
if (setupEconomy() == false) {
|
||||||
|
log.severe("Warning! - Vault installed? If yes Economy system installed?");
|
||||||
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Load Configuration
|
||||||
|
configHandler = new ConfigHandler(this);
|
||||||
|
//Setup MySQL
|
||||||
|
mysqlSetup = new MysqlSetup(this);
|
||||||
|
ecoMysqlHandler = new EcoMysqlHandler(this);
|
||||||
|
edH = new EcoDataHandler(this);
|
||||||
|
bt = new BackgroundTask(this);
|
||||||
|
//Register Listeners
|
||||||
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
pm.registerEvents(new PlayerJoin(this), this);
|
||||||
|
pm.registerEvents(new PlayerDisconnect(this), this);
|
||||||
|
log.info(pluginName + " loaded successfully!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
|
HandlerList.unregisterAll(this);
|
||||||
|
if (mysqlSetup.getConnection() != null) {
|
||||||
|
edH.onShutDownDataSave();
|
||||||
|
mysqlSetup.closeConnection();
|
||||||
|
}
|
||||||
|
log.info(pluginName + " is disabled!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setupEconomy() {
|
||||||
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (rsp == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
vault = rsp.getProvider();
|
||||||
|
log.info("Using economy system: " + rsp.getProvider().getName());
|
||||||
|
return vault != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigHandler getConfigHandler() {
|
||||||
|
return configHandler;
|
||||||
|
}
|
||||||
|
public MysqlSetup getMysqlSetup() {
|
||||||
|
return mysqlSetup;
|
||||||
|
}
|
||||||
|
public EcoMysqlHandler getEcoMysqlHandler() {
|
||||||
|
return ecoMysqlHandler;
|
||||||
|
}
|
||||||
|
public EcoDataHandler getEcoDataHandler() {
|
||||||
|
return edH;
|
||||||
|
}
|
||||||
|
public BackgroundTask getBackgroundTask() {
|
||||||
|
return bt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user