tab_cache #173
@ -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;
|
||||
@ -65,6 +66,7 @@ public class SchematicNode {
|
||||
private static final SQL.Statement updateDatabase = new SQL.Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||
private static final SQL.Statement selSchemData = new SQL.Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
||||
private static final SQL.Statement deleteNode = new SQL.Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
||||
private static String path;
|
||||
|
||||
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
||||
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
||||
@ -504,6 +506,7 @@ public class SchematicNode {
|
||||
updateDB.update(name, owner, parent, item, type, rank, id);
|
||||
this.lastUpdate = Timestamp.from(Instant.now());
|
||||
this.brCache.clear();
|
||||
TAB_CACHE.clear();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
@ -581,12 +584,21 @@ public class SchematicNode {
|
||||
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) {
|
||||
List<String> list = new ArrayList<>();
|
||||
boolean sws = s.startsWith("/");
|
||||
if (sws) {
|
||||
s = s.substring(1);
|
||||
}
|
||||
if(TAB_CACHE.containsKey(user.getId()) && TAB_CACHE.get(user.getId()).containsKey(s)) {
|
||||
return new ArrayList<>(TAB_CACHE.get(user.getId()).get(s));
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
if (s.contains("/")) {
|
||||
String preTab = s.substring(0, s.lastIndexOf("/") + 1);
|
||||
SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab);
|
||||
@ -598,6 +610,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(s, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren