Skip to content

Commit

Permalink
1.4.28
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Sep 28, 2022
1 parent 2dc6708 commit c50429e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,6 @@ public PreparedStatement selectAllFromData(String keyType, String key, String ta
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
if (connection != null)
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

Expand All @@ -341,13 +334,6 @@ public PreparedStatement updateDataSet(String keyType, String table, String valu
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
if (connection != null)
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/us/mytheria/bloblib/utilities/BukkitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -17,6 +18,8 @@ public class BukkitUtil {
* @see Location
*/
public static String locationToString(Location loc) {
if (loc == null)
return "null";
return loc.getWorld().getName() + "%loc:%" + loc.getX() + "%loc:%" + loc.getY() + "%loc:%" + loc.getZ();
}

Expand All @@ -26,6 +29,8 @@ public static String locationToString(Location loc) {
* @see Location
*/
public static Location stringToLocation(String string) {
if (string.equals("null"))
return null;
String[] split = string.split("%loc:%");
return new Location(Bukkit.getWorld(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]),
Double.parseDouble(split[3]));
Expand Down Expand Up @@ -55,4 +60,21 @@ public static Set<Block> deserializeBlockSet(List<String> serialized) {
}
return blocks;
}

public static List<String> serializeVectorSet(Set<Vector> vectors) {
List<String> serialized = new ArrayList<>();
for (Vector vector : vectors) {
serialized.add(vector.getBlockX() + "%" + vector.getBlockY() + "%" + vector.getBlockZ());
}
return serialized;
}

public static Set<Vector> deserializeVectorSet(List<String> serialized) {
Set<Vector> vectors = new HashSet<>();
for (String string : serialized) {
String[] split = string.split("%");
vectors.add(new Vector(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])));
}
return vectors;
}
}

0 comments on commit c50429e

Please sign in to comment.