Skip to content

Commit

Permalink
mongodb and iaoraxen included
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsinco committed Aug 26, 2024
1 parent a5498ce commit 023859a
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 63 deletions.
11 changes: 8 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
val langVersion: Int = 17

group = "com.dre.brewery"
version = "3.2.7"
version = "3.2.7-SNAPSHOT"

repositories {
mavenCentral()
Expand All @@ -25,6 +25,7 @@ repositories {
maven("https://repo.projectshard.dev/repository/releases/") // Shopkeepers
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // PlaceholderAPI
maven("https://repo.glaremasters.me/repository/towny/") // Towny
maven("https://repo.oraxen.com/releases") // Oraxen
}

// TODO: Figure out exclusions because this is a mess.
Expand All @@ -50,7 +51,10 @@ dependencies {
compileOnly("com.nisovin.shopkeepers:ShopkeepersAPI:2.18.0") // https://www.spigotmc.org/resources/shopkeepers.80756/history
compileOnly("nl.rutgerkok:blocklocker:1.10.4") // https://www.spigotmc.org/resources/blocklocker.3268/history
compileOnly("me.clip:placeholderapi:2.11.5") // https://www.spigotmc.org/resources/placeholderapi.6245/history
compileOnly("io.th0rgal:oraxen:1.163.0")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.1")

implementation("org.mongodb:mongodb-driver-sync:5.0.1")
implementation("com.google.code.gson:gson:2.11.0")
implementation("org.jetbrains:annotations:16.0.2") // https://www.jetbrains.com/help/idea/annotating-source-code.html
implementation("com.github.Anon8281:UniversalScheduler:0.1.3") // https://github.com/Anon8281/UniversalScheduler
Expand Down Expand Up @@ -88,8 +92,9 @@ tasks {
}

shadowJar {
relocate("com.google", "com.dre.brewery.integration.google")
relocate("com.github.Anon8281.universalScheduler", "com.dre.brewery.integration.universalScheduler")
relocate("com.google", "com.dre.brewery.depend.google")
relocate("com.mongodb", "com.dre.brewery.depend.mongodb")
relocate("com.github.Anon8281.universalScheduler", "com.dre.brewery.depend.universalScheduler")
//relocate("org.bstats", "com.dre.brewery.integration.bstats")

archiveClassifier.set("")
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/dre/brewery/Barrel.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,13 @@ public void remove(@Nullable Block broken, @Nullable Player breaker, boolean dro
e.printStackTrace();
}
}
if (event.willDropItems() && body != null) {
if (event.willDropItems()) {
if (body == null) {
BreweryPlugin.getInstance().debugLog("Barrel Body is null, can't drop items: " + this.id);
barrels.remove(this);
return;
}

byte wood = body.getWood();
for (ItemStack item : items) {
if (item != null) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/dre/brewery/BreweryPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ public void onLoad() {
public void onEnable() {
migrateBreweryDataFolder();

// Version check
log("Minecraft version&7:&a " + minecraftVersion.getVersion());
if (minecraftVersion == MinecraftVersion.UNKNOWN) {
warningLog("This version of Minecraft is not known to Brewery! Please be wary of bugs or other issues that may occur in this version.");
}


// MC 1.13 uses a different NBT API than the newer versions.
// We decide here which to use, the new or the old or none at all
Expand Down Expand Up @@ -146,6 +140,12 @@ public void onEnable() {
PluginItem.registerItemLoader(this);


log("Minecraft version&7:&a " + minecraftVersion.getVersion());
if (minecraftVersion == MinecraftVersion.UNKNOWN) {
warningLog("This version of Minecraft is not known to Brewery! Please be wary of bugs or other issues that may occur in this version.");
}


// Load DataManager
try {
dataManager = DataManager.createDataManager(BConfig.configuredDataManager);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/dre/brewery/filedata/BConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import com.dre.brewery.integration.barrel.WGBarrel6;
import com.dre.brewery.integration.barrel.WGBarrel7;
import com.dre.brewery.integration.item.BreweryPluginItem;
import com.dre.brewery.integration.item.ItemsAdderPluginItem;
import com.dre.brewery.integration.item.MMOItemsPluginItem;
import com.dre.brewery.integration.item.OraxenPluginItem;
import com.dre.brewery.integration.item.SlimefunPluginItem;
import com.dre.brewery.recipe.BCauldronRecipe;
import com.dre.brewery.recipe.BRecipe;
Expand Down Expand Up @@ -68,6 +70,8 @@ public class BConfig {
public static Boolean hasMMOItems = null; // MMOItems ; Null if not checked
public static boolean hasChestShop;
public static boolean hasShopKeepers;
public static boolean hasOraxen;
public static boolean hasItemsAdder;

// Barrel
public static boolean openEverywhere;
Expand Down Expand Up @@ -234,6 +238,8 @@ public static void readConfig(FileConfiguration config) {
hasChestShop = plMan.isPluginEnabled("ChestShop");
hasShopKeepers = plMan.isPluginEnabled("Shopkeepers");
hasSlimefun = plMan.isPluginEnabled("Slimefun");
hasOraxen = plMan.isPluginEnabled("Oraxen");
hasItemsAdder = plMan.isPluginEnabled("ItemsAdder");

// various Settings
BreweryPlugin.debug = config.getBoolean("debug", false);
Expand Down Expand Up @@ -283,6 +289,8 @@ public static void readConfig(FileConfiguration config) {
PluginItem.registerForConfig("mmoitems", MMOItemsPluginItem::new);
PluginItem.registerForConfig("slimefun", SlimefunPluginItem::new);
PluginItem.registerForConfig("exoticgarden", SlimefunPluginItem::new);
PluginItem.registerForConfig("oraxen", OraxenPluginItem::new);
PluginItem.registerForConfig("itemsadder", ItemsAdderPluginItem::new);

// Loading custom items
ConfigurationSection configSection = config.getConfigurationSection("customItems");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dre.brewery.integration.item;

import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.recipe.PluginItem;
import dev.lone.itemsadder.api.CustomStack;
import org.bukkit.inventory.ItemStack;

public class ItemsAdderPluginItem extends PluginItem {
@Override
public boolean matches(ItemStack itemStack) {
if (!BConfig.hasItemsAdder) {
return false;
}

CustomStack cs = CustomStack.byItemStack(itemStack);
if (cs == null) {
return false;
}
return cs.getId().equals(this.getItemId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dre.brewery.integration.item;

import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.recipe.PluginItem;
import io.th0rgal.oraxen.api.OraxenItems;
import org.bukkit.inventory.ItemStack;

public class OraxenPluginItem extends PluginItem {
@Override
public boolean matches(ItemStack itemStack) {
if (!BConfig.hasOraxen) {
return false;
}

String itemId = OraxenItems.getIdByItem(itemStack);
if (itemId == null) {
return false;
}
return itemId.equals(this.getItemId());
}
}
8 changes: 5 additions & 3 deletions src/main/java/com/dre/brewery/storage/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.integration.bstats.Stats;
import com.dre.brewery.storage.impls.FlatFileStorage;
import com.dre.brewery.storage.impls.MongoDBStorage;
import com.dre.brewery.storage.impls.MySQLStorage;
import com.dre.brewery.storage.impls.SQLiteStorage;
import com.dre.brewery.storage.records.BreweryMiscData;
Expand Down Expand Up @@ -119,14 +120,14 @@ public void exit(boolean save, boolean async, Runnable callback) {
if (save) {
saveAll(async, () -> {
this.closeConnection();
plugin.log("DataManager exited.");
plugin.log("Closed connection from&7:&a " + this.getClass().getSimpleName());
if (callback != null) {
callback.run();
}
});
} else {
this.closeConnection(); // let databases close their connections
plugin.log("DataManager exited.");
plugin.log("Closed connection from&7:&a " + this.getClass().getSimpleName());
if (callback != null) {
callback.run();
}
Expand All @@ -138,6 +139,7 @@ public static DataManager createDataManager(ConfiguredDataManager record) throws
case FLATFILE -> new FlatFileStorage(record);
case MYSQL -> new MySQLStorage(record);
case SQLITE -> new SQLiteStorage(record);
case MONGODB -> new MongoDBStorage(record);
};

// Legacy data migration
Expand All @@ -155,7 +157,7 @@ public static DataManager createDataManager(ConfiguredDataManager record) throws
}


plugin.log("DataManager created&7:&a " + record.type());
plugin.log("DataManager created&7:&a " + record.type().getFormattedName());
return dataManager;
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/com/dre/brewery/storage/DataManagerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
public enum DataManagerType {
// We can add whatever type of storage type we want! As long as it's implemented properly.
// Maybe add: h2, mongodb, sqlite?
FLATFILE,
MYSQL,
SQLITE
FLATFILE("FlatFile"),
MYSQL("MySQL"),
SQLITE("SQLite"),
MONGODB("MongoDB"),;

private final String formattedName;

DataManagerType(String formattedName) {
this.formattedName = formattedName;
}

public String getFormattedName() {
return formattedName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void save() {
try {
dataFile.save(rawFile);
} catch (IOException e) {
plugin.errorLog("Failed to save brewery-data.yml!", e);
plugin.errorLog("Failed to save to Flatfile!", e);
}
}

Expand Down
Loading

0 comments on commit 023859a

Please sign in to comment.