Exemplo n.º 1
0
 /**
  * Calls an event with the given details.<br>
  * This method only synchronizes when the event is not asynchronous.
  *
  * @param event Event details
  */
 public void callEvent(Event event) {
   if (event.isAsynchronous()) {
     if (Thread.holdsLock(this)) {
       throw new IllegalStateException(
           event.getEventName()
               + " cannot be triggered asynchronously from inside synchronized code.");
     }
     if (server.isPrimaryThread()) {
       throw new IllegalStateException(
           event.getEventName()
               + " cannot be triggered asynchronously from primary server thread.");
     }
     fireEvent(event);
   } else {
     synchronized (this) {
       fireEvent(event);
     }
   }
 }
Exemplo n.º 2
0
  private void fireEvent(Event event) {
    HandlerList handlers = event.getHandlers();
    RegisteredListener[] listeners = handlers.getRegisteredListeners();

    for (RegisteredListener registration : listeners) {
      if (!registration.getPlugin().isEnabled()) {
        continue;
      }

      try {
        registration.callEvent(event);
      } catch (AuthorNagException ex) {
        Plugin plugin = registration.getPlugin();

        if (plugin.isNaggable()) {
          plugin.setNaggable(false);

          server
              .getLogger()
              .log(
                  Level.SEVERE,
                  String.format(
                      "Nag author(s): '%s' of '%s' about the following: %s",
                      plugin.getDescription().getAuthors(),
                      plugin.getDescription().getFullName(),
                      ex.getMessage()));
        }
      } catch (Throwable ex) {
        server
            .getLogger()
            .log(
                Level.SEVERE,
                "Could not pass event "
                    + event.getEventName()
                    + " to "
                    + registration.getPlugin().getDescription().getFullName(),
                ex);
      }
    }
  }
Exemplo n.º 3
0
  public void main(Event e) {

    if (Util.config("bumpintherail", null).getBoolean("active")) {

      if (e.getEventName().equalsIgnoreCase("VehicleMoveEvent")) {
        VehicleMoveEvent event = (VehicleMoveEvent) e;

        if (event.getVehicle().getPassenger() instanceof Player) {
          Player player = (Player) event.getVehicle().getPassenger();

          if (!Util.config("bumpintherail", null)
              .getList("skipworld")
              .contains(player.getWorld().getName())) {
            if (event.getTo().getBlock().getType().equals(Material.RAILS)
                && event.getVehicle().getType().equals(EntityType.MINECART)) {
              if (!player.hasPermission("ijmh.immunity.rail")) {
                Rails rail = (Rails) event.getTo().getBlock().getState().getData();
                if (rail.isCurve()
                    && Util.pctChance(
                        Util.config("bumpintherail", null).getInt("chance"),
                        Util.config("bumpintherail", null).getInt("chancemod"))) {
                  event.getVehicle().eject();
                  Vector vector =
                      event.getTo().getDirection().midpoint(event.getFrom().getDirection());
                  player.setVelocity(
                      new Vector(
                          vector.getX() + Util.config("bumpintherail", null).getInt("distance"),
                          Util.config("bumpintherail", null).getInt("angle"),
                          vector.getZ() + Util.config("bumpintherail", null).getInt("distance")));
                  if (Util.config("bumpintherail", null).getBoolean("message"))
                    player.sendMessage(
                        ChatColor.GOLD + Util.chatColorText(Util.language.getString("lan_18")));
                }
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 4
0
  public static void call(Event event, EventPriority priority) {
    for (RegisteredListener registration : event.getHandlers().getRegisteredListeners(priority)) {
      if (!registration.getPlugin().isEnabled()) {
        continue;
      }

      try {
        registration.callEvent(event);
      } catch (AuthorNagException ex) {
        Plugin plugin = registration.getPlugin();

        if (plugin.isNaggable()) {
          plugin.setNaggable(false);

          Pore.getServer()
              .getLogger()
              .log(
                  Level.SEVERE,
                  String.format(
                      "Nag author(s): '%s' of '%s' about the following: %s",
                      plugin.getDescription().getAuthors(),
                      plugin.getDescription().getFullName(),
                      ex.getMessage()));
        }
      } catch (EventException ex) {
        Pore.getServer()
            .getLogger()
            .log(
                Level.SEVERE,
                "Could not pass event "
                    + event.getEventName()
                    + " to "
                    + registration.getPlugin().getDescription().getFullName(),
                ex);
      }
    }
  }
Exemplo n.º 5
0
 @Override
 public void eventTrigger(Event event) {
   if (event.getEventName().equalsIgnoreCase("playerjoinevent")) {
     eh.onPlayerJoin((PlayerJoinEvent) event);
   }
 }