Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ dependencies {
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'

implementation 'org.apache.commons:commons-lang3:3.12.0'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.toofifty.goaltracker.models;

import com.toofifty.goaltracker.models.task.Task;

import java.lang.reflect.Method;
import com.toofifty.goaltracker.models.enums.Status;

/**
* Action for toggling a task's completion state.
* Uses reflection to avoid a hard dependency on the Status enum.
* Directly depends on Status enum for compliance with RuneLite rules.
*/
public final class ToggleCompleteAction implements ActionHistory.Action
{
Expand All @@ -24,34 +23,12 @@ public ToggleCompleteAction(Task task, boolean oldValue, boolean newValue)
@Override
public void undo()
{
setStatusByName(oldValue ? "COMPLETED" : "NOT_STARTED");
task.setStatus(oldValue ? Status.COMPLETED : Status.NOT_STARTED);
}

@Override
public void redo()
{
setStatusByName(newValue ? "COMPLETED" : "NOT_STARTED");
}

/**
* Set task status by enum name without importing the enum type.
* This works whether Status is a nested enum or a top-level type.
*/
private void setStatusByName(String name)
{
try
{
Object current = task.getStatus();
Class<?> enumClass = current.getClass();
@SuppressWarnings({"unchecked","rawtypes"})
Enum newStatus = Enum.valueOf((Class<Enum>) enumClass, name);

Method m = task.getClass().getMethod("setStatus", enumClass);
m.invoke(task, newStatus);
}
catch (Exception ignored)
{
// If we can't reflectively set it, ignore rather than crash.
}
task.setStatus(newValue ? Status.COMPLETED : Status.NOT_STARTED);
}
}
Loading