From c74c8e4e28bcbb81a8d40d2d52cee9d809099016 Mon Sep 17 00:00:00 2001 From: RoinujNosde Date: Sun, 19 May 2024 22:58:16 -0300 Subject: [PATCH 1/3] perf: changed warriors collection from hashset to hashmap --- .../managers/DatabaseManager.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java b/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java index 2dfb3da..e17cbd9 100644 --- a/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java +++ b/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java @@ -69,7 +69,7 @@ public class DatabaseManager { private Connection connection; private final Map groups = new HashMap<>(); - private final Set warriors = new HashSet<>(); + private final Map warriors = new HashMap<>(); private final List winners = new ArrayList<>(); private enum CountType { @@ -315,24 +315,17 @@ public GroupData getGroupData(@NotNull String id) { @NotNull public Warrior getWarrior(@NotNull OfflinePlayer player) { - UUID uuid = player.getUniqueId(); - for (Warrior warrior : warriors) { - if (warrior.toPlayer().getUniqueId().equals(uuid)) { - if (player instanceof Player) { - warrior.setOnlinePlayer((Player) player); - } - return warrior; - } - } - - Warrior warrior = new Warrior(player, plugin::getGroupManager); - warriors.add(warrior); - return warrior; + return getWarrior(player.getUniqueId()); } @NotNull public Warrior getWarrior(@NotNull UUID uuid) { - return getWarrior(Bukkit.getOfflinePlayer(uuid)); + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); + Warrior warrior = warriors.computeIfAbsent(uuid, (id) -> new Warrior(offlinePlayer, plugin::getGroupManager)); + if (offlinePlayer instanceof Player) { + warrior.setOnlinePlayer((Player) offlinePlayer); + } + return warrior; } private void loopThroughGroups() { @@ -390,7 +383,7 @@ private void loopThroughWarriors() { Warrior warrior = new Warrior(player, plugin::getGroupManager, playerData.get(CountType.KILLS), playerData.get(CountType.DEATHS), playerData.get(CountType.VICTORIES)); - warriors.add(warrior); + warriors.put(warrior.getUniqueId(), warrior); } @@ -562,7 +555,7 @@ public Winners getWinners(Date date) { } public Set getWarriors() { - return Collections.unmodifiableSet(warriors); + return new HashSet<>(warriors.values()); } public Map getGroups() { From d8cfc7d05811678bf4bc6ab2946e10bf4f56a56a Mon Sep 17 00:00:00 2001 From: RoinujNosde Date: Sun, 4 Aug 2024 21:28:32 -0300 Subject: [PATCH 2/3] build: updated item-nbt-api to 2.13.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 02d7ae3..8ce1e19 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,7 @@ de.tr7zw item-nbt-api - 2.12.0-SNAPSHOT + 2.13.1-SNAPSHOT org.bstats From 1a0349c8b3b099da4292859598a760f0a0c88596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o?= <142264317+leogianfagna@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:55:00 -0300 Subject: [PATCH 3/3] fix: updated NBT usage to fix kits on 1.21 (#128) --- pom.xml | 6 +++--- .../java/me/roinujnosde/titansbattle/types/Kit.java | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 8ce1e19..08ab049 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ com.google.code.gson gson - 2.9.0 + 2.11.0 net.sacredlabyrinth.phaed.simpleclans @@ -163,7 +163,7 @@ de.tr7zw item-nbt-api - 2.13.1-SNAPSHOT + 2.13.2 org.bstats @@ -184,4 +184,4 @@ https://repo.roinujnosde.me/snapshots/ - \ No newline at end of file + diff --git a/src/main/java/me/roinujnosde/titansbattle/types/Kit.java b/src/main/java/me/roinujnosde/titansbattle/types/Kit.java index 73f7089..959b56a 100644 --- a/src/main/java/me/roinujnosde/titansbattle/types/Kit.java +++ b/src/main/java/me/roinujnosde/titansbattle/types/Kit.java @@ -1,6 +1,8 @@ package me.roinujnosde.titansbattle.types; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT; + import org.bukkit.Material; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; @@ -12,6 +14,7 @@ import java.util.Map; import java.util.TreeMap; +import java.util.function.Consumer; @SerializableAs("kit") public class Kit implements ConfigurationSerializable { @@ -138,10 +141,14 @@ private ItemStack getItem(Object object) { return clone((ItemStack) object); } + private void applyNBTTag(ItemStack item) { + NBT.modify(item, (Consumer) nbtItem -> nbtItem.setBoolean(NBT_TAG, true)); + } + private ItemStack clone(ItemStack item) { if (item != null && item.getType() != Material.AIR) { item = item.clone(); - new NBTItem(item, true).setBoolean(NBT_TAG, true); + applyNBTTag(item); } return item; } @@ -149,7 +156,7 @@ private ItemStack clone(ItemStack item) { private void setNBTTag(ItemStack[] items) { for (ItemStack item : items) { if (item != null && item.getType() != Material.AIR) { - new NBTItem(item, true).setBoolean(NBT_TAG, true); + applyNBTTag(item); } } }