Exemplo n.º 1
0
 @Override
 protected JSONMessage[] get(Event event) {
   JSONMessage j = json.getSingle(event);
   String a = append.getSingle(event);
   if (j == null || a == null) return null;
   return Collect.asArray(j.link(a));
 }
Exemplo n.º 2
0
 @Override
 public Iterator<Block> iterator(Event e) {
   Location p1 = pos1.getSingle(e);
   Location p2 = pos2.getSingle(e);
   if (p1 == null || p2 == null) return new EmptyIterator<>();
   return new CuboidIterator(p1, p2);
 }
Exemplo n.º 3
0
 @SuppressWarnings("deprecation")
 @Override
 protected void execute(Event e) {
   Location pos1 = location1.getSingle(e);
   Location pos2 = location2.getSingle(e);
   EditSession session = editSession.getSingle(e);
   ItemStack[] blocks = blockList.getAll(e);
   RandomPattern random = new RandomPattern();
   if (session == null) return;
   for (ItemStack b : blocks) {
     if (b.getType().isBlock()) {
       random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
     }
   }
   try {
     session.makeWalls(
         new CuboidRegion(
             (World) BukkitUtil.getLocalWorld(pos1.getWorld()),
             BukkitUtil.toVector(pos1),
             BukkitUtil.toVector(pos2)),
         Patterns.wrap(random));
     session.flushQueue();
   } catch (WorldEditException ex) {
     if (ex instanceof MaxChangedBlocksException) return;
     else ex.printStackTrace();
   }
 }
Exemplo n.º 4
0
 @Override
 public String toString(final Event e, final boolean debug) {
   return expr.toString(e, debug)
       + (expr.isSingle() ? " is " : " are ")
       + (isNegated() ? "not " : "")
       + property;
 }
Exemplo n.º 5
0
 @Override
 protected void execute(Event event) {
   String u = url.getSingle(event);
   if (u == null) return;
   for (Player p : target.getAll(event)) {
     p.setResourcePack(u);
   }
 }
Exemplo n.º 6
0
 @Override
 protected void execute(Event event) {
   Player player = eplayer.getSingle(event);
   String path = epath.getSingle(event);
   String line1 = eline1.getSingle(event);
   String line2 = eline2.getSingle(event);
   String line3 = eline3.getSingle(event);
   ImgInChat.ShowImgFromURL(player, path, line1, line2, line3);
 }
Exemplo n.º 7
0
 @Override
 public String toString(@Nullable Event e, boolean debug) {
   return "make walls from "
       + location1.toString(e, debug)
       + " to "
       + location2.toString(e, debug)
       + " using an edit session with "
       + blockList.toString(e, debug);
 }
Exemplo n.º 8
0
 @Override
 protected Block[] get(Event event) {
   Location p1 = pos1.getSingle(event);
   Location p2 = pos2.getSingle(event);
   if (p1 == null || p2 == null) return null;
   List<Block> list = new ArrayList<>();
   for (Block b : new IteratorIterable<>(iterator(event))) {
     list.add(b);
   }
   return list.toArray(new Block[list.size()]);
 }
Exemplo n.º 9
0
  @Override
  protected Slot[] get(final Event e, final Player[] source) {
    if (players.isDefault() && !Delay.isDelayed(e)) {
      if (e instanceof PlayerItemHeldEvent) {
        return new Slot[] {
          new Slot(
              ((PlayerItemHeldEvent) e).getPlayer().getInventory(),
              getTime() >= 0
                  ? ((PlayerItemHeldEvent) e).getNewSlot()
                  : ((PlayerItemHeldEvent) e).getPreviousSlot())
        };
      } else if (e instanceof PlayerBucketEvent) {
        return new Slot[] {
          new Slot(
              ((PlayerBucketEvent) e).getPlayer().getInventory(),
              ((PlayerBucketEvent) e).getPlayer().getInventory().getHeldItemSlot()) {
            @Override
            public ItemStack getItem() {
              return getTime() <= 0 ? super.getItem() : ((PlayerBucketEvent) e).getItemStack();
            }

            @Override
            public void setItem(final ItemStack item) {
              if (getTime() >= 0) {
                ((PlayerBucketEvent) e).setItemStack(item);
              } else {
                super.setItem(item);
              }
            }
          }
        };
      }
    }
    return get(
        source,
        new Getter<Slot, Player>() {
          @Override
          public Slot get(final Player p) {
            return new Slot(p.getInventory(), p.getInventory().getHeldItemSlot()) {
              @Override
              public void setItem(final ItemStack item) {
                p.setItemInHand(item);
              }

              @Override
              public ItemStack getItem() {
                return p.getItemInHand();
              }

              @Override
              public String toString(final Event e, final boolean debug) {
                return (getTime() == 1 ? "future " : getTime() == -1 ? "former " : "")
                    + "tool of "
                    + p.getName();
              }
            };
          }
        });
  }
Exemplo n.º 10
0
 @Override
 public String toString(final Event e, final boolean debug) {
   if (e == null)
     return "the "
         + (getTime() == 1 ? "future " : getTime() == -1 ? "former " : "")
         + "tool of "
         + players.toString(e, debug);
   return Skript.getDebugMessage(getSingle(e));
 }
Exemplo n.º 11
0
 @Override
 protected void execute(Event event) {
   Location l = location.getSingle(event);
   Player p = player.getSingle(event);
   if (l == null) {
     return;
   } else if (p == null) {
     return;
   }
   Location loc = p.getLocation().clone();
   Inventory inv = p.getInventory();
   for (ItemStack item : inv.getContents()) {
     if (item != null) {
       loc.getWorld().dropItem(l, item.clone());
     }
   }
   inv.clear();
 }
Exemplo n.º 12
0
 @Override
 protected ItemStack[] get(Event e) {
   PotionEffectType p = effect.getSingle(e);
   if (p == null) return null;
   ItemStack potion = new Potion(PotionType.getByEffect(p)).toItemStack(1);
   PotionMeta meta = ((PotionMeta) potion.getItemMeta());
   meta.addCustomEffect(new PotionEffect(p, 0, 0), true);
   potion.setItemMeta(meta);
   return Collect.asArray(potion);
 }
Exemplo n.º 13
0
 @Override
 protected Boolean[] get(Event e) {
   Comparator.Relation r = Comparators.compare(first.getSingle(e), second.getSingle(e));
   switch (match) {
     case 0:
       return Collect.asArray(Comparator.Relation.EQUAL.is(r));
     case 1:
       return Collect.asArray((first.getSingle(e) + "").equals(second.getSingle(e) + ""));
     case 2:
       return Collect.asArray(Comparator.Relation.GREATER.is(r));
     case 3:
       return Collect.asArray(Comparator.Relation.SMALLER.is(r));
     case 4:
       return Collect.asArray(Comparator.Relation.GREATER_OR_EQUAL.is(r));
     case 5:
       return Collect.asArray(Comparator.Relation.SMALLER_OR_EQUAL.is(r));
   }
   return null;
 }
Exemplo n.º 14
0
  @Override
  protected void execute(Event evt) {
    IChatBaseComponent header =
        ChatSerializer.a("{\"text\": \"" + coreHeader.getSingle(evt).replace("\"", "") + "\"}");
    IChatBaseComponent footer =
        ChatSerializer.a("{\"text\": \"" + coreFooter.getSingle(evt).replace("\"", "") + "\"}");
    PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
    try {
      Field headerField = packet.getClass().getDeclaredField("a");
      headerField.setAccessible(true);
      headerField.set(packet, header);
      headerField.setAccessible(!headerField.isAccessible());

      Field footerField = packet.getClass().getDeclaredField("b");
      footerField.setAccessible(true);
      footerField.set(packet, footer);
      footerField.setAccessible(!footerField.isAccessible());
    } catch (Exception e) {
      e.printStackTrace();
    }
    ((CraftPlayer) player.getSingle(evt)).getHandle().playerConnection.sendPacket(packet);
  }
Exemplo n.º 15
0
  @Override
  @javax.annotation.Nullable
  protected Entity[] get(Event arg0) {

    Entity returnEnt = null;
    for (World w : Bukkit.getWorlds()) {
      for (Entity e : w.getEntities()) {
        if (e.getUniqueId().toString() == uuid.getSingle(arg0)) {
          return new Entity[] {e};
        }
      }
    }
    return null;
  }
Exemplo n.º 16
0
 @Override
 protected void execute(Event event) {
   ParticleEnum particlename = particleName.getSingle(event);
   Number offx = this.offx.getSingle(event);
   Number offy = this.offy.getSingle(event);
   Number offz = this.offz.getSingle(event);
   Number speed = this.speed.getSingle(event);
   Location[] loc = this.locations.getAll(event);
   Integer count = this.count.getSingle(event).intValue();
   Integer data = this.data.getSingle(event).intValue();
   Integer secondaryData = this.secondaryData.getSingle(event).intValue();
   if (particlename == null) {
     return;
   }
   ParticleFunction.spawnParticle(
       count, particlename, speed, offx, offy, offz, loc, data, secondaryData);
 }
Exemplo n.º 17
0
 @Override
 public void execute(final Event e) {
   double damage = 0;
   if (this.damage != null) {
     final Number n = this.damage.getSingle(e);
     if (n == null) return;
     damage = n.doubleValue();
   }
   for (final Object damageable : damageables.getArray(e)) {
     if (damageable instanceof Slot) {
       ItemStack is = ((Slot) damageable).getItem();
       if (this.damage == null) {
         is.setDurability((short) 0);
       } else {
         is.setDurability((short) Math.max(0, is.getDurability() + (heal ? -damage : damage)));
         if (is.getDurability() >= is.getType().getMaxDurability()) is = null;
       }
       ((Slot) damageable).setItem(is);
     } else if (damageable instanceof LivingEntity) {
       if (this.damage == null) {
         ((LivingEntity) damageable).setHealth(((LivingEntity) damageable).getMaxHealth());
       } else {
         if (!heal) {
           ((LivingEntity) damageable).damage((int) Math.round(2. * damage));
         } else {
           ((LivingEntity) damageable)
               .setHealth(
                   Math.max(
                       0,
                       Math.min(
                           ((LivingEntity) damageable).getMaxHealth(),
                           ((LivingEntity) damageable).getHealth()
                               + (int) Math.round(2. * damage))));
         }
       }
     }
   }
 }
Exemplo n.º 18
0
 @Override
 public boolean check(Event event) {
   return isNegated() ? !item.getSingle(event).hasBlock() : item.getSingle(event).hasBlock();
 }
Exemplo n.º 19
0
 @Override
 public String toString(final Event e, final boolean debug) {
   return (heal ? "heal " : "damage ")
       + damageables.toString(e, debug)
       + (damage == null ? "" : " by " + damage.toString(e, debug));
 }
Exemplo n.º 20
0
 @Override
 public String toString(Event event, boolean b) {
   return json.getSingle(event).toOldMessageFormat();
 }
Exemplo n.º 21
0
 @Override
 public boolean init(
     Expression<?>[] exprs,
     int matchedPattern,
     Kleenean isDelayed,
     SkriptParser.ParseResult parseResult) {
   first = exprs[0];
   second = exprs[1];
   match = matchedPattern;
   if (first instanceof Variable && second instanceof Variable) {
     first = first.getConvertedExpression(Object.class);
     second = second.getConvertedExpression(Object.class);
   } else if (first instanceof Literal<?> && second instanceof Literal<?>) {
     first = first.getConvertedExpression(Object.class);
     second = second.getConvertedExpression(Object.class);
     if (first == null || second == null) return false;
   } else {
     if (first instanceof Literal<?>) {
       first = first.getConvertedExpression(second.getReturnType());
       if (first == null) return false;
     } else if (second instanceof Literal<?>) {
       second = second.getConvertedExpression(first.getReturnType());
       if (second == null) return false;
     }
     if (first instanceof Variable) {
       first = first.getConvertedExpression(second.getReturnType());
     } else if (second instanceof Variable) {
       second = second.getConvertedExpression(first.getReturnType());
     }
     assert first != null && second != null;
   }
   return true;
 }
Exemplo n.º 22
0
 @Override
 public boolean check(final Event e) {
   return expr.check(e, checker, this);
 }