Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
75 changes: 38 additions & 37 deletions src/main/java/ch/njol/skript/effects/EffFeed.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package ch.njol.skript.effects;

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 be in org/skriptlang/skript/bukkit/entity/player/elements/effects


import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
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;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxRegistry;

@Name("Feed")
@Description("Feeds the specified players.")
Expand All @@ -20,41 +21,41 @@
@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) : "");
}
public static void register(SyntaxRegistry registry) {
registry.register(SyntaxRegistry.EFFECT, SyntaxInfo.builder(EffFeed.class)
.addPatterns("feed %players% [by %-number% [beef[s]]]")

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.

I believe someone already asked this in another pr or at some point but why is there beef in the syntax it just seems off

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 its optional though

@AnOwlBe AnOwlBe Jun 30, 2026

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.

well atleast imo it should be removed as its kind of misleading as if you eat beef/steak ingame it feeds by 6 health so if you do feed player by 1 beef kind of misleading

though for this pr probably not best idea as it'd cause breaking changes

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.

Beefs, as that's what the hunger bars could be refered to, don't see the use in removing it, would just cause it to break for anyone using it.

.supplier(EffFeed::new)
.build());
}

private Expression<Player> players;
private @Nullable Expression<Number> beefs;

@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 event) {
int foodAmount = 0;
Comment thread
TheMug06 marked this conversation as resolved.

if (beefs != null) {
Number n = beefs.getSingle(event);
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(event)) {
player.setFoodLevel(beefs == null ? 20 : player.getFoodLevel() + foodAmount);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "feed " + players.toString(event, debug) + (beefs != null ? " by " + beefs.toString(event, debug) : "");
}


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

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.skriptlang.skript.bukkit.entity.player;

import ch.njol.skript.Skript;
import ch.njol.skript.effects.EffFeed;
import ch.njol.skript.lang.util.SimpleEvent;
import io.papermc.paper.event.player.AsyncChatEvent;
import org.skriptlang.skript.addon.AddonModule;
Expand All @@ -23,6 +24,7 @@ protected void loadSelf(SkriptAddon addon) {
register(addon,
EffBan::register,
EffKick::register,
EffFeed::register,

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 be before EffKick I believe

ExprChatFormat::register,
ExprChatMessage::register,
ExprChatRecipients::register,
Expand Down