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:
parent
a442887b36
commit
a77e0cc472
File diff suppressed because it is too large
Load Diff
@ -1,87 +1,89 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class MoveProtectionListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public MoveProtectionListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void moveProtection(PlayerMoveEvent event) {
|
||||
//If we have the move protection enabled, then let's do it.
|
||||
//Other wise we don't need to deal with it.
|
||||
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());
|
||||
|
||||
//If the player is being teleported, let's ignore it
|
||||
if(p.isTeleporting()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//They moved, so they're no longer afk
|
||||
p.setAFKTime(0L);
|
||||
|
||||
//If the event's to location is NOT inside the jail, then let's do some action.
|
||||
//For right now, we're only going to apply the time. Later we're going to do
|
||||
//the guards, but first get a beta version out.
|
||||
if (!j.isInside(event.getTo())) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.MOVEPENALTY.getPath()));
|
||||
p.addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.MOVING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.MOVING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch(Exception e) {
|
||||
pl.getLogger().severe("Moving (escaping) outside a jail penalty time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//If the prisoner is in a cell, then let's teleport them to the cell's in location
|
||||
if(j.isJailedInACell(event.getPlayer().getUniqueId())) {
|
||||
event.setTo(j.getCellPrisonerIsIn(event.getPlayer().getUniqueId()).getTeleport());
|
||||
}else {
|
||||
//Otherwise let's teleport them to the in location of the jail
|
||||
event.setTo(j.getTeleportIn());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
PlayerMoveEvent move = new PlayerMoveEvent(event.getPlayer(), event.getFrom(), event.getTo());
|
||||
moveProtection(move);
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
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;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class MoveProtectionListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public MoveProtectionListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void moveProtection(PlayerMoveEvent event) {
|
||||
//If we have the move protection enabled, then let's do it.
|
||||
//Other wise we don't need to deal with it.
|
||||
if(pl.getConfig().getBoolean(Settings.MOVEPROTECTION.getPath())) {
|
||||
//Let's be sure the player we're dealing with is in jail
|
||||
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//They moved, so they're no longer afk
|
||||
p.setAFKTime(0L);
|
||||
|
||||
//If the event's to location is NOT inside the jail, then let's do some action.
|
||||
//For right now, we're only going to apply the time. Later we're going to do
|
||||
//the guards, but first get a beta version out.
|
||||
if (!j.isInside(event.getTo())) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.MOVEPENALTY.getPath()));
|
||||
p.addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.MOVING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.MOVING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch(Exception e) {
|
||||
pl.getLogger().severe("Moving (escaping) outside a jail penalty time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//If the prisoner is in a cell, then let's teleport them to the cell's in location
|
||||
if(j.isJailedInACell(event.getPlayer().getUniqueId())) {
|
||||
event.setTo(j.getCellPrisonerIsIn(event.getPlayer().getUniqueId()).getTeleport());
|
||||
}else {
|
||||
//Otherwise let's teleport them to the in location of the jail
|
||||
event.setTo(j.getTeleportIn());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
PlayerMoveEvent move = new PlayerMoveEvent(event.getPlayer(), event.getFrom(), event.getTo());
|
||||
moveProtection(move);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user