Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major changes #31

Merged
merged 5 commits into from
Oct 24, 2023
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
Binary file added libs/GemAPI.jar
Binary file not shown.
Binary file added libs/GringottsAPI.jar
Binary file not shown.
Binary file added libs/RoyaleEconomyAPI.jar
Binary file not shown.
68 changes: 65 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.geik.farmer</groupId>
<artifactId>Farmer</artifactId>
<version>v6-b002</version>
<version>v6-b003</version>

<properties>
<shaded.package>org.cas.osd.platform.ciam.shaded</shaded.package>
Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<version>1.20.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- FabledSkyblock -->
Expand Down Expand Up @@ -100,6 +100,13 @@
<version>0.99.5.0</version>
<scope>provided</scope>
</dependency>
<!-- LandsAPI -->
<dependency>
<groupId>com.github.angeschossen</groupId>
<artifactId>LandsAPI</artifactId>
<version>6.37.0</version>
<scope>provided</scope>
</dependency>
<!-- xSeries -->
<dependency>
<groupId>com.github.cryptomorin</groupId>
Expand All @@ -110,7 +117,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.11.3</version>
<version>2.12.0</version>
</dependency>
<!-- WildStacker -->
<dependency>
Expand All @@ -119,12 +126,57 @@
<version>2022.6</version>
<scope>provided</scope>
</dependency>
<!-- SpawnerMeta -->
<dependency>
<groupId>com.github.OfficialRell</groupId>
<artifactId>SpawnerMeta</artifactId>
<version>21.8</version>
<scope>provided</scope>
</dependency>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>
<!-- PlaceholderAPI -->
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.4</version>
<scope>provided</scope>
</dependency>
<!-- PlayerPoints -->
<dependency>
<groupId>org.black_ixx</groupId>
<artifactId>playerpoints</artifactId>
<version>3.2.6</version>
<scope>provided</scope>
</dependency>
<!-- ElementalGems -->
<dependency>
<groupId>me.elementalgaming</groupId>
<artifactId>GemAPI</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/GemAPI.jar</systemPath>
</dependency>
<!-- RoyaleEconomy -->
<dependency>
<groupId>me.qKing12</groupId>
<artifactId>RoyaleEconomyAPI</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/RoyaleEconomyAPI.jar</systemPath>
</dependency>
<!-- Gringotts -->
<dependency>
<groupId>org.gestern</groupId>
<artifactId>GringottsAPI</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/GringottsAPI.jar</systemPath>
</dependency>
</dependencies>

<!-- Repos -->
Expand Down Expand Up @@ -173,6 +225,16 @@
<id>glaremasters repo</id>
<url>https://repo.glaremasters.me/repository/towny/</url>
</repository>
<!-- PlaceholderAPI -->
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<!-- PlayerPoints -->
<repository>
<id>rosewood-repo</id>
<url>https://repo.rosewooddev.io/repository/public/</url>
</repository>
</repositories>

<build>
Expand Down
67 changes: 40 additions & 27 deletions src/main/java/xyz/geik/farmer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import de.leonhard.storage.Config;
import lombok.Getter;
import lombok.Setter;
import net.md_5.bungee.api.ChatColor;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import xyz.geik.farmer.api.FarmerAPI;
Expand All @@ -18,7 +17,9 @@
import xyz.geik.farmer.database.SQLite;
import xyz.geik.farmer.helpers.ItemsLoader;
import xyz.geik.farmer.helpers.Settings;
import xyz.geik.farmer.helpers.economy.*;
import xyz.geik.farmer.integrations.Integrations;
import xyz.geik.farmer.integrations.placeholderapi.PlaceholderAPI;
import xyz.geik.farmer.listeners.ListenerRegister;
import xyz.geik.farmer.model.FarmerLevel;
import xyz.geik.farmer.modules.FarmerModule;
Expand Down Expand Up @@ -52,6 +53,10 @@ public class Main extends JavaPlugin {
@Getter
private SQL sql;

@Getter
@Setter
private PlaceholderAPI placeholderAPI;

/**
* Instance of this class
*/
Expand Down Expand Up @@ -87,14 +92,15 @@ public class Main extends JavaPlugin {
* Main integration of plugin integrations#Integrations
*/
@Getter
@Setter
private static Integrations integration;

/**
* Economy hookup it's initialing down below.
* #setupEconomy
* Economy integration of plugin integrations#EconomyIntegrations
*/
@Getter
private static Economy econ = null;
@Setter
private static Economy economyIntegrations;

/**
* Constructor of class
Expand Down Expand Up @@ -123,13 +129,13 @@ public void onEnable() {
FarmerAPI.getModuleManager();
FarmerAPI.getStorageManager();
FarmerAPI.getDatabaseManager();
setupEconomy();
Settings.regenSettings();
new ItemsLoader();
FarmerLevel.loadLevels();
getCommand("farmer").setExecutor(new Commands());
getCommand("farmer").setTabCompleter(new FarmerTabComplete());
Integrations.registerIntegrations();
registerIntegrations();
sendEnableMessage();
setDatabaseManager();
this.sql.loadAllFarmers();
Expand All @@ -146,15 +152,7 @@ public void onEnable() {
*/
public void onDisable() {
this.sql.updateAllFarmers();
}

/**
* Integration setter
*
* @param data data of integration
*/
public static void setIntegration(Integrations data) {
integration = data;
this.placeholderAPI.unregister();
}

/**
Expand All @@ -175,18 +173,6 @@ public static void setIntegration(Integrations data) {
return ChatColor.translateAlternateColorCodes('&', text);
}

/**
* Setup economy by Vault.
*/
private void setupEconomy() {
if (Main.instance.getServer().getPluginManager().getPlugin("Vault") == null)
return;
RegisteredServiceProvider<Economy> rsp = Main.instance.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null)
return;
econ = rsp.getProvider();
}

/**
* Sends enable message to console.
*/
Expand Down Expand Up @@ -234,4 +220,31 @@ private void registerModules() {
FarmerAPI.getModuleManager().registerModule(new SpawnerKiller());
FarmerAPI.getModuleManager().loadModules();
}

/**
* Catches plugin that server uses
* and loads integration class of it.
*/
public static void registerIntegrations() {
if (Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("vault")
|| Bukkit.getPluginManager().isPluginEnabled("Vault")
&& Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("auto"))
Main.setEconomyIntegrations(new Vault());
else if (Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("royaleeconomy")
|| Bukkit.getPluginManager().isPluginEnabled("RoyaleEconomy")
&& Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("auto"))
Main.setEconomyIntegrations(new RoyaleEconomy());
else if (Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("playerpoints")
|| Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")
&& Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("auto"))
Main.setEconomyIntegrations(new PlayerPoints());
else if (Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("gringotts")
|| Bukkit.getPluginManager().isPluginEnabled("GrinGotts")
&& Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("auto"))
Main.setEconomyIntegrations(new GrinGotts());
else if(Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("elementalgems")
|| Bukkit.getPluginManager().isPluginEnabled("ElementalGems")
&& Main.getConfigFile().getString("settings.economy").equalsIgnoreCase("auto"))
Main.setEconomyIntegrations(new ElementalGems());
}
}
5 changes: 3 additions & 2 deletions src/main/java/xyz/geik/farmer/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ private void selfRemoveCommand(@NotNull Player player) {
*/
private void aboutCommand(@NotNull CommandSender player) {
player.sendMessage(Main.color("&7&m----------------------------------------"));
player.sendMessage(Main.color("#FFA500 FARMER &7- &6v" + Main.getInstance().getDescription().getVersion()));
player.sendMessage(Main.color("#FFA500 FARMER &7- &6" + Main.getInstance().getDescription().getVersion()));
player.sendMessage(Main.color("#3CB371Author: #90EE90Geik"));
player.sendMessage(Main.color("#FF7F50Contributors: #FFA07A" + Arrays.toString(Main.getInstance().getDescription().getAuthors().toArray())));
player.sendMessage(Main.color("#7289DADiscord: &7&ohttps://discord.geik.xyz"));
player.sendMessage(Main.color("#FFD700Website: &7&ohttps://geik.xyz"));
player.sendMessage(Main.color("&7&m----------------------------------------"));
player.sendMessage(Main.color("&aAPI: &7" + Main.getIntegration().getClass().getName()));
player.sendMessage(Main.color("&aActive Farmer: &7" + FarmerManager.getFarmers().size() ));
player.sendMessage(Main.color("&aEconomy API: &7" + Main.getEconomyIntegrations().getClass().getName()));
player.sendMessage(Main.color("&aActive Farmer: &7" + FarmerManager.getFarmers().size()));
player.sendMessage(Main.color("&7&m----------------------------------------"));
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/xyz/geik/farmer/guis/BuyGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.cryptomorin.xseries.XSound;
import de.themoep.inventorygui.InventoryGui;
import de.themoep.inventorygui.StaticGuiElement;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;
import xyz.geik.farmer.Main;
import xyz.geik.farmer.helpers.Settings;
Expand All @@ -27,7 +28,7 @@ public static void showGui(Player player) {
// Gui template as array
String[] buyGui = Main.getLangFile().getStringList("buyGui.interface").toArray(new String[0]);
// Inventory object
InventoryGui gui = new InventoryGui(Main.getInstance(), null, Main.getLangFile().getText("buyGui.guiName"), buyGui);
InventoryGui gui = new InventoryGui(Main.getInstance(), null, PlaceholderAPI.setPlaceholders(null, Main.getLangFile().getText("buyGui.guiName")), buyGui);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller());
// Buy item placer
Expand All @@ -39,9 +40,9 @@ public static void showGui(Player player) {
// Event written on bottom
click -> {
// If player has enough money to buy farmer
if (Main.getEcon().getBalance(player) >= Settings.farmerPrice) {
if (Main.getEconomyIntegrations().getBalance(player) >= Settings.farmerPrice) {
// Removes farmer money from player
Main.getEcon().withdrawPlayer(player, Settings.farmerPrice);
Main.getEconomyIntegrations().withdrawPlayer(player, Settings.farmerPrice);
// Creates new farmer
Farmer farmer = new Farmer(Main.getIntegration()
.getRegionID(player.getLocation()), 0);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xyz/geik/farmer/guis/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cryptomorin.xseries.XMaterial;
import de.themoep.inventorygui.*;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -41,7 +42,7 @@ public static void showGui(Player player, Farmer farmer) {
// Array of gui interface
String[] guiSetup = Main.getLangFile().getStringList("Gui.interface").toArray(new String[0]);
// Gui object
InventoryGui gui = new InventoryGui(Main.getInstance(), null, Main.getLangFile().getText("Gui.guiName"), guiSetup);
InventoryGui gui = new InventoryGui(Main.getInstance(), null, PlaceholderAPI.setPlaceholders(null, Main.getLangFile().getText("Gui.guiName")), guiSetup);
// Fills empty spaces on gui
gui.setFiller(GuiHelper.getFiller());
// Manage Icon element
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/xyz/geik/farmer/guis/ManageGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.themoep.inventorygui.DynamicGuiElement;
import de.themoep.inventorygui.InventoryGui;
import de.themoep.inventorygui.StaticGuiElement;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;
import xyz.geik.farmer.Main;
import xyz.geik.farmer.api.FarmerAPI;
Expand Down Expand Up @@ -31,7 +32,7 @@ public static void showGui(Player player, Farmer farmer) {
// Gui interface array
String[] guiSetup = Main.getLangFile().getStringList("manageGui.interface").toArray(new String[0]);
// Inventory object
InventoryGui gui = new InventoryGui(Main.getInstance(), null, Main.getLangFile().getText("manageGui.guiName"), guiSetup);
InventoryGui gui = new InventoryGui(Main.getInstance(), null, PlaceholderAPI.setPlaceholders(null, Main.getLangFile().getText("manageGui.guiName")), guiSetup);
// Filler for empty slots
gui.setFiller(GuiHelper.getFiller());
// Change state of Farmer Icon
Expand Down Expand Up @@ -75,11 +76,11 @@ public static void showGui(Player player, Farmer farmer) {
if (!(FarmerLevel.getAllLevels().size()-1 < nextLevelIndex)) {
FarmerLevel nextLevel = FarmerLevel.getAllLevels()
.get(nextLevelIndex);
if (Main.getEcon().getBalance(player) >= nextLevel.getReqMoney()) {
if (Main.getEconomyIntegrations().getBalance(player) >= nextLevel.getReqMoney()) {
if (nextLevel.getPerm() != null && !player.hasPermission(nextLevel.getPerm()))
player.sendMessage(Main.getLangFile().getText("noPerm"));
else {
Main.getEcon().withdrawPlayer(player, nextLevel.getReqMoney());
Main.getEconomyIntegrations().withdrawPlayer(player, nextLevel.getReqMoney());
farmer.setLevel(nextLevel);
farmer.getInv().setCapacity(nextLevel.getCapacity());
player.sendMessage(Main.getLangFile().getText("levelUpgraded")
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xyz/geik/farmer/guis/ModuleGui.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.geik.farmer.guis;

import de.themoep.inventorygui.InventoryGui;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;
import xyz.geik.farmer.Main;
import xyz.geik.farmer.api.handlers.FarmerModuleGuiCreateEvent;
Expand Down Expand Up @@ -29,7 +30,7 @@ public static void showGui(Player player, Farmer farmer) {
// Gui template as array
String[] moduleGui = Main.getLangFile().getStringList("moduleGui.interface").toArray(new String[0]);
// Inventory object
InventoryGui gui = new InventoryGui(Main.getInstance(), null, Main.getLangFile().getText("moduleGui.guiName"), moduleGui);
InventoryGui gui = new InventoryGui(Main.getInstance(), null, PlaceholderAPI.setPlaceholders(null, Main.getLangFile().getText("moduleGui.guiName")), moduleGui);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller());
// Addons placer
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xyz/geik/farmer/guis/UsersGui.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.geik.farmer.guis;

import de.themoep.inventorygui.*;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
Expand Down Expand Up @@ -38,7 +39,7 @@ public static void showGui(Player player, @NotNull Farmer farmer) {
// Gui interface array
String[] userGui = Main.getLangFile().getStringList("usersGui.interface").toArray(new String[0]);
// Inventory object
InventoryGui gui = new InventoryGui(Main.getInstance(), null, Main.getLangFile().getText("usersGui.guiName"), userGui);
InventoryGui gui = new InventoryGui(Main.getInstance(), null, PlaceholderAPI.setPlaceholders(null, Main.getLangFile().getText("usersGui.guiName")), userGui);
// Filler fills empty slots
gui.setFiller(GuiHelper.getFiller());
// Help icon show basic information about gui
Expand Down
Loading