Skip to content

Commit

Permalink
move Gson types to own class
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Jul 27, 2024
1 parent 61f6c0f commit 0fa15c7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/mrnavastar/sqlib/SQLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static Database getDatabase() {
Velocity.init();
return database;
} catch (ClassNotFoundException ignore) {
throw new RuntimeException("SQLib currently only support Fabric, Quilt, and Velocity!");
throw new RuntimeException("SQLib currently only supports Fabric, Quilt, and Velocity!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.kyori.adventure.text.minimessage.MiniMessage;

public class AdventureTypes {

public static final SQLibType<Key> KEY = new SQLibType<>(SQLPrimitive.STRING, Key::asMinimalString, Key::key);
public static final SQLibType<Component> COMPONENT = new SQLibType<>(SQLPrimitive.STRING, v -> MiniMessage.miniMessage().serialize(v), v -> MiniMessage.miniMessage().deserialize(v));
}
11 changes: 11 additions & 0 deletions src/main/java/me/mrnavastar/sqlib/api/types/GsonTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.mrnavastar.sqlib.api.types;

import com.google.gson.*;
import me.mrnavastar.sqlib.impl.SQLPrimitive;

public class GsonTypes {
public static final SQLibType<JsonElement> ELEMENT = new SQLibType<>(SQLPrimitive.STRING, JsonElement::toString, JsonParser::parseString);
public static final SQLibType<JsonObject> OBJECT = new SQLibType<>(ELEMENT, v -> v, v -> (JsonObject) v);
public static final SQLibType<JsonArray> ARRAY = new SQLibType<>(ELEMENT, v -> v, v -> (JsonArray) v);
public static final SQLibType<JsonPrimitive> PRIMITIVE = new SQLibType<>(ELEMENT, v -> v, v -> (JsonPrimitive) v);
}
2 changes: 0 additions & 2 deletions src/main/java/me/mrnavastar/sqlib/api/types/JavaTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Date;

public class JavaTypes {

// Primitives
public static final SQLibType<Byte> BYTE = new SQLibType<>(SQLPrimitive.INT, Byte::intValue, Integer::byteValue);
public static final SQLibType<byte[]> BYTES = new SQLibType<>(SQLPrimitive.BYTES, v -> v, v -> v);
Expand All @@ -19,7 +18,6 @@ public class JavaTypes {
public static final SQLibType<Long> LONG = new SQLibType<>(SQLPrimitive.LONG, v -> v, v -> v);
public static final SQLibType<String> STRING = new SQLibType<>(SQLPrimitive.STRING, v -> v, v -> v);
public static final SQLibType<Character> CHAR = new SQLibType<>(SQLPrimitive.CHAR, v -> v, v -> v);

// Java Data Types
public static final SQLibType<Date> DATE = new SQLibType<>(SQLPrimitive.LONG, Date::getTime, Date::new);
public static final SQLibType<Color> COLOR = new SQLibType<>(SQLPrimitive.INT, Color::getRGB, Color::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.mrnavastar.sqlib.api.types;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import me.mrnavastar.sqlib.impl.SQLPrimitive;
import me.mrnavastar.sqlib.impl.TextParser;
Expand All @@ -15,7 +13,6 @@
import net.minecraft.util.math.Vec3i;

public class MinecraftTypes {

public static final SQLibType<Vec3i> VEC3I = new SQLibType<>(SQLPrimitive.LONG, v -> BlockPos.asLong(v.getX(), v.getY(), v.getZ()), v -> new Vec3i(BlockPos.unpackLongX(v), BlockPos.unpackLongY(v), BlockPos.unpackLongZ(v)));
public static final SQLibType<BlockPos> BLOCKPOS = new SQLibType<>(SQLPrimitive.LONG, BlockPos::asLong, BlockPos::fromLong);
public static final SQLibType<ChunkPos> CHUNKPOS = new SQLibType<>(SQLPrimitive.LONG, ChunkPos::toLong, ChunkPos::new);
Expand All @@ -24,7 +21,6 @@ public class MinecraftTypes {
public static final SQLibType<Identifier> IDENTIFIER = new SQLibType<>(SQLPrimitive.STRING, Identifier::toString, Identifier::tryParse);
public static final SQLibType<SoundEvent> SOUND = new SQLibType<>(IDENTIFIER, SoundEvent::getId, SoundEvent::of);

public static final SQLibType<JsonElement> JSON = new SQLibType<>(SQLPrimitive.STRING, JsonElement::toString, JsonParser::parseString);
public static final SQLibType<NbtElement> NBT = new SQLibType<>(SQLPrimitive.STRING, NbtElement::toString, v -> {
try {
return StringNbtReader.parse(v);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/me/mrnavastar/sqlib/impl/SQLConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public void close() {
}

public void createTable(DataStore store) {
try {
sql.useHandle(h -> h.execute(store.getDatabase().getTableCreationQuery(store.toString())));
} catch (Exception ignore) {}
sql.useHandle(h -> h.execute(store.getDatabase().getTableCreationQuery(store.toString())));
}

public int createRow(DataStore store) {
Expand Down

0 comments on commit 0fa15c7

Please sign in to comment.