Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mustafabinguldev/handatabasecoreapi
- Owner: mustafabinguldev
- License: mit
- Created: 2023-04-10T15:15:53.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T15:58:47.000Z (almost 2 years ago)
- Last Synced: 2024-11-22T05:08:18.576Z (2 months ago)
- Topics: database, minecraft-plugin, minecraft-plugin-api, mysql, orm, spigot, spigot-api, sql
- Language: Java
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
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
```