-
-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a CPS variable to Meteor Starscript #4057
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). | ||
* Copyright (c) Meteor Development. | ||
*/ | ||
|
||
package meteordevelopment.meteorclient.utils.misc; | ||
|
||
import meteordevelopment.meteorclient.MeteorClient; | ||
import meteordevelopment.meteorclient.events.world.TickEvent; | ||
import meteordevelopment.meteorclient.utils.PreInit; | ||
import meteordevelopment.orbit.EventHandler; | ||
import meteordevelopment.starscript.value.Value; | ||
|
||
|
||
public class CPSUtils { | ||
private static int clicks; | ||
private static int cps; | ||
private static int secondsClicking; | ||
private static long lastTime; | ||
|
||
@PreInit | ||
public static void init() { | ||
MeteorClient.EVENT_BUS.subscribe(CPSUtils.class); | ||
} | ||
|
||
@EventHandler | ||
private static void onTick(TickEvent.Pre event) { | ||
CPSUtils.cpsChecker(); | ||
} | ||
|
||
|
||
public static void onAttack() { | ||
CPSUtils.clicks++; | ||
CPSUtils.cps++; | ||
} | ||
|
||
public static Value getCpsAverage() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should return an |
||
return Value.number((int)( | ||
clicks / (secondsClicking == 0 ? 1 : (float)secondsClicking) | ||
)); | ||
} | ||
|
||
public static void cpsChecker() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesnt need to be a method, and a public one at that. You can just move the body to the |
||
long currentTime = System.currentTimeMillis(); | ||
// Run every second | ||
if (currentTime - CPSUtils.lastTime >= 1000) { | ||
if (CPSUtils.cps == 0) { | ||
CPSUtils.clicks = 0; | ||
CPSUtils.secondsClicking = 0; | ||
} else { | ||
CPSUtils.lastTime = currentTime; | ||
CPSUtils.secondsClicking++; | ||
CPSUtils.cps = 0; | ||
} | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why. If you want to cleanup then move the 2 constants to the top of the file and with a new line to separate constants and static variables.