Skip to content

Commit

Permalink
Merge pull request #25 from poyrazinan/develop
Browse files Browse the repository at this point in the history
update main
  • Loading branch information
poyrazinan committed Aug 18, 2023
2 parents cc7b436 + 83c7548 commit 6e13145
Show file tree
Hide file tree
Showing 32 changed files with 1,102 additions and 550 deletions.
60 changes: 46 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<groupId>xyz.geik.farmer</groupId>
<artifactId>Farmer</artifactId>
<version>1.0-SNAPSHOT</version>
<version>v6-b001</version>

<properties>
<shaded.package>org.cas.osd.platform.ciam.shaded</shaded.package>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- FabledSkyblock -->
Expand All @@ -33,23 +33,23 @@
</dependency>
<!-- Vault -->
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>9520d8847e</version>
<groupId>com.github.milkbowl</groupId>
<artifactId>Vault</artifactId>
<version>1.7.3</version>
<scope>provided</scope>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<!-- SimplixStorage -->
<dependency>
<groupId>com.github.Son-Hukumdar</groupId>
<groupId>com.github.poyrazinan</groupId>
<artifactId>SimplixStorage</artifactId>
<version>1.0.0-RELOADED</version>
<version>-ae92994823-1</version>
</dependency>
<!-- InventoryAPI -->
<dependency>
Expand Down Expand Up @@ -93,17 +93,24 @@
<version>3.0.9.4</version>
<scope>provided</scope>
</dependency>
<!-- TownyAdvanced -->
<dependency>
<groupId>com.palmergames.bukkit.towny</groupId>
<artifactId>towny</artifactId>
<version>0.99.5.0</version>
<scope>provided</scope>
</dependency>
<!-- xSeries -->
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.3.0</version>
<version>9.4.0</version>
</dependency>
<!-- NBT Api -->
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.11.1</version>
<version>2.11.3</version>
</dependency>
<!-- WildStacker -->
<dependency>
Expand All @@ -112,6 +119,12 @@
<version>2022.6</version>
<scope>provided</scope>
</dependency>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>
</dependencies>

<!-- Repos -->
Expand All @@ -124,7 +137,7 @@
<!-- Jitpack Repo -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
<url>https://www.jitpack.io</url>
</repository>
<!-- Spigot Repo -->
<repository>
Expand Down Expand Up @@ -155,6 +168,11 @@
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<!-- TownyAdvanced -->
<repository>
<id>glaremasters repo</id>
<url>https://repo.glaremasters.me/repository/towny/</url>
</repository>
</repositories>

<build>
Expand All @@ -163,7 +181,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
Expand Down Expand Up @@ -200,6 +218,10 @@
<pattern>de.tr7zw.nbtapi</pattern>
<shadedPattern>xyz.geik.farmer.shades.nbtapi</shadedPattern>
</relocation>
<relocation>
<pattern>com.zaxxer.hikari</pattern>
<shadedPattern>xyz.geik.farmer.shades.hikari</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
Expand All @@ -211,6 +233,16 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</build>
</project>
59 changes: 53 additions & 6 deletions src/main/java/xyz/geik/farmer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import de.leonhard.storage.Config;
import lombok.Getter;
import net.md_5.bungee.api.ChatColor;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -13,7 +13,9 @@
import xyz.geik.farmer.api.managers.FarmerManager;
import xyz.geik.farmer.commands.Commands;
import xyz.geik.farmer.commands.FarmerTabComplete;
import xyz.geik.farmer.database.DBQueries;
import xyz.geik.farmer.database.MySQL;
import xyz.geik.farmer.database.SQL;
import xyz.geik.farmer.database.SQLite;
import xyz.geik.farmer.helpers.ItemsLoader;
import xyz.geik.farmer.helpers.Settings;
import xyz.geik.farmer.integrations.Integrations;
Expand All @@ -28,6 +30,8 @@

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Main class of farmer
Expand All @@ -42,6 +46,11 @@ public class Main extends JavaPlugin {
*/
public Map<FarmerModule, Listener> listenerList = new HashMap<>();

/**
* SQL Manager
*/
private SQL sql;

/**
* Instance of this class
*/
Expand All @@ -51,7 +60,7 @@ public class Main extends JavaPlugin {
* Config files which using SimplixStorage API for it.
* Also, you can find usage code of API on helpers#StorageAPI
*/
private static Config configFile, itemsFile, langFile;
private static Config configFile, itemsFile, langFile, databaseFile;

/**
* Main integration of plugin integrations#Integrations
Expand All @@ -73,6 +82,7 @@ public void onLoad() {
configFile = FarmerAPI.getStorageManager().initConfig("config");
itemsFile = FarmerAPI.getStorageManager().initConfig("items");
langFile = FarmerAPI.getStorageManager().initLangFile(getConfigFile().getString("settings.lang"));
databaseFile = FarmerAPI.getStorageManager().initConfig("storage/database");
}

/**
Expand All @@ -91,10 +101,10 @@ public void onEnable() {
FarmerLevel.loadLevels();
getCommand("farmer").setExecutor(new Commands());
getCommand("farmer").setTabCompleter(new FarmerTabComplete());
DBQueries.createTable();
Integrations.registerIntegrations();
sendEnableMessage();
DBQueries.loadAllFarmers();
setDatabaseManager();
this.sql.loadAllFarmers();
new ListenerRegister();
loadMetrics();
registerModules();
Expand All @@ -107,7 +117,7 @@ public void onEnable() {
* can't handle async tasks while shutting down
*/
public void onDisable() {
DBQueries.updateAllFarmers();
this.sql.updateAllFarmers();
}

/**
Expand All @@ -128,12 +138,26 @@ public void onDisable() {
*/
public static Config getLangFile() { return langFile; }

/**
* Gets database file
* @return Config file
*/
public static Config getDatabaseFile() { return databaseFile; }

/**
* Gets instance
* @return Main class of main
*/
public static Main getInstance() { return instance; }

/**
* Gets SQL Manager
* @return SQL Manager
*/
public SQL getSql() {
return this.sql;
}

/**
* Gets Integration plugin instance
* @return Integrations plugin of integration
Expand Down Expand Up @@ -161,6 +185,15 @@ public static void setIntegration(Integrations data) {
* @return String of replaced text
*/
public static @NotNull String color(String text) {
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
if (Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19") || Bukkit.getVersion().contains("1.20")) {
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String color = text.substring(matcher.start(), matcher.end());
text = text.replace(color, ChatColor.of(color) + "");
matcher = pattern.matcher(text);
}
}
return ChatColor.translateAlternateColorCodes('&', text);
}

Expand Down Expand Up @@ -198,6 +231,20 @@ private void loadMetrics() {
}));
}

/**
* Registering Database Manager
*/
private void setDatabaseManager() {
String sqlType = getDatabaseFile().getString("database.type");
sqlType = sqlType.toLowerCase();

if (sqlType.equals("sqlite")) {
this.sql = new SQLite();
} else if (sqlType.equals("mysql")) {
this.sql = new MySQL();
}
}

/**
* Register modules to this plugin
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package xyz.geik.farmer.api.managers;

import xyz.geik.farmer.database.DBConnection;
import xyz.geik.farmer.Main;

import java.sql.Connection;

Expand All @@ -10,14 +10,16 @@
*/
public class DatabaseManager {

// MAYBE NOT WORK WITH NEW SYSTEM

/**
* Connects database of farmer.
*
* @return Connection to database
* @see Connection
*/
public static Connection connectDatabase() {
return DBConnection.connect();
return (Connection) Main.getInstance().getSql();
}

}
}
13 changes: 5 additions & 8 deletions src/main/java/xyz/geik/farmer/api/managers/FarmerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import org.bukkit.Location;
import xyz.geik.farmer.Main;
import xyz.geik.farmer.api.FarmerAPI;
import xyz.geik.farmer.database.DBConnection;
import xyz.geik.farmer.database.DBQueries;
import xyz.geik.farmer.model.Farmer;
import xyz.geik.farmer.model.user.FarmerPerm;
import xyz.geik.farmer.model.user.User;

import java.util.HashMap;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -46,7 +43,7 @@ public class FarmerManager {
*/
public boolean removeFarmer(String regionId) {
if (getFarmers().containsKey(regionId)) {
DBQueries.removeFarmer(getFarmers().get(regionId));
Main.getInstance().getSql().removeFarmer(getFarmers().get(regionId));
return true;
}
return false;
Expand All @@ -67,7 +64,7 @@ public void changeOwner(UUID oldOwner, UUID newOwner, String regionId) {
getFarmers().remove(regionId);
FarmerAPI.getFarmerManager().removeFarmer(regionId);
// Replaces old owner role to coop on db
User.updateRole(oldOwner, 1, newFarmer.getId());
Main.getInstance().getSql().updateRole(oldOwner, 1, newFarmer.getId());
// Replace old owner role to coop on cache
newFarmer.getUsers().stream().filter(user -> user.getUuid().equals(oldOwner)).findFirst().get().setPerm(FarmerPerm.MEMBER);
// Adds player if not exists on farmer users
Expand All @@ -83,10 +80,10 @@ public void changeOwner(UUID oldOwner, UUID newOwner, String regionId) {
*
* @author WaterArchery
*/
newFarmer.addUser(newOwner, Bukkit.getOfflinePlayer(newOwner).getName(), FarmerPerm.OWNER);
farmer.addUser(newOwner, Bukkit.getOfflinePlayer(newOwner).getName(), FarmerPerm.OWNER);
else {
// Replaces new owner role to owner on db
User.updateRole(newOwner, 2, newFarmer.getId());
Main.getInstance().getSql().updateRole(newOwner, 2, newFarmer.getId());
// Replaces new owner role to owner on cache
newFarmer.getUsers().stream().filter(user -> user.getUuid().equals(newOwner)).findFirst().get().setPerm(FarmerPerm.OWNER);
}
Expand All @@ -95,7 +92,7 @@ public void changeOwner(UUID oldOwner, UUID newOwner, String regionId) {
newFarmer.setRegionID(newOwner.toString());
getFarmers().put(newFarmer.getRegionID(), newFarmer);
// Saves farmer to db
newFarmer.saveFarmer(Objects.requireNonNull(DBConnection.connect()));
farmer.saveFarmer();
}
}

Expand Down
Loading

0 comments on commit 6e13145

Please sign in to comment.