Advertisement
Guest User

Untitled

a guest
Aug 5th, 2011
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. public class ActionMenuPlugin extends JavaPlugin {
  2.  
  3.     public MapActionMenu menu;
  4.     public static final Logger log = Logger.getLogger("Minecraft.ActionMenu");
  5.  
  6.     public void onEnable() {
  7.         getServer().getPluginManager().registerEvent(Event.Type.PLAYER_INTERACT, new ActionMenuPlayerListener(this), Event.Priority.Normal, this);
  8.     // Instantiate the menu.. MapActionMenu requires a JavaPlugin (But not all the ActionMenus do)
  9.         menu = new MapActionMenu(this);
  10.     // Give the menu a header (optional)
  11.         menu.setHeader("Spells");
  12.     // Add a menu item, passing in the text it will display.
  13.         menu.add(new MapActionMenuItem("Fireball") {
  14.             @Override
  15.             public void run() {
  16.         // Shoot a fireball.
  17.                 final Vector direction = getPlayer().getEyeLocation().getDirection().multiply(2);
  18.                 getPlayer().getWorld().spawn(getPlayer().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Fireball.class);
  19.             }
  20.         });
  21.         menu.add(new MapActionMenuItem("Ice Breath") {
  22.             @Override
  23.             public void run() {
  24.         // note: this doesn't actually do anything! :3
  25.             }
  26.         });
  27.         menu.add(new MapActionMenuItem("Blink") {
  28.             @Override
  29.             public void run() {
  30.         // note: this doesn't actually do anything! :3
  31.             }
  32.         });
  33.         log.info(this + " enabled.");
  34.     }
  35.  
  36.     public void onDisable() {
  37.         log.info(this + " disabled.");
  38.     }
  39. }
  40.  
  41. public class ActionMenuPlayerListener extends PlayerListener {
  42.  
  43.     ActionMenuPlugin plugin;
  44.  
  45.     public ActionMenuPlayerListener(ActionMenuPlugin plugin) {
  46.         this.plugin = plugin;
  47.     }
  48.  
  49.     public void onPlayerInteract(PlayerInteractEvent event) {
  50.         if (event.getPlayer().getItemInHand().getType() != Material.MAP) return;
  51.     // On right click with map, cycle the menu selection.
  52.         if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  53.             plugin.menu.cycleMenu();
  54.             plugin.menu.showMenu(event.getPlayer());
  55.         }
  56.     // On left click with map, perform the menu selection
  57.     else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
  58.             plugin.menu.doSelectedMenuItem(event.getPlayer());
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement