Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mustafabinguldev/handatabasecoreapi

Complex minecraft database API
https://github.com/mustafabinguldev/handatabasecoreapi

database minecraft-plugin minecraft-plugin-api mysql orm spigot spigot-api sql

Last synced: 4 days ago
JSON representation

Complex minecraft database API

Awesome Lists containing this project

README

        

The Minecraft database plugin API is a tool for developers to create plugins that interact with the game's database. It uses Hibernate ORM to simplify database programming and includes classes for creating database connections, executing queries, and retrieving results. With this API, developers can create plugins to store and retrieve game data, such as player statistics and game items.

Gradle
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

dependencies {
implementation 'com.github.BingulHan:HanDatabaseCoreAPI:1.0'
}
```

Maven
```


jitpack.io
https://jitpack.io




com.github.BingulHan
HanDatabaseCoreAPI
1.0

```

How to add database?
```
File xmlConfigFile = new File(getDataFolder(), "exampleConfig.xml");
HanDatabaseObject databaseObject = new HanDatabaseObject(xmlConfigFile, "skywars", PlayerScore.class);
HanDatabaseCore.addDatabase(databaseObject);
```

How to add, remove, fetch and update objects from database?
```
DatabaseHelper databaseHelper = HanDatabaseCore.getDatabase("skywars").get().getHelper(PlayerScore.class);

//The first parameter must be 1.
//Player Name, Kills, Deaths

PlayerScore score = databaseHelper.get(player.getName());
if (score == null) {

databaseHelper.create(1, player.getName(), 0, 0);

}else {

score.kills += 1;
databaseHelper.update(score);

}

// databaseHelper.delete(score);
```

PlayerScore.class

```
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

//All annotations need to be put.
@Entity
@Table(name = "scores")
public class PlayerScore {

//Tables of objects that do not contain IDs are not created.
//Putting Id in String is a must.
@Id
@Column(name = "uuid")
public String uuid;

@Column(name = "kills")
public int kills;

@Column(name = "deaths")
public int deaths;

//Two constructor blocks must be placed, one must contain all variables,
//one must be empty, the first constructor block must be empty.
public PlayerScore() {
super();
}

public PlayerScore(String uuid, int kills, int deaths) {
this.uuid = uuid;
this.kills = kills;
this.deaths = deaths;
}
}
```

exampleConfig.xml
```


com.mysql.cj.jdbc.Driver
jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC
test
test


1


org.hibernate.dialect.MySQLDialect


false


false


thread


update

```