Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup more fields on player & world #1390

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 +184,20 @@ 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;
world.setKeepSpawnInMemory(false);
}

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

@Override
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