Skip to content

Commit

Permalink
feat(api): added simplified overloaded methods to RenamesManager and …
Browse files Browse the repository at this point in the history
…FavoritesManager
  • Loading branch information
HiWord9 committed Nov 14, 2024
1 parent 53f242c commit 00163e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ public void loadSavedFavorites() {
renames.putAll(favoritesFileManager.getAllSavedFavorites());
}

public void addRename(Item item, String name) {
addRename(item, new AbstractRename(name, item));
}

public void addRename(Item item, AbstractRename rename) {
super.addRename(item, rename);
taskQueue.addTask(() -> favoritesFileManager.setFavorites(getRenames(item), item));
}

public void removeRename(Item item, String name) {
removeRename(item, new AbstractRename(name, item));
}

public void removeRename(Item item, AbstractRename rename) {
super.removeRename(item, rename);
taskQueue.addTask(() -> favoritesFileManager.setFavorites(getRenames(item), item));
Expand All @@ -48,4 +56,8 @@ public boolean isFavorite(Item item, String name) {
}
return false;
}

public boolean isFavorite(Item item, AbstractRename rename) {
return getRenames(item).contains(rename);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ public void addOrRemoveFavorite(boolean add) {
public void addOrRemoveFavorite(boolean add, String favoriteName, Item item) {
if (item != Items.AIR) {
if (add) {
favoritesManager.addRename(item, new AbstractRename(favoriteName, item));
favoritesManager.addRename(item, favoriteName);
} else {
favoritesManager.removeRename(item, new AbstractRename(favoriteName, item));
favoritesManager.removeRename(item, favoriteName);
}
updateAfterFavorite();
}
Expand Down Expand Up @@ -339,7 +339,7 @@ private void favoriteInGui(boolean favorite, AbstractRename rename, boolean asCu
if (favorite) {
for (Item i : rename.getItems()) {
if (favoritesManager.isFavorite(i, rename.getName())) {
favoritesManager.removeRename(i, new AbstractRename(rename.getName(), i));
favoritesManager.removeRename(i, rename.getName());
}
}
updateAfterFavorite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ public interface RenamesManager {

ArrayList<AbstractRename> getRenames(Item item);

default void addRename(AbstractRename rename) {
addRename(rename.getItem(), rename);
}

void addRename(Item item, AbstractRename rename);

default void removeRename(AbstractRename rename) {
removeRename(rename.getItem(), rename);
}

void removeRename(Item item, AbstractRename rename);

void clearRenames();
Expand Down

0 comments on commit 00163e0

Please sign in to comment.