mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 01:49:49 -05:00
Some improves
Former-commit-id: 8b43732021332bfe04f38983f123fd91d35a2cb0 [formerly 2809a4b6b191e0ddccb5e9eb0544b7a2997007e2] Former-commit-id: b0fd2fc3c0ac49c12ec12847cafae9312951b716
This commit is contained in:
1 parent
e844b86c0c
commit
b9ef371f74
8 files changed
+100
-80
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.*;
|
||||
import org.bukkit.Chunk;
|
||||
@@ -15,6 +16,7 @@ import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.QueueAction;
|
||||
import org.maxgamer.quickshop.Shop.QueueShopObject;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopChunk;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
@AllArgsConstructor
|
||||
@@ -24,10 +26,11 @@ public class ChunkListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onChunkLoad(ChunkLoadEvent e) {
|
||||
Chunk c = e.getChunk();
|
||||
if (plugin.getShopManager().getShops() == null)
|
||||
Map<String, HashMap<ShopChunk, HashMap<Location, Shop>>> map = plugin.getShopManager().getShops();
|
||||
if (plugin.getShopManager().getShops() == null || map.isEmpty())
|
||||
return;
|
||||
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(c);
|
||||
if (inChunk == null)
|
||||
if (inChunk == null || inChunk.isEmpty())
|
||||
return;
|
||||
new BukkitRunnable() {
|
||||
|
||||
@@ -47,7 +50,7 @@ public class ChunkListener implements Listener {
|
||||
public void onChunkUnload(ChunkUnloadEvent e) {
|
||||
Chunk c = e.getChunk();
|
||||
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(c);
|
||||
if (inChunk == null)
|
||||
if (inChunk == null || inChunk.isEmpty())
|
||||
return;
|
||||
for (Shop shop : inChunk.values()) {
|
||||
plugin.getQueuedShopManager().add(new QueueShopObject(shop, QueueAction.UNLOAD));
|
||||
|
||||
@@ -17,8 +17,11 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent.State;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.DisplayItem;
|
||||
@@ -32,18 +35,29 @@ public class DisplayProtectionListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
for (int i = 0; i < event.getInventory().getContents().length; i++) {
|
||||
try {
|
||||
ItemStack is = event.getInventory().getContents()[i];
|
||||
if (itemStackCheck(is)) {
|
||||
is.setAmount(0);
|
||||
is.setType(Material.AIR);
|
||||
event.getPlayer().closeInventory();
|
||||
Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + event.getPlayer()
|
||||
.getLocation().toString() + ")");
|
||||
Util.inventoryCheck(event.getInventory());
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
// for (int i = 0; i < event.getInventory().getContents().length; i++) {
|
||||
// try {
|
||||
// ItemStack is = event.getInventory().getContents()[i];
|
||||
// if (itemStackCheck(is)) {
|
||||
// is.setAmount(0);
|
||||
// is.setType(Material.AIR);
|
||||
// event.getPlayer().closeInventory();
|
||||
// Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + event.getPlayer()
|
||||
// .getLocation().toString() + ")");
|
||||
// //Util.inventoryCheck(event.getInventory());
|
||||
// }
|
||||
// } catch (Exception e) {}
|
||||
// }
|
||||
|
||||
for (ItemStack is : event.getInventory().getContents()) {
|
||||
if (itemStackCheck(is)) {
|
||||
is.setType(Material.AIR);
|
||||
is.setAmount(1);
|
||||
event.getPlayer().closeInventory();
|
||||
Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + event.getPlayer()
|
||||
.getLocation().toString() + ")");
|
||||
//Util.inventoryCheck(event.getInventory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,56 +87,56 @@ public class DisplayProtectionListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void mendItem(PlayerItemMendEvent e) {
|
||||
ItemStack stack = e.getPlayer().getInventory().getItemInMainHand();
|
||||
ItemStack stackOffHand = e.getPlayer().getInventory().getItemInOffHand();
|
||||
try {
|
||||
if (DisplayItem.checkShopItem(stack)) {
|
||||
e.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR, 0));
|
||||
// You shouldn't be able to pick up that...
|
||||
MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
.toString() + ")");
|
||||
Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
}
|
||||
if (DisplayItem.checkShopItem(stackOffHand)) {
|
||||
e.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR, 0));
|
||||
// You shouldn't be able to pick up that...
|
||||
MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
.toString() + ")");
|
||||
Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
}
|
||||
}
|
||||
// @EventHandler(ignoreCancelled = true)
|
||||
// public void mendItem(PlayerItemMendEvent e) {
|
||||
// ItemStack stack = e.getPlayer().getInventory().getItemInMainHand();
|
||||
// ItemStack stackOffHand = e.getPlayer().getInventory().getItemInOffHand();
|
||||
// try {
|
||||
// if (DisplayItem.checkShopItem(stack)) {
|
||||
// e.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR, 0));
|
||||
// // You shouldn't be able to pick up that...
|
||||
// MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
// Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
// .toString() + ")");
|
||||
// Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
// }
|
||||
// if (DisplayItem.checkShopItem(stackOffHand)) {
|
||||
// e.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR, 0));
|
||||
// // You shouldn't be able to pick up that...
|
||||
// MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
// Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
// .toString() + ")");
|
||||
// Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
// }
|
||||
// } catch (NullPointerException ex) {
|
||||
// }
|
||||
// }
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void changeHand(PlayerChangedMainHandEvent e) {
|
||||
ItemStack stack = e.getPlayer().getInventory().getItemInMainHand();
|
||||
ItemStack stackOffHand = e.getPlayer().getInventory().getItemInOffHand();
|
||||
try {
|
||||
if (DisplayItem.checkShopItem(stack)) {
|
||||
e.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR, 0));
|
||||
// You shouldn't be able to pick up that...
|
||||
MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
.toString() + ")");
|
||||
Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
}
|
||||
if (DisplayItem.checkShopItem(stackOffHand)) {
|
||||
e.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR, 0));
|
||||
// You shouldn't be able to pick up that...
|
||||
MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
.toString() + ")");
|
||||
Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
}
|
||||
|
||||
}
|
||||
// @EventHandler(ignoreCancelled = true)
|
||||
// public void changeHand(PlayerChangedMainHandEvent e) {
|
||||
// ItemStack stack = e.getPlayer().getInventory().getItemInMainHand();
|
||||
// ItemStack stackOffHand = e.getPlayer().getInventory().getItemInOffHand();
|
||||
// try {
|
||||
// if (DisplayItem.checkShopItem(stack)) {
|
||||
// e.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR, 0));
|
||||
// // You shouldn't be able to pick up that...
|
||||
// MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
// Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
// .toString() + ")");
|
||||
// Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
// }
|
||||
// if (DisplayItem.checkShopItem(stackOffHand)) {
|
||||
// e.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR, 0));
|
||||
// // You shouldn't be able to pick up that...
|
||||
// MsgUtil.sendExploitAlert(e.getPlayer(), "Player Inventory Scan", e.getPlayer().getLocation());
|
||||
// Util.debugLog("Something trying collect QuickShop displayItem, already cancelled. (" + e.getPlayer().getLocation()
|
||||
// .toString() + ")");
|
||||
// Util.inventoryCheck(e.getPlayer().getInventory());
|
||||
// }
|
||||
// } catch (NullPointerException ex) {
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerPickup(EntityPickupItemEvent e) {
|
||||
|
||||
@@ -145,7 +145,7 @@ public class LockListener implements Listener {
|
||||
if (shop != null) {
|
||||
// ToDo: Shouldn't I be decrementing 1 here? Concurrency and
|
||||
// all..
|
||||
e.blockList().remove(b);
|
||||
e.blockList().remove(b); //Protect shop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class WorldListener implements Listener {
|
||||
// So manually tell all of these shops they're loaded.
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
|
||||
if (inChunk == null)
|
||||
if (inChunk == null || inChunk.isEmpty())
|
||||
continue;
|
||||
for (Shop shop : inChunk.values()) {
|
||||
plugin.getQueuedShopManager().add(new QueueShopObject(shop, QueueAction.LOAD));
|
||||
@@ -74,7 +74,7 @@ public class WorldListener implements Listener {
|
||||
// So manually tell all of these shops they're unloaded.
|
||||
for (Chunk chunk : e.getWorld().getLoadedChunks()) {
|
||||
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
|
||||
if (inChunk == null)
|
||||
if (inChunk == null || inChunk.isEmpty())
|
||||
continue;
|
||||
for (Shop shop : inChunk.values()) {
|
||||
plugin.getQueuedShopManager().add(new QueueShopObject(shop, QueueAction.UNLOAD));
|
||||
|
||||
@@ -719,7 +719,6 @@ public class ContainerShop implements Shop {
|
||||
|
||||
public boolean checkDisplayMoved() {
|
||||
// don't check if the plugin doesn't know about the object
|
||||
UUID timer = Util.setTimer();
|
||||
|
||||
if (!Util.isLoaded(getLocation()))
|
||||
return false;
|
||||
@@ -740,7 +739,6 @@ public class ContainerShop implements Shop {
|
||||
if (!item.getLocation().getWorld().isChunkLoaded(item.getLocation().getChunk())) {
|
||||
return false;
|
||||
}
|
||||
Util.debugLog("Performace for checkDisplayMoved: " + Util.endTimer(timer) + "ms");
|
||||
return this.getDisplayItem().getDisplayLocation().distanceSquared(item.getLocation()) > 0.2;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ public class QueuedShopManager {
|
||||
}
|
||||
|
||||
public void uninit() {
|
||||
task.cancel();
|
||||
if (!task.isCancelled())
|
||||
task.cancel();
|
||||
plugin.getLogger().info("Please waiting for finish the shops queue works...");
|
||||
runTask(true);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.maxgamer.quickshop.Shop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -46,7 +46,6 @@ public class RealDisplayItem implements DisplayItem {
|
||||
*/
|
||||
@Override
|
||||
public void spawn() {
|
||||
UUID timer = Util.setTimer();
|
||||
if (shop.getLocation().getWorld() == null)
|
||||
return;
|
||||
Location dispLoc = this.getDisplayLocation();
|
||||
@@ -69,7 +68,6 @@ public class RealDisplayItem implements DisplayItem {
|
||||
plugin.getLogger().log(Level.WARNING,
|
||||
"QuickShop version mismatch! This version of QuickShop is incompatible with this version of bukkit! Try update?");
|
||||
}
|
||||
Util.debugLog("Performace for spawn item: " + Util.endTimer(timer) + "ms");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +86,6 @@ public class RealDisplayItem implements DisplayItem {
|
||||
*/
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
UUID timer = Util.setTimer();
|
||||
item.setPickupDelay(Integer.MAX_VALUE);
|
||||
ItemMeta iMeta = item.getItemStack().getItemMeta();
|
||||
|
||||
@@ -105,7 +102,6 @@ public class RealDisplayItem implements DisplayItem {
|
||||
}
|
||||
iMeta.setLore(lore);
|
||||
item.getItemStack().setItemMeta(iMeta);
|
||||
Util.debugLog("Performace for safeGuard: " + Util.endTimer(timer) + "ms");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,18 +110,21 @@ public class RealDisplayItem implements DisplayItem {
|
||||
*/
|
||||
@Override
|
||||
public boolean removeDupe() {
|
||||
UUID timer = Util.setTimer();
|
||||
if (shop.getLocation().getWorld() == null)
|
||||
return false;
|
||||
Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation();
|
||||
boolean removed = false;
|
||||
if (!Util.isLoaded(displayLoc))
|
||||
return false;
|
||||
Chunk c = displayLoc.getChunk();
|
||||
for (Entity e : c.getEntities()) {
|
||||
if (e.getType() != EntityType.DROPPED_ITEM)
|
||||
continue;
|
||||
if (!(e instanceof Item))
|
||||
continue;
|
||||
if (this.item == null)
|
||||
continue;
|
||||
if (this.item != null && e.getEntityId() == this.item.getEntityId())
|
||||
if (e.getEntityId() == this.item.getEntityId()) //Not dupe, is our item
|
||||
continue;
|
||||
Location eLoc = e.getLocation().getBlock().getLocation();
|
||||
if (eLoc.equals(shop.getLocation()) || eLoc.equals(displayLoc)) {
|
||||
@@ -137,7 +136,6 @@ public class RealDisplayItem implements DisplayItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
Util.debugLog("Performace for displayDupe check: " + Util.endTimer(timer) + "ms");
|
||||
return removed;
|
||||
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ public class Util {
|
||||
public static Map sortHashMap(Map map) {
|
||||
List<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
|
||||
//升序排序
|
||||
|
||||
public int compare(Entry<String, String> o1,
|
||||
Entry<String, String> o2) {
|
||||
return o1.getValue().compareTo(o2.getValue());
|
||||
@@ -1027,6 +1027,12 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static void permformanceLog(String className, String methodName, long tookedTime) {
|
||||
if (!devMode)
|
||||
return;
|
||||
plugin.getLogger().info("[PERFORMANCE] [" + className + "] [" + methodName + "] Used time " + tookedTime + "ns.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Timer and return this timer's UUID
|
||||
* Time Unit: ms
|
||||
|
||||
Reference in new issue
Block a user