mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
[Fix] Resource Leak Risk in AutoClicker
[Fix] Thread Safety Issue in MathUtil [Fix] Potential Performance Issue in MathUtil
This commit is contained in:
1 parent
d97d943104
commit
deea0fb1f8
2 files changed
+21
-10
No files matched your search
@@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AutoClicker extends Module {
|
||||
|
||||
private static final ScheduledExecutorService CLICK_EXECUTOR =
|
||||
private final ScheduledExecutorService CLICK_EXECUTOR =
|
||||
Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "OrangeX-ClickThread"));
|
||||
|
||||
private final Random random = new Random();
|
||||
@@ -110,4 +110,9 @@ public class AutoClicker extends Module {
|
||||
lastClickTime = now;
|
||||
delayMs = generateDelayMs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisable() {
|
||||
CLICK_EXECUTOR.shutdownNow();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,27 @@
|
||||
package cn.xiaozhou233.orangex.utils;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class MathUtil {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final int MAX_ATTEMPTS = 8;
|
||||
|
||||
public static double generateNoise(double min, double max) {
|
||||
double mean = (max + min) / 2;
|
||||
double stdDev = Math.max(1.0, (max - min) / 3); // stdDev >= 1
|
||||
double mean = (min + max) / 2.0;
|
||||
double range = max - min;
|
||||
double stdDev = Math.max(1.0, range / 3.0);
|
||||
|
||||
double value;
|
||||
do {
|
||||
value = random.nextGaussian() * stdDev + mean;
|
||||
} while (value < min || value > max);
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
|
||||
return value;
|
||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||
double value = random.nextGaussian() * stdDev + mean;
|
||||
if (value >= min && value <= max) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// fallback: clamp gaussian
|
||||
return clamp(random.nextGaussian() * stdDev + mean, min, max);
|
||||
}
|
||||
|
||||
public static double clamp(double value, double min, double max) {
|
||||
|
||||
Reference in new issue
Block a user