Skip to content

Commit

Permalink
Merge pull request #72 from BreweryTeam/snapshot
Browse files Browse the repository at this point in the history
PR 3.4.5-Snapshot
  • Loading branch information
Jsinco authored Dec 21, 2024
2 parents 6d6744b + 8af9384 commit caaad36
Show file tree
Hide file tree
Showing 52 changed files with 1,113 additions and 340 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/hangar-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Upload to Hangar'

on:
release:
branches: [master]
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.release.prerelease }} == false
steps:
- uses: benwoo1110/hangar-upload-action@v1
with:
api_token: ${{ secrets.HANGAR_TOKEN }}
slug: 'BreweryX'
version: ${{ github.event.release.tag_name }}
channel: release
description: ${{ github.event.release.body }}
files: |
[
{
"path": "build/libs/BreweryX-*.jar",
"platforms": ["PAPER", "FOLIA"]
}
]
# platform_dependencies: |
# {
# "PAPER": ["1.12","1.16-1.18.2","1.20.x"]
# }
14 changes: 9 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ val langVersion = 17
val encoding = "UTF-8"

group = "com.dre.brewery"
version = "3.4.4"
version = "3.4.5-SNAPSHOT"

repositories {
mavenCentral()
maven("https://repo.jsinco.dev/releases") // UniversalScheduler
maven("https://jitpack.io") // GriefPrevention, SlimeFun, PlaceholderAPI
maven("https://repo.md-5.net/content/groups/public/") // Bungee
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") // Spigot
Expand Down Expand Up @@ -65,7 +66,7 @@ dependencies {
// Which don't support records.
implementation("com.google.code.gson:gson:2.11.0")
// For proper scheduling between Bukkit-Folia like servers, https://github.com/Anon8281/UniversalScheduler
implementation("com.github.Anon8281:UniversalScheduler:0.1.3")
implementation("com.github.Anon8281:UniversalScheduler:0.1.3-dev")
// Nice annotations, I prefer these to Lombok's, https://www.jetbrains.com/help/idea/annotating-source-code.html
implementation("org.jetbrains:annotations:16.0.2")
// MongoDB & log4j to suppress MongoDB's logger
Expand Down Expand Up @@ -93,7 +94,9 @@ dependencies {
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.7")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.3.0-SNAPSHOT") // https://dev.bukkit.org/projects/worldedit/files
compileOnly("com.sk89q.worldedit:worldedit-core:7.3.0-SNAPSHOT") // https://dev.bukkit.org/projects/worldguard/files
compileOnly("com.griefcraft.lwc:LWCX:2.2.9-dev")// https://www.spigotmc.org/resources/lwc-extended.69551/history
compileOnly("com.griefcraft:lwc:2.3.2") { // https://www.spigotmc.org/resources/lwc-extended.69551/history
exclude("com.google")
}
compileOnly("com.github.TechFortress:GriefPrevention:16.18") // https://www.spigotmc.org/resources/griefprevention.1884/history
compileOnly("de.diddiz:logblock:1.16.5.1") // https://www.spigotmc.org/resources/logblock.67333/history
compileOnly("com.github.Slimefun:Slimefun4:RC-35") // https://github.com/Slimefun/Slimefun4/releases
Expand All @@ -118,7 +121,7 @@ tasks {

build {
dependsOn(shadowJar)
finalizedBy("kotlinReducedJar")
//finalizedBy("kotlinReducedJar")
}

jar {
Expand All @@ -141,7 +144,8 @@ tasks {
}

shadowJar {
relocate("com.google", "com.dre.brewery.depend.google")
relocate("com.google.gson", "com.dre.brewery.depend.google.gson")
relocate("com.google.errorprone", "com.dre.brewery.depend.google.errorprone")
relocate("com.github.Anon8281.universalScheduler", "com.dre.brewery.depend.universalScheduler")
relocate("eu.okaeri", "com.dre.brewery.depend.okaeri")
relocate("com.mongodb", "com.dre.brewery.depend.mongodb")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dre/brewery/BCauldron.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public static void clickCauldron(PlayerInteractEvent event) {
} else if (isBottle) {
BUtil.setItemInHand(event, Material.GLASS_BOTTLE, handSwap);
} else {
BUtil.setItemInHand(event, Material.AIR, handSwap);
item.setAmount(0);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/dre/brewery/BPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down Expand Up @@ -189,13 +190,13 @@ public static void clear() {
}

// Drink a brew and apply effects, etc.
public static boolean drink(Brew brew, ItemMeta meta, Player player) {
public static boolean drink(Brew brew, Player player, @Nullable ItemMeta meta, @Nullable PlayerItemConsumeEvent event) {
BPlayer bPlayer = get(player);
if (bPlayer == null) {
bPlayer = addPlayer(player);
}
// In this event the added alcohol amount is calculated, based on the sensitivity permission
BrewDrinkEvent drinkEvent = new BrewDrinkEvent(brew, meta, player, bPlayer);
BrewDrinkEvent drinkEvent = new BrewDrinkEvent(brew, meta, player, bPlayer, event);
if (meta != null) {
BreweryPlugin.getInstance().getServer().getPluginManager().callEvent(drinkEvent);
if (brew != drinkEvent.getBrew()) brew = drinkEvent.getBrew();
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/com/dre/brewery/BreweryPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import com.dre.brewery.storage.StorageInitException;
import com.dre.brewery.utility.Logging;
import com.dre.brewery.utility.MinecraftVersion;
import com.dre.brewery.utility.UpdateChecker;
import com.dre.brewery.utility.releases.ReleaseChecker;
import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import io.papermc.lib.PaperLib;
Expand All @@ -74,9 +74,7 @@
import java.util.stream.Collectors;

@Getter
public class BreweryPlugin extends JavaPlugin {

private static final int RESOURCE_ID = 114777;
public final class BreweryPlugin extends JavaPlugin {

private @Getter static AddonManager addonManager;
private @Getter static TaskScheduler scheduler;
Expand Down Expand Up @@ -123,14 +121,17 @@ public void onEnable() {

BSealer.registerRecipe(); // Sealing table recipe
ConfigManager.registerDefaultPluginItems(); // Register plugin items

// Load Addons
addonManager = new AddonManager(this);
addonManager.loadAddons();

ConfigManager.loadCauldronIngredients();
ConfigManager.loadRecipes();
ConfigManager.loadDistortWords();
this.breweryStats = new BreweryStats(); // Load metrics

// Load Addons
addonManager = new AddonManager(this);
addonManager.loadAddons();




Expand Down Expand Up @@ -173,7 +174,7 @@ public void onEnable() {
.filter(Objects::nonNull)
.toList());


addonManager.enableAddons();
// Setup Metrics
this.breweryStats.setupBStats();
new BreweryXStats().setupBStats();
Expand Down Expand Up @@ -220,16 +221,17 @@ public void onEnable() {
placeholderAPIHook.getInstance().register();
}

if (config.isUpdateCheck()) {
UpdateChecker.run(RESOURCE_ID);
}

Logging.log("Using scheduler&7: &a" + scheduler.getClass().getSimpleName());
Logging.log("Environment&7: &a" + Logging.getEnvironmentAsString());
if (!PaperLib.isPaper()) {
Logging.log("&aBreweryX performs best on Paper-based servers. Please consider switching to Paper for the best experience. &7https://papermc.io");
}
Logging.log("BreweryX enabled!");

ReleaseChecker releaseChecker = ReleaseChecker.getInstance();
releaseChecker.checkForUpdate().thenAccept(updateAvailable -> {
releaseChecker.notify(Bukkit.getConsoleSender());
});
}

@Override
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/dre/brewery/api/addons/AddonConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.dre.brewery.configuration.ConfigHead;
import com.dre.brewery.configuration.annotation.OkaeriConfigFileOptions;
import eu.okaeri.configs.configurer.Configurer;
import eu.okaeri.configs.serdes.BidirectionalTransformer;
import eu.okaeri.configs.serdes.OkaeriSerdesPack;
import org.jetbrains.annotations.Nullable;

Expand All @@ -40,8 +41,6 @@ public class AddonConfigManager {

private final ConfigHead INSTANCE;



public AddonConfigManager(BreweryAddon addon) {
this.INSTANCE = new ConfigHead(BreweryPlugin.getInstance().getDataFolder().toPath().resolve("addons").resolve(addon.getAddonInfo().name()));
}
Expand Down Expand Up @@ -106,24 +105,36 @@ private <T extends AddonConfigFile> T createConfig(Class<T> configClass, Path fi
* @return The new config instance
* @param <T> The type of the config
*/
private <T extends AddonConfigFile> T createConfig(Class<T> configClass) {
public <T extends AddonConfigFile> T createConfig(Class<T> configClass) {
return INSTANCE.createConfig(configClass);
}

@Nullable
private <T extends AddonConfigFile> T createBlankConfigInstance(Class<T> configClass) {
public <T extends AddonConfigFile> T createBlankConfigInstance(Class<T> configClass) {
return INSTANCE.createBlankConfigInstance(configClass);
}


public void addSerdesPacks(OkaeriSerdesPack... serdesPacks) {
INSTANCE.addSerdesPacks(serdesPacks);
}

public void addBiDirectionalTransformers(BidirectionalTransformer<?, ?>... transformers) {
INSTANCE.addBidirectionalTransformers(transformers);
}

public void addConfigurer(Configurer configurer) {
INSTANCE.addConfigurer(configurer);
}

// Util

public void createFileFromResources(String resourcesPath, Path destination) {
INSTANCE.createFileFromResources(resourcesPath, destination);
}


private OkaeriConfigFileOptions getOkaeriConfigFileOptions(Class<? extends AddonConfigFile> configClass) {
public OkaeriConfigFileOptions getOkaeriConfigFileOptions(Class<? extends AddonConfigFile> configClass) {
return INSTANCE.getOkaeriConfigFileOptions(configClass);
}
public Path getDataFolder() {
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/dre/brewery/api/addons/AddonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/
public class AddonManager {

public final static ConcurrentLinkedQueue<BreweryAddon> LOADED_ADDONS = new ConcurrentLinkedQueue<>();
public static final ConcurrentLinkedQueue<BreweryAddon> LOADED_ADDONS = new ConcurrentLinkedQueue<>();

private final BreweryPlugin plugin;
private final File addonsFolder;
Expand Down Expand Up @@ -118,16 +118,19 @@ public void loadAddons() {
loadAddon(file); // Go read the documentation below to understand what this does.
}

int loaded = LOADED_ADDONS.size();
if (loaded > 0) Logging.log("Loaded " + loaded + " addon(s)");
}

public void enableAddons() {
for (BreweryAddon addon : LOADED_ADDONS) {
try {
addon.onAddonEnable(); // All done, let the addon know it's been enabled.
} catch (Throwable t) {
Logging.errorLog("Failed to enable addon " + addon.getClass().getSimpleName(), t);
Logging.errorLog("Failed to enable addon " + addon.getAddonInfo().name(), t);
unloadAddon(addon);
}
}
int loaded = LOADED_ADDONS.size();
if (loaded > 0) Logging.log("Loaded " + loaded + " addon(s)");
}


Expand Down Expand Up @@ -167,10 +170,12 @@ public void loadAddon(File file) {
Field loggerField = BreweryAddon.class.getDeclaredField("logger"); loggerField.setAccessible(true);
Field fileManagerField = BreweryAddon.class.getDeclaredField("addonFileManager"); fileManagerField.setAccessible(true);
Field addonConfigManagerField = BreweryAddon.class.getDeclaredField("addonConfigManager"); addonConfigManagerField.setAccessible(true);
Field addonFile = BreweryAddon.class.getDeclaredField("addonFile"); addonFile.setAccessible(true);

loggerField.set(addon, new AddonLogger(addon.getAddonInfo()));
fileManagerField.set(addon, new AddonFileManager(addon, file));
addonConfigManagerField.set(addon, new AddonConfigManager(addon));
addonFile.set(addon, file);


addon.getAddonLogger().info("Loading &a" + addon.getAddonInfo().name() + " &f-&a v" + addon.getAddonInfo().version() + " &fby &a" + addon.getAddonInfo().author());
Expand Down Expand Up @@ -234,6 +239,7 @@ private Tuple<Class<? extends BreweryAddon>, List<Class<?>>> getClassesFromJar(F
// It's important that we don't initialize any other classes before our main class.
clazz = Class.forName(className, false, classLoader);
} catch (ClassNotFoundException | NoClassDefFoundError e) {
Logging.errorLog("An exception occurred while trying to load a class from an addon", e);
continue;
}
if (BreweryAddon.class.isAssignableFrom(clazz)) {
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/dre/brewery/api/addons/BreweryAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@

import com.dre.brewery.BreweryPlugin;
import com.dre.brewery.commands.CommandManager;
import com.dre.brewery.storage.DataManager;
import com.dre.brewery.utility.MinecraftVersion;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import com.google.common.reflect.ClassPath;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Entry and exit point for a BreweryX addon. Addon classes should be annotated with {@link AddonInfo}.
Expand Down Expand Up @@ -81,6 +89,7 @@ public abstract class BreweryAddon {
private AddonLogger logger;
private AddonFileManager addonFileManager;
private AddonConfigManager addonConfigManager;
private File addonFile;


public void onAddonPreEnable() {
Expand Down Expand Up @@ -133,6 +142,13 @@ public AddonLogger getAddonLogger() {
return logger;
}


@NotNull
public File getAddonFile() {
return addonFile;
}


/**
* Register a listener with the server.
* @param listener The listener to register
Expand Down Expand Up @@ -213,6 +229,16 @@ public TaskScheduler getScheduler() {
return BreweryPlugin.getScheduler();
}

/**
* Retrieves the DataManager associated with the BreweryX plugin.
*
* @return The DataManager instance
*/
@NotNull
public DataManager getDataManager() {
return BreweryPlugin.getDataManager();
}

/**
* Get the addon manager for BreweryX.
* @return The addon manager
Expand Down Expand Up @@ -246,4 +272,26 @@ public boolean isFolia() {
public boolean isPaper() {
return PaperLib.isPaper();
}


// Exposed Reflection API for addons.

/**
* For addons to reflectively discover their own classes, they must reference their own Jar.
* @param packageName Package to search
* @return Set of classes in the package
*/
public Set<Class<?>> findClasses(String packageName) throws IOException {
URLClassLoader classLoader = new URLClassLoader(
new URL[] { getAddonFile().toURI().toURL() },
this.getClass().getClassLoader()
);
return ClassPath.from(classLoader)
.getAllClasses()
.stream()
.filter(clazz -> clazz.getPackageName()
.equalsIgnoreCase(packageName)) // should just be equals instead of equalsIgnoreCase probs
.map(ClassPath.ClassInfo::load)
.collect(Collectors.toSet());
}
}
Loading

0 comments on commit caaad36

Please sign in to comment.