Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 91c8a9b

Browse files
committed
Improve WorldGuardUtil debug and barrier rendering
* Cleanup
1 parent 97a38ca commit 91c8a9b

6 files changed

Lines changed: 73 additions & 40 deletions

File tree

src/main/java/net/opmasterleo/combat/Combat.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,6 @@ public void onEnable() {
14751475
if (!folia) {
14761476
maxWorkerPoolSize = Math.max(2, Math.min(cpus, 8));
14771477
} else {
1478-
// For Folia, be more conservative
14791478
maxWorkerPoolSize = Math.max(1, Math.min(2, cpus - 1));
14801479
}
14811480
int corePoolSize = Math.max(1, Math.min(maxWorkerPoolSize / 3, 2));

src/main/java/net/opmasterleo/combat/manager/CrystalManager.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package net.opmasterleo.combat.manager;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Set;
6+
import java.util.UUID;
7+
import java.util.concurrent.ConcurrentHashMap;
8+
import java.util.concurrent.TimeUnit;
9+
310
import org.bukkit.Bukkit;
411
import org.bukkit.World;
5-
import org.bukkit.entity.Entity;
612
import org.bukkit.entity.EnderCrystal;
13+
import org.bukkit.entity.Entity;
714
import org.bukkit.entity.Player;
815

916
import net.opmasterleo.combat.Combat;
1017
import net.opmasterleo.combat.util.SchedulerUtil;
1118

12-
import java.util.*;
13-
import java.util.concurrent.ConcurrentHashMap;
14-
import java.util.concurrent.TimeUnit;
15-
1619
public class CrystalManager {
1720
private static final long CLEANUP_INTERVAL = TimeUnit.MINUTES.toMillis(1);
1821
private static final long CRYSTAL_EXPIRY = TimeUnit.MINUTES.toMillis(5);
@@ -106,7 +109,6 @@ private void cleanupExpiredEntries() {
106109
worldCache.put(world.getName(), world);
107110
}
108111

109-
// Schedule the cleanup task on the main thread
110112
Bukkit.getScheduler().runTask(plugin, () -> {
111113
crystalData.keySet().removeIf(crystalId -> {
112114
CrystalData data = crystalData.get(crystalId);

src/main/java/net/opmasterleo/combat/manager/GlowManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public void setGlowing(Player player, boolean glowing, UUID opponentId) {
150150

151151
if (glowing && (!enabled || !plugin.getConfig().getBoolean("General.CombatTagGlowing", false))) {
152152
glowingPlayers.remove(playerId);
153-
// Direct call instead of entity task
154153
removeGlowEffect(player);
155154
return;
156155
}

src/main/java/net/opmasterleo/combat/manager/SuperVanishManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package net.opmasterleo.combat.manager;
22

3+
import java.lang.reflect.InvocationTargetException;
4+
import java.lang.reflect.Method;
5+
36
import org.bukkit.Bukkit;
47
import org.bukkit.entity.Player;
58
import org.bukkit.plugin.Plugin;
69

7-
import java.lang.reflect.InvocationTargetException;
8-
import java.lang.reflect.Method;
9-
1010
public class SuperVanishManager {
1111

1212
private Plugin vanishPlugin;
@@ -15,7 +15,6 @@ public class SuperVanishManager {
1515

1616
public SuperVanishManager() {
1717
try {
18-
// Add support for PremiumVanish as well
1918
Plugin superVanish = Bukkit.getPluginManager().getPlugin("SuperVanish");
2019
Plugin premiumVanish = Bukkit.getPluginManager().getPlugin("PremiumVanish");
2120
if (superVanish != null && superVanish.isEnabled()) {

src/main/java/net/opmasterleo/combat/util/SchedulerUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ private static void scheduleCleanupTask() {
123123
runTaskTimerAsync(
124124
getPlugin(),
125125
() -> {
126-
// OPTIMIZATION: Simplified cleanup - just remove cancelled tasks
127126
activeTasks.removeIf(task -> task == null || task.isCancelled());
128127
int activeTaskCount = activeTasks.size();
129128

src/main/java/net/opmasterleo/combat/util/WorldGuardUtil.java

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public class WorldGuardUtil extends PacketListenerAbstract implements Listener {
5454
private final Map<UUID, Vector3d> lastPositions = new ConcurrentHashMap<>();
5555
private final Map<UUID, Long> lastBarrierRender = new ConcurrentHashMap<>();
5656
private static final long BARRIER_RENDER_INTERVAL_MS = 150L;
57+
private final java.util.concurrent.atomic.AtomicLong wgPackets = new java.util.concurrent.atomic.AtomicLong();
58+
private final java.util.concurrent.atomic.AtomicLong exitNotInCombat = new java.util.concurrent.atomic.AtomicLong();
59+
private final java.util.concurrent.atomic.AtomicLong exitBypass = new java.util.concurrent.atomic.AtomicLong();
60+
private final java.util.concurrent.atomic.AtomicLong exitWorldDisabled = new java.util.concurrent.atomic.AtomicLong();
61+
private final java.util.concurrent.atomic.AtomicLong exitSmallDelta = new java.util.concurrent.atomic.AtomicLong();
62+
private final java.util.concurrent.atomic.AtomicLong processedPackets = new java.util.concurrent.atomic.AtomicLong();
5763
private static class LRUCache<K, V> extends LinkedHashMap<K, V> {
5864
private final int maxSize;
5965

@@ -154,11 +160,13 @@ public void onPacketReceive(PacketReceiveEvent event) {
154160
var type = event.getPacketType();
155161

156162
if (type == Client.PLAYER_POSITION || type == Client.PLAYER_POSITION_AND_ROTATION) {
163+
boolean dbg = plugin.isDebugEnabled();
164+
if (dbg) wgPackets.incrementAndGet();
157165
Player player = (Player) event.getPlayer();
158166
if (!player.isOnline()) return;
159-
if (!plugin.isInCombat(player)) return;
160-
if (shouldBypass(player)) return;
161-
if (!plugin.isCombatEnabledInWorld(player)) return;
167+
if (!plugin.isInCombat(player)) { if (dbg) exitNotInCombat.incrementAndGet(); return; }
168+
if (shouldBypass(player)) { if (dbg) exitBypass.incrementAndGet(); return; }
169+
if (!plugin.isCombatEnabledInWorld(player)) { if (dbg) exitWorldDisabled.incrementAndGet(); return; }
162170
Vector3d newPos;
163171
if (type == Client.PLAYER_POSITION) {
164172
WrapperPlayClientPlayerPosition wrapper = new WrapperPlayClientPlayerPosition(event);
@@ -172,17 +180,15 @@ public void onPacketReceive(PacketReceiveEvent event) {
172180
if (lastPos != null) {
173181
double deltaX = Math.abs(newPos.getX() - lastPos.getX());
174182
double deltaZ = Math.abs(newPos.getZ() - lastPos.getZ());
175-
if (deltaX < 0.01 && deltaZ < 0.01) {
176-
return;
177-
}
183+
if (deltaX < 0.01 && deltaZ < 0.01) { if (dbg) exitSmallDelta.incrementAndGet(); return; }
178184
}
179185

180186
lastPositions.put(player.getUniqueId(), newPos);
181187
Location to = new Location(player.getWorld(), newPos.getX(), newPos.getY(), newPos.getZ());
182188
Location from = lastPos != null
183189
? new Location(player.getWorld(), lastPos.getX(), lastPos.getY(), lastPos.getZ())
184190
: player.getLocation();
185-
191+
if (dbg) processedPackets.incrementAndGet();
186192
SchedulerUtil.runEntityTask(plugin, player, () -> handlePlayerMovement(player, from, to));
187193
}
188194
} catch (IllegalStateException e) {
@@ -239,6 +245,19 @@ private void startCleanupTask() {
239245
if (System.currentTimeMillis() - lastCleanupTime > 60000) {
240246
pvpCache.entrySet().removeIf(entry -> entry.getValue().isExpired());
241247
lastCleanupTime = System.currentTimeMillis();
248+
if (plugin.isDebugEnabled()) {
249+
long total = wgPackets.getAndSet(0);
250+
long notCombat = exitNotInCombat.getAndSet(0);
251+
long bypass = exitBypass.getAndSet(0);
252+
long worldOff = exitWorldDisabled.getAndSet(0);
253+
long small = exitSmallDelta.getAndSet(0);
254+
long processed = processedPackets.getAndSet(0);
255+
long exits = notCombat + bypass + worldOff + small;
256+
double exitRate = total > 0 ? (exits * 100.0 / total) : 0.0;
257+
plugin.debug(String.format(
258+
"WG packets: total=%d, exits={notCombat=%d, bypass=%d, worldDisabled=%d, smallDelta=%d} processed=%d, exitRate=%.1f%%",
259+
total, notCombat, bypass, worldOff, small, processed, exitRate));
260+
}
242261
}
243262
}, 1200L, 1200L);
244263
}
@@ -309,10 +328,14 @@ private void createVisualBarrier(Player player, Location location) {
309328
Location south = findBorder(location, 0, 1, base);
310329
Location north = findBorder(location, 0, -1, base);
311330

312-
if (east != null) createBarrierLine(player, east);
313-
if (west != null) createBarrierLine(player, west);
314-
if (south != null) createBarrierLine(player, south);
315-
if (north != null) createBarrierLine(player, north);
331+
java.util.List<Location> starts = new java.util.ArrayList<>(4);
332+
if (east != null) starts.add(east);
333+
if (west != null) starts.add(west);
334+
if (south != null) starts.add(south);
335+
if (north != null) starts.add(north);
336+
if (!starts.isEmpty()) {
337+
createBarrierGroup(player, starts);
338+
}
316339
}
317340

318341
private Location findBorder(Location origin, int dx, int dz, boolean base) {
@@ -331,22 +354,34 @@ private Location findBorder(Location origin, int dx, int dz, boolean base) {
331354
}
332355
return null;
333356
}
334-
335-
private void createBarrierLine(Player player, Location start) {
336-
int maxHeight = Math.min(barrierHeight, 5);
337-
Location blockLoc = start.clone();
338-
for (int y = 0; y < maxHeight; y++) {
339-
blockLoc.setY(start.getY() + y);
340-
sendBlockChange(player, blockLoc, barrierMaterial);
341-
342-
final Location finalLoc = blockLoc.clone();
343-
SchedulerUtil.runRegionTaskLater(plugin, finalLoc, () -> {
344-
if (player.isOnline()) {
345-
resetBlockChange(player, finalLoc);
346-
}
347-
}, 100L);
348-
}
349-
}
357+
358+
private void createBarrierGroup(Player player, java.util.List<Location> starts) {
359+
if (starts == null || starts.isEmpty()) return;
360+
final int maxHeight = Math.min(barrierHeight, 5);
361+
for (Location base : starts) {
362+
if (base == null) continue;
363+
final double baseY = base.getY();
364+
Location temp = base.clone();
365+
for (int y = 0; y < maxHeight; y++) {
366+
temp.setY(baseY + y);
367+
sendBlockChange(player, temp, barrierMaterial);
368+
}
369+
}
370+
371+
Location anchor = starts.get(0);
372+
SchedulerUtil.runRegionTaskLater(plugin, anchor, () -> {
373+
if (!player.isOnline()) return;
374+
for (Location base : starts) {
375+
if (base == null) continue;
376+
final double baseY = base.getY();
377+
Location temp = base.clone();
378+
for (int y = 0; y < maxHeight; y++) {
379+
temp.setY(baseY + y);
380+
resetBlockChange(player, temp);
381+
}
382+
}
383+
}, 100L);
384+
}
350385

351386
private void sendBlockChange(Player player, Location loc, Material material) {
352387
try {

0 commit comments

Comments
 (0)