1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Added sounds and two more messages

This commit is contained in:
TheBusyBiscuit 2021-02-06 00:14:44 +01:00
parent 3567dd87ba
commit a25b470272
5 changed files with 38 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@ -198,6 +199,9 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
menu.addItem(49, new CustomItem(Material.BARRIER, SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.remove")));
menu.addMenuClickHandler(49, (pl, item, slot, action) -> {
setSelectedRecipe(b, null);
pl.closeInventory();
p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-removed");
return false;
});
@ -205,6 +209,8 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
recipe.show(menu, task);
menu.open(p);
p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
if (!task.isEmpty()) {
task.start(menu.toInventory());
}

View File

@ -4,6 +4,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
@ -55,6 +56,8 @@ public class EnhancedAutoCrafter extends AbstractAutoCrafter {
if (recipe != null) {
setSelectedRecipe(b, recipe);
p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-set");
showRecipe(p, b, recipe);
} else {
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes");

View File

@ -1,5 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.auto_crafters;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
@ -14,8 +16,11 @@ import org.bukkit.block.Skull;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
@ -76,7 +81,27 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
@Override
protected void updateRecipe(@Nonnull Block b, @Nonnull Player p) {
ItemStack item = p.getInventory().getItemInMainHand();
List<Recipe> recipes = getRecipesFor(item);
if (recipes.isEmpty()) {
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes");
} else {
// TODO Choose vanilla recipe
}
}
@Nonnull
private List<Recipe> getRecipesFor(@Nonnull ItemStack item) {
List<Recipe> recipes = new ArrayList<>();
for (Recipe recipe : Bukkit.getRecipesFor(item)) {
if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) {
recipes.add(recipe);
}
}
return recipes;
}
}

View File

@ -72,6 +72,7 @@ public class RecipeChoiceTask implements Runnable {
@Override
public void run() {
// Terminate the task when noone is viewing the Inventory
if (inventory.getViewers().isEmpty()) {
Bukkit.getScheduler().cancelTask(id);
return;

View File

@ -148,6 +148,8 @@ messages:
auto-crafting:
select-a-recipe: '&eCrouch and Right-Click &7this block with the Item you want it to craft.'
recipe-set: '&aYou have successfully set the recipe for this machine.'
recipe-removed: '&eYou have successfully removed the recipe from this machine. You can set a new recipe at any time!'
no-recipes: '&cWe could not find any valid recipes for the item you are holding.'
select: 'Select this recipe'
remove: 'Remove this recipe'