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 #2887
|
||||||
* Fixed items getting deleted when breaking enhanced furnaces
|
* Fixed items getting deleted when breaking enhanced furnaces
|
||||||
* Fixed #2895
|
* Fixed #2895
|
||||||
|
* Fixed #2896
|
||||||
|
|
||||||
## Release Candidate 21 (14 Mar 2021)
|
## Release Candidate 21 (14 Mar 2021)
|
||||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#21
|
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.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
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.SeismicAxe;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;
|
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.BackpackListener;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BeeWingsListener;
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BeeWingsListener;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockListener;
|
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.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.MenuListener;
|
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.AContainer;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||||
@ -642,6 +645,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
|||||||
new HopperListener(this);
|
new HopperListener(this);
|
||||||
new TalismanListener(this);
|
new TalismanListener(this);
|
||||||
new SoulboundListener(this);
|
new SoulboundListener(this);
|
||||||
|
new AutoCrafterListener(this);
|
||||||
|
|
||||||
// Bees were added in 1.15
|
// Bees were added in 1.15
|
||||||
if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
||||||
@ -834,12 +838,26 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
|||||||
return instance.blockDataService;
|
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
|
@Nonnull
|
||||||
public static PerWorldSettingsService getWorldSettingsService() {
|
public static PerWorldSettingsService getWorldSettingsService() {
|
||||||
validateInstance();
|
validateInstance();
|
||||||
return instance.worldSettingsService;
|
return instance.worldSettingsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns our {@link HologramsService} which handles the creation and
|
||||||
|
* cleanup of any holograms.
|
||||||
|
*
|
||||||
|
* @return Our instance of {@link HologramsService}
|
||||||
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static HologramsService getHologramsService() {
|
public static HologramsService getHologramsService() {
|
||||||
validateInstance();
|
validateInstance();
|
||||||
@ -997,12 +1015,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
public static Set<Plugin> getInstalledAddons() {
|
public static Set<Plugin> getInstalledAddons() {
|
||||||
validateInstance();
|
validateInstance();
|
||||||
|
|
||||||
String pluginName = instance.getName();
|
String pluginName = instance.getName();
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
return Arrays.stream(instance.getServer().getPluginManager().getPlugins())
|
return Arrays.stream(instance.getServer().getPluginManager().getPlugins()).filter(plugin -> {
|
||||||
.filter(plugin -> {
|
|
||||||
PluginDescriptionFile description = plugin.getDescription();
|
PluginDescriptionFile description = plugin.getDescription();
|
||||||
return description.getDepend().contains(pluginName) || description.getSoftDepend().contains(pluginName);
|
return description.getDepend().contains(pluginName) || description.getSoftDepend().contains(pluginName);
|
||||||
}).collect(Collectors.toSet());
|
}).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.SlimefunAddon;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
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.core.networks.energy.EnergyNetComponentType;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
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.implementation.tasks.AsyncRecipeChoiceTask;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
@ -88,7 +88,6 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
|||||||
|
|
||||||
recipeStorageKey = new NamespacedKey(SlimefunPlugin.instance(), "recipe_key");
|
recipeStorageKey = new NamespacedKey(SlimefunPlugin.instance(), "recipe_key");
|
||||||
|
|
||||||
addItemHandler(onRightClick());
|
|
||||||
addItemHandler(new BlockTicker() {
|
addItemHandler(new BlockTicker() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -103,13 +102,21 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
/**
|
||||||
private BlockUseHandler onRightClick() {
|
* This method handles our right-clicking behaviour.
|
||||||
return e -> e.getClickedBlock().ifPresent(b -> {
|
* <p>
|
||||||
Player p = e.getPlayer();
|
* Do not call this method directly, see our {@link AutoCrafterListener} for the intended
|
||||||
|
* use case.
|
||||||
// Prevent blocks from being placed, food from being eaten, etc...
|
*
|
||||||
e.cancel();
|
* @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
|
// Check if we have a valid chest below
|
||||||
if (!isValidChest(b.getRelative(BlockFace.DOWN))) {
|
if (!isValidChest(b.getRelative(BlockFace.DOWN))) {
|
||||||
@ -132,7 +139,6 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
|||||||
} else {
|
} else {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "inventory.no-access");
|
SlimefunPlugin.getLocalization().sendMessage(p, "inventory.no-access");
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tick(@Nonnull Block b, @Nonnull Config data) {
|
protected void tick(@Nonnull Block b, @Nonnull Config data) {
|
||||||
|
@ -5,6 +5,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable;
|
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.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
@ -18,6 +19,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
|||||||
* @see AbstractAutoCrafter
|
* @see AbstractAutoCrafter
|
||||||
* @see VanillaAutoCrafter
|
* @see VanillaAutoCrafter
|
||||||
* @see SlimefunItemRecipe
|
* @see SlimefunItemRecipe
|
||||||
|
* @see AutoCrafterListener
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EnhancedAutoCrafter extends SlimefunAutoCrafter {
|
public class EnhancedAutoCrafter extends SlimefunAutoCrafter {
|
||||||
|
@ -60,6 +60,7 @@ public class AncientAltarListener implements Listener {
|
|||||||
private final List<Block> altars = new ArrayList<>();
|
private final List<Block> altars = new ArrayList<>();
|
||||||
private final Set<UUID> removedItems = new HashSet<>();
|
private final Set<UUID> removedItems = new HashSet<>();
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public AncientAltarListener(SlimefunPlugin plugin, AncientAltar altar, AncientPedestal pedestal) {
|
public AncientAltarListener(SlimefunPlugin plugin, AncientAltar altar, AncientPedestal pedestal) {
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
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