1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-31 21:37:57 +01:00

properly close connections

This commit is contained in:
Zrips 2016-06-25 15:51:21 +03:00
parent e7a30ec608
commit 324b4dc0b4
18 changed files with 456 additions and 525 deletions

View File

@ -43,8 +43,8 @@ public class HookEconomyTask implements Runnable {
if (provider != null) {
Economy economy = provider.getProvider();
if (economy != null) {
Jobs.setEconomy(plugin, new VaultEconomy(economy));
String message = ChatColor.translateAlternateColorCodes('&', "&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault.");
Jobs.setEconomy(this.plugin, new VaultEconomy(economy));
String message = ChatColor.translateAlternateColorCodes('&', "&e[" + this.plugin.getDescription().getName() + "] Successfully linked with Vault.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
console.sendMessage(message);
return;
@ -53,8 +53,8 @@ public class HookEconomyTask implements Runnable {
}
// no Vault found
Jobs.setEconomy(plugin, new BlackholeEconomy());
Bukkit.getServer().getLogger().severe("==================== " + plugin.getDescription().getName() + " ====================");
Jobs.setEconomy(this.plugin, new BlackholeEconomy());
Bukkit.getServer().getLogger().severe("==================== " + this.plugin.getDescription().getName() + " ====================");
Bukkit.getServer().getLogger().severe("Vault is required by this plugin for economy support!");
Bukkit.getServer().getLogger().severe("Please install Vault and economy manager first!");
Bukkit.getServer().getLogger().severe("You can find the latest version here:");

View File

@ -57,15 +57,15 @@ import com.gamingmesh.jobs.economy.BufferedEconomy;
import com.gamingmesh.jobs.economy.Economy;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.listeners.McMMOlistener;
import com.gamingmesh.jobs.listeners.MythicMobsListener;
import com.gamingmesh.jobs.listeners.PistonProtectionListener;
import com.gamingmesh.jobs.stuff.ActionBar;
import com.gamingmesh.jobs.stuff.JobsClassLoader;
import com.gamingmesh.jobs.stuff.Loging;
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
import net.coreprotect.CoreProtectAPI;
public class Jobs {
public static Jobs instance = new Jobs();
// public static JobsPlugin plugin = new JobsPlugin();
@ -85,6 +85,9 @@ public class Jobs {
private static BossBarManager BBManager;
private static ShopManager shopManager;
private static PistonProtectionListener PistonProtectionListener = null;
private static McMMOlistener McMMOlistener = null;
private static MythicMobsListener MythicManager;
private static ConfigManager configManager;
@ -114,14 +117,20 @@ public class Jobs {
private static ActionBar actionbar;
private static CoreProtectAPI CPAPI = null;
public static CoreProtectAPI getCoreProtectApi() {
return CPAPI;
public static void setMcMMOlistener(JobsPlugin plugin) {
McMMOlistener = new McMMOlistener(plugin);
}
public static void setCoreProtectApi(CoreProtectAPI capi) {
CPAPI = capi;
public static McMMOlistener getMcMMOlistener() {
return McMMOlistener;
}
public static void setPistonProtectionListener(JobsPlugin plugin) {
PistonProtectionListener = new PistonProtectionListener(plugin);
}
public static PistonProtectionListener getPistonProtectionListener() {
return PistonProtectionListener;
}
public static void setMythicManager(JobsPlugin plugin) {

View File

@ -20,7 +20,6 @@ package com.gamingmesh.jobs;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import net.coreprotect.CoreProtect;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
@ -30,7 +29,6 @@ import com.gamingmesh.jobs.listeners.JobsListener;
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
import com.gamingmesh.jobs.listeners.McMMOlistener;
import com.gamingmesh.jobs.listeners.MythicMobsListener;
import com.gamingmesh.jobs.listeners.PistonProtectionListener;
import com.gamingmesh.jobs.stuff.ActionBar;
import com.gamingmesh.jobs.stuff.TabComplete;
import com.gamingmesh.jobs.config.YmlMaker;
@ -40,9 +38,9 @@ public class JobsPlugin extends JavaPlugin {
@Override
public void onEnable() {
String packageName = getServer().getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
String version = packageSplit[packageSplit.length - 1].substring(0,packageSplit[packageSplit.length - 1].length()-3);
String packageName = getServer().getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
String version = packageSplit[packageSplit.length - 1].substring(0, packageSplit[packageSplit.length - 1].length() - 3);
try {
Class<?> nmsClass;
nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
@ -105,24 +103,23 @@ public class JobsPlugin extends JavaPlugin {
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
if (McMMOlistener.CheckmcMMO())
if (Jobs.getMcMMOlistener().CheckmcMMO()){
getServer().getPluginManager().registerEvents(new McMMOlistener(this), this);
}
Jobs.setMythicManager(this);
if (Jobs.getMythicManager().Check() && Jobs.getGCManager().MythicMobsEnabled) {
getServer().getPluginManager().registerEvents(new MythicMobsListener(this), this);
}
if (Jobs.getGCManager().useBlockProtection)
getServer().getPluginManager().registerEvents(new PistonProtectionListener(this), this);
if (Jobs.getGCManager().useBlockProtection) {
Jobs.setPistonProtectionListener(this);
getServer().getPluginManager().registerEvents(Jobs.getPistonProtectionListener(), this);
}
// register economy
Bukkit.getScheduler().runTask(this, new HookEconomyTask(this));
if (getServer().getPluginManager().getPlugin("CoreProtect") != null) {
Jobs.setCoreProtectApi(((CoreProtect) getServer().getPluginManager().getPlugin("CoreProtect")).getAPI());
}
// all loaded properly.
Jobs.getScheduleManager().DateUpdater();

View File

@ -57,9 +57,9 @@ public class PermissionHandler {
// remove old permissions
String permName = "jobs.players." + player.getName();
Permission permission = plugin.getServer().getPluginManager().getPermission(permName);
Permission permission = this.plugin.getServer().getPluginManager().getPermission(permName);
if (permission != null) {
plugin.getServer().getPluginManager().removePermission(permission);
this.plugin.getServer().getPluginManager().removePermission(permission);
changed = true;
}
@ -198,7 +198,7 @@ public class PermissionHandler {
// add new permissions (if applicable)
if (permissions.size() > 0) {
plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
this.plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
changed = true;
}
}
@ -217,7 +217,7 @@ public class PermissionHandler {
// create if attachment doesn't exist
if (attachment == null) {
attachment = player.addAttachment(plugin);
attachment = player.addAttachment(this.plugin);
attachment.setPermission(permName, true);
}
@ -226,8 +226,8 @@ public class PermissionHandler {
}
public void registerPermissions() {
PluginManager pm = plugin.getServer().getPluginManager();
for (World world : plugin.getServer().getWorlds()) {
PluginManager pm = this.plugin.getServer().getPluginManager();
for (World world : this.plugin.getServer().getWorlds()) {
if (pm.getPermission("jobs.world." + world.getName().toLowerCase()) == null)
pm.addPermission(new Permission("jobs.world." + world.getName().toLowerCase(), PermissionDefault.TRUE));
}

View File

@ -66,23 +66,23 @@ public class PlayerManager {
}
public PointsData getPointsData() {
return PointsDatabase;
return this.PointsDatabase;
}
public HashMap<String, PlayerInfo> getPlayerMap() {
return PlayerMap;
return this.PlayerMap;
}
public ConcurrentHashMap<String, JobsPlayer> getPlayersCache() {
return playersCache;
return this.playersCache;
}
public ConcurrentHashMap<String, JobsPlayer> getPlayers() {
return players;
return this.players;
}
public int getPlayerIdByName(String name) {
for (Entry<String, PlayerInfo> one : PlayerMap.entrySet()) {
for (Entry<String, PlayerInfo> one : this.PlayerMap.entrySet()) {
if (one.getValue().getName() == null)
continue;
if (one.getValue().getName().equalsIgnoreCase(name))
@ -92,7 +92,7 @@ public class PlayerManager {
}
public Entry<String, PlayerInfo> getPlayerInfoByName(String name) {
for (Entry<String, PlayerInfo> one : PlayerMap.entrySet()) {
for (Entry<String, PlayerInfo> one : this.PlayerMap.entrySet()) {
if (one.getValue().getName() == null)
continue;
if (one.getValue().getName().equalsIgnoreCase(name))
@ -102,7 +102,7 @@ public class PlayerManager {
}
public Entry<String, PlayerInfo> getPlayerInfoById(int id) {
for (Entry<String, PlayerInfo> one : PlayerMap.entrySet()) {
for (Entry<String, PlayerInfo> one : this.PlayerMap.entrySet()) {
if (one.getValue().getName() == null)
continue;
if (one.getValue().getID() == id)
@ -116,14 +116,14 @@ public class PlayerManager {
* @param playername
*/
public void playerJoin(Player player) {
JobsPlayer jPlayer = playersCache.get(player.getName().toLowerCase());
JobsPlayer jPlayer = this.playersCache.get(player.getName().toLowerCase());
if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
JobsPlayer.loadLogFromDao(jPlayer);
playersCache.put(player.getName().toLowerCase(), jPlayer);
this.playersCache.put(player.getName().toLowerCase(), jPlayer);
}
players.put(player.getName().toLowerCase(), jPlayer);
this.players.put(player.getName().toLowerCase(), jPlayer);
AutoJoinJobs(player);
jPlayer.onConnect();
@ -138,13 +138,13 @@ public class PlayerManager {
*/
public void playerQuit(Player player) {
if (Jobs.getGCManager().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
JobsPlayer jPlayer = this.players.remove(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.save(Jobs.getJobsDAO());
jPlayer.onDisconnect();
}
} else {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
JobsPlayer jPlayer = this.players.get(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.onDisconnect();
}
@ -165,13 +165,13 @@ public class PlayerManager {
* 3) Garbage collect the real list to remove any offline players with saved data
*/
ArrayList<JobsPlayer> list = null;
list = new ArrayList<JobsPlayer>(players.values());
list = new ArrayList<JobsPlayer>(this.players.values());
for (JobsPlayer jPlayer : list) {
jPlayer.save(dao);
}
Iterator<JobsPlayer> iter = players.values().iterator();
Iterator<JobsPlayer> iter = this.players.values().iterator();
while (iter.hasNext()) {
JobsPlayer jPlayer = iter.next();
if (!jPlayer.isOnline() && jPlayer.isSaved()) {
@ -186,7 +186,7 @@ public class PlayerManager {
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayer(Player player) {
return playersCache.get(player.getName().toLowerCase());
return this.playersCache.get(player.getName().toLowerCase());
}
/**
@ -195,7 +195,7 @@ public class PlayerManager {
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayer(String playerName) {
return playersCache.get(playerName.toLowerCase());
return this.playersCache.get(playerName.toLowerCase());
}
public JobsPlayer getJobsPlayerOffline(OfflinePlayer player) {
@ -208,7 +208,7 @@ public class PlayerManager {
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayerOffline(String playerName) {
JobsPlayer jPlayer = playersCache.get(playerName.toLowerCase());
JobsPlayer jPlayer = this.playersCache.get(playerName.toLowerCase());
if (jPlayer != null)
return jPlayer;
@ -584,7 +584,7 @@ public class PlayerManager {
* Perform reload
*/
public void reload() {
for (JobsPlayer jPlayer : players.values()) {
for (JobsPlayer jPlayer : this.players.values()) {
for (JobProgression progression : jPlayer.getJobProgression()) {
String jobName = progression.getJob().getName();
Job job = Jobs.getJob(jobName);
@ -718,7 +718,7 @@ public class PlayerManager {
return;
if (!Jobs.getGCManager().AutoJobJoinUse)
return;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
public void run() {
if (!player.isOnline())
return;

View File

@ -88,8 +88,7 @@ public class SignUtil {
try {
writer.save(f);
} catch (IOException e) {
e.printStackTrace();
;
e.printStackTrace();
}
return;
}

View File

@ -97,6 +97,8 @@ public class ConfigManager {
Bukkit.getServer().getLogger().severe("Error: " + e.getMessage());
Bukkit.getServer().getLogger().severe("==============================================");
return;
} finally {
s.close();
}
//conf.options().header(new StringBuilder().append("Jobs configuration.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Stores information about each job.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("For example configurations, visit http://dev.bukkit.org/bukkit-plugins/jobs-reborn/.").append(System.getProperty("line.separator")).toString());

View File

@ -663,22 +663,6 @@ public class GeneralConfigManager {
"Set to 0 if you want to disable timer");
CowMilkingTimer = c.get("Economy.MilkingCow.Timer", 30) * 1000;
c.getW().addComment("ExploitProtections.Coreprotect.Use",
"Requires to have CoreProtect plugin and there should be block place/break logging enabled in core protect config file.",
"This will prevent players from abusing by placing and breaking blocks again and again", "This will work even after server restart");
useCoreProtect = c.get("ExploitProtections.Coreprotect.Use", false);
c.getW().addComment("ExploitProtections.Coreprotect.TimeLimit", "Time limit in minutes to protect blocks from repeating place/breake action.",
"10080 equals to 7 days, keep it in reasonable time range");
CoreProtectInterval = c.get("ExploitProtections.Coreprotect.TimeLimit", 604800);
c.getW().addComment("ExploitProtections.Coreprotect.BlockPlace.Use", "Do you want to use block place interval protection");
BlockPlaceUse = c.get("ExploitProtections.Coreprotect.BlockPlace.Use", true);
EnableAnounceMessage = c.get("ExploitProtections.Coreprotect.BlockPlace.EnableAnounceMessage", true);
c.getW().addComment("ExploitProtections.Coreprotect.BlockPlace.Interval", "Time interval in seconds in how fast you can place block in same place.",
"Keep it on low interval, 3-5 sec will be enough to prevent fast block place in same place and dont annoy peps",
"Edit block list in restrictedBlocks.yml under PlacedBlockTimer");
BlockPlaceInterval = c.get("ExploitProtections.Coreprotect.BlockPlace.Interval", 2);
c.getW().addComment("ExploitProtections.General.PlaceAndBreakProtection",
"Enable blocks protection, like ore, from exploiting by placing and destroying same block again and again.", "This works only until server restart",
"Modify restrictedBlocks.yml for blocks you want to protect");

View File

@ -1,92 +1,96 @@
package com.gamingmesh.jobs.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.gamingmesh.jobs.JobsPlugin;
public class YmlMaker
{
JobsPlugin Plugin;
public String fileName;
private JavaPlugin plugin;
public File ConfigFile;
private FileConfiguration Configuration;
public YmlMaker(JobsPlugin Plugin)
{
this.Plugin = Plugin;
}
public YmlMaker(JavaPlugin plugin, String fileName)
{
if (plugin == null) {
throw new IllegalArgumentException("plugin cannot be null");
}
this.plugin = plugin;
this.fileName = fileName;
File dataFolder = plugin.getDataFolder();
if (dataFolder == null) {
throw new IllegalStateException();
}
this.ConfigFile = new File(dataFolder.toString() + File.separatorChar + this.fileName);
}
public void reloadConfig()
{
try {
this.Configuration = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(this.ConfigFile), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
InputStream defConfigStream = this.plugin.getResource(this.fileName);
if (defConfigStream != null)
{
@SuppressWarnings("deprecation")
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
this.Configuration.setDefaults(defConfig);
}
}
public FileConfiguration getConfig()
{
if (this.Configuration == null) {
reloadConfig();
}
return this.Configuration;
}
public void saveConfig()
{
if ((this.Configuration == null) || (this.ConfigFile == null)) {
return;
}
try
{
getConfig().save(this.ConfigFile);
} catch (IOException ex)
{
this.plugin.getLogger().log(Level.SEVERE, "Could not save config to " + this.ConfigFile, ex);
}
}
public void saveDefaultConfig()
{
if (!this.ConfigFile.exists()) {
this.plugin.saveResource(this.fileName, false);
}
}
}
package com.gamingmesh.jobs.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.gamingmesh.jobs.JobsPlugin;
public class YmlMaker {
JobsPlugin Plugin;
public String fileName;
private JavaPlugin plugin;
public File ConfigFile;
private FileConfiguration Configuration;
public YmlMaker(JobsPlugin Plugin) {
this.Plugin = Plugin;
}
public YmlMaker(JavaPlugin plugin, String fileName) {
if (plugin == null) {
throw new IllegalArgumentException("plugin cannot be null");
}
this.plugin = plugin;
this.fileName = fileName;
File dataFolder = plugin.getDataFolder();
if (dataFolder == null) {
throw new IllegalStateException();
}
this.ConfigFile = new File(dataFolder.toString() + File.separatorChar + this.fileName);
}
public void reloadConfig() {
InputStreamReader f = null;
try {
f = new InputStreamReader(new FileInputStream(this.ConfigFile), "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} finally {
try {
f.close();
} catch (Exception e) {
e.printStackTrace();
}
}
this.Configuration = YamlConfiguration.loadConfiguration(f);
InputStream defConfigStream = this.plugin.getResource(this.fileName);
if (defConfigStream != null) {
@SuppressWarnings("deprecation")
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
this.Configuration.setDefaults(defConfig);
}
try {
defConfigStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public FileConfiguration getConfig() {
if (this.Configuration == null) {
reloadConfig();
}
return this.Configuration;
}
public void saveConfig() {
if ((this.Configuration == null) || (this.ConfigFile == null)) {
return;
}
try {
getConfig().save(this.ConfigFile);
} catch (IOException ex) {
this.plugin.getLogger().log(Level.SEVERE, "Could not save config to " + this.ConfigFile, ex);
}
}
public void saveDefaultConfig() {
if (!this.ConfigFile.exists()) {
this.plugin.saveResource(this.fileName, false);
}
}
}

View File

@ -438,8 +438,7 @@ public class JobsPlayer {
// synchronized (saveLock) {
progression.clear();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
;
Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
// }
}

View File

@ -48,7 +48,8 @@ public class JobsConnectionPool {
}
if (connection == null) {
Connection conn = DriverManager.getConnection(url, username, password);
@SuppressWarnings("resource")
Connection conn = DriverManager.getConnection(url, username, password);
connection = new JobsConnection(conn);
}

View File

@ -158,16 +158,25 @@ public abstract class JobsDAO {
JobsConnection conn = getConnection();
if (conn == null)
return jobs;
ResultSet res = null;
try {
PreparedStatement prest = conn.prepareStatement("SELECT `job`, `level`, `experience` FROM `" + prefix + "jobs` WHERE `userid` = ?;");
prest.setInt(1, id);
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
while (res.next()) {
jobs.add(new JobsDAOData(uuid, res.getString(1), res.getInt(2), res.getInt(3)));
}
prest.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (res != null)
try {
res.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return jobs;
}
@ -217,16 +226,24 @@ public abstract class JobsDAO {
if (conn == null)
return 0;
int count = 0;
ResultSet res = null;
try {
PreparedStatement prest = conn.prepareStatement("SELECT COUNT(*) FROM `" + prefix + "jobs` WHERE `job` = ?;");
prest.setString(1, JobName);
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
while (res.next()) {
count = res.getInt(1);
}
prest.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (res != null)
try {
res.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return count;
}
@ -721,27 +738,28 @@ public abstract class JobsDAO {
JobsConnection conn = getConnection();
if (conn == null)
return;
PreparedStatement prest1 = null;
PreparedStatement prest2 = null;
try {
PreparedStatement prest = conn.prepareStatement("UPDATE `" + prefix
prest1 = conn.prepareStatement("UPDATE `" + prefix
+ "log` SET `count` = ?, `money` = ?, `exp` = ? WHERE `userid` = ? AND `time` = ? AND `action` = ? AND `itemname` = ?;");
for (Log log : player.getLog()) {
for (Entry<String, LogAmounts> one : log.getAmountList().entrySet()) {
if (one.getValue().isNewEntry())
continue;
prest.setInt(1, one.getValue().getCount());
prest.setDouble(2, one.getValue().getMoney());
prest.setDouble(3, one.getValue().getExp());
prest1.setInt(1, one.getValue().getCount());
prest1.setDouble(2, one.getValue().getMoney());
prest1.setDouble(3, one.getValue().getExp());
prest.setInt(4, player.getUserId());
prest.setInt(5, log.getDate());
prest.setString(6, log.getActionType());
prest.setString(7, one.getKey());
prest.execute();
prest1.setInt(4, player.getUserId());
prest1.setInt(5, log.getDate());
prest1.setString(6, log.getActionType());
prest1.setString(7, one.getKey());
prest1.execute();
}
}
prest = conn.prepareStatement("INSERT INTO `" + prefix
prest2 = conn.prepareStatement("INSERT INTO `" + prefix
+ "log` (`userid`, `time`, `action`, `itemname`, `count`, `money`, `exp`) VALUES (?, ?, ?, ?, ?, ?, ?);");
for (Log log : player.getLog()) {
for (Entry<String, LogAmounts> one : log.getAmountList().entrySet()) {
@ -751,19 +769,31 @@ public abstract class JobsDAO {
one.getValue().setNewEntry(false);
prest.setInt(1, player.getUserId());
prest.setInt(2, log.getDate());
prest.setString(3, log.getActionType());
prest.setString(4, one.getKey());
prest.setInt(5, one.getValue().getCount());
prest.setDouble(6, one.getValue().getMoney());
prest.setDouble(7, one.getValue().getExp());
prest.execute();
prest2.setInt(1, player.getUserId());
prest2.setInt(2, log.getDate());
prest2.setString(3, log.getActionType());
prest2.setString(4, one.getKey());
prest2.setInt(5, one.getValue().getCount());
prest2.setDouble(6, one.getValue().getMoney());
prest2.setDouble(7, one.getValue().getExp());
prest2.execute();
}
}
prest.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (prest1 != null)
try {
prest1.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (prest2 != null)
try {
prest2.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@ -985,12 +1015,14 @@ public abstract class JobsDAO {
if (conn == null)
return 0;
PreparedStatement prest = null;
ResultSet res = null;
int schema = 0;
try {
prest = conn.prepareStatement("SELECT `value` FROM `" + prefix + "config` WHERE `key` = ?;");
prest.setString(1, "version");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
return Integer.valueOf(res.getString(1));
schema = Integer.valueOf(res.getString(1));
}
res.close();
} catch (SQLException e) {
@ -998,6 +1030,12 @@ public abstract class JobsDAO {
} catch (NumberFormatException e) {
e.printStackTrace();
} finally {
if (res != null) {
try {
res.close();
} catch (SQLException e) {
}
}
if (prest != null) {
try {
prest.close();
@ -1005,8 +1043,7 @@ public abstract class JobsDAO {
}
}
}
return 0;
return schema;
}
/**

View File

@ -47,6 +47,24 @@ public class JobsDAOMySQL extends JobsDAO {
return dao;
}
private static void close(ResultSet res) {
if (res != null) {
try {
res.close();
} catch (SQLException e) {
}
}
}
private static void close(PreparedStatement prest) {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
}
@Override
protected synchronized void setupConfig() throws SQLException {
JobsConnection conn = getConnection();
@ -56,22 +74,19 @@ public class JobsDAOMySQL extends JobsDAO {
}
PreparedStatement prest = null;
int rows = 0;
ResultSet res = null;
try {
// Check for config table
prest = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?;");
prest.setString(1, database);
prest.setString(2, getPrefix() + "config");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
if (rows == 0) {
@ -84,12 +99,7 @@ public class JobsDAOMySQL extends JobsDAO {
insert.setString(2, "1");
insert.execute();
} finally {
if (insert != null) {
try {
insert.close();
} catch (SQLException e) {
}
}
close(insert);
}
}
}
@ -117,6 +127,7 @@ public class JobsDAOMySQL extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
@ -124,17 +135,13 @@ public class JobsDAOMySQL extends JobsDAO {
prest.setString(1, database);
prest.setString(2, getPrefix() + "jobs");
prest.setString(3, "username");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -152,25 +159,22 @@ public class JobsDAOMySQL extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?;");
prest.setString(1, database);
prest.setString(2, getPrefix() + "archive");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -191,23 +195,20 @@ public class JobsDAOMySQL extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?;");
prest.setString(1, database);
prest.setString(2, getPrefix() + "log");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -301,12 +302,16 @@ public class JobsDAOMySQL extends JobsDAO {
if (insert != null)
insert.executeBatch();
conn.commit();
conn.setAutoCommit(true);
rs.close();
if (insert != null)
insert.close();
if (rs != null)
rs.close();
if (pst1 != null)
pst1.close();
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "jobs`;");
executeSQL("ALTER TABLE `" + getPrefix() + "jobs_temp` RENAME TO `" + getPrefix() + "jobs`;");
@ -367,7 +372,10 @@ public class JobsDAOMySQL extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
rs1.close();
if (rs1 != null)
rs1.close();
if (pst11 != null)
pst11.close();
if (insert1 != null)
insert1.close();
@ -437,7 +445,10 @@ public class JobsDAOMySQL extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
rs11.close();
if (pst111 != null)
pst111.close();
if (rs11 != null)
rs11.close();
if (insert11 != null)
insert11.close();
@ -458,25 +469,22 @@ public class JobsDAOMySQL extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?;");
prest.setString(1, database);
prest.setString(2, getPrefix() + "explore");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -501,25 +509,22 @@ public class JobsDAOMySQL extends JobsDAO {
}
PreparedStatement tempPrest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
tempPrest = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?;");
tempPrest.setString(1, database);
tempPrest.setString(2, getPrefix() + "users");
ResultSet res = tempPrest.executeQuery();
res = tempPrest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (tempPrest != null) {
try {
tempPrest.close();
} catch (SQLException e) {
}
}
close(res);
close(tempPrest);
}
// Create new points table
try {
@ -546,21 +551,9 @@ public class JobsDAOMySQL extends JobsDAO {
break;
}
} catch (Exception ex) {
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
} finally {
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
close(rsLogTemp);
close(prestLogTemp);
}
if (!next) {
@ -575,54 +568,45 @@ public class JobsDAOMySQL extends JobsDAO {
if (rows == 0) {
HashMap<String, String> tempMap = new HashMap<String, String>();
PreparedStatement prestJobs = null;
ResultSet res1 = null;
try {
prestJobs = conn.prepareStatement("SELECT DISTINCT(player_uuid),username FROM " + getPrefix() + "jobs;");
ResultSet res = prestJobs.executeQuery();
while (res.next()) {
tempMap.put(res.getString("player_uuid"), res.getString("username"));
res1 = prestJobs.executeQuery();
while (res1.next()) {
tempMap.put(res1.getString("player_uuid"), res1.getString("username"));
}
} catch (Exception e) {
} finally {
if (prestJobs != null) {
try {
prestJobs.close();
} catch (SQLException e) {
}
}
close(res1);
close(prestJobs);
}
PreparedStatement prestArchive = null;
ResultSet res2 = null;
try {
prestArchive = conn.prepareStatement("SELECT DISTINCT(player_uuid),username FROM " + getPrefix() + "archive;");
ResultSet res = prestArchive.executeQuery();
while (res.next()) {
tempMap.put(res.getString("player_uuid"), res.getString("username"));
res2 = prestArchive.executeQuery();
while (res2.next()) {
tempMap.put(res2.getString("player_uuid"), res2.getString("username"));
}
} catch (Exception e) {
} finally {
if (prestArchive != null) {
try {
prestArchive.close();
} catch (SQLException e) {
}
}
close(res2);
close(prestArchive);
}
PreparedStatement prestLog = null;
ResultSet res3 = null;
try {
prestLog = conn.prepareStatement("SELECT DISTINCT(player_uuid),username FROM " + getPrefix() + "log;");
ResultSet res = prestLog.executeQuery();
while (res.next()) {
tempMap.put(res.getString("player_uuid"), res.getString("username"));
res3 = prestLog.executeQuery();
while (res3.next()) {
tempMap.put(res3.getString("player_uuid"), res3.getString("username"));
}
} catch (Exception e) {
} finally {
if (prestLog != null) {
try {
prestLog.close();
} catch (SQLException e) {
}
}
close(res3);
close(prestLog);
}
try {
@ -647,32 +631,24 @@ public class JobsDAOMySQL extends JobsDAO {
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prestUsers != null) {
try {
prestUsers.close();
} catch (SQLException e) {
}
}
close(prestUsers);
}
HashMap<String, PlayerInfo> tempPlayerMap = new HashMap<String, PlayerInfo>();
PreparedStatement prestUsersT = null;
ResultSet res4 = null;
try {
prestUsersT = conn.prepareStatement("SELECT * FROM " + getPrefix() + "users;");
ResultSet res = prestUsersT.executeQuery();
while (res.next()) {
tempPlayerMap.put(res.getString("player_uuid"), new PlayerInfo(res.getString("username"), res.getInt("id")));
res4 = prestUsersT.executeQuery();
while (res4.next()) {
tempPlayerMap.put(res4.getString("player_uuid"), new PlayerInfo(res4.getString("username"), res4.getInt("id")));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prestUsersT != null) {
try {
prestUsersT.close();
} catch (SQLException e) {
}
}
close(res4);
close(prestUsersT);
}
// Modifying jobs main table
@ -695,12 +671,7 @@ public class JobsDAOMySQL extends JobsDAO {
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prestJobsT != null) {
try {
prestJobsT.close();
} catch (SQLException e) {
}
}
close(prestJobsT);
}
try {
@ -728,12 +699,7 @@ public class JobsDAOMySQL extends JobsDAO {
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prestArchiveT != null) {
try {
prestArchiveT.close();
} catch (SQLException e) {
}
}
close(prestArchiveT);
}
try {

View File

@ -29,7 +29,6 @@ import org.bukkit.Bukkit;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.PlayerInfo;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.UUIDUtil;
public class JobsDAOSQLite extends JobsDAO {
@ -50,6 +49,24 @@ public class JobsDAOSQLite extends JobsDAO {
super("org.sqlite.JDBC", "jdbc:sqlite:" + new File(Jobs.getDataFolder(), "jobs.sqlite.db").getPath(), null, null, "");
}
private static void close(ResultSet res) {
if (res != null) {
try {
res.close();
} catch (SQLException e) {
}
}
}
private static void close(PreparedStatement prest) {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
}
@Override
protected synchronized void setupConfig() throws SQLException {
JobsConnection conn = getConnection();
@ -59,22 +76,19 @@ public class JobsDAOSQLite extends JobsDAO {
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for config table
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
prest.setString(1, getPrefix() + "config");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
if (rows == 0) {
@ -87,12 +101,7 @@ public class JobsDAOSQLite extends JobsDAO {
insert.setString(2, "1");
insert.execute();
} finally {
if (insert != null) {
try {
insert.close();
} catch (SQLException e) {
}
}
close(insert);
}
}
}
@ -120,22 +129,19 @@ public class JobsDAOSQLite extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
prest.setString(1, getPrefix() + "jobs");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -155,22 +161,19 @@ public class JobsDAOSQLite extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
prest.setString(1, getPrefix() + "archive");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -191,22 +194,19 @@ public class JobsDAOSQLite extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
prest.setString(1, getPrefix() + "log");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -315,7 +315,10 @@ public class JobsDAOSQLite extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
rs.close();
if (rs != null)
rs.close();
if (pst1 != null)
pst1.close();
if (insert != null)
insert.close();
@ -383,7 +386,10 @@ public class JobsDAOSQLite extends JobsDAO {
insert1.executeBatch();
conn.commit();
conn.setAutoCommit(true);
rs1.close();
if (rs1 != null)
rs1.close();
if (pst11 != null)
pst11.close();
if (insert1 != null)
insert1.close();
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "archive`;");
@ -455,7 +461,10 @@ public class JobsDAOSQLite extends JobsDAO {
insert11.executeBatch();
conn.commit();
conn.setAutoCommit(true);
rs11.close();
if (rs11 != null)
rs11.close();
if (pst111 != null)
pst111.close();
if (insert11 != null)
insert11.close();
@ -475,22 +484,19 @@ public class JobsDAOSQLite extends JobsDAO {
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
prest.setString(1, getPrefix() + "explore");
ResultSet res = prest.executeQuery();
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} finally {
if (prest != null) {
try {
prest.close();
} catch (SQLException e) {
}
}
close(res);
close(prest);
}
try {
@ -510,22 +516,19 @@ public class JobsDAOSQLite extends JobsDAO {
return;
}
PreparedStatement prestTemp = null;
ResultSet res1 = null;
int rows = 0;
try {
// Check for jobs table
prestTemp = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
prestTemp.setString(1, getPrefix() + "users");
ResultSet res = prestTemp.executeQuery();
if (res.next()) {
rows = res.getInt(1);
res1 = prestTemp.executeQuery();
if (res1.next()) {
rows = res1.getInt(1);
}
} finally {
if (prestTemp != null) {
try {
prestTemp.close();
} catch (SQLException e) {
}
}
close(res1);
close(prestTemp);
}
// Create new points table
@ -540,11 +543,9 @@ public class JobsDAOSQLite extends JobsDAO {
ResultSet rsLogTemp = null;
boolean next = false;
try {
Debug.D("trying table");
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
rsLogTemp = prestLogTemp.executeQuery();
while (next = rsLogTemp.next()) {
Debug.D("din table");
rsLogTemp.getInt("userid");
rsLogTemp.getLong("time");
rsLogTemp.getString("action");
@ -552,33 +553,16 @@ public class JobsDAOSQLite extends JobsDAO {
rsLogTemp.getInt("count");
rsLogTemp.getDouble("money");
rsLogTemp.getDouble("exp");
Debug.D("din table");
break;
}
} catch (Exception ex) {
Debug.D("recreating table");
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
} finally {
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
close(rsLogTemp);
close(prestLogTemp);
}
if (!next){
if (!next) {
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "log`;");
try {
executeSQL("CREATE TABLE `" + getPrefix()
@ -593,38 +577,31 @@ public class JobsDAOSQLite extends JobsDAO {
HashMap<String, String> tempMap = new HashMap<String, String>();
PreparedStatement prestJobs = null;
ResultSet res2 = null;
try {
prestJobs = conn.prepareStatement("SELECT * FROM " + getPrefix() + "jobs;");
ResultSet res = prestJobs.executeQuery();
while (res.next()) {
Bukkit.getConsoleSender().sendMessage(res.getString("player_uuid") + " -> " + res.getString("username"));
tempMap.put(res.getString("player_uuid"), res.getString("username"));
res2 = prestJobs.executeQuery();
while (res2.next()) {
Bukkit.getConsoleSender().sendMessage(res2.getString("player_uuid") + " -> " + res2.getString("username"));
tempMap.put(res2.getString("player_uuid"), res2.getString("username"));
}
} finally {
if (prestJobs != null) {
try {
prestJobs.close();
} catch (SQLException e) {
}
}
close(res2);
close(prestJobs);
}
PreparedStatement prestArchive = null;
ResultSet res3 = null;
try {
prestArchive = conn.prepareStatement("SELECT * FROM " + getPrefix() + "archive;");
ResultSet res = prestArchive.executeQuery();
while (res.next()) {
tempMap.put(res.getString("player_uuid"), res.getString("username"));
Bukkit.getConsoleSender().sendMessage(res.getString("player_uuid") + " -> " + res.getString("username"));
res3 = prestArchive.executeQuery();
while (res3.next()) {
tempMap.put(res3.getString("player_uuid"), res3.getString("username"));
Bukkit.getConsoleSender().sendMessage(res3.getString("player_uuid") + " -> " + res3.getString("username"));
}
if (res != null)
res.close();
} finally {
if (prestArchive != null) {
try {
prestArchive.close();
} catch (SQLException e) {
}
}
close(res3);
close(prestArchive);
}
try {
@ -646,32 +623,22 @@ public class JobsDAOSQLite extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
} finally {
if (prestUsers != null) {
try {
prestUsers.close();
} catch (SQLException e) {
}
}
close(prestUsers);
}
HashMap<String, PlayerInfo> tempPlayerMap = new HashMap<String, PlayerInfo>();
PreparedStatement prestUsers2 = null;
ResultSet res4 = null;
try {
prestUsers2 = conn.prepareStatement("SELECT * FROM " + getPrefix() + "users;");
ResultSet res = prestUsers2.executeQuery();
while (res.next()) {
tempPlayerMap.put(res.getString("player_uuid"), new PlayerInfo(res.getString("username"), res.getInt("id")));
res4 = prestUsers2.executeQuery();
while (res4.next()) {
tempPlayerMap.put(res4.getString("player_uuid"), new PlayerInfo(res4.getString("username"), res4.getInt("id")));
}
if (res != null)
res.close();
} finally {
if (prestUsers2 != null) {
try {
prestUsers2.close();
} catch (SQLException e) {
}
}
close(res4);
close(prestUsers2);
}
// Modifying jobs main table
@ -693,12 +660,7 @@ public class JobsDAOSQLite extends JobsDAO {
conn.setAutoCommit(true);
} catch (Exception e) {
} finally {
if (prestJobsT != null) {
try {
prestJobsT.close();
} catch (SQLException e) {
}
}
close(prestJobsT);
}
// dropping 2 columns
@ -722,7 +684,10 @@ public class JobsDAOSQLite extends JobsDAO {
insert11.execute();
}
}
rs11.close();
if (rs11 != null)
rs11.close();
if (pst111 != null)
pst111.close();
if (insert11 != null)
insert11.close();
try {
@ -749,12 +714,7 @@ public class JobsDAOSQLite extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
} finally {
if (prestArchiveT != null) {
try {
prestArchiveT.close();
} catch (SQLException e) {
}
}
close(prestArchiveT);
}
// dropping 2 columns
@ -811,12 +771,7 @@ public class JobsDAOSQLite extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
} finally {
if (prestPreLog != null) {
try {
prestPreLog.close();
} catch (SQLException e) {
}
}
close(prestPreLog);
}
}

View File

@ -421,7 +421,7 @@ public class JobsListener implements Listener {
event.setLine(2, Convert(color + job.getName()));
}
private String Convert(String line) {
private static String Convert(String line) {
Pattern ReplacePatern = Pattern.compile("&([0-9a-fk-or])");
return ReplacePatern.matcher(ChatColor.translateAlternateColorCodes('&', line)).replaceAll("\u00a7$1");
}
@ -584,7 +584,7 @@ public class JobsListener implements Listener {
}
}
private boolean isThisItem(JobLimitedItems oneItem, int id, String name, List<String> lore, Map<Enchantment, Integer> enchants) {
private static boolean isThisItem(JobLimitedItems oneItem, int id, String name, List<String> lore, Map<Enchantment, Integer> enchants) {
if (oneItem.getId() != id)
return false;

View File

@ -107,7 +107,7 @@ public class JobsPaymentListener implements Listener {
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
if (!(event.getRightClicked() instanceof LivingEntity))
@ -160,7 +160,7 @@ public class JobsPaymentListener implements Listener {
Long Timer = System.currentTimeMillis();
cow.setMetadata(CowMetadata, new FixedMetadataValue(plugin, Timer));
cow.setMetadata(CowMetadata, new FixedMetadataValue(this.plugin, Timer));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -174,13 +174,13 @@ public class JobsPaymentListener implements Listener {
Sheep sheep = (Sheep) event.getEntity();
// mob spawner, no payment or experience
if (sheep.hasMetadata(mobSpawnerMetadata)) {
sheep.removeMetadata(mobSpawnerMetadata, plugin);
if (sheep.hasMetadata(this.mobSpawnerMetadata)) {
sheep.removeMetadata(this.mobSpawnerMetadata, this.plugin);
return;
}
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Player player = (Player) event.getPlayer();
@ -208,7 +208,7 @@ public class JobsPaymentListener implements Listener {
//disabling plugin in world
if (event.getBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
return;
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Block block = event.getBlock();
if (block == null)
@ -251,26 +251,19 @@ public class JobsPaymentListener implements Listener {
if (block == null)
return;
if (block.getType() == Material.FURNACE && block.hasMetadata(furnaceOwnerMetadata))
block.removeMetadata(furnaceOwnerMetadata, plugin);
if (block.getType() == Material.FURNACE && block.hasMetadata(this.furnaceOwnerMetadata))
block.removeMetadata(this.furnaceOwnerMetadata, this.plugin);
if (Jobs.getGCManager().useBlockProtection)
if (block.getState().hasMetadata(BlockMetadata))
return;
if (Jobs.getCoreProtectApi() != null && Jobs.getGCManager().useCoreProtect)
if (PistonProtectionListener.CheckBlock(block)) {
List<String[]> blockLookup = Jobs.getCoreProtectApi().blockLookup(block, Jobs.getGCManager().CoreProtectInterval);
if (blockLookup.size() > 0)
return;
}
if (Jobs.getGCManager().useBlockTimer)
if (PistonProtectionListener.checkVegybreak(block, (Player) event.getPlayer()))
if (Jobs.getPistonProtectionListener().checkVegybreak(block, (Player) event.getPlayer()))
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Player player = event.getPlayer();
@ -303,15 +296,15 @@ public class JobsPaymentListener implements Listener {
// restricted area multiplier
double multiplier = 0.0;
if (McMMOlistener.mcMMOPresent)
multiplier = McMMOlistener.getMultiplier(player) * 100 - 100;
if (Jobs.getMcMMOlistener().mcMMOPresent)
multiplier = Jobs.getMcMMOlistener().getMultiplier(player) * 100 - 100;
// Item in hand
ItemStack item = Jobs.getNms().getItemInMainHand(player);
// Protection for block break with silktouch
if (Jobs.getGCManager().useSilkTouchProtection && item != null)
if (PistonProtectionListener.CheckBlock(block))
if (Jobs.getPistonProtectionListener().CheckBlock(block))
for (Entry<Enchantment, Integer> one : item.getEnchantments().entrySet())
if (one.getKey().getName().equalsIgnoreCase("SILK_TOUCH"))
return;
@ -337,7 +330,7 @@ public class JobsPaymentListener implements Listener {
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
// check to make sure you can build
@ -349,21 +342,6 @@ public class JobsPaymentListener implements Listener {
if (!player.isOnline())
return;
if (Jobs.getCoreProtectApi() != null && Jobs.getGCManager().useCoreProtect && Jobs.getGCManager().BlockPlaceUse) {
if (PistonProtectionListener.CheckPlaceBlock(block)) {
List<String[]> blockLookup = Jobs.getCoreProtectApi().blockLookup(block, Jobs.getGCManager().BlockPlaceInterval + 1);
if (blockLookup.size() > 0) {
long PlacedBlockTime = Integer.valueOf(blockLookup.get(0)[0]);
long CurrentTime = System.currentTimeMillis() / 1000;
if (PlacedBlockTime + Jobs.getGCManager().BlockPlaceInterval > CurrentTime) {
if (Jobs.getGCManager().EnableAnounceMessage)
Jobs.getActionBar().send(player, Jobs.getLanguage().getMessage("message.placeblocktimer", "[time]", Jobs.getGCManager().BlockPlaceInterval));
return;
}
}
}
}
// check if in creative
if (event.getPlayer().getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative())
return;
@ -373,21 +351,21 @@ public class JobsPaymentListener implements Listener {
// Block place/break protection
if (Jobs.getGCManager().useBlockProtection)
if (PistonProtectionListener.CheckBlock(block))
block.getState().setMetadata(BlockMetadata, new FixedMetadataValue(plugin, true));
if (Jobs.getPistonProtectionListener().CheckBlock(block))
block.getState().setMetadata(BlockMetadata, new FixedMetadataValue(this.plugin, true));
if (Jobs.getGCManager().WaterBlockBreake)
block.getState().setMetadata(PlacedBlockMetadata, new FixedMetadataValue(plugin, true));
block.getState().setMetadata(PlacedBlockMetadata, new FixedMetadataValue(this.plugin, true));
if (Jobs.getGCManager().useBlockTimer)
if (PistonProtectionListener.CheckVegy(block)) {
if (Jobs.getPistonProtectionListener().CheckVegy(block)) {
long time = System.currentTimeMillis();
block.setMetadata(VegyMetadata, new FixedMetadataValue(plugin, time));
block.setMetadata(VegyMetadata, new FixedMetadataValue(this.plugin, time));
}
if (Jobs.getGCManager().useGlobalTimer) {
long time = System.currentTimeMillis();
block.setMetadata(GlobalMetadata, new FixedMetadataValue(plugin, time));
block.setMetadata(GlobalMetadata, new FixedMetadataValue(this.plugin, time));
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
@ -402,7 +380,7 @@ public class JobsPaymentListener implements Listener {
if (event.getPlayer() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()))
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Player player = event.getPlayer();
@ -434,13 +412,13 @@ public class JobsPaymentListener implements Listener {
LivingEntity animal = (LivingEntity) event.getEntity();
// mob spawner, no payment or experience
if (animal.hasMetadata(mobSpawnerMetadata)) {
animal.removeMetadata(mobSpawnerMetadata, plugin);
if (animal.hasMetadata(this.mobSpawnerMetadata)) {
animal.removeMetadata(this.mobSpawnerMetadata, this.plugin);
return;
}
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Player player = (Player) event.getOwner();
@ -469,7 +447,7 @@ public class JobsPaymentListener implements Listener {
if (event.getWhoClicked() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld()))
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
// If event is nothing or place, do nothing
@ -600,7 +578,7 @@ public class JobsPaymentListener implements Listener {
for (int i = 0; i < preInv.length; i++) {
preInv[i] = preInv[i] != null ? preInv[i].clone() : null;
}
return Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
return Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
@Override
public void run() {
final ItemStack[] postInv = player.getInventory().getContents();
@ -626,12 +604,12 @@ public class JobsPaymentListener implements Listener {
}, 1);
}
private boolean hasItems(ItemStack stack) {
private static boolean hasItems(ItemStack stack) {
return stack != null && stack.getAmount() > 0;
}
@SuppressWarnings("deprecation")
private boolean hasSameItem(ItemStack a, ItemStack b) {
private static boolean hasSameItem(ItemStack a, ItemStack b) {
if (a == null)
return b == null;
else if (b == null)
@ -640,7 +618,7 @@ public class JobsPaymentListener implements Listener {
.getEnchantments());
}
private boolean isStackSumLegal(ItemStack a, ItemStack b) {
private static boolean isStackSumLegal(ItemStack a, ItemStack b) {
// See if we can create a new item stack with the combined elements of a and b
if (a == null || b == null)
return true;// Treat null as an empty stack
@ -654,7 +632,7 @@ public class JobsPaymentListener implements Listener {
if (event.getWhoClicked() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld()))
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Inventory inv = event.getInventory();
@ -730,7 +708,7 @@ public class JobsPaymentListener implements Listener {
if (event.getEnchanter() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEnchanter().getWorld()))
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
if (event.isCancelled())
@ -785,15 +763,15 @@ public class JobsPaymentListener implements Listener {
//disabling plugin in world
if (event.getBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
return;
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Block block = event.getBlock();
if (block == null)
return;
if (!block.hasMetadata(furnaceOwnerMetadata))
if (!block.hasMetadata(this.furnaceOwnerMetadata))
return;
List<MetadataValue> data = block.getMetadata(furnaceOwnerMetadata);
List<MetadataValue> data = block.getMetadata(this.furnaceOwnerMetadata);
if (data.isEmpty())
return;
@ -834,13 +812,13 @@ public class JobsPaymentListener implements Listener {
}
// mob spawner, no payment or experience
if (lVictim.hasMetadata(mobSpawnerMetadata) && !Jobs.getGCManager().payNearSpawner()) {
if (lVictim.hasMetadata(this.mobSpawnerMetadata) && !Jobs.getGCManager().payNearSpawner()) {
//lVictim.removeMetadata(mobSpawnerMetadata, plugin);
return;
}
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Player pDamager = null;
@ -880,7 +858,7 @@ public class JobsPaymentListener implements Listener {
return;
Double NearSpawnerMultiplier = 0.0;
if (lVictim.hasMetadata(mobSpawnerMetadata))
if (lVictim.hasMetadata(this.mobSpawnerMetadata))
NearSpawnerMultiplier = jDamager.getVipSpawnerMultiplier() * 100 - 100;
// Calulating multiplaier
@ -911,7 +889,7 @@ public class JobsPaymentListener implements Listener {
return;
if (event.getSpawnReason() == SpawnReason.SPAWNER) {
LivingEntity creature = (LivingEntity) event.getEntity();
creature.setMetadata(mobSpawnerMetadata, new FixedMetadataValue(plugin, true));
creature.setMetadata(this.mobSpawnerMetadata, new FixedMetadataValue(this.plugin, true));
}
}
@ -920,7 +898,7 @@ public class JobsPaymentListener implements Listener {
//disabling plugin in world
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
if (!event.getEntity().hasMetadata(mobSpawnerMetadata))
if (!event.getEntity().hasMetadata(this.mobSpawnerMetadata))
return;
EntityType type = event.getEntityType();
@ -955,7 +933,7 @@ public class JobsPaymentListener implements Listener {
LivingEntity animal = (LivingEntity) event.getEntity();
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
double closest = 30.0;
@ -995,7 +973,7 @@ public class JobsPaymentListener implements Listener {
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
if (!(event.getEntity() instanceof Player))
@ -1035,7 +1013,7 @@ public class JobsPaymentListener implements Listener {
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
if (!Jobs.getGCManager().isUseTntFinder())
@ -1080,8 +1058,8 @@ public class JobsPaymentListener implements Listener {
if (block == null)
continue;
if (block.getType() == Material.FURNACE && block.hasMetadata(furnaceOwnerMetadata))
block.removeMetadata(furnaceOwnerMetadata, plugin);
if (block.getType() == Material.FURNACE && block.hasMetadata(this.furnaceOwnerMetadata))
block.removeMetadata(this.furnaceOwnerMetadata, this.plugin);
if (Jobs.getGCManager().useBlockProtection)
if (block.getState().hasMetadata(BlockMetadata))
@ -1097,7 +1075,7 @@ public class JobsPaymentListener implements Listener {
//disabling plugin in world
if (event.getPlayer() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()))
return;
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
Block block = event.getClickedBlock();
@ -1108,14 +1086,14 @@ public class JobsPaymentListener implements Listener {
return;
if (block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE) {
if (block.hasMetadata(furnaceOwnerMetadata))
block.removeMetadata(furnaceOwnerMetadata, plugin);
block.setMetadata(furnaceOwnerMetadata, new FixedMetadataValue(plugin, event.getPlayer().getName()));
if (block.hasMetadata(this.furnaceOwnerMetadata))
block.removeMetadata(this.furnaceOwnerMetadata, this.plugin);
block.setMetadata(this.furnaceOwnerMetadata, new FixedMetadataValue(this.plugin, event.getPlayer().getName()));
} else if (block.getType() == Material.BREWING_STAND) {
if (block.hasMetadata(brewingOwnerMetadata))
block.removeMetadata(brewingOwnerMetadata, plugin);
block.removeMetadata(brewingOwnerMetadata, this.plugin);
block.setMetadata(brewingOwnerMetadata, new FixedMetadataValue(plugin, event.getPlayer().getName()));
block.setMetadata(brewingOwnerMetadata, new FixedMetadataValue(this.plugin, event.getPlayer().getName()));
}
}
@ -1138,7 +1116,7 @@ public class JobsPaymentListener implements Listener {
return;
// make sure plugin is enabled
if (!plugin.isEnabled())
if (!this.plugin.isEnabled())
return;
if (!player.isOnline())

View File

@ -20,7 +20,7 @@ import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
public class McMMOlistener implements Listener {
private JobsPlugin plugin;
public static boolean mcMMOPresent = false;
public boolean mcMMOPresent = false;
public McMMOlistener(JobsPlugin plugin) {
this.plugin = plugin;
@ -56,7 +56,7 @@ public class McMMOlistener implements Listener {
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR), 0.0);
}
public static double getMultiplier(Player player) {
public double getMultiplier(Player player) {
try {
if (AbilityAPI.treeFellerEnabled(player))
return Jobs.getGCManager().TreeFellerMultiplier;
@ -84,7 +84,7 @@ public class McMMOlistener implements Listener {
return 1.0;
}
public static boolean CheckmcMMO() {
public boolean CheckmcMMO() {
Plugin McMMO = Bukkit.getPluginManager().getPlugin("mcMMO");
if (McMMO != null) {
try {

View File

@ -23,7 +23,7 @@ public class PistonProtectionListener implements Listener {
}
@SuppressWarnings("deprecation")
public static boolean CheckBlock(Block block) {
public boolean CheckBlock(Block block) {
for (String BlockId : Jobs.getRestrictedBlockManager().restrictedBlocks) {
if (BlockId.equalsIgnoreCase(String.valueOf(block.getTypeId()))) {
return true;
@ -33,7 +33,7 @@ public class PistonProtectionListener implements Listener {
}
@SuppressWarnings("deprecation")
public static boolean CheckPlaceBlock(Block block) {
public boolean CheckPlaceBlock(Block block) {
for (int BlockId : Jobs.getRestrictedBlockManager().restrictedPlaceBlocksTimer) {
if (BlockId == block.getTypeId()) {
return true;
@ -43,7 +43,7 @@ public class PistonProtectionListener implements Listener {
}
@SuppressWarnings("deprecation")
public static boolean CheckVegy(Block block) {
public boolean CheckVegy(Block block) {
for (String ConfigOneBlock : Jobs.getRestrictedBlockManager().restrictedBlocksTimer) {
int ConfigPlacedBlockId = 0;
try {
@ -59,7 +59,7 @@ public class PistonProtectionListener implements Listener {
}
@SuppressWarnings("deprecation")
public static boolean checkVegybreak(Block block, Player player) {
public boolean checkVegybreak(Block block, Player player) {
for (String ConfigOneBlock : Jobs.getRestrictedBlockManager().restrictedBlocksTimer) {
int ConfigPlacedBlockId = 0;
int ConfigPlacedBlockTimer = 0;
@ -78,7 +78,7 @@ public class PistonProtectionListener implements Listener {
return false;
}
public static boolean CheckVegyTimer(Block block, int time, Player player) {
public boolean CheckVegyTimer(Block block, int time, Player player) {
long currentTime = System.currentTimeMillis();
if (!block.hasMetadata(JobsPaymentListener.VegyMetadata))
return false;