Skip to content

Commit

Permalink
remove clear & clearAll in ArgumentProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Oct 29, 2023
1 parent 8e83db2 commit 6a1aed6
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,4 @@ public interface ArgumentProcessor extends MenuElement {
default Pair<Optional<List<String>>, String[]> tabComplete(UUID uuid, String[] args) {
return Pair.of(Optional.empty(), args);
}

/**
* Called when the display of the menu is removed
*
* @param uuid the UUID of the player
*/
default void onClear(UUID uuid) {
// EMPTY
}

/**
* Called when the menu is cleared
*/
default void onClearAll() {
// EMPTY
}
}
14 changes: 0 additions & 14 deletions src/main/java/me/hsgamer/bettergui/argument/ArgumentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ public List<String> handleTabComplete(UUID uuid, String[] args) {
return tabComplete(uuid, args).getKey().orElse(Collections.emptyList());
}

@Override
public void onClear(UUID uuid) {
for (ArgumentProcessor processor : processorMap.values()) {
processor.onClear(uuid);
}
}

@Override
public void onClearAll() {
for (ArgumentProcessor processor : processorMap.values()) {
processor.onClearAll();
}
}

@Override
public Menu getMenu() {
return menu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class StoreArgumentProcessor implements ArgumentProcessor {
private final ArgumentProcessorBuilder.Input input;
private final Map<UUID, String> map = new HashMap<>();
private final int length;
private final String defaultValue;
private final boolean clearOnClose;
private final boolean takeRemaining;
private final ActionApplier actionApplier;
private final List<String> suggestions;
Expand All @@ -37,15 +35,6 @@ public StoreArgumentProcessor(ArgumentProcessorBuilder.Input input) {
.map(BigDecimal::intValue)
.orElse(1);

this.defaultValue = Optional.ofNullable(options.get("default"))
.map(Objects::toString)
.orElse("");

this.clearOnClose = Optional.ofNullable(options.get("clear-on-close"))
.map(String::valueOf)
.map(Boolean::parseBoolean)
.orElse(false);

this.takeRemaining = Optional.ofNullable(options.get("take-remaining"))
.map(String::valueOf)
.map(Boolean::parseBoolean)
Expand Down Expand Up @@ -88,7 +77,7 @@ public Optional<String[]> process(UUID uuid, String[] args) {

@Override
public String getValue(String query, UUID uuid) {
return map.getOrDefault(uuid, defaultValue);
return map.getOrDefault(uuid, "");
}

@Override
Expand All @@ -114,18 +103,6 @@ public Pair<Optional<List<String>>, String[]> tabComplete(UUID uuid, String[] ar
return Pair.of(Optional.of(list), new String[0]);
}

@Override
public void onClear(UUID uuid) {
if (clearOnClose) {
map.remove(uuid);
}
}

@Override
public void onClearAll() {
map.clear();
}

@Override
public Menu getMenu() {
return input.menu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ protected BaseInventoryMenu(Config config) {

@Override
protected void onRemoveDisplay(@NotNull BukkitGUIDisplay display) {
argumentHandler.onClear(display.getUniqueId());
Optional.ofNullable(updateTasks.remove(display.getUniqueId())).ifPresent(Task::cancel);
super.onRemoveDisplay(display);
}
Expand Down Expand Up @@ -276,7 +275,6 @@ public void close(Player player) {
@Override
public void closeAll() {
guiHolder.stop();
argumentHandler.onClearAll();
}

protected abstract B createButtonMap();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/me/hsgamer/bettergui/menu/PredicateMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public boolean create(Player player, String[] args, boolean bypass) {
break;
}
}
argumentHandler.onClear(uuid);
return isSuccessful;
}

Expand All @@ -122,7 +121,7 @@ public void close(Player player) {

@Override
public void closeAll() {
argumentHandler.onClearAll();
// EMPTY
}

private static final class MenuProcess {
Expand Down

0 comments on commit 6a1aed6

Please sign in to comment.