mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-08 07:27:39 +01:00
Merge branch 'master' of https://Indyuce@git.lumine.io/mythiccraft/mmoitems/
This commit is contained in:
commit
d613c781c2
@ -22,7 +22,6 @@ import net.Indyuce.mmoitems.api.SoulboundInfo;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.util.RecipeBookUtil;
|
||||
import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot;
|
||||
import net.Indyuce.mmoitems.command.UpdateItemCommand;
|
||||
import net.Indyuce.mmoitems.command.completion.UpdateItemCompletion;
|
||||
@ -294,13 +293,21 @@ public class MMOItems extends JavaPlugin {
|
||||
// compatibility with /reload
|
||||
Bukkit.getScheduler().runTask(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.load(player)));
|
||||
|
||||
if (getConfig().getBoolean("recipes.recipe-amounts")) {
|
||||
RecipeBookUtil.enableAmounts();
|
||||
Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
|
||||
boolean book = getConfig().getBoolean("recipes.use-recipe-book");
|
||||
boolean amounts = getConfig().getBoolean("recipes.recipe-amounts");
|
||||
|
||||
if(book && amounts) {
|
||||
getLogger().warning("Tried to enable recipe book while amounts are active!");
|
||||
getLogger().warning("Please use only ONE of these options!");
|
||||
getLogger().warning("Disabling both options for now...");
|
||||
book = false;
|
||||
amounts = false;
|
||||
}
|
||||
if (getConfig().getBoolean("recipes.use-recipe-book"))
|
||||
RecipeBookUtil.enableBook();
|
||||
|
||||
|
||||
recipeManager.load(book, amounts);
|
||||
if(amounts)
|
||||
Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
|
||||
|
||||
// amount and bukkit recipes
|
||||
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
||||
recipeManager.loadRecipes();
|
||||
|
@ -26,7 +26,6 @@ import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.AirIngredient;
|
||||
import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.WorkbenchIngredient;
|
||||
import net.Indyuce.mmoitems.api.util.RecipeBookUtil;
|
||||
import net.Indyuce.mmoitems.stat.data.DoubleData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
|
||||
@ -47,7 +46,7 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
WorkbenchIngredient ingredient = MMOItems.plugin.getRecipes().getWorkbenchIngredient(recipe.get(i));
|
||||
// Only add AirIngredients if the amount system is enabled
|
||||
if (RecipeBookUtil.isAmounts() || !(ingredient instanceof AirIngredient))
|
||||
if (MMOItems.plugin.getRecipes().isAmounts() || !(ingredient instanceof AirIngredient))
|
||||
ingredients.put(i, ingredient);
|
||||
}
|
||||
return;
|
||||
|
@ -1,62 +0,0 @@
|
||||
package net.Indyuce.mmoitems.api.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
|
||||
public class RecipeBookUtil {
|
||||
private static boolean amounts = false;
|
||||
private static boolean enabled = false;
|
||||
|
||||
public static void enableAmounts() {
|
||||
amounts = true;
|
||||
}
|
||||
|
||||
public static void enableBook() {
|
||||
if(amounts) {
|
||||
MMOItems.plugin.getLogger().warning("Tried to enable recipe book while amounts are active!");
|
||||
MMOItems.plugin.getLogger().warning("Please use only ONE of these options!");
|
||||
return;
|
||||
}
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
public static void refresh(Player player) {
|
||||
if(!enabled) return;
|
||||
|
||||
if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 16)) {
|
||||
for (NamespacedKey key : player.getDiscoveredRecipes())
|
||||
if (key.getNamespace().equals("mmoitems")
|
||||
&& !MMOItems.plugin.getRecipes().getNamespacedKeys().contains(key))
|
||||
player.undiscoverRecipe(key);
|
||||
|
||||
for (NamespacedKey recipe : MMOItems.plugin.getRecipes().getNamespacedKeys())
|
||||
if (!player.hasDiscoveredRecipe(recipe))
|
||||
player.discoverRecipe(recipe);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (NamespacedKey recipe : MMOItems.plugin.getRecipes().getNamespacedKeys())
|
||||
player.discoverRecipe(recipe);
|
||||
}
|
||||
|
||||
public static void refreshOnline() {
|
||||
if(!enabled) return;
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
refresh(player);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
for (NamespacedKey recipe : MMOItems.plugin.getRecipes().getNamespacedKeys())
|
||||
Bukkit.removeRecipe(recipe);
|
||||
}
|
||||
|
||||
public static boolean isAmounts() {
|
||||
return amounts;
|
||||
}
|
||||
}
|
@ -47,6 +47,7 @@ public class GetMMOItemObjective extends Objective {
|
||||
@EventHandler
|
||||
public void a(CitizenInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(!getQuestProgress().getPlayer().isOnline()) return;
|
||||
if (player.equals(getQuestProgress().getPlayer().getPlayer()) && event.getNPC().getId() == npcId && player.getInventory().getItemInMainHand() != null) {
|
||||
NBTItem item = NBTItem.get(player.getInventory().getItemInMainHand());
|
||||
int amount;
|
||||
|
@ -28,7 +28,6 @@ import net.Indyuce.mmoitems.api.ability.Ability.CastingMode;
|
||||
import net.Indyuce.mmoitems.api.interaction.util.InteractItem;
|
||||
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.util.RecipeBookUtil;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
@ -37,7 +36,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void loadPlayerData(PlayerJoinEvent event) {
|
||||
RecipeBookUtil.refresh(event.getPlayer());
|
||||
MMOItems.plugin.getRecipes().refreshRecipeBook(event.getPlayer());
|
||||
PlayerData.load(event.getPlayer());
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.BlastingRecipe;
|
||||
import org.bukkit.inventory.CampfireRecipe;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
@ -29,7 +30,7 @@ import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.AirIngredient;
|
||||
import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.MMOItemIngredient;
|
||||
import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.VanillaIngredient;
|
||||
import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.WorkbenchIngredient;
|
||||
import net.Indyuce.mmoitems.api.util.RecipeBookUtil;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
|
||||
public class RecipeManager {
|
||||
/**
|
||||
@ -43,6 +44,18 @@ public class RecipeManager {
|
||||
*/
|
||||
private final Set<Recipe> loadedRecipes = new HashSet<>();
|
||||
|
||||
private boolean book = false;
|
||||
private boolean amounts = false;
|
||||
|
||||
public void load(boolean book, boolean amounts) {
|
||||
this.book = book;
|
||||
this.amounts = amounts;
|
||||
}
|
||||
|
||||
public boolean isAmounts() {
|
||||
return amounts;
|
||||
}
|
||||
|
||||
public void loadRecipes() {
|
||||
craftingRecipes.clear();
|
||||
|
||||
@ -98,7 +111,7 @@ public class RecipeManager {
|
||||
public void registerShapedRecipe(Type type, String id, List<String> list, String number) {
|
||||
CustomRecipe recipe = new CustomRecipe(type, id, list, false);
|
||||
|
||||
if (RecipeBookUtil.isAmounts())
|
||||
if (amounts)
|
||||
registerRecipe(recipe);
|
||||
else
|
||||
registerBukkitRecipe(recipe, number);
|
||||
@ -106,7 +119,7 @@ public class RecipeManager {
|
||||
|
||||
public void registerShapelessRecipe(Type type, String id, List<String> list, String number) {
|
||||
CustomRecipe recipe = new CustomRecipe(type, id, list, true);
|
||||
if (RecipeBookUtil.isAmounts())
|
||||
if (amounts)
|
||||
registerRecipe(recipe);
|
||||
else
|
||||
registerBukkitRecipe(recipe, number);
|
||||
@ -152,13 +165,36 @@ public class RecipeManager {
|
||||
*/
|
||||
public void reloadRecipes() {
|
||||
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> {
|
||||
RecipeBookUtil.clear();
|
||||
for (NamespacedKey recipe : getNamespacedKeys())
|
||||
Bukkit.removeRecipe(recipe);
|
||||
loadedRecipes.clear();
|
||||
loadRecipes();
|
||||
RecipeBookUtil.refreshOnline();
|
||||
if(book)
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
refreshRecipeBook(player);
|
||||
});
|
||||
}
|
||||
|
||||
public void refreshRecipeBook(Player player) {
|
||||
if(!book) return;
|
||||
|
||||
if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 16)) {
|
||||
for (NamespacedKey key : player.getDiscoveredRecipes())
|
||||
if (key.getNamespace().equals("mmoitems")
|
||||
&& !getNamespacedKeys().contains(key))
|
||||
player.undiscoverRecipe(key);
|
||||
|
||||
for (NamespacedKey recipe : getNamespacedKeys())
|
||||
if (!player.hasDiscoveredRecipe(recipe))
|
||||
player.discoverRecipe(recipe);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (NamespacedKey recipe : getNamespacedKeys())
|
||||
player.discoverRecipe(recipe);
|
||||
}
|
||||
|
||||
public WorkbenchIngredient getWorkbenchIngredient(String input) {
|
||||
String[] split = input.split("\\:");
|
||||
int amount = split.length > 1 ? Integer.parseInt(split[1]) : 1;
|
||||
|
Loading…
Reference in New Issue
Block a user