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

mysql fixes / recalculate boost on command / disable autojoin if needed

This commit is contained in:
Zrips 2016-06-15 13:27:43 +03:00
parent a8466e5e2f
commit 445e30e407
10 changed files with 214 additions and 132 deletions

View File

@ -571,9 +571,12 @@ public class PlayerManager {
return false;
}
public double GetBoostInPerc(JobsPlayer player, Job job, BoostType type) {
double Boost = player.getBoost(job.getName(), type) * 100.0 - 100.0;
return GetBoostInPerc(player, job, type, false);
}
public double GetBoostInPerc(JobsPlayer player, Job job, BoostType type, boolean force) {
double Boost = player.getBoost(job.getName(), type, force) * 100.0 - 100.0;
return Boost;
}
@ -713,6 +716,8 @@ public class PlayerManager {
return;
if (player.isOp())
return;
if (!Jobs.getGCManager().AutoJobJoinUse)
return;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
if (!player.isOnline())
@ -720,20 +725,18 @@ public class PlayerManager {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null)
return;
if (player.hasPermission("jobs.*"))
return;
int confMaxJobs = Jobs.getGCManager().getMaxJobs();
for (Job one : Jobs.getJobs()) {
if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots())
continue;
short PlayerMaxJobs = (short) jPlayer.getJobProgression().size();
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(player, PlayerMaxJobs))
break;
if (jPlayer.isInJob(one))
continue;
if (Perm.hasPermission(player, "jobs.autojoin." + one.getName().toLowerCase()))
if (player.hasPermission("jobs.autojoin." + one.getName().toLowerCase()))
Jobs.getPlayerManager().joinJob(jPlayer, one);
}
return;

View File

@ -102,6 +102,7 @@ public class SignUtil {
int timelapse = 1;
for (com.gamingmesh.jobs.Signs.Sign one : Copy) {
String SignJobName = one.GetJobName();
if (JobName.equalsIgnoreCase(SignJobName)) {
String SignsWorld = one.GetWorld();
double SignsX = one.GetX();
@ -198,6 +199,7 @@ public class SignUtil {
public void UpdateHead(final org.bukkit.block.Sign sign, final String Playername, final int timelapse) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@SuppressWarnings("deprecation")
public void run() {
org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData();

View File

@ -41,11 +41,11 @@ public class bonus implements Cmd {
return false;
// sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", job.getChatColor() + job.getName()));
double PMoneyBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.MONEY);
double PMoneyBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.MONEY, true);
PMoneyBoost = (int) (PMoneyBoost * 100D) / 100D;
double PPointBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.POINTS);
double PPointBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.POINTS, true);
PPointBoost = (int) (PPointBoost * 100D) / 100D;
double PExpBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.EXP);
double PExpBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.EXP, true);
PExpBoost = (int) (PExpBoost * 100D) / 100D;
double GMoneyBoost = job.getMoneyBoost() * 100.0 - 100.0;

View File

@ -125,7 +125,9 @@ public class GeneralConfigManager {
public boolean UseTaxes;
public boolean TransferToServerAccount;
public boolean TakeFromPlayersPayment;
public int AutoJobJoinDelay;
public boolean AutoJobJoinUse;
//BossBar
public boolean BossBarEnabled;
@ -418,12 +420,15 @@ public class GeneralConfigManager {
MultiServerCompatability = c.get("MultiServerCompatability", false);
if (MultiServerCompatability)
saveOnDisconnect = true;
c.getW().addComment("Optimizations.AutoJobJoinDelay", "Delay in seconds to perform auto join job if used after player joins server",
c.getW().addComment("Optimizations.AutoJobJoin.Use", "Use or not auto join jobs feature",
"If you are not using auto join feature, keep it disabled");
AutoJobJoinUse = c.get("Optimizations.AutoJobJoin.Use", false);
c.getW().addComment("Optimizations.AutoJobJoin.Delay", "Delay in seconds to perform auto join job if used after player joins server",
"If you using offline server, try to keep it slightly more than your login plugin gives time to enter password",
"For player to auto join job add permission node jobs.autojoin.[jobname]",
"Op players are ignored");
AutoJobJoinDelay = c.get("Optimizations.AutoJobJoinDelay", 15);
AutoJobJoinDelay = c.get("Optimizations.AutoJobJoin.Delay", 15);
c.getW().addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files",
"This will eliminate small lag spikes when request is being send to mojangs servers for offline players data",

View File

@ -209,6 +209,10 @@ public class JobsPlayer {
* @return the Boost
*/
public double getBoost(String JobName, BoostType type) {
return getBoost(JobName, type, false);
}
public double getBoost(String JobName, BoostType type, boolean force) {
if (this.player == null)
this.player = Bukkit.getPlayer(this.OffPlayer.getUniqueId());
@ -225,7 +229,7 @@ public class JobsPlayer {
for (BoostCounter counter : counterList) {
if (counter.getType() != type)
continue;
if (time - counter.getTime() > 1000 * 60) {
if (force || time - counter.getTime() > 1000 * 60) {
Boost = getPlayerBoost(JobName, type);
counter.setBoost(Boost);
counter.setTime(time);
@ -245,13 +249,11 @@ public class JobsPlayer {
counterList.add(new BoostCounter(type, Boost, time));
boostCounter.put(JobName, counterList);
return Boost;
}
private Double getPlayerBoost(String JobName, BoostType type) {
double Boost = 1.0;
Debug.D("recalculating for " + JobName);
if (Perm.hasPermission(player, "jobs.boost." + JobName + "." + type.getName().toLowerCase()) ||
Perm.hasPermission(player, "jobs.boost." + JobName + ".all") ||
Perm.hasPermission(player, "jobs.boost.all.all") ||

View File

@ -527,35 +527,97 @@ public class JobsDAOMySQL extends JobsDAO {
+ "points` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `totalpoints` double, `currentpoints` double);");
} catch (SQLException e) {
}
// dropping 2 columns
PreparedStatement prestLogTemp = null;
ResultSet rsLogTemp = null;
try {
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
rsLogTemp = prestLogTemp.executeQuery();
while (rsLogTemp.next()) {
rsLogTemp.getInt("userid");
rsLogTemp.getLong("time");
rsLogTemp.getString("action");
rsLogTemp.getString("itemname");
rsLogTemp.getInt("count");
rsLogTemp.getDouble("money");
rsLogTemp.getDouble("exp");
break;
}
} catch (Exception ex) {
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "log` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
} catch (Exception e) {
}
} finally {
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
}
if (rows == 0) {
HashMap<String, String> tempMap = new HashMap<String, String>();
PreparedStatement prest = null;
PreparedStatement prestJobs = null;
try {
prest = conn.prepareStatement("SELECT DISTINCT(player_uuid),username FROM " + getPrefix() + "jobs;");
ResultSet res = prest.executeQuery();
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"));
}
} catch (Exception e) {
} finally {
if (prestJobs != null) {
try {
prestJobs.close();
} catch (SQLException e) {
}
}
}
PreparedStatement prestArchive = null;
try {
prest = conn.prepareStatement("SELECT DISTINCT(player_uuid),username FROM " + getPrefix() + "archive;");
ResultSet res = prest.executeQuery();
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"));
}
} catch (Exception e) {
} finally {
if (prestArchive != null) {
try {
prestArchive.close();
} catch (SQLException e) {
}
}
}
PreparedStatement prestLog = null;
try {
prest = conn.prepareStatement("SELECT DISTINCT(player_uuid),username FROM " + getPrefix() + "log;");
ResultSet res = prest.executeQuery();
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"));
}
} catch (Exception e) {
} finally {
if (prestLog != null) {
try {
prestLog.close();
} catch (SQLException e) {
}
}
}
try {
@ -565,31 +627,47 @@ public class JobsDAOMySQL extends JobsDAO {
e.printStackTrace();
}
PreparedStatement prestUsers = null;
try {
prest = conn.prepareStatement("INSERT INTO `" + getPrefix() + "users` (`player_uuid`, `username`) VALUES (?, ?);");
prestUsers = conn.prepareStatement("INSERT INTO `" + getPrefix() + "users` (`player_uuid`, `username`) VALUES (?, ?);");
conn.setAutoCommit(false);
for (Entry<String, String> users : tempMap.entrySet()) {
prest.setString(1, users.getKey());
prest.setString(2, users.getValue());
prest.addBatch();
prestUsers.setString(1, users.getKey());
prestUsers.setString(2, users.getValue());
prestUsers.addBatch();
}
prest.executeBatch();
prestUsers.executeBatch();
conn.commit();
conn.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prestUsers != null) {
try {
prestUsers.close();
} catch (SQLException e) {
}
}
}
HashMap<String, PlayerInfo> tempPlayerMap = new HashMap<String, PlayerInfo>();
PreparedStatement prestUsersT = null;
try {
prest = conn.prepareStatement("SELECT * FROM " + getPrefix() + "users;");
ResultSet res = prest.executeQuery();
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")));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prestUsersT != null) {
try {
prestUsersT.close();
} catch (SQLException e) {
}
}
}
// Modifying jobs main table
@ -597,19 +675,27 @@ public class JobsDAOMySQL extends JobsDAO {
executeSQL("ALTER TABLE `" + getPrefix() + "jobs` ADD COLUMN `userid` int;");
} catch (Exception e) {
}
PreparedStatement prestJobsT = null;
try {
prest = conn.prepareStatement("UPDATE `" + getPrefix() + "jobs` SET `userid` = ? WHERE `player_uuid` = ?;");
prestJobsT = conn.prepareStatement("UPDATE `" + getPrefix() + "jobs` SET `userid` = ? WHERE `player_uuid` = ?;");
conn.setAutoCommit(false);
for (Entry<String, PlayerInfo> users : tempPlayerMap.entrySet()) {
prest.setInt(1, users.getValue().getID());
prest.setString(2, users.getKey());
prest.addBatch();
prestJobsT.setInt(1, users.getValue().getID());
prestJobsT.setString(2, users.getKey());
prestJobsT.addBatch();
}
prest.executeBatch();
prestJobsT.executeBatch();
conn.commit();
conn.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prestJobsT != null) {
try {
prestJobsT.close();
} catch (SQLException e) {
}
}
}
try {
@ -621,53 +707,32 @@ public class JobsDAOMySQL extends JobsDAO {
executeSQL("ALTER TABLE `" + getPrefix() + "archive` ADD COLUMN `userid` int;");
} catch (Exception e) {
}
try {
prest = conn.prepareStatement("UPDATE `" + getPrefix() + "archive` SET `userid` = ? WHERE `player_uuid` = ?;");
conn.setAutoCommit(false);
for (Entry<String, PlayerInfo> users : tempPlayerMap.entrySet()) {
prest.setInt(1, users.getValue().getID());
prest.setString(2, users.getKey());
prest.addBatch();
}
prest.executeBatch();
conn.commit();
conn.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
}
PreparedStatement prestArchiveT = null;
try {
executeSQL("ALTER TABLE `" + getPrefix() + "archive` DROP COLUMN `player_uuid`, DROP COLUMN `username`;");
} catch (Exception e) {
}
// Modifying jobs log table
try {
executeSQL("ALTER TABLE `" + getPrefix() + "log` ADD COLUMN `userid` int;");
} catch (Exception e) {
}
try {
prest = conn.prepareStatement("UPDATE `" + getPrefix() + "log` SET `userid` = ? WHERE `player_uuid` = ?;");
prestArchiveT = conn.prepareStatement("UPDATE `" + getPrefix() + "archive` SET `userid` = ? WHERE `player_uuid` = ?;");
conn.setAutoCommit(false);
for (Entry<String, PlayerInfo> users : tempPlayerMap.entrySet()) {
prest.setInt(1, users.getValue().getID());
prest.setString(2, users.getKey());
prest.addBatch();
prestArchiveT.setInt(1, users.getValue().getID());
prestArchiveT.setString(2, users.getKey());
prestArchiveT.addBatch();
}
prest.executeBatch();
prestArchiveT.executeBatch();
conn.commit();
conn.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (prest != null) {
if (prestArchiveT != null) {
try {
prest.close();
prestArchiveT.close();
} catch (SQLException e) {
}
}
}
try {
executeSQL("ALTER TABLE `" + getPrefix() + "log` DROP COLUMN `player_uuid`, DROP COLUMN `username`;");
executeSQL("ALTER TABLE `" + getPrefix() + "archive` DROP COLUMN `player_uuid`, DROP COLUMN `username`;");
} catch (Exception e) {
}

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 {
@ -504,7 +503,6 @@ public class JobsDAOSQLite extends JobsDAO {
@Override
protected synchronized void checkUpdate9() throws SQLException {
Debug.D("checkling 9");
JobsConnection conn = getConnection();
if (conn == null) {
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to SQLite!");
@ -528,14 +526,55 @@ public class JobsDAOSQLite extends JobsDAO {
}
}
}
// Create new points table
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "points` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `totalpoints` double, `currentpoints` double);");
} catch (Exception e) {
}
// checking log table, recreating if old version present
PreparedStatement prestLogTemp = null;
ResultSet rsLogTemp = null;
try {
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
rsLogTemp = prestLogTemp.executeQuery();
while (rsLogTemp.next()) {
rsLogTemp.getInt("userid");
rsLogTemp.getLong("time");
rsLogTemp.getString("action");
rsLogTemp.getString("itemname");
rsLogTemp.getInt("count");
rsLogTemp.getDouble("money");
rsLogTemp.getDouble("exp");
break;
}
} catch (Exception ex) {
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "log`;");
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "log_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
} catch (Exception e) {
e.printStackTrace();
}
} finally {
try {
if (rsLogTemp != null)
rsLogTemp.close();
if (prestLogTemp != null)
prestLogTemp.close();
} catch (Exception e) {
}
}
if (rows != 0)
return;
@ -712,26 +751,33 @@ public class JobsDAOSQLite extends JobsDAO {
} catch (Exception e) {
}
PreparedStatement pstArchive = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "archive`;");
ResultSet rsArchive = pstArchive.executeQuery();
PreparedStatement pstArchive = null;
ResultSet rsArchive = null;
PreparedStatement insertArchive = null;
while (rsArchive.next()) {
String uuid = UUIDUtil.fromBytes(rsArchive.getBytes("player_uuid")).toString();
if (uuid != null) {
insertArchive = conn.prepareStatement("INSERT INTO `" + getPrefix() + "archive_temp` (`userid`, `job`, `experience`, `level`) VALUES (?, ?, ?, ?);");
insertArchive.setInt(1, rsArchive.getInt("userid"));
insertArchive.setString(2, rsArchive.getString("job"));
insertArchive.setInt(3, rsArchive.getInt("experience"));
insertArchive.setInt(4, rsArchive.getInt("level"));
insertArchive.execute();
try {
pstArchive = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "archive`;");
rsArchive = pstArchive.executeQuery();
while (rsArchive.next()) {
String uuid = UUIDUtil.fromBytes(rsArchive.getBytes("player_uuid")).toString();
if (uuid != null) {
insertArchive = conn.prepareStatement("INSERT INTO `" + getPrefix() + "archive_temp` (`userid`, `job`, `experience`, `level`) VALUES (?, ?, ?, ?);");
insertArchive.setInt(1, rsArchive.getInt("userid"));
insertArchive.setString(2, rsArchive.getString("job"));
insertArchive.setInt(3, rsArchive.getInt("experience"));
insertArchive.setInt(4, rsArchive.getInt("level"));
insertArchive.execute();
}
}
} catch (Exception e) {
} finally {
if (rsArchive != null)
rsArchive.close();
if (insertArchive != null)
insertArchive.close();
if (pstArchive != null)
pstArchive.close();
}
if (rsArchive != null)
rsArchive.close();
if (insertArchive != null)
insertArchive.close();
if (pstArchive != null)
pstArchive.close();
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "archive`;");
try {
executeSQL("ALTER TABLE `" + getPrefix() + "archive_temp` RENAME TO `" + getPrefix() + "archive`;");
@ -760,45 +806,6 @@ public class JobsDAOSQLite extends JobsDAO {
}
}
// dropping 2 columns
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "log_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
} catch (Exception e) {
e.printStackTrace();
}
PreparedStatement prestLogT = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
ResultSet rsLog = prestLogT.executeQuery();
PreparedStatement insertLog = null;
while (rsLog.next()) {
String uuid = UUIDUtil.fromBytes(rsLog.getBytes("player_uuid")).toString();
if (uuid != null) {
insertLog = conn.prepareStatement("INSERT INTO `" + getPrefix()
+ "log_temp` (`userid`, `time`, `action`, `itemname`, `count`, `money`, `exp`) VALUES (?, ?, ?, ?, ?, ?, ?);");
insertLog.setInt(1, rsLog.getInt("userid"));
insertLog.setLong(2, rsLog.getLong("time"));
insertLog.setString(3, rsLog.getString("action"));
insertLog.setString(4, rsLog.getString("itemname"));
insertLog.setInt(5, rsLog.getInt("count"));
insertLog.setDouble(6, rsLog.getDouble("money"));
insertLog.setDouble(7, rsLog.getDouble("exp"));
insertLog.execute();
}
}
rsLog.close();
if (insertLog != null)
insertLog.close();
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "log`;");
try {
executeSQL("ALTER TABLE `" + getPrefix() + "log_temp` RENAME TO `" + getPrefix() + "log`;");
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean createDefaultExploreBase() {

View File

@ -426,10 +426,8 @@ public class JobsListener implements Listener {
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (!plugin.isEnabled())
return;
if (!Jobs.getGCManager().getModifyChat())
return;
Player player = event.getPlayer();
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);

View File

@ -5,11 +5,11 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class Debug {
public static void D(String message) {
public static void D(Object message) {
Player player = Bukkit.getPlayer("Zrips");
if (player == null)
return;
player.sendMessage(ChatColor.DARK_GRAY + "[Jobs Debug] " + ChatColor.DARK_AQUA + ChatColor.translateAlternateColorCodes('&', message));
player.sendMessage(ChatColor.DARK_GRAY + "[Jobs Debug] " + ChatColor.DARK_AQUA + ChatColor.translateAlternateColorCodes('&', String.valueOf(message)));
return;
}
}

View File

@ -1,7 +1,7 @@
name: Jobs
description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin
version: 3.4.5
version: 3.4.7
author: phrstbrn
depend: [Vault]
softdepend: [CoreProtect, MythicMobs, McMMO]