mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
[BLIND] Quick fix for memory leak with unloaded worlds (MovingData).
This commit is contained in:
parent
b8141f5f32
commit
a9f26e2d7d
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.access.ACheckData;
|
||||
@ -30,6 +31,11 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
*/
|
||||
public class MovingData extends ACheckData {
|
||||
|
||||
/**
|
||||
* Assume the player has to move on ground or so to lift off. TODO: Test, might be better ground.
|
||||
*/
|
||||
private static final MediumLiftOff defaultMediumLiftOff = MediumLiftOff.LIMIT_JUMP;
|
||||
|
||||
// private static final long IGNORE_SETBACK_Y = BlockProperties.F_SOLID | BlockProperties.F_GROUND | BlockProperties.F_CLIMBABLE | BlockProperties.F_LIQUID;
|
||||
|
||||
/** The factory creating data. */
|
||||
@ -75,9 +81,19 @@ public class MovingData extends ACheckData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assume the player has to move on ground or so to lift off. TODO: Test, might be better ground.
|
||||
* Clear data related to the given world.
|
||||
* @param world The world that gets unloaded.
|
||||
*/
|
||||
private static final MediumLiftOff defaultMediumLiftOff = MediumLiftOff.LIMIT_JUMP;
|
||||
public static void onWorldUnload(final World world){
|
||||
final String worldName = world.getName();
|
||||
for (final MovingData data : playersMap.values()){
|
||||
data.onWorldUnload(worldName);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Not static.
|
||||
/////////////////
|
||||
|
||||
// Violation levels -----
|
||||
public double creativeFlyVL = 0D;
|
||||
@ -552,5 +568,30 @@ public class MovingData extends ACheckData {
|
||||
}
|
||||
return loc.getX() == setBack.getX() && loc.getY() == setBack.getY() && loc.getZ() == setBack.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player leaves the server.
|
||||
*/
|
||||
public void onPlayerLeave() {
|
||||
removeAllVelocity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up data related to worlds with the given name (not case-sensitive).
|
||||
* @param worldName
|
||||
*/
|
||||
public void onWorldUnload(final String worldName){
|
||||
// TODO: Unlink world references.
|
||||
if (teleported != null && worldName.equalsIgnoreCase(teleported.getWorld().getName())){
|
||||
resetTeleported();
|
||||
}
|
||||
if (setBack != null && worldName.equalsIgnoreCase(setBack.getWorld().getName())){
|
||||
clearFlyData();
|
||||
}
|
||||
if (morePacketsSetback != null && worldName.equalsIgnoreCase(morePacketsSetback.getWorld().getName()) || morePacketsVehicleSetback != null && worldName.equalsIgnoreCase(morePacketsVehicleSetback.getWorld().getName())){
|
||||
clearMorePacketsData();
|
||||
clearNoFallData(); // just in case.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -1277,7 +1278,13 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
||||
noFall.onLeave(player);
|
||||
final MovingData data = MovingData.getData(player);
|
||||
// TODO: Add a method for ordinary presence-change resetting (use in join + leave).
|
||||
data.removeAllVelocity();
|
||||
data.onPlayerLeave();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWorldunload(final WorldUnloadEvent event){
|
||||
// TODO: Consider removing the world-related data anyway (even if the event is cancelled).
|
||||
MovingData.onWorldUnload(event.getWorld());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
|
Loading…
Reference in New Issue
Block a user