mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-06 16:27:59 +01:00
Improve connecting to database
This commit is contained in:
parent
d81bdfcc1c
commit
5a090c4242
@ -34,7 +34,6 @@ import com.gamingmesh.jobs.api.JobsPrePaymentEvent;
|
||||
import com.gamingmesh.jobs.commands.JobsCommands;
|
||||
import com.gamingmesh.jobs.config.*;
|
||||
import com.gamingmesh.jobs.container.*;
|
||||
import com.gamingmesh.jobs.dao.JobsClassLoader;
|
||||
import com.gamingmesh.jobs.dao.JobsDAO;
|
||||
import com.gamingmesh.jobs.dao.JobsDAOData;
|
||||
import com.gamingmesh.jobs.dao.JobsManager;
|
||||
@ -92,7 +91,6 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
private static Reflections reflections = null;
|
||||
|
||||
private static JobsClassLoader classLoader = null;
|
||||
private static JobsDAO dao = null;
|
||||
private static List<Job> jobs = null;
|
||||
private static Job noneJob = null;
|
||||
@ -544,16 +542,6 @@ public class Jobs extends JavaPlugin {
|
||||
usedSlots.put(job, usedSlots.get(job) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the jobs classloader
|
||||
* @return the classloader
|
||||
*/
|
||||
public static JobsClassLoader getJobsClassloader() {
|
||||
if (classLoader == null)
|
||||
classLoader = new JobsClassLoader(instance);
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the permission handler
|
||||
* @return the permission handler
|
||||
|
@ -978,7 +978,10 @@ public class PlayerManager {
|
||||
public Boost getFinalBonus(JobsPlayer player, Job prog, Entity ent, LivingEntity victim, boolean force, boolean getall) {
|
||||
Boost boost = new Boost();
|
||||
|
||||
if (player == null || !player.isOnline() || prog == null)
|
||||
if (player == null || !player.isOnline())
|
||||
return boost;
|
||||
|
||||
if (prog == null)
|
||||
return boost;
|
||||
|
||||
if (HookManager.getMcMMOManager().mcMMOPresent || HookManager.getMcMMOManager().mcMMOOverHaul)
|
||||
|
@ -64,8 +64,6 @@ public class expboost implements Cmd {
|
||||
one.addBoost(CurrencyType.EXP, rate);
|
||||
succeed = true;
|
||||
} else if (sec != 0 || min != 0 || hour != 0) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.boostadded",
|
||||
"%boost%", rate, "%jobname%", one.getName()));
|
||||
one.addBoost(CurrencyType.EXP, rate, hour, min, sec);
|
||||
succeed = true;
|
||||
}
|
||||
|
@ -64,8 +64,6 @@ public class moneyboost implements Cmd {
|
||||
one.addBoost(CurrencyType.MONEY, rate);
|
||||
succeed = true;
|
||||
} else if (sec != 0 || min != 0 || hour != 0) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.boostadded",
|
||||
"%boost%", rate, "%jobname%", one.getName()));
|
||||
one.addBoost(CurrencyType.MONEY, rate, hour, min, sec);
|
||||
succeed = true;
|
||||
}
|
||||
|
@ -64,8 +64,6 @@ public class pointboost implements Cmd {
|
||||
one.addBoost(CurrencyType.POINTS, rate);
|
||||
succeed = true;
|
||||
} else if (sec != 0 || min != 0 || hour != 0) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.boostadded",
|
||||
"%boost%", rate, "%jobname%", one.getName()));
|
||||
one.addBoost(CurrencyType.POINTS, rate, hour, min, sec);
|
||||
succeed = true;
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
package com.gamingmesh.jobs.dao;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class JobsClassLoader extends URLClassLoader {
|
||||
|
||||
public JobsClassLoader(Jobs core) {
|
||||
super(new URL[0], core.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
public void addFile(File f) throws IOException {
|
||||
addURL(f.toURI().toURL());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(URL url) {
|
||||
for (URL u : getURLs())
|
||||
if (url.sameFile(u)) return;
|
||||
|
||||
super.addURL(url);
|
||||
}
|
||||
}
|
@ -1,11 +1,8 @@
|
||||
package com.gamingmesh.jobs.dao;
|
||||
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class JobsConnectionPool {
|
||||
|
||||
private JobsConnection connection;
|
||||
@ -13,12 +10,7 @@ public class JobsConnectionPool {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public JobsConnectionPool(String driverName, String url, String username, String password)
|
||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
||||
Driver driver = (Driver) Class.forName(driverName, true, Jobs.getJobsClassloader()).newInstance();
|
||||
JobsDrivers jDriver = new JobsDrivers(driver);
|
||||
DriverManager.registerDriver(jDriver);
|
||||
|
||||
public JobsConnectionPool(String url, String username, String password) {
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
@ -456,12 +456,17 @@ public abstract class JobsDAO {
|
||||
|
||||
protected JobsDAO(Jobs plugin, String driverName, String url, String username, String password, String pr) {
|
||||
this.plugin = plugin;
|
||||
|
||||
prefix = pr;
|
||||
|
||||
try {
|
||||
pool = new JobsConnectionPool(driverName, url, username, password);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Class.forName(driverName);
|
||||
} catch (ClassNotFoundException c) {
|
||||
c.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
pool = new JobsConnectionPool(url, username, password);
|
||||
}
|
||||
|
||||
public final synchronized void setUp() throws SQLException {
|
||||
|
@ -122,6 +122,7 @@ public class JobsManager {
|
||||
data.initialize();
|
||||
return data;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user