mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
exception after exception after exception after
This commit is contained in:
1 parent
be51157812
commit
8286f91061
11 files changed
+71
-23
No files matched your search
@@ -25,6 +25,7 @@ fun ShadowJar.standardRelocations() {
|
|||||||
relocateDependency("com.google.common")
|
relocateDependency("com.google.common")
|
||||||
relocateDependency("com.google.thirdparty.publicsuffix")
|
relocateDependency("com.google.thirdparty.publicsuffix")
|
||||||
relocateDependency("it.unimi.dsi.fastutil")
|
relocateDependency("it.unimi.dsi.fastutil")
|
||||||
|
relocateDependency("org.flywaydb")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ShadowJar.relocateCloud() {
|
fun ShadowJar.relocateCloud() {
|
||||||
|
|||||||
@@ -28,4 +28,6 @@ dependencies {
|
|||||||
api(libs.jdbiObject)
|
api(libs.jdbiObject)
|
||||||
api(libs.hikariCP)
|
api(libs.hikariCP)
|
||||||
api(libs.flyway)
|
api(libs.flyway)
|
||||||
|
api(libs.flywayMysql)
|
||||||
|
api(libs.mysql)
|
||||||
}
|
}
|
||||||
@@ -151,6 +151,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
this.muted = muted;
|
this.muted = muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<UUID> ignoredPlayers() {
|
||||||
|
return this.ignoredPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ignoring(final UUID player) {
|
public boolean ignoring(final UUID player) {
|
||||||
return this.ignoredPlayers.contains(player);
|
return this.ignoredPlayers.contains(player);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.flywaydb.core.Flyway;
|
import org.flywaydb.core.Flyway;
|
||||||
import org.jdbi.v3.core.Jdbi;
|
import org.jdbi.v3.core.Jdbi;
|
||||||
|
import org.jdbi.v3.core.statement.PreparedBatch;
|
||||||
import org.jdbi.v3.core.statement.Update;
|
import org.jdbi.v3.core.statement.Update;
|
||||||
import static net.kyori.adventure.text.Component.empty;
|
import static net.kyori.adventure.text.Component.empty;
|
||||||
import static net.kyori.adventure.text.Component.text;
|
import static net.kyori.adventure.text.Component.text;
|
||||||
@@ -42,23 +43,24 @@ public class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
|
|||||||
final DatabaseSettings databaseSettings,
|
final DatabaseSettings databaseSettings,
|
||||||
final ClassLoader classLoader
|
final ClassLoader classLoader
|
||||||
) {
|
) {
|
||||||
final HikariConfig hikariConfig = new HikariConfig();
|
// final HikariConfig hikariConfig = new HikariConfig();
|
||||||
hikariConfig.setJdbcUrl(databaseSettings.url());
|
// hikariConfig.setJdbcUrl(databaseSettings.url());
|
||||||
hikariConfig.setUsername(databaseSettings.username());
|
// hikariConfig.setUsername(databaseSettings.username());
|
||||||
hikariConfig.setPassword(databaseSettings.password());
|
// hikariConfig.setPassword(databaseSettings.password());
|
||||||
|
//
|
||||||
final DataSource dataSource = new HikariDataSource(hikariConfig);
|
// final DataSource dataSource = new HikariDataSource(hikariConfig);
|
||||||
|
|
||||||
Flyway.configure(classLoader)
|
Flyway.configure(classLoader)
|
||||||
.baselineVersion("0")
|
.baselineVersion("0")
|
||||||
.baselineOnMigrate(true)
|
.baselineOnMigrate(true)
|
||||||
.locations("queries/migrations")
|
.locations("queries/migrations")
|
||||||
.dataSource(dataSource)
|
.dataSource(databaseSettings.url(), databaseSettings.username(), databaseSettings.password())
|
||||||
|
//.dataSource(dataSource)
|
||||||
.validateOnMigrate(true)
|
.validateOnMigrate(true)
|
||||||
.load()
|
.load()
|
||||||
.migrate();
|
.migrate();
|
||||||
|
|
||||||
final Jdbi jdbi = Jdbi.create(dataSource)
|
final Jdbi jdbi = Jdbi.create(databaseSettings.url(), databaseSettings.username(), databaseSettings.password())
|
||||||
.registerArrayType(UUID.class, "uuid")
|
.registerArrayType(UUID.class, "uuid")
|
||||||
.registerArgument(new UUIDArgumentFactory())
|
.registerArgument(new UUIDArgumentFactory())
|
||||||
.registerColumnMapper(Component.class, new ComponentMapper())
|
.registerColumnMapper(Component.class, new ComponentMapper())
|
||||||
@@ -80,13 +82,13 @@ public class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
|
|||||||
return this.jdbi.withHandle(handle -> {
|
return this.jdbi.withHandle(handle -> {
|
||||||
try {
|
try {
|
||||||
final @Nullable CarbonPlayerCommon carbonPlayerCommon = handle.createQuery(this.locator.query("select-player"))
|
final @Nullable CarbonPlayerCommon carbonPlayerCommon = handle.createQuery(this.locator.query("select-player"))
|
||||||
.bind("uuid", uuid)
|
.bind("id", uuid)
|
||||||
.mapTo(CarbonPlayerCommon.class)
|
.mapTo(CarbonPlayerCommon.class)
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
if (carbonPlayerCommon != null) {
|
if (carbonPlayerCommon != null) {
|
||||||
handle.createQuery(this.locator.query("select-ignores"))
|
handle.createQuery(this.locator.query("select-ignores"))
|
||||||
.bind("uuid", uuid)
|
.bind("id", uuid)
|
||||||
.mapTo(UUID.class)
|
.mapTo(UUID.class)
|
||||||
.forEach(ignoredPlayer -> carbonPlayerCommon.ignoring(ignoredPlayer, true));
|
.forEach(ignoredPlayer -> carbonPlayerCommon.ignoring(ignoredPlayer, true));
|
||||||
}
|
}
|
||||||
@@ -94,8 +96,6 @@ public class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
|
|||||||
return new ComponentPlayerResult<>(carbonPlayerCommon, empty());
|
return new ComponentPlayerResult<>(carbonPlayerCommon, empty());
|
||||||
} catch (final IllegalStateException exception) {
|
} catch (final IllegalStateException exception) {
|
||||||
// Player doesn't exist in the DB, create them!
|
// Player doesn't exist in the DB, create them!
|
||||||
// TODO: create them
|
|
||||||
|
|
||||||
final String name = Objects.requireNonNull(
|
final String name = Objects.requireNonNull(
|
||||||
CarbonChatProvider.carbonChat().server().resolveName(uuid).join());
|
CarbonChatProvider.carbonChat().server().resolveName(uuid).join());
|
||||||
|
|
||||||
@@ -117,6 +117,16 @@ public class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
|
|||||||
this.bindPlayerArguments(handle.createUpdate(this.locator.query("save-player")), player)
|
this.bindPlayerArguments(handle.createUpdate(this.locator.query("save-player")), player)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
if (!player.ignoredPlayers().isEmpty()) {
|
||||||
|
final PreparedBatch batch = handle.prepareBatch(this.locator.query("save-ignores"));
|
||||||
|
|
||||||
|
for (final UUID ignoredPlayer : player.ignoredPlayers()) {
|
||||||
|
batch.bind("id", player.uuid()).bind("ignoredplayer", ignoredPlayer).add();
|
||||||
|
}
|
||||||
|
|
||||||
|
batch.execute();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: save ignoredplayers
|
// TODO: save ignoredplayers
|
||||||
return new ComponentPlayerResult<>(player, empty());
|
return new ComponentPlayerResult<>(player, empty());
|
||||||
});
|
});
|
||||||
@@ -125,7 +135,7 @@ public class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
|
|||||||
|
|
||||||
private Update bindPlayerArguments(final Update update, final CarbonPlayerCommon player) {
|
private Update bindPlayerArguments(final Update update, final CarbonPlayerCommon player) {
|
||||||
return update
|
return update
|
||||||
.bind("uuid", player.uuid())
|
.bind("id", player.uuid())
|
||||||
.bind("muted", player.muted())
|
.bind("muted", player.muted())
|
||||||
.bind("deafened", player.deafened())
|
.bind("deafened", player.deafened())
|
||||||
.bind("selectedchannel", player.selectedChannelKey())
|
.bind("selectedchannel", player.selectedChannelKey())
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
CREATE TABLE carbon_users
|
CREATE TABLE carbon_users (
|
||||||
(
|
`id` UUID NOT NULL PRIMARY KEY,
|
||||||
`uuid` UUID NOT NULL PRIMARY KEY,
|
|
||||||
`muted` BOOLEAN,
|
`muted` BOOLEAN,
|
||||||
`deafened` BOOLEAN,
|
`deafened` BOOLEAN,
|
||||||
`selectedchannel` varchar(256),
|
`selectedchannel` varchar(256),
|
||||||
@@ -11,8 +10,8 @@ CREATE TABLE carbon_users
|
|||||||
`spying` BOOLEAN
|
`spying` BOOLEAN
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE carbon_ignores
|
CREATE TABLE carbon_ignores (
|
||||||
(
|
`id` UUID NOT NULL,
|
||||||
`uuid` UUID NOT NULL,
|
`ignoredplayer` UUID NOT NULL,
|
||||||
`ignoredplayer` UUID NOT NULL
|
PRIMARY KEY (id, ignoredplayer)
|
||||||
);
|
);
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
INSERT INTO carbon_users VALUES (
|
||||||
|
:uuid,
|
||||||
|
:muted,
|
||||||
|
:deafened,
|
||||||
|
:selectedchannel,
|
||||||
|
:username,
|
||||||
|
:displayname,
|
||||||
|
:lastwhispertarget,
|
||||||
|
:whisperreplytarget,
|
||||||
|
:spying
|
||||||
|
);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
INSERT INTO carbon_ignores (id, ignoredplayer) VALUES(:id, :name)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
UPDATE carbon_users
|
||||||
|
SET
|
||||||
|
id = :id,
|
||||||
|
muted = :muted,
|
||||||
|
deafened = :deafened,
|
||||||
|
selectedchannel = :selectedchannel,
|
||||||
|
username= :username,
|
||||||
|
displayname = :displayname,
|
||||||
|
lastwhispertarget = :lastwhispertarget,
|
||||||
|
whisperreplytarget = :whisperreplytarget,
|
||||||
|
spying = :spying
|
||||||
|
WHERE id = :id;
|
||||||
@@ -1 +1 @@
|
|||||||
SELECT ignoredplayer FROM carbon_ignores WHERE (uuid = <uuid>);
|
SELECT ignoredplayer FROM carbon_ignores WHERE (id = :id);
|
||||||
@@ -1 +1 @@
|
|||||||
SELECT * from carbon_users WHERE (uuid = <uuid>);
|
SELECT * from carbon_users WHERE (id = :id);
|
||||||
@@ -39,7 +39,7 @@ versions:
|
|||||||
discordsrv: 1.26.0-SNAPSHOT
|
discordsrv: 1.26.0-SNAPSHOT
|
||||||
jdbi: 3.25.0
|
jdbi: 3.25.0
|
||||||
hikari: 5.0.0
|
hikari: 5.0.0
|
||||||
mariadb: 2.1.2
|
mysql: 8.0.12
|
||||||
flyway: 8.2.3
|
flyway: 8.2.3
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -191,6 +191,14 @@ dependencies:
|
|||||||
group: org.flywaydb
|
group: org.flywaydb
|
||||||
name: flyway-core
|
name: flyway-core
|
||||||
version: { ref: flyway }
|
version: { ref: flyway }
|
||||||
|
flywayMysql:
|
||||||
|
group: org.flywaydb
|
||||||
|
name: flyway-mysql
|
||||||
|
version: { ref: flyway }
|
||||||
|
mysql:
|
||||||
|
group: mysql
|
||||||
|
name: mysql-connector-java
|
||||||
|
version: { ref: mysql }
|
||||||
|
|
||||||
paperApi:
|
paperApi:
|
||||||
group: io.papermc.paper
|
group: io.papermc.paper
|
||||||
|
|||||||
Reference in new issue
Block a user