mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 09:59:49 -05:00
Optimize AsyncPacketSender
This commit is contained in:
1 parent
ca07cb3fad
commit
296c3b2ffe
3 files changed
+10
-16
No files matched your search
@@ -247,8 +247,6 @@ public class QuickShop extends JavaPlugin {
|
||||
private String currency = null;
|
||||
@Getter
|
||||
private ShopControlPanel shopControlPanelManager;
|
||||
@Nullable
|
||||
private AsyncPacketSender asyncPacketSender;
|
||||
|
||||
@NotNull
|
||||
public static QuickShop getInstance() {
|
||||
@@ -576,9 +574,7 @@ public class QuickShop extends JavaPlugin {
|
||||
}
|
||||
|
||||
Util.debugLog("Cleanup tasks...");
|
||||
if (asyncPacketSender != null) {
|
||||
asyncPacketSender.stop();
|
||||
}
|
||||
AsyncPacketSender.stop();
|
||||
try {
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
} catch (Throwable ignored) {
|
||||
@@ -820,7 +816,7 @@ public class QuickShop extends JavaPlugin {
|
||||
displayDupeRemoverWatcher.runTaskTimerAsynchronously(this, 0, 1);
|
||||
}
|
||||
if (display && DisplayItem.getNowUsing() == DisplayType.VIRTUALITEM) {
|
||||
asyncPacketSender = AsyncPacketSender.getInstance();
|
||||
AsyncPacketSender.start(this);
|
||||
}
|
||||
if (logWatcher != null) {
|
||||
logWatcher.runTaskTimerAsynchronously(this, 10, 10);
|
||||
|
||||
@@ -336,7 +336,7 @@ public class VirtualDisplayItem extends DisplayItem {
|
||||
int x = integerStructureModifier.read(0);
|
||||
//chunk z
|
||||
int z = integerStructureModifier.read(1);
|
||||
AsyncPacketSender.getInstance().offer(() -> {
|
||||
AsyncPacketSender.offer(() -> {
|
||||
if (chunkLocation == null) {
|
||||
World world = shop.getLocation().getWorld();
|
||||
Chunk chunk;
|
||||
|
||||
@@ -18,26 +18,21 @@
|
||||
*/
|
||||
package org.maxgamer.quickshop.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.util.holder.QuickShopInstanceHolder;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public final class AsyncPacketSender extends QuickShopInstanceHolder {
|
||||
public final class AsyncPacketSender {
|
||||
|
||||
private static final Queue<Runnable> asyncPacketSendQueue = new ConcurrentLinkedQueue<>();
|
||||
@Getter
|
||||
private static final AsyncPacketSender instance = new AsyncPacketSender(QuickShop.getInstance());
|
||||
private static BukkitTask asyncSendingTask;
|
||||
|
||||
private AsyncPacketSender(QuickShop plugin) {
|
||||
super(plugin);
|
||||
private AsyncPacketSender() {
|
||||
}
|
||||
|
||||
public void offer(Runnable runnable) {
|
||||
public static void start(QuickShop plugin) {
|
||||
//lazy initialize
|
||||
if (asyncSendingTask == null || asyncSendingTask.isCancelled()) {
|
||||
asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
|
||||
@@ -48,10 +43,13 @@ public final class AsyncPacketSender extends QuickShopInstanceHolder {
|
||||
}
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void offer(Runnable runnable) {
|
||||
asyncPacketSendQueue.offer(runnable);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
public static void stop() {
|
||||
if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) {
|
||||
asyncSendingTask.cancel();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user