Skip to content

Commit 43c3b39

Browse files
authored
Merge pull request #2693 from BentoBoxWorld/2690_glow_berry_api_change
Use reflection for backward api compatibility. Fixes #2690
2 parents b7e22a7 + 1eee6e3 commit 43c3b39

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package world.bentobox.bentobox.listeners.flags.protection;
22

3+
import java.lang.reflect.Method;
4+
35
import org.bukkit.Location;
46
import org.bukkit.Material;
57
import org.bukkit.Tag;
@@ -75,6 +77,20 @@ public void onBreakHanging(final HangingBreakByEntityEvent e) {
7577
}
7678
}
7779

80+
private static final Method BERRIES_CHECK;
81+
82+
static {
83+
Method m = null;
84+
try {
85+
m = CaveVinesPlant.class.getMethod("hasBerries");
86+
} catch (NoSuchMethodException ignored) {
87+
try {
88+
m = CaveVinesPlant.class.getMethod("isBerries");
89+
} catch (NoSuchMethodException ignored2) {
90+
}
91+
}
92+
BERRIES_CHECK = m;
93+
}
7894
/**
7995
* Handles breaking objects
8096
*
@@ -94,8 +110,14 @@ public void onPlayerInteract(final PlayerInteractEvent e)
94110
Material clickedType = e.getClickedBlock().getType();
95111
switch (clickedType) {
96112
case CAVE_VINES, CAVE_VINES_PLANT -> {
97-
if (((CaveVinesPlant) e.getClickedBlock().getBlockData()).hasBerries()) {
98-
this.checkIsland(e, p, l, Flags.HARVEST);
113+
try {
114+
boolean hasBerries = (Boolean) BERRIES_CHECK
115+
.invoke((CaveVinesPlant) e.getClickedBlock().getBlockData());
116+
if (hasBerries) {
117+
this.checkIsland(e, p, l, Flags.HARVEST);
118+
}
119+
} catch (ReflectiveOperationException ex) {
120+
getPlugin().logStacktrace(ex);
99121
}
100122
}
101123
case SWEET_BERRY_BUSH -> this.checkIsland(e, p, l, Flags.HARVEST);

0 commit comments

Comments
 (0)