Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ jobs:
BRANCH_NAME=${GITHUB_REF##*/}
echo "Branch: $BRANCH_NAME"

# Останній тег для release або pre-release
if [ "$BRANCH_NAME" == "release" ]; then
LAST_TAG=$(git describe --tags --match "v[0-9]*\.[0-9]*\.[0-9]*" --abbrev=0 2>/dev/null || echo "")
# беремо тільки стабільні теги vX.Y.Z
LAST_TAG=$(git tag --list "v[0-9]*.[0-9]*.[0-9]*" --sort=-creatordate | tail -n1)
else
LAST_TAG=$(git tag --list "v*-dev.*" --sort=-creatordate | head -n1 || echo "")
# беремо тільки dev/pre-release теги
LAST_TAG=$(git tag --list "v*-dev.*" --sort=-creatordate | tail -n1)
fi

echo "Last tag: $LAST_TAG"

# Розбираємо версію
Expand Down Expand Up @@ -154,6 +156,7 @@ jobs:

echo "New version: $NEW_VERSION"
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT


- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
23 changes: 5 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

group = 'dev.lotus.studio'
Expand All @@ -21,7 +21,7 @@ repositories {
url = "https://maven.enginehub.org/repo/"
}
maven { url 'https://jitpack.io' }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases/" } // JBoss репозиторій
maven { url "https://repository.jboss.org/nexus/content/repositories/releases/" }
maven {
url "https://repo.oraxen.com/releases"
}
Expand All @@ -31,15 +31,8 @@ dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
compileOnly 'io.th0rgal:oraxen:1.184.1'
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.15")
implementation 'org.hibernate.orm:hibernate-core:6.6.1.Final'
implementation 'org.hibernate.orm:hibernate-community-dialects:6.6.1.Final'
implementation 'org.xerial:sqlite-jdbc:3.47.0.0'
// https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.5'
// https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-core
implementation 'org.glassfish.jaxb:jaxb-core:4.0.5'
// https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.2'
implementation("org.xerial:sqlite-jdbc:3.50.3.0")
implementation("com.j256.ormlite:ormlite-jdbc:6.1")
}

java {
Expand All @@ -49,12 +42,6 @@ java {
}


shadowJar {
archiveClassifier.set('')
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations = [project.configurations.runtimeClasspath]
}


processResources {
def props = [version: version]
Expand All @@ -63,4 +50,4 @@ processResources {
filesMatching('paper-plugin.yml') {
expand props
}
}
}
31 changes: 19 additions & 12 deletions src/main/java/dev/lotus/studio/Main.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package dev.lotus.studio;

import com.j256.ormlite.support.ConnectionSource;
import dev.lotus.studio.database.DatabaseInitializer;
import dev.lotus.studio.database.playerdata.PlayerDataService;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import dev.lotus.studio.database.hibernate.playerdata.PlayerDataServiceImpl;
import dev.lotus.studio.database.hibernate.savezone.SaveZoneDataService;
import dev.lotus.studio.database.hibernate.savezone.SaveZoneDataServiceImpl;
import dev.lotus.studio.database.playerdata.PlayerDataServiceImpl;
import dev.lotus.studio.database.savezone.SaveZoneDataService;
import dev.lotus.studio.database.savezone.SaveZoneDataServiceImpl;
import dev.lotus.studio.event.EatEvent;
import dev.lotus.studio.event.JoinLeaveEvent;
import dev.lotus.studio.item.CustomItemManager;
import dev.lotus.studio.command.MainCommand;
import dev.lotus.studio.database.hibernate.HibernateUtil;
import dev.lotus.studio.event.ArmorEvent;
import dev.lotus.studio.playerdata.PlayerBar;
import dev.lotus.studio.playerdata.PlayerManager;
import dev.lotus.studio.safezone.SafeZoneManager;

import java.sql.SQLException;

public final class Main extends JavaPlugin {

private static Main instance;
Expand All @@ -23,9 +27,9 @@ public final class Main extends JavaPlugin {



private PlayerDataServiceImpl playerDataBase;
private PlayerDataService playerDataBase;
private SaveZoneDataService saveZoneDataService;

private DatabaseInitializer databaseInitializer;



Expand All @@ -36,8 +40,11 @@ public void onEnable() {
PlayerManager.getInstance().startGlobalTask();
//cfg
itemManager = new CustomItemManager();
this.playerDataBase = new PlayerDataServiceImpl();
this.saveZoneDataService = new SaveZoneDataServiceImpl();
databaseInitializer = new DatabaseInitializer(this);
playerDataBase = databaseInitializer.getPlayerDataBase();
saveZoneDataService = databaseInitializer.getSaveZoneDataService();



itemManager.loadItems();
getServer().getPluginManager().registerEvents(new ArmorEvent(itemManager),this);
Expand All @@ -57,14 +64,14 @@ public void onEnable() {
@Override
public void onDisable() {
PlayerManager.getInstance().getGlobalTask().cancel();
// Закриття SessionFactory Hibernate при вимкненні плагіна
if (HibernateUtil.getSessionFactory() != null) {
HibernateUtil.getSessionFactory().close();
// Закриття DataBase
if (databaseInitializer != null) {
databaseInitializer.closeConnection();
}
getLogger().info("LotusOffSeason plugin disabled!");
HandlerList.unregisterAll(this);
}
public PlayerDataServiceImpl getPlayerDataBase() {
public PlayerDataService getPlayerDataBase() {
return playerDataBase;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/lotus/studio/command/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import dev.lotus.studio.database.hibernate.savezone.SaveZoneDataService;
import dev.lotus.studio.database.savezone.SaveZoneDataService;
import dev.lotus.studio.item.CustomItemManager;

import java.util.ArrayList;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/dev/lotus/studio/command/SafeZoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import dev.lotus.studio.database.hibernate.savezone.SaveZoneData;
import dev.lotus.studio.database.hibernate.savezone.SaveZoneDataService;
import dev.lotus.studio.database.savezone.SafeZoneDataBase;
import dev.lotus.studio.database.savezone.SaveZoneDataService;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -70,27 +70,27 @@ public boolean execute(CommandSender sender, String label, String[] args) {
}

private void removeZoneToDB(Player player, int id) {
service.getAllSaveZones().forEach(saveZoneData -> {
if (saveZoneData.getSafeZoneId() == id){
player.sendMessage("Сейв зону удаленно с названием: " + saveZoneData.getSafeZoneName() + " ID: " + saveZoneData.getSafeZoneId());
service.getAllSaveZones().forEach(safeZoneDataBase -> {
if (safeZoneDataBase.getSafeZoneId() == id){
player.sendMessage("Сейв зону удаленно с названием: " + safeZoneDataBase.getSafeZoneName() + " ID: " + safeZoneDataBase.getSafeZoneId());
}
});
service.removeProtectZone(id);
}

private void listZoneToDB(Player player) {
// Отримуємо всі збережені зони з бази даних
List<SaveZoneData> saveZoneDatas = service.getAllSaveZones();
List<SafeZoneDataBase> safeZoneDataBases = service.getAllSaveZones();

// Якщо зон немає, повідомляємо гравця
if (saveZoneDatas.isEmpty()) {
if (safeZoneDataBases.isEmpty()) {
player.sendMessage("нет зон.");
return;
}

// Формуємо мапу з імен зон і їх ідентифікаторів
HashMap<String, Integer> saveId = new HashMap<>();
saveZoneDatas.forEach(saveZoneData -> saveId.put(saveZoneData.getSafeZoneName(), saveZoneData.getSafeZoneId()));
safeZoneDataBases.forEach(saveZoneData -> saveId.put(saveZoneData.getSafeZoneName(), saveZoneData.getSafeZoneId()));

// Виводимо гравцю список зон
player.sendMessage("Список зон:");
Expand Down
137 changes: 137 additions & 0 deletions src/main/java/dev/lotus/studio/database/DatabaseInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package dev.lotus.studio.database;

import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import dev.lotus.studio.database.playerdata.PlayerDataBase;
import dev.lotus.studio.database.playerdata.PlayerDataService;
import dev.lotus.studio.database.playerdata.PlayerDataServiceImpl;
import dev.lotus.studio.database.savezone.SafeZoneDataBase;
import dev.lotus.studio.database.savezone.SaveZoneDataService;
import dev.lotus.studio.database.savezone.SaveZoneDataServiceImpl;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Logger;

public class DatabaseInitializer {

private final JavaPlugin plugin;
private final Logger logger;
private final String databasePath;
private ConnectionSource connectionSource;

private PlayerDataService playerDataBase;

private SaveZoneDataService saveZoneDataService;

public DatabaseInitializer(JavaPlugin plugin) {
this.plugin = plugin;
this.logger = plugin.getLogger();
this.databasePath = plugin.getDataFolder().getAbsolutePath() + File.separator + "database.db";
try {
createDatabaseFile();
createTables();
initialDataService();
} catch (IOException | SQLException e) {
throw new RuntimeException(e);
}
}

/**
* Створюємо файл бази даних якщо його ще нема
*/
public void createDatabaseFile() throws IOException {
File dataFolder = plugin.getDataFolder();
if (!dataFolder.exists()) {
if (!dataFolder.mkdirs()) {
logger.warning("Не вдалося створити директорію плагіна: " + dataFolder.getAbsolutePath());
}
}

File databaseFile = new File(databasePath);
if (!databaseFile.exists()) {
if (databaseFile.createNewFile()) {
logger.info("Створено новий файл бази даних: " + databasePath);
} else {
logger.warning("Не вдалося створити файл бази даних: " + databasePath);
}
}
}


/**
* Инициализация сервисов бд
*/

public void initialDataService() {
try {
ConnectionSource connectionSource = openConnection();
this.playerDataBase = new PlayerDataServiceImpl(connectionSource);
this.saveZoneDataService = new SaveZoneDataServiceImpl(connectionSource);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}






/**
* Повертає ORMLite ConnectionSource
*/
public ConnectionSource openConnection() throws SQLException {
if (connectionSource == null) {
String url = "jdbc:sqlite:" + databasePath;
connectionSource = new JdbcConnectionSource(url);

logger.info("З’єднання з базою даних встановлено (ORMLite)");
}
return connectionSource;
}

/**
* Створюємо таблиці через ORMLite
*/
public void createTables() throws SQLException {
ConnectionSource cs = openConnection();

TableUtils.createTableIfNotExists(cs, PlayerDataBase.class);
TableUtils.createTableIfNotExists(cs, SafeZoneDataBase.class);

logger.info("Таблиці ORMLite створені/перевірені");
}

/**
* Закриття з’єднання
*/
public void closeConnection() {
if (connectionSource != null) {
try {
connectionSource.close();
logger.info("З’єднання з базою даних закрито");
} catch (Exception e) {
logger.warning("Помилка закриття з’єднання: " + e.getMessage());
}
}
}

/**
* This method
* @return PlayerDataService
*/
public PlayerDataService getPlayerDataBase() {
return playerDataBase;
}
/**
* This method
* @return SaveZoneDataService
*/
public SaveZoneDataService getSaveZoneDataService() {
return saveZoneDataService;
}
}
Loading