java - How to load playerdata correctly and avoid it from getting the old data -
i have problem bungeecord server network.
basicly problem have stated in title when load playerdata mysql database loads old data instead of new playerdata saved on playerquitevent
(playerkickevent
) , reloaded instantly on playerjoinevent
in server.
here steps can reproduce problem:
- setup bungeecord network 2 servers , sql methods:
- on
playerquitevent
(player switch server) store data mysql database(example: rank: vip)
problem: since data doesn't update instantly causes load old data before player quit event
- on
playerjoinevent
(player switched server) load data stored on playerquitevent
my code: save method:
public void savefields(string uuid, map<string, string> fields) { (final string s : fields.keyset()) { if (s.equalsignorecase("uuid")) continue; if (s.equalsignorecase("id")) continue; createcolumn(database + "_data", s); sendupdatequery("update " + database + "_data set " + s + "='" + fields.get(s) + "' uuid='" + uuid + "'"); } }
load method:
public map<string, string> getfields(string uuid) { map<string, string> map = new hashmap<>(); resultset rs = null; preparedstatement st = null; try { st = con.preparestatement("select * " + database + "_data uuid=?"); st.setstring(1, uuid); rs = st.executequery(); (string colum : getcolumns(rs)) { rs.first(); if (rs.getrow() != 0) { map.put(colum, rs.getstring(colum)); } } } catch (sqlexception e) { e.printstacktrace(); } { closeresources(rs, st); } closeresources(rs, st); return map; }
this behaviour known race condition. mysql bad database , therefore has problem. workaround it, have query reasonable relay in second event when player relogs, or force player wait before relogging (which approach taken minigame proxy servers), effective ditch mysql , use proper database.
Comments
Post a Comment