This commit is contained in:
neroduckale 2024-07-05 04:56:44 +05:00
commit 1869255a54
8 changed files with 229 additions and 0 deletions

76
pom.xml Normal file
View file

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.neroduckale</groupId>
<artifactId>sharik</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>vanya</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-jdbc</artifactId>
<version>6.1</version>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

13
sharik.iml Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
</module>

View file

@ -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;
}
}

View file

@ -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()));
}
}

View file

@ -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<Component> lore = new ArrayList<>();
lore.add(Component.text("Ваш баланс: " + balance.getBalance()));
item.lore(lore);
event.getPlayer().getInventory().addItem(item);
}
}

View file

@ -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<Balance, Long> {
public Balance findByName(String name) throws SQLException;
}

View file

@ -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<Balance, Long> 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);
}
}

View file

@ -0,0 +1,4 @@
name: vanya
version: '${project.version}'
main: ru.neroduckale.sharik.Main
api-version: '1.20'