Skip to content

Commit bcb47d2

Browse files
Initial commit
0 parents  commit bcb47d2

File tree

16 files changed

+768
-0
lines changed

16 files changed

+768
-0
lines changed

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/artifacts/HanDatabaseCore_jar.xml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HanDatabaseCore.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>PAPER</platformType>
8+
</autoDetectTypes>
9+
</configuration>
10+
</facet>
11+
</component>
12+
</module>

README.MD

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
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.
2+
3+
4+
5+
How to add database?
6+
```
7+
File xmlConfigFile = new File(getDataFolder(), "exampleConfig.xml");
8+
HanDatabaseObject databaseObject = new HanDatabaseObject(xmlConfigFile, "skywars", PlayerScore.class);
9+
HanDatabaseCore.addDatabase(databaseObject);
10+
```
11+
12+
13+
How to add, remove, fetch and update objects from database?
14+
```
15+
DatabaseHelper<PlayerScore> databaseHelper = getDatabase("skywars").get().getHelper(PlayerScore.class);
16+
17+
//The first parameter must be 1.
18+
//Player Name, Kills, Deaths
19+
20+
PlayerScore score = databaseHelper.get(player.getName());
21+
if (score == null) {
22+
23+
databaseHelper.create(1, player.getName(), 0, 0);
24+
25+
}else {
26+
27+
score.kills += 1;
28+
databaseHelper.update(score);
29+
30+
}
31+
32+
// databaseHelper.delete(score);
33+
```
34+
35+
PlayerScore.class
36+
37+
```
38+
import javax.persistence.Column;
39+
import javax.persistence.Entity;
40+
import javax.persistence.Id;
41+
import javax.persistence.Table;
42+
43+
//All annotations need to be put.
44+
@Entity
45+
@Table(name = "scores")
46+
public class PlayerScore {
47+
48+
//Tables of objects that do not contain IDs are not created.
49+
//Putting Id in String is a must.
50+
@Id
51+
@Column(name = "uuid")
52+
public String uuid;
53+
54+
@Column(name = "kills")
55+
public int kills;
56+
57+
@Column(name = "deaths")
58+
public int deaths;
59+
60+
//Two constructor blocks must be placed, one must contain all variables,
61+
//one must be empty, the first constructor block must be empty.
62+
public PlayerScore() {
63+
super();
64+
}
65+
66+
public PlayerScore(String uuid, int kills, int deaths) {
67+
this.uuid = uuid;
68+
this.kills = kills;
69+
this.deaths = deaths;
70+
}
71+
}
72+
```
73+
74+
exampleConfig.xml
75+
```
76+
<!DOCTYPE hibernate-configuration PUBLIC
77+
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
78+
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
79+
80+
<hibernate-configuration>
81+
82+
<session-factory>
83+
84+
<!-- JDBC Database connection settings -->
85+
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
86+
<property name="connection.url">jdbc:mysql://localhost:3306/test?useSSL=false&amp;serverTimezone=UTC</property>
87+
<property name="connection.username">test</property>
88+
<property name="connection.password">test</property>
89+
90+
<!-- JDBC connection pool settings -->
91+
<property name="connection.pool_size">1</property>
92+
93+
<!-- Select our SQL dialect -->
94+
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
95+
96+
<!-- Echo the SQL to stdout -->
97+
<property name="show_sql">false</property>
98+
99+
<!-- Format the SQL -->
100+
<property name="format_sql">false</property>
101+
102+
<!-- Set the current session context -->
103+
<property name="current_session_context_class">thread</property>
104+
105+
<!-- Handles the entity table changes -->
106+
<property name="hibernate.hbm2ddl.auto">update</property>
107+
108+
109+
</session-factory>
110+
111+
</hibernate-configuration>
112+
```
113+

0 commit comments

Comments
 (0)