Skip to content

Commit

Permalink
Validate instanceof ManaKey (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh authored Feb 18, 2023
1 parent ea6f346 commit ace92c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/appbot/ae2/ManaExternalStorageStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/appbot/ae2/ManaStorageExportStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit ace92c8

Please sign in to comment.