Add Tabcomplete Cache for Schematic Node
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
15a35ca5a7
Commit
f6c8edc45b
@ -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;
|
||||||
@ -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 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 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 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) {
|
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
||||||
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
||||||
@ -504,6 +506,7 @@ public class SchematicNode {
|
|||||||
updateDB.update(name, owner, parent, item, type, rank, id);
|
updateDB.update(name, owner, parent, item, type, rank, id);
|
||||||
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() {
|
||||||
@ -581,12 +584,21 @@ 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);
|
||||||
}
|
}
|
||||||
|
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("/")) {
|
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);
|
||||||
@ -598,6 +610,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(s, list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren