1
1
package world .bentobox .bentobox .listeners .flags .protection ;
2
2
3
+ import java .lang .reflect .Method ;
4
+
3
5
import org .bukkit .Location ;
4
6
import org .bukkit .Material ;
5
7
import org .bukkit .Tag ;
@@ -75,6 +77,20 @@ public void onBreakHanging(final HangingBreakByEntityEvent e) {
75
77
}
76
78
}
77
79
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
+ }
78
94
/**
79
95
* Handles breaking objects
80
96
*
@@ -94,8 +110,14 @@ public void onPlayerInteract(final PlayerInteractEvent e)
94
110
Material clickedType = e .getClickedBlock ().getType ();
95
111
switch (clickedType ) {
96
112
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 );
99
121
}
100
122
}
101
123
case SWEET_BERRY_BUSH -> this .checkIsland (e , p , l , Flags .HARVEST );
0 commit comments