fix some hovers, fix ping

This commit is contained in:
Daniella / Tove 2024-05-27 10:43:11 +02:00
parent d36fba4b5b
commit b00c5e78bf
4 changed files with 12 additions and 20 deletions

View file

@ -35,7 +35,7 @@ public class StringButton extends Button {
@Override @Override
public Component hover(String hover) { public Component hover(String hover) {
underlyingHover = hover; underlyingHover = hover == null ? "" : hover;
return super.hover(hover); return super.hover(hover);
} }
} }

View file

@ -146,10 +146,10 @@ public abstract class Feature extends ToggleButton implements SetCommand {
} }
} }
if (f.getType() == String.class) { if (f.getType() == String.class) {
subComponents.add(new StringButton(config.value(), settings, config.value()).gate(gate)); subComponents.add(new StringButton(config.value(), settings, config.value()).gate(gate).hover(description));
} }
if (f.getType() == KeyBind.class) { if (f.getType() == KeyBind.class) {
subComponents.add(new KeyButton(config.value(), settings, config.value()).gate(gate)); subComponents.add(new KeyButton(config.value(), settings, config.value()).gate(gate).hover(description));
try { try {
BaseBand.registerKeyBind((KeyBind) f.get(this)); BaseBand.registerKeyBind((KeyBind) f.get(this));
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {

View file

@ -8,14 +8,10 @@ import com.baseband.client.module.Feature;
import com.baseband.client.module.category.World; import com.baseband.client.module.category.World;
import net.minecraft.network.play.client.CPacketKeepAlive; import net.minecraft.network.play.client.CPacketKeepAlive;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Queue;
@World @World
public class Ping extends Feature { public class Ping extends Feature {
Queue<PacketHolder> queue = new LinkedList<>(); PacketHolder holder = null;
long total = 0; long total = 0;
@ -32,10 +28,10 @@ public class Ping extends Feature {
@Override @Override
public void onTick() { public void onTick() {
text = "Ping "+ (enabled ? " §7[" + queue.size() +"/" + total + "]" : ""); text = "Ping" + (enabled ? " §7[" + seconds + "/" + total + "]" : "");
if (mc.player != null && !queue.isEmpty() && queue.peek().passed()) { if (mc.player != null && holder != null && holder.passed()) {
total++; total++;
mc.player.connection.sendPacket(Objects.requireNonNull(queue.poll()).getPacket()); mc.player.connection.sendPacket(holder.packet);
} }
} }
@ -46,26 +42,22 @@ public class Ping extends Feature {
public void onPacket(PacketEvent.Send e) { public void onPacket(PacketEvent.Send e) {
if (e.getPacket() instanceof CPacketKeepAlive) { if (e.getPacket() instanceof CPacketKeepAlive) {
queue.add(new PacketHolder((CPacketKeepAlive) e.getPacket(), System.currentTimeMillis())); holder = new PacketHolder((CPacketKeepAlive) e.getPacket(), System.currentTimeMillis());
e.setCancelled(true); e.setCancelled(true);
} }
} }
public class PacketHolder { public class PacketHolder {
long time; long time;
CPacketKeepAlive cPacketKeepAlive; CPacketKeepAlive packet;
public PacketHolder(CPacketKeepAlive cPacketKeepAlive, long time) { public PacketHolder(CPacketKeepAlive packet, long time) {
this.time = time; this.time = time;
this.cPacketKeepAlive = cPacketKeepAlive; this.packet = packet;
} }
public boolean passed() { public boolean passed() {
return (System.currentTimeMillis() - time) >= (seconds * 1000L); return (System.currentTimeMillis() - time) >= (seconds * 1000L);
} }
public CPacketKeepAlive getPacket() {
return cPacketKeepAlive;
}
} }
} }

View file

@ -44,7 +44,7 @@ public class TextSplitter {
String[] split = text.split("\n"); String[] split = text.split("\n");
StringBuilder codes = new StringBuilder(); StringBuilder codes = new StringBuilder();
for (int i = 0; i < split.length; i++) { for (int i = 0; i < split.length; i++) {
fontRenderer.drawString(codes + split[i], (float) x, (float) y + fontRenderer.FONT_HEIGHT * i, color, shadow); fontRenderer.drawString(codes + split[i] + "§r", (float) x, (float) y + fontRenderer.FONT_HEIGHT * i, color, shadow);
codes.append(split[i].replaceAll("[^§]*?(§\\w)?[^§]*", "$1")); codes.append(split[i].replaceAll("[^§]*?(§\\w)?[^§]*", "$1"));
} }
} }