commit 1869255a54d7e4b97acedaad25d47e42f9eb66df Author: neroduckale Date: Fri Jul 5 04:56:44 2024 +0500 asd diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7bb8779 --- /dev/null +++ b/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + ru.neroduckale + sharik + 1.0.0 + jar + + vanya + + + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + + + src/main/resources + true + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + com.j256.ormlite + ormlite-jdbc + 6.1 + + + io.papermc.paper + paper-api + 1.20.1-R0.1-SNAPSHOT + provided + + + diff --git a/sharik.iml b/sharik.iml new file mode 100644 index 0000000..3cf00db --- /dev/null +++ b/sharik.iml @@ -0,0 +1,13 @@ + + + + + + + PAPER + + 1 + + + + \ No newline at end of file diff --git a/src/main/java/ru/neroduckale/sharik/Balance.java b/src/main/java/ru/neroduckale/sharik/Balance.java new file mode 100644 index 0000000..5dacd8c --- /dev/null +++ b/src/main/java/ru/neroduckale/sharik/Balance.java @@ -0,0 +1,26 @@ +package ru.neroduckale.sharik; + +import com.j256.ormlite.field.DatabaseField; +import com.j256.ormlite.table.DatabaseTable; +import ru.neroduckale.sharik.dao.balanceDaoImpl; + +@DatabaseTable(tableName = "balanceTable", daoClass = balanceDaoImpl.class) +public class Balance { + @DatabaseField(canBeNull = false, unique = true, columnName = "nickname") + private String nickname; + + @DatabaseField(canBeNull = false, unique = false, columnName = "balance") + private int balance; + public Balance() {} + public int getBalance() { + return balance; + } + public String getNickname() {return nickname;} + public void setBalance(int balance) { + this.balance = balance; + } + public void setNickname(String nickname) { + this.nickname = nickname; + } + +} diff --git a/src/main/java/ru/neroduckale/sharik/Main.java b/src/main/java/ru/neroduckale/sharik/Main.java new file mode 100644 index 0000000..f358d27 --- /dev/null +++ b/src/main/java/ru/neroduckale/sharik/Main.java @@ -0,0 +1,45 @@ +package ru.neroduckale.sharik; + +import com.j256.ormlite.dao.Dao; +import com.j256.ormlite.dao.DaoManager; +import com.j256.ormlite.jdbc.JdbcPooledConnectionSource; +import org.bukkit.plugin.java.JavaPlugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ru.neroduckale.sharik.dao.balanceDao; +import ru.neroduckale.sharik.dao.balanceDaoImpl; + +import java.sql.SQLException; + +public final class Main extends JavaPlugin { + private JdbcPooledConnectionSource connectionSource; + private Logger logger = LoggerFactory.getLogger("Balance"); + @Override + public void onEnable() { + try { + start(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + @Override + public void onDisable() { + try { + connectionSource.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void start() throws SQLException { + connectionSource = new JdbcPooledConnectionSource("jdbc:mysql://neroduck.ru:3306/balance", "pluginUser", "14881488"); + getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this); + balanceDaoImpl libraryDao = DaoManager.createDao(connectionSource, Balance.class); + Balance balance = new Balance(); + balance.setNickname("nerod"); + balance.setBalance(10); + libraryDao.create(balance); + Balance nero = libraryDao.findByName("nero"); + logger.error(String.valueOf(nero.getBalance())); + } +} diff --git a/src/main/java/ru/neroduckale/sharik/PlayerJoinListener.java b/src/main/java/ru/neroduckale/sharik/PlayerJoinListener.java new file mode 100644 index 0000000..1841d51 --- /dev/null +++ b/src/main/java/ru/neroduckale/sharik/PlayerJoinListener.java @@ -0,0 +1,34 @@ +package ru.neroduckale.sharik; + +import net.kyori.adventure.text.Component; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class PlayerJoinListener implements Listener { + + public PlayerJoinListener() { + + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) throws SQLException { + + Balance balance = new Balance(); + balance.setBalance(0); + balance.setNickname(event.getPlayer().getName()); + + + ItemStack item = new ItemStack(Material.STICK, 1); + List lore = new ArrayList<>(); + lore.add(Component.text("Ваш баланс: " + balance.getBalance())); + item.lore(lore); + event.getPlayer().getInventory().addItem(item); + } +} \ No newline at end of file diff --git a/src/main/java/ru/neroduckale/sharik/dao/balanceDao.java b/src/main/java/ru/neroduckale/sharik/dao/balanceDao.java new file mode 100644 index 0000000..39b5e04 --- /dev/null +++ b/src/main/java/ru/neroduckale/sharik/dao/balanceDao.java @@ -0,0 +1,10 @@ +package ru.neroduckale.sharik.dao; + +import com.j256.ormlite.dao.Dao; +import ru.neroduckale.sharik.Balance; + +import java.sql.SQLException; + +public interface balanceDao extends Dao { + public Balance findByName(String name) throws SQLException; +} diff --git a/src/main/java/ru/neroduckale/sharik/dao/balanceDaoImpl.java b/src/main/java/ru/neroduckale/sharik/dao/balanceDaoImpl.java new file mode 100644 index 0000000..77e590a --- /dev/null +++ b/src/main/java/ru/neroduckale/sharik/dao/balanceDaoImpl.java @@ -0,0 +1,21 @@ +package ru.neroduckale.sharik.dao; + +import com.j256.ormlite.dao.*; +import com.j256.ormlite.support.ConnectionSource; +import ru.neroduckale.sharik.Balance; + +import java.sql.SQLException; + +public class balanceDaoImpl extends BaseDaoImpl implements balanceDao{ + public balanceDaoImpl(ConnectionSource connectionSource) throws SQLException { + super(connectionSource, Balance.class); + } + + + @Override + public Balance findByName(String name) throws SQLException { + return super.queryForEq("nickname", name).get(0); + } + + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..18c3dba --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,4 @@ +name: vanya +version: '${project.version}' +main: ru.neroduckale.sharik.Main +api-version: '1.20' \ No newline at end of file