Dieser Commit ist enthalten in:
Ursprung
acd9f2588c
Commit
e92a3f7369
@ -241,7 +241,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
|
|||||||
try{
|
try{
|
||||||
return Material.valueOf(material);
|
return Material.valueOf(material);
|
||||||
}catch(IllegalArgumentException e){
|
}catch(IllegalArgumentException e){
|
||||||
return renamedLegacy.get(material);
|
return renamedLegacy.getOrDefault(material, Material.STONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class TypeUtils {
|
|||||||
SWCommandUtils.addMapper(SchematicNode.class, new TypeMapper<SchematicNode>() {
|
SWCommandUtils.addMapper(SchematicNode.class, new TypeMapper<SchematicNode>() {
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
return SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s);
|
return SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,10 +20,7 @@
|
|||||||
package de.steamwar.inventory;
|
package de.steamwar.inventory;
|
||||||
|
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.sql.NodeMember;
|
import de.steamwar.sql.*;
|
||||||
import de.steamwar.sql.SchematicNode;
|
|
||||||
import de.steamwar.sql.SchematicType;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -241,11 +238,15 @@ public class SchematicSelector {
|
|||||||
name = name.replace(filter.getName(), Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_REPLACE", player, filter.getName()));
|
name = name.replace(filter.getName(), Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_REPLACE", player, filter.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name())), !node.isDir() && !node.getSchemtype().writeable(), click -> {
|
String finalName = name;
|
||||||
|
SWItem item = node.getSchematic().map(schematicNodeSchematic ->
|
||||||
|
new SWItem(m, finalName, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, schematicNodeSchematic.getSchemtype().name())), !node.isDir() && !schematicNodeSchematic.getSchemtype().writeable(), click -> {
|
||||||
|
})).orElseGet(() ->
|
||||||
|
new SWItem(m, finalName, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)), false, click -> {
|
||||||
|
}));
|
||||||
|
node.getSchematic().map(sNode -> sNode.getRank() > 0 ? sNode : null).ifPresent(sNode -> {
|
||||||
|
item.setLore(Arrays.asList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, sNode.getSchemtype().name()), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player, sNode.getRank())));
|
||||||
});
|
});
|
||||||
if(!node.isDir() && node.getRank() > 0) {
|
|
||||||
item.setLore(Arrays.asList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name()), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player, node.getRank())));
|
|
||||||
}
|
|
||||||
return new SWListInv.SWListEntry<>(item, node);
|
return new SWListInv.SWListEntry<>(item, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +388,7 @@ public class SchematicSelector {
|
|||||||
nodes.removeIf(node -> !node.isDir());
|
nodes.removeIf(node -> !node.isDir());
|
||||||
}
|
}
|
||||||
if(target.target == Target.SCHEMATIC_TYPE) {
|
if(target.target == Target.SCHEMATIC_TYPE) {
|
||||||
nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type));
|
nodes.removeIf(node -> node.getSchematic().map(SchematicNode.SchematicNodeSchematic::getSchemtype).map(type -> type != filter.getType()).orElse(true));
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
@ -406,12 +407,7 @@ public class SchematicSelector {
|
|||||||
case SCHEMATIC_TYPE:
|
case SCHEMATIC_TYPE:
|
||||||
nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(user.getId(), target.type.toDB(), parent==null?0:parent.getId()));
|
nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(user.getId(), target.type.toDB(), parent==null?0:parent.getId()));
|
||||||
if(target.rank >= 0) {
|
if(target.rank >= 0) {
|
||||||
nodes.removeIf(node -> {
|
nodes.removeIf(node -> node.getSchematic().map(SchematicNode.SchematicNodeSchematic::getRank).map(rank -> rank < target.rank).orElse(true));
|
||||||
if(node.isDir()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return node.getRank() > target.rank;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -425,10 +421,7 @@ public class SchematicSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static SchematicNode getParent(SchematicNode node) {
|
private static SchematicNode getParent(SchematicNode node) {
|
||||||
if(node.getParent() == null) {
|
return node.getParentNode().orElse(null);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return node.getParentNode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SelectorTarget selectSchematic() {
|
public static SelectorTarget selectSchematic() {
|
||||||
@ -504,7 +497,7 @@ public class SchematicSelector {
|
|||||||
matches = false;
|
matches = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) {
|
if(type != null && node.getSchematic().map(SchematicNode.SchematicNodeSchematic::getSchemtype).map(type::equals).orElse(false)) {
|
||||||
matches = false;
|
matches = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,7 +529,8 @@ public class SchematicSelector {
|
|||||||
if(o1.isDir() || o2.isDir()) {
|
if(o1.isDir() || o2.isDir()) {
|
||||||
return Boolean.compare(o1.isDir(), o2.isDir());
|
return Boolean.compare(o1.isDir(), o2.isDir());
|
||||||
} else {
|
} else {
|
||||||
return o1.getSchemtype().name().compareTo(o2.getSchemtype().name());
|
// Unclean, but it works
|
||||||
|
return o1.getSchematic().get().getSchemtype().name().compareTo(o2.getSchematic().get().getSchemtype().name());
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
LAST_UPDATED(SWItem.getMaterial("WATCH"), "SCHEM_SELECTOR_SORTING_UPDATE", Comparator.comparing(SchematicNode::getLastUpdate));
|
LAST_UPDATED(SWItem.getMaterial("WATCH"), "SCHEM_SELECTOR_SORTING_UPDATE", Comparator.comparing(SchematicNode::getLastUpdate));
|
||||||
|
@ -21,6 +21,7 @@ package de.steamwar.sql;
|
|||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CheckedSchematic {
|
public class CheckedSchematic {
|
||||||
@ -75,11 +76,11 @@ public class CheckedSchematic {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSchemName() {
|
public Optional<String> getSchemName() {
|
||||||
return SchematicNode.getSchematicNode(node).getName();
|
return SchematicNode.getSchematicNode(node).map(SchematicNode::getName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSchemOwner() {
|
public Optional<Integer> getSchemOwner() {
|
||||||
return SchematicNode.getSchematicNode(node).getId();
|
return SchematicNode.getSchematicNode(node).map(SchematicNode::getOwner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,7 @@ import de.steamwar.core.Core;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public interface Provider {
|
public interface Provider {
|
||||||
@ -85,12 +82,12 @@ public interface Provider {
|
|||||||
void removePlayerConfig(int id, String config);
|
void removePlayerConfig(int id, String config);
|
||||||
|
|
||||||
void createSchematicNode(int owner, String name, Integer parent, String type, String item);
|
void createSchematicNode(int owner, String name, Integer parent, String type, String item);
|
||||||
SchematicNode getSchematicNode(int owner, String name, Integer parent);
|
Optional<SchematicNode> getSchematicNode(int owner, String name, Integer parent);
|
||||||
List<SchematicNode> getSchematicNodeInNode(Integer parent);
|
List<SchematicNode> getSchematicNodeInNode(Integer parent);
|
||||||
List<SchematicNode> getSchematicDirectoryInNode(Integer parent);
|
List<SchematicNode> getSchematicDirectoryInNode(Integer parent);
|
||||||
SchematicNode getSchematicDirectory(String name, Integer parent);
|
Optional<SchematicNode> getSchematicDirectory(String name, Integer parent);
|
||||||
SchematicNode getSchematicNode(String name, Integer parent);
|
Optional<SchematicNode> getSchematicNode(String name, Integer parent);
|
||||||
SchematicNode getSchematicNode(int id);
|
Optional<SchematicNode> getSchematicNode(int id);
|
||||||
List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent);
|
List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent);
|
||||||
List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType);
|
List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType);
|
||||||
List<SchematicNode> getAllSchematicsOfType(int owner, String schemType);
|
List<SchematicNode> getAllSchematicsOfType(int owner, String schemType);
|
||||||
|
@ -409,7 +409,8 @@ public class SQLProvider implements Provider {
|
|||||||
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
||||||
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
||||||
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
||||||
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ?, ReplaceColor = ?, AllowReplay = ? WHERE NodeId = ?");
|
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ? WHERE NodeId = ?");
|
||||||
|
private static final Statement updateSchematicDB = new Statement("UPDATE SchematicNode SET NodeType = ?, NodeRank = ?, ReplaceColor = ?, AllowReplay = ? WHERE NodeId = ?");
|
||||||
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||||
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
||||||
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
||||||
@ -422,11 +423,11 @@ public class SQLProvider implements Provider {
|
|||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
private static final Statement.ResultSetUser<SchematicNode> toSchematicNode = rs -> {
|
private static final Statement.ResultSetUser<Optional<SchematicNode>> toSchematicNode = rs -> {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return nodeFromResultSet(rs);
|
return Optional.of(nodeFromResultSet(rs));
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
};
|
};
|
||||||
|
|
||||||
private static SchematicNode nodeFromResultSet(ResultSet rs) throws SQLException {
|
private static SchematicNode nodeFromResultSet(ResultSet rs) throws SQLException {
|
||||||
@ -435,7 +436,7 @@ public class SQLProvider implements Provider {
|
|||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
String type = rs.getString("NodeType");
|
String type = rs.getString("NodeType");
|
||||||
return new SchematicNode(
|
return SchematicNode.constructSchematicNode(
|
||||||
rs.getInt("NodeId"),
|
rs.getInt("NodeId"),
|
||||||
rs.getInt("NodeOwner"),
|
rs.getInt("NodeOwner"),
|
||||||
rs.getString("NodeName"),
|
rs.getString("NodeName"),
|
||||||
@ -457,7 +458,7 @@ public class SQLProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
public Optional<SchematicNode> getSchematicNode(int owner, String name, Integer parent) {
|
||||||
|
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
return getSchematicNode_Null.select(toSchematicNode, owner, name);
|
return getSchematicNode_Null.select(toSchematicNode, owner, name);
|
||||||
@ -485,14 +486,14 @@ public class SQLProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
public Optional<SchematicNode> getSchematicDirectory(String name, Integer parent) {
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
Statement.ResultSetUser<Optional<SchematicNode>> user = rs -> {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
SchematicNode node = nodeFromResultSet(rs);
|
SchematicNode node = nodeFromResultSet(rs);
|
||||||
if(node.isDir())
|
if(node.isDir())
|
||||||
return node;
|
return Optional.of(node);
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
};
|
};
|
||||||
|
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
@ -503,7 +504,7 @@ public class SQLProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicNode(String name, Integer parent) {
|
public Optional<SchematicNode> getSchematicNode(String name, Integer parent) {
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
return getSchematicNodeO_Null.select(toSchematicNode, name);
|
return getSchematicNodeO_Null.select(toSchematicNode, name);
|
||||||
}else {
|
}else {
|
||||||
@ -512,12 +513,8 @@ public class SQLProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicNode(int id) {
|
public Optional<SchematicNode> getSchematicNode(int id) {
|
||||||
return getSchematicNodeId.select(rs -> {
|
return getSchematicNodeId.select(toSchematicNode, id);
|
||||||
if (!rs.next())
|
|
||||||
return null;
|
|
||||||
return nodeFromResultSet(rs);
|
|
||||||
}, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -591,12 +588,19 @@ public class SQLProvider implements Provider {
|
|||||||
node.getOwner(),
|
node.getOwner(),
|
||||||
node.getParent(),
|
node.getParent(),
|
||||||
node.getItem(),
|
node.getItem(),
|
||||||
node.getType(),
|
|
||||||
node.getRankUnsafe(),
|
|
||||||
node.replaceColor(),
|
|
||||||
node.allowReplay(),
|
|
||||||
node.getId()
|
node.getId()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
node.getSchematic().ifPresent(schematicNodeSchematic -> {
|
||||||
|
SchematicNode.SchematicNodeSchematic.Unsafe unsafe = schematicNodeSchematic.unsafe();
|
||||||
|
updateSchematicDB.update(
|
||||||
|
unsafe.getType(),
|
||||||
|
schematicNodeSchematic.getRank(),
|
||||||
|
schematicNodeSchematic.replaceColor(),
|
||||||
|
schematicNodeSchematic.allowReplay(),
|
||||||
|
node.getId()
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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 lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -35,125 +36,137 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class SchematicNode {
|
public class SchematicNode {
|
||||||
|
protected static final Map<Integer, Map<String, List<String>>> TAB_CACHE = new HashMap<>();
|
||||||
|
|
||||||
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
static {
|
||||||
|
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), TAB_CACHE::clear, 20L * 30, 20L * 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NonNull SchematicNode createSchematic(int owner, @NonNull String name, Integer parent) {
|
||||||
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode createSchematicDirectory(int owner, String name, Integer parent) {
|
public static @NonNull SchematicNode createSchematicDirectory(int owner, @NonNull String name, Integer parent) {
|
||||||
return createSchematicNode(owner, name, parent, null, "");
|
return createSchematicNode(owner, name, parent, null, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
public static @NonNull SchematicNode createSchematicNode(int owner, @NonNull String name, Integer parent, String type, @NonNull String item) {
|
||||||
if (parent != null && parent == 0)
|
|
||||||
parent = null;
|
|
||||||
Provider.impl.createSchematicNode(owner, name, parent, type, item);
|
Provider.impl.createSchematicNode(owner, name, parent, type, item);
|
||||||
return getSchematicNode(owner, name, parent);
|
return getSchematicNode(owner, name, parent).orElseThrow(() -> new IllegalStateException("Could not create schematic node"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
public static Optional<SchematicNode> getSchematicNode(int owner, @NonNull String name, @NonNull SchematicNode parent) {
|
||||||
return getSchematicNode(owner, name, parent.getId());
|
return getSchematicNode(owner, name, parent.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SchematicNode constructSchematicNode(
|
||||||
|
int id,
|
||||||
|
int owner,
|
||||||
|
@NonNull String name,
|
||||||
|
Integer parent,
|
||||||
|
@NonNull String item,
|
||||||
|
String type,
|
||||||
|
boolean isDir,
|
||||||
|
int rank,
|
||||||
|
@NonNull Timestamp lastUpdate,
|
||||||
|
boolean schemFormat,
|
||||||
|
boolean replaceColor,
|
||||||
|
boolean allowReplay
|
||||||
|
) {
|
||||||
|
if(isDir) {
|
||||||
|
return new SchematicNode(id, owner, name, parent, item, true, lastUpdate);
|
||||||
|
} else {
|
||||||
|
return new SchematicNodeSchematic(id, owner, name, parent, item, type, rank, lastUpdate, schemFormat, replaceColor, allowReplay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SchematicNode(
|
public SchematicNode(
|
||||||
int id,
|
int id,
|
||||||
int owner,
|
int owner,
|
||||||
String name,
|
@NonNull String name,
|
||||||
Integer parent,
|
@NonNull Integer parent,
|
||||||
String item,
|
@NonNull String item,
|
||||||
String type,
|
|
||||||
boolean isDir,
|
boolean isDir,
|
||||||
int rank,
|
@NonNull Timestamp lastUpdate
|
||||||
Timestamp lastUpdate,
|
|
||||||
boolean schemFormat,
|
|
||||||
boolean replaceColor,
|
|
||||||
boolean allowReplay
|
|
||||||
) {
|
) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.type = type;
|
|
||||||
this.lastUpdate = lastUpdate;
|
this.lastUpdate = lastUpdate;
|
||||||
this.isDir = isDir;
|
this.isDir = isDir;
|
||||||
if (!isDir) {
|
|
||||||
this.schemFormat = schemFormat;
|
|
||||||
this.rank = rank;
|
|
||||||
this.replaceColor = replaceColor;
|
|
||||||
this.allowReplay = allowReplay;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicNodeInNode(SchematicNode parent) {
|
public static @NonNull List<SchematicNode> getSchematicNodeInNode(@NonNull SchematicNode parent) {
|
||||||
return getSchematicNodeInNode(parent.getId());
|
return getSchematicNodeInNode(parent.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicDirectory(String name, SchematicNode parent) {
|
public static @NonNull Optional<SchematicNode> getSchematicDirectory(@NonNull String name, @NonNull SchematicNode parent) {
|
||||||
return getSchematicDirectory(name, parent.getId());
|
return getSchematicDirectory(name, parent.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
public static @NonNull Optional<SchematicNode> getSchematicNode(int owner, @NonNull String name, Integer parent) {
|
||||||
if (parent != null && parent == 0) {
|
if (parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
return Provider.impl.getSchematicNode(owner, name, parent);
|
return Provider.impl.getSchematicNode(owner, name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
public static @NonNull List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
if(parent != null && parent == 0) {
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
return Provider.impl.getSchematicNodeInNode(parent);
|
return Provider.impl.getSchematicNodeInNode(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
public static @NonNull List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||||
if(parent != null && parent == 0) {
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
return Provider.impl.getSchematicDirectoryInNode(parent);
|
return Provider.impl.getSchematicDirectoryInNode(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
public static @NonNull Optional<SchematicNode> getSchematicDirectory(@NonNull String name, Integer parent) {
|
||||||
if(parent != null && parent == 0) {
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
return Provider.impl.getSchematicDirectory(name, parent);
|
return Provider.impl.getSchematicDirectory(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(String name, Integer parent) {
|
public static @NonNull Optional<SchematicNode> getSchematicNode(@NonNull String name, Integer parent) {
|
||||||
if(parent != null && parent == 0) {
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
return Provider.impl.getSchematicNode(name, parent);
|
return Provider.impl.getSchematicNode(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int id) {
|
public static @NonNull Optional<SchematicNode> getSchematicNode(int id) {
|
||||||
return Provider.impl.getSchematicNode(id);
|
return Provider.impl.getSchematicNode(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
public static @NonNull List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, @NonNull String schemType, Integer parent) {
|
||||||
return Provider.impl.getAccessibleSchematicsOfTypeInParent(owner, schemType, parent);
|
return Provider.impl.getAccessibleSchematicsOfTypeInParent(owner, schemType, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
public static @NonNull List<SchematicNode> getAllAccessibleSchematicsOfType(int user, @NonNull String schemType) {
|
||||||
return Provider.impl.getAllAccessibleSchematicsOfType(user, schemType);
|
return Provider.impl.getAllAccessibleSchematicsOfType(user, schemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
public static @NonNull List<SchematicNode> getAllSchematicsOfType(int owner, @NonNull String schemType) {
|
||||||
return Provider.impl.getAllSchematicsOfType(owner, schemType);
|
return Provider.impl.getAllSchematicsOfType(owner, schemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
public static @NonNull List<SchematicNode> getAllSchematicsOfType(@NonNull String schemType) {
|
||||||
return Provider.impl.getAllSchematicsOfType(schemType);
|
return Provider.impl.getAllSchematicsOfType(schemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(SchematicType schemType) {
|
public static @NonNull List<SchematicNode> getAllSchematicsOfType(@NonNull SchematicType schemType) {
|
||||||
return Provider.impl.getAllSchematicsOfType(schemType.toDB());
|
return Provider.impl.getAllSchematicsOfType(schemType.toDB());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
|
public static @NonNull List<SchematicNode> deepGet(Integer parent, @NonNull Predicate<SchematicNode> filter) {
|
||||||
List<SchematicNode> finalList = new ArrayList<>();
|
List<SchematicNode> finalList = new ArrayList<>();
|
||||||
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(parent);
|
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(parent);
|
||||||
nodes.forEach(node -> {
|
nodes.forEach(node -> {
|
||||||
@ -167,53 +180,54 @@ public class SchematicNode {
|
|||||||
return finalList;
|
return finalList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
public static @NonNull List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
return Provider.impl.getSchematicsAccessibleByUser(user, parent);
|
return Provider.impl.getSchematicsAccessibleByUser(user, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
public static @NonNull List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
return Provider.impl.getAllSchematicsAccessibleByUser(user);
|
return Provider.impl.getAllSchematicsAccessibleByUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
public static @NonNull List<SchematicNode> getAllParentsOfNode(@NonNull SchematicNode node) {
|
||||||
return getAllParentsOfNode(node.getId());
|
return getAllParentsOfNode(node.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
public static @NonNull List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
return Provider.impl.getAllParentsOfNode(node);
|
return Provider.impl.getAllParentsOfNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getNodeFromPath(SteamwarUser user, String s) {
|
public static @NonNull Optional<SchematicNode> getNodeFromPath(@NonNull SteamwarUser user, @NonNull String s) {
|
||||||
if (s.startsWith("/")) {
|
if (s.startsWith("/")) {
|
||||||
s = s.substring(1);
|
s = s.substring(1);
|
||||||
}
|
}
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
if (s.contains("/")) {
|
if (s.contains("/")) {
|
||||||
String[] layers = s.split("/");
|
String[] layers = s.split("/");
|
||||||
SchematicNode currentNode = null;
|
Optional<SchematicNode> currentNode = Optional.empty();
|
||||||
for (int i = 0; i < layers.length; i++) {
|
for (int i = 0; i < layers.length; i++) {
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
Optional<SchematicNode> node;
|
Optional<SchematicNode> node;
|
||||||
if (currentNode == null) {
|
if (!currentNode.isPresent()) {
|
||||||
node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
|
node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
|
||||||
} else {
|
} else {
|
||||||
node = Optional.ofNullable(SchematicNode.getSchematicNode(layers[i], currentNode.getId()));
|
node = SchematicNode.getSchematicNode(layers[i], currentNode.get().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.isPresent()) {
|
if (!node.isPresent()) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
} else {
|
} else {
|
||||||
currentNode = node.get();
|
currentNode = node;
|
||||||
if (!currentNode.isDir() && i != layers.length - 1) {
|
if (!currentNode.map(SchematicNode::isDir).orElse(false) && i != layers.length - 1) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return currentNode;
|
return currentNode;
|
||||||
} else {
|
} else {
|
||||||
String finalS = s;
|
String finalS = s;
|
||||||
return SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(finalS)).findAny().orElse(null);
|
return SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(finalS)).findAny();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,16 +236,11 @@ public class SchematicNode {
|
|||||||
private String name;
|
private String name;
|
||||||
private Integer parent;
|
private Integer parent;
|
||||||
private String item;
|
private String item;
|
||||||
private String type;
|
|
||||||
private boolean replaceColor;
|
|
||||||
private boolean allowReplay;
|
|
||||||
private boolean schemFormat;
|
|
||||||
private int rank;
|
|
||||||
private Timestamp lastUpdate;
|
private Timestamp lastUpdate;
|
||||||
private final boolean isDir;
|
private final boolean isDir;
|
||||||
private Map<Integer, String> brCache = new HashMap<>();
|
private Map<Integer, String> brCache = new HashMap<>();
|
||||||
|
|
||||||
public static List<SchematicNode> filterSchems(int user, Predicate<SchematicNode> filter) {
|
public static @NonNull List<SchematicNode> filterSchems(int user, @NonNull Predicate<SchematicNode> filter) {
|
||||||
List<SchematicNode> finalList = new ArrayList<>();
|
List<SchematicNode> finalList = new ArrayList<>();
|
||||||
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user, null);
|
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user, null);
|
||||||
nodes.forEach(node -> {
|
nodes.forEach(node -> {
|
||||||
@ -245,7 +254,7 @@ public class SchematicNode {
|
|||||||
return finalList;
|
return finalList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer countNodes() {
|
public static @NonNull Integer countNodes() {
|
||||||
return Provider.impl.countNodes();
|
return Provider.impl.countNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,17 +266,17 @@ public class SchematicNode {
|
|||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public @NonNull String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(@NonNull String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
updateDB();
|
updateDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getParent() {
|
public @NonNull Optional<Integer> getParent() {
|
||||||
return parent;
|
return Optional.ofNullable(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParent(Integer parent) {
|
public void setParent(Integer parent) {
|
||||||
@ -275,73 +284,24 @@ public class SchematicNode {
|
|||||||
updateDB();
|
updateDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getItem() {
|
public @NonNull String getItem() {
|
||||||
if (item.isEmpty()) {
|
if (item.isEmpty()) {
|
||||||
return isDir ? "CHEST" : "CAULDRON_ITEM";
|
return isDir ? "CHEST" : "CAULDRON_ITEM";
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItem(String item) {
|
public void setItem(@NonNull String item) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
updateDB();
|
updateDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setType(String type) {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
this.type = type;
|
|
||||||
updateDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDir() {
|
public boolean isDir() {
|
||||||
return isDir;
|
return isDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSchemFormat() {
|
public @NonNull Optional<SchematicNode> getParentNode() {
|
||||||
if(isDir)
|
if(parent == null) return Optional.empty();
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
return schemFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRank() {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
return rank;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public int getRankUnsafe() {
|
|
||||||
return rank;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRank(int rank) {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
this.rank = rank;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SchematicType getSchemtype() {
|
|
||||||
if(isDir())
|
|
||||||
throw new SecurityException("Is Directory");
|
|
||||||
return SchematicType.fromDB(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSchemtype(SchematicType type) {
|
|
||||||
if(isDir())
|
|
||||||
throw new SecurityException("Is Directory");
|
|
||||||
this.type = type.toDB();
|
|
||||||
updateDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SchematicNode getParentNode() {
|
|
||||||
if(parent == null) return null;
|
|
||||||
return SchematicNode.getSchematicNode(parent);
|
return SchematicNode.getSchematicNode(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,27 +309,31 @@ public class SchematicNode {
|
|||||||
return NodeMember.getNodeMember(id, user) != null;
|
return NodeMember.getNodeMember(id, user) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<NodeMember> getMembers() {
|
public @NonNull Set<NodeMember> getMembers() {
|
||||||
return NodeMember.getNodeMembers(id);
|
return NodeMember.getNodeMembers(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getLastUpdate() {
|
public @NonNull Timestamp getLastUpdate() {
|
||||||
return lastUpdate;
|
return lastUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateBreadcrumbs(SteamwarUser user) {
|
public @NonNull Optional<SchematicNodeSchematic> getSchematic() {
|
||||||
|
return Optional.of(isDir).map(dir -> dir ? null : (SchematicNodeSchematic) this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NonNull String generateBreadcrumbs(@NonNull SteamwarUser user) {
|
||||||
return brCache.computeIfAbsent(user.getId(), integer -> generateBreadcrumbs("/", user));
|
return brCache.computeIfAbsent(user.getId(), integer -> generateBreadcrumbs("/", user));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateBreadcrumbs(String split, SteamwarUser user) {
|
public @NonNull String generateBreadcrumbs(@NonNull String split, @NonNull SteamwarUser user) {
|
||||||
StringBuilder builder = new StringBuilder(getName());
|
StringBuilder builder = new StringBuilder(getName());
|
||||||
SchematicNode currentNode = this;
|
SchematicNode currentNode = this;
|
||||||
if (currentNode.isDir()) builder.append("/");
|
if (currentNode.isDir()) builder.append(split);
|
||||||
final Set<NodeMember> nodeMembers = NodeMember.getSchematics(user.getId());
|
final Set<NodeMember> nodeMembers = NodeMember.getSchematics(user.getId());
|
||||||
AtomicInteger i = new AtomicInteger();
|
AtomicInteger i = new AtomicInteger();
|
||||||
i.set(currentNode.getId());
|
i.set(currentNode.getId());
|
||||||
while (currentNode.getParentNode() != null && nodeMembers.stream().noneMatch(nodeMember -> nodeMember.getNode() == i.get())) {
|
while (currentNode.getParentNode().isPresent() && nodeMembers.stream().noneMatch(nodeMember -> nodeMember.getNode() == i.get())) {
|
||||||
currentNode = currentNode.getParentNode();
|
currentNode = currentNode.getParentNode().get();
|
||||||
i.set(currentNode.getId());
|
i.set(currentNode.getId());
|
||||||
builder.insert(0, split)
|
builder.insert(0, split)
|
||||||
.insert(0, currentNode.getName());
|
.insert(0, currentNode.getName());
|
||||||
@ -377,7 +341,7 @@ public class SchematicNode {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDB() {
|
protected void updateDB() {
|
||||||
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();
|
||||||
@ -388,53 +352,6 @@ public class SchematicNode {
|
|||||||
Provider.impl.deleteSchematicNode(this);
|
Provider.impl.deleteSchematicNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream schemData() throws IOException {
|
|
||||||
return Provider.impl.getSchematicData(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Clipboard load() throws IOException, NoClipboardException {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
return WorldEditWrapper.impl.getClipboard(schemData(), schemFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), schemFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
saveFromPlayer(player, Core.getVersion() > 12);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveFromBytes(byte[] bytes, boolean newFormat) {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
updateDatabase(new ByteArrayInputStream(bytes), newFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
updateDatabase(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDatabase(InputStream blob, boolean newFormat) {
|
|
||||||
Provider.impl.saveSchematicNode(this, blob, newFormat);
|
|
||||||
schemFormat = newFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) {
|
|
||||||
try {
|
|
||||||
return WorldEditWrapper.impl.getClipboard(is, schemFormat);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new SecurityException("Could not read schem", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof SchematicNode))
|
if (!(obj instanceof SchematicNode))
|
||||||
@ -444,13 +361,7 @@ public class SchematicNode {
|
|||||||
return node.getId() == id;
|
return node.getId() == id;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final Map<Integer, Map<String, List<String>>> TAB_CACHE = new HashMap<>();
|
public static @NonNull List<String> getNodeTabcomplete(@NonNull SteamwarUser user, @NonNull String s) {
|
||||||
|
|
||||||
static {
|
|
||||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), TAB_CACHE::clear, 20L * 30, 20L * 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getNodeTabcomplete(SteamwarUser user, String s) {
|
|
||||||
boolean sws = s.startsWith("/");
|
boolean sws = s.startsWith("/");
|
||||||
if (sws) {
|
if (sws) {
|
||||||
s = s.substring(1);
|
s = s.substring(1);
|
||||||
@ -463,9 +374,9 @@ public class SchematicNode {
|
|||||||
List<String> list = new ArrayList<>();
|
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);
|
Optional<SchematicNode> pa = SchematicNode.getNodeFromPath(user, preTab);
|
||||||
if (pa == null) return Collections.emptyList();
|
if (pa.isPresent()) return Collections.emptyList();
|
||||||
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(pa);
|
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(pa.get());
|
||||||
nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user)));
|
nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user)));
|
||||||
} else {
|
} else {
|
||||||
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0);
|
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0);
|
||||||
@ -477,7 +388,7 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||||
public static boolean invalidSchemName(String[] layers) {
|
public static boolean invalidSchemName(@NonNull String[] layers) {
|
||||||
for (String layer : layers) {
|
for (String layer : layers) {
|
||||||
if (layer.isEmpty()) {
|
if (layer.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
@ -500,13 +411,62 @@ public class SchematicNode {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SchematicNodeSchematic extends SchematicNode {
|
||||||
|
|
||||||
|
private boolean replaceColor;
|
||||||
|
private boolean allowReplay;
|
||||||
|
private boolean schemFormat;
|
||||||
|
private int rank;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public SchematicNodeSchematic(
|
||||||
|
int id,
|
||||||
|
int owner,
|
||||||
|
@NonNull String name,
|
||||||
|
Integer parent,
|
||||||
|
@NonNull String item,
|
||||||
|
@NonNull String type,
|
||||||
|
int rank,
|
||||||
|
@NonNull Timestamp lastUpdate,
|
||||||
|
boolean schemFormat,
|
||||||
|
boolean replaceColor,
|
||||||
|
boolean allowReplay
|
||||||
|
) {
|
||||||
|
super(id, owner, name, parent, item, false, lastUpdate);
|
||||||
|
this.rank = rank;
|
||||||
|
this.schemFormat = schemFormat;
|
||||||
|
this.replaceColor = replaceColor;
|
||||||
|
this.allowReplay = allowReplay;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSchemFormat() {
|
||||||
|
return schemFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRank() {
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRank(int rank) {
|
||||||
|
this.rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SchematicType getSchemtype() {
|
||||||
|
return SchematicType.fromDB(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchemtype(@NonNull SchematicType type) {
|
||||||
|
this.type = type.toDB();
|
||||||
|
updateDB();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean replaceColor() {
|
public boolean replaceColor() {
|
||||||
return replaceColor;
|
return replaceColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplaceColor(boolean replaceColor) {
|
public void setReplaceColor(boolean replaceColor) {
|
||||||
if(isDir())
|
|
||||||
throw new SecurityException("Is Directory");
|
|
||||||
this.replaceColor = replaceColor;
|
this.replaceColor = replaceColor;
|
||||||
updateDB();
|
updateDB();
|
||||||
}
|
}
|
||||||
@ -516,8 +476,6 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAllowReplay(boolean allowReplay) {
|
public void setAllowReplay(boolean allowReplay) {
|
||||||
if(isDir())
|
|
||||||
throw new SecurityException("Is Directory");
|
|
||||||
this.allowReplay = allowReplay;
|
this.allowReplay = allowReplay;
|
||||||
updateDB();
|
updateDB();
|
||||||
}
|
}
|
||||||
@ -525,4 +483,75 @@ public class SchematicNode {
|
|||||||
public int getElo(int season) {
|
public int getElo(int season) {
|
||||||
return Provider.impl.getSchematicElo(this, season);
|
return Provider.impl.getSchematicElo(this, season);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull Unsafe unsafe() {
|
||||||
|
return new Unsafe() {
|
||||||
|
@Override
|
||||||
|
public void setType(@NonNull String type) {
|
||||||
|
SchematicNode.SchematicNodeSchematic.this.type = type;
|
||||||
|
SchematicNode.SchematicNodeSchematic.this.updateDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull String getType() {
|
||||||
|
return SchematicNode.SchematicNodeSchematic.this.type;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Unsafe {
|
||||||
|
public void setType(@NonNull String type);
|
||||||
|
public @NonNull String getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDatabase(@NonNull InputStream blob, boolean newFormat) {
|
||||||
|
Provider.impl.saveSchematicNode(this, blob, newFormat);
|
||||||
|
schemFormat = newFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NonNull Spigot spigot() {
|
||||||
|
return new Spigot() {
|
||||||
|
public @NonNull InputStream schemData() throws IOException {
|
||||||
|
return Provider.impl.getSchematicData(SchematicNode.SchematicNodeSchematic.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NonNull Clipboard load() throws IOException, NoClipboardException {
|
||||||
|
return WorldEditWrapper.impl.getClipboard(schemData(), schemFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadToPlayer(@NonNull Player player) throws IOException, NoClipboardException {
|
||||||
|
WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), schemFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFromPlayer(@NonNull Player player) throws IOException, NoClipboardException {
|
||||||
|
saveFromPlayer(player, Core.getVersion() > 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFromBytes(byte[] bytes, boolean newFormat) {
|
||||||
|
updateDatabase(new ByteArrayInputStream(bytes), newFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFromPlayer(@NonNull Player player, boolean newFormat) throws IOException, NoClipboardException {
|
||||||
|
updateDatabase(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Spigot {
|
||||||
|
@NonNull InputStream schemData() throws IOException;
|
||||||
|
@NonNull Clipboard load() throws IOException, NoClipboardException;
|
||||||
|
void loadToPlayer(@NonNull Player player) throws IOException, NoClipboardException;
|
||||||
|
void saveFromPlayer(@NonNull Player player) throws IOException, NoClipboardException;
|
||||||
|
void saveFromBytes(byte[] bytes, boolean newFormat);
|
||||||
|
void saveFromPlayer(@NonNull Player player, boolean newFormat) throws IOException, NoClipboardException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NonNull Clipboard clipboardFromStream(@NonNull InputStream is, boolean schemFormat) {
|
||||||
|
try {
|
||||||
|
return WorldEditWrapper.impl.getClipboard(is, schemFormat);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException("Could not read schem", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ public class StandaloneProvider implements Provider {
|
|||||||
try (Stream<Path> stream = Files.list(id==null?schematicDir.toPath():nodesToPath.get(id))) {
|
try (Stream<Path> stream = Files.list(id==null?schematicDir.toPath():nodesToPath.get(id))) {
|
||||||
List<SchematicNode> list = stream.map(path -> {
|
List<SchematicNode> list = stream.map(path -> {
|
||||||
File file = path.toFile();
|
File file = path.toFile();
|
||||||
SchematicNode node = new SchematicNode(
|
SchematicNode node = SchematicNode.constructSchematicNode(
|
||||||
nodeId++,
|
nodeId++,
|
||||||
0,
|
0,
|
||||||
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
||||||
@ -268,7 +268,7 @@ public class StandaloneProvider implements Provider {
|
|||||||
File file = p.toFile();
|
File file = p.toFile();
|
||||||
int id = nodeId++;
|
int id = nodeId++;
|
||||||
nodesToPath.put(id, p);
|
nodesToPath.put(id, p);
|
||||||
SchematicNode node = new SchematicNode(
|
SchematicNode node = SchematicNode.constructSchematicNode(
|
||||||
nodeId++,
|
nodeId++,
|
||||||
0,
|
0,
|
||||||
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
||||||
@ -287,8 +287,8 @@ public class StandaloneProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
public Optional<SchematicNode> getSchematicNode(int owner, String name, Integer parent) {
|
||||||
return nodesByParent.get(parent).stream().filter(node -> node.getName().equals(name)).findAny().orElse(null);
|
return nodesByParent.get(parent).stream().filter(node -> node.getName().equals(name)).findAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -302,28 +302,36 @@ public class StandaloneProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
public Optional<SchematicNode> getSchematicDirectory(String name, Integer parent) {
|
||||||
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getName().equals(name)).findFirst().orElse(null);
|
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getName().equals(name)).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicNode(String name, Integer parent) {
|
public Optional<SchematicNode> getSchematicNode(String name, Integer parent) {
|
||||||
return getSchematicNodeInNode(parent).stream().filter(node -> name.equals(node.getName())).findFirst().orElse(null);
|
return getSchematicNodeInNode(parent).stream().filter(node -> name.equals(node.getName())).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode getSchematicNode(int id) {
|
public Optional<SchematicNode> getSchematicNode(int id) {
|
||||||
return nodeById.getOrDefault(id, null);
|
return Optional.ofNullable(nodeById.get(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int ignored, String schemType, Integer parent) {
|
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int ignored, String schemType, Integer parent) {
|
||||||
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getType().equals(schemType)).collect(Collectors.toList());
|
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getSchematic()
|
||||||
|
.map(SchematicNode.SchematicNodeSchematic::unsafe)
|
||||||
|
.map(SchematicNode.SchematicNodeSchematic.Unsafe::getType)
|
||||||
|
.map(type -> type.equals(schemType))
|
||||||
|
.orElse(false)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SchematicNode> getAllAccessibleSchematicsOfType(int ignored, String schemType) {
|
public List<SchematicNode> getAllAccessibleSchematicsOfType(int ignored, String schemType) {
|
||||||
return getAllSchematicsAccessibleByUser(ignored).stream().filter(node -> schemType.equals(node.getType())).collect(Collectors.toList());
|
return getAllSchematicsAccessibleByUser(ignored).stream().filter(node -> node.getSchematic()
|
||||||
|
.map(SchematicNode.SchematicNodeSchematic::unsafe)
|
||||||
|
.map(SchematicNode.SchematicNodeSchematic.Unsafe::getType)
|
||||||
|
.map(type -> type.equals(schemType))
|
||||||
|
.orElse(false)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -352,7 +360,7 @@ public class StandaloneProvider implements Provider {
|
|||||||
@Override
|
@Override
|
||||||
public List<SchematicNode> getAllParentsOfNode(int node) {
|
public List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
List<SchematicNode> allSchematicsAccessibleByUser = getAllSchematicsAccessibleByUser(node);
|
List<SchematicNode> allSchematicsAccessibleByUser = getAllSchematicsAccessibleByUser(node);
|
||||||
allSchematicsAccessibleByUser.remove(getSchematicNode(node));
|
allSchematicsAccessibleByUser.remove(getSchematicNode(node).get());
|
||||||
return allSchematicsAccessibleByUser;
|
return allSchematicsAccessibleByUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +372,7 @@ public class StandaloneProvider implements Provider {
|
|||||||
@Override
|
@Override
|
||||||
public void updateSchematicNode(SchematicNode node) {
|
public void updateSchematicNode(SchematicNode node) {
|
||||||
try {
|
try {
|
||||||
Path newPath = new File(nodesToPath.get(node.getParent() == null?-1:node.getParent()).toFile(), node.getName() + (node.getSchemFormat()?".schem":".schematic")).toPath();
|
Path newPath = new File(nodesToPath.get(node.getParent().isPresent()?-1:node.getParent()).toFile(), node.getName() + node.getSchematic().map(SchematicNode.SchematicNodeSchematic::getSchemFormat).map(aBoolean -> aBoolean?".schem":".schematic").orElse("")).toPath();
|
||||||
Files.move(nodesToPath.get(node.getId()), newPath);
|
Files.move(nodesToPath.get(node.getId()), newPath);
|
||||||
nodesToPath.put(node.getId(), newPath);
|
nodesToPath.put(node.getId(), newPath);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -399,9 +407,12 @@ public class StandaloneProvider implements Provider {
|
|||||||
stream.write(bucket, 0, nReadBytes);
|
stream.write(bucket, 0, nReadBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newFormat != node.getSchemFormat()) {
|
node.getSchematic().ifPresent(schematicNodeSchematic -> {
|
||||||
|
if(newFormat != schematicNodeSchematic.getSchemFormat()) {
|
||||||
nodesToPath.get(node.getId()).toFile().renameTo(new File(nodesToPath.get(node.getId()).toFile().getParentFile(), node.getName() + "." + (newFormat?".schem":"schematic")));
|
nodesToPath.get(node.getId()).toFile().renameTo(new File(nodesToPath.get(node.getId()).toFile().getParentFile(), node.getName() + "." + (newFormat?".schem":"schematic")));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException(e);
|
throw new SecurityException(e);
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren