diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java index 531d70ef..1bfa1f9e 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java @@ -42,13 +42,13 @@ public class SchematicNode { TAB_CACHE.clear(); } - private static final String nodeSelector = "SELECT NodeId, NodeOwner, NodeOwner AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode "; + private static final String nodeSelector = "SELECT NodeId, NodeOwner, NodeOwner AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode "; private static final Table table = new Table<>(SchematicNode.class); private static final Statement create = table.insertFields(true, "NodeOwner", "NodeName", "ParentNode", "NodeItem", "NodeType"); private static final Statement update = table.update(Table.PRIMARY, "NodeName", "ParentNode", "NodeItem", - "NodeType", "NodeRank", "ReplaceColor", "AllowReplay"); + "NodeType", "NodeRank", "Config"); private static final Statement delete = table.delete(Table.PRIMARY); private static final SelectStatement byId = new SelectStatement<>(table, @@ -66,13 +66,13 @@ public class SchematicNode { private static final SelectStatement all = new SelectStatement<>(table, "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId"); private static final SelectStatement list = new SelectStatement<>(table, - "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + Statement.NULL_SAFE_EQUALS - + "? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName"); + + "? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName"); private static final SelectStatement byParentName = new SelectStatement<>(table, - "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + Statement.NULL_SAFE_EQUALS - + "? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?"); + + "? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?"); private static final SelectStatement schematicAccessibleForUser = new SelectStatement<>(table, "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE NodeId = ?"); private static final SelectStatement accessibleByUserTypeInParent = new SelectStatement<>(table, @@ -81,7 +81,7 @@ public class SchematicNode { private static final SelectStatement accessibleByUserType = new SelectStatement<>(table, "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE NodeType = ?"); private static final SelectStatement byIdAndUser = new SelectStatement<>(table, - "SELECT NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE NodeId = ?"); + "SELECT NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE NodeId = ?"); private static final SelectStatement allParentsOfNode = new SelectStatement<>(table, "WITH RECURSIVE R AS (SELECT NodeId, ParentNode FROM EffectiveSchematicNode WHERE NodeId = ? AND EffectiveOwner = ? UNION SELECT E.NodeId, E.ParentNode FROM R, EffectiveSchematicNode E WHERE R.ParentNode = E.NodeId AND E.EffectiveOwner = ?) SELECT SN.NodeId, SN.NodeOwner, ? AS EffectiveOwner, SN.NodeName, R.ParentNode, SN.LastUpdate, SN.NodeItem, SN.NodeType, SN.NodeRank, SN.ReplaceColor, SN.AllowReplay FROM R INNER JOIN SchematicNode SN ON SN.NodeId = R.NodeId"); @@ -108,10 +108,8 @@ public class SchematicNode { private SchematicType nodeType; @Field(def = "0") private int nodeRank; - @Field(def = "1") - private boolean replaceColor; - @Field(def = "1") - private boolean allowReplay; + @Field + private int config; private String brCache; @@ -125,8 +123,7 @@ public class SchematicNode { String nodeItem, SchematicType nodeType, int nodeRank, - boolean replaceColor, - boolean allowReplay) { + int config) { this.nodeId = nodeId; this.nodeOwner = nodeOwner; this.effectiveOwner = effectiveOwner; @@ -136,8 +133,7 @@ public class SchematicNode { this.nodeType = nodeType; this.lastUpdate = lastUpdate; this.nodeRank = nodeRank; - this.replaceColor = replaceColor; - this.allowReplay = allowReplay; + this.config = config; } public static List getAll(SteamwarUser user) { @@ -441,24 +437,45 @@ public class SchematicNode { } public boolean replaceColor() { - return replaceColor; + return getConfig(ConfigFlags.REPLACE_COLOR); } public void setReplaceColor(boolean replaceColor) { if (isDir()) throw new SecurityException("Is Directory"); - this.replaceColor = replaceColor; - updateDB(); + setConfig(ConfigFlags.REPLACE_COLOR, replaceColor); } public boolean allowReplay() { - return allowReplay; + return getConfig(ConfigFlags.ALLOW_REPLAY); } public void setAllowReplay(boolean allowReplay) { if (isDir()) throw new SecurityException("Is Directory"); - this.allowReplay = allowReplay; + setConfig(ConfigFlags.ALLOW_REPLAY, allowReplay); + } + + public boolean isPrepared() { + return getConfig(ConfigFlags.IS_PREPARED); + } + + public void setPrepared(boolean prepared) { + if (isDir()) + throw new SecurityException("Is Directory"); + setConfig(ConfigFlags.IS_PREPARED, prepared); + } + + public boolean getConfig(ConfigFlags flag) { + return (config & (1 << flag.ordinal())) == 1; + } + + public void setConfig(ConfigFlags flag, boolean value) { + if (value) { + config |= (1 << flag.ordinal()); + } else { + config &= ~(1 << flag.ordinal()); + } updateDB(); } @@ -486,7 +503,7 @@ public class SchematicNode { private void updateDB() { this.lastUpdate = Timestamp.from(Instant.now()); - update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, replaceColor, allowReplay, nodeId); + update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, config, nodeId); TAB_CACHE.clear(); } @@ -608,4 +625,10 @@ public class SchematicNode { TAB_CACHE.computeIfAbsent(user.getId(), integer -> new HashMap<>()).putIfAbsent(cacheKey, list); return list; } + + public static enum ConfigFlags { + REPLACE_COLOR, + ALLOW_REPLAY, + IS_PREPARED + } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 9ebc4f0c..d602ed0b 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -41,6 +41,7 @@ import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.message.Message; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicNode; import lombok.Getter; import org.bukkit.Bukkit; @@ -173,11 +174,8 @@ public class FightSystem extends JavaPlugin { SchematicNode checkSchematicNode = SchematicNode.getSchematicNode(Config.CheckSchemID); Fight.getBlueTeam().setSchem(checkSchematicNode); - if (checkSchematicNode.getName().endsWith("-prepared")) { - SchematicNode unpreparedSchematicNode = SchematicNode.getSchematicNode(checkSchematicNode.getOwner(), checkSchematicNode.getName().substring(0, checkSchematicNode.getName().length() - 9), checkSchematicNode.getParent()); - if (unpreparedSchematicNode != null) { - Fight.getRedTeam().setSchem(unpreparedSchematicNode); - } + if (checkSchematicNode.isPrepared()) { + Fight.getRedTeam().setSchem(checkSchematicNode, NodeData.getRevisions(checkSchematicNode) - 1); } new TechareaCommand(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index d566c022..fa9b9c24 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -74,9 +74,13 @@ public class FightSchematic extends StateDependent { } public void setSchematic(SchematicNode schem) { + setSchematic(schem, -1); + } + + public void setSchematic(SchematicNode schem, int revision) { schematic = schem.getId(); try { - clipboard = new SchematicData(schem).load(); + clipboard = new SchematicData(schem, revision).load(); if(schem.replaceColor()) replaceTeamColor(clipboard); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 0cb68f71..a5464a3e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -412,6 +412,10 @@ public class FightTeam { } public void setSchem(SchematicNode schematic){ + setSchem(schematic, -1); + } + + public void setSchem(SchematicNode schematic, int revision){ this.schematic.setSchematic(schematic); broadcast("SCHEMATIC_CHOSEN", Config.GameName, schematic.getName()); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index 2b9548c0..f02beeed 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -84,6 +84,7 @@ public class PrepareSchem implements Listener { } schem.setSchemtype(Config.SchematicType.checkType()); + schem.setPrepared(true); try{ WorldeditWrapper.impl.saveSchem(schem, region, minY); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index 39fbd137..b7b61084 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -428,6 +428,8 @@ public class SchematicCommandUtils { return; } + node.setPrepared(false); + if (type.writeable()) { node.setSchemtype(type); SchematicSystem.MESSAGE.send("UTIL_TYPE_DONE", player); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index a032eb92..8d618600 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -309,8 +309,12 @@ public class CheckCommand extends SWCommand { private void concludeCheckSession(String reason, SchematicType type, BooleanSupplier sendMessageIsOnline) { if(SchematicNode.getSchematicNode(schematic.getId()) != null) { CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.getAsBoolean()); - if(type != null) + if(type != null) { schematic.setSchemtype(type); + if (type == SchematicType.Normal) { + schematic.setPrepared(false); + } + } } remove();