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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<properties>
<java.version>16</java.version>
<codex.version>1.1.1-R0.3-SNAPSHOT</codex.version>
<codex.version>1.1.1-R0.7-SNAPSHOT</codex.version>
</properties>

<repositories>
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/studio/magemonkey/fusion/Fusion.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public void onEnable() {
LevelFunction.generate(200);
this.getCommand("craft").setExecutor(new Commands());
this.getCommand("fusion-editor").setExecutor(new FusionEditorCommand());
getServer().getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new RecipeGuiEventRouter(), this);
registerListener(this);
registerListener(new RecipeGuiEventRouter());
runQueueTask();

if (hookManager.isHooked(HookType.PlaceholderAPI)) {
Expand Down Expand Up @@ -190,6 +190,9 @@ private void runQueueTask() {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
PlayerLoader.loadPlayer(event.getPlayer());
if(!Cfg.autoJoinProfessions.isEmpty()) {
Cfg.autoJoinProfessions(event.getPlayer());
}
if (Cfg.craftingQueue) {
notifyForQueue(event.getPlayer());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ProfessionGuiRegistry getProfessionGui(String profession) {
* This object handles all players guis individually by caching them in a map.
*
* @param profession The name of the profession
* @param player The Player object
* @param player The Player object
* @return The profession gui object
*/
public ProfessionGuiRegistry openProfessionGui(String profession, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class FusionEvent extends Event implements Cancellable {
* Constructor for the FusionEvent
*
* @param professionName The name of the profession
* @param craftingTable The crafting table
* @param player The player
* @param craftingTable The crafting table
* @param player The player
*/
public FusionEvent(String professionName, CraftingTable craftingTable, Player player) {
this.professionName = professionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ProfessionGainXpEvent extends FusionEvent {
* Constructor for the ProfessionGainXpEvent
*
* @param professionName The name of the profession
* @param player The player that gained the experience
* @param gainedExp The amount of experience gained
* @param player The player that gained the experience
* @param gainedExp The amount of experience gained
*/
public ProfessionGainXpEvent(String professionName, Player player, long gainedExp) {
super(professionName, ProfessionsCfg.getTable(professionName), player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ProfessionJoinEvent extends FusionEvent {
* Constructor for the ProfessionJoinEvent
*
* @param professionName The name of the profession
* @param player The player that joined the profession
* @param player The player that joined the profession
*/
public ProfessionJoinEvent(String professionName, Player player) {
super(professionName, ProfessionsCfg.getTable(professionName), player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ProfessionLeaveEvent extends FusionEvent {
* Constructor for the ProfessionLeaveEvent
*
* @param professionName The name of the profession
* @param player The player that left the profession
* @param player The player that left the profession
*/
public ProfessionLeaveEvent(String professionName, Player player) {
super(professionName, ProfessionsCfg.getTable(professionName), player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class ProfessionLevelUpEvent extends FusionEvent {
* Constructor for the ProfessionLevelUpEvent
*
* @param professionName The name of the profession
* @param player The player that leveled up
* @param previousLevel The previous level of the profession
* @param newLevel The new level of the profession
* @param player The player that leveled up
* @param previousLevel The previous level of the profession
* @param newLevel The new level of the profession
*/
public ProfessionLevelUpEvent(String professionName, Player player, int previousLevel, int newLevel) {
super(professionName, ProfessionsCfg.getTable(professionName), player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class ProfessionMasteryEvent extends FusionEvent {
* Constructor for the ProfessionMasteryEvent
*
* @param professionName The name of the profession
* @param player The player that has mastered the profession
* @param hasMastered Whether the player has mastered the profession
* @param player The player that has mastered the profession
* @param hasMastered Whether the player has mastered the profession
*/
public ProfessionMasteryEvent(String professionName, Player player, boolean hasMastered) {
super(professionName, ProfessionsCfg.getTable(professionName), player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class QueueItemAddedEvent extends FusionEvent {
* Constructor for the QueueItemAddedEvent
*
* @param professionName The name of the profession
* @param player The player that added the item to the queue
* @param queue The crafting queue
* @param queueItem The queue item
* @param player The player that added the item to the queue
* @param queue The crafting queue
* @param queueItem The queue item
*/
public QueueItemAddedEvent(String professionName, Player player, CraftingQueue queue, QueueItem queueItem) {
super(professionName, ProfessionsCfg.getTable(professionName), player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ public class QueueItemFinishedEvent extends FusionEvent {
/**
* The crafting queue
*/
private final CraftingQueue queue;
private final CraftingQueue queue;
/**
* The queue item
*/
private final QueueItem queueItem;
private final QueueItem queueItem;
/**
* The result item
*/
@Setter
private List<RecipeItem> resultItems;
private List<RecipeItem> resultItems;

/**
* Constructor for the QueueItemFinishedEvent
*
* @param professionName The name of the profession
* @param player The player that finished the item
* @param queue The crafting queue
* @param queueItem The queue item
* @param resultItems The result items
* @param player The player that finished the item
* @param queue The crafting queue
* @param queueItem The queue item
* @param resultItems The result items
*/
public QueueItemFinishedEvent(String professionName,
Player player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class QueueItemRemovedEvent extends FusionEvent {
* Constructor for the QueueItemRemovedEvent
*
* @param professionName The name of the profession
* @param player The player that removed the item from the queue
* @param queue The crafting queue
* @param queueItem The queue item
* @param finished Whether the item was finished
* @param refunded Whether the item was refunded
* @param refundedItems The refunded items in case `refunded` is `true`
* @param player The player that removed the item from the queue
* @param queue The crafting queue
* @param queueItem The queue item
* @param finished Whether the item was finished
* @param refunded Whether the item was refunded
* @param refundedItems The refunded items in case `refunded` is `true`
*/
public QueueItemRemovedEvent(String professionName,
Player player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import studio.magemonkey.fusion.Fusion;
import studio.magemonkey.fusion.api.FusionAPI;
import studio.magemonkey.fusion.api.events.*;
import studio.magemonkey.fusion.cfg.ProfessionsCfg;
import studio.magemonkey.fusion.data.player.FusionPlayer;
import studio.magemonkey.fusion.data.professions.Profession;
import studio.magemonkey.fusion.data.recipes.CraftingTable;
import studio.magemonkey.fusion.util.ChatUT;
import studio.magemonkey.fusion.util.ExperienceManager;
import studio.magemonkey.fusion.util.PlayerUtil;

import java.util.Objects;

public class ProfessionService {

/**
Expand All @@ -27,15 +31,19 @@ public void joinProfession(String professionName, Player player, double moneyCos
ProfessionJoinEvent event = new ProfessionJoinEvent(professionName, player);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
event.getFusionPlayer()
.addProfession(new Profession(-1, player.getUniqueId(), professionName, 0, false, true));
if(!event.getFusionPlayer().hasProfession(professionName)) {
event.getFusionPlayer().addProfession(new Profession(-1, player.getUniqueId(), professionName, 0, false, true));
} else {
Objects.requireNonNull(event.getFusionPlayer().getProfession(professionName)).setJoined(true);
}
if (moneyCost > 0)
CodexEngine.get().getVault().take(player, moneyCost);
if (expCost > 0)
ExperienceManager.setTotalExperience(player, (ExperienceManager.getTotalExperience(player) - expCost));

MessageData[] data = {
new MessageData("profession", professionName),
new MessageData("inventoryName", ChatUT.hexString(ProfessionsCfg.getTable(professionName).getInventoryName())),
new MessageData("costs.money", moneyCost),
new MessageData("costs.experience", expCost),
new MessageData("unlocked", event.getFusionPlayer().getJoinedProfessions().size()),
Expand All @@ -58,6 +66,7 @@ public void leaveProfession(CraftingTable table, Player player) {
ProfessionLeaveEvent event = new ProfessionLeaveEvent(table.getName(), player);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
event.getFusionPlayer().setJoined(table, false);
event.getFusionPlayer().removeProfession(table);
CodexEngine.get().getMessageUtil().sendMessage("fusion.forgotten",
player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ public void finishQueueItem(Player player,
}
// Items if no commands exist
if (!item.getRecipe().getResults().hasCommandsOrItems()) {
ItemStack result = event.getQueueItem().getRecipe().getDivinityRecipeMeta() == null ? event.getQueueItem().getRecipe().getSettings().getRecipeItem().getItemStack()
ItemStack result =
event.getQueueItem().getRecipe().getDivinityRecipeMeta() == null ? event.getQueueItem()
.getRecipe()
.getSettings()
.getRecipeItem()
.getItemStack()
: event.getQueueItem().getRecipe().getDivinityRecipeMeta().generateItem();
// If there is no space in the inventory, drop the items
Collection<ItemStack> notAdded = player.getInventory().addItem(result).values();
Expand All @@ -165,7 +170,8 @@ public void finishQueueItem(Player player,
if (itemStack != null) {
Collection<ItemStack> remainings = player.getInventory().addItem(itemStack).values();
if (!remainings.isEmpty()) {
remainings.forEach(_item -> player.getWorld().dropItemNaturally(player.getLocation(), _item));
remainings.forEach(_item -> player.getWorld()
.dropItemNaturally(player.getLocation(), _item));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package studio.magemonkey.fusion.cfg;

import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import studio.magemonkey.fusion.Fusion;

import java.util.ArrayList;
import java.util.List;

public class BukkitRecipeWrapper {

public static List<NamespacedKey> getRecipeKeysForMaterials(List<Material> material) {

List<NamespacedKey> entries = new ArrayList<>();

for (Material mat : material) {
if (mat.isAir()) continue;
ItemStack stack = new ItemStack(mat);
var recipes = Bukkit.getRecipesFor(stack);
if (recipes.isEmpty()) {
Fusion.getInstance().error("No recipes found for material: " + mat);
continue;
}
for(Recipe recipe : recipes) {
if (recipe instanceof Keyed keyed) {
NamespacedKey key = keyed.getKey();
entries.add(key);
} else {
Bukkit.getLogger().info("Recipe has no key (likely a custom non-keyed recipe).");
}
}
}
return entries;
}

public static void enableBukkitRecipes(List<NamespacedKey> recipes) {
for (NamespacedKey recipe : recipes) {
Recipe bukkitRecipe = Fusion.getInstance().getServer().getRecipe(recipe);
if (bukkitRecipe != null) {
Fusion.getInstance().getServer().addRecipe(bukkitRecipe);
Bukkit.getLogger().info("Enabled Bukkit recipe with key: " + recipe);
} else {
Fusion.getInstance().error("Bukkit recipe with key " + recipe + " not found.");
}
}
}

public static void disableBukkitRecipes(List<NamespacedKey> recipes) {
for (NamespacedKey recipe : recipes) {
Recipe bukkitRecipe = Fusion.getInstance().getServer().getRecipe(recipe);
if (bukkitRecipe != null) {
Fusion.getInstance().getServer().removeRecipe(recipe);
Bukkit.getLogger().info("Disabled Bukkit recipe with key: " + recipe);
} else {
Fusion.getInstance().error("Bukkit recipe with key " + recipe + " not found.");
}
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/studio/magemonkey/fusion/cfg/Cfg.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package studio.magemonkey.fusion.cfg;

import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import studio.magemonkey.fusion.Fusion;
import studio.magemonkey.fusion.cfg.sql.DatabaseType;
import studio.magemonkey.fusion.commands.CommandMechanics;
import studio.magemonkey.fusion.data.player.FusionPlayer;
import studio.magemonkey.fusion.data.player.PlayerLoader;
import studio.magemonkey.fusion.gui.BrowseGUI;

import java.io.File;
import java.io.IOException;
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public final class Cfg {
public static String recursive = "floor(n+300^(n/7)^2)";
Expand All @@ -28,6 +38,8 @@ public final class Cfg {

public static String finishMessage = "&aYou have crafting items ready for pickup! ($<amount>)";

public static List<NamespacedKey> disabledVanillaRecipes = new ArrayList<>();
public static List<String> autoJoinProfessions = new ArrayList<>();

// No usage inside of Cfg, just used for default values. The actual values are stored in SQLManager.class
private static final DatabaseType storageType = DatabaseType.LOCAL;
Expand Down Expand Up @@ -89,6 +101,8 @@ private static void addDefs(FileConfiguration cfg) {
if (!cfg.isSet("storage.password")) cfg.set("storage.password", storagePassword);

if (!cfg.isSet("useCustomFormula")) cfg.set("useCustomFormula", useCustomFormula);
if (!cfg.isSet("disabled_vanilla_recipes")) cfg.set("disabled_vanilla_recipes", disabledVanillaRecipes);
if (!cfg.isSet("auto_join_professions")) cfg.set("auto_join_professions", autoJoinProfessions);
}

public static void init() {
Expand All @@ -111,6 +125,9 @@ public static void init() {
hideRecipesLimitReached = cfg.getBoolean("hideRecipesDefault.recipeLimitReached");

useCustomFormula = cfg.getBoolean("useCustomFormula");
List<Material> materials = cfg.getStringList("disabled_vanilla_recipes").stream().map(x -> Material.valueOf(x.toUpperCase())).toList();
disabledVanillaRecipes = BukkitRecipeWrapper.getRecipeKeysForMaterials(materials);
autoJoinProfessions = cfg.getStringList("auto_join_professions");

migrateOldTypes(cfg);
}
Expand All @@ -124,6 +141,8 @@ private static void reload(FileConfiguration cfg, File file) {
cfg.save(file);
// Load the config again
cfg.load(file);

BukkitRecipeWrapper.disableBukkitRecipes(disabledVanillaRecipes);
} catch (Exception e) {
Fusion.getInstance().getLogger().warning("Can't load config file: " + file + ":" + e.getMessage());
}
Expand Down Expand Up @@ -165,4 +184,12 @@ public static boolean setDatabaseType(DatabaseType type) {
return false;
}
}

public static void autoJoinProfessions(Player player) {
FusionPlayer fp = PlayerLoader.getPlayer(player);
for (String professionId : autoJoinProfessions) {
if(fp.hasProfession(professionId) && fp.hasJoined(professionId)) continue;
BrowseGUI.joinProfession(player, ProfessionsCfg.getGuiMap().get(professionId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static String getCraftingRequirementLine(String path) {
return ChatUT.hexString(config.getString(path + ".requirementLine", "&7Crafting Requirements"));
}

public static String getCraftingConditionLine(String path) {
return ChatUT.hexString(config.getString(path + ".conditionLine", "&7Crafting Conditions"));
}

public static String getBossBarTitle(ItemStack item) {
String itemName = item.getItemMeta() != null && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName()
: ChatUT.serialize(Component.translatable(item.getTranslationKey()));
Expand Down
Loading