Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new API; disable shift click in inventory GUIs
- Loading branch information
Showing
6 changed files
with
68 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.citizensnpcs.api; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.InventoryView; | ||
|
||
public interface InventoryHelper { | ||
void updateInventoryTitle(Player player, InventoryView view, String newTitle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,57 @@ | ||
package net.citizensnpcs.api.gui; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
import com.google.common.base.Function; | ||
|
||
@Menu(type = InventoryType.ANVIL) | ||
public class InputMenu extends InventoryMenuPage { | ||
private final Function<String, Boolean> callback; | ||
private MenuContext ctx; | ||
private final Supplier<String> initialValue; | ||
@MenuSlot(slot = { 0, 0 }, material = Material.PAPER, amount = 1) | ||
private InventoryMenuSlot slot; | ||
|
||
public InputMenu(Supplier<String> initialValue, Function<String, Boolean> callback) { | ||
this.initialValue = initialValue; | ||
this.callback = callback; | ||
} | ||
|
||
@ClickHandler(slot = { 0, 0 }) | ||
public void cancel(InventoryMenuSlot slot, CitizensInventoryClickEvent evt) { | ||
evt.setCancelled(true); | ||
ctx.getMenu().transitionBack(); | ||
} | ||
|
||
@Override | ||
public void initialise(MenuContext ctx) { | ||
this.ctx = ctx; | ||
ItemStack item = slot.getCurrentItem(); | ||
ItemMeta meta = item.getItemMeta(); | ||
meta.setDisplayName(initialValue.get()); | ||
item.setItemMeta(meta); | ||
} | ||
|
||
@ClickHandler(slot = { 0, 1 }) | ||
@ClickHandler(slot = { 0, 2 }) | ||
public void save(InventoryMenuSlot slot, CitizensInventoryClickEvent evt) { | ||
evt.setCancelled(true); | ||
if (callback.apply(slot.getCurrentItem().getItemMeta().getDisplayName())) { | ||
ctx.getMenu().transitionBack(); | ||
} else { | ||
evt.setCancelled(true); | ||
} | ||
} | ||
|
||
public static InputMenu setter(Supplier<String> initialValue, Consumer<String> callback) { | ||
return new InputMenu(initialValue, (s) -> { | ||
callback.accept(s); | ||
return true; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/main/java/net/citizensnpcs/api/gui/ModalMenuInput.java
This file was deleted.
Oops, something went wrong.