Skip to content

Commit db42889

Browse files
committed
Fix Slimefun item eat at cauldron
1 parent f08e3ca commit db42889

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Brewery
22
version: 3.1
33
main: com.dre.brewery.P
4-
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny, BlockLocker]
4+
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny, BlockLocker, Slimefun]
55
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]
66
api-version: 1.13
77
commands:

src/com/dre/brewery/P.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.dre.brewery.integration.ChestShopListener;
3333
import com.dre.brewery.integration.IntegrationListener;
3434
import com.dre.brewery.integration.ShopKeepersListener;
35+
import com.dre.brewery.integration.SlimefunListener;
3536
import com.dre.brewery.integration.barrel.BlocklockerBarrel;
3637
import com.dre.brewery.integration.barrel.LogBlockBarrel;
3738
import com.dre.brewery.listeners.*;
@@ -161,6 +162,9 @@ public void onEnable() {
161162
if (BConfig.hasShopKeepers) {
162163
p.getServer().getPluginManager().registerEvents(new ShopKeepersListener(), p);
163164
}
165+
if (BConfig.hasSlimefun && use1_14) {
166+
p.getServer().getPluginManager().registerEvents(new SlimefunListener(), p);
167+
}
164168

165169
// Heartbeat
166170
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
@@ -267,7 +271,6 @@ private void clearConfigData() {
267271
BCauldronRecipe.getConfigRecipes().clear();
268272
BCauldronRecipe.numConfigRecipes = 0;
269273
BConfig.customItems.clear();
270-
BConfig.hasSlimefun = null;
271274
BConfig.hasMMOItems = null;
272275
DistortChat.commands = null;
273276
BConfig.drainItems.clear();

src/com/dre/brewery/filedata/BConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class BConfig {
5555
public static boolean hasVault; // Vault
5656
public static boolean useCitadel; // CivCraft/DevotedMC Citadel
5757
public static boolean useGMInventories; // GamemodeInventories
58-
public static Boolean hasSlimefun = null; // Slimefun ; Null if not checked
58+
public static boolean hasSlimefun; // Slimefun
5959
public static Boolean hasMMOItems = null; // MMOItems ; Null if not checked
6060
public static boolean hasChestShop;
6161
public static boolean hasShopKeepers;
@@ -216,6 +216,7 @@ public static void readConfig(FileConfiguration config) {
216216
&& Integer.parseInt(plMan.getPlugin("Vault").getDescription().getVersion().split("\\.")[1]) <= 6;
217217
hasChestShop = plMan.isPluginEnabled("ChestShop");
218218
hasShopKeepers = plMan.isPluginEnabled("Shopkeepers");
219+
hasSlimefun = plMan.isPluginEnabled("Slimefun");
219220

220221
// various Settings
221222
DataSave.autosave = config.getInt("autosave", 3);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.dre.brewery.integration;
2+
3+
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
4+
import com.dre.brewery.Brew;
5+
import com.dre.brewery.P;
6+
import com.dre.brewery.filedata.BConfig;
7+
import com.dre.brewery.integration.item.SlimefunPluginItem;
8+
import com.dre.brewery.recipe.BCauldronRecipe;
9+
import com.dre.brewery.recipe.RecipeItem;
10+
import com.dre.brewery.utility.LegacyUtil;
11+
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
12+
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
13+
import org.bukkit.Material;
14+
import org.bukkit.block.Block;
15+
import org.bukkit.block.Container;
16+
import org.bukkit.event.EventHandler;
17+
import org.bukkit.event.HandlerList;
18+
import org.bukkit.event.Listener;
19+
import org.bukkit.event.block.Action;
20+
import org.bukkit.inventory.EquipmentSlot;
21+
import org.bukkit.inventory.ItemStack;
22+
23+
import java.util.Optional;
24+
25+
public class SlimefunListener implements Listener {
26+
27+
/**
28+
* Catch the Slimefun Right Click event, to cancel it if the right click was on a Cauldron.
29+
* This prevents item consumption while adding to the cauldron
30+
*/
31+
@EventHandler
32+
public void onCauldronClickSlimefun(PlayerRightClickEvent event) {
33+
try {
34+
if (event.getClickedBlock().isPresent() && event.getHand() == EquipmentSlot.HAND) {
35+
if (LegacyUtil.isWaterCauldron(event.getClickedBlock().get().getType())) {
36+
Optional<SlimefunItem> slimefunItem = event.getSlimefunItem();
37+
if (slimefunItem.isPresent()) {
38+
for (RecipeItem rItem : BCauldronRecipe.acceptedCustom) {
39+
if (rItem instanceof SlimefunPluginItem) {
40+
if (slimefunItem.get().getId().equalsIgnoreCase(((SlimefunPluginItem) rItem).getItemId())) {
41+
event.cancel();
42+
P.p.playerListener.onPlayerInteract(event.getInteractEvent());
43+
return;
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
} catch (Throwable e) {
51+
HandlerList.unregisterAll(this);
52+
P.p.errorLog("Slimefun check failed");
53+
e.printStackTrace();
54+
}
55+
}
56+
}

src/com/dre/brewery/integration/item/SlimefunPluginItem.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public class SlimefunPluginItem extends PluginItem {
1515

1616
@Override
1717
public boolean matches(ItemStack item) {
18-
if (BConfig.hasSlimefun == null) {
19-
BConfig.hasSlimefun = P.p.getServer().getPluginManager().isPluginEnabled("Slimefun");
20-
}
2118
if (!BConfig.hasSlimefun) return false;
2219

2320
try {

0 commit comments

Comments
 (0)