Skip to content

Commit

Permalink
modules aliases, invalid name logging, deprecate getCategoryByHash
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog committed Oct 11, 2024
1 parent 06c5422 commit 3b91a12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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

0 comments on commit 3b91a12

Please sign in to comment.