@@ -198,45 +198,52 @@ public void update() {
198
198
// Prevent inventory double clicks from stealing items from the menu
199
199
if (ce instanceof ClickInventoryEvent .Double ) ce .setCancelled (true );
200
200
201
- if (ce .getSlot ().isPresent ()) {
202
- Integer slot = ce .getSlot ().get ().getInventoryProperty (SlotIndex .class ).get ().getValue ();
203
- if (slot == null ) slot = -1 ;
204
- if (slot < 9 * this .rows ) {
205
- ce .setCancelled (true );
206
-
207
- this .getOnClick ().accept (ce );
208
-
209
- MenuItem item = getItem (slot );
210
- if (item == null ) item = dummyItem ;
211
-
212
- if (ce instanceof ClickInventoryEvent .Double ) {
213
- this .getOnDouble ().accept ((ClickInventoryEvent .Double ) ce );
214
- item .getOnDouble ().accept ((ClickInventoryEvent .Double ) ce );
215
- } else if (ce instanceof ClickInventoryEvent .Shift .Primary ) {
216
- this .getOnShiftPrimary ().accept ((ClickInventoryEvent .Shift .Primary ) ce );
217
- item .getOnShiftPrimary ().accept ((ClickInventoryEvent .Shift .Primary ) ce );
218
- } else if (ce instanceof ClickInventoryEvent .Shift .Secondary ) {
219
- this .getOnShiftSecondary ().accept ((ClickInventoryEvent .Shift .Secondary ) ce );
220
- item .getOnShiftSecondary ().accept ((ClickInventoryEvent .Shift .Secondary ) ce );
221
- } else if (ce instanceof ClickInventoryEvent .Primary ) {
222
- this .getOnPrimary ().accept ((ClickInventoryEvent .Primary ) ce );
223
- item .getOnPrimary ().accept ((ClickInventoryEvent .Primary ) ce );
224
- } else if (ce instanceof ClickInventoryEvent .Middle ) {
225
- this .getOnMiddle ().accept ((ClickInventoryEvent .Middle ) ce );
226
- item .getOnMiddle ().accept ((ClickInventoryEvent .Middle ) ce );
227
- } else if (ce instanceof ClickInventoryEvent .Secondary ) {
228
- this .getOnSecondary ().accept ((ClickInventoryEvent .Secondary ) ce );
229
- item .getOnSecondary ().accept ((ClickInventoryEvent .Secondary ) ce );
230
- } else if (ce instanceof ClickInventoryEvent .Drop .Full ) {
231
- this .getOnDropAll ().accept ((ClickInventoryEvent .Drop .Full ) ce );
232
- item .getOnDropAll ().accept ((ClickInventoryEvent .Drop .Full ) ce );
233
- } else if (ce instanceof ClickInventoryEvent .Drop ) {
234
- this .getOnDrop ().accept ((ClickInventoryEvent .Drop .Single ) ce );
235
- item .getOnDrop ().accept ((ClickInventoryEvent .Drop .Single ) ce );
236
- } else if (ce instanceof ClickInventoryEvent .NumberPress ) {
237
- this .getOnNumber ().accept ((ClickInventoryEvent .NumberPress ) ce );
238
- item .getOnNumber ().accept ((ClickInventoryEvent .NumberPress ) ce );
239
- }
201
+ // Prevent dragging items from placing items inside the menu
202
+ if (ce instanceof ClickInventoryEvent .Drag ) ce .setCancelled (true );
203
+
204
+ // Prevent weird things from happening when sponge do not send the slot in the event
205
+ if (!ce .getSlot ().isPresent ()) {
206
+ ce .setCancelled (true );
207
+ return ;
208
+ }
209
+
210
+ Integer slot = ce .getSlot ().get ().getInventoryProperty (SlotIndex .class ).get ().getValue ();
211
+ if (slot == null ) slot = -1 ;
212
+ if (slot < 9 * this .rows ) {
213
+ ce .setCancelled (true );
214
+
215
+ this .getOnClick ().accept (ce );
216
+
217
+ MenuItem item = getItem (slot );
218
+ if (item == null ) item = dummyItem ;
219
+
220
+ if (ce instanceof ClickInventoryEvent .Double ) {
221
+ this .getOnDouble ().accept ((ClickInventoryEvent .Double ) ce );
222
+ item .getOnDouble ().accept ((ClickInventoryEvent .Double ) ce );
223
+ } else if (ce instanceof ClickInventoryEvent .Shift .Primary ) {
224
+ this .getOnShiftPrimary ().accept ((ClickInventoryEvent .Shift .Primary ) ce );
225
+ item .getOnShiftPrimary ().accept ((ClickInventoryEvent .Shift .Primary ) ce );
226
+ } else if (ce instanceof ClickInventoryEvent .Shift .Secondary ) {
227
+ this .getOnShiftSecondary ().accept ((ClickInventoryEvent .Shift .Secondary ) ce );
228
+ item .getOnShiftSecondary ().accept ((ClickInventoryEvent .Shift .Secondary ) ce );
229
+ } else if (ce instanceof ClickInventoryEvent .Primary ) {
230
+ this .getOnPrimary ().accept ((ClickInventoryEvent .Primary ) ce );
231
+ item .getOnPrimary ().accept ((ClickInventoryEvent .Primary ) ce );
232
+ } else if (ce instanceof ClickInventoryEvent .Middle ) {
233
+ this .getOnMiddle ().accept ((ClickInventoryEvent .Middle ) ce );
234
+ item .getOnMiddle ().accept ((ClickInventoryEvent .Middle ) ce );
235
+ } else if (ce instanceof ClickInventoryEvent .Secondary ) {
236
+ this .getOnSecondary ().accept ((ClickInventoryEvent .Secondary ) ce );
237
+ item .getOnSecondary ().accept ((ClickInventoryEvent .Secondary ) ce );
238
+ } else if (ce instanceof ClickInventoryEvent .Drop .Full ) {
239
+ this .getOnDropAll ().accept ((ClickInventoryEvent .Drop .Full ) ce );
240
+ item .getOnDropAll ().accept ((ClickInventoryEvent .Drop .Full ) ce );
241
+ } else if (ce instanceof ClickInventoryEvent .Drop ) {
242
+ this .getOnDrop ().accept ((ClickInventoryEvent .Drop .Single ) ce );
243
+ item .getOnDrop ().accept ((ClickInventoryEvent .Drop .Single ) ce );
244
+ } else if (ce instanceof ClickInventoryEvent .NumberPress ) {
245
+ this .getOnNumber ().accept ((ClickInventoryEvent .NumberPress ) ce );
246
+ item .getOnNumber ().accept ((ClickInventoryEvent .NumberPress ) ce );
240
247
}
241
248
}
242
249
})
0 commit comments