1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Check for null player when he is logging off

This commit is contained in:
Zrips 2017-01-10 15:01:44 +02:00
parent f5452e2e41
commit fcbc42e043
5 changed files with 38 additions and 54 deletions

View File

@ -144,18 +144,18 @@ public class PlayerManager {
*/
public void playerQuit(Player player) {
JobsPlayer jPlayer = this.players.remove(player.getName().toLowerCase());
if (jPlayer == null)
jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null)
return;
playersCache.put(player.getName().toLowerCase(), jPlayer);
if (Jobs.getGCManager().saveOnDisconnect()) {
if (jPlayer != null) {
jPlayer.save();
jPlayer.onDisconnect();
}
} else {
if (jPlayer != null) {
jPlayer.onDisconnect();
}
}
}
/**
* Save all the information of all of the players in the game

View File

@ -23,14 +23,11 @@ import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
public class Job {
// job info

View File

@ -391,19 +391,22 @@ public abstract class JobsDAO {
JobsConnection conn = getConnection();
if (conn == null)
return;
PreparedStatement prest = null;
PreparedStatement prest2 = null;
try {
prest = conn.prepareStatement("DELETE FROM `" + prefix + "limits` WHERE `userid` = ?;");
prest.setInt(1, jPlayer.getUserId());
prest.execute();
prest2 = conn.prepareStatement("DELETE FROM `" + prefix + "limits` WHERE `userid` = ?;");
prest2.setInt(1, jPlayer.getUserId());
prest2.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(prest);
close(prest2);
}
PreparedStatement prest = null;
try {
PaymentData limit = jPlayer.getPaymentLimit();
prest = conn.prepareStatement("INSERT INTO `" + prefix + "limits` (`userid`, `type`, `collected`, `started`) VALUES (?, ?, ?, ?);");
conn.setAutoCommit(false);
for (CurrencyType type : CurrencyType.values()) {
if (limit == null)
continue;
@ -412,14 +415,16 @@ public abstract class JobsDAO {
if (limit.GetLeftTime(type) < 0)
continue;
prest = conn.prepareStatement("INSERT INTO `" + prefix + "limits` (`userid`, `type`, `collected`, `started`) VALUES (?, ?, ?, ?);");
prest.setInt(1, jPlayer.getUserId());
prest.setString(2, type.getName());
prest.setDouble(3, limit.GetAmount(type));
prest.setLong(4, limit.GetTime(type));
prest.execute();
prest.addBatch();
}
} catch (SQLException e) {
prest.executeBatch();
conn.commit();
conn.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
} finally {
close(prest);

View File

@ -310,9 +310,7 @@ public class JobsDAOMySQL extends JobsDAO {
if (insert != null)
insert.close();
if (rs != null)
rs.close();
if (pst1 != null)
pst1.close();
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "jobs`;");
@ -374,9 +372,7 @@ public class JobsDAOMySQL extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
if (rs1 != null)
rs1.close();
if (pst11 != null)
pst11.close();
if (insert1 != null)
insert1.close();
@ -447,9 +443,7 @@ public class JobsDAOMySQL extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
if (pst111 != null)
pst111.close();
if (rs11 != null)
rs11.close();
if (insert11 != null)
insert11.close();

View File

@ -22,14 +22,8 @@ import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.PlayerInfo;
import com.gamingmesh.jobs.stuff.UUIDUtil;
@ -318,9 +312,7 @@ public class JobsDAOSQLite extends JobsDAO {
conn.commit();
conn.setAutoCommit(true);
if (rs != null)
rs.close();
if (pst1 != null)
pst1.close();
if (insert != null)
insert.close();
@ -389,9 +381,8 @@ public class JobsDAOSQLite extends JobsDAO {
insert1.executeBatch();
conn.commit();
conn.setAutoCommit(true);
if (rs1 != null)
rs1.close();
if (pst11 != null)
pst11.close();
if (insert1 != null)
insert1.close();
@ -464,9 +455,8 @@ public class JobsDAOSQLite extends JobsDAO {
insert11.executeBatch();
conn.commit();
conn.setAutoCommit(true);
if (rs11 != null)
rs11.close();
if (pst111 != null)
pst111.close();
if (insert11 != null)
insert11.close();
@ -685,9 +675,7 @@ public class JobsDAOSQLite extends JobsDAO {
insert11.execute();
}
}
if (rs11 != null)
rs11.close();
if (pst111 != null)
pst111.close();
if (insert11 != null)
insert11.close();