Skip to content

Commit

Permalink
Begin stubbing menu api
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 17, 2020
1 parent 02f0812 commit 22cf824
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/ClickHandler.java
@@ -0,0 +1,20 @@
package net.citizensnpcs.api.gui;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.bukkit.event.inventory.ClickType;

/**
* Defines a click handler.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface ClickHandler {
/**
* An optional filter for specific click types.
*/
ClickType[] value() default {};
}
6 changes: 6 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/InventoryMenu.java
@@ -0,0 +1,6 @@
package net.citizensnpcs.api.gui;

public class InventoryMenu {
public InventoryMenu(Menu menu) {
}
}
@@ -0,0 +1,6 @@
package net.citizensnpcs.api.gui;

public class InventoryMenuPattern {
public InventoryMenuPattern(InventoryMenu menu, MenuPattern pattern) {
}
}
6 changes: 6 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/InventoryMenuSlot.java
@@ -0,0 +1,6 @@
package net.citizensnpcs.api.gui;

public class InventoryMenuSlot {
public InventoryMenuSlot(InventoryMenu menu, MenuSlot slot) {
}
}
@@ -0,0 +1,6 @@
package net.citizensnpcs.api.gui;

public class InventoryMenuTransition {
public InventoryMenuTransition(InventoryMenu menu, MenuTransition transition) {
}
}
31 changes: 31 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/Menu.java
@@ -0,0 +1,31 @@
package net.citizensnpcs.api.gui;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.bukkit.event.inventory.ClickType;

/**
* Defines a GUI inventory menu. Can be linked to a {@link InventoryMenuPattern} or simply at the class level.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface Menu {

/**
* The dimensions of the menu, if supported.
*/
int[] dimensions() default { 3, 3 };

/**
* The click types to allow by default. Empty = all allowed
*/
ClickType[] filter() default {};

/**
* The menu title.
*/
String title() default "";
}
41 changes: 41 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/MenuContext.java
@@ -0,0 +1,41 @@
package net.citizensnpcs.api.gui;

import java.util.Map;

import org.bukkit.entity.Entity;
import org.bukkit.inventory.Inventory;

import com.google.common.collect.Maps;

/**
* A context class passed into the constructor of a {@link Menu} instance.
*/
public class MenuContext {
private final Map<String, Object> data = Maps.newHashMap();
private final Inventory inventory;
private final InventoryMenu parent;
private final Entity user;

public MenuContext(InventoryMenu parent, Inventory inventory, Entity user, Map<String, Object> data) {
this.inventory = inventory;
this.parent = parent;
this.user = user;
this.data.putAll(data);
}

public Map<String, Object> data() {
return data;
}

public Inventory getInventory() {
return inventory;
}

public InventoryMenu getParent() {
return parent;
}

public Entity getUser() {
return user;
}
}
30 changes: 30 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/MenuPattern.java
@@ -0,0 +1,30 @@
package net.citizensnpcs.api.gui;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.bukkit.Material;

/**
* Defines a pattern of slots. Can be linked to a {@link InventoryMenuPattern} or simply at the class level.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD })
public @interface MenuPattern {
/**
* The amount of the itemstacks to display.
*/
int amount() default 1;

/**
* The material to display (defaults to AIR).
*/
Material material() default Material.AIR;

/**
* The pattern string. 0 = AIR
*/
String value();
}
36 changes: 36 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/MenuSlot.java
@@ -0,0 +1,36 @@
package net.citizensnpcs.api.gui;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.bukkit.Material;
import org.bukkit.event.inventory.ClickType;

/**
* Defines a slot with a certain item. Can be linked to a {@link InventoryMenuSlot} or simply at the class level.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD })
public @interface MenuSlot {
/**
* The amount of the itemstack to display.
*/
int amount() default 1;

/**
* Whitelist the allowed clicktypes (empty = all allowed).
*/
ClickType[] filter() default {};

/**
* The material to display (defaults to AIR). For extra customisation see {@link InventoryMenuSlot}.
*/
Material material() default Material.AIR;

/**
* The position of the slot within the inventory.
*/
int[] value() default { 0, 0 };
}
42 changes: 42 additions & 0 deletions src/main/java/net/citizensnpcs/api/gui/MenuTransition.java
@@ -0,0 +1,42 @@
package net.citizensnpcs.api.gui;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.bukkit.Material;
import org.bukkit.event.inventory.ClickType;

/**
* Defines a menu transition to a new sub-menu. Can be linked to a {@link InventoryMenuTransition} or simply at the
* class level.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD })
public @interface MenuTransition {
/**
* The amount of the itemstack to display.
*/
int amount() default 1;

/**
* Whitelist the allowed clicktypes for transition (empty = all allowed).
*/
ClickType[] filter() default {};

/**
* The material to display (defaults to AIR). For extra customisation see {@link InventoryMenuTransition}.
*/
Material material() default Material.AIR;

/**
* The position of the slot within the inventory.
*/
int[] pos() default { 0, 0 };

/**
* The next sub-menu class to transition to.
*/
Class<?> value();
}

0 comments on commit 22cf824

Please sign in to comment.