Last Filters in SchematicSelector #247
@ -19,6 +19,9 @@
|
||||
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.*;
|
||||
import lombok.*;
|
||||
@ -374,6 +377,16 @@ public class SchematicSelector {
|
||||
|
||||
if (!filterCache.containsKey(player)) {
|
||||
filterCache.put(player, new SelectorFilter[9]);
|
||||
|
||||
String cfg = UserConfig.getConfig(user.getId(), "selector:filters");
|
||||
|
||||
if (cfg != null) {
|
||||
JsonArray array = JsonParser.parseString(cfg).getAsJsonArray();
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JsonObject object = array.get(i).getAsJsonObject();
|
||||
filterCache.get(player)[i] = new SelectorFilter(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SelectorFilter[] filters = filterCache.get(player);
|
||||
@ -381,7 +394,7 @@ public class SchematicSelector {
|
||||
for (int i = 0; i < filters.length; i++) {
|
||||
SelectorFilter filterCached = filters[i];
|
||||
if (filterCached == null) {
|
||||
inv.setItem(i + 9, new SWItem(Material.BARRIER, "SCHEM_SELECTOR_FILTER_EMPTY", click -> {}));
|
||||
inv.setItem(i + 9, new SWItem(Material.BARRIER, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_EMPTY", player), click -> {}));
|
||||
} else {
|
||||
SWItem item = filterCached.toItemStack(player);
|
||||
item.setEnchanted(filterCached.equals(filter));
|
||||
@ -413,6 +426,14 @@ public class SchematicSelector {
|
||||
filters[0] = filter;
|
||||
|
||||
filterCache.put(player, filters);
|
||||
JsonArray array = new JsonArray();
|
||||
for (SelectorFilter f : filters) {
|
||||
if (f != null) {
|
||||
array.add(f.toJson());
|
||||
}
|
||||
}
|
||||
|
||||
UserConfig.updatePlayerConfig(user.getId(), "selector:filters", array.toString());
|
||||
}
|
||||
|
||||
injectable.onFilterApply(this);
|
||||
@ -526,6 +547,13 @@ public class SchematicSelector {
|
||||
private final SchematicType type;
|
||||
private final Material item;
|
||||
|
||||
public SelectorFilter(JsonObject object) {
|
||||
this.name = object.get("name").isJsonNull() ? null : object.get("name").getAsString();
|
||||
this.owner = object.get("owner").isJsonNull() ? null : object.get("owner").getAsInt();
|
||||
this.type = object.get("type").isJsonNull() ? null : SchematicType.fromDB(object.get("type").getAsString());
|
||||
this.item = object.get("item").isJsonNull() ? null : Material.valueOf(object.get("item").getAsString());
|
||||
}
|
||||
|
||||
public boolean matches(SchematicNode node) {
|
||||
boolean matches = name == null || node.getName().contains(name);
|
||||
|
||||
@ -594,6 +622,16 @@ public class SchematicSelector {
|
||||
return new SWItem(Material.BARRIER, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE_EMPTY", player), Collections.emptyList(), false, click -> {});
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject toJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("name", name);
|
||||
object.addProperty("owner", owner);
|
||||
object.addProperty("type", type == null?null:type.toDB());
|
||||
object.addProperty("item", item == null?null:item.name());
|
||||
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
public enum PublicMode {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren