@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); } }
@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); } } }
@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; }
@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); } } }
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); }
@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)); }
@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)); }) ); }
@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); } }
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); }
@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); } } } } }
@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; }
@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); }
@Override public void destroy() { if (!this.dead) { Bukkit.getPluginManager().callEvent((Event)new LoggerRemovedEvent(this)); this.dead = true; this.cancelTask(); } }
@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)}; }
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; }
@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); }
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); }
@Override public void execute(Listener listener, Event event) throws EventException { if (cm.disableExplode) { ((Collection<?>) Reflection.getMethod(event.getClass(), "blockList") .invoke(event)).clear(); } }
@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."); } }
@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))); }
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; }
@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; }
@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; } }
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; }
@Override protected TriggerItem walk(Event e) { EffectEvent effectEvent = invokeEffect(e); if (effectEvent.isSync()) { return getNext(); } return null; }
@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); }
/** * 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); }
@Override public String toString(Event e, boolean debug) { Descriptor descriptor = getDescriptor(e); if (descriptor == null) { return "java call"; } return descriptor.toString(); }
/** * 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; }
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; } } } }
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; } } } }
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; }
@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; }
/** * 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; }
@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; }
@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); } }); }
/** * 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); }
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(); } }); }
@Override public String toString(@Nullable Event arg0, boolean arg1) { return "the current two-factor code of secret code %string%"; }
public static boolean isCancelled(Event event) { return event instanceof Cancellable && ((Cancellable) event).isCancelled(); }