mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2896
This commit is contained in:
parent
001e7654aa
commit
13355c1afe
@ -37,6 +37,7 @@
|
||||
* Fixed #2887
|
||||
* Fixed items getting deleted when breaking enhanced furnaces
|
||||
* Fixed #2895
|
||||
* Fixed #2896
|
||||
|
||||
## Release Candidate 21 (14 Mar 2021)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#21
|
||||
|
@ -18,6 +18,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -61,6 +62,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GrapplingHo
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AutoCrafterListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BeeWingsListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockListener;
|
||||
@ -118,6 +120,7 @@ import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.MenuListener;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
@ -642,6 +645,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
new HopperListener(this);
|
||||
new TalismanListener(this);
|
||||
new SoulboundListener(this);
|
||||
new AutoCrafterListener(this);
|
||||
|
||||
// Bees were added in 1.15
|
||||
if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
||||
@ -834,12 +838,26 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
return instance.blockDataService;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns out world settings service.
|
||||
* That service is responsible for managing item settings per
|
||||
* {@link World}, such as disabling a {@link SlimefunItem} in a
|
||||
* specific {@link World}.
|
||||
*
|
||||
* @return Our instance of {@link PerWorldSettingsService}
|
||||
*/
|
||||
@Nonnull
|
||||
public static PerWorldSettingsService getWorldSettingsService() {
|
||||
validateInstance();
|
||||
return instance.worldSettingsService;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns our {@link HologramsService} which handles the creation and
|
||||
* cleanup of any holograms.
|
||||
*
|
||||
* @return Our instance of {@link HologramsService}
|
||||
*/
|
||||
@Nonnull
|
||||
public static HologramsService getHologramsService() {
|
||||
validateInstance();
|
||||
@ -997,12 +1015,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
@Nonnull
|
||||
public static Set<Plugin> getInstalledAddons() {
|
||||
validateInstance();
|
||||
|
||||
String pluginName = instance.getName();
|
||||
|
||||
// @formatter:off
|
||||
return Arrays.stream(instance.getServer().getPluginManager().getPlugins())
|
||||
.filter(plugin -> {
|
||||
return Arrays.stream(instance.getServer().getPluginManager().getPlugins()).filter(plugin -> {
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
return description.getDepend().contains(pluginName) || description.getSoftDepend().contains(pluginName);
|
||||
}).collect(Collectors.toSet());
|
||||
|
@ -31,9 +31,9 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AutoCrafterListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
@ -88,7 +88,6 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
||||
|
||||
recipeStorageKey = new NamespacedKey(SlimefunPlugin.instance(), "recipe_key");
|
||||
|
||||
addItemHandler(onRightClick());
|
||||
addItemHandler(new BlockTicker() {
|
||||
|
||||
@Override
|
||||
@ -103,13 +102,21 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
||||
});
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BlockUseHandler onRightClick() {
|
||||
return e -> e.getClickedBlock().ifPresent(b -> {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
// Prevent blocks from being placed, food from being eaten, etc...
|
||||
e.cancel();
|
||||
/**
|
||||
* This method handles our right-clicking behaviour.
|
||||
* <p>
|
||||
* Do not call this method directly, see our {@link AutoCrafterListener} for the intended
|
||||
* use case.
|
||||
*
|
||||
* @param b
|
||||
* The {@link Block} that was clicked
|
||||
* @param p
|
||||
* The {@link Player} who clicked
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public void onRightClick(Block b, Player p) {
|
||||
Validate.notNull(b, "The Block must not be null!");
|
||||
Validate.notNull(p, "The Player cannot be null!");
|
||||
|
||||
// Check if we have a valid chest below
|
||||
if (!isValidChest(b.getRelative(BlockFace.DOWN))) {
|
||||
@ -132,7 +139,6 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
||||
} else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "inventory.no-access");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void tick(@Nonnull Block b, @Nonnull Config data) {
|
||||
|
@ -5,6 +5,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AutoCrafterListener;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -18,6 +19,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
* @see AbstractAutoCrafter
|
||||
* @see VanillaAutoCrafter
|
||||
* @see SlimefunItemRecipe
|
||||
* @see AutoCrafterListener
|
||||
*
|
||||
*/
|
||||
public class EnhancedAutoCrafter extends SlimefunAutoCrafter {
|
||||
|
@ -60,6 +60,7 @@ public class AncientAltarListener implements Listener {
|
||||
private final List<Block> altars = new ArrayList<>();
|
||||
private final Set<UUID> removedItems = new HashSet<>();
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public AncientAltarListener(SlimefunPlugin plugin, AncientAltar altar, AncientPedestal pedestal) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
|
@ -0,0 +1,62 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.auto_crafters.AbstractAutoCrafter;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.auto_crafters.EnhancedAutoCrafter;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for providing interactions to the auto crafters.
|
||||
* See Issue #2896 with the {@link EnhancedAutoCrafter}, any {@link SlimefunItem} which
|
||||
* overrides the right click functonality would be ignored.
|
||||
* This {@link Listener} resolves that issue.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see EnhancedAutoCrafter
|
||||
*
|
||||
*/
|
||||
public class AutoCrafterListener implements Listener {
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public AutoCrafterListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerRightClickEvent e) {
|
||||
Optional<Block> clickedBlock = e.getClickedBlock();
|
||||
|
||||
// We want to make sure we used the main hand, the interaction was not cancelled and a Block was clicked.
|
||||
if (e.getHand() == EquipmentSlot.HAND && e.useBlock() != Result.DENY && clickedBlock.isPresent()) {
|
||||
Optional<SlimefunItem> slimefunBlock = e.getSlimefunBlock();
|
||||
|
||||
// Check if the clicked Block is a Slimefun block.
|
||||
if (!slimefunBlock.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SlimefunItem block = slimefunBlock.get();
|
||||
|
||||
if (block instanceof AbstractAutoCrafter) {
|
||||
// Prevent blocks from being placed, food from being eaten, etc...
|
||||
e.cancel();
|
||||
|
||||
// Fixes 2896 - Forward the interaction before items get handled.
|
||||
((AbstractAutoCrafter) block).onRightClick(clickedBlock.get(), e.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user