Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ActionMenuPlugin extends JavaPlugin {
- public MapActionMenu menu;
- public static final Logger log = Logger.getLogger("Minecraft.ActionMenu");
- public void onEnable() {
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_INTERACT, new ActionMenuPlayerListener(this), Event.Priority.Normal, this);
- // Instantiate the menu.. MapActionMenu requires a JavaPlugin (But not all the ActionMenus do)
- menu = new MapActionMenu(this);
- // Give the menu a header (optional)
- menu.setHeader("Spells");
- // Add a menu item, passing in the text it will display.
- menu.add(new MapActionMenuItem("Fireball") {
- @Override
- public void run() {
- // Shoot a fireball.
- final Vector direction = getPlayer().getEyeLocation().getDirection().multiply(2);
- getPlayer().getWorld().spawn(getPlayer().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Fireball.class);
- }
- });
- menu.add(new MapActionMenuItem("Ice Breath") {
- @Override
- public void run() {
- // note: this doesn't actually do anything! :3
- }
- });
- menu.add(new MapActionMenuItem("Blink") {
- @Override
- public void run() {
- // note: this doesn't actually do anything! :3
- }
- });
- log.info(this + " enabled.");
- }
- public void onDisable() {
- log.info(this + " disabled.");
- }
- }
- public class ActionMenuPlayerListener extends PlayerListener {
- ActionMenuPlugin plugin;
- public ActionMenuPlayerListener(ActionMenuPlugin plugin) {
- this.plugin = plugin;
- }
- public void onPlayerInteract(PlayerInteractEvent event) {
- if (event.getPlayer().getItemInHand().getType() != Material.MAP) return;
- // On right click with map, cycle the menu selection.
- if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
- plugin.menu.cycleMenu();
- plugin.menu.showMenu(event.getPlayer());
- }
- // On left click with map, perform the menu selection
- else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
- plugin.menu.doSelectedMenuItem(event.getPlayer());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement