Java Code Examples for org.bukkit.event.Listener

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project craftbook, under directory /common/src/main/java/com/sk89q/craftbook/bukkit/.

Source file: MechanicListenerAdapter.java

  22 
vote

/** 
 * Register events.
 * @param manager
 */
public void register(MechanicManager manager){
  PluginManager pluginManager=plugin.getServer().getPluginManager();
  Listener playerListener=new MechanicPlayerListener(manager,plugin);
  Listener blockListener=new MechanicBlockListener(manager,plugin);
  Listener worldListener=new MechanicWorldListener(manager,plugin);
  pluginManager.registerEvents(playerListener,plugin);
  pluginManager.registerEvents(blockListener,plugin);
  pluginManager.registerEvents(worldListener,plugin);
}
 

Example 2

From project Citizens, under directory /src/guard/net/citizensnpcs/guards/types/.

Source file: Bodyguard.java

  21 
vote

public Bodyguard(){
  NPCTypeManager.registerEvents(new Listener(){
    @EventHandler public void onPlayerLogin(    PlayerLoginEvent event){
      Player player=event.getPlayer();
      String owner=player.getName();
      if (!toRespawn.containsKey(owner))       return;
      NPCManager.register(toRespawn.get(owner).getUID(),owner,NPCCreateReason.RESPAWN);
      CitizensManager.getNPC(toRespawn.get(owner).getUID()).teleport(player.getLocation());
      toRespawn.remove(owner);
    }
  }
);
}
 

Example 3

From project mcore, under directory /src/com/massivecraft/mcore4/util/.

Source file: EventUtil.java

  21 
vote

public static void callEventAfter(Event event,Listener listener,EventPriority priority){
  HandlerList handlers=event.getHandlers();
  RegisteredListener[] listeners=handlers.getRegisteredListeners().clone();
  boolean run=false;
  for (  RegisteredListener registration : listeners) {
    if (run) {
      fireEventRegistration(event,registration);
    }
 else {
      try {
        EventPriority thisPriority=(EventPriority)fieldRegisteredListenerDotPriority.get(registration);
        Listener thisListener=(Listener)fieldRegisteredListenerDotListener.get(registration);
        if (thisListener == listener && thisPriority == priority)         run=true;
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
  }
}
 

Example 4

From project AntiCheat, under directory /src/main/java/net/h31ix/anticheat/.

Source file: Anticheat.java

  19 
vote

private void setupEvents(){
  for (  Listener listener : eventList) {
    getServer().getPluginManager().registerEvents(listener,this);
    if (verbose) {
      getLogger().log(Level.INFO,"Registered events for ".concat(listener.toString().split("@")[0].split(".anticheat.")[1]));
    }
  }
}
 

Example 5

From project Bukkit-Plugin-Utilties, under directory /src/main/java/de/xzise/.

Source file: MinecraftUtil.java

  19 
vote

public static void registerMultipleListeners(final Plugin plugin,final Listener... listeners){
  final PluginManager manager=plugin.getServer().getPluginManager();
  for (  Listener listener : listeners) {
    manager.registerEvents(listener,plugin);
  }
}
 

Example 6

From project regionbook, under directory /src/main/java/com/sk89q/regionbook/bukkit/.

Source file: RegionBookPlugin.java

  19 
vote

/** 
 * Register an event, but not failing if the event is not implemented.
 * @param typeName
 * @param priority
 * @param listener
 */
public void registerEvent(String typeName,Event.Priority priority,Listener listener){
  try {
    Event.Type type=Event.Type.valueOf(typeName);
    PluginManager pm=getServer().getPluginManager();
    pm.registerEvent(type,listener,priority,this);
  }
 catch (  IllegalArgumentException e) {
    logger.info("RegionBook: Unable to register missing event type " + typeName);
  }
}
 

Example 7

From project routes, under directory /src/main/java/eu/tomylobo/abstraction/platform/bukkit/event/.

Source file: BukkitEventTransposer.java

  19 
vote

@Override public void execute(Listener me,org.bukkit.event.Event backend) throws EventException {
  if (me != this)   throw new EventException("ListenerExecutor got passed a different listener!");
  try {
    bukkitEvent.invoke(listener,handler,backend);
  }
 catch (  IllegalAccessException e) {
    throw new EventException(e,"Could not access handler");
  }
catch (  InvocationTargetException e) {
    throw new EventException(e.getCause(),"Exception caught from handler");
  }
}
 

Example 8

From project routes, under directory /src/main/java/eu/tomylobo/abstraction/platform/bukkit/event/.

Source file: BukkitSimpleEventExecutor.java

  19 
vote

@Override public void execute(Listener me,org.bukkit.event.Event backend) throws EventException {
  if (me != this)   throw new EventException("ListenerExecutor got passed a different listener!");
  try {
    handler.invoke(listener,backend);
  }
 catch (  IllegalAccessException e) {
    throw new EventException(e,"Could not access handler");
  }
catch (  InvocationTargetException e) {
    throw new EventException(e.getCause(),"Exception caught from handler");
  }
}