mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Optimize performance for listeners, something need keep tracking for future possible optimize, also PlayerListener need rewrite
Former-commit-id: 2e25048d4574ec310e2229879a63175b086a4682
This commit is contained in:
1 parent
df29e82937
commit
cbeddcdaf9
6 files changed
+53
-61
No files matched your search
@@ -60,14 +60,13 @@ public class BlockListener extends ProtectionListenerBase implements Listener {
|
||||
|
||||
final Block b = e.getBlock();
|
||||
|
||||
if (b.getState() instanceof Sign) {
|
||||
if (b.getState() instanceof Sign) { //FIXME: It seems dupe with LockListener, remove it if can be removed
|
||||
Sign sign = (Sign) b.getState();
|
||||
if (super.getPlugin().getConfig().getBoolean("lockette.enable")
|
||||
&& sign.getLine(0).equals(super.getPlugin().getConfig().getString("lockette.private"))
|
||||
|| sign.getLine(0).equals(super.getPlugin().getConfig().getString("lockette.more_users"))) {
|
||||
// Ignore break lockette sign
|
||||
super.getPlugin().getLogger()
|
||||
.info("Skipped a dead-lock shop sign.(Lockette or other sign-lock plugin)");
|
||||
Util.debugLog("Skipped a dead-lock shop sign.(Lockette or other sign-lock plugin)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package org.maxgamer.quickshop.listener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -32,6 +31,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.shop.Shop;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ChunkListener implements Listener {
|
||||
|
||||
@@ -56,7 +57,6 @@ public class ChunkListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onChunkUnload(ChunkUnloadEvent e) {
|
||||
|
||||
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(e.getChunk());
|
||||
|
||||
if (inChunk == null || inChunk.isEmpty()) {
|
||||
|
||||
@@ -119,8 +119,7 @@ public class LockListener extends ProtectionListenerBase implements Listener {
|
||||
if (sign.getLine(0).equals(super.getPlugin().getConfig().getString("lockette.private"))
|
||||
|| sign.getLine(0).equals(super.getPlugin().getConfig().getString("lockette.more_users"))) {
|
||||
// Ignore break lockette sign
|
||||
super.getPlugin().getLogger()
|
||||
.info("Skipped a dead-lock shop sign.(Lockette or other sign-lock plugin)");
|
||||
Util.debugLog("Skipped a dead-lock shop sign.(Lockette or other sign-lock plugin)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && e.getClickedBlock() != null) {
|
||||
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
|
||||
&& Util.isWallSign(e.getClickedBlock().getType())) {
|
||||
&& Util.isWallSign(e.getClickedBlock().getType())) {
|
||||
final Block block;
|
||||
|
||||
if (Util.isWallSign(e.getClickedBlock().getType())) {
|
||||
@@ -69,27 +69,23 @@ public class PlayerListener implements Listener {
|
||||
} else {
|
||||
block = e.getClickedBlock();
|
||||
}
|
||||
|
||||
if (plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation()) != null
|
||||
&& (Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation()))
|
||||
.getOwner()
|
||||
.equals(e.getPlayer().getUniqueId())
|
||||
|| e.getPlayer().isOp())) {
|
||||
Shop controlPanelShop = plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation());
|
||||
if (controlPanelShop != null && (controlPanelShop.getOwner().equals(e.getPlayer().getUniqueId()) || e.getPlayer().isOp())){
|
||||
if (plugin.getConfig().getBoolean("shop.sneak-to-control")
|
||||
&& !e.getPlayer().isSneaking()) {
|
||||
&& !e.getPlayer().isSneaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getConfig().getBoolean("effect.sound.onclick")) {
|
||||
e.getPlayer()
|
||||
.playSound(e.getPlayer().getLocation(), Sound.BLOCK_DISPENSER_FAIL, 80.f, 1.0f);
|
||||
.playSound(e.getPlayer().getLocation(), Sound.BLOCK_DISPENSER_FAIL, 80.f, 1.0f);
|
||||
}
|
||||
|
||||
MsgUtil.sendControlPanelInfo(
|
||||
e.getPlayer(),
|
||||
Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())));
|
||||
e.getPlayer(),
|
||||
Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())));
|
||||
Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation()))
|
||||
.setSignText();
|
||||
.setSignText();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +141,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
if (plugin.getConfig().getBoolean("effect.sound.onclick")) {
|
||||
e.getPlayer()
|
||||
.playSound(e.getPlayer().getLocation(), Sound.BLOCK_DISPENSER_FAIL, 80.f, 1.0f);
|
||||
.playSound(e.getPlayer().getLocation(), Sound.BLOCK_DISPENSER_FAIL, 80.f, 1.0f);
|
||||
}
|
||||
// Text menu
|
||||
MsgUtil.sendShopInfo(p, shop);
|
||||
@@ -157,8 +153,8 @@ public class PlayerListener implements Listener {
|
||||
|
||||
if (shop.isSelling()) {
|
||||
int itemAmount =
|
||||
Math.min(
|
||||
Util.countSpace(p.getInventory(), shop.getItem()), (int) Math.floor(money / price));
|
||||
Math.min(
|
||||
Util.countSpace(p.getInventory(), shop.getItem()), (int) Math.floor(money / price));
|
||||
|
||||
if (!shop.isUnlimited()) {
|
||||
itemAmount = Math.min(itemAmount, shop.getRemainingStock());
|
||||
@@ -167,10 +163,10 @@ public class PlayerListener implements Listener {
|
||||
if (itemAmount < 0) {
|
||||
itemAmount = 0;
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("shop.allow-stacks") && shop.getItem().getAmount()>1) { //FIXME: A trash impl, need use a better way
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("how-many-buy-stack", p, ""+shop.getItem().getAmount(),"" + itemAmount/shop.getItem().getAmount()));
|
||||
if (plugin.getConfig().getBoolean("shop.allow-stacks") && shop.getItem().getAmount() > 1) { //FIXME: A trash impl, need use a better way
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("how-many-buy-stack", p, "" + shop.getItem().getAmount(), "" + itemAmount / shop.getItem().getAmount()));
|
||||
} else {
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("how-many-buy", p, "" + itemAmount));
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("how-many-buy", p, "" + itemAmount));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -193,10 +189,10 @@ public class PlayerListener implements Listener {
|
||||
if (items < 0) {
|
||||
items = 0;
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("shop.allow-stacks") && shop.getItem().getAmount()>1) { //FIXME: A trash impl, need use a better way
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("how-many-sell-stack", p,""+shop.getItem().getAmount(), "" + items/shop.getItem().getAmount()));
|
||||
if (plugin.getConfig().getBoolean("shop.allow-stacks") && shop.getItem().getAmount() > 1) { //FIXME: A trash impl, need use a better way
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("how-many-sell-stack", p, "" + shop.getItem().getAmount(), "" + items / shop.getItem().getAmount()));
|
||||
} else {
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("how-many-sell", p, "" + items));
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("how-many-sell", p, "" + items));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -207,14 +203,14 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
// Handles creating shops
|
||||
else if (e.useInteractedBlock() == Result.ALLOW
|
||||
&& shop == null
|
||||
&& item != null
|
||||
&& item.getType() != Material.AIR
|
||||
&& QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.sell")
|
||||
&& p.getGameMode() != GameMode.CREATIVE) {
|
||||
&& shop == null
|
||||
&& item != null
|
||||
&& item.getType() != Material.AIR
|
||||
&& QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.sell")
|
||||
&& p.getGameMode() != GameMode.CREATIVE) {
|
||||
if (e.useInteractedBlock() == Result.DENY
|
||||
|| plugin.getConfig().getBoolean("shop.sneak-to-create") && !p.isSneaking()
|
||||
|| !plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())){
|
||||
|| plugin.getConfig().getBoolean("shop.sneak-to-create") && !p.isSneaking()
|
||||
|| !plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
|
||||
// As of the new checking system, most plugins will tell the
|
||||
// player why they can't create a shop there.
|
||||
// So telling them a message would cause spam etc.
|
||||
@@ -222,20 +218,20 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
if (Util.getSecondHalf(b) != null
|
||||
&& !QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.double")) {
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("no-double-chests", p));
|
||||
&& !QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.double")) {
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("no-double-chests", p));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Util.isBlacklisted(item)
|
||||
&& !QuickShop.getPermissionManager()
|
||||
.hasPermission(p, "quickshop.bypass." + item.getType().name())) {
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("blacklisted-item", p));
|
||||
&& !QuickShop.getPermissionManager()
|
||||
.hasPermission(p, "quickshop.bypass." + item.getType().name())) {
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("blacklisted-item", p));
|
||||
return;
|
||||
}
|
||||
|
||||
if (b.getType() == Material.ENDER_CHEST
|
||||
&& !QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.enderchest")) {
|
||||
&& !QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.enderchest")) {
|
||||
return;
|
||||
}
|
||||
/*if (!Util.canBeShop(b)) {
|
||||
@@ -270,10 +266,10 @@ public class PlayerListener implements Listener {
|
||||
|
||||
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
|
||||
MsgUtil.sendMessage(p,
|
||||
MsgUtil.getMessage(
|
||||
"how-much-to-trade-for",
|
||||
p,
|
||||
Util.getItemStackName(Objects.requireNonNull(e.getItem()))));
|
||||
MsgUtil.getMessage(
|
||||
"how-much-to-trade-for",
|
||||
p,
|
||||
Util.getItemStackName(Objects.requireNonNull(e.getItem()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,10 +339,10 @@ public class PlayerListener implements Listener {
|
||||
|
||||
if (loc1.getWorld() != loc2.getWorld() || loc1.distanceSquared(loc2) > 25) {
|
||||
if (info.getAction() == ShopAction.CREATE) {
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("shop-creation-cancelled", p));
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("shop-creation-cancelled", p));
|
||||
Util.debugLog(p.getName() + " too far with the shop location.");
|
||||
} else if (info.getAction() == ShopAction.BUY) {
|
||||
MsgUtil.sendMessage(p,MsgUtil.getMessage("shop-purchase-cancelled", p));
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("shop-purchase-cancelled", p));
|
||||
Util.debugLog(p.getName() + " too far with the shop location.");
|
||||
}
|
||||
plugin.getShopManager().getActions().remove(p.getUniqueId());
|
||||
@@ -356,8 +352,8 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onDyeing(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK
|
||||
|| e.getItem() == null
|
||||
|| !Util.isDyes(e.getItem().getType())) {
|
||||
|| e.getItem() == null
|
||||
|| !Util.isDyes(e.getItem().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -370,7 +366,7 @@ public class PlayerListener implements Listener {
|
||||
final Block attachedBlock = Util.getAttached(block);
|
||||
|
||||
if (attachedBlock == null
|
||||
|| plugin.getShopManager().getShopIncludeAttached(attachedBlock.getLocation()) == null) {
|
||||
|| plugin.getShopManager().getShopIncludeAttached(attachedBlock.getLocation()) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
|
||||
package org.maxgamer.quickshop.listener;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -44,6 +41,8 @@ import org.maxgamer.quickshop.shop.Shop;
|
||||
import org.maxgamer.quickshop.util.MsgUtil;
|
||||
import org.maxgamer.quickshop.util.Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class ShopProtectionListener extends ProtectionListenerBase implements Listener {
|
||||
|
||||
@@ -54,10 +53,6 @@ public class ShopProtectionListener extends ProtectionListenerBase implements Li
|
||||
|
||||
private final boolean sendProtectionAlert = QuickShop.instance.getConfig().getBoolean("send-shop-protection-alert", false);
|
||||
|
||||
// Protect Minecart steal shop
|
||||
Map.Entry<Location, Boolean> lastInventoryMoveItemCheck =
|
||||
new AbstractMap.SimpleEntry<>(null, null);
|
||||
|
||||
public ShopProtectionListener(@NotNull QuickShop plugin, @Nullable Cache cache) {
|
||||
super(plugin, cache);
|
||||
this.plugin = plugin;
|
||||
@@ -142,10 +137,13 @@ public class ShopProtectionListener extends ProtectionListenerBase implements Li
|
||||
|
||||
final Block newBlock = e.getNewState().getBlock();
|
||||
final Shop thisBlockShop = getShopNature(newBlock.getLocation(), true);
|
||||
final Shop underBlockShop =
|
||||
getShopNature(newBlock.getRelative(BlockFace.DOWN).getLocation(), true);
|
||||
|
||||
if (thisBlockShop == null && underBlockShop == null) {
|
||||
if (thisBlockShop == null) {
|
||||
return;
|
||||
}
|
||||
final Shop underBlockShop =
|
||||
getShopNature(newBlock.getRelative(BlockFace.DOWN).getLocation(), true);
|
||||
if(underBlockShop == null){
|
||||
return;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
public class BukkitGameLanguageImpl extends org.maxgamer.quickshop.util.language.game.InternalGameLanguageImpl implements org.maxgamer.quickshop.util.language.game.GameLanguage {
|
||||
public class BukkitGameLanguageImpl extends InternalGameLanguageImpl implements GameLanguage {
|
||||
private QuickShop plugin;
|
||||
|
||||
public BukkitGameLanguageImpl(@NotNull QuickShop plugin) {
|
||||
|
||||
Reference in new issue
Block a user