Makes legacy item checks configurable and have it disabled by default

The legacy checks is causing big performance problems on bigger servers.
It will be removed in the future
This commit is contained in:
Christian Koop 2023-07-18 14:35:36 +02:00
parent a0a2351148
commit 4aee977bfa
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
4 changed files with 41 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package com.songoda.epicvouchers.listeners;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.settings.Settings;
import com.songoda.epicvouchers.utils.CachedSet;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.ChatColor;
@ -25,6 +26,8 @@ public class PlayerInteractListener implements Listener {
@EventHandler
public void voucherListener(PlayerInteractEvent e) {
boolean legacyCheckEnabled = Settings.CHECK_FOR_LEGACY_ITEMS.getBoolean();
ItemStack item = e.getItem();
if (item == null || !isRightClickAction(e.getAction())) {
return;
@ -33,7 +36,7 @@ public class PlayerInteractListener implements Listener {
NBTItem nbtItem = new NBTItem(item);
boolean itemHasVoucher = nbtItem.hasTag("epicvouchers:voucher");
boolean itemHasBeenLegacyChecked = this.itemsThatGotLegacyChecked.contains(item);
boolean itemHasBeenLegacyChecked = !legacyCheckEnabled || this.itemsThatGotLegacyChecked.contains(item);
if (!itemHasVoucher && itemHasBeenLegacyChecked) {
return;
}
@ -52,6 +55,10 @@ public class PlayerInteractListener implements Listener {
return;
}
if (!Settings.CHECK_FOR_LEGACY_ITEMS.getBoolean()) {
return;
}
voucher = findVoucherForLegacyItem(item, allVouchers);
if (voucher == null) {
this.itemsThatGotLegacyChecked.add(item);

View File

@ -13,6 +13,10 @@ public class Settings implements Listener {
public static final ConfigSetting FILL_GLASS = new ConfigSetting(config, "Interface.Fill Interfaces With Glass", true);
public static final ConfigSetting COOLDOWN_DELAY = new ConfigSetting(config, "Main.Cooldown Delay", 10);
public static final ConfigSetting CHECK_FOR_LEGACY_ITEMS = new ConfigSetting(config, "Main.Check For Legacy Items", false,
"When you have a really old installation of EpicVouchers, some items in chests etc. might still be created with the old system.",
"This enables checking/detection for those items.",
"2 warnings: Enabling this comes with a performance impact with many vouchers configured + This check will be removed in the future");
public static final ConfigSetting DATABASE_SUPPORT = new ConfigSetting(config, "Database.Activate Mysql Support", false);
public static final ConfigSetting DATABASE_IP = new ConfigSetting(config, "Database.IP", "127.0.0.1");

View File

@ -4,7 +4,7 @@ import java.util.Map;
import java.util.WeakHashMap;
public class CachedSet<K> {
private final Map<K, Long> cache = new WeakHashMap<>();
private final Map<K, Long> cache = new WeakHashMap<>(0);
private final int ttl;
private long lastClear = System.currentTimeMillis();

View File

@ -21,9 +21,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import static org.bukkit.Material.PAPER;
@ -134,15 +134,39 @@ public class Voucher {
}
public List<String> getLore(boolean applyFormatting) {
return applyFormatting ? lore.stream().map(TextUtils::formatText).collect(Collectors.toList()) : lore;
if (!applyFormatting) {
return Collections.unmodifiableList(this.lore);
}
List<String> lore = new ArrayList<>();
for (String line : this.lore) {
lore.add(TextUtils.formatText(line));
}
return lore;
}
public List<String> getBroadcasts(boolean applyFormatting) {
return applyFormatting ? broadcasts.stream().map(TextUtils::formatText).collect(Collectors.toList()) : broadcasts;
if (!applyFormatting) {
return this.broadcasts;
}
List<String> result = new ArrayList<>();
for (String broadcast : this.broadcasts) {
result.add(TextUtils.formatText(broadcast));
}
return result;
}
public List<String> getMessages(boolean applyFormatting) {
return applyFormatting ? messages.stream().map(TextUtils::formatText).collect(Collectors.toList()) : messages;
if (!applyFormatting) {
return this.messages;
}
List<String> list = new ArrayList<>();
for (String message : this.messages) {
list.add(TextUtils.formatText(message));
}
return list;
}
public void saveSetting(String key, List<String> list) {