Skip to content
This repository has been archived by the owner on May 6, 2018. It is now read-only.

Commit

Permalink
Added a 'poison' and a 'cure from poison' effect
Browse files Browse the repository at this point in the history
Fixed the command effect to propely accept a slash at the beginning of the command
Made timespans available as arguments of commands
Fixed the expressions 'argument-<type>' and '<type> argument'
Added cave spiders
  • Loading branch information
Njol committed Jul 19, 2012
1 parent c383e40 commit e7d57b7
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 42 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Expand Up @@ -11,7 +11,7 @@ main: ch.njol.skript.Skript
#load: startup # not needed for addons, as they should add [soft-]depend: [Skript] to their plugin.yml
# must be uncommented to ever be able to have 'on world load' triggers that also execute when the server starts

version: 1.3.1
version: 1.3.2

commands:
skript:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Skript</groupId>
<artifactId>Skript</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<name>Skript</name>
<dependencies>
<dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/ch/njol/skript/Skript.java
Expand Up @@ -200,10 +200,11 @@ public void onEnable() {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
Skript.stopAcceptingRegistrations();

// Economy.load(); // causes an exception at least with iConomy 6

Skript.stopAcceptingRegistrations();

loadVariables();

loadScripts();
Expand Down
4 changes: 3 additions & 1 deletion src/ch/njol/skript/effects/EffCommand.java
Expand Up @@ -62,7 +62,9 @@ public boolean init(final Expression<?>[] vars, final int matchedPattern, final

@Override
public void execute(final Event e) {
for (final String command : commands.getArray(e)) {
for (String command : commands.getArray(e)) {
if (command.startsWith("/"))
command = command.substring(1);
if (senders == null) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} else {
Expand Down
82 changes: 82 additions & 0 deletions src/ch/njol/skript/effects/EffPoison.java
@@ -0,0 +1,82 @@
/*
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
*
* Copyright 2011, 2012 Peter Güttinger
*
*/

package ch.njol.skript.effects;

import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import ch.njol.skript.Skript;
import ch.njol.skript.api.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Timeperiod;
import ch.njol.skript.util.Timespan;

/**
* @author Peter Güttinger
*
*/
public class EffPoison extends Effect {

static {
Skript.registerEffect(EffPoison.class,
"poison %livingentities% [for %-timespan%]",
"(cure|unpoison) %livingentities% [from poison]");
}

private final static int DEFAULT_DURATION = 15*20; // 15 seconds on hard difficulty

private Expression<LivingEntity> entites;
private Expression<Timespan> duration;

private boolean cure;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, ParseResult parseResult) {
entites = (Expression<LivingEntity>) exprs[0];
if (matchedPattern == 0)
duration = (Expression<Timespan>) exprs[1];
cure = matchedPattern == 1;
return true;
}

@Override
public String toString(Event e, boolean debug) {
return "poison "+entites.toString(e, debug);
}

@Override
protected void execute(Event e) {
for (LivingEntity le : entites.getArray(e)) {
if (!cure) {
int d = duration == null || duration.getSingle(e) == null ? DEFAULT_DURATION : duration.getSingle(e).getTicks();
le.addPotionEffect(new PotionEffect(PotionEffectType.POISON, d, 0), true);
} else {
le.removePotionEffect(PotionEffectType.POISON);
}
}
}

}
4 changes: 4 additions & 0 deletions src/ch/njol/skript/entity/SimpleEntityData.java
Expand Up @@ -27,6 +27,7 @@

import org.bukkit.entity.Arrow;
import org.bukkit.entity.Boat;
import org.bukkit.entity.CaveSpider;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Creature;
Expand Down Expand Up @@ -78,6 +79,8 @@ public class SimpleEntityData extends EntityData<Entity> {
names.put("boat", Boat.class);
names.put("chicken", Chicken.class);
names.put("cow", Cow.class);
names.put("cave spider", CaveSpider.class);
names.put("cavespider", CaveSpider.class);
names.put("egg", Egg.class);
names.put("ender crystal", EnderCrystal.class);
names.put("ender dragon", EnderDragon.class);
Expand All @@ -104,6 +107,7 @@ public class SimpleEntityData extends EntityData<Entity> {
names.put("spider", Spider.class);
names.put("squid", Squid.class);
names.put("bottle o' enchanting", ThrownExpBottle.class);
names.put("bottle of enchanting", ThrownExpBottle.class);
names.put("thrown potion", ThrownPotion.class);
names.put("primed TNT", TNTPrimed.class);
names.put("tnt", TNTPrimed.class);
Expand Down
43 changes: 11 additions & 32 deletions src/ch/njol/skript/expressions/ExprArgument.java
Expand Up @@ -52,9 +52,7 @@ public class ExprArgument extends SimpleExpression<Object> {
"[the] <.+>( |-)arg[ument]", "[the] arg[ument]( |-)<.+>");
}

private Class<?> type = Object.class;
private Argument<?> arg;
private int a = -1;

@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final ParseResult parser) {
Expand All @@ -68,30 +66,27 @@ public boolean init(final Expression<?>[] vars, final int matchedPattern, final
}
switch (matchedPattern) {
case 0:
a = Commands.currentArguments.size();
arg = Commands.currentArguments.get(a - 1);
type = arg.getType();
arg = Commands.currentArguments.get(Commands.currentArguments.size() - 1);
break;
case 1:
case 2:
a = Integer.parseInt(parser.regexes.get(0).group(1));
if (Commands.currentArguments.size() <= a - 1) {
Skript.error("the command doesn't have a " + StringUtils.fancyOrderNumber(a) + " argument");
int i = Integer.parseInt(parser.regexes.get(0).group(1));
if (i > Commands.currentArguments.size()) {
Skript.error("the command doesn't have a " + StringUtils.fancyOrderNumber(i) + " argument");
return false;
}
arg = Commands.currentArguments.get(a - 1);
type = arg.getType();
arg = Commands.currentArguments.get(i - 1);
break;
case 3:
if (Commands.currentArguments.size() == 1) {
arg = Commands.currentArguments.get(0);
type = arg.getType();
} else {
Skript.error("'argument(s)' cannot be used if the command has multiple arguments");
return false;
}
break;
case 4:
case 5:
final Class<?> c = Skript.getClassFromUserInput(parser.regexes.get(0).group());
if (c == null)
return false;
Expand All @@ -103,59 +98,43 @@ public boolean init(final Expression<?>[] vars, final int matchedPattern, final
return false;
}
arg = a;
this.a = arg.getIndex() + 1;
}
if (arg == null) {
Skript.error("There is no " + Skript.getExactClassName(c) + " argument in this command");
return false;
}
}
assert arg != null;
return true;
}

@Override
protected Object[] get(final Event e) {
if (!(e instanceof SkriptCommandEvent))
return null;
if (arg == null) {
final ArrayList<Object> r = new ArrayList<Object>(((SkriptCommandEvent) e).getSkriptCommand().getArguments().size());
for (final Argument<?> a : ((SkriptCommandEvent) e).getSkriptCommand().getArguments()) {
for (final Object o : a.getCurrent())
r.add(o);
}
return r.toArray((Object[]) Array.newInstance(type, r.size()));
}
return arg.getCurrent();
}

@Override
public <R> ConvertedExpression<Object, ? extends R> getConvertedExpr(final Class<R> to) {
if (arg != null) {
return super.getConvertedExpr(to);
}
return null;
}

@Override
public Class<? extends Object> getReturnType() {
return type;
return arg.getType();
}

@Override
public String toString(final Event e, final boolean debug) {
if (e == null)
return a == -1 ? "arguments" : StringUtils.fancyOrderNumber(a) + " argument";
return "the "+ StringUtils.fancyOrderNumber(arg.getIndex() + 1) + " argument";
return Skript.getDebugMessage(getArray(e));
}

@Override
public boolean isSingle() {
return arg != null && arg.isSingle();
return arg.isSingle();
}

@Override
public boolean canLoop() {
return arg == null || !arg.isSingle();
return !arg.isSingle();
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/ch/njol/skript/lang/Expression.java
Expand Up @@ -45,7 +45,8 @@ public interface Expression<T> extends SyntaxElement, Debuggable {

/**
* Get the single value of this expression.<br/>
* Do not use this in conditions, use {@link #check(Event, Checker, Condition)} instead.
* Do not use this in conditions, use {@link #check(Event, Checker, Condition)} instead.<br/>
* This method must only return null if it always returns null for the given event.
*
* @param e
* @return The value or null if this expression doesn't have any value for the event
Expand Down
6 changes: 3 additions & 3 deletions src/ch/njol/skript/util/ItemType.java
Expand Up @@ -474,16 +474,16 @@ public boolean isContainedIn(final ItemStack[] list) {
if (d.isOfType(i)) {
found += i == null ? 1 : i.getAmount();
if (found >= getAmount()) {
if (!isAll())
if (!all)
return true;
break;
}
}
}
if (isAll() && found < getAmount())
if (all && found < getAmount())
return false;
}
return isAll();
return all;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/ch/njol/skript/util/Offset.java
Expand Up @@ -219,9 +219,11 @@ private final static BlockFace scanForFace(final String s, final int i) {
public static Offset parse(final String s) {
if (s.isEmpty())
return null;
final String lower = s.toLowerCase();
if (lower.equalsIgnoreCase("at"))
String lower = s.toLowerCase();
if (lower.equals("at"))
return new Offset(0, 0, 0);
if (lower.startsWith("at "))
lower = lower.substring(3);
final Matcher m = offsetPattern.matcher(" " + lower);
if (!m.matches())
return null;
Expand Down
1 change: 1 addition & 0 deletions src/ch/njol/skript/util/Timespan.java
Expand Up @@ -46,6 +46,7 @@ public class Timespan {
simpleValues.put("day", 20 * 60 * 60 * 24);

Skript.registerClass(new ClassInfo<Timespan>(Timespan.class, "timespan", "time span")
.user("time ?spans?")
.parser(new Parser<Timespan>() {
@Override
public Timespan parse(final String s, final ParseContext context) {
Expand Down

0 comments on commit e7d57b7

Please sign in to comment.