Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 35 additions & 36 deletions src/main/java/ch/njol/skript/effects/EffFeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
Expand All @@ -20,41 +20,40 @@
@Since("2.2-dev34")
public class EffFeed extends Effect {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class should also be moved to the PlayerModule directory. specifically org/skriptlang/skript/bukkit/entity/player/elements/effects


static {
Skript.registerEffect(EffFeed.class, "feed [the] %players% [by %-number% [beef[s]]]");
}

@SuppressWarnings("null")
private Expression<Player> players;
@Nullable
private Expression<Number> beefs;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use ParseResult not SkriptParser.ParseResult

players = (Expression<Player>) exprs[0];
beefs = (Expression<Number>) exprs[1];
return true;
}

@Override
protected void execute(Event e) {
int level = 20;

if (beefs != null) {
Number n = beefs.getSingle(e);
if (n == null)
return;
level = n.intValue();
}
for (Player player : players.getArray(e)) {
player.setFoodLevel(player.getFoodLevel() + level);
}
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "feed " + players.toString(e, debug) + (beefs != null ? " by " + beefs.toString(e, debug) : "");
}
static {
Skript.registerEffect(EffFeed.class, "feed [the] %players% [by %-number% [beef[s]]]");
Comment thread
hotpoc marked this conversation as resolved.
Outdated
Comment thread
hotpoc marked this conversation as resolved.
Outdated
}

@SuppressWarnings("null")
private Expression<Player> players;
Comment thread
hotpoc marked this conversation as resolved.
Outdated
@Nullable
private Expression<Number> beefs;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my thoughts but why is this named beefs? couldn't it be named something like amount

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont know bro

Comment thread
hotpoc marked this conversation as resolved.
Outdated

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
players = (Expression<Player>) exprs[0];
beefs = (Expression<Number>) exprs[1];
return true;
}

@Override
protected void execute(Event e) {
Comment thread
hotpoc marked this conversation as resolved.
Outdated
int foodAmount = 20;

if (beefs != null) {
Number n = beefs.getSingle(e);
if (n != null)
foodAmount = n.intValue();
Comment on lines +46 to +48

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would retain the behavior of terminating if n is null.

}
for (Player player : players.getArray(e)) {
player.setFoodLevel(beefs == null ? 20 : player.getFoodLevel() + foodAmount);
}
}

@Override
public String toString(@Nullable Event e, boolean debug) {
Comment thread
hotpoc marked this conversation as resolved.
Outdated
return "feed " + players.toString(e, debug) + (beefs != null ? " by " + beefs.toString(e, debug) : "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use SyntaxStringBuilder

}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

extraneous space

}