Merge pull request 'tab_cache' (#173) from tab_cache into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #173 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
191fd779fc
@ -22,6 +22,7 @@ package de.steamwar.sql;
|
|||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.WorldEditWrapper;
|
import de.steamwar.core.WorldEditWrapper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -375,6 +376,7 @@ public class SchematicNode {
|
|||||||
Provider.impl.updateSchematicNode(this);
|
Provider.impl.updateSchematicNode(this);
|
||||||
this.lastUpdate = Timestamp.from(Instant.now());
|
this.lastUpdate = Timestamp.from(Instant.now());
|
||||||
this.brCache.clear();
|
this.brCache.clear();
|
||||||
|
TAB_CACHE.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
@ -437,12 +439,23 @@ public class SchematicNode {
|
|||||||
return node.getId() == id;
|
return node.getId() == id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static final Map<Integer, Map<String, List<String>>> TAB_CACHE = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), TAB_CACHE::clear, 20L * 30, 20L * 30);
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> getNodeTabcomplete(SteamwarUser user, String s) {
|
public static List<String> getNodeTabcomplete(SteamwarUser user, String s) {
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
boolean sws = s.startsWith("/");
|
boolean sws = s.startsWith("/");
|
||||||
if (sws) {
|
if (sws) {
|
||||||
s = s.substring(1);
|
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<String> list = new ArrayList<>();
|
||||||
if (s.contains("/")) {
|
if (s.contains("/")) {
|
||||||
String preTab = s.substring(0, s.lastIndexOf("/") + 1);
|
String preTab = s.substring(0, s.lastIndexOf("/") + 1);
|
||||||
SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab);
|
SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab);
|
||||||
@ -454,6 +467,7 @@ public class SchematicNode {
|
|||||||
nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : "")));
|
nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : "")));
|
||||||
}
|
}
|
||||||
list.remove("//copy");
|
list.remove("//copy");
|
||||||
|
Objects.requireNonNull(TAB_CACHE.putIfAbsent(user.getId(), new HashMap<>())).putIfAbsent(cacheKey, list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren