mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Improve the performance
Former-commit-id: 2195af6fe4db798e4fdee9e61da131fe3014ab3a [formerly de40a8056edf6d6ecef58b86eee690babccb3daa] Former-commit-id: 46320eb8eb57e392c1a6465113354457820fc866
This commit is contained in:
1 parent
885ec7050c
commit
ed2ec19086
3 files changed
+86
-54
No files matched your search
@@ -20,11 +20,11 @@ import org.maxgamer.quickshop.Database.*;
|
||||
import org.maxgamer.quickshop.Database.Database.ConnectionException;
|
||||
import org.maxgamer.quickshop.Economy.*;
|
||||
import org.maxgamer.quickshop.Listeners.*;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopLoader;
|
||||
import org.maxgamer.quickshop.Shop.ShopManager;
|
||||
import org.maxgamer.quickshop.Util.Timer;
|
||||
import org.maxgamer.quickshop.Util.*;
|
||||
import org.maxgamer.quickshop.Watcher.DisplayWatcher;
|
||||
import org.maxgamer.quickshop.Watcher.LogWatcher;
|
||||
import org.maxgamer.quickshop.Watcher.UpdateWatcher;
|
||||
|
||||
@@ -109,6 +109,7 @@ public class QuickShop extends JavaPlugin {
|
||||
private SentryErrorReporter sentryErrorReporter;
|
||||
private CommandManager commandManager;
|
||||
private ShopProtectionListener shopProtectListener;
|
||||
private DisplayWatcher displayWatcher;
|
||||
|
||||
/**
|
||||
* Get the Player's Shop limit.
|
||||
@@ -276,6 +277,7 @@ public class QuickShop extends JavaPlugin {
|
||||
customInventoryListener = new CustomInventoryListener(this);
|
||||
displayBugFixListener = new DisplayBugFixListener(this);
|
||||
shopProtectListener = new ShopProtectionListener(this);
|
||||
displayWatcher = new DisplayWatcher(this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blockListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(chatListener, this);
|
||||
@@ -285,26 +287,7 @@ public class QuickShop extends JavaPlugin {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(customInventoryListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(displayBugFixListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(shopProtectListener, this);
|
||||
getLogger().info("Registering DisplayCheck task....");
|
||||
if (display && displayItemCheckTicks > 0) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getConfig().getInt("shop.display-items-check-ticks") < 3000)
|
||||
getLogger()
|
||||
.severe("Shop.display-items-check-ticks is too low! It may cause HUGE lag! Pick a number > 3000");
|
||||
Iterator<Shop> it = getShopManager().getShopIterator();
|
||||
while (it.hasNext()) {
|
||||
Shop shop = it.next();
|
||||
if (shop == null)
|
||||
continue;
|
||||
if (!shop.isLoaded())
|
||||
continue;
|
||||
shop.checkDisplay();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(this, 1L, displayItemCheckTicks);
|
||||
}
|
||||
|
||||
getLogger().info("Cleaning MsgUtils...");
|
||||
MsgUtil.loadTransactionMessages();
|
||||
MsgUtil.clean();
|
||||
|
||||
@@ -72,12 +72,12 @@ public class ContainerShop implements Shop {
|
||||
/**
|
||||
* Adds a new shop.
|
||||
*
|
||||
* @param loc The location of the chest block
|
||||
* @param price The cost per item
|
||||
* @param item The itemstack with the properties we want. This is .cloned, no
|
||||
* need to worry about references
|
||||
* @param loc The location of the chest block
|
||||
* @param price The cost per item
|
||||
* @param item The itemstack with the properties we want. This is .cloned, no
|
||||
* need to worry about references
|
||||
* @param moderator The modertators
|
||||
* @param type The shop type
|
||||
* @param type The shop type
|
||||
* @param unlimited The unlimited
|
||||
*/
|
||||
public ContainerShop(@NotNull Location loc, double price, @NotNull ItemStack item, @NotNull ShopModerator moderator, boolean unlimited, @NotNull ShopType type) {
|
||||
@@ -111,7 +111,6 @@ public class ContainerShop implements Shop {
|
||||
Util.debugLog("The display was disabled.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -600,15 +599,14 @@ public class ContainerShop implements Shop {
|
||||
|
||||
for (Block b : blocks) {
|
||||
if (b == null) {
|
||||
plugin.getLogger().warning("Null signs in the queue");
|
||||
plugin.getLogger().warning("Null signs in the queue, skipping");
|
||||
continue;
|
||||
}
|
||||
Material mat = b.getType();
|
||||
if (!Util.isWallSign(mat)) {
|
||||
if (!Util.isWallSign(mat))
|
||||
continue;
|
||||
}
|
||||
if (!isAttached(b)) {
|
||||
if (!isAttached(b))
|
||||
continue;
|
||||
}
|
||||
if (!(b.getState() instanceof Sign))
|
||||
continue;
|
||||
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) b.getState();
|
||||
@@ -623,9 +621,8 @@ public class ContainerShop implements Shop {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!text) {
|
||||
if (!text)
|
||||
signs.add(sign);
|
||||
}
|
||||
}
|
||||
}
|
||||
return signs;
|
||||
@@ -723,17 +720,10 @@ public class ContainerShop implements Shop {
|
||||
Util.debugLog("Dupe load request, canceled.");
|
||||
return;
|
||||
}
|
||||
|
||||
ShopLoadEvent shopLoadEvent = new ShopLoadEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(shopLoadEvent);
|
||||
if (shopLoadEvent.isCancelled()) {
|
||||
if (shopLoadEvent.isCancelled())
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!Util.isLoaded(this.getLocation())) {
|
||||
// Util.debugLog("Shop " + this.getLocation().toString() + " skipped to load: Target location not loaded.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (!Util.canBeShop(this.getLocation().getBlock())) {
|
||||
this.onUnload();
|
||||
@@ -763,19 +753,14 @@ public class ContainerShop implements Shop {
|
||||
}
|
||||
|
||||
public String ownerName() {
|
||||
if (this.isUnlimited()) {
|
||||
if (this.isUnlimited())
|
||||
return MsgUtil.getMessage("admin-shop");
|
||||
}
|
||||
|
||||
if (this.getOwner() == null) {
|
||||
if (this.getOwner() == null)
|
||||
return MsgUtil.getMessage("unknown-owner");
|
||||
}
|
||||
|
||||
final String name = Bukkit.getOfflinePlayer(this.getOwner()).getName();
|
||||
if (name == null) {
|
||||
String name = Bukkit.getOfflinePlayer(this.getOwner()).getName();
|
||||
if (name == null || name.isEmpty())
|
||||
return MsgUtil.getMessage("unknown-owner");
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -829,10 +814,12 @@ public class ContainerShop implements Shop {
|
||||
this.displayItem.spawn();
|
||||
} else {
|
||||
/* If not spawned, we didn't need check these, only check them when we need. */
|
||||
if (this.displayItem.checkDisplayNeedRegen())
|
||||
if (this.displayItem.checkDisplayNeedRegen()) {
|
||||
this.displayItem.fixDisplayNeedRegen();
|
||||
if (this.displayItem.checkDisplayIsMoved())
|
||||
this.displayItem.fixDisplayMoved();
|
||||
} else {/* If display was regened, we didn't need check it moved, performance! */
|
||||
if (this.displayItem.checkDisplayIsMoved())
|
||||
this.displayItem.fixDisplayMoved();
|
||||
}
|
||||
}
|
||||
/* Dupe is always need check, if enabled display */
|
||||
if (plugin.isDisplay())
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.maxgamer.quickshop.Watcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import lombok.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
@Data
|
||||
public class DisplayWatcher {
|
||||
private QuickShop plugin;
|
||||
private ArrayList<Shop> pendingCheckDisplay = new ArrayList<>();
|
||||
|
||||
public DisplayWatcher(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
registerTask();
|
||||
}
|
||||
|
||||
private void registerTask() {
|
||||
plugin.getLogger().info("Registering DisplayCheck task....");
|
||||
if (plugin.isDisplay() && plugin.getDisplayItemCheckTicks() > 0) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.getConfig().getInt("shop.display-items-check-ticks") < 3000)
|
||||
plugin.getLogger()
|
||||
.severe("Shop.display-items-check-ticks is too low! It may cause HUGE lag! Pick a number > 3000");
|
||||
Iterator<Shop> it = plugin.getShopManager().getShopIterator();
|
||||
while (it.hasNext()) {
|
||||
Shop shop = it.next();
|
||||
if (shop == null)
|
||||
continue;
|
||||
if (!shop.isLoaded())
|
||||
continue;
|
||||
if (!Util.isLoaded(shop.getLocation()))
|
||||
continue;
|
||||
pendingCheckDisplay.add(shop);
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, new DisplayRunnable());
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 1L, plugin.getDisplayItemCheckTicks());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DisplayRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
@SuppressWarnings("unchecked") ArrayList<Shop> pendingCheckDisplayCopy = (ArrayList<Shop>) QuickShop.instance
|
||||
.getDisplayWatcher().getPendingCheckDisplay().clone();
|
||||
for (Shop shop : pendingCheckDisplayCopy) {
|
||||
shop.checkDisplay();
|
||||
}
|
||||
pendingCheckDisplayCopy.clear();
|
||||
QuickShop.instance.getDisplayWatcher().getPendingCheckDisplay().clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user