add background features, add ServerSafeguard with do-not-join list
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m30s

This commit is contained in:
Daniella / Tove 2024-06-25 14:44:39 +02:00
parent 26f81ed71e
commit ad9b8c18eb
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
10 changed files with 109 additions and 29 deletions

View file

@ -32,7 +32,7 @@ public class BaseBand {
public static final SecureRandom RANDOM = new SecureRandom();
public static String buildString = LoadHandler.data.getBoolean("release-branch") ? "Broadway" : "Dark Side of the Moon";
public static final EventBus EVENT_BUS = new EventBus(LOGGER::error);
public static final EventBus EVENT_BUS = new EventBus(Throwable::printStackTrace);
public static final RemoteEventBus REMOTE_EVENT_BUS = new RemoteEventBus();
public static final StaticEventHandler STATIC_EVENT_HANDLER = new StaticEventHandler();
public static boolean enabled = true;
@ -94,8 +94,6 @@ public class BaseBand {
LOGGER.info("Unloaded.");
}, "Async Config Updater").start();
LOGGER.info("Initialized.");
}

View file

@ -34,6 +34,9 @@ public class DevStub implements IFMLLoadingPlugin {
LoadHandler.data.set("branch", "[dev]");
LoadHandler.data.set("username", "root");
LoadHandler.data.set("disabled-modules", new TCNArray());
TCNArray array = new TCNArray();
LoadHandler.data.set("do-not-join", array);
array.add("mc.hypixel.net");
}
@Override

View file

@ -1,6 +1,7 @@
package de.com.baseband.client;
import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.background.ServerSafeguard;
import de.com.baseband.client.feature.commands.*;
import de.com.baseband.client.feature.modules.chat.*;
import de.com.baseband.client.feature.modules.client.*;
@ -82,6 +83,8 @@ public class Setup {
new Trigger(),
new Trust(),
new Velocity(),
new ServerSafeguard(),
};

View file

@ -7,35 +7,44 @@ import de.com.baseband.client.util.adapt.FieldFinder;
import de.com.baseband.client.util.adapt.Marker;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
public enum Category {
COMMAND("Commands", Command.class),
CHAT("Chat", Chat.class),
COMBAT("Combat", Combat.class),
MOVEMENT("Movement", Movement.class),
RENDER("Render", Render.class),
INGAME("World & Interactions", Ingame.class),
CLIENT("Client", ClientCategory.class)
CLIENT("Client", ClientCategory.class),
COMMAND("Commands", Command.class, false),
BACKGROUND("Background", Background.class, false),
;
Category(String name, Class<? extends Annotation> annotationClass) {
this.name = name;
Category(String categoryName, Class<? extends Annotation> annotationClass) {
this(categoryName, annotationClass, true);
}
Category(String categoryName, Class<? extends Annotation> annotationClass, boolean mayDisplay) {
this.categoryName = categoryName;
this.annotationClass = annotationClass;
this.mayDisplay = mayDisplay;
try {
handle = Configuration.register("Category/" + name.toLowerCase().replace(' ', '_'));
ConfigHandle handle = Configuration.register("Category/" + categoryName.toLowerCase().replace(' ', '_'));
Configuration.registerUpdater(handle.linkWith(this, FieldFinder.findMarked(getClass(), 1)).name("x"));
Configuration.registerUpdater(handle.linkWith(this, FieldFinder.findMarked(getClass(), 2)).name("y"));
Configuration.registerUpdater(handle.linkWith(this, FieldFinder.findMarked(getClass(), 3)).name("show"));
} catch (IllegalAccessException e) {
} catch (Exception e) {
//:skollerolley:
throw new RuntimeException(e);
}
}
private final Class<? extends Annotation> annotationClass;
@SuppressWarnings("FieldCanBeLocal")
private final ConfigHandle handle;
public final String categoryName;
public final Class<? extends Annotation> annotationClass;
public final boolean mayDisplay;
@Marker(1)
public int x;
@Marker(2)
@ -43,21 +52,23 @@ public enum Category {
@Marker(3)
public boolean show;
public final String name;
public String toString() {
return name;
return categoryName;
}
public static Category fromName(String s) {
for (Category c : values()) {
if(c.name.equals(s))
if(c.categoryName.equals(s))
return c;
}
return null;
}
public Class<? extends Annotation> getAnnotationClass() {
return annotationClass;
public static Category fromCategory(AnnotatedElement element) {
for (Category c : values()) {
if(element.getDeclaredAnnotation(c.annotationClass) != null)
return c;
}
throw new IllegalStateException();
}
}

View file

@ -3,7 +3,6 @@ package de.com.baseband.client.feature;
import com.mojang.realmsclient.gui.ChatFormatting;
import de.com.baseband.client.BaseBand;
import de.com.baseband.client.event.KeyManager;
import de.com.baseband.client.feature.category.Command;
import de.com.baseband.client.feature.modules.render.HUD;
import de.com.baseband.client.gui.lib.component.*;
import de.com.baseband.client.gui.lib.component.Button;
@ -44,7 +43,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
public Category category;
@Marker(M_ENABLED)
public boolean enabled = defaultEnable();
public boolean enabled;
public String meta = null;
@ -59,7 +58,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
// feature methods
protected boolean defaultEnable() {
return this.getClass().isAnnotationPresent(Command.class);
return !category.mayDisplay;
}
public void onDisable() {
@ -87,7 +86,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
protected void setup() {}
public boolean displayOnClickGUI() {
return !this.getClass().isAnnotationPresent(Command.class);
return category.mayDisplay;
}
// own methods
@ -111,12 +110,10 @@ public abstract class Feature extends ToggleButton implements SetCommand {
public final void register(Minecraft mc) {
this.mc = mc;
this.text = toString();
category = Category.fromCategory(getClass());
enabled = defaultEnable();
for (Category c : Category.values()) {
if(getClass().getDeclaredAnnotation(c.getAnnotationClass()) != null)
category = c;
}
this.text = toString();
subComponents.clear();

View file

@ -0,0 +1,50 @@
package de.com.baseband.client.feature.background;
import de.com.baseband.client.event.events.PacketEvent;
import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.category.Background;
import de.com.baseband.prod.LoadHandler;
import de.tudbut.parsing.TCNArray;
import net.minecraft.client.gui.GuiDisconnected;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.handshake.client.C00Handshake;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@Background
public class ServerSafeguard extends Feature {
public int showError = 0;
public void onServerJoin(PacketEvent.Send event) {
if(event.getPacket() instanceof C00Handshake && ((C00Handshake) event.getPacket()).getRequestedState() == EnumConnectionState.LOGIN) {
if(LoadHandler.data.getArray("do-not-join").contains(mc.getCurrentServerData().serverIP.split(":")[0])) {
showError = 2;
event.setCancelled(true);
}
}
}
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if(showError > 0) {
showError--;
if(showError == 0) {
mc.displayGuiScreen(new GuiDisconnected(new GuiMainMenu(), "connect.failed", new TextComponentString("!! This server is on the do-not-join list !!\n - BaseBand")));
}
}
}
@Override
public boolean canExist() {
LoadHandler.data.setIfAbsent("do-not-join", new TCNArray());
return !LoadHandler.data.getArray("do-not-join").isEmpty();
}
@Override
public String toString() {
return "ServerSafeguard";
}
}

View file

@ -0,0 +1,11 @@
package de.com.baseband.client.feature.category;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Background {
}

View file

@ -66,7 +66,7 @@ public class Help extends Feature {
Chat.print("§c§l" + Setup.Name + " help system: Modules");
Chat.print("§7Below you find a list of modules in the client:");
for (Category category : Category.values()) {
if(category == Category.COMMAND)
if(!category.mayDisplay)
continue;
Chat.print(" §lCategory " + category);
for (Feature feature : Features.features) {

View file

@ -64,7 +64,7 @@ public class GuiRewrite extends GuiScreen {
Category category;
if ((category = map.get(feature.category)) == null) {
map.set(feature.category, category = new Category() {{
text = feature.category.name;
text = feature.category.categoryName;
}});
if ((feature.category.x | feature.category.y) != 0) {
category.location = new Point(feature.category.x, feature.category.y);

View file

@ -176,6 +176,13 @@ public class Loader implements Util {
x1.data.set("config-file", file);
x1.focus();
})
.option("Server blocklist", x1 -> {
String list = JOptionPane.showInputDialog("Server blocklist (comma separated, no ports):");
if(list == null || list.isEmpty())
x1.data.set("do-not-join", new TCNArray());
else
x1.data.set("do-not-join", new TCNArray(Arrays.asList(list.split(", *"))));
})
.option("Back", ClientBoot::back);
})
.option("ClientBoot options", x -> x.newScreen()