From 930510a94fc72f6be7b35ace60385d6f57d60e14 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 19 Dec 2017 15:36:54 -0500 Subject: [PATCH 01/57] Created methods to generate the name of tables that are created when a new animation is created --- .../bl4de/Animation/data/SQLResources.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index b34edfc..86c501a 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -1,12 +1,43 @@ package com.servegame.bl4de.Animation.data; +import com.servegame.bl4de.Animation.model.Animation; +import com.servegame.bl4de.Animation.model.Frame; +import com.servegame.bl4de.Animation.model.SubSpace3D; + /** * File: SQLResources.java * * @author Brandon Bires-Navel (brandonnavel@outlook.com) */ -public class SQLResources { - public static final String ANIMATION_TABLE = "ANIMATION_TABLE"; +class SQLResources { + static final String ANIMATION_TABLE = "animations"; + + static final String[] TABLES = {ANIMATION_TABLE}; + + /** + * Creates the name of a table that will contain the frames associated with a given animation. + * Result is: animationName_owner_frames, where animationName is the name of the animation + * and owner is the animation owner's uuid.toString(). + * @param animation {@link Animation} to create the name for a frame table + * @return String in the format of: animationName_owner_frames + */ + static String getFrameTableName(Animation animation){ + return animation.getAnimationName() + "_" + animation.getOwner().toString() + "_frames"; + } - public static final String[] TABLES = {ANIMATION_TABLE}; + /** + * Creates the name of a table that will contain the {@link SubSpace3D#contents} of a {@link SubSpace3D}. + * Result is: animationName_owner_frameName_contents, where animationName is the name of the animation, + * and owner is the frames owner's uuid.toString() and frameName is the name of the {@link Frame} that + * encapsulates the {@link SubSpace3D} and subsequently the {@link SubSpace3D#contents} + * @param animation given {@link Animation} that the {@link Frame} is associated with + * @param frame given {@link Frame} that contains the {@link SubSpace3D#contents} that will be stored in + * the created table + * @return String in the format of: animationName_owner_frameName_contents + */ + static String getContentTableName(Animation animation, Frame frame){ + return animation.getAnimationName() + "_" + + frame.getCreator().toString() + "_" + + frame.getName() + "_contents"; + } } From 85425978371957f7a286f2c7aada7181ab889df0 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 19 Dec 2017 16:42:50 -0500 Subject: [PATCH 02/57] Created method skeletons for creating frame table and contents table --- .../servegame/bl4de/Animation/data/SQLManager.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index 8edbc59..ec77926 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -7,10 +7,10 @@ import javax.sql.DataSource; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.concurrent.ConcurrentHashMap; -import static com.servegame.bl4de.Animation.data.SQLResources.ANIMATION_TABLE; import static com.servegame.bl4de.Animation.data.SQLResources.TABLES; /** @@ -92,4 +92,16 @@ public DataSource getDataSource() throws SQLException { SqlService sqlService = Sponge.getServiceManager().provide(SqlService.class).get(); return sqlService.getDataSource("jdbc:h2:./config/" + this.plugin.getId() + "/animation/" + this.database); } + + void createFrameTable(String tableName){ + try (Connection conn = getConnection()){ + PreparedStatement preparedStatement = conn.prepareStatement("CREATE TABLE " + tableName + " ()"); + } catch (SQLException e){ + + } + } + + void createContentsTable(String tableName){ + + } } From 1c3090b5e7778ca8f08133f5b03b85d9da870cbd Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 19 Dec 2017 15:36:54 -0500 Subject: [PATCH 03/57] Created methods to generate the name of tables that are created when a new animation is created --- .../bl4de/Animation/data/SQLResources.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index b34edfc..86c501a 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -1,12 +1,43 @@ package com.servegame.bl4de.Animation.data; +import com.servegame.bl4de.Animation.model.Animation; +import com.servegame.bl4de.Animation.model.Frame; +import com.servegame.bl4de.Animation.model.SubSpace3D; + /** * File: SQLResources.java * * @author Brandon Bires-Navel (brandonnavel@outlook.com) */ -public class SQLResources { - public static final String ANIMATION_TABLE = "ANIMATION_TABLE"; +class SQLResources { + static final String ANIMATION_TABLE = "animations"; + + static final String[] TABLES = {ANIMATION_TABLE}; + + /** + * Creates the name of a table that will contain the frames associated with a given animation. + * Result is: animationName_owner_frames, where animationName is the name of the animation + * and owner is the animation owner's uuid.toString(). + * @param animation {@link Animation} to create the name for a frame table + * @return String in the format of: animationName_owner_frames + */ + static String getFrameTableName(Animation animation){ + return animation.getAnimationName() + "_" + animation.getOwner().toString() + "_frames"; + } - public static final String[] TABLES = {ANIMATION_TABLE}; + /** + * Creates the name of a table that will contain the {@link SubSpace3D#contents} of a {@link SubSpace3D}. + * Result is: animationName_owner_frameName_contents, where animationName is the name of the animation, + * and owner is the frames owner's uuid.toString() and frameName is the name of the {@link Frame} that + * encapsulates the {@link SubSpace3D} and subsequently the {@link SubSpace3D#contents} + * @param animation given {@link Animation} that the {@link Frame} is associated with + * @param frame given {@link Frame} that contains the {@link SubSpace3D#contents} that will be stored in + * the created table + * @return String in the format of: animationName_owner_frameName_contents + */ + static String getContentTableName(Animation animation, Frame frame){ + return animation.getAnimationName() + "_" + + frame.getCreator().toString() + "_" + + frame.getName() + "_contents"; + } } From 5b6c3d1ad10e4dcdf0b7bb240ed860854f65dd72 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 19 Dec 2017 16:42:50 -0500 Subject: [PATCH 04/57] Created method skeletons for creating frame table and contents table --- .../servegame/bl4de/Animation/data/SQLManager.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index 8edbc59..ec77926 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -7,10 +7,10 @@ import javax.sql.DataSource; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.concurrent.ConcurrentHashMap; -import static com.servegame.bl4de.Animation.data.SQLResources.ANIMATION_TABLE; import static com.servegame.bl4de.Animation.data.SQLResources.TABLES; /** @@ -92,4 +92,16 @@ public DataSource getDataSource() throws SQLException { SqlService sqlService = Sponge.getServiceManager().provide(SqlService.class).get(); return sqlService.getDataSource("jdbc:h2:./config/" + this.plugin.getId() + "/animation/" + this.database); } + + void createFrameTable(String tableName){ + try (Connection conn = getConnection()){ + PreparedStatement preparedStatement = conn.prepareStatement("CREATE TABLE " + tableName + " ()"); + } catch (SQLException e){ + + } + } + + void createContentsTable(String tableName){ + + } } From b9dd7daa9f1f322fae812f5a2c295712d1213644 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 20 Dec 2017 14:08:47 -0500 Subject: [PATCH 05/57] Readme update --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7299351..8e66e8a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ See the wiki for the commands and their respective usages. (Still a WIP) [BUGFIX] Setting the cycles when starting an animation doesn't do anything [REQUIREMENT] Define characters that are illegal to have in a frame/animation name [BUGFIX] There's a problem when displaying the volume of small subspaces, a 1x4x1 will have a volume of 0 +[BUGFIX] Some animations, when stopped, play certain frames continuously even after they are stopped (maybe because it +was played and then stopped immediately) #### Low Priority [PERMISSIONS] Permissions that only allow certain values to be set with certain flags @@ -109,6 +111,9 @@ the internal states and then starting the animation backup on the frame it stopp * ~~In the frame info view if there are contents show the number of not air blocks~~ * ~~In the animation info view add a line for the volume of the master subspace (no longer think I want to do this)~~ +#### Matt Notes +* Pausing the the animation should stop the animation on the given frame, + ## Animations to show off * Door opening * Bridge extending From 5fae362defc8cf4e9ad8efbac77c2ca03fcc7ea3 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 20 Dec 2017 14:10:09 -0500 Subject: [PATCH 06/57] Altered the animations table that gets created --- .../bl4de/Animation/data/SQLManager.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index ec77926..a0c26ff 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -11,7 +11,7 @@ import java.sql.SQLException; import java.util.concurrent.ConcurrentHashMap; -import static com.servegame.bl4de.Animation.data.SQLResources.TABLES; +import static com.servegame.bl4de.Animation.data.SQLResources.*; /** * File: SQLManager.java @@ -47,14 +47,17 @@ private SQLManager(PluginContainer plugin){ */ private void initSettings(){ // In the future this would get data from a config file - this.database = "ANIMATIONS"; + this.database = DATABASE; try (Connection connection = getDataSource().getConnection()){ - for (String table : - TABLES) { - connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + table + " (name VARCHAR2(255), owner UUID, data CLOB)") - .executeUpdate(); - - } + connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + ANIMATION_TABLE + " (" + + "name VARCHAR2(255), " + + "owner UUID, " + + "status ENUM('STOPPED', 'RUNNING', 'PAUSED'), " + + "startFrameIndex INT, " + + "tickDelay INT, " + + "cycles INT, " + + "frameNames ARRAY)") + .executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } From 985b6582679d53955202ce4a52326397de36edce Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 20 Dec 2017 14:10:26 -0500 Subject: [PATCH 07/57] Added the name of the database --- .../java/com/servegame/bl4de/Animation/data/SQLResources.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index 86c501a..f998765 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -14,6 +14,8 @@ class SQLResources { static final String[] TABLES = {ANIMATION_TABLE}; + static final String DATABASE = "ANIMATIONS"; + /** * Creates the name of a table that will contain the frames associated with a given animation. * Result is: animationName_owner_frames, where animationName is the name of the animation From 191bc7ad7a89d22712d2adab3de7fb49f3d93616 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 20 Dec 2017 23:21:10 -0500 Subject: [PATCH 08/57] Added database table constants --- .../bl4de/Animation/data/SQLResources.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index f998765..98ad781 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -10,7 +10,25 @@ * @author Brandon Bires-Navel (brandonnavel@outlook.com) */ class SQLResources { - static final String ANIMATION_TABLE = "animations"; + + /* Animation Table Constants */ + static final String ANIMATION_TABLE = "animations"; + static final String COLUMN_ANIMATION_NAME = "name"; + static final String COLUMN_ANIMATION_OWNER = "owner"; + static final String COLUMN_ANIMATION_STATUS = "status"; + static final String COLUMN_ANIMATION_START_FRAME_INDEX = "startFrameIndex"; + static final String COLUMN_ANIMATION_TICK_DELAY = "tickDelay"; + static final String COLUMN_ANIMATION_CYCLES = "cycles"; + static final String COLUMN_ANIMATION_FRAME_NAMES = "frameNames"; + + /* Frame Table Constants */ + static final String COLUMN_FRAME_NAME = "frameName"; + static final String COLUMN_FRAME_CREATOR = "creator"; + static final String COLUMN_FRAME_SUBSPACE_C1 = "subspace_cornerOne"; + static final String COLUMN_FRAME_SUBSPACE_C2 = "subspace_cornerTwo"; + static final String COLUMN_FRAME_SUBSPACE_CONTENTS = "subspace_contents"; + + /* Contents Table Constants */ static final String[] TABLES = {ANIMATION_TABLE}; From d4391dc7f391bc612bccf6f7a860c2847f3d7704 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Thu, 21 Dec 2017 16:56:26 -0500 Subject: [PATCH 09/57] Added Content table constants --- .../java/com/servegame/bl4de/Animation/data/SQLResources.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index 98ad781..39aebd6 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -13,6 +13,7 @@ class SQLResources { /* Animation Table Constants */ static final String ANIMATION_TABLE = "animations"; + static final String COLUMN_ANIMATION_NAME = "name"; static final String COLUMN_ANIMATION_OWNER = "owner"; static final String COLUMN_ANIMATION_STATUS = "status"; @@ -29,6 +30,8 @@ class SQLResources { static final String COLUMN_FRAME_SUBSPACE_CONTENTS = "subspace_contents"; /* Contents Table Constants */ + static final String COLUMN_CONTENTS_XYZ = "xyz"; + static final String COLUMN_CONTENTS_DATA = "data"; static final String[] TABLES = {ANIMATION_TABLE}; From 74eff7fa07a7dd119c76046e3a8e97b2cda9887e Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Thu, 21 Dec 2017 16:57:18 -0500 Subject: [PATCH 10/57] Added implementation of the createFrameTable and createContentTable methods --- .../bl4de/Animation/data/SQLManager.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index a0c26ff..93ca98b 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -96,15 +96,28 @@ public DataSource getDataSource() throws SQLException { return sqlService.getDataSource("jdbc:h2:./config/" + this.plugin.getId() + "/animation/" + this.database); } - void createFrameTable(String tableName){ + protected void createFrameTable(String tableName){ try (Connection conn = getConnection()){ - PreparedStatement preparedStatement = conn.prepareStatement("CREATE TABLE " + tableName + " ()"); + conn.prepareStatement("CREATE TABLE " + tableName + " (" + + "frameName VARCHAR2(255), " + + "creator UUID, " + + "subspace_cornterOne CLOB, " + + "subspace_cornterTwo CLOB, " + + "subspace_contents ARRAY" + + ")").executeUpdate(); } catch (SQLException e){ - + e.printStackTrace(); } } - void createContentsTable(String tableName){ - + protected void createContentsTable(String tableName){ + try (Connection conn = getConnection()){ + conn.prepareStatement("CREATE TABLE " + tableName + " (" + + "xyz VARCHAR2(100), " + + "data CLOB" + + ")").executeUpdate(); + } catch (SQLException e){ + e.printStackTrace(); + } } } From 5ee2659eceaa2d3e9ba6c077cd3b357ff05c608c Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Thu, 21 Dec 2017 17:01:56 -0500 Subject: [PATCH 11/57] - Fixed up createAnimation() to conform to the new database design - Fixed up saveAnimation() (not finished yet) - Implemented createFrame(), which creates a frame table and populates it with all the frames from the animation - Implemented createContents(), which creates a content table and populates it with data from the given frame's subspace --- .../Animation/data/PreparedStatements.java | 232 ++++++++++++++++-- 1 file changed, 215 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java index e5b0d8e..e3bd20d 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java @@ -1,18 +1,22 @@ package com.servegame.bl4de.Animation.data; +import com.servegame.bl4de.Animation.AnimationPlugin; import com.servegame.bl4de.Animation.model.Animation; +import com.servegame.bl4de.Animation.model.Frame; +import org.spongepowered.api.block.BlockSnapshot; +import org.spongepowered.api.data.persistence.DataFormats; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; +import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import static com.servegame.bl4de.Animation.data.SQLResources.ANIMATION_TABLE; +import static com.servegame.bl4de.Animation.data.SQLResources.*; /** * File: PreparedStatements.java @@ -32,12 +36,45 @@ public static boolean createAnimation(Animation animation){ try (Connection connection = SQLManager.getConnection()){ // Insert new animation into the table PreparedStatement statement = connection.prepareStatement( - "INSERT INTO " + ANIMATION_TABLE + " (name, owner, data) VALUES (?, ?, ?)" + "INSERT INTO " + ANIMATION_TABLE + " (" + + COLUMN_ANIMATION_NAME + ", " + + COLUMN_ANIMATION_OWNER + ", " + + COLUMN_ANIMATION_STATUS + ", " + + COLUMN_ANIMATION_START_FRAME_INDEX + ", " + + COLUMN_ANIMATION_TICK_DELAY + ", " + + COLUMN_ANIMATION_CYCLES + ", " + + COLUMN_ANIMATION_FRAME_NAMES +") " + + " VALUES (?, ?, ?, ?, ?, ?, ?)" + ); + // Put all the names of the frames into a list + final List frames = animation.getFrames(); + final List frameNames = new ArrayList<>(); + frames.forEach(frame -> frameNames.add(frame.getName())); + + statement.setString(1, animation.getAnimationName()); // Animation name + statement.setObject(2, animation.getOwner()); // Owner + statement.setString(3, animation.getStatus().toString()); // Status + statement.setInt(4, animation.getStartFrameIndex()); // Start frame index + statement.setInt(5, animation.getTickDelay()); // Tick delay + statement.setInt(6, animation.getCycles()); // Cycles + statement.setArray(7, connection.createArrayOf( // Array of all frame names + "VARCHAR2", + frameNames.toArray()) ); - statement.setString(1, animation.getAnimationName()); - statement.setObject(2, animation.getOwner()); - statement.setString(3, Animation.serialize(animation)); statement.executeUpdate(); + + // Create table for the frames + final String FRAMES_TABLE = getFrameTableName(animation); + SQLManager.get(AnimationPlugin.plugin).createFrameTable(FRAMES_TABLE); + + // Add all the frames + List frameList = animation.getFrames(); + for (Frame frame : + frameList) { + if (!createFrame(animation, frame, FRAMES_TABLE)){ + return false; + } + } } catch (SQLException e){ e.printStackTrace(); return false; @@ -53,11 +90,37 @@ public static boolean createAnimation(Animation animation){ public static boolean saveAnimation(Animation animation){ try (Connection connection = SQLManager.getConnection()){ PreparedStatement statement = connection.prepareStatement( - "UPDATE " + ANIMATION_TABLE + " SET data = ? WHERE name = ? AND owner = ?" + "UPDATE " + ANIMATION_TABLE + " SET " + + COLUMN_ANIMATION_STATUS + " = ?," + + COLUMN_ANIMATION_START_FRAME_INDEX + " = ?," + + COLUMN_ANIMATION_TICK_DELAY + " = ?," + + COLUMN_ANIMATION_CYCLES + " = ?," + + COLUMN_ANIMATION_FRAME_NAMES + " = ?" + + "WHERE " + + COLUMN_ANIMATION_NAME + " = ? AND " + + COLUMN_ANIMATION_OWNER + " = ?" + ); + + // Put all the names of the frames into a list + final List frames = animation.getFrames(); + final List frameNames = new ArrayList<>(); + frames.forEach(frame -> frameNames.add(frame.getName())); + + // SET Clause + statement.setString(1, animation.getStatus().toString()); // Status + statement.setInt(2, animation.getStartFrameIndex()); // Start frame index + statement.setInt(3, animation.getTickDelay()); // Tick delay + statement.setInt(4, animation.getCycles()); // Cycles + statement.setArray(5, // Array of frame names + connection.createArrayOf( + "VARCHAR2", + frameNames.toArray() + ) ); - statement.setString(1, Animation.serialize(animation)); - statement.setString(2, animation.getAnimationName()); - statement.setObject(3, animation.getOwner()); + + // WHERE Clause + statement.setString(6, animation.getAnimationName()); // Animation name + statement.setObject(7, animation.getOwner()); // Owner statement.executeUpdate(); } catch (SQLException e){ e.printStackTrace(); @@ -87,7 +150,6 @@ public static Optional getAnimation(String name, UUID owner){ // The data exists String animationString = rs.getString("data"); newAnimation = Animation.deserialize(animationString); - return Optional.ofNullable(newAnimation); } } } catch (SQLException e){ @@ -95,7 +157,7 @@ public static Optional getAnimation(String name, UUID owner){ } // The animation we are looking for doesn't appear in the call find all animations by name // and or the data didn't exist/couldn't get pulled from the DB - return Optional.empty(); + return Optional.ofNullable(newAnimation); } /** @@ -160,8 +222,144 @@ public static boolean deleteAnimation(Animation animation){ /* END: Animation Operations */ /* START: Frame Operations */ + + private static boolean createFrame(Animation animation, Frame frame, final String FRAMES_TABLE){ + try (Connection connection = SQLManager.getConnection()){ + PreparedStatement insertFrameStatement = connection.prepareStatement( + "INSERT INTO " + FRAMES_TABLE + " (" + + COLUMN_FRAME_NAME + ", " + + COLUMN_FRAME_CREATOR + ", " + + COLUMN_FRAME_SUBSPACE_C1 + ", " + + COLUMN_FRAME_SUBSPACE_C2 + ", " + + COLUMN_FRAME_SUBSPACE_CONTENTS + ") " + + "VALUES (?, ?, ?, ?, ?)" + ); + + insertFrameStatement.setString(1, frame.getName()); // Frame name + insertFrameStatement.setObject(2, frame.getCreator()); // Creator + Optional> corner1Optional = frame.getCornerOne(); + Optional> corner2Optional = frame.getCornerTwo(); + Location corner1 = null, corner2 = null; + + // Not using ifPresent here because you need to have a separate + // try-catch for the SQL and IOException (which is ugly) + if (corner1Optional.isPresent()){ + corner1 = corner1Optional.get(); + insertFrameStatement.setString(3, DataFormats.HOCON.write(corner1.createSnapshot().toContainer())); + } + if (corner2Optional.isPresent()){ + corner2 = corner2Optional.get(); + insertFrameStatement.setString(4, DataFormats.HOCON.write(corner2.createSnapshot().toContainer())); + } + if (corner1 != null && corner2 != null){ + if (!createContents(animation, frame)){ + return false; + } + int xLen = Math.abs(Math.abs(corner1.getBlockX()) - Math.abs(corner2.getBlockX())); + int yLen = Math.abs(Math.abs(corner1.getBlockY()) - Math.abs(corner2.getBlockY())); + int zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ())); + + String[][][] contentPositions = new String[xLen][yLen][zLen]; + // Populate the contentPositions with coordinates in the format of "x|y|z" + for (int i = 0; i < xLen; i++) { + for (int j = 0; j < yLen; j++) { + for (int k = 0; k < zLen; k++) { + contentPositions[i][j][k] = i + "|" + j + "|" + k; + } + } + } + insertFrameStatement.setArray(5, connection.createArrayOf("VARCHAR2", contentPositions)); + } + insertFrameStatement.executeUpdate(); + + } catch (SQLException|IOException e){ + e.printStackTrace(); + return false; + } + return true; + } + + private static boolean saveFrame(Animation animation, Frame frame){ + return false; + } + + public static Optional getFrame(Animation animation, String frameName){ + return null; + } + + public static Optional getFrame(String animationName, String frameName){ + return null; + } + /* END: Frame Operations */ - /* START: SubSpace3D Operations */ - /* END: SubSpace3D Operations */ + /* START: Content Operations */ + + private static boolean createContents(Animation animation, Frame frame){ + Optional> corner1Optional = frame.getCornerOne(); + Optional> corner2Optional = frame.getCornerTwo(); + Location corner1, corner2; + + if (!corner1Optional.isPresent() || !corner2Optional.isPresent()){ + return false; + } + corner1 = corner1Optional.get(); + corner2 = corner2Optional.get(); + + // Create 3D array for the subspace_contents + int xLen = Math.abs(Math.abs(corner1.getBlockX()) - Math.abs(corner2.getBlockX())); + int yLen = Math.abs(Math.abs(corner1.getBlockY()) - Math.abs(corner2.getBlockY())); + int zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ())); + Optional blockSnapshotsOptional = frame.getContents(); + if (!blockSnapshotsOptional.isPresent()){ + return false; + } + BlockSnapshot[][][] contents = blockSnapshotsOptional.get(); + + try (Connection connection = SQLManager.getConnection()){ + Map contentPositions = new HashMap<>(); + + // Populate the contentPositions with coordinates in the format of "x|y|z" + for (int i = 0; i < xLen; i++) { + for (int j = 0; j < yLen; j++) { + for (int k = 0; k < zLen; k++) { + contentPositions.put(i + "|" + j + "|" + k, DataFormats.HOCON.write(contents[i][j][k].toContainer())); + } + } + } + + // Create contents table + final String CONTENT_TABLE = SQLResources.getContentTableName(animation, frame); + SQLManager.get(AnimationPlugin.plugin).createContentsTable(CONTENT_TABLE); + + // Populate the table + for (Map.Entry entry : + contentPositions.entrySet()) { + PreparedStatement statement = connection.prepareStatement( + "INSERT INTO " + CONTENT_TABLE + " SET " + + COLUMN_CONTENTS_XYZ + " = ?, " + + COLUMN_CONTENTS_DATA + " = ?" + ); + statement.setString(1, entry.getKey()); + statement.setString(2, entry.getValue()); + statement.execute(); + } + connection.commit(); + } catch (SQLException|IOException e){ + e.printStackTrace(); + return false; + } + return true; + } + + private static boolean saveContents(Animation animation, Frame frame){ + return false; + } + + private static BlockSnapshot[][][] getContents(Animation animation, Frame frame){ + return null; + } + + + /* END: Content Operations */ } From c91671cf738041e08524656d3b34e02a53b7ed2e Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Thu, 21 Dec 2017 17:02:56 -0500 Subject: [PATCH 12/57] Rewrote stopAllAnimations() to utilize the TaskManager's references of all playing animations --- .../controller/AnimationController.java | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java index 0b7eb77..d0c4fcf 100644 --- a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java +++ b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java @@ -1,16 +1,15 @@ package com.servegame.bl4de.Animation.controller; +import com.servegame.bl4de.Animation.AnimationPlugin; import com.servegame.bl4de.Animation.data.PreparedStatements; import com.servegame.bl4de.Animation.model.Animation; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.action.TextActions; import java.util.ArrayList; -import java.util.Map; import java.util.Optional; import java.util.UUID; -import static com.servegame.bl4de.Animation.data.PreparedStatements.getAnimations; import static com.servegame.bl4de.Animation.util.Util.*; /** @@ -27,15 +26,7 @@ public class AnimationController { * Stops all animations, usually ran when the server is shutting down. */ public static void stopAllAnimations(){ - Map> animations = getAnimations(); - for (Map.Entry> entry : - animations.entrySet()) { - ArrayList animationNames = entry.getValue(); - UUID uuid = entry.getKey(); - for (int i = 0; i < animationNames.size(); i++) { - getAnimation(animationNames.get(i), uuid).get().stop(); - } - } + AnimationPlugin.taskManager.stopAllAnimations(); } /** @@ -93,22 +84,48 @@ public static Text getButtonsForList(){ .build(); } + /** + * todo + * @param animation + * @return + */ public static boolean createAnimation(Animation animation){ return PreparedStatements.createAnimation(animation); } + /** + * TODO + * @param name + * @param owner + * @return + */ public static Optional getAnimation(String name, UUID owner){ return PreparedStatements.getAnimation(name, owner); } + /** + * TODO + * @param owner + * @return + */ public static ArrayList getAnimationsByOwner(UUID owner) { return PreparedStatements.getAnimationsByOwner(owner); } + /** + * todo + * @param animation + * @return + */ public static boolean saveAnimation(Animation animation){ return PreparedStatements.saveAnimation(animation); } + /** + * todo + * @param animation + * @return + */ public static boolean deleteAnimation(Animation animation){ return PreparedStatements.deleteAnimation(animation); } From e7c2b4582de5f2d14296d844b4c2a11b1b96a680 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Thu, 21 Dec 2017 19:37:50 -0500 Subject: [PATCH 13/57] - Implemented deleteTable() - Added IF NOT EXISTS constraint when making frame or content tables --- .../bl4de/Animation/data/SQLManager.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index 93ca98b..51a51d5 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -96,9 +96,9 @@ public DataSource getDataSource() throws SQLException { return sqlService.getDataSource("jdbc:h2:./config/" + this.plugin.getId() + "/animation/" + this.database); } - protected void createFrameTable(String tableName){ + void createFrameTable(String tableName){ try (Connection conn = getConnection()){ - conn.prepareStatement("CREATE TABLE " + tableName + " (" + + conn.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName + " (" + "frameName VARCHAR2(255), " + "creator UUID, " + "subspace_cornterOne CLOB, " + @@ -110,9 +110,17 @@ protected void createFrameTable(String tableName){ } } - protected void createContentsTable(String tableName){ + void deleteTable(String tableName){ + try (Connection connection = SQLManager.getConnection()){ + connection.prepareStatement("DROP TABLE " + tableName); + } catch (SQLException e){ + e.printStackTrace(); + } + } + + void createContentsTable(String tableName){ try (Connection conn = getConnection()){ - conn.prepareStatement("CREATE TABLE " + tableName + " (" + + conn.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName + " (" + "xyz VARCHAR2(100), " + "data CLOB" + ")").executeUpdate(); From 34f8b6ba9079256abacacd0505d0771a89224386 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Thu, 21 Dec 2017 23:08:33 -0500 Subject: [PATCH 14/57] Added more constants for animation table --- .../java/com/servegame/bl4de/Animation/data/SQLResources.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index 39aebd6..ad33f3b 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -21,6 +21,8 @@ class SQLResources { static final String COLUMN_ANIMATION_TICK_DELAY = "tickDelay"; static final String COLUMN_ANIMATION_CYCLES = "cycles"; static final String COLUMN_ANIMATION_FRAME_NAMES = "frameNames"; + static final String COLUMN_ANIMATION_C1 = "animation_corner1"; + static final String COLUMN_ANIMATION_C2 = "animation_corner2"; /* Frame Table Constants */ static final String COLUMN_FRAME_NAME = "frameName"; From 84b082b0b08802fa6966af7dedb120d9d09715be Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Thu, 21 Dec 2017 23:10:16 -0500 Subject: [PATCH 15/57] Altered the create table statements --- .../com/servegame/bl4de/Animation/data/SQLManager.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index 51a51d5..2370267 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -56,7 +56,9 @@ private void initSettings(){ "startFrameIndex INT, " + "tickDelay INT, " + "cycles INT, " + - "frameNames ARRAY)") + "frameNames ARRAY," + + "animation_cornerOne CLOB, " + + "animation_cornerTwo CLOB) ") .executeUpdate(); } catch (SQLException e) { e.printStackTrace(); @@ -101,8 +103,8 @@ void createFrameTable(String tableName){ conn.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName + " (" + "frameName VARCHAR2(255), " + "creator UUID, " + - "subspace_cornterOne CLOB, " + - "subspace_cornterTwo CLOB, " + + "subspace_cornerOne CLOB, " + + "subspace_cornerTwo CLOB, " + "subspace_contents ARRAY" + ")").executeUpdate(); } catch (SQLException e){ From 90331c7c28197434f94878ecfff7dd3da1fa6d4f Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 03:46:09 -0500 Subject: [PATCH 16/57] When displaying a frame, it makes sure there are contents to display --- .../bl4de/Animation/command/frame/DisplayFrame.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java index f803e27..db04b6c 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java @@ -67,6 +67,12 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm Frame frame = frameOptional.get(); + if (!frame.getContents().isPresent()) { + // The frame has no contents + player.sendMessage(TextResponses.FRAME_HAS_NO_CONTENT); + return CommandResult.success(); + } + if (FrameController.displayContents(frame)){ Text message = Text.of( PRIMARY_COLOR, "Frame '", From d24df5c04deeabe29218f43bbc6aa69c15658564 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 03:49:33 -0500 Subject: [PATCH 17/57] - getBareAnimation implemented (this gets animation data, but not frame data) - Lots of reworks to save and getAnimation - re-Implemented deleteAnimation - In create frame, it's ensuring the frame table exists - Implemented saveFrame, getFrame, and deleteFrame - Implemented saveContents, getContents, and deleteContents --- .../Animation/data/PreparedStatements.java | 454 +++++++++++++++--- 1 file changed, 382 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java index e3bd20d..b62607f 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java @@ -1,18 +1,17 @@ package com.servegame.bl4de.Animation.data; import com.servegame.bl4de.Animation.AnimationPlugin; +import com.servegame.bl4de.Animation.exception.UninitializedException; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; +import com.servegame.bl4de.Animation.model.SubSpace3D; import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.data.persistence.DataFormats; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import java.io.IOException; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -57,21 +56,14 @@ public static boolean createAnimation(Animation animation){ statement.setInt(4, animation.getStartFrameIndex()); // Start frame index statement.setInt(5, animation.getTickDelay()); // Tick delay statement.setInt(6, animation.getCycles()); // Cycles - statement.setArray(7, connection.createArrayOf( // Array of all frame names - "VARCHAR2", - frameNames.toArray()) - ); + statement.setObject(7, frameNames.toArray()); statement.executeUpdate(); - // Create table for the frames - final String FRAMES_TABLE = getFrameTableName(animation); - SQLManager.get(AnimationPlugin.plugin).createFrameTable(FRAMES_TABLE); - // Add all the frames List frameList = animation.getFrames(); for (Frame frame : frameList) { - if (!createFrame(animation, frame, FRAMES_TABLE)){ + if (!createFrame(animation, frame)){ return false; } } @@ -91,11 +83,13 @@ public static boolean saveAnimation(Animation animation){ try (Connection connection = SQLManager.getConnection()){ PreparedStatement statement = connection.prepareStatement( "UPDATE " + ANIMATION_TABLE + " SET " + - COLUMN_ANIMATION_STATUS + " = ?," + - COLUMN_ANIMATION_START_FRAME_INDEX + " = ?," + - COLUMN_ANIMATION_TICK_DELAY + " = ?," + - COLUMN_ANIMATION_CYCLES + " = ?," + - COLUMN_ANIMATION_FRAME_NAMES + " = ?" + + COLUMN_ANIMATION_STATUS + " = ?, " + + COLUMN_ANIMATION_START_FRAME_INDEX + " = ?, " + + COLUMN_ANIMATION_TICK_DELAY + " = ?, " + + COLUMN_ANIMATION_CYCLES + " = ?, " + + COLUMN_ANIMATION_FRAME_NAMES + " = ?, " + + COLUMN_ANIMATION_C1 + " = ?, " + + COLUMN_ANIMATION_C2 + " = ? " + "WHERE " + COLUMN_ANIMATION_NAME + " = ? AND " + COLUMN_ANIMATION_OWNER + " = ?" @@ -111,18 +105,31 @@ public static boolean saveAnimation(Animation animation){ statement.setInt(2, animation.getStartFrameIndex()); // Start frame index statement.setInt(3, animation.getTickDelay()); // Tick delay statement.setInt(4, animation.getCycles()); // Cycles - statement.setArray(5, // Array of frame names - connection.createArrayOf( - "VARCHAR2", - frameNames.toArray() - ) - ); + statement.setObject(5, frameNames.toArray()); + Optional> worldLocation1 = animation.getSubSpace().getCornerOne(); + Optional> worldLocation2 = animation.getSubSpace().getCornerTwo(); + if (worldLocation1.isPresent()){ + statement.setString(6, DataFormats.HOCON.write(worldLocation1.get().createSnapshot().toContainer())); + } else { + statement.setString(6, null); + } + if (worldLocation2.isPresent()){ + statement.setString(7, DataFormats.HOCON.write(worldLocation2.get().createSnapshot().toContainer())); + } else { + statement.setString(7, null); + + } // WHERE Clause - statement.setString(6, animation.getAnimationName()); // Animation name - statement.setObject(7, animation.getOwner()); // Owner + statement.setString(8, animation.getAnimationName()); // Animation name + statement.setObject(9, animation.getOwner()); // Owner statement.executeUpdate(); - } catch (SQLException e){ + + for (Frame frame : + animation.getFrames()) { + saveFrame(animation, frame); + } + } catch (SQLException|IOException e){ e.printStackTrace(); return false; } @@ -136,28 +143,117 @@ public static boolean saveAnimation(Animation animation){ * @return Optional of the {@link Animation} */ public static Optional getAnimation(String name, UUID owner){ - ArrayList animations = getAnimationsByOwner(owner); - Animation newAnimation = null; + Optional bareAnimationOptional = getBareAnimation(name, owner); + Animation animation = null; + if (!bareAnimationOptional.isPresent()){ + return Optional.empty(); + } try (Connection connection = SQLManager.getConnection()){ - if (animations.contains(name)){ - PreparedStatement statement = connection.prepareStatement( - "SELECT name, owner, data FROM " + ANIMATION_TABLE + " WHERE name = ? AND owner = ?" - ); - statement.setString(1, name); - statement.setObject(2, owner); - ResultSet rs = statement.executeQuery(); - if (rs.next()){ - // The data exists - String animationString = rs.getString("data"); - newAnimation = Animation.deserialize(animationString); + animation = bareAnimationOptional.get(); + // Reset frames list (since blank ones were added in getBareAnimation()) + animation.setFrames(new ArrayList<>()); + + // Get all frames + final String FRAME_TABLE = getFrameTableName(animation); + PreparedStatement getFrameNames = connection.prepareStatement( + "SELECT " + COLUMN_ANIMATION_FRAME_NAMES + + " FROM " + ANIMATION_TABLE + + " WHERE " + COLUMN_ANIMATION_NAME + " = ? AND " + + COLUMN_ANIMATION_OWNER + " = ?"); + getFrameNames.setString(1, animation.getAnimationName()); + getFrameNames.setObject(2, animation.getOwner()); + ResultSet rs = getFrameNames.executeQuery(); + if (rs.next()){ + Object[] array = ((Object[]) rs.getArray(COLUMN_ANIMATION_FRAME_NAMES).getArray()); + String[] frames = new String[array.length]; + for (int i = 0; i < array.length; i++) { + frames[i] = (String) array[i]; + } + for (String frameName : + frames) { + Optional frameOptional = getFrame(frameName, FRAME_TABLE, + getContentTableName(animation, new Frame(animation.getOwner(), frameName, new SubSpace3D()))); + if (frameOptional.isPresent()) { + animation.addFrame(frameOptional.get()); + } } + } } catch (SQLException e){ e.printStackTrace(); + } catch (UninitializedException e){ + System.err.println("Frame/Animation is not initialized. (This is likely a bug)"); } // The animation we are looking for doesn't appear in the call find all animations by name // and or the data didn't exist/couldn't get pulled from the DB - return Optional.ofNullable(newAnimation); + return Optional.ofNullable(animation); + } + + /** + * Get an animation with no frames or any of the data associated with the frames. + * Do note that it does have a SubSpace inorder to know the corners of the animation. + * @param name name of the {@link Animation} + * @param owner {@link UUID} of the owner of the animation + * @return - Optional of the animation + */ + public static Optional getBareAnimation(String name, UUID owner){ + Animation animation = null; + try (Connection connection = SQLManager.getConnection()){ + PreparedStatement getAnimation = connection.prepareStatement( + "SELECT * FROM " + ANIMATION_TABLE + + " WHERE " + COLUMN_ANIMATION_NAME + " = ? AND " + + COLUMN_ANIMATION_OWNER + " = ?"); + getAnimation.setString(1, name); + getAnimation.setObject(2, owner); + ResultSet rs = getAnimation.executeQuery(); + String[] frames = {}; + + if (rs.next()){ + // Get animation data (except subspace data) + animation = new Animation(owner, name); + animation.setStatus(Animation.Status.valueOf(rs.getString(COLUMN_ANIMATION_STATUS))); + animation.setCycles(rs.getInt(COLUMN_ANIMATION_CYCLES)); + animation.setTickDelay(rs.getInt(COLUMN_ANIMATION_TICK_DELAY)); + animation.setStartFrameIndex(rs.getInt(COLUMN_ANIMATION_START_FRAME_INDEX)); + + Object[] array = ((Object[]) rs.getArray(COLUMN_ANIMATION_FRAME_NAMES).getArray()); + frames = new String[array.length]; + + for (int i = 0; i < array.length; i++) { + frames[i] = (String) array[i]; + } + + // Create SubSpace3D + SubSpace3D subSpace3D = new SubSpace3D(); + Optional c1 = Optional.empty(); + Optional c2 = Optional.empty(); + String c1String = rs.getString(COLUMN_ANIMATION_C1); + String c2String = rs.getString(COLUMN_ANIMATION_C2); + + if (c1String != null){ + // Corner one is in the DB + c1 = BlockSnapshot.builder().build(DataFormats.HOCON.read(c1String)); + } + if (c2String != null){ + // Corner two is in the DB + c2 = BlockSnapshot.builder().build(DataFormats.HOCON.read(c2String)); + } + c1.ifPresent(blockSnapshot -> subSpace3D.setCornerOne(blockSnapshot.getLocation().orElse(null))); + c2.ifPresent(blockSnapshot -> subSpace3D.setCornerTwo(blockSnapshot.getLocation().orElse(null))); + animation.setSubSpace(subSpace3D); + } + if (animation != null && animation.isInitialized()) { + // Add blank frames + for (int i = 0; i < frames.length; i++) { + animation.addFrame(new Frame()); + } + } + } catch (SQLException|IOException e){ + e.printStackTrace(); + } catch (UninitializedException e){ + System.err.println("An animation was uninitialized but frames were added anyway. (This is likely a bug)"); + } + return Optional.ofNullable(animation); } /** @@ -188,30 +284,48 @@ public static Map> getAnimations(){ return animationOwnerNamePair; } - /** - * Get all available {@link Animation} that are owned by a given owner - * @param owner the given owner - * @return ArrayList of strings containing the animation names - */ public static ArrayList getAnimationsByOwner(UUID owner) { Map> animations = getAnimations(); return animations.getOrDefault(owner, new ArrayList<>()); } - /** - * Deletes an animation file - * @param animation given {@link Animation} - * @return boolean of whether or not the file was deleted - */ public static boolean deleteAnimation(Animation animation){ try (Connection connection = SQLManager.getConnection()){ - // Delete row in animation table + // Get all the frames in for the given animation PreparedStatement statement = connection.prepareStatement( - "DELETE FROM " + ANIMATION_TABLE + " WHERE name = ? AND owner = ?" + "SELECT " + COLUMN_ANIMATION_FRAME_NAMES + + " FROM " + ANIMATION_TABLE + " WHERE " + + COLUMN_ANIMATION_NAME + " = ? AND " + + COLUMN_ANIMATION_OWNER + " = ?" ); statement.setString(1, animation.getAnimationName()); statement.setObject(2, animation.getOwner()); - statement.executeUpdate(); + ResultSet rs = statement.executeQuery(); + if (rs.next()){ + Object[] array = ((Object[]) rs.getArray(COLUMN_ANIMATION_FRAME_NAMES).getArray()); + String[] frameNames = new String[array.length]; + for (int i = 0; i < array.length; i++) { + frameNames[i] = (String) array[i]; + } + for (String frame : + frameNames) { + // For every frame in the animation delete the content table associated with the frame + Frame frameWithOnlyName = new Frame(animation.getOwner(), frame, new SubSpace3D()); + SQLManager.get(AnimationPlugin.plugin).deleteTable(getContentTableName(animation, frameWithOnlyName)); + } + + } + // Delete the frame table associated with the animation + SQLManager.get(AnimationPlugin.plugin).deleteTable(getFrameTableName(animation)); + + // Delete the row containing the animation in the animation table + PreparedStatement deleteAnimationRow = connection.prepareStatement( + "DELETE FROM " + ANIMATION_TABLE + + " WHERE " + COLUMN_ANIMATION_NAME + " = ? AND " + + COLUMN_ANIMATION_OWNER + " = ?"); + deleteAnimationRow.setString(1, animation.getAnimationName()); + deleteAnimationRow.setObject(2, animation.getOwner()); + deleteAnimationRow.executeUpdate(); } catch (SQLException e){ e.printStackTrace(); return false; @@ -223,8 +337,12 @@ public static boolean deleteAnimation(Animation animation){ /* START: Frame Operations */ - private static boolean createFrame(Animation animation, Frame frame, final String FRAMES_TABLE){ + public static boolean createFrame(Animation animation, Frame frame){ + final String FRAMES_TABLE = getFrameTableName(animation); try (Connection connection = SQLManager.getConnection()){ + // Create table for the frames + SQLManager.get(AnimationPlugin.plugin).createFrameTable(FRAMES_TABLE); + PreparedStatement insertFrameStatement = connection.prepareStatement( "INSERT INTO " + FRAMES_TABLE + " (" + COLUMN_FRAME_NAME + ", " + @@ -251,7 +369,7 @@ private static boolean createFrame(Animation animation, Frame frame, final Strin corner2 = corner2Optional.get(); insertFrameStatement.setString(4, DataFormats.HOCON.write(corner2.createSnapshot().toContainer())); } - if (corner1 != null && corner2 != null){ + if (frame.getContents().isPresent()){ if (!createContents(animation, frame)){ return false; } @@ -268,7 +386,9 @@ private static boolean createFrame(Animation animation, Frame frame, final Strin } } } - insertFrameStatement.setArray(5, connection.createArrayOf("VARCHAR2", contentPositions)); + insertFrameStatement.setObject(5, contentPositions); + } else { + insertFrameStatement.setObject(5, null); } insertFrameStatement.executeUpdate(); @@ -279,16 +399,144 @@ private static boolean createFrame(Animation animation, Frame frame, final Strin return true; } - private static boolean saveFrame(Animation animation, Frame frame){ - return false; + public static boolean saveFrame(Animation animation, Frame frame){ + final String FRAME_TABLE = getFrameTableName(animation); + final String CONTENT_TABLE = getContentTableName(animation, frame); + SQLManager.get(AnimationPlugin.plugin).createFrameTable(FRAME_TABLE); + + try (Connection connection = SQLManager.getConnection()){ + // Check to make sure the frame has been created + PreparedStatement beenCreated = connection.prepareStatement( + "SELECT * FROM " + FRAME_TABLE + + " WHERE " + COLUMN_FRAME_NAME + " = ? AND " + + COLUMN_FRAME_CREATOR + " = ?"); + beenCreated.setString(1, frame.getName()); + beenCreated.setObject(2, frame.getCreator()); + ResultSet resultSet = beenCreated.executeQuery(); + if (!resultSet.next()){ + return createFrame(animation, frame); + } + + // Update frame row + PreparedStatement statement = connection.prepareStatement( + "UPDATE " + FRAME_TABLE + " SET " + + COLUMN_FRAME_SUBSPACE_C1 + " = ?, " + + COLUMN_FRAME_SUBSPACE_C2 + " = ?, " + + COLUMN_FRAME_SUBSPACE_CONTENTS + " = ?" + + " WHERE " + + COLUMN_FRAME_NAME + " = ? AND " + + COLUMN_FRAME_CREATOR + " = ?"); + // SET Clause + Optional> corner1Optional = frame.getCornerOne(); + Optional> corner2Optional = frame.getCornerTwo(); + Location corner1 = null, corner2 = null; + + // Not using ifPresent here because you need to have a separate + // try-catch for the SQL and IOException (which is ugly) + if (corner1Optional.isPresent()){ + corner1 = corner1Optional.get(); + statement.setString(1, DataFormats.HOCON.write(corner1.createSnapshot().toContainer())); + } + if (corner2Optional.isPresent()){ + corner2 = corner2Optional.get(); + statement.setString(2, DataFormats.HOCON.write(corner2.createSnapshot().toContainer())); + } + if (frame.getContents().isPresent()){ + if (!createContents(animation, frame)){ + return false; + } + int xLen = Math.abs(Math.abs(corner1.getBlockX()) - Math.abs(corner2.getBlockX())); + int yLen = Math.abs(Math.abs(corner1.getBlockY()) - Math.abs(corner2.getBlockY())); + int zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ())); + + String[][][] contentPositions = new String[xLen][yLen][zLen]; + // Populate the contentPositions with coordinates in the format of "x|y|z" + for (int i = 0; i < xLen; i++) { + for (int j = 0; j < yLen; j++) { + for (int k = 0; k < zLen; k++) { + contentPositions[i][j][k] = i + "|" + j + "|" + k; + } + } + } + statement.setObject(3, contentPositions); + saveContents(CONTENT_TABLE, frame.getContents().get()); + } else { + statement.setObject(3, null); + } + + // WHERE Clause + statement.setString(4, frame.getName()); + statement.setObject(5, frame.getCreator()); + statement.executeUpdate(); + } catch (SQLException|IOException e){ + e.printStackTrace(); + return false; + } + return true; } - public static Optional getFrame(Animation animation, String frameName){ - return null; + public static Optional getFrame(String frameName, final String FRAME_TABLE, final String CONTENTS_TABLE){ + Frame frame = null; + try (Connection connection = SQLManager.getConnection()) { + PreparedStatement statement = connection.prepareStatement( + "SELECT * FROM " + FRAME_TABLE + + " WHERE " + COLUMN_FRAME_NAME + " = ?"); + statement.setString(1, frameName); + ResultSet rs = statement.executeQuery(); + if (rs.next()){ + + // Create SubSpace3D + SubSpace3D subSpace3D = new SubSpace3D(); + Optional c1 = BlockSnapshot.builder().build(DataFormats.HOCON.read(rs.getString(COLUMN_FRAME_SUBSPACE_C1))); + Optional c2 = BlockSnapshot.builder().build(DataFormats.HOCON.read(rs.getString(COLUMN_FRAME_SUBSPACE_C2))); + c1.ifPresent(blockSnapshot -> subSpace3D.setCornerOne(blockSnapshot.getLocation().orElse(null))); + c2.ifPresent(blockSnapshot -> subSpace3D.setCornerTwo(blockSnapshot.getLocation().orElse(null))); + + if (rs.getObject(COLUMN_FRAME_SUBSPACE_CONTENTS) != null){ + // Create and set contents of the SubSpace + Location corner1 = c1.get().getLocation().get(); + Location corner2 = c2.get().getLocation().get(); + + int xLen = Math.abs(Math.abs(corner1.getBlockX()) - Math.abs(corner2.getBlockX())) + 1; + int yLen = Math.abs(Math.abs(corner1.getBlockY()) - Math.abs(corner2.getBlockY())) + 1; + int zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ())) + 1; + + BlockSnapshot[][][] blockSnapshots = new BlockSnapshot[xLen][yLen][zLen]; + getContents(CONTENTS_TABLE, blockSnapshots); + subSpace3D.setContents(blockSnapshots); + } + + // Create Frame + String name = rs.getString(COLUMN_FRAME_NAME); + UUID creator = (UUID) rs.getObject(COLUMN_FRAME_CREATOR); + + frame = new Frame(creator, name, subSpace3D); + } + + + } catch (IOException|SQLException e){ + e.printStackTrace(); + } + return Optional.ofNullable(frame); } - public static Optional getFrame(String animationName, String frameName){ - return null; + public static boolean deleteFrame(Animation animation, Frame frame){ + final String FRAME_TABLE = getFrameTableName(animation); + final String CONTENT_TABLE = getContentTableName(animation, frame); + try (Connection connection = SQLManager.getConnection()){ + deleteContents(CONTENT_TABLE); + PreparedStatement statement = connection.prepareStatement( + "DELETE FROM " + FRAME_TABLE + + " WHERE " + COLUMN_FRAME_NAME + " = ? " + + "AND " + COLUMN_FRAME_CREATOR + " = ?"); + statement.setString(1, frame.getName()); + statement.setObject(2, frame.getCreator()); + statement.executeUpdate(); + } catch (SQLException e){ + e.printStackTrace(); + return false; + } + return true; } /* END: Frame Operations */ @@ -312,17 +560,19 @@ private static boolean createContents(Animation animation, Frame frame){ int zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ())); Optional blockSnapshotsOptional = frame.getContents(); if (!blockSnapshotsOptional.isPresent()){ - return false; + return true; } BlockSnapshot[][][] contents = blockSnapshotsOptional.get(); try (Connection connection = SQLManager.getConnection()){ + // The key is the coordinate in the format of "x|y|z" and the value + // is the HOCON translation of the BlockSnapShot's DataView Map contentPositions = new HashMap<>(); // Populate the contentPositions with coordinates in the format of "x|y|z" - for (int i = 0; i < xLen; i++) { - for (int j = 0; j < yLen; j++) { - for (int k = 0; k < zLen; k++) { + for (int i = 0; i <= xLen; i++) { + for (int j = 0; j <= yLen; j++) { + for (int k = 0; k <= zLen; k++) { contentPositions.put(i + "|" + j + "|" + k, DataFormats.HOCON.write(contents[i][j][k].toContainer())); } } @@ -352,14 +602,74 @@ private static boolean createContents(Animation animation, Frame frame){ return true; } - private static boolean saveContents(Animation animation, Frame frame){ - return false; + private static boolean saveContents(final String CONTENT_TABLE, BlockSnapshot[][][] blockSnapshots){ + int xLength = blockSnapshots.length; + int yLength = blockSnapshots[0].length; + int zLength = blockSnapshots[0][0].length; + + SQLManager.get(AnimationPlugin.plugin).createContentsTable(CONTENT_TABLE); + + try (Connection connection = SQLManager.getConnection()){ + // Delete all rows from the table + PreparedStatement statement = connection.prepareStatement("TRUNCATE TABLE " + CONTENT_TABLE); + statement.execute(); + for (int i = 0; i < xLength; i++) { + for (int j = 0; j < yLength; j++) { + for (int k = 0; k < zLength; k++) { + // Re add each block as a row + PreparedStatement statement1 = connection.prepareStatement( + "INSERT INTO " + CONTENT_TABLE + + " SET " + + COLUMN_CONTENTS_XYZ + " = ?, " + + COLUMN_CONTENTS_DATA + " = ?" + ); + statement1.setString(1, i + "|" + j + "|" + k); + statement1.setString(2, DataFormats.HOCON.write(blockSnapshots[i][j][k].toContainer())); + statement1.execute(); + } + } + } + connection.commit(); + } catch (SQLException|IOException e){ + e.printStackTrace(); + return false; + } + return true; + } + + private static void getContents(final String CONTENT_TABLE, BlockSnapshot[][][] blockSnapshotsReference){ + int xLength = blockSnapshotsReference.length; + int yLength = blockSnapshotsReference[0].length; + int zLength = blockSnapshotsReference[0][0].length; + + try (Connection connection = SQLManager.getConnection()) { + // X + for (int i = 0; i < xLength; i++) { + // Y + for (int j = 0; j < yLength; j++) { + // Z + for (int k = 0; k < zLength; k++) { + PreparedStatement statement = connection.prepareStatement( + "SELECT " + COLUMN_CONTENTS_DATA + + " FROM " + CONTENT_TABLE + + " WHERE " + COLUMN_CONTENTS_XYZ + " = ?"); + statement.setString(1, i + "|" + j + "|" + k); + ResultSet rs = statement.executeQuery(); + if (rs.next()){ + String data = rs.getString(COLUMN_CONTENTS_DATA); + blockSnapshotsReference[i][j][k] = BlockSnapshot.builder().build(DataFormats.HOCON.read(data)).get(); + } + } + } + } + } catch (SQLException|IOException e){ + e.printStackTrace(); + } } - private static BlockSnapshot[][][] getContents(Animation animation, Frame frame){ - return null; + private static void deleteContents(final String CONTENT_TABLE){ + SQLManager.get(AnimationPlugin.plugin).deleteTable(CONTENT_TABLE); } - /* END: Content Operations */ } From cd8fd0ea5d62312372568181526299bc4536b8ce Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 03:50:42 -0500 Subject: [PATCH 18/57] Reworked ENUM declaration in the schema of the animation table --- .../java/com/servegame/bl4de/Animation/data/SQLManager.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index 2370267..eeef24c 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -7,7 +7,6 @@ import javax.sql.DataSource; import java.sql.Connection; -import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.concurrent.ConcurrentHashMap; @@ -52,7 +51,7 @@ private void initSettings(){ connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + ANIMATION_TABLE + " (" + "name VARCHAR2(255), " + "owner UUID, " + - "status ENUM('STOPPED', 'RUNNING', 'PAUSED'), " + + "status VARCHAR_IGNORECASE(100) CHECK (status IN ('STOPPED', 'RUNNING', 'PAUSED')), " + "startFrameIndex INT, " + "tickDelay INT, " + "cycles INT, " + From 5924ae2aebf21817cbae73b3f0c4ae5ffdde5be6 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 03:51:45 -0500 Subject: [PATCH 19/57] - Encapsulated table names with backticks - Added additional animation table columns --- .../servegame/bl4de/Animation/data/SQLResources.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index ad33f3b..e1a88c3 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -21,8 +21,8 @@ class SQLResources { static final String COLUMN_ANIMATION_TICK_DELAY = "tickDelay"; static final String COLUMN_ANIMATION_CYCLES = "cycles"; static final String COLUMN_ANIMATION_FRAME_NAMES = "frameNames"; - static final String COLUMN_ANIMATION_C1 = "animation_corner1"; - static final String COLUMN_ANIMATION_C2 = "animation_corner2"; + static final String COLUMN_ANIMATION_C1 = "animation_cornerOne"; + static final String COLUMN_ANIMATION_C2 = "animation_cornerTwo"; /* Frame Table Constants */ static final String COLUMN_FRAME_NAME = "frameName"; @@ -47,7 +47,7 @@ class SQLResources { * @return String in the format of: animationName_owner_frames */ static String getFrameTableName(Animation animation){ - return animation.getAnimationName() + "_" + animation.getOwner().toString() + "_frames"; + return "`" + animation.getAnimationName() + "_" + animation.getOwner().toString() + "_frames`"; } /** @@ -61,8 +61,8 @@ static String getFrameTableName(Animation animation){ * @return String in the format of: animationName_owner_frameName_contents */ static String getContentTableName(Animation animation, Frame frame){ - return animation.getAnimationName() + "_" + + return "`" + animation.getAnimationName() + "_" + frame.getCreator().toString() + "_" + - frame.getName() + "_contents"; + frame.getName() + "_contents`"; } } From 6c17a1d6dc9dc9ca0bacb6042d6d7014952ed029 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 03:54:03 -0500 Subject: [PATCH 20/57] Ensured the animation is initialized before attempting to start it. Just catching the UnitializedException leads to a problem where the status of the animation is set to playing before the exception is thrown and doesn't get reverted. --- .../Animation/command/animation/action/StartAnimation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StartAnimation.java b/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StartAnimation.java index 5722015..2db893c 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StartAnimation.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StartAnimation.java @@ -40,6 +40,12 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } Animation animation = animationOptional.get(); + if (!animation.isInitialized()){ + // Animation is not initialized + player.sendMessage(TextResponses.ANIMATION_NOT_INITIALIZED_ERROR); + return CommandResult.success(); + } + if (animation.getStatus() == Animation.Status.RUNNING){ // Animation is already running player.sendMessage(TextResponses.ANIMATION_ALREADY_RUNNING); From e7c7144dcfe30e25593074fa1c22e81cde3636e6 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 03:56:45 -0500 Subject: [PATCH 21/57] Added frame has no content message --- .../java/com/servegame/bl4de/Animation/util/TextResponses.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/util/TextResponses.java b/src/main/java/com/servegame/bl4de/Animation/util/TextResponses.java index a98459e..ccabe9b 100644 --- a/src/main/java/com/servegame/bl4de/Animation/util/TextResponses.java +++ b/src/main/java/com/servegame/bl4de/Animation/util/TextResponses.java @@ -54,6 +54,7 @@ public class TextResponses { public static final Text FRAME_DELETE_ERROR = Text.of(ERROR_COLOR, "There was a problem deleting the frame."); public static final Text FRAME_NOT_DISPLAYED_ERROR = Text.of(ERROR_COLOR, "There was a problem displaying the frame."); public static final Text FRAME_FAILED_DUPLICATION_ERROR = Text.of(ERROR_COLOR, "There was a problem duplicating the frame."); + public static final Text FRAME_HAS_NO_CONTENT = Text.of(ERROR_COLOR, "The frame does not have any content."); // Other Error Responses From 041d5ac2facce97e7204c145cd28744d36c25608 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 05:08:18 -0500 Subject: [PATCH 22/57] Readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e66e8a..4347f42 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The Animation plugin works mostly as intended. The max animation size has been s See the wiki for the commands and their respective usages. (Still a WIP) #### Known bugs / Not Implemented Yet -* Many tile entities are wonky and mostly don't work +* Many tile entities are wonky and ~~mostly don't work~~ don't retain their data * At a certain point the animation becomes too big and won't load -- leads to a OutOfMemory exception * Pause button does nothing * Settings button does nothing From 2017cb904dc8619f6fa13ed92ca4e86a23453d47 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 05:08:39 -0500 Subject: [PATCH 23/57] Removed debug message --- src/main/java/com/servegame/bl4de/Animation/util/Util.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/util/Util.java b/src/main/java/com/servegame/bl4de/Animation/util/Util.java index bc350be..70b1e70 100644 --- a/src/main/java/com/servegame/bl4de/Animation/util/Util.java +++ b/src/main/java/com/servegame/bl4de/Animation/util/Util.java @@ -112,7 +112,6 @@ public static void copySubSpaceToWorld(SubSpace3D subSpace) throws Uninitialized int xLength = subSpaceSnapShot.length; int yLength = subSpaceSnapShot[0].length; int zLength = subSpaceSnapShot[0][0].length; - System.out.println(xLength + ", " + yLength + ", " + zLength); // Y for (int x = 0; x < xLength; x++) { @@ -202,9 +201,9 @@ public static Optional getOfflinePlayer(UUID uuid, CommandSource src){ */ public static long calculateVolume(Location corner1, Location corner2){ // Get absolute length of sub space dimensions - long xLen = Math.abs(Math.abs(corner1.getBlockX()) - Math.abs(corner2.getBlockX())); - long yLen = Math.abs(Math.abs(corner1.getBlockY()) - Math.abs(corner2.getBlockY())); - long zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ())); + long xLen = Math.abs(Math.abs(corner1.getBlockX()) - Math.abs(corner2.getBlockX())) + 1; + long yLen = Math.abs(Math.abs(corner1.getBlockY()) - Math.abs(corner2.getBlockY())) + 1; + long zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ())) + 1; return xLen * yLen * zLen; } From 9d360b17ca8834c6c488d1077fa5cf78a91c142d Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 13:10:58 -0500 Subject: [PATCH 24/57] Small optimization --- .../bl4de/Animation/command/animation/ListAnimation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/animation/ListAnimation.java b/src/main/java/com/servegame/bl4de/Animation/command/animation/ListAnimation.java index f99154e..a85cc15 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/animation/ListAnimation.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/animation/ListAnimation.java @@ -41,7 +41,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm int animationsToList = animationsByOwner.size() > 10 ? 10 : animationsByOwner.size(); for (int i = 0; i < animationsToList; i++) { // Add all animations that are owned into a Text object - Optional optionalAnimation = AnimationController.getAnimation(animationsByOwner.get(i), player.getUniqueId()); + Optional optionalAnimation = AnimationController.getBareAnimation(animationsByOwner.get(i), player.getUniqueId()); if (!optionalAnimation.isPresent()){ // There are no animations to display if (AnimationPlugin.instance.isDebug()){ @@ -87,7 +87,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } if (!displayedAAnimation){ // There were animations to display but weren't - player.sendMessage(Text.of(PRIMARY_COLOR, "There were no animations displayed.")); + player.sendMessage(Text.of(PRIMARY_COLOR, "No animations were displayed.")); } return CommandResult.success(); } From 4da8c5e9f6dc488c3201f5d2c88ed49182431eb0 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 13:11:19 -0500 Subject: [PATCH 25/57] Created getBareAnimation method --- .../bl4de/Animation/controller/AnimationController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java index d0c4fcf..0095126 100644 --- a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java +++ b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java @@ -103,6 +103,10 @@ public static Optional getAnimation(String name, UUID owner){ return PreparedStatements.getAnimation(name, owner); } + public static Optional getBareAnimation(String name, UUID owner){ + return PreparedStatements.getBareAnimation(name, owner); + } + /** * TODO * @param owner From 5195e483238fdae40117d29c8da2ff8457a2df2a Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 13:11:49 -0500 Subject: [PATCH 26/57] When deleting the table, it's ensured it exists --- .../java/com/servegame/bl4de/Animation/data/SQLManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index eeef24c..7c260fc 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -113,7 +113,7 @@ void createFrameTable(String tableName){ void deleteTable(String tableName){ try (Connection connection = SQLManager.getConnection()){ - connection.prepareStatement("DROP TABLE " + tableName); + connection.prepareStatement("DROP TABLE IF EXISTS " + tableName).executeUpdate(); } catch (SQLException e){ e.printStackTrace(); } From 2f0d2f51fb2698fcc3389be4cb824524e034749b Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 17:06:47 -0500 Subject: [PATCH 27/57] Created class to convert animations from the previous db schema to the next --- .../Animation/data/DatabaseSchemaUpdates.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java diff --git a/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java b/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java new file mode 100644 index 0000000..06e3f8c --- /dev/null +++ b/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java @@ -0,0 +1,74 @@ +package com.servegame.bl4de.Animation.data; + +import com.servegame.bl4de.Animation.AnimationPlugin; +import com.servegame.bl4de.Animation.data.PreparedStatements; +import com.servegame.bl4de.Animation.data.SQLManager; +import com.servegame.bl4de.Animation.model.Animation; +import com.servegame.bl4de.Animation.util.Util; +import org.spongepowered.api.data.persistence.InvalidDataException; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +/** + * File: DatabaseSchemaUpdates.java + * @author Brandon Bires-Navel (brandonnavel@outlook.com) + */ +public class DatabaseSchemaUpdates { + + private static final String TABLE_VERSION_ONE = "ANIMATION_TABLE"; + + + /** + * Version one of the database was a single table named "animation_table", this schema + * will be converted to the newer version of the database + * @return boolean - whether the old table was found or not + */ + public static boolean checkForVersionOne(){ + try (Connection connection = SQLManager.getConnection()){ + ResultSet rs = connection.getMetaData() + .getTables(null, null, TABLE_VERSION_ONE, null); + if (rs.next()){ + return true; + } + connection.close(); + } catch (Exception e){ + return false; + } + return false; + } + + public static boolean convertVersionOneToVersionTwo(){ + // Backup Database + ArrayList animations = new ArrayList<>(); + try (Connection connection = SQLManager.getConnection()){ + PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + TABLE_VERSION_ONE); + ResultSet rs = statement.executeQuery(); + while (rs.next()){ + System.out.println(rs.getString("name")); + Animation tmp = Animation.deserialize(Util.encapColons(rs.getString("data"))); + animations.add(tmp); + } + } catch (SQLException e){ + e.printStackTrace(); + return false; + } + try { + for (Animation animation : + animations) { + PreparedStatements.createAnimation(animation); + } + } catch (InvalidDataException e){ + AnimationPlugin.logger.error("Failed to convert an animation. ", e); + } + SQLManager.get(AnimationPlugin.plugin).deleteTable(TABLE_VERSION_ONE); + return true; + } +} From 7e814913c7194ff0095fffbe7088d8d9d45cfe5b Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 17:08:24 -0500 Subject: [PATCH 28/57] Class to convert the old db schema to the new one --- .../bl4de/Animation/data/DatabaseSchemaUpdates.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java b/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java index 06e3f8c..054039b 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java @@ -1,16 +1,10 @@ package com.servegame.bl4de.Animation.data; import com.servegame.bl4de.Animation.AnimationPlugin; -import com.servegame.bl4de.Animation.data.PreparedStatements; -import com.servegame.bl4de.Animation.data.SQLManager; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.util.Util; import org.spongepowered.api.data.persistence.InvalidDataException; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; From ca7d8264dfb1e1313df2c31016d63aa04bf00d38 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 17:09:06 -0500 Subject: [PATCH 29/57] Test to see if the db needs to be updated --- .../servegame/bl4de/Animation/AnimationPlugin.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java b/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java index e60d655..2141a20 100644 --- a/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java +++ b/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java @@ -4,6 +4,7 @@ import com.servegame.bl4de.Animation.controller.AnimationController; import com.servegame.bl4de.Animation.data.SQLManager; import com.servegame.bl4de.Animation.task.TaskManager; +import com.servegame.bl4de.Animation.data.DatabaseSchemaUpdates; import com.servegame.bl4de.Animation.util.Resource; import com.servegame.bl4de.Animation.util.Util; import org.slf4j.Logger; @@ -35,8 +36,8 @@ public class AnimationPlugin { @Inject private Game game; - private final String CONFIG_DIR = "./config/animation"; - private final String ANIMATION_DATA_DIR = CONFIG_DIR + "/animations"; + public final String CONFIG_DIR = "./config/animation"; + public final String ANIMATION_DATA_DIR = CONFIG_DIR + "/animation"; private boolean debug; @@ -50,6 +51,12 @@ public void onConstruction(GameConstructionEvent event){ instance = this; plugin = Sponge.getPluginManager().getPlugin(Resource.ID).get(); taskManager = new TaskManager(); + + logger.info("Checking database structure..."); + if (DatabaseSchemaUpdates.checkForVersionOne()){ + logger.info("...Old database structure found, converting animations."); + DatabaseSchemaUpdates.convertVersionOneToVersionTwo(); + } } @Listener From 42bfd120125102dde8327f41aa2553a683750402 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 20:50:48 -0500 Subject: [PATCH 30/57] Moved the database alteration to the GameServerStart event (This allows access to the worlds) --- .../bl4de/Animation/AnimationPlugin.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java b/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java index 2141a20..00d7af5 100644 --- a/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java +++ b/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java @@ -51,12 +51,6 @@ public void onConstruction(GameConstructionEvent event){ instance = this; plugin = Sponge.getPluginManager().getPlugin(Resource.ID).get(); taskManager = new TaskManager(); - - logger.info("Checking database structure..."); - if (DatabaseSchemaUpdates.checkForVersionOne()){ - logger.info("...Old database structure found, converting animations."); - DatabaseSchemaUpdates.convertVersionOneToVersionTwo(); - } } @Listener @@ -82,9 +76,21 @@ public void onInit(GameInitializationEvent event){ @Listener public void onLoad(GameLoadCompleteEvent event){ + instance = this; + plugin = Sponge.getPluginManager().getPlugin(Resource.ID).get(); + taskManager = new TaskManager(); logger.info("Animation has loaded."); } + @Listener + public void onServerStart(GameStartingServerEvent event){ + logger.info("Checking database structure..."); + if (DatabaseSchemaUpdates.checkForVersionOne()){ + logger.info("...Old database structure found, converting animations."); + DatabaseSchemaUpdates.convertVersionOneToVersionTwo(); + } + } + @Listener public void onStop(GameStoppingEvent event){ logger.info("Stopping animations..."); From b3a28904ef77a2d7cfa92f63ac4fef53804b3881 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 20:53:15 -0500 Subject: [PATCH 31/57] Removed debug message --- .../servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java b/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java index 054039b..6b4aee9 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/DatabaseSchemaUpdates.java @@ -46,7 +46,6 @@ public static boolean convertVersionOneToVersionTwo(){ PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + TABLE_VERSION_ONE); ResultSet rs = statement.executeQuery(); while (rs.next()){ - System.out.println(rs.getString("name")); Animation tmp = Animation.deserialize(Util.encapColons(rs.getString("data"))); animations.add(tmp); } From 36faa2625b813b3957c2a93b588738382cd92845 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Sat, 23 Dec 2017 20:58:20 -0500 Subject: [PATCH 32/57] Altered createAnimation PreparedStatement - Set the subspace of the animation in the database --- .../Animation/data/PreparedStatements.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java index b62607f..fd143ac 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java @@ -42,8 +42,10 @@ public static boolean createAnimation(Animation animation){ COLUMN_ANIMATION_START_FRAME_INDEX + ", " + COLUMN_ANIMATION_TICK_DELAY + ", " + COLUMN_ANIMATION_CYCLES + ", " + - COLUMN_ANIMATION_FRAME_NAMES +") " + - " VALUES (?, ?, ?, ?, ?, ?, ?)" + COLUMN_ANIMATION_FRAME_NAMES + ", " + + COLUMN_ANIMATION_C1 + ", " + + COLUMN_ANIMATION_C2 + ") " + + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" ); // Put all the names of the frames into a list final List frames = animation.getFrames(); @@ -57,6 +59,18 @@ public static boolean createAnimation(Animation animation){ statement.setInt(5, animation.getTickDelay()); // Tick delay statement.setInt(6, animation.getCycles()); // Cycles statement.setObject(7, frameNames.toArray()); + Optional> locationOptional1 = animation.getSubSpace().getCornerOne(); + Optional> locationOptional2 = animation.getSubSpace().getCornerTwo(); + if (locationOptional1.isPresent()){ + statement.setString(8, DataFormats.HOCON.write(locationOptional1.get().createSnapshot().toContainer())); + } else { + statement.setString(8, null); + } + if (locationOptional2.isPresent()){ + statement.setString(9, DataFormats.HOCON.write(locationOptional2.get().createSnapshot().toContainer())); + } else { + statement.setString(9, null); + } statement.executeUpdate(); // Add all the frames @@ -67,7 +81,7 @@ public static boolean createAnimation(Animation animation){ return false; } } - } catch (SQLException e){ + } catch (SQLException|IOException e){ e.printStackTrace(); return false; } From 31025e6247baf8561f412226173157bd591caba1 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Mon, 25 Dec 2017 21:02:24 -0500 Subject: [PATCH 33/57] When obtaining the frame it gets the entire frame. Where the animation it is handed is bare and doesn't have frame content. --- .../servegame/bl4de/Animation/command/frame/DeleteFrame.java | 3 +-- .../servegame/bl4de/Animation/command/frame/DisplayFrame.java | 4 ++-- .../bl4de/Animation/command/frame/DuplicateFrame.java | 4 ++-- .../servegame/bl4de/Animation/command/frame/InfoFrame.java | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java index 62dbebe..7bedd92 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java @@ -55,8 +55,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm Optional frameOptional; if (StringUtils.isNumeric(frameName)){ // They gave the frame number - Integer frameNum = Integer.valueOf(frameName); - frameOptional = this.animation.getFrame(frameNum); + frameOptional = this.animation.getFrame(Integer.valueOf(frameName)); } else { // They gave the frame name frameOptional = this.animation.getFrame(frameName); diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java index db04b6c..cf09494 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DisplayFrame.java @@ -52,10 +52,10 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm if (isNumeric(frameName)){ // User specified a frame number 0, 1, ..., n - frameOptional = this.animation.getFrame(Integer.parseInt(frameName)); + frameOptional = FrameController.getFrameWithContents(this.animation, Integer.parseInt(frameName)); } else { // User specified a frame name - frameOptional = this.animation.getFrame(frameName); + frameOptional = FrameController.getFrameWithContents(this.animation, frameName); } if (!frameOptional.isPresent()){ diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java index 624f1da..ace8394 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java @@ -54,10 +54,10 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm if (isNumeric(frameName)){ // User specified a frame number 0, 1, ..., n - frameOptional = this.animation.getFrame(Integer.parseInt(frameName)); + frameOptional = FrameController.getFrameWithContents(this.animation, Integer.parseInt(frameName)); } else { // User specified a frame name - frameOptional = this.animation.getFrame(frameName); + frameOptional = FrameController.getFrameWithContents(this.animation, frameName); } if (!frameOptional.isPresent()){ diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/InfoFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/InfoFrame.java index d0ac939..63f4533 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/InfoFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/InfoFrame.java @@ -50,10 +50,10 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm if (isNumeric(frameName)){ // User specified a frame number 0, 1, ..., n - frameOptional = this.animation.getFrame(Integer.parseInt(frameName)); + frameOptional = FrameController.getFrameWithContents(this.animation, Integer.parseInt(frameName)); } else { // User specified a frame name - frameOptional = this.animation.getFrame(frameName); + frameOptional = FrameController.getFrameWithContents(this.animation, frameName); } if (!frameOptional.isPresent()){ From 2b3f7cc4a1e5a77ccce41c18b2396a9b0d7fcf49 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Mon, 25 Dec 2017 21:03:07 -0500 Subject: [PATCH 34/57] Added methods to get full frames by name and index --- .../Animation/controller/FrameController.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java b/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java index f8aa79c..0c6df50 100644 --- a/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java +++ b/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java @@ -1,5 +1,7 @@ package com.servegame.bl4de.Animation.controller; +import com.servegame.bl4de.Animation.data.PreparedStatements; +import com.servegame.bl4de.Animation.data.SQLResources; import com.servegame.bl4de.Animation.exception.UninitializedException; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; @@ -9,7 +11,9 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.text.action.TextActions; +import java.sql.PreparedStatement; import java.util.List; +import java.util.Optional; import java.util.Random; import static com.servegame.bl4de.Animation.util.Util.*; @@ -59,6 +63,31 @@ public static String generateFrameName(Animation animation){ return "frame" + ((Integer) new Random().nextInt(999999)).toString(); } + /** + * + * @param animation + * @param index + * @return + */ + public static Optional getFrameWithContents(Animation animation, int index){ + String frameName = animation.getFrame(index).get().getName(); + return PreparedStatements.getFrame( + frameName, + SQLResources.getFrameTableName(animation), + SQLResources.getContentTableName(animation, animation.getFrame(index).get()), + true + ); + } + + public static Optional getFrameWithContents(Animation animation, String name){ + return PreparedStatements.getFrame( + name, + SQLResources.getFrameTableName(animation), + SQLResources.getContentTableName(animation, animation.getFrame(name).get()), + true + ); + } + /** * TODO * @param name From 443734769bb7786c472d27ccef4a6bcfd0714ae8 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Mon, 25 Dec 2017 21:03:26 -0500 Subject: [PATCH 35/57] Made the class and most of the methods public --- .../com/servegame/bl4de/Animation/data/SQLResources.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java index e1a88c3..5f1d985 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLResources.java @@ -9,7 +9,7 @@ * * @author Brandon Bires-Navel (brandonnavel@outlook.com) */ -class SQLResources { +public class SQLResources { /* Animation Table Constants */ static final String ANIMATION_TABLE = "animations"; @@ -46,7 +46,7 @@ class SQLResources { * @param animation {@link Animation} to create the name for a frame table * @return String in the format of: animationName_owner_frames */ - static String getFrameTableName(Animation animation){ + public static String getFrameTableName(Animation animation){ return "`" + animation.getAnimationName() + "_" + animation.getOwner().toString() + "_frames`"; } @@ -60,7 +60,7 @@ static String getFrameTableName(Animation animation){ * the created table * @return String in the format of: animationName_owner_frameName_contents */ - static String getContentTableName(Animation animation, Frame frame){ + public static String getContentTableName(Animation animation, Frame frame){ return "`" + animation.getAnimationName() + "_" + frame.getCreator().toString() + "_" + frame.getName() + "_contents`"; From 782952927a34259ab0b7745e7c1d343984a2ea00 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Mon, 25 Dec 2017 21:21:23 -0500 Subject: [PATCH 36/57] Updated frame commands to utilize the FrameController --- .../bl4de/Animation/command/frame/CreateFrame.java | 4 ++-- .../bl4de/Animation/command/frame/DeleteFrame.java | 3 ++- .../Animation/command/frame/DuplicateFrame.java | 2 +- .../bl4de/Animation/command/frame/SetFrame.java | 13 +++---------- .../bl4de/Animation/command/frame/UpdateFrame.java | 3 ++- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java index ea94620..34f8df9 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java @@ -1,9 +1,9 @@ package com.servegame.bl4de.Animation.command.frame; +import com.servegame.bl4de.Animation.controller.FrameController; import com.servegame.bl4de.Animation.exception.UninitializedException; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; -import com.servegame.bl4de.Animation.controller.AnimationController; import com.servegame.bl4de.Animation.util.TextResponses; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; @@ -59,7 +59,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm player.sendMessage(Text.of(" ", uie.getDetailText())); return CommandResult.success(); } - if (AnimationController.saveAnimation(this.animation)){ + if (FrameController.createFrame(this.animation, frame)){ // Animation was updated and saved player.sendMessage(Text.of(PRIMARY_COLOR, "Frame ", PRIMARY_COLOR, "'", diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java index 7bedd92..3e69653 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java @@ -1,5 +1,6 @@ package com.servegame.bl4de.Animation.command.frame; +import com.servegame.bl4de.Animation.controller.FrameController; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; import com.servegame.bl4de.Animation.controller.AnimationController; @@ -83,7 +84,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } this.animation.deleteFrame(frameToDelete); - if (AnimationController.saveAnimation(this.animation)){ + if (FrameController.deleteFrame(this.animation, frameToDelete)){ // Animation changed and saved Text message = Text.builder() .append(Text.of(PRIMARY_COLOR, "Frame '", diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java index ace8394..b47889a 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java @@ -94,7 +94,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } if (frameInserted){ // Frame went in just fine - if (AnimationController.saveAnimation(this.animation)){ + if (FrameController.createFrame(this.animation, newFrame)){ Text message = Text.of( PRIMARY_COLOR, "Frame '", NAME_COLOR, theFrame.getName(), diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java index a8edeb0..cd5c21b 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java @@ -1,5 +1,6 @@ package com.servegame.bl4de.Animation.command.frame; +import com.servegame.bl4de.Animation.controller.FrameController; import com.servegame.bl4de.Animation.exception.UninitializedException; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; @@ -73,17 +74,9 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm player.sendMessage(TextResponses.GENERAL_ARGUMENTS_INCORRECT); return CommandResult.empty(); } - // Get the index of the frame needing renaming, remove the frame, - // change the name, readd the frame at the same index - int frameIndex = this.animation.getIndexOfFrame(frame); - this.animation.removeFrame(frame); + // Modify the frame and save the frame that is being changed frame.setName(newFrameNameOptional.get()); - try { - this.animation.addFrame(frame, frameIndex); - } catch (UninitializedException e) { - // This should never happen - player.sendMessage(TextResponses.FRAME_NOT_INITIALIZED_ERROR); - } + FrameController.saveFrame(this.animation, frame); } return CommandResult.success(); } diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java index e87ba83..71086d0 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java @@ -1,6 +1,7 @@ package com.servegame.bl4de.Animation.command.frame; import com.servegame.bl4de.Animation.controller.AnimationController; +import com.servegame.bl4de.Animation.controller.FrameController; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; import com.servegame.bl4de.Animation.util.TextResponses; @@ -66,7 +67,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm frame.setContents(Util.copyWorldToSubSpace(frame.getCornerOne().get(), frame.getCornerTwo().get())); // Save the Animation - if (AnimationController.saveAnimation(this.animation)){ + if (FrameController.saveFrame(this.animation, frame)){ // Animation was saved successfully player.sendMessage(Text.of(Util.PRIMARY_COLOR, "Frame ", Util.PRIMARY_COLOR, "'", From 07b199ed27867bd44cc4a7a56ad611597e9dbdd9 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Mon, 25 Dec 2017 21:21:40 -0500 Subject: [PATCH 37/57] Added Frame controlling functionality --- .../bl4de/Animation/controller/FrameController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java b/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java index 0c6df50..ebeb47d 100644 --- a/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java +++ b/src/main/java/com/servegame/bl4de/Animation/controller/FrameController.java @@ -88,6 +88,18 @@ public static Optional getFrameWithContents(Animation animation, String n ); } + public static boolean saveFrame(Animation animation, Frame frame){ + return PreparedStatements.saveFrame(animation, frame); + } + + public static boolean createFrame(Animation animation, Frame frame){ + return PreparedStatements.createFrame(animation, frame); + } + + public static boolean deleteFrame(Animation animation, Frame frame){ + return PreparedStatements.deleteFrame(animation, frame); + } + /** * TODO * @param name From 4c2077fa7a1605cc704e4dd9605aab6b701e91be Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 00:17:08 -0500 Subject: [PATCH 38/57] getContents optimization --- .../Animation/data/PreparedStatements.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java index fd143ac..5811b94 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java @@ -657,24 +657,17 @@ private static void getContents(final String CONTENT_TABLE, BlockSnapshot[][][] int zLength = blockSnapshotsReference[0][0].length; try (Connection connection = SQLManager.getConnection()) { - // X - for (int i = 0; i < xLength; i++) { - // Y - for (int j = 0; j < yLength; j++) { - // Z - for (int k = 0; k < zLength; k++) { - PreparedStatement statement = connection.prepareStatement( - "SELECT " + COLUMN_CONTENTS_DATA + - " FROM " + CONTENT_TABLE + - " WHERE " + COLUMN_CONTENTS_XYZ + " = ?"); - statement.setString(1, i + "|" + j + "|" + k); - ResultSet rs = statement.executeQuery(); - if (rs.next()){ - String data = rs.getString(COLUMN_CONTENTS_DATA); - blockSnapshotsReference[i][j][k] = BlockSnapshot.builder().build(DataFormats.HOCON.read(data)).get(); - } - } - } + PreparedStatement statement = connection.prepareStatement( + "SELECT *" + " FROM " + CONTENT_TABLE); + ResultSet rs = statement.executeQuery(); + while (rs.next()){ + String posData = rs.getString(COLUMN_CONTENTS_XYZ); + String data = rs.getString(COLUMN_CONTENTS_DATA); + String[] xyzData = posData.split("\\|"); + int x = Integer.parseInt(xyzData[0]); + int y = Integer.parseInt(xyzData[1]); + int z = Integer.parseInt(xyzData[2]); + blockSnapshotsReference[x][y][z] = BlockSnapshot.builder().build(DataFormats.HOCON.read(data)).get(); } } catch (SQLException|IOException e){ e.printStackTrace(); From 7fefb7c5a2e919570d4a75ce6d7dbdc0fd3bf32a Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 14:33:14 -0500 Subject: [PATCH 39/57] Updated how the frames are saved -- for most of them it's enough just to save the animation --- .../Animation/command/frame/CreateFrame.java | 8 +++---- .../Animation/command/frame/DeleteFrame.java | 9 ++++---- .../command/frame/DuplicateFrame.java | 2 +- .../Animation/command/frame/SetFrame.java | 21 ++++++++++++++++--- .../Animation/command/frame/UpdateFrame.java | 1 - 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java index 34f8df9..bf8f92f 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/CreateFrame.java @@ -1,6 +1,6 @@ package com.servegame.bl4de.Animation.command.frame; -import com.servegame.bl4de.Animation.controller.FrameController; +import com.servegame.bl4de.Animation.controller.AnimationController; import com.servegame.bl4de.Animation.exception.UninitializedException; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; @@ -13,10 +13,10 @@ import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.text.Text; -import static com.servegame.bl4de.Animation.util.Util.*; - import java.util.Optional; +import static com.servegame.bl4de.Animation.util.Util.*; + /** * File: CreateFrame.java * @@ -59,7 +59,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm player.sendMessage(Text.of(" ", uie.getDetailText())); return CommandResult.success(); } - if (FrameController.createFrame(this.animation, frame)){ + if (AnimationController.saveAnimation(this.animation)){ // Animation was updated and saved player.sendMessage(Text.of(PRIMARY_COLOR, "Frame ", PRIMARY_COLOR, "'", diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java index 3e69653..77f9d80 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DeleteFrame.java @@ -1,9 +1,8 @@ package com.servegame.bl4de.Animation.command.frame; -import com.servegame.bl4de.Animation.controller.FrameController; +import com.servegame.bl4de.Animation.controller.AnimationController; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; -import com.servegame.bl4de.Animation.controller.AnimationController; import com.servegame.bl4de.Animation.util.TextResponses; import org.apache.commons.lang3.StringUtils; import org.spongepowered.api.command.CommandException; @@ -15,10 +14,10 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.text.action.TextActions; -import static com.servegame.bl4de.Animation.util.Util.*; - import java.util.Optional; +import static com.servegame.bl4de.Animation.util.Util.*; + /** * File: DeleteFrame.java * @@ -84,7 +83,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } this.animation.deleteFrame(frameToDelete); - if (FrameController.deleteFrame(this.animation, frameToDelete)){ + if (AnimationController.saveAnimation(this.animation)){ // Animation changed and saved Text message = Text.builder() .append(Text.of(PRIMARY_COLOR, "Frame '", diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java index b47889a..ace8394 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/DuplicateFrame.java @@ -94,7 +94,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } if (frameInserted){ // Frame went in just fine - if (FrameController.createFrame(this.animation, newFrame)){ + if (AnimationController.saveAnimation(this.animation)){ Text message = Text.of( PRIMARY_COLOR, "Frame '", NAME_COLOR, theFrame.getName(), diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java index cd5c21b..d2631af 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/SetFrame.java @@ -1,7 +1,6 @@ package com.servegame.bl4de.Animation.command.frame; -import com.servegame.bl4de.Animation.controller.FrameController; -import com.servegame.bl4de.Animation.exception.UninitializedException; +import com.servegame.bl4de.Animation.controller.AnimationController; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; import com.servegame.bl4de.Animation.util.TextResponses; @@ -12,9 +11,13 @@ import org.spongepowered.api.command.args.CommandContext; import org.spongepowered.api.command.spec.CommandExecutor; import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.text.Text; import java.util.Optional; +import static com.servegame.bl4de.Animation.util.Util.NAME_COLOR; +import static com.servegame.bl4de.Animation.util.Util.PRIMARY_COLOR; + /** * File: SetFrame.java * @@ -76,7 +79,19 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } // Modify the frame and save the frame that is being changed frame.setName(newFrameNameOptional.get()); - FrameController.saveFrame(this.animation, frame); + if (AnimationController.saveAnimation(this.animation)){ + Text message = Text.of( + PRIMARY_COLOR, "Frame has been renamed and is now known as '", + NAME_COLOR, frame.getName(), + PRIMARY_COLOR, "'", + PRIMARY_COLOR, ". " + ); + player.sendMessage(message); + return CommandResult.success(); + } else { + player.sendMessage(TextResponses.ANIMATION_SAVE_ERROR); + return CommandResult.empty(); + } } return CommandResult.success(); } diff --git a/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java b/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java index 71086d0..462c4c4 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/frame/UpdateFrame.java @@ -1,6 +1,5 @@ package com.servegame.bl4de.Animation.command.frame; -import com.servegame.bl4de.Animation.controller.AnimationController; import com.servegame.bl4de.Animation.controller.FrameController; import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.model.Frame; From f3234fd0fc39181c0a4db8eb480068a30223226b Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 14:34:07 -0500 Subject: [PATCH 40/57] When the animation is loaded, it's a bare animation. Any commands that need frame contents will get the frame contents specifically --- .../servegame/bl4de/Animation/command/CommandGateKeeper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/CommandGateKeeper.java b/src/main/java/com/servegame/bl4de/Animation/command/CommandGateKeeper.java index 8665bf1..9770bf8 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/CommandGateKeeper.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/CommandGateKeeper.java @@ -4,8 +4,8 @@ import com.servegame.bl4de.Animation.command.animation.InfoAnimation; import com.servegame.bl4de.Animation.command.animation.SetAnimation; import com.servegame.bl4de.Animation.command.frame.*; -import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.controller.AnimationController; +import com.servegame.bl4de.Animation.model.Animation; import com.servegame.bl4de.Animation.util.TextResponses; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; @@ -42,7 +42,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm return CommandResult.success(); } String animationName = animationNameOptional.get(); - Optional animationOptional = AnimationController.getAnimation(animationName, player.getUniqueId()); + Optional animationOptional = AnimationController.getBareAnimation(animationName, player.getUniqueId()); if (!animationOptional.isPresent()){ // Animation wasn't found player.sendMessage(TextResponses.ANIMATION_NOT_FOUND_ERROR); From bc37ace9c3aef6a02532e3e1e3a5e44331ae3f6a Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 14:34:35 -0500 Subject: [PATCH 41/57] The bare animation is used instead of getting the full animation --- .../Animation/command/animation/action/PauseAnimation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/animation/action/PauseAnimation.java b/src/main/java/com/servegame/bl4de/Animation/command/animation/action/PauseAnimation.java index a5c9b89..3ec4b07 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/animation/action/PauseAnimation.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/animation/action/PauseAnimation.java @@ -32,7 +32,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm player.sendMessage(TextResponses.ANIMATION_NOT_SPECIFIED_ERROR); return CommandResult.empty(); } - Optional animationOptional = AnimationController.getAnimation(animationNameOptional.get(), player.getUniqueId()); + Optional animationOptional = AnimationController.getBareAnimation(animationNameOptional.get(), player.getUniqueId()); if (!animationOptional.isPresent()){ player.sendMessage(TextResponses.ANIMATION_NOT_FOUND_ERROR); return CommandResult.success(); From b401887b685158cbd69ab62a6e10a05fc8a8f961 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 14:34:57 -0500 Subject: [PATCH 42/57] The bare animation is used instead of the full animation --- .../bl4de/Animation/command/animation/action/StopAnimation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StopAnimation.java b/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StopAnimation.java index 6119280..41687d5 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StopAnimation.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/animation/action/StopAnimation.java @@ -32,7 +32,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm player.sendMessage(TextResponses.ANIMATION_NOT_SPECIFIED_ERROR); return CommandResult.empty(); } - Optional animationOptional = AnimationController.getAnimation(animationNameOptional.get(), player.getUniqueId()); + Optional animationOptional = AnimationController.getBareAnimation(animationNameOptional.get(), player.getUniqueId()); if (!animationOptional.isPresent()){ player.sendMessage(TextResponses.ANIMATION_NOT_FOUND_ERROR); return CommandResult.success(); From c835c813b059872fc5c931eec336a943cc3e4fdd Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 14:36:32 -0500 Subject: [PATCH 43/57] Changed return value on parse method --- .../bl4de/Animation/command/element/AnimationElement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/element/AnimationElement.java b/src/main/java/com/servegame/bl4de/Animation/command/element/AnimationElement.java index 319e9cd..d4ce605 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/element/AnimationElement.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/element/AnimationElement.java @@ -33,7 +33,7 @@ public AnimationElement(Text key, Animation animation){ @Nullable @Override - protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { + protected Optional parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { return null; } From 1370c7815406ecb919c64459c49f1c8c62ffbd57 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 14:36:57 -0500 Subject: [PATCH 44/57] Added a method to update an animation's status --- .../bl4de/Animation/controller/AnimationController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java index 0095126..9cef7c0 100644 --- a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java +++ b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java @@ -116,6 +116,10 @@ public static ArrayList getAnimationsByOwner(UUID owner) { return PreparedStatements.getAnimationsByOwner(owner); } + public static boolean updateAnimationStatus(Animation animation, Animation.Status status){ + return PreparedStatements.updateAnimationStatus(animation, status); + } + /** * todo * @param animation From 1f47020bcbd23f3bce17fe1fdfbbd9fd19305bfb Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 15:39:50 -0500 Subject: [PATCH 45/57] Updated stop method - when an animation is stopped the first frame is displayed --- .../servegame/bl4de/Animation/model/Animation.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/model/Animation.java b/src/main/java/com/servegame/bl4de/Animation/model/Animation.java index d0feb98..a2d1c4e 100644 --- a/src/main/java/com/servegame/bl4de/Animation/model/Animation.java +++ b/src/main/java/com/servegame/bl4de/Animation/model/Animation.java @@ -228,12 +228,14 @@ public void start() throws UninitializedException { * {@link Task}s associated with this {@link Animation} */ public void stop(){ - setStatus(Status.STOPPED); - if (AnimationController.saveAnimation(this)){ - AnimationPlugin.taskManager.stopAnimation(this); - } else { - AnimationPlugin.logger.info("Failed to save animation"); - } + // This will set the status of the animation in the database. We don't + // need to update it in this class since the update will take affect the + // next time the animation is loaded + AnimationController.updateAnimationStatus(this, Status.STOPPED); + AnimationPlugin.taskManager.stopAnimation(this); + + // Now display the first frame + FrameController.displayContents(FrameController.getFrameWithContents(this, 0).get()); } /** From 83f9aaba47929ba22837f57e19dcd6a40204cca1 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 16:19:18 -0500 Subject: [PATCH 46/57] Updated help page --- .../bl4de/Animation/command/animation/HelpAnimation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/command/animation/HelpAnimation.java b/src/main/java/com/servegame/bl4de/Animation/command/animation/HelpAnimation.java index 85b3be2..297105f 100644 --- a/src/main/java/com/servegame/bl4de/Animation/command/animation/HelpAnimation.java +++ b/src/main/java/com/servegame/bl4de/Animation/command/animation/HelpAnimation.java @@ -27,6 +27,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm /animate stop /animate list /animate info + /animate set -f /animate frame create -h /animate frame delete_frame -f /animate frame display @@ -80,7 +81,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm Util.NAME_COLOR, " ", Util.ACTION_COLOR, " set", Util.PRIMARY_COLOR, " ", - Util.FLAG_COLOR, "[-f]\n")) + Util.FLAG_COLOR, "-f\n")) .append(Text.of(TextColors.WHITE, "/", Util.PRIMARY_COLOR, "animate", Util.NAME_COLOR, " ", From 46a71519f67318aef9cc66af66bec2f042ace4f4 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 17:30:26 -0500 Subject: [PATCH 47/57] Added log messages and removed unused method --- .../com/servegame/bl4de/Animation/AnimationPlugin.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java b/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java index 00d7af5..2a8a2d2 100644 --- a/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java +++ b/src/main/java/com/servegame/bl4de/Animation/AnimationPlugin.java @@ -88,6 +88,8 @@ public void onServerStart(GameStartingServerEvent event){ if (DatabaseSchemaUpdates.checkForVersionOne()){ logger.info("...Old database structure found, converting animations."); DatabaseSchemaUpdates.convertVersionOneToVersionTwo(); + } else { + logger.info("...database is up to date, no action needed."); } } @@ -97,11 +99,6 @@ public void onStop(GameStoppingEvent event){ AnimationController.stopAllAnimations(); } - @Listener - public void onMessage(MessageEvent event){ - - } - /** * Getter for debug flag * @return boolean debug flag From b0a3bf00c9d3c21cd95afcca2ecf46e0716d8357 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 17:31:09 -0500 Subject: [PATCH 48/57] Readme update --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4347f42..b92c8c5 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ See the wiki for the commands and their respective usages. (Still a WIP) #### High Priority [WIKI] Write basic usage guidelines [BUGFIX] After playing the animation for awhile the frames fall out of sync -[BUGFIX] Tile entities aren't un-serialized correctly + #### Medium Priority [UI] The message that tells the user that the frame has been created or deleted should link to that frame [PERMISSIONS] Setup specific permissions for the usage of flags, and any other permissions that isn't already setup @@ -37,6 +37,7 @@ See the wiki for the commands and their respective usages. (Still a WIP) [BUGFIX] There's a problem when displaying the volume of small subspaces, a 1x4x1 will have a volume of 0 [BUGFIX] Some animations, when stopped, play certain frames continuously even after they are stopped (maybe because it was played and then stopped immediately) +[BUGFIX] Deleting a frame that doesn't exist leads to a index out of bounds error #### Low Priority [PERMISSIONS] Permissions that only allow certain values to be set with certain flags @@ -110,7 +111,7 @@ the internal states and then starting the animation backup on the frame it stopp * ~~An animation can only be paused if the current status is a played status~~ * ~~In the frame info view if there are contents show the number of not air blocks~~ * ~~In the animation info view add a line for the volume of the master subspace (no longer think I want to do this)~~ - +* [BUGFIX] ~~Tile entities aren't un-serialized correctly~~ #### Matt Notes * Pausing the the animation should stop the animation on the given frame, From 1ddd100a975e3918cf25a3cdca3ee518c7f80796 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 17:31:35 -0500 Subject: [PATCH 49/57] Modified the structure of the version number --- build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 3fd1053..cc7bd0a 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,8 @@ sourceCompatibility = 1.8 -project.ext.versionno = '0.1.1' +project.ext.versionno = '0.2.1' +project.ext.versionending = '-SNAPSHOT' project.ext.buildno = '0' task setBuildNum { @@ -41,7 +42,7 @@ task incrementBuildNum { } allprojects { - version = rootProject.minecraftversion + "-" + rootProject.versionno + "." + rootProject.buildno + version = rootProject.minecraftversion + "-" + rootProject.versionno + "." + rootProject.buildno + rootProject.versionending incrementBuildNum From ba66972c5d88259df778c05105e4e98025fffbac Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 17:32:16 -0500 Subject: [PATCH 50/57] When a bare animation is gotten, the frames are loaded with frame data --- .../Animation/data/PreparedStatements.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java index 5811b94..9097c45 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/PreparedStatements.java @@ -186,7 +186,7 @@ public static Optional getAnimation(String name, UUID owner){ for (String frameName : frames) { Optional frameOptional = getFrame(frameName, FRAME_TABLE, - getContentTableName(animation, new Frame(animation.getOwner(), frameName, new SubSpace3D()))); + getContentTableName(animation, new Frame(animation.getOwner(), frameName, new SubSpace3D())), true); if (frameOptional.isPresent()) { animation.addFrame(frameOptional.get()); } @@ -220,7 +220,7 @@ public static Optional getBareAnimation(String name, UUID owner){ getAnimation.setString(1, name); getAnimation.setObject(2, owner); ResultSet rs = getAnimation.executeQuery(); - String[] frames = {}; + String[] frameNames = {}; if (rs.next()){ // Get animation data (except subspace data) @@ -231,10 +231,10 @@ public static Optional getBareAnimation(String name, UUID owner){ animation.setStartFrameIndex(rs.getInt(COLUMN_ANIMATION_START_FRAME_INDEX)); Object[] array = ((Object[]) rs.getArray(COLUMN_ANIMATION_FRAME_NAMES).getArray()); - frames = new String[array.length]; + frameNames = new String[array.length]; for (int i = 0; i < array.length; i++) { - frames[i] = (String) array[i]; + frameNames[i] = (String) array[i]; } // Create SubSpace3D @@ -256,11 +256,10 @@ public static Optional getBareAnimation(String name, UUID owner){ c2.ifPresent(blockSnapshot -> subSpace3D.setCornerTwo(blockSnapshot.getLocation().orElse(null))); animation.setSubSpace(subSpace3D); } - if (animation != null && animation.isInitialized()) { - // Add blank frames - for (int i = 0; i < frames.length; i++) { - animation.addFrame(new Frame()); - } + + for (String frameName : + frameNames) { + animation.addFrame(getFrame(frameName, SQLResources.getFrameTableName(animation), null, false).get()); } } catch (SQLException|IOException e){ e.printStackTrace(); @@ -489,7 +488,24 @@ public static boolean saveFrame(Animation animation, Frame frame){ return true; } - public static Optional getFrame(String frameName, final String FRAME_TABLE, final String CONTENTS_TABLE){ + public static boolean updateAnimationStatus(Animation animation, Animation.Status status){ + try (Connection connection = SQLManager.getConnection()){ + PreparedStatement updateStatus = connection.prepareStatement( + "UPDATE " + ANIMATION_TABLE + + " SET " + COLUMN_ANIMATION_STATUS + " = ? WHERE " + + COLUMN_ANIMATION_NAME + " = ? AND " + COLUMN_ANIMATION_OWNER + " = ?"); + updateStatus.setString(1, status.toString()); + updateStatus.setString(2, animation.getAnimationName()); + updateStatus.setObject(3, animation.getOwner()); + updateStatus.executeUpdate(); + } catch (SQLException e){ + e.printStackTrace(); + return false; + } + return true; + } + + public static Optional getFrame(String frameName, final String FRAME_TABLE, final String CONTENTS_TABLE, boolean loadContents){ Frame frame = null; try (Connection connection = SQLManager.getConnection()) { PreparedStatement statement = connection.prepareStatement( @@ -506,8 +522,8 @@ public static Optional getFrame(String frameName, final String FRAME_TABL c1.ifPresent(blockSnapshot -> subSpace3D.setCornerOne(blockSnapshot.getLocation().orElse(null))); c2.ifPresent(blockSnapshot -> subSpace3D.setCornerTwo(blockSnapshot.getLocation().orElse(null))); - if (rs.getObject(COLUMN_FRAME_SUBSPACE_CONTENTS) != null){ - // Create and set contents of the SubSpace + if (rs.getObject(COLUMN_FRAME_SUBSPACE_CONTENTS) != null && loadContents){ + // Create and set contents of the SubSpace if loadContents is true Location corner1 = c1.get().getLocation().get(); Location corner2 = c2.get().getLocation().get(); @@ -657,6 +673,7 @@ private static void getContents(final String CONTENT_TABLE, BlockSnapshot[][][] int zLength = blockSnapshotsReference[0][0].length; try (Connection connection = SQLManager.getConnection()) { + PreparedStatement statement = connection.prepareStatement( "SELECT *" + " FROM " + CONTENT_TABLE); ResultSet rs = statement.executeQuery(); @@ -669,6 +686,13 @@ private static void getContents(final String CONTENT_TABLE, BlockSnapshot[][][] int z = Integer.parseInt(xyzData[2]); blockSnapshotsReference[x][y][z] = BlockSnapshot.builder().build(DataFormats.HOCON.read(data)).get(); } + // Iterate through the list and check for nulls (if null insert minecraft air) todo +// for (int i = 0; i < xLength; i++) { +// for (int j = 0; j < yLength; j++) { +// for (int k = 0; k < zLength; k++) { +// } +// } +// } } catch (SQLException|IOException e){ e.printStackTrace(); } From 368e0e673cfcb7a4ee1d87337deac9991ea60911 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 18:09:40 -0500 Subject: [PATCH 51/57] Comments update --- .../bl4de/Animation/data/SQLManager.java | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java index 7c260fc..0172341 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/SQLManager.java @@ -1,6 +1,8 @@ package com.servegame.bl4de.Animation.data; import com.servegame.bl4de.Animation.AnimationPlugin; +import com.servegame.bl4de.Animation.model.Animation; +import com.servegame.bl4de.Animation.model.Frame; import org.spongepowered.api.Sponge; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.sql.SqlService; @@ -32,17 +34,16 @@ public class SQLManager { /** - * TODO + * Default constructor that just inits itself and sets a few things up * @param plugin */ private SQLManager(PluginContainer plugin){ this.plugin = plugin; - initSettings(); } /** - * Create default must-have tables + * Create default must-have tables (currently only the animation table) */ private void initSettings(){ // In the future this would get data from a config file @@ -65,9 +66,9 @@ private void initSettings(){ } /** - * TODO - * @param plugin - * @return + * Get an instance of the {@link SQLManager}, this gives access to the create and delete table methods + * @param plugin instance of the {@link PluginContainer} that is requesting access to the SQLManger + * @return {@link SQLManager} instance */ public static SQLManager get(PluginContainer plugin) { if (!sqlManagers.containsKey(plugin.getId())) { @@ -79,24 +80,40 @@ public static SQLManager get(PluginContainer plugin) { } /** - * TODO - * @return - * @throws SQLException + * Get a {@link Connection} to the database responsible for storing all information regarding the + * {@link Animation} and their given {@link Frame}s + * @return the {@link Connection} object + * @throws SQLException when a connection could not be obtained or other bad things happen */ public static Connection getConnection() throws SQLException { return get(AnimationPlugin.plugin).getDataSource().getConnection(); } - /** - * TODO - * @return - * @throws SQLException - */ - public DataSource getDataSource() throws SQLException { + private DataSource getDataSource() throws SQLException { SqlService sqlService = Sponge.getServiceManager().provide(SqlService.class).get(); return sqlService.getDataSource("jdbc:h2:./config/" + this.plugin.getId() + "/animation/" + this.database); } + /** + * Delete a given table. Used for deleting content tables and frame data tables when either an + * {@link Animation} is deleted or a {@link Frame} is deleted. + * @param tableName name of the table to delete, this is usually obtained from + * {@link SQLResources#getContentTableName(Animation, Frame)} or + * {@link SQLResources#getFrameTableName(Animation)} + */ + void deleteTable(String tableName){ + try (Connection connection = SQLManager.getConnection()){ + connection.prepareStatement("DROP TABLE IF EXISTS " + tableName).executeUpdate(); + } catch (SQLException e){ + e.printStackTrace(); + } + } + + /** + * Creates a table that stores information about the {@link Frame}s assoiated with an {@link Animation}. + * The name of the table should always be generated with {@link SQLResources#getFrameTableName(Animation)} + * @param tableName the name the new table will be given + */ void createFrameTable(String tableName){ try (Connection conn = getConnection()){ conn.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName + " (" + @@ -111,14 +128,11 @@ void createFrameTable(String tableName){ } } - void deleteTable(String tableName){ - try (Connection connection = SQLManager.getConnection()){ - connection.prepareStatement("DROP TABLE IF EXISTS " + tableName).executeUpdate(); - } catch (SQLException e){ - e.printStackTrace(); - } - } - + /** + * Create a table that is used to store the contents of a {@link Frame}, the name of the + * table should be obtained for {@link SQLResources#getContentTableName(Animation, Frame)} + * @param tableName the name of the table that will be created + */ void createContentsTable(String tableName){ try (Connection conn = getConnection()){ conn.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName + " (" + From e577b2fe99a3cabb754f5099983cf72fe4d96458 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 18:18:47 -0500 Subject: [PATCH 52/57] Rewrote pause method to stop the animation and not display the first frame (stopping an animation displays the first frame after stopping the animation) -- this still doesn't exhibit the functionality desired from pausing the animation, but it's a step closer I guess... --- .../com/servegame/bl4de/Animation/model/Animation.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/model/Animation.java b/src/main/java/com/servegame/bl4de/Animation/model/Animation.java index a2d1c4e..b98b8a2 100644 --- a/src/main/java/com/servegame/bl4de/Animation/model/Animation.java +++ b/src/main/java/com/servegame/bl4de/Animation/model/Animation.java @@ -245,12 +245,8 @@ public void stop(){ * that is always saved under the {@link Animation#startFrameIndex} state. */ public void pause(){ - setStatus(Status.PAUSED); - if (AnimationController.saveAnimation(this)){ - // No functionality right now, need to add some things for this to work - } else { - AnimationPlugin.logger.info("Failed to save animation"); - } + AnimationController.updateAnimationStatus(this, Status.PAUSED); + AnimationPlugin.taskManager.stopAnimation(this); } /* END ACTION METHODS */ From 071786228f39aaa1a1fa8ddeee02ef8bb7e01ebb Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Tue, 26 Dec 2017 18:19:20 -0500 Subject: [PATCH 53/57] Slight reorganization, removed unused variables and removed comments --- .../controller/AnimationController.java | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java index 9cef7c0..988601b 100644 --- a/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java +++ b/src/main/java/com/servegame/bl4de/Animation/controller/AnimationController.java @@ -19,9 +19,6 @@ */ public class AnimationController { - private static final String CONFIG_DIR = "./config/animation"; - private static final String ANIMATION_DATA_DIR = CONFIG_DIR + "/animations"; - /** * Stops all animations, usually ran when the server is shutting down. */ @@ -70,8 +67,8 @@ public static Text getButtonsForAnimation(Animation animation){ } /** - * TODO - * @return + * Creates the buttons that appear at the bottom of /animate list + * @return Text representing a button that allows for creating animations */ public static Text getButtonsForList(){ return Text.builder() @@ -84,21 +81,12 @@ public static Text getButtonsForList(){ .build(); } - /** - * todo - * @param animation - * @return - */ + // Most of these methods are just calls to the PreparedStatements class + public static boolean createAnimation(Animation animation){ return PreparedStatements.createAnimation(animation); } - /** - * TODO - * @param name - * @param owner - * @return - */ public static Optional getAnimation(String name, UUID owner){ return PreparedStatements.getAnimation(name, owner); } @@ -107,11 +95,6 @@ public static Optional getBareAnimation(String name, UUID owner){ return PreparedStatements.getBareAnimation(name, owner); } - /** - * TODO - * @param owner - * @return - */ public static ArrayList getAnimationsByOwner(UUID owner) { return PreparedStatements.getAnimationsByOwner(owner); } @@ -120,20 +103,10 @@ public static boolean updateAnimationStatus(Animation animation, Animation.Statu return PreparedStatements.updateAnimationStatus(animation, status); } - /** - * todo - * @param animation - * @return - */ public static boolean saveAnimation(Animation animation){ return PreparedStatements.saveAnimation(animation); } - /** - * todo - * @param animation - * @return - */ public static boolean deleteAnimation(Animation animation){ return PreparedStatements.deleteAnimation(animation); } From 26d48b94d2ad1398f88859a5f5195661e41669ed Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 27 Dec 2017 03:25:33 -0500 Subject: [PATCH 54/57] Update --- build.gradle | 10 +++++++++- version.properties | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index cc7bd0a..9c82fbe 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ task setBuildNum { setBuildNum project.ext.minecraftversion = '1.11.2' -project.ext.spongeapiversion = '6.1' +project.ext.spongeapiversion = '6.1.0' description = 'Animations - Allowing the creation of frame based animations.' ext.url = 'https://github.com/TheCahyag/MinecraftAnimation' @@ -76,4 +76,12 @@ blossom { replaceToken '@description@', project.description, location replaceToken '@url@', project.url, location + + location = 'src/main/resources/mcmod.info' + + replaceToken '@name@', project.name, location + replaceToken '@version@', project.version, location + + replaceToken '@description@', project.description, location + replaceToken '@url@', project.url, location } \ No newline at end of file diff --git a/version.properties b/version.properties index d49da72..922ff95 100644 --- a/version.properties +++ b/version.properties @@ -1 +1 @@ -VERSION_BUILD=16 \ No newline at end of file +VERSION_BUILD=43 \ No newline at end of file From c38e4f5123b7326d90a3149501c06eee17b4c7c8 Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 27 Dec 2017 03:25:43 -0500 Subject: [PATCH 55/57] Minor spacing change --- .../bl4de/Animation/data/DataQueries.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/servegame/bl4de/Animation/data/DataQueries.java b/src/main/java/com/servegame/bl4de/Animation/data/DataQueries.java index e9451ef..cbf10f2 100644 --- a/src/main/java/com/servegame/bl4de/Animation/data/DataQueries.java +++ b/src/main/java/com/servegame/bl4de/Animation/data/DataQueries.java @@ -11,22 +11,22 @@ */ public class DataQueries { // Animation - public static final DataQuery ANIMATION_NAME = of("animation_name"); - public static final DataQuery ANIMATION_OWNER = of("animation_owner"); - public static final DataQuery ANIMATION_FRAMES = of("animation_frames"); - public static final DataQuery ANIMATION_SUBSPACE = of("animation_subspace"); - public static final DataQuery ANIMATION_FRAME_INDEX = of("animation_frame_index"); - public static final DataQuery ANIMATION_TICK_DELAY = of("animation_tick_delay"); - public static final DataQuery ANIMATION_CYCLES = of("animation_cycles"); - public static final DataQuery ANIMATION_STATUS = of("animation_status"); + public static final DataQuery ANIMATION_NAME = of("animation_name"); + public static final DataQuery ANIMATION_OWNER = of("animation_owner"); + public static final DataQuery ANIMATION_FRAMES = of("animation_frames"); + public static final DataQuery ANIMATION_SUBSPACE = of("animation_subspace"); + public static final DataQuery ANIMATION_FRAME_INDEX = of("animation_frame_index"); + public static final DataQuery ANIMATION_TICK_DELAY = of("animation_tick_delay"); + public static final DataQuery ANIMATION_CYCLES = of("animation_cycles"); + public static final DataQuery ANIMATION_STATUS = of("animation_status"); // Frame - public static final DataQuery FRAME_CREATOR = of("frame_creator"); - public static final DataQuery FRAME_NAME = of("frame_name"); - public static final DataQuery FRAME_SUBSPACE = of("frame_subspace"); + public static final DataQuery FRAME_CREATOR = of("frame_creator"); + public static final DataQuery FRAME_NAME = of("frame_name"); + public static final DataQuery FRAME_SUBSPACE = of("frame_subspace"); // SubSpace - public static final DataQuery SUBSPACE_CORNER_ONE = of("subspace_corner_one"); - public static final DataQuery SUBSPACE_CORNER_TWO = of("subspace_corner_two"); - public static final DataQuery SUBSPACE_CONTENTS = of("subspace_contents"); + public static final DataQuery SUBSPACE_CORNER_ONE = of("subspace_corner_one"); + public static final DataQuery SUBSPACE_CORNER_TWO = of("subspace_corner_two"); + public static final DataQuery SUBSPACE_CONTENTS = of("subspace_contents"); } From 8fd3ecc5305a4cbf3e16c9c5be68d284376054ee Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 27 Dec 2017 03:25:54 -0500 Subject: [PATCH 56/57] Added description --- description.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 description.md diff --git a/description.md b/description.md new file mode 100644 index 0000000..2bbe2ad --- /dev/null +++ b/description.md @@ -0,0 +1,13 @@ +# Animations + +Animations is a Sponge plugin that allows for the creation of frame-based animations. Animations was inspired by [VoxelTronix](https://www.youtube.com/watch?annotation_id=annotation_683155&feature=iv&src_vid=UW54ks4ttIo&v=Y06Xgk2YI0I). +### Quick Links +[Basic Usage](https://github.com/TheCahyag/MinecraftAnimation/wiki/Basic-Usage) | [Commands](https://github.com/TheCahyag/MinecraftAnimation/wiki/Command-List) | [Permissions](https://github.com/TheCahyag/MinecraftAnimation/wiki/Permissions) +### Examples: +https://i.imgur.com/xapoJqA.mp4 +or +https://imgur.com/Shdtj1N + + **At the moment the plugin has only been tested for servers running API 6.0 and 6.1.** This should soon be updated to API 7. + +See the [basic usage guide](https://github.com/TheCahyag/MinecraftAnimation/wiki/Basic-Usage) on the [wiki](https://github.com/TheCahyag/MinecraftAnimation/wiki). From e691ed429d761c119d2ea680c912ced34a2573ba Mon Sep 17 00:00:00 2001 From: Brandon Bires-Navel Date: Wed, 27 Dec 2017 03:26:06 -0500 Subject: [PATCH 57/57] Updated mcmod.info --- src/main/resources/mcmod.info | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 1bb9076..763a15f 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,9 +1,10 @@ [{ - "modid": "animations", + "modid": "animation", "name": "Animations", - "version": "0.1.1", - "description": "A Minecraft plugin allowing the creation of frame based animations utilizing the Sponge API", + "version": "0.2.1", + "description": "Animations - Allowing the creation of frame based animations.", "authorList": [ "TheCahyag" - ] + ], + "url": "https://github.com/TheCahyag/MinecraftAnimation" }] \ No newline at end of file