Java 类org.bukkit.event.Event 实例源码

项目:Crescent    文件:ImpossibleA.java   
@Override
public void call(Event event) {
    final Player player = profile.getPlayer();

    if (event instanceof PlayerMoveEvent) {
        if ((player.isSprinting() || player.isBlocking() || player.isConversing()) && player.isSneaking()) {
            callback(true);
            return;
        }
        callback(false);
    } else if (event instanceof AsyncPlayerChatEvent) {
        if ((player.isBlocking() || player.isSprinting() || player.isSneaking())) {
            callback(true);
            return;
        }
        callback(false);
    }
}
项目:Crescent    文件:AntiDamageA.java   
@Override
public void call(Event event) {
    if (event instanceof EntityDamageEvent) {
        final EntityDamageEvent ede = (EntityDamageEvent) event;
        final DamageCause cause = ede.getCause();

        if (cause == DamageCause.FIRE || cause == DamageCause.CONTACT) {
            final Player player = profile.getPlayer();

            if (cause == DamageCause.FIRE && player.getFoodLevel() < 20) {
                // The AntiFire cheat only works when the hunger bar is
                // full.
                return;
            }

            final double previousHealth = player.getHealth();

            // Check a little later.
            Bukkit.getScheduler().runTaskLater(Crescent.getInstance(), () -> {
                if (player.getHealth() > previousHealth - ede.getDamage()) {
                    callback(true);
                }
            }, 2L);
        }
    }
}
项目:skLib    文件:CondVpnCheck.java   
@Override
public boolean check(Event arg0) {
    @SuppressWarnings("unused")
    Boolean goodip = IpTools.validIP(ip.getSingle(arg0));
    if (!goodip) {
        Skript.error("\"" + ip + "\" is not a valid IPv4 address!");
        return false;
    }
    JSONObject jsonparsed = null;
    try {
        jsonparsed = JsonReader.readJsonFromUrl("http://proxycheck.io/v1/" + ip.getSingle(arg0) + "&vpn=1&asn=0&node=1&time=1&tag=skLib");
    } catch (JSONException | IOException e) {
        e.printStackTrace();
    }
    String jsonvalue = (String) jsonparsed.get("proxy");
    if (jsonvalue.equalsIgnoreCase("yes")) {
        return true;
    }
    return false;
}
项目:NeverLag    文件:EventExecutorInjector.java   
@Override
// 计算调用次数和花费总时间以及花费最多的时间
public void execute(Listener listener, Event e) throws EventException {
    if (e.isAsynchronous()) {
        this.eventExecutor.execute(listener, e);
    } else {
        long startTime = System.nanoTime();
        try {
            this.eventExecutor.execute(listener, e);
        } finally {
            long endTime = System.nanoTime();
            long executeTime = endTime - startTime;
            this.record(e.getEventName(), executeTime);
        }
    }
}
项目:ZentrelaRPG    文件:EtcItem.java   
public static void healWithPotion(int amount, String name, Event event, Player p) {
    if (!(event instanceof PlayerInteractEvent))
        return;
    PlayerInteractEvent e = (PlayerInteractEvent) event;
    if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK))
        return;
    if (lastHealItem.containsKey(p.getName()) && System.currentTimeMillis() - lastHealItem.get(p.getName()) < 500) {
        return;
    }
    lastHealItem.put(p.getName(), System.currentTimeMillis());
    p.getEquipment().setItemInMainHand(new ItemStack(Material.AIR));
    PlayerDataRPG pd = plugin.getPD(p);
    pd.heal(amount, HealType.POTION);
    for (int k = 0; k < p.getInventory().getContents().length; k++) {
        if (ItemManager.isItem(p.getInventory().getItem(k), name)) {
            p.getEquipment().setItemInMainHand(p.getInventory().getItem(k));
            p.getInventory().setItem(k, new ItemStack(Material.AIR));
            break;
        }
    }
    RSound.playSound(p, Sound.ENTITY_GENERIC_DRINK);
}
项目:skript-mirror    文件:ExprJavaCall.java   
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
  Object target = targetArg.getSingle(e);
  if (target == null) {
    return;
  }

  Object[] args = new Object[1];

  switch (mode) {
    case SET:
      args[0] = delta[0];
      break;
    case DELETE:
      args[0] = null;
      break;
  }

  invoke(target, args, getDescriptor(e));
}
项目:BungeeMaster    文件:EffPerformCommandAsPlayer.java   
@Override
protected void execute(Event event) {
    String[] commands = this.commands.getAll(event);
    Object[] senders = this.senders.getAll(event);
    if (commands == null || senders == null) {
        return;
    }
    Arrays.stream(getBungeeMaster().convertObjectsToNamesAndUUIDs(senders))
            .forEach(sender ->
                    Arrays.stream(commands)
                    .filter(Objects::nonNull)
                    .forEach(command -> {
                        if (command.startsWith("/")) {
                            command = command.substring(1);
                        }
                        send(new SendMessageAsPlayerPacket(sender, "/" + command));
                    })
            );
}
项目:skript-mirror    文件:CustomExpression.java   
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
  Trigger trigger = changerHandlers.get(which);
  ExpressionChangeEvent expressionEvent =
      new ExpressionChangeEvent(e, exprs, parseResult, delta, mode);

  if (trigger == null) {
    Skript.error(
        String.format("The custom expression '%s' no longer has a change handler.",
            which.getPattern())
    );
  } else {
    trigger.execute(expressionEvent);
  }
}
项目:skLib    文件:EffectSetVariable.java   
protected void execute(final Event arg0) {
    final Jedis jedis = Main.pool.getResource();
    new BukkitRunnable(){

        public void run() {
            try {
                jedis.set((String)EffectSetVariable.this.key.getSingle(arg0), (String)EffectSetVariable.this.value.getSingle(arg0));
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            jedis.close();
        }
    }.runTaskAsynchronously(Main.plugin);
}
项目:Crescent    文件:AntiGravityA.java   
@Override
public void call(Event event) {
    if (event instanceof PlayerMoveEvent) {
        final PlayerMoveEvent pme = (PlayerMoveEvent) event;

        final Behaviour behaviour = profile.getBehaviour();

        if (!behaviour.isOnGround() && !behaviour.isInLiquid() && !behaviour.isInWeb()) {
            if (behaviour.getMotion().isDescending()) {
                final double difference = Math.abs((behaviour.getMotion()
                        .calculateGravityEffect() /*
                                                     * Expected y difference
                                                     */)
                        - (pme.getTo().getY() - pme.getFrom()
                                .getY()) /* Actual y difference */);
                if (difference > ALLOWED_MAX_GRAVITY_DIFFERENCE && behaviour
                        .getBlocksBelowGround() > 2 /*
                                                     * The player being too
                                                     * close to the ground
                                                     * causes false
                                                     * positives.
                                                     */) {
                    callback(true);
                }
            }
        }
    }
}
项目:skLib    文件:ExprClickedRow.java   
@Override
@Nullable
protected Number[] get(Event e) {
    InventoryType container = ((InventoryClickEvent)e).getClickedInventory().getType();
    if (container != InventoryType.CHEST || container != InventoryType.DISPENSER || container != InventoryType.DROPPER || container != InventoryType.WORKBENCH || container != InventoryType.ENDER_CHEST || container != InventoryType.PLAYER) {
        for (int i = 1; i < ((InventoryClickEvent)e).getClickedInventory().getSize() + 1; i++) {
            if (rowType(i, ((InventoryClickEvent)e).getSlot(), ((InventoryClickEvent)e).getInventory())) {
                return new Number[]{i};
            }
        }
    }
    return null;
}
项目:skript-mirror    文件:ExprBits.java   
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
  Number num = numbers.getSingle(e);
  Number f = from.getSingle(e);
  Number t = to.getSingle(e);

  if (num == null || f == null || t == null) {
    return;
  }

  long mask = getRangeMaskIndexed(f.intValue(), t.intValue());

  long number = num.longValue();

  switch (mode) {
    case SET:
      if (delta[0] instanceof Number) {
        number &= ~mask;
        mask &= (((Number) delta[0]).longValue()) << f.intValue();
      } else if (delta[0] instanceof Boolean) {
        if (!((Boolean) delta[0])) {
          mask = ~mask;
        }
      } else {
        throw new IllegalStateException();
      }

      number |= mask;
      break;
    case DELETE:
      number &= ~mask;
      break;
    default:
      throw new IllegalStateException();
  }

  numbers.change(e, new Object[]{number}, Changer.ChangeMode.SET);
}
项目:HCFCore    文件:LoggerEntityHuman.java   
@Override
public void destroy() {
    if (!this.dead) {
        Bukkit.getPluginManager().callEvent((Event)new LoggerRemovedEvent(this));
        this.dead = true;
        this.cancelTask();
    }
}
项目:QuarSK    文件:ExprCustomBannerLayer.java   
@Nullable
@Override
protected Pattern[] get(Event e) {
    Color c = color.getSingle(e);
    PatternType p = pattern.getSingle(e);
    if (c == null || p == null) {
        return null;
    }
    return new Pattern[]{new Pattern(c.getWoolColor(), p)};
}
项目:ProjectAres    文件:PlayerItemTransferEvent.java   
public PlayerItemTransferEvent(Event cause,
                               Type type,
                               Player player,
                               Optional<InventorySlot<?>> from,
                               Optional<InventorySlot<?>> to,
                               ItemStack itemStack,
                               @Nullable Item itemEntity,
                               int quantity,
                               @Nullable ItemStack cursorItems) {

    super(cause, type, from, to, itemStack, itemEntity, quantity);
    this.player = checkNotNull(player);
    this.cursorItems = cursorItems;
}
项目:skript-mirror    文件:ExprExpression.java   
@Override
public T[] getAll(Event e) {
  Expression<?> expr = getExpression(e);

  if (expr == null) {
    return Util.newArray(superType, 0);
  }

  return Converters.convertArray(expr.getAll(e), types, superType);
}
项目:VoxelGamesLibv2    文件:EventHandler.java   
public void registerEvents(@Nonnull Listener listener, @Nonnull Game game) {
    Set<Class<Event>> newEvents = new HashSet<>();
    Arrays.stream(listener.getClass().getMethods()).filter((method -> method.isAnnotationPresent(GameEvent.class))).forEach(
            method -> {
                if (method.getParameterCount() != 1 && method.getParameterCount() != 2) {
                    log.warning("Invalid parameters for " + listener.getClass().getName() + " " + method.toString());
                    return;
                }

                if (Event.class.isAssignableFrom(method.getParameterTypes()[0])) {
                    //noinspection unchecked
                    Class<Event> eventClass = (Class<Event>) method.getParameterTypes()[0];
                    GameEvent annotation = method.getAnnotation(GameEvent.class);

                    RegisteredListener registeredListener = new RegisteredListener(listener, game, eventClass, method, new ArrayList<>());

                    if (annotation.filterPlayers()) {
                        registeredListener.addFilter(filterPlayers);
                    }

                    activeListeners.computeIfAbsent(game.getUuid(), (key) -> new CopyOnWriteArrayList<>()).add(registeredListener);

                    activeEvents.computeIfAbsent(eventClass, (key) -> {
                        newEvents.add(eventClass);
                        return new CopyOnWriteArrayList<>();
                    }).add(registeredListener);
                } else {
                    log.warning("Invalid parameter for " + listener.getClass().getName() + " " + method.toString());
                    return;
                }
            }
    );

    // check if we need to register a new event
    newEvents.forEach(eventClass ->
            Bukkit.getServer().getPluginManager().registerEvent(eventClass, this, EventPriority.HIGH, eventExecutor, voxelGamesLib));

    // register normal events
    Bukkit.getServer().getPluginManager().registerEvents(listener, voxelGamesLib);
}
项目:NeverLag    文件:ExplodeDisabler.java   
@Override
public void execute(Listener listener, Event event) throws EventException {
    if (cm.disableExplode) {
        ((Collection<?>) Reflection.getMethod(event.getClass(), "blockList")
            .invoke(event)).clear();
    }
}
项目:skLib    文件:EffCreateScrollSB.java   
@Override
protected void execute(Event evt) {
    if(title.getSingle(evt) != null && player.getSingle(evt) != null) {
        Player p = player.getSingle(evt);
        SbManager.createscrollsb(p, title.getSingle(evt));
    }else{
        Skript.error("May not provide null for either of the required arguments, refer to the syntax.");
    }
}
项目:BungeeMaster    文件:EffConnectPlayer.java   
@Override
protected void execute(Event event) {
    Object[] players = this.players.getAll(event);
    String destination = this.destination.getSingle(event);
    if (players == null || destination == null) {
        return;
    }
    Arrays.stream(getBungeeMaster().convertObjectsToNamesAndUUIDs(players))
        .forEach(player -> send(new ConnectPlayerPacket(player, destination, remote)));
}
项目:ProjectAres    文件:ItemTransferEvent.java   
public ItemTransferEvent(@Nullable Event cause,
                         Type type,
                         Optional<InventorySlot<?>> from,
                         Optional<InventorySlot<?>> to,
                         ItemStack itemStack,
                         @Nullable Item itemEntity,
                         int quantity) {
    super(cause);
    this.type = type;
    this.from = from;
    this.to = to;
    this.itemStack = itemStack;
    this.itemEntity = itemEntity;
    this.quantity = quantity;
}
项目:QuarSK    文件:SExprPotionItemEffects.java   
@Nullable
@Override
protected PotionEffect[] get(Event e) {
    ItemStack i = potionItem.getSingle(e);
    if (i == null) {
        return null;
    }
    if (PotionUtils.isPotionItem(i)) {
        PotionMeta meta = (PotionMeta) i.getItemMeta();
        return PotionUtils.actualPotionEffects(meta);
    }
    return null;
}
项目:skLib    文件:ExprNewPasteUnlisted.java   
@Override
@Nullable
protected String[] get(Event evt) {
  try {
      return new String[] {unlistedPaster.createPaste(title.getSingle(evt), body.getSingle(evt))};
  } catch (PastebinException | IOException e) {
      e.printStackTrace();
      return null;
  }
}
项目:pl    文件:EventSource.java   
private static <T extends Event> boolean canDispatch(Set<Class<? extends T>> kinds, Event v) {
    Class<? extends Event> aClass = v.getClass();
    for (Class<? extends T> kind : kinds)
        if (kind == aClass || kind.isAssignableFrom(aClass))
            return true;

    return false;
}
项目:skript-mirror    文件:CustomEffect.java   
@Override
protected TriggerItem walk(Event e) {
  EffectEvent effectEvent = invokeEffect(e);

  if (effectEvent.isSync()) {
    return getNext();
  }
  return null;
}
项目:skript-mirror    文件:ExprSpread.java   
@Override
public T[] getAll(Event e) {
  Object obj = object.getSingle(e);

  if (obj instanceof Collection) {
    obj = ((Collection) obj).toArray();
  } else if (obj instanceof Iterable) {
    obj = toArray(((Iterable) obj).iterator());
  } else if (obj instanceof Iterator) {
    obj = toArray((Iterator<?>) obj);
  }

  if (obj == null || !obj.getClass().isArray()) {
    return Util.newArray(superType, 0);
  }

  Class<?> componentType = obj.getClass().getComponentType();
  if (componentType != null && componentType.isPrimitive()) {
    int length = Array.getLength(obj);
    Object[] boxedArray = Util.newArray(Util.WRAPPER_CLASSES.get(componentType), length);

    for (int i = 0; i < length; i++) {
      boxedArray[i] = Array.get(obj, i);
    }

    obj = boxedArray;
  }

  return Converters.convertArray((Object[]) obj, types, superType);
}
项目:NyaaCore    文件:IPCUtils.java   
/**
 * Register an event and its constructor
 * @param name the event name, this is case-insensitive
 * @param eventConstructor the constructor
 */
public static void registerEvent(String name, Constructor<? extends Event> eventConstructor) {
    name = name.toLowerCase();
    if (eventMap.containsKey(name)) {
        throw new IllegalArgumentException("duplicated event name");
    }
    eventMap.put(name , eventConstructor);
}
项目:skript-mirror    文件:ExprJavaCall.java   
@Override
public String toString(Event e, boolean debug) {
  Descriptor descriptor = getDescriptor(e);

  if (descriptor == null) {
    return "java call";
  }

  return descriptor.toString();
}
项目:ProjectAres    文件:BlockTransformEvent.java   
/**
 * Return true if the block transformation was performed "by hand".
 *
 * Handled:
 *  - place
 *  - mine
 *  - bucket fill/empty
 *  - flint & steel fire/tnt
 *
 * Not handled:
 *  - bonemeal
 *  - probably lots of other things
 */
public boolean isManual() {
    final Event event = getCause();

    if(Types.instanceOfAny(
        event,
        BlockPlaceEvent.class,
        BlockBreakEvent.class,
        PlayerBucketEmptyEvent.class,
        PlayerBucketFillEvent.class
    )) return true;

    if(event instanceof BlockIgniteEvent) {
        BlockIgniteEvent igniteEvent = (BlockIgniteEvent) event;
        if(igniteEvent.getCause() == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && igniteEvent.getIgnitingEntity() != null) {
            return true;
        }
    }

    if(event instanceof ExplosionPrimeByEntityEvent && ((ExplosionPrimeByEntityEvent) event).getPrimer() instanceof Player) {
        return true;
    }

    return false;
}
项目:ProjectAres    文件:EventRuleMatchModule.java   
private void handleHangingPlace(Event event, BlockState blockState, Entity placer) {
    IEventQuery query = makeBlockQuery(event, placer, blockState);

    for(EventRule rule : this.ruleContext.get(EventRuleScope.BLOCK_PLACE)) {
        if(rule.region().contains(blockState)) {
            if(processQuery(rule, query)) {
                sendCancelMessage(rule, query);
                if(this.useRegionPriority) break;
            }
        }
    }
}
项目:ProjectAres    文件:EventRuleMatchModule.java   
private void handleHangingBreak(Event event, Hanging hanging, Entity breaker) {
    BlockState blockState = getHangingBlockState(hanging);
    if(blockState == null) return;

    IEventQuery query = makeBlockQuery(event, breaker, blockState);

    for(EventRule rule : this.ruleContext.get(EventRuleScope.BLOCK_BREAK)) {
        if(rule.region().contains(blockState)) {
            if(processQuery(rule, query)) {
                sendCancelMessage(rule, query);
                if(this.useRegionPriority) break;
            }
        }
    }
}
项目:ProjectAres    文件:BlockTransformListener.java   
private BlockTransformEvent callEvent(Event cause, BlockState oldState, BlockState newState, @Nullable MatchPlayerState player) {
    BlockTransformEvent event;
    if(player == null) {
        event = new BlockTransformEvent(cause, oldState, newState);
    } else if(player instanceof ParticipantState) {
        event = new ParticipantBlockTransformEvent(cause, oldState, newState, (ParticipantState) player);
    } else {
        event = new PlayerBlockTransformEvent(cause, oldState, newState, player);
    }
    callEvent(event);
    return event;
}
项目:QuarSK    文件:EvtPotionSplash.java   
@Override
public boolean check(Event e) {
    if (e instanceof PotionSplashEvent) {
        if (effectTypesLiteral.getAll().length > 0) {
            if (effectTypesLiteral.getAll() != null) {
                return ((PotionSplashEvent) e).getEntity()
                                              .getEffects()
                                              .containsAll(Arrays.asList(effectTypesLiteral.getAll()));
            }
        }
        return true;
    }
    return false;
}
项目:ChatModerator    文件:Violation.java   
/**
 * For subclasses only.
 */
protected Violation(final Instant time, final Player player, final FixedMessage message, double level, boolean fixed, final ZoneType zoneType, final FixStyleApplicant.FixStyle fixStyle, Event event, boolean forceNoSend) {
    this.time = Preconditions.checkNotNull(time, "Time");
    this.player = Preconditions.checkNotNull(player, "Player");
    this.message = Preconditions.checkNotNull(message, "Message");
    this.level = level;
    this.fixed = fixed;
    this.zoneType = Preconditions.checkNotNull(zoneType, "Zone type");
    this.fixStyle = fixStyle;
    this.event = Preconditions.checkNotNull(event, "event");
    this.forceNoSend = forceNoSend;
}
项目:QuarSK    文件:SExprBannerBlockLayers.java   
@Nullable
@Override
protected Pattern[] get(Event e) {
    Block b = block.getSingle(e);
    if (b == null) {
        return null;
    }
    if (b.getType() == Material.STANDING_BANNER || b.getType() == Material.WALL_BANNER) {
        return ((Banner) b.getState()).getPatterns().stream().toArray(Pattern[]::new);
    }
    return null;
}
项目:BungeeMaster    文件:EffProxyCommand.java   
@Override
protected void execute(Event event) {
    String[] commands = this.commands.getAll(event);
    if (commands == null) {
        return;
    }
    Arrays.stream(commands).forEach(command -> {
        Object rawOutput = send(new ProxyCommandPacket(command, this.output));
        if (this.output) {
            lastOutput = Arrays.stream((Object[]) rawOutput).toArray(String[]::new);
        }
    });
}
项目:ProjectAres    文件:DamageMatchModule.java   
/**
 * Query whether the given damage is allowed or not. Both the custom damage filters and the friendly fire policy
 * are considered, the former having priority over the latter.
 */
public Filter.QueryResponse queryDamage(Event event, ParticipantState victim, DamageInfo damageInfo) {
    Filter.QueryResponse response = queryRules(event, victim, damageInfo);
    if(response != Filter.QueryResponse.ABSTAIN) return response;

    return queryDefaultRules(victim, damageInfo);
}
项目:ProjectAres    文件:KillRewardMatchModule.java   
private Collection<KillReward> getRewards(@Nullable Event event, ParticipantState victim, DamageInfo damageInfo) {
    final DamageQuery query = DamageQuery.attackerDefault(event, victim, damageInfo);
    return Collections2.filter(killRewards, new Predicate<KillReward>() {
        @Override
        public boolean apply(KillReward killReward) {
            return killReward.filter.query(query).isAllowed();
        }
    });
}
项目:skLib    文件:ExprCurrentCode.java   
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
    return "the current two-factor code of secret code %string%";
}
项目:ProjectAres    文件:BukkitEvents.java   
public static boolean isCancelled(Event event) {
    return event instanceof Cancellable && ((Cancellable) event).isCancelled();
}