Only save the prisoners if they were changed, add that flag.
This commit is contained in:
parent
f3c2772a87
commit
3912dbfabc
@ -19,6 +19,7 @@ Beta 2 Changes
|
|||||||
* Added `/jail time` for easy access to adding/subtracting time - [Bukkit Dev Ticket #432](http://dev.bukkit.org/bukkit-plugins/jail/tickets/432/)
|
* Added `/jail time` for easy access to adding/subtracting time - [Bukkit Dev Ticket #432](http://dev.bukkit.org/bukkit-plugins/jail/tickets/432/)
|
||||||
* Added `/togglejaildebug` for easily toggling the debugging state, enable if you have a problem and want to send me information
|
* Added `/togglejaildebug` for easily toggling the debugging state, enable if you have a problem and want to send me information
|
||||||
* Added some caching of online prisoners and where they're located at, this improves performance on servers with 500+ prisoners jailed
|
* Added some caching of online prisoners and where they're located at, this improves performance on servers with 500+ prisoners jailed
|
||||||
|
* Only updating prisoners in the database if they were changed, this should help improve saving speed
|
||||||
|
|
||||||
Beta 1 Changes
|
Beta 1 Changes
|
||||||
===
|
===
|
||||||
@ -44,7 +45,6 @@ Changes
|
|||||||
|
|
||||||
ToDo
|
ToDo
|
||||||
===
|
===
|
||||||
* Only save prisoners that have been edited, aka a flag on the prisoners which is "have they changed" and change that when a function is called that changes the prisoner so we don't save prisoners that haven't changed
|
|
||||||
* When calculating the reducing of time, make it async and all the calls it does be scheduled
|
* When calculating the reducing of time, make it async and all the calls it does be scheduled
|
||||||
* Jail set
|
* Jail set
|
||||||
* Jail vote
|
* Jail vote
|
||||||
|
@ -470,6 +470,7 @@ public class JailIO {
|
|||||||
p.setArmor(new String(ar.getBytes(1, (int)ar.length())));
|
p.setArmor(new String(ar.getBytes(1, (int)ar.length())));
|
||||||
p.setPreviousPosition(set.getString("previousLocation"));
|
p.setPreviousPosition(set.getString("previousLocation"));
|
||||||
p.setPreviousGameMode(set.getString("previousGameMode"));
|
p.setPreviousGameMode(set.getString("previousGameMode"));
|
||||||
|
p.setChanged(false);//Since we just loaded the prisoner, we really don't need to save them.
|
||||||
|
|
||||||
if(cellname == null || cellname.isEmpty()) {
|
if(cellname == null || cellname.isEmpty()) {
|
||||||
j.addPrisoner(p);
|
j.addPrisoner(p);
|
||||||
@ -608,6 +609,7 @@ public class JailIO {
|
|||||||
p.setPreviousGameMode(flat.getString(cellNode + "prisoner.previousGameMode"));
|
p.setPreviousGameMode(flat.getString(cellNode + "prisoner.previousGameMode"));
|
||||||
p.setInventory(flat.getString(cellNode + "prisoner.inventory", ""));
|
p.setInventory(flat.getString(cellNode + "prisoner.inventory", ""));
|
||||||
p.setArmor(flat.getString(cellNode + "prisoner.armor", ""));
|
p.setArmor(flat.getString(cellNode + "prisoner.armor", ""));
|
||||||
|
p.setChanged(false);//Since we just loaded the prisoner, we really don't need to save them.
|
||||||
c.setPrisoner(p);
|
c.setPrisoner(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,6 +635,7 @@ public class JailIO {
|
|||||||
pris.setPreviousGameMode(flat.getString(pNode + "previousGameMode"));
|
pris.setPreviousGameMode(flat.getString(pNode + "previousGameMode"));
|
||||||
pris.setInventory(flat.getString(pNode + "inventory", ""));
|
pris.setInventory(flat.getString(pNode + "inventory", ""));
|
||||||
pris.setArmor(flat.getString(pNode + "armor", ""));
|
pris.setArmor(flat.getString(pNode + "armor", ""));
|
||||||
|
pris.setChanged(false);//Since we just loaded the prisoner, we really don't need to save them.
|
||||||
j.addPrisoner(pris);
|
j.addPrisoner(pris);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,7 +714,7 @@ public class JailIO {
|
|||||||
if(con == null) this.prepareStorage(false);
|
if(con == null) this.prepareStorage(false);
|
||||||
|
|
||||||
for(Cell c : j.getCells()) {
|
for(Cell c : j.getCells()) {
|
||||||
if(c.hasPrisoner()) {
|
if(c.hasPrisoner() && c.getPrisoner().wasChanged()) {
|
||||||
Prisoner p = c.getPrisoner();
|
Prisoner p = c.getPrisoner();
|
||||||
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`uuid`, `name`, `jail`, `cell`, `muted`, `time`,"
|
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`uuid`, `name`, `jail`, `cell`, `muted`, `time`,"
|
||||||
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`)"
|
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`)"
|
||||||
@ -733,6 +736,8 @@ public class JailIO {
|
|||||||
|
|
||||||
pPS.executeUpdate();
|
pPS.executeUpdate();
|
||||||
pPS.close();
|
pPS.close();
|
||||||
|
|
||||||
|
p.setChanged(false);//Since we just saved the prisoner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -745,6 +750,7 @@ public class JailIO {
|
|||||||
if(con == null) this.prepareStorage(false);
|
if(con == null) this.prepareStorage(false);
|
||||||
|
|
||||||
for(Prisoner p : j.getPrisonersNotInCells().values()) {
|
for(Prisoner p : j.getPrisonersNotInCells().values()) {
|
||||||
|
if(p.wasChanged()) {
|
||||||
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`uuid`, `name`, `jail`, `cell`, `muted`, `time`,"
|
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`uuid`, `name`, `jail`, `cell`, `muted`, `time`,"
|
||||||
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||||
pPS.setString(1, p.getUUID().toString());
|
pPS.setString(1, p.getUUID().toString());
|
||||||
@ -764,6 +770,8 @@ public class JailIO {
|
|||||||
|
|
||||||
pPS.executeUpdate();
|
pPS.executeUpdate();
|
||||||
pPS.close();
|
pPS.close();
|
||||||
|
p.setChanged(false);//Since we just saved the prisoner
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -12,11 +12,11 @@ import org.bukkit.Location;
|
|||||||
*
|
*
|
||||||
* @author graywolf336
|
* @author graywolf336
|
||||||
* @since 2.x.x
|
* @since 2.x.x
|
||||||
* @version 3.0.1
|
* @version 3.0.2
|
||||||
*/
|
*/
|
||||||
public class Prisoner {
|
public class Prisoner {
|
||||||
private String uuid, name, jailer, reason, inventory, armor;
|
private String uuid, name, jailer, reason, inventory, armor;
|
||||||
private boolean muted, offlinePending, teleporting, toBeTransferred;
|
private boolean muted, offlinePending, teleporting, toBeTransferred, changed;
|
||||||
private long time, afk;
|
private long time, afk;
|
||||||
private Location previousPosition;
|
private Location previousPosition;
|
||||||
private GameMode previousGameMode;
|
private GameMode previousGameMode;
|
||||||
@ -46,6 +46,7 @@ public class Prisoner {
|
|||||||
this.inventory = "";
|
this.inventory = "";
|
||||||
this.armor = "";
|
this.armor = "";
|
||||||
this.afk = 0;
|
this.afk = 0;
|
||||||
|
this.changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the UUID of the prisoner. */
|
/** Returns the UUID of the prisoner. */
|
||||||
@ -61,6 +62,7 @@ public class Prisoner {
|
|||||||
/** Sets the name of this prisoner. */
|
/** Sets the name of this prisoner. */
|
||||||
public String setLastKnownName(String username) {
|
public String setLastKnownName(String username) {
|
||||||
this.name = username;
|
this.name = username;
|
||||||
|
this.changed = true;
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +71,16 @@ public class Prisoner {
|
|||||||
return this.reason;
|
return this.reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the reason this player was jailed for. */
|
/**
|
||||||
public void setReason(String reason) {
|
* Sets the reason this player was jailed for.
|
||||||
|
*
|
||||||
|
* @param reason the player was jailed.
|
||||||
|
* @return the reason the player was jailed, what we have stored about them.
|
||||||
|
*/
|
||||||
|
public String setReason(String reason) {
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
|
this.changed = true;
|
||||||
|
return this.reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the person who jailed this prisoner. */
|
/** Gets the person who jailed this prisoner. */
|
||||||
@ -82,6 +91,7 @@ public class Prisoner {
|
|||||||
/** Sets the person who jailed this prisoner. */
|
/** Sets the person who jailed this prisoner. */
|
||||||
public void setJailer(String jailer) {
|
public void setJailer(String jailer) {
|
||||||
this.jailer = jailer;
|
this.jailer = jailer;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets whether the prisoner is muted or not. */
|
/** Gets whether the prisoner is muted or not. */
|
||||||
@ -92,6 +102,7 @@ public class Prisoner {
|
|||||||
/** Sets whether the prisoner is muted or not. */
|
/** Sets whether the prisoner is muted or not. */
|
||||||
public void setMuted(boolean muted) {
|
public void setMuted(boolean muted) {
|
||||||
this.muted = muted;
|
this.muted = muted;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the remaining time the prisoner has. */
|
/** Gets the remaining time the prisoner has. */
|
||||||
@ -116,6 +127,7 @@ public class Prisoner {
|
|||||||
*/
|
*/
|
||||||
public void setRemainingTime(long time) {
|
public void setRemainingTime(long time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,6 +138,7 @@ public class Prisoner {
|
|||||||
*/
|
*/
|
||||||
public long addTime(long time) {
|
public long addTime(long time) {
|
||||||
this.time += time;
|
this.time += time;
|
||||||
|
this.changed = true;
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +150,7 @@ public class Prisoner {
|
|||||||
*/
|
*/
|
||||||
public long subtractTime(long time) {
|
public long subtractTime(long time) {
|
||||||
this.time -= time;
|
this.time -= time;
|
||||||
|
this.changed = true;
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,6 +162,7 @@ public class Prisoner {
|
|||||||
/** Sets whether the player is offline or not. */
|
/** Sets whether the player is offline or not. */
|
||||||
public void setOfflinePending(boolean offline) {
|
public void setOfflinePending(boolean offline) {
|
||||||
this.offlinePending = offline;
|
this.offlinePending = offline;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets whether the player is being teleported or not. */
|
/** Gets whether the player is being teleported or not. */
|
||||||
@ -168,6 +183,7 @@ public class Prisoner {
|
|||||||
/** Sets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
/** Sets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
||||||
public void setToBeTransferred(boolean transferred) {
|
public void setToBeTransferred(boolean transferred) {
|
||||||
this.toBeTransferred = transferred;
|
this.toBeTransferred = transferred;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the previous location of this player, can be null. */
|
/** Gets the previous location of this player, can be null. */
|
||||||
@ -197,6 +213,7 @@ public class Prisoner {
|
|||||||
if(location == null) return;
|
if(location == null) return;
|
||||||
if(location.isEmpty()) return;
|
if(location.isEmpty()) return;
|
||||||
|
|
||||||
|
this.changed = true;
|
||||||
String[] s = location.split(",");
|
String[] s = location.split(",");
|
||||||
this.previousPosition = new Location(Bukkit.getWorld(s[0]),
|
this.previousPosition = new Location(Bukkit.getWorld(s[0]),
|
||||||
Double.valueOf(s[1]),
|
Double.valueOf(s[1]),
|
||||||
@ -214,6 +231,7 @@ public class Prisoner {
|
|||||||
/** Sets the previous gamemode of this player. */
|
/** Sets the previous gamemode of this player. */
|
||||||
public void setPreviousGameMode(GameMode previous) {
|
public void setPreviousGameMode(GameMode previous) {
|
||||||
this.previousGameMode = previous;
|
this.previousGameMode = previous;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the previous gamemode of this player based upon the provided string. */
|
/** Sets the previous gamemode of this player based upon the provided string. */
|
||||||
@ -221,6 +239,7 @@ public class Prisoner {
|
|||||||
if(previous == null) return;
|
if(previous == null) return;
|
||||||
else if(previous.isEmpty()) return;
|
else if(previous.isEmpty()) return;
|
||||||
else this.previousGameMode = GameMode.valueOf(previous);
|
else this.previousGameMode = GameMode.valueOf(previous);
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the inventory string for this player, it is encoded in Base64 string. */
|
/** Gets the inventory string for this player, it is encoded in Base64 string. */
|
||||||
@ -231,6 +250,7 @@ public class Prisoner {
|
|||||||
/** Sets the inventory Base64 string. */
|
/** Sets the inventory Base64 string. */
|
||||||
public void setInventory(String inventory) {
|
public void setInventory(String inventory) {
|
||||||
this.inventory = inventory;
|
this.inventory = inventory;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the armor content, encoded in Base64 string. */
|
/** Gets the armor content, encoded in Base64 string. */
|
||||||
@ -241,6 +261,7 @@ public class Prisoner {
|
|||||||
/** Sets the armor inventory Base64 string. */
|
/** Sets the armor inventory Base64 string. */
|
||||||
public void setArmor(String armor) {
|
public void setArmor(String armor) {
|
||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the time, in milliseconds, this prisoner has been afk. */
|
/** Gets the time, in milliseconds, this prisoner has been afk. */
|
||||||
@ -252,4 +273,15 @@ public class Prisoner {
|
|||||||
public void setAFKTime(long time) {
|
public void setAFKTime(long time) {
|
||||||
this.afk = time;
|
this.afk = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if the prisoner was changed or not. */
|
||||||
|
public boolean wasChanged() {
|
||||||
|
return this.changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets whether the prisoner was changed or not. */
|
||||||
|
public boolean setChanged(boolean change) {
|
||||||
|
this.changed = change;
|
||||||
|
return this.changed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user