Skip to content
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

modules aliases, invalid name logging, deprecate getCategoryByHash #4946

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
import java.util.Objects;

public abstract class Module implements ISerializable<Module>, Comparable<Module> {
protected final MinecraftClient mc;
protected static final MinecraftClient mc = MinecraftClient.getInstance();

public final Category category;
public final String name;
public final String title;
public final String description;
public final String[] aliases;
public final Color color;

public final Settings settings = new Settings();
Expand All @@ -46,12 +47,13 @@ public abstract class Module implements ISerializable<Module>, Comparable<Module
public boolean chatFeedback = true;
public boolean favorite = false;

public Module(Category category, String name, String description) {
this.mc = MinecraftClient.getInstance();
public Module(Category category, String name, String description, String... aliases) {
if (name.contains(" ")) MeteorClient.LOG.warn("Module '{}' contains invalid characters in its name making it incompatible with Meteor Client commands.", name);
this.category = category;
this.name = name;
this.title = Utils.nameToTitle(name);
this.description = description;
this.aliases = aliases;
this.color = Color.fromHsv(Utils.random(0.0, 360.0), 0.35, 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static Iterable<Category> loopCategories() {
return CATEGORIES;
}

@Deprecated(forRemoval = true)
public static Category getCategoryByHash(int hash) {
for (Category category : CATEGORIES) {
if (category.hashCode() == hash) return category;
Expand Down Expand Up @@ -174,6 +175,10 @@ public Set<Module> searchTitles(String text) {

for (Module module : this.moduleInstances.values()) {
int score = Utils.searchLevenshteinDefault(module.title, text, false);
for (String alias : module.aliases) {
int aliasScore = Utils.searchLevenshteinDefault(alias, text, false);
if (aliasScore < score) score = aliasScore;
}
modules.put(module, modules.getOrDefault(module, 0) + score);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class BlockESP extends Module {
private Dimension lastDimension;

public BlockESP() {
super(Categories.Render, "block-esp", "Renders specified blocks through walls.");
super(Categories.Render, "block-esp", "Renders specified blocks through walls.", "search");

RainbowColors.register(this::onTickRainbow);
}
Expand Down
Loading