Skip to content

Commit

Permalink
Cleanup more fields on player & world
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <pabloherrerapalacio@gmail.com>
  • Loading branch information
Pablete1234 committed Aug 21, 2024
1 parent 820faff commit f7cb906
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/src/main/java/tc/oc/pgm/match/MatchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static tc.oc.pgm.util.Assert.assertNotNull;
import static tc.oc.pgm.util.Assert.assertTrue;
import static tc.oc.pgm.util.nms.NMSHacks.NMS_HACKS;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -909,6 +910,7 @@ public void destroy() {
if (world == null) return;

final String worldName = world.getName();
NMS_HACKS.cleanupWorld(world);
if (PGM.get().getServer().unloadWorld(worldName, false)) {
logger.fine("Successfully unloaded " + worldName);
} else {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/tc/oc/pgm/match/MatchManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private void onNonMatchUnload(World world) {
if (name.startsWith("match")) return;

NMS_HACKS.resetDimension(world);
NMS_HACKS.cleanupWorld(world);

if (PGM.get().getServer().unloadWorld(name, false)) {
logger.info("Unloaded non-match " + name);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/tc/oc/pgm/match/MatchPlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public void reset() {
bukkit.setFlySpeed(0.1f);
bukkit.setWalkSpeed(WalkSpeedKit.BUKKIT_DEFAULT);
bukkit.setLastDamageCause(null);
NMS_HACKS.cleanupPlayer(bukkit);
PLAYER_UTILS.clearArrowsInPlayer(bukkit);
PLAYER_UTILS.setKnockbackReduction(bukkit, 0);
bukkit.setVelocity(new Vector());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ public void resetDimension(World world) {
// no-op
}

@Override
public void cleanupWorld(World world) {
// no-op
}

@Override
public void cleanupPlayer(Player player) {
// no-op
}

@Override
public double getTPS() {
return Bukkit.getServer().getTPS()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFireball;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFirework;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
Expand Down Expand Up @@ -183,10 +184,21 @@ public void resetDimension(World world) {
// No-op, newer version of Java have disabled modifying final fields
}
}
}

@Override
public void cleanupWorld(World world) {
var nmsWorld = ((CraftWorld) world).getHandle();
nmsWorld.craftingManager.lastCraftView = null;
}

@Override
public void cleanupPlayer(Player player) {
var nmsPlayer = ((CraftPlayer) player).getHandle();
nmsPlayer.killer = null;
nmsPlayer.p(null); // Resets who last hit the entityLiving
}

@Override
public double getTPS() {
return Bukkit.getServer().spigot().getTPS()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public float getKnockbackReduction(Player player) {

@Override
public void clearArrowsInPlayer(Player player) {
((CraftPlayer) player).getHandle().o(0);
player.setArrowsStuck(0);
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public interface NMSHacks {

void resetDimension(World world);

void cleanupWorld(World world);

void cleanupPlayer(Player player);

double getTPS();

void postToMainThread(Plugin plugin, boolean priority, Runnable task);
Expand Down

0 comments on commit f7cb906

Please sign in to comment.