Skip to content

Commit

Permalink
Fix Slimefun item eat at cauldron
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0wStorm committed Jul 10, 2022
1 parent f08e3ca commit db42889
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/com/dre/brewery/P.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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.*;
Expand Down Expand Up @@ -161,6 +162,9 @@ public void onEnable() {
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);
Expand Down Expand Up @@ -267,7 +271,6 @@ private void clearConfigData() {
BCauldronRecipe.getConfigRecipes().clear();
BCauldronRecipe.numConfigRecipes = 0;
BConfig.customItems.clear();
BConfig.hasSlimefun = null;
BConfig.hasMMOItems = null;
DistortChat.commands = null;
BConfig.drainItems.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/com/dre/brewery/filedata/BConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -216,6 +216,7 @@ public static void readConfig(FileConfiguration config) {
&& 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);
Expand Down
56 changes: 56 additions & 0 deletions src/com/dre/brewery/integration/SlimefunListener.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
3 changes: 0 additions & 3 deletions src/com/dre/brewery/integration/item/SlimefunPluginItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit db42889

Please sign in to comment.