From ace92c8f5973e4343e35a95dcccb497bcfadcf1a Mon Sep 17 00:00:00 2001 From: ramidzkh Date: Sat, 18 Feb 2023 20:23:29 +1100 Subject: [PATCH] Validate instanceof ManaKey (#36) --- src/main/java/appbot/ae2/ManaExternalStorageStrategy.java | 8 ++++++++ src/main/java/appbot/ae2/ManaStorageExportStrategy.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/appbot/ae2/ManaExternalStorageStrategy.java b/src/main/java/appbot/ae2/ManaExternalStorageStrategy.java index 1b61aa4..b8db939 100644 --- a/src/main/java/appbot/ae2/ManaExternalStorageStrategy.java +++ b/src/main/java/appbot/ae2/ManaExternalStorageStrategy.java @@ -47,6 +47,10 @@ private record ManaStorageAdapter(ManaReceiver receiver, Runnable injectOrExtrac @Override public long insert(AEKey what, long amount, Actionable mode, IActionSource source) { + if (!(what instanceof ManaKey)) { + return 0; + } + var inserted = (int) Math.min(amount, ManaHelper.getCapacity(receiver) - receiver.getCurrentMana()); @@ -60,6 +64,10 @@ public long insert(AEKey what, long amount, Actionable mode, IActionSource sourc @Override public long extract(AEKey what, long amount, Actionable mode, IActionSource source) { + if (!(what instanceof ManaKey)) { + return 0; + } + var extracted = (int) Math.min(amount, receiver.getCurrentMana()); if (extracted > 0 && mode == Actionable.MODULATE) { diff --git a/src/main/java/appbot/ae2/ManaStorageExportStrategy.java b/src/main/java/appbot/ae2/ManaStorageExportStrategy.java index 21d9288..06a6829 100644 --- a/src/main/java/appbot/ae2/ManaStorageExportStrategy.java +++ b/src/main/java/appbot/ae2/ManaStorageExportStrategy.java @@ -29,6 +29,10 @@ public ManaStorageExportStrategy(ServerLevel level, @Override public long transfer(StackTransferContext context, AEKey what, long amount) { + if (!(what instanceof ManaKey)) { + return 0; + } + var receiver = apiCache.find(fromSide); if (receiver == null) { @@ -50,6 +54,10 @@ public long transfer(StackTransferContext context, AEKey what, long amount) { @Override public long push(AEKey what, long amount, Actionable mode) { + if (!(what instanceof ManaKey)) { + return 0; + } + var receiver = apiCache.find(fromSide); if (receiver == null) {