Fix Slimefun item eat at cauldron

This commit is contained in:
Sn0wStorm 2022-07-10 14:22:23 +02:00
parent f08e3caac2
commit db428892e9
5 changed files with 63 additions and 6 deletions

View File

@ -1,7 +1,7 @@
name: Brewery
version: 3.1
main: com.dre.brewery.P
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny, BlockLocker]
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny, BlockLocker, Slimefun]
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]
api-version: 1.13
commands:

View File

@ -32,6 +32,7 @@ import com.dre.brewery.filedata.UpdateChecker;
import com.dre.brewery.integration.ChestShopListener;
import com.dre.brewery.integration.IntegrationListener;
import com.dre.brewery.integration.ShopKeepersListener;
import com.dre.brewery.integration.SlimefunListener;
import com.dre.brewery.integration.barrel.BlocklockerBarrel;
import com.dre.brewery.integration.barrel.LogBlockBarrel;
import com.dre.brewery.listeners.*;
@ -161,6 +162,9 @@ public class P extends JavaPlugin {
if (BConfig.hasShopKeepers) {
p.getServer().getPluginManager().registerEvents(new ShopKeepersListener(), p);
}
if (BConfig.hasSlimefun && use1_14) {
p.getServer().getPluginManager().registerEvents(new SlimefunListener(), p);
}
// Heartbeat
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
@ -267,7 +271,6 @@ public class P extends JavaPlugin {
BCauldronRecipe.getConfigRecipes().clear();
BCauldronRecipe.numConfigRecipes = 0;
BConfig.customItems.clear();
BConfig.hasSlimefun = null;
BConfig.hasMMOItems = null;
DistortChat.commands = null;
BConfig.drainItems.clear();

View File

@ -55,7 +55,7 @@ public class BConfig {
public static boolean hasVault; // Vault
public static boolean useCitadel; // CivCraft/DevotedMC Citadel
public static boolean useGMInventories; // GamemodeInventories
public static Boolean hasSlimefun = null; // Slimefun ; Null if not checked
public static boolean hasSlimefun; // Slimefun
public static Boolean hasMMOItems = null; // MMOItems ; Null if not checked
public static boolean hasChestShop;
public static boolean hasShopKeepers;
@ -216,6 +216,7 @@ public class BConfig {
&& Integer.parseInt(plMan.getPlugin("Vault").getDescription().getVersion().split("\\.")[1]) <= 6;
hasChestShop = plMan.isPluginEnabled("ChestShop");
hasShopKeepers = plMan.isPluginEnabled("Shopkeepers");
hasSlimefun = plMan.isPluginEnabled("Slimefun");
// various Settings
DataSave.autosave = config.getInt("autosave", 3);

View File

@ -0,0 +1,56 @@
package com.dre.brewery.integration;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.dre.brewery.Brew;
import com.dre.brewery.P;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.integration.item.SlimefunPluginItem;
import com.dre.brewery.recipe.BCauldronRecipe;
import com.dre.brewery.recipe.RecipeItem;
import com.dre.brewery.utility.LegacyUtil;
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Container;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.Optional;
public class SlimefunListener implements Listener {
/**
* Catch the Slimefun Right Click event, to cancel it if the right click was on a Cauldron.
* This prevents item consumption while adding to the cauldron
*/
@EventHandler
public void onCauldronClickSlimefun(PlayerRightClickEvent event) {
try {
if (event.getClickedBlock().isPresent() && event.getHand() == EquipmentSlot.HAND) {
if (LegacyUtil.isWaterCauldron(event.getClickedBlock().get().getType())) {
Optional<SlimefunItem> slimefunItem = event.getSlimefunItem();
if (slimefunItem.isPresent()) {
for (RecipeItem rItem : BCauldronRecipe.acceptedCustom) {
if (rItem instanceof SlimefunPluginItem) {
if (slimefunItem.get().getId().equalsIgnoreCase(((SlimefunPluginItem) rItem).getItemId())) {
event.cancel();
P.p.playerListener.onPlayerInteract(event.getInteractEvent());
return;
}
}
}
}
}
}
} catch (Throwable e) {
HandlerList.unregisterAll(this);
P.p.errorLog("Slimefun check failed");
e.printStackTrace();
}
}
}

View File

@ -15,9 +15,6 @@ public class SlimefunPluginItem extends PluginItem {
@Override
public boolean matches(ItemStack item) {
if (BConfig.hasSlimefun == null) {
BConfig.hasSlimefun = P.p.getServer().getPluginManager().isPluginEnabled("Slimefun");
}
if (!BConfig.hasSlimefun) return false;
try {