Skip to content
Closed
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
22 changes: 20 additions & 2 deletions src/main/java/top/ellan/mahjong/runtime/ServerScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public boolean isCancelled() {
};

private final Plugin plugin;
private volatile Object cachedGlobalRegionScheduler;
private volatile Object cachedRegionScheduler;

public ServerScheduler(Plugin plugin) {
this.plugin = Objects.requireNonNull(plugin, "plugin");
Expand Down Expand Up @@ -313,11 +315,27 @@ public PluginTask removeEntity(Entity entity, long delayTicks) {
}

private Object globalRegionScheduler() {
return this.invokeNoArgs(this.plugin.getServer(), GET_GLOBAL_REGION_SCHEDULER);
Object cached = this.cachedGlobalRegionScheduler;
if (cached != null) {
return cached;
}
Object resolved = this.invokeNoArgs(this.plugin.getServer(), GET_GLOBAL_REGION_SCHEDULER);
if (resolved != null) {
this.cachedGlobalRegionScheduler = resolved;
}
return resolved;
}

private Object regionScheduler() {
return this.invokeNoArgs(this.plugin.getServer(), GET_REGION_SCHEDULER);
Object cached = this.cachedRegionScheduler;
if (cached != null) {
return cached;
}
Object resolved = this.invokeNoArgs(this.plugin.getServer(), GET_REGION_SCHEDULER);
if (resolved != null) {
this.cachedRegionScheduler = resolved;
}
return resolved;
}

private Object entityScheduler(Entity entity) {
Expand Down
Loading