Skip to content

Commit

Permalink
Add cache feature
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Mar 16, 2024
1 parent 2915d42 commit b30a5d1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/io/wdsj/asw/listener/PlayerItemListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.HashSet;
import java.util.List;

import static io.wdsj.asw.AdvancedSensitiveWords.*;
import static io.wdsj.asw.util.Utils.messagesFilteredNum;

public class PlayerItemListener implements Listener {
private static final HashSet<ItemMeta> NORMAL_ITEM_META = new HashSet<>();

@EventHandler(priority = EventPriority.LOW)
public void onPlayerHeldItem(PlayerItemHeldEvent event) {
Expand All @@ -34,6 +36,7 @@ public void onPlayerHeldItem(PlayerItemHeldEvent event) {
ItemStack item = player.getInventory().getItem(event.getNewSlot());
if (item != null && item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (NORMAL_ITEM_META.contains(meta)) return;
if (meta != null && meta.hasDisplayName()) {
String originalName = meta.getDisplayName();
long startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -61,6 +64,8 @@ public void onPlayerHeldItem(PlayerItemHeldEvent event) {
TimingUtils.addProcessStatistic(endTime, startTime);
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ITEM, originalName);
if (settingsManager.getProperty(PluginSettings.ITEM_PUNISH)) Punishment.punish(player);
} else {
NORMAL_ITEM_META.add(meta);
}
}
}
Expand All @@ -74,6 +79,7 @@ public void onDrop(PlayerDropItemEvent event) {
ItemStack item = event.getItemDrop().getItemStack();
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (NORMAL_ITEM_META.contains(meta)) return;
if (meta != null && meta.hasDisplayName()) {
String originalName = meta.getDisplayName();
long startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -101,6 +107,8 @@ public void onDrop(PlayerDropItemEvent event) {
TimingUtils.addProcessStatistic(endTime, startTime);
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ITEM, originalName);
if (settingsManager.getProperty(PluginSettings.ITEM_PUNISH)) Punishment.punish(player);
} else {
NORMAL_ITEM_META.add(meta);
}
}
}
Expand Down

0 comments on commit b30a5d1

Please sign in to comment.