> inputConsume
this.selector = selector;
register();
selector.open();
+ clickSoundReference = "Builder.Button-Click";
}
private void register() {
@@ -44,14 +53,44 @@ public void setInput(T input) {
inputConsumer.accept(this);
}
+ /**
+ * Sets the input from the specified slot in the {@link VariableSelector}.
+ *
+ * This method will only succeed if the provided selector matches the one associated with this listener.
+ * If no value is available at the specified slot, or if setting the new input fails for any reason,
+ * the method returns false
.
+ *
+ * @param selector the selector from which to retrieve the input
+ * @param slot the index of the slot containing the desired input
+ * @return true
if the input was successfully set, or false
otherwise
+ */
@SuppressWarnings("unchecked")
- public void setInputFromSlot(VariableSelector> selector, int slot) {
+ public boolean setInputFromSlot(VariableSelector> selector, int slot) {
if (!getSelector().equals(this.selector))
- return;
- setInput((T) selector.getValue(slot));
+ return false;
+ @Nullable T input = (T) selector.getValue(slot);
+ if (input == null)
+ return false;
+ setInput(input);
+ return true;
}
public VariableSelector getSelector() {
return selector;
}
+
+ @NotNull
+ public String getClickSoundReference() {
+ return clickSoundReference;
+ }
+
+ public void setClickSoundReference(@NotNull String clickSoundReference) {
+ Objects.requireNonNull(clickSoundReference, "'blobSoundReference' cannot be null");
+ this.clickSoundReference = clickSoundReference;
+ }
+
+ @NotNull
+ public BlobSound getClickSound() {
+ return Objects.requireNonNull(BlobLibSoundAPI.getInstance().getSound(clickSoundReference), "Not a valid BlobSound: " + clickSoundReference);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java b/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java
index 95e4de1..aec3417 100644
--- a/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java
+++ b/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java
@@ -43,32 +43,30 @@ public void onEditorClick(InventoryClickEvent event) {
event.setCancelled(true);
int slot = event.getRawSlot();
BlobSound clickSound = BlobLibSoundAPI.getInstance().getSound("Builder.Button-Click");
- if (slot > blobEditor.valuesSize() - 1) {
- if (blobEditor.isNextPageButton(slot)) {
- blobEditor.nextPage();
- return;
- }
- if (blobEditor.isPreviousPageButton(slot)) {
- blobEditor.previousPage();
- return;
- }
- if (blobEditor.isAddElementButton(slot)) {
- clickSound.handle(player);
- blobEditor.addElement(player);
- return;
- }
- if (blobEditor.isRemoveElementButton(slot)) {
- clickSound.handle(player);
- blobEditor.removeElement(player);
- return;
- }
- if (blobEditor.isReturnButton(slot)) {
- blobEditor.processReturn();
- return;
- }
+ if (blobEditor.isNextPageButton(slot)) {
+ blobEditor.nextPage();
return;
}
- listener.setInputFromSlot(blobEditor, event.getRawSlot());
+ if (blobEditor.isPreviousPageButton(slot)) {
+ blobEditor.previousPage();
+ return;
+ }
+ if (blobEditor.isAddElementButton(slot)) {
+ clickSound.handle(player);
+ blobEditor.addElement(player);
+ return;
+ }
+ if (blobEditor.isRemoveElementButton(slot)) {
+ clickSound.handle(player);
+ blobEditor.removeElement(player);
+ return;
+ }
+ if (blobEditor.isReturnButton(slot)) {
+ blobEditor.processReturn();
+ return;
+ }
+ if (!listener.setInputFromSlot(blobEditor, event.getRawSlot()))
+ return;
clickSound.handle(player);
}
@@ -79,27 +77,29 @@ public void onSelectorClick(InventoryClickEvent e) {
if (variableSelector == null)
return;
SelectorListener> listener = main.getSelectorManager().getSelectorListener(player);
+ BlobSound clickSound = BlobLibSoundAPI.getInstance().getSound("Builder.Button-Click");
if (listener == null)
return;
e.setCancelled(true);
int slot = e.getRawSlot();
- if (slot > variableSelector.valuesSize() - 1) {
- if (variableSelector.isNextPageButton(slot)) {
- variableSelector.nextPage();
- return;
- }
- if (variableSelector.isPreviousPageButton(slot)) {
- variableSelector.previousPage();
- return;
- }
- if (variableSelector.isReturnButton(slot)) {
- variableSelector.processReturn();
- return;
- }
+ if (variableSelector.isNextPageButton(slot)) {
+ variableSelector.nextPage();
+ clickSound.handle(player);
+ return;
+ }
+ if (variableSelector.isPreviousPageButton(slot)) {
+ variableSelector.previousPage();
+ clickSound.handle(player);
return;
}
- listener.setInputFromSlot(variableSelector, slot);
- BlobLibSoundAPI.getInstance().getSound("Builder.Button-Click").handle(player);
+ if (variableSelector.isReturnButton(slot)) {
+ variableSelector.processReturn();
+ clickSound.handle(player);
+ return;
+ }
+ if (!listener.setInputFromSlot(variableSelector, slot))
+ return;
+ listener.getClickSound().handle(player);
}
@EventHandler