Performance changes to get better performance on the move protection.

We now get the cache object inside the move event and get all the other
objects from that. The reason for this is so that we don't have to then
loop through all the prisoners in a jail again to get one prisoner, just
get it from the cache object.
This commit is contained in:
graywolf336 2014-06-12 10:30:00 -05:00
parent a442887b36
commit a77e0cc472
3 changed files with 758 additions and 744 deletions

View File

@ -193,6 +193,16 @@ public class JailManager {
return this.cache.containsKey(uuid);
}
/**
* Gets a cached prisoner object.
*
* @param uuid of the prisoner to get
* @return the cahced prisoner object, will be null if it doesn't exist
*/
public CachePrisoner getCacheObject(UUID uuid) {
return this.cache.get(uuid);
}
/**
* Removes the cache object stored for this uuid.
*

View File

@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.CachePrisoner;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.enums.LangString;
@ -28,9 +29,10 @@ public class MoveProtectionListener implements Listener {
if(pl.getConfig().getBoolean(Settings.MOVEPROTECTION.getPath())) {
//Let's be sure the player we're dealing with is in jail
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
if(j != null) {
Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId());
CachePrisoner cp = pl.getJailManager().getCacheObject(event.getPlayer().getUniqueId());
if(cp != null) {
Jail j = cp.getJail();
Prisoner p = cp.getPrisoner();
//If the player is being teleported, let's ignore it
if(p.isTeleporting()) {

View File

@ -24,6 +24,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.beans.CachePrisoner;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
@ -61,6 +62,7 @@ public class BenchmarkTest extends AbstractBenchmark {
main.getPrisonerManager().prepareJail(main.getJailManager().getJail("testingJail"), null, null, new Prisoner(i == 555 ? use.toString() : UUID.randomUUID().toString(), "mockPlayer" + i, true, 100000L, "testJailer", "Test jailing " + i));
}
main.getJailManager().addCacheObject(new CachePrisoner(main.getJailManager().getJailPlayerIsIn(use), main.getJailManager().getPrisoner(use)));
r = new Random();
}