first commit
This commit is contained in:
33
src/main/java/org/andrewkydev/api/API.java
Normal file
33
src/main/java/org/andrewkydev/api/API.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package org.andrewkydev.api;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.andrewkydev.api.database.SessionFactoryMaker;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class API extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static Logger jlogger;
|
||||
|
||||
@Getter
|
||||
private static API instance;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
jlogger = super.getLogger();
|
||||
jlogger.info("plugin is enabled1");
|
||||
SessionFactory sessionFactory = SessionFactoryMaker.getSessionFactory();
|
||||
jlogger.info(String.valueOf(sessionFactory.isOpen()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
}
|
||||
4
src/main/java/org/andrewkydev/api/database/Database.java
Normal file
4
src/main/java/org/andrewkydev/api/database/Database.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package org.andrewkydev.api.database;
|
||||
|
||||
public class Database {
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.andrewkydev.api.database;
|
||||
|
||||
|
||||
import org.andrewkydev.api.database.models.*;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class SessionFactoryMaker {
|
||||
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
if (sessionFactory == null) {
|
||||
try {
|
||||
Configuration configuration = getConfiguration();
|
||||
|
||||
configuration.addAnnotatedClass(User.class);
|
||||
configuration.addAnnotatedClass(UserStatistic.class);
|
||||
configuration.addAnnotatedClass(AuthInformation.class);
|
||||
configuration.addAnnotatedClass(Economy.class);
|
||||
configuration.addAnnotatedClass(EconomyTransactions.class);
|
||||
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(configuration.getProperties()).build();
|
||||
|
||||
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Configuration getConfiguration() {
|
||||
Configuration configuration = new Configuration();
|
||||
|
||||
Properties settings = new Properties();
|
||||
settings.put(Environment.DRIVER, "org.postgresql.Driver");
|
||||
settings.put(Environment.URL, "jdbc:postgresql://localhost:5432/db");
|
||||
settings.put(Environment.USER, "postgres");
|
||||
settings.put(Environment.PASS, "pass");
|
||||
settings.put(Environment.DIALECT, "org.hibernate.dialect.PostgreSQLDialect");
|
||||
|
||||
settings.put(Environment.SHOW_SQL, "true");
|
||||
|
||||
settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
|
||||
|
||||
settings.put(Environment.HBM2DDL_AUTO, "create-drop");
|
||||
|
||||
configuration.setProperties(settings);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
17
src/main/java/org/andrewkydev/api/database/dao/UserDao.java
Normal file
17
src/main/java/org/andrewkydev/api/database/dao/UserDao.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package org.andrewkydev.api.database.dao;
|
||||
|
||||
import org.andrewkydev.api.database.SessionFactoryMaker;
|
||||
import org.andrewkydev.api.database.models.User;
|
||||
import org.hibernate.Session;
|
||||
|
||||
public class UserDao {
|
||||
|
||||
private static final Session session = (Session) SessionFactoryMaker.getSessionFactory();
|
||||
|
||||
|
||||
public static void saveUser(User user) {
|
||||
session.beginTransaction();
|
||||
session.saveOrUpdate(user);
|
||||
session.getTransaction();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.andrewkydev.api.database.models;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "auth_information")
|
||||
public class AuthInformation {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id")
|
||||
@SerializedName(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "email")
|
||||
@SerializedName(value = "email")
|
||||
private String email;
|
||||
|
||||
@Column(name = "last_ip")
|
||||
@SerializedName(value = "last_ip")
|
||||
private String lastIp;
|
||||
|
||||
@Column(name = "previous_ip")
|
||||
@SerializedName(value = "previous_ip")
|
||||
private String previous_ip;
|
||||
|
||||
public AuthInformation() {
|
||||
}
|
||||
|
||||
public AuthInformation setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public AuthInformation setLastIp(String lastIp) {
|
||||
this.lastIp = lastIp;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public String getLastIp() {
|
||||
return lastIp;
|
||||
}
|
||||
|
||||
public AuthInformation setEmail(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public AuthInformation setPrevious_ip(String previous_ip) {
|
||||
this.previous_ip = previous_ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPrevious_ip() {
|
||||
return previous_ip;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.andrewkydev.api.database.models;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "economy")
|
||||
public class Economy {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id")
|
||||
@SerializedName(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "money")
|
||||
@SerializedName(value = "money")
|
||||
private BigInteger money;
|
||||
|
||||
@Column(name = "bank_money")
|
||||
@SerializedName(value = "bank_money")
|
||||
private BigInteger bankMoney;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "ecId")
|
||||
@SerializedName(value = "ecId")
|
||||
private Set<EconomyTransactions> economyTransactions;
|
||||
|
||||
public Economy() {
|
||||
}
|
||||
|
||||
public Economy setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Economy setBankMoney(BigInteger bankMoney) {
|
||||
this.bankMoney = bankMoney;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigInteger getBankMoney() {
|
||||
return bankMoney;
|
||||
}
|
||||
|
||||
public Economy setEconomyTransactions(Set<EconomyTransactions> economyTransactions) {
|
||||
this.economyTransactions = economyTransactions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<EconomyTransactions> getEconomyTransactions() {
|
||||
return economyTransactions;
|
||||
}
|
||||
|
||||
public Economy setMoney(BigInteger money) {
|
||||
this.money = money;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigInteger getMoney() {
|
||||
return money;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Economy [" +
|
||||
"id=" + id +
|
||||
", money=" + money +
|
||||
", bankMoney=" + bankMoney +
|
||||
", economyTransactions=" + economyTransactions +
|
||||
']';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.andrewkydev.api.database.models;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "economy_transactons")
|
||||
public class EconomyTransactions {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id")
|
||||
@SerializedName(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "amount")
|
||||
@SerializedName(value = "amount")
|
||||
private BigInteger amount;
|
||||
|
||||
@Column(name = "transaction_date")
|
||||
@SerializedName(value = "transaction_date")
|
||||
private LocalDateTime transactionDate;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@SerializedName(value = "recipientId")
|
||||
@JoinColumn(name = "recipientId", referencedColumnName = "id")
|
||||
private User recipientId;
|
||||
|
||||
public EconomyTransactions() {
|
||||
}
|
||||
|
||||
public EconomyTransactions setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public EconomyTransactions setRecipientId(User recipientId) {
|
||||
this.recipientId = recipientId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public User getRecipientId() {
|
||||
return recipientId;
|
||||
}
|
||||
|
||||
public EconomyTransactions setAmount(BigInteger amount) {
|
||||
this.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigInteger getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public EconomyTransactions setTransactionDate(LocalDateTime transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalDateTime getTransactionDate() {
|
||||
return transactionDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EconomyTransactions [" +
|
||||
"id=" + id +
|
||||
", amount=" + amount +
|
||||
", transactionDate=" + transactionDate +
|
||||
", recipientId=" + recipientId +
|
||||
']';
|
||||
}
|
||||
}
|
||||
98
src/main/java/org/andrewkydev/api/database/models/User.java
Normal file
98
src/main/java/org/andrewkydev/api/database/models/User.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package org.andrewkydev.api.database.models;
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
@SerializedName(value = "id")
|
||||
private Integer id;
|
||||
|
||||
|
||||
@Column(name = "nickname")
|
||||
@SerializedName(value = "nickname")
|
||||
private String nickname;
|
||||
|
||||
@Column(name = "creation_date")
|
||||
@SerializedName(value = "creation_date")
|
||||
private LocalDateTime creationDate;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@SerializedName(value = "user_statistic")
|
||||
@JoinColumn(name = "id", referencedColumnName = "id")
|
||||
private UserStatistic userStatistic;
|
||||
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@SerializedName(value = "auth_information")
|
||||
@JoinColumn(name = "id", referencedColumnName = "id")
|
||||
private AuthInformation authInformation;
|
||||
|
||||
|
||||
public User() {
|
||||
|
||||
}
|
||||
|
||||
public User setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public User setCreationDate(LocalDateTime creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public LocalDateTime getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public User setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setUserStatistic(UserStatistic userStatistic) {
|
||||
this.userStatistic = userStatistic;
|
||||
}
|
||||
|
||||
public UserStatistic getUserStatistic() {
|
||||
return userStatistic;
|
||||
}
|
||||
|
||||
public void setAuthInformation(AuthInformation authInformation) {
|
||||
this.authInformation = authInformation;
|
||||
}
|
||||
|
||||
public AuthInformation getAuthInformation() {
|
||||
return authInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [" +
|
||||
"id=" + id +
|
||||
", nickname='" + nickname + '\'' +
|
||||
", creationDate=" + creationDate +
|
||||
", userStatistic=" + userStatistic +
|
||||
", authInformation=" + authInformation +
|
||||
']';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.andrewkydev.api.database.models;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user_statistic")
|
||||
public class UserStatistic {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id")
|
||||
@SerializedName(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "block_placed")
|
||||
@SerializedName(value = "block_placed")
|
||||
Integer blockPlaced;
|
||||
|
||||
@Column(name = "block_broken")
|
||||
@SerializedName(value = "block_broken")
|
||||
Integer blocksBroken;
|
||||
|
||||
@Column(name = "playing_time")
|
||||
@SerializedName(value = "playing_time")
|
||||
Integer playingTime;
|
||||
|
||||
public UserStatistic() {
|
||||
}
|
||||
|
||||
public UserStatistic setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setBlockPlaced(Integer blockPlaced) {
|
||||
this.blockPlaced = blockPlaced;
|
||||
}
|
||||
|
||||
public Integer getBlockPlaced() {
|
||||
return blockPlaced;
|
||||
}
|
||||
|
||||
public void setBlocksBroken(Integer blocksBroken) {
|
||||
this.blocksBroken = blocksBroken;
|
||||
}
|
||||
|
||||
public Integer getBlocksBroken() {
|
||||
return blocksBroken;
|
||||
}
|
||||
|
||||
public void setPlayingTime(Integer playingTime) {
|
||||
this.playingTime = playingTime;
|
||||
}
|
||||
|
||||
public Integer getPlayingTime() {
|
||||
return playingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserStatistic [" +
|
||||
"id=" + id +
|
||||
", blockPlaced=" + blockPlaced +
|
||||
", blocksBroken=" + blocksBroken +
|
||||
", playingTime=" + playingTime +
|
||||
']';
|
||||
}
|
||||
}
|
||||
4
src/main/resources/plugin.yml
Normal file
4
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: API
|
||||
version: '${version}'
|
||||
main: org.andrewkydev.api.API
|
||||
api-version: '1.20'
|
||||
Reference in New Issue
Block a user