add PacketCounter, move ping to Client category
All checks were successful
/ Build BaseBand (push) Successful in 2m37s
All checks were successful
/ Build BaseBand (push) Successful in 2m37s
This commit is contained in:
parent
acdb41a1ea
commit
8b326ad8c9
5 changed files with 97 additions and 7 deletions
|
@ -70,6 +70,7 @@ public class Setup {
|
|||
new NoRender(),
|
||||
new NoSlowDown(),
|
||||
new Notifier(),
|
||||
new PacketCounter(),
|
||||
new Ping(),
|
||||
new PlayerLog(),
|
||||
new PlayerSelector(),
|
||||
|
|
|
@ -56,7 +56,7 @@ public class EventBus {
|
|||
|
||||
for (SubscriberMethod subscriberMethod : subscriberMethods) {
|
||||
Class<?>[] parameterTypes = subscriberMethod.method.getParameterTypes();
|
||||
if(parameterTypes.length == 1 && eventType.isAssignableFrom(parameterTypes[0])) {
|
||||
if(parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(eventType)) {
|
||||
subscriberMethod.invoke(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package de.com.baseband.client.feature.modules.client;
|
||||
|
||||
import de.com.baseband.client.event.events.PacketEvent;
|
||||
import de.com.baseband.client.feature.Feature;
|
||||
import de.com.baseband.client.feature.category.ClientCategory;
|
||||
import de.com.baseband.client.feature.category.Experimental;
|
||||
import de.com.baseband.client.registry.annotation.Config;
|
||||
import de.com.baseband.client.registry.annotation.Description;
|
||||
import de.com.baseband.client.registry.annotation.Trigger;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
@ClientCategory
|
||||
@Description("Shows how many packets per second are being sent/received.")
|
||||
public class PacketCounter extends Feature {
|
||||
|
||||
long totUp = 0, totDown = 0;
|
||||
Queue<PacketTimestamp> up = new LinkedList<>(), down = new LinkedList<>();
|
||||
|
||||
@Config("Abbreviate")
|
||||
@Description("Abbreviates numbers with ...K and ...M once they get too large.")
|
||||
public boolean abbrev;
|
||||
|
||||
@Trigger("Reset")
|
||||
public void reset() {
|
||||
totUp = totDown = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEveryTick() {
|
||||
meta = abbreviate(totUp) + "↑/↓" + abbreviate(totDown) + "] [" +
|
||||
(up.isEmpty() ? "-" : "§c" + up.size()) + "↑§7/" +
|
||||
(down.isEmpty() ? "↓-" : "§c↓" + down.size()) + "§7";
|
||||
}
|
||||
|
||||
private String abbreviate(long n) {
|
||||
if(n < 10_000L) {
|
||||
return String.valueOf(n);
|
||||
}
|
||||
if(n < 10_000_000L) {
|
||||
return n / 1000L + "K";
|
||||
}
|
||||
return n / 1_000_000L + "M";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
processQueue(up);
|
||||
processQueue(down);
|
||||
}
|
||||
|
||||
private void processQueue(Queue<PacketTimestamp> queue) {
|
||||
while (!queue.isEmpty()) {
|
||||
if(queue.peek().passed())
|
||||
queue.remove();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PacketCounter";
|
||||
}
|
||||
|
||||
public void onPacket(PacketEvent event) {
|
||||
if(event instanceof PacketEvent.Send) {
|
||||
totUp ++;
|
||||
up.add(new PacketTimestamp());
|
||||
}
|
||||
if(event instanceof PacketEvent.Receive) {
|
||||
totDown ++;
|
||||
down.add(new PacketTimestamp());
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketTimestamp {
|
||||
long time;
|
||||
|
||||
public PacketTimestamp() {
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean passed() {
|
||||
return (System.currentTimeMillis() - time) >= 1000;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package de.com.baseband.client.feature.modules.ingame;
|
||||
package de.com.baseband.client.feature.modules.client;
|
||||
|
||||
import de.com.baseband.client.BaseBand;
|
||||
import de.com.baseband.client.event.events.PrePacketEvent;
|
||||
import de.com.baseband.client.feature.Feature;
|
||||
import de.com.baseband.client.feature.category.Ingame;
|
||||
import de.com.baseband.client.feature.category.ClientCategory;
|
||||
import de.com.baseband.client.registry.annotation.Config;
|
||||
import de.com.baseband.client.registry.annotation.Description;
|
||||
import de.com.baseband.client.registry.annotation.Range;
|
||||
|
@ -16,7 +16,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
@Ingame
|
||||
@ClientCategory
|
||||
public class Ping extends Feature {
|
||||
|
||||
Queue<PacketHolder> holderSend = new LinkedList<>();
|
||||
|
@ -33,7 +33,7 @@ public class Ping extends Feature {
|
|||
@Description("How many milliseconds to add to your ping.\n" +
|
||||
"§lWarning§r: You might get timed out on high settings (Time-out happens at 15 seconds including real ping).")
|
||||
@Range("0..5000")
|
||||
public int milliseconds;
|
||||
public int milliseconds = 300;
|
||||
|
||||
Packet<?> allowRecv = null;
|
||||
Packet<?> allowSend = null;
|
||||
|
@ -47,7 +47,7 @@ public class Ping extends Feature {
|
|||
public void onEveryTick() {
|
||||
meta = milliseconds + "ms: " +
|
||||
(holderSend.isEmpty() ? "-" : "§c" + holderSend.size()) + "↑§7/" +
|
||||
(holderRecv.isEmpty() ? "-" : "§c" + holderRecv.size()) + "↓§7";
|
||||
(holderRecv.isEmpty() ? "↓-" : "§c↓" + holderRecv.size()) + "§7";
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
|
@ -4,7 +4,7 @@ import de.com.baseband.client.BaseBand;
|
|||
import de.com.baseband.client.Setup;
|
||||
import de.com.baseband.client.feature.Features;
|
||||
import de.com.baseband.client.feature.modules.client.Client;
|
||||
import de.com.baseband.client.feature.modules.ingame.Ping;
|
||||
import de.com.baseband.client.feature.modules.client.Ping;
|
||||
import de.com.baseband.client.util.adapt.ServerPing;
|
||||
import de.tudbut.tools.Lock;
|
||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||
|
|
Loading…
Add table
Reference in a new issue