Skip to content

Commit 9b53b8a

Browse files
committed
Fix scheduler use during plugin shutdown
1 parent e3aefab commit 9b53b8a

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/main/java/top/ellan/mahjong/runtime/ServerScheduler.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public ServerScheduler(Plugin plugin) {
2929
}
3030

3131
public PluginTask runGlobal(Runnable runnable) {
32-
if (runnable == null) {
32+
if (runnable == null || !this.isPluginEnabled()) {
3333
return NO_OP_TASK;
3434
}
3535
Object scheduler = this.globalRegionScheduler();
@@ -49,7 +49,7 @@ public PluginTask runGlobal(Runnable runnable) {
4949
}
5050

5151
public PluginTask runGlobalDelayed(Runnable runnable, long delayTicks) {
52-
if (runnable == null) {
52+
if (runnable == null || !this.isPluginEnabled()) {
5353
return NO_OP_TASK;
5454
}
5555
Object scheduler = this.globalRegionScheduler();
@@ -70,7 +70,7 @@ public PluginTask runGlobalDelayed(Runnable runnable, long delayTicks) {
7070
}
7171

7272
public PluginTask runGlobalTimer(Runnable runnable, long delayTicks, long periodTicks) {
73-
if (runnable == null) {
73+
if (runnable == null || !this.isPluginEnabled()) {
7474
return NO_OP_TASK;
7575
}
7676
Object scheduler = this.globalRegionScheduler();
@@ -92,7 +92,7 @@ public PluginTask runGlobalTimer(Runnable runnable, long delayTicks, long period
9292
}
9393

9494
public PluginTask runRegion(Location location, Runnable runnable) {
95-
if (location == null || location.getWorld() == null || runnable == null) {
95+
if (location == null || location.getWorld() == null || runnable == null || !this.isPluginEnabled()) {
9696
return NO_OP_TASK;
9797
}
9898
Object scheduler = this.regionScheduler();
@@ -113,7 +113,7 @@ public PluginTask runRegion(Location location, Runnable runnable) {
113113
}
114114

115115
public PluginTask runRegionDelayed(Location location, Runnable runnable, long delayTicks) {
116-
if (location == null || location.getWorld() == null || runnable == null) {
116+
if (location == null || location.getWorld() == null || runnable == null || !this.isPluginEnabled()) {
117117
return NO_OP_TASK;
118118
}
119119
Object scheduler = this.regionScheduler();
@@ -135,7 +135,7 @@ public PluginTask runRegionDelayed(Location location, Runnable runnable, long de
135135
}
136136

137137
public PluginTask runRegionTimer(Location location, Runnable runnable, long delayTicks, long periodTicks) {
138-
if (location == null || location.getWorld() == null || runnable == null) {
138+
if (location == null || location.getWorld() == null || runnable == null || !this.isPluginEnabled()) {
139139
return NO_OP_TASK;
140140
}
141141
Object scheduler = this.regionScheduler();
@@ -158,7 +158,7 @@ public PluginTask runRegionTimer(Location location, Runnable runnable, long dela
158158
}
159159

160160
public PluginTask runEntity(Entity entity, Runnable runnable) {
161-
if (entity == null || runnable == null) {
161+
if (entity == null || runnable == null || !this.isPluginEnabled()) {
162162
return NO_OP_TASK;
163163
}
164164
Object scheduler = this.entityScheduler(entity);
@@ -179,7 +179,7 @@ public PluginTask runEntity(Entity entity, Runnable runnable) {
179179
}
180180

181181
public PluginTask runEntityDelayed(Entity entity, Runnable runnable, long delayTicks) {
182-
if (entity == null || runnable == null) {
182+
if (entity == null || runnable == null || !this.isPluginEnabled()) {
183183
return NO_OP_TASK;
184184
}
185185
Object scheduler = this.entityScheduler(entity);
@@ -202,7 +202,7 @@ public PluginTask runEntityDelayed(Entity entity, Runnable runnable, long delayT
202202

203203
@SuppressWarnings("unchecked")
204204
public CompletableFuture<Boolean> teleport(Entity entity, Location location) {
205-
if (entity == null || location == null) {
205+
if (entity == null || location == null || !this.isPluginEnabled()) {
206206
return CompletableFuture.completedFuture(Boolean.FALSE);
207207
}
208208
try {
@@ -231,7 +231,7 @@ public PluginTask removeEntity(Entity entity) {
231231
}
232232

233233
public PluginTask removeEntity(Entity entity, long delayTicks) {
234-
if (entity == null) {
234+
if (entity == null || !this.isPluginEnabled()) {
235235
return NO_OP_TASK;
236236
}
237237
Runnable removeTask = () -> {
@@ -257,6 +257,10 @@ private Object entityScheduler(Entity entity) {
257257
return this.invokeNoArgs(entity, "getScheduler");
258258
}
259259

260+
private boolean isPluginEnabled() {
261+
return this.plugin.isEnabled();
262+
}
263+
260264
private Object invokeNoArgs(Object target, String methodName) {
261265
if (target == null) {
262266
return null;

src/main/java/top/ellan/mahjong/table/presentation/TableViewerPresentationCoordinator.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void shutdown() {
8585
this.markDirty();
8686
this.nextOverlayRefreshTick = 0L;
8787
this.nextHudRefreshTick = 0L;
88-
this.clearHud();
88+
this.clearHudImmediately();
8989
}
9090

9191
public void hideHud(UUID viewerId) {
@@ -103,6 +103,17 @@ public void clearHud() {
103103
}
104104
}
105105

106+
private void clearHudImmediately() {
107+
for (UUID viewerId : List.copyOf(this.viewerHudBars.keySet())) {
108+
BossBar bar = this.viewerHudBars.remove(viewerId);
109+
this.viewerHudState.remove(viewerId);
110+
Player player = this.session.onlinePlayer(viewerId);
111+
if (bar != null && player != null) {
112+
player.hideBossBar(bar);
113+
}
114+
}
115+
}
116+
106117
private void flushOverlay(long nowTick) {
107118
this.updateViewerOverlayRegions();
108119
this.viewerOverlayDirty = false;

0 commit comments

Comments
 (0)