diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 34439ea..9a90105 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -22,6 +22,7 @@ package de.steamwar.sql; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; import de.steamwar.core.WorldEditWrapper; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.io.ByteArrayInputStream; @@ -375,6 +376,7 @@ public class SchematicNode { Provider.impl.updateSchematicNode(this); this.lastUpdate = Timestamp.from(Instant.now()); this.brCache.clear(); + TAB_CACHE.clear(); } public void delete() { @@ -437,12 +439,23 @@ public class SchematicNode { return node.getId() == id; } + protected static final Map>> TAB_CACHE = new HashMap<>(); + + static { + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), TAB_CACHE::clear, 20L * 30, 20L * 30); + } + public static List getNodeTabcomplete(SteamwarUser user, String s) { - List list = new ArrayList<>(); boolean sws = s.startsWith("/"); if (sws) { s = s.substring(1); } + int index = s.lastIndexOf("/"); + String cacheKey = index == -1 ? "" : s.substring(0, index); + if(TAB_CACHE.containsKey(user.getId()) && TAB_CACHE.get(user.getId()).containsKey(cacheKey)) { + return new ArrayList<>(TAB_CACHE.get(user.getId()).get(cacheKey)); + } + List list = new ArrayList<>(); if (s.contains("/")) { String preTab = s.substring(0, s.lastIndexOf("/") + 1); SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab); @@ -454,6 +467,7 @@ public class SchematicNode { nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : ""))); } list.remove("//copy"); + Objects.requireNonNull(TAB_CACHE.putIfAbsent(user.getId(), new HashMap<>())).putIfAbsent(cacheKey, list); return list; }