Welcome
SquishyDatabase and SquishyConfiguration are not linked with this library.
This is a new version of the libraries combined into one project.
This library contains useful tools such as simplified logging, test helpers, a good universal configuration library and an interesting abstract database library.
This library is used in many of my (Smudgge's) projects, one specifically leaf currently being used on 72 servers (2024).
Intro to Configuration
Configuration config = new YamlConfiguration(new File("file.yml"));
config.setResourcePath("file.yml"); // The name of the file in the resource folder.
config.load();String hello = config.getString("hello", "hello world");
config.set("hello", "hello again");config.save();This is quite similar to the spigot configuration classes but designed to be simpler.
Intro to Databases
Have you ever had a project that offered different database types?
It can be a pain to implement the same thing for each type of database. That's why I have created this library, you can now do all your database actions without worrying about doing it for each type! It abstracts the type of database.
Below is a step-by-step guide to creating a simple database and querying.
# Database Library Author: Smudge
# File: database.yml
should_reconnect_every_cycle: true
reconnect_cooldown_millis: 2000
will_reconnect: true
time_between_requests_millis: 100
max_requests_pending: 40
sqlite:
enabled: true
path: "plugins/CozyJoinLeave/database.sqlite3"Load the config file and create the database.
Configuration databaseConfig = new YamlConfiguration(
this.getPlugin().getDataFolder(),
"database.yml"
);
databaseConfig.setResourcePath("database.yml");
databaseConfig.load();
Database database = new DatabaseBuilder(this.databaseConfig).create().connect();public class ExampleRecord implements Record<Example2Record> {
public static final @NotNull String IDENTIFIER_KEY = "identifier";
public static final @NotNull String STRING_KEY = "value";
private final @Field(IDENTIFIER_KEY) @Primary @NotNull String identifier;
private @Field(STRING_KEY) String string;
public ExampleRecord(@NotNull String identifier) {
this.identifier = identifier;
}
@Override
public @NotNull ConfigurationSection convert() {
MemoryConfigurationSection section = new MemoryConfigurationSection();
section.set(STRING_KEY, string);
return section;
}
@Override
public @NotNull Example2Record convert(
@NotNull ConfigurationSection section) {
this.string = section.getString(STRING_KEY);
return this;
}
}Define the table.
public class ExampleTable extends Table<ExampleRecord> {
public static final @NotNull String TABLE_NAME = "example";
@Override
public @NotNull String getName() {
return ExampleTable.TABLE_NAME;
}
@Override
public @NotNull ExampleRecord createEmpty(@NotNull PrimaryFieldMap identifiers) {
return new ExampleRecord(
identifiers.getString(ExampleRecord.IDENTIFIER_KEY)
);
}
}Create the table in the database.
database.createTable(new ExampleTable());ExampleRecord record = database.getTable(ExampleTable.class)
.getFirstRecord();Last updated