Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
86 changes: 86 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondGoatHorns.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.effects.EffGoatHorns.GoatHorn;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.SyntaxStringBuilder;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Goat Has Horns")
@Description("Checks to see if a goat has or does not have a left, right, or both horns.")
@Examples({
"if last spawned goat does not have both horns:",
"\tmake last spawned goat have both horns",
"",
"if {_goat} has a right horn:",
"\tforce {_goat} to not have a right horn"
})
@Since("INSERT VERSION")
public class CondGoatHorns extends Condition {
Comment thread
Absolutionism marked this conversation as resolved.
Outdated

static {
Skript.registerCondition(CondGoatHorns.class,
"%livingentities% (has|[does] have) [a] left horn",
"%livingentities% (has|[does] have) [a] right horn",
"%livingentities% (has|[does] have) both horns",
"%livingentities% (does not|doesn't) have [a] left horn",
"%livingentities% (does not|doesn't) have [a] right horn",
"%livingentities% (does not|doesn't) have both horns");
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
}

private Expression<LivingEntity> entities;
private GoatHorn goatHorn;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
entities = (Expression<LivingEntity>) exprs[0];
goatHorn = GoatHorn.values()[matchedPattern / 3];
setNegated(matchedPattern >= 3);
return true;
}

@Override
public boolean check(Event event) {
return entities.check(event, entity -> {
if (!(entity instanceof Goat goat))
return false;
boolean hasHorns = true;
if (goatHorn != GoatHorn.RIGHT)
hasHorns = goat.hasLeftHorn();
if (goatHorn != GoatHorn.LEFT)
hasHorns &= goat.hasRightHorn();
return hasHorns;
}, isNegated());
}

@Override
public String toString(@Nullable Event event, boolean debug) {
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
builder.append(entities);
if (isNegated()) {
builder.append("does not have");
} else if (entities.isSingle()) {
builder.append("has");
} else {
builder.append("have");
}
builder.append(switch (goatHorn) {
case LEFT -> "left horn";
case RIGHT -> "right horn";
case BOTH -> "both horns";
});
return builder.toString();
}

}
44 changes: 44 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsScreaming.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.*;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;

@Name("Is Screaming")
@Description("Check if a goat or enderman (Paper) is or is not screaming.")
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
@Examples({
"if last spawned goat is not screaming:",
"\tmake last spawned goat scream",
"",
"if {_enderman} is screaming:",
"\tforce {_enderman} to stop screaming"
})
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
@RequiredPlugins("Paper (enderman)")
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
@Since("INSERT VERSION")
public class CondIsScreaming extends PropertyCondition<LivingEntity> {

private static final boolean SUPPORTS_ENDERMAN = Skript.methodExists(Enderman.class, "isScreaming");

static {
register(CondIsScreaming.class, "screaming", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
if (entity instanceof Goat goat) {
return goat.isScreaming();
} else if (SUPPORTS_ENDERMAN && entity instanceof Enderman enderman) {
return enderman.isScreaming();
}
return false;
}

@Override
protected String getPropertyName() {
return "screaming";
}

}
86 changes: 86 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffGoatHorns.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
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.ParseResult;
import ch.njol.skript.lang.SyntaxStringBuilder;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Make Goat Have Horns")
@Description("Make a goat have or not have a left, right, or both horns.")
@Examples({
"make last spawned goat not have both horns",
"force {_goat} to have a left horn",
"make all goats have a right horn"
})
@Since("INSERT VERSION")
public class EffGoatHorns extends Effect {
Comment thread
Absolutionism marked this conversation as resolved.

public enum GoatHorn {
LEFT, RIGHT, BOTH
}

static {
Skript.registerEffect(EffGoatHorns.class,
"make %livingentities% [:not] have [a] left horn",
"force %livingentities% to [:not] have [a] left horn",
"make %livingentities% [:not] have [a] right horn",
"force %livingentities% to [:not] have [a] right horn",
"make %livingentities% [:not] have both horns",
"force %livingentities% to [:not] have both horns");
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
}

private Expression<LivingEntity> entities;
private GoatHorn goatHorn = GoatHorn.LEFT;
private boolean have;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (matchedPattern >= 4) {
goatHorn = GoatHorn.BOTH;
} else if (matchedPattern >= 2) {
goatHorn = GoatHorn.RIGHT;
}
//noinspection unchecked
entities = (Expression<LivingEntity>) exprs[0];
have = !parseResult.hasTag("not");
return true;
}

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof Goat goat) {
if (goatHorn != GoatHorn.RIGHT)
goat.setLeftHorn(have);
if (goatHorn != GoatHorn.LEFT)
goat.setRightHorn(have);
}
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
builder.append("make", entities);
if (!have)
builder.append("not");
builder.append("have");
builder.append(switch (goatHorn) {
case LEFT -> "left horn";
case RIGHT -> "right horn";
case BOTH -> "both horns";
});
return builder.toString();
}

}
60 changes: 60 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffGoatRam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Make Goat Ram")
@Description({
"Make a goat ram an entity.",
"Ramming does have a cooldown and currently no way to change it."
})
@Examples("make all goats ram player")
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class EffGoatRam extends Effect {

static {
if (Skript.methodExists(Goat.class, "ram", LivingEntity.class))
Skript.registerEffect(EffGoatRam.class,
"make %livingentities% ram %livingentity%",
"force %livingentities% to ram %livingentity%");
}

private Expression<LivingEntity> entities;
private Expression<LivingEntity> target;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
entities = (Expression<LivingEntity>) exprs[0];
//noinspection unchecked
target = (Expression<LivingEntity>) exprs[1];
return true;
}

@Override
protected void execute(Event event) {
LivingEntity target = this.target.getSingle(event);
if (target == null)
return;
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof Goat goat) {
goat.ram(target);
}
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make " + entities.toString(event, debug) + " ram " + target.toString(event, debug);
}

}
65 changes: 65 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffScreaming.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Make Entity Scream")
@Description("Make a goat or enderman (Paper) start or stop screaming.")
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
@Examples({
"make last spawned goat start screaming",
"force last spawned goat to not scream",
"",
"make {_enderman} scream",
"force {_enderman} to stop screaming"
})
@RequiredPlugins("Paper (enderman)")
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
@Since("INSERT VERSION")
public class EffScreaming extends Effect {

private static final boolean SUPPORTS_ENDERMAN = Skript.methodExists(Enderman.class, "setScreaming", boolean.class);

static {
Skript.registerEffect(EffScreaming.class,
"make %livingentities% (start screaming|scream)",
"force %livingentities% to (start screaming|scream)",
"make %livingentities% (stop screaming|not scream)",
"force %livingentities% to (stop screaming|not scream)");
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
Comment thread
Absolutionism marked this conversation as resolved.
Outdated
}

private Expression<LivingEntity> entities;
private boolean scream;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
entities = (Expression<LivingEntity>) exprs[0];
scream = matchedPattern <= 1;
return true;
}

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof Goat goat) {
goat.setScreaming(scream);
} else if (SUPPORTS_ENDERMAN && entity instanceof Enderman enderman) {
enderman.setScreaming(scream);
}
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make " + entities.toString(event, debug) + (scream ? " start " : " stop ") + "screaming";
}

}
17 changes: 17 additions & 0 deletions src/test/skript/tests/syntaxes/effects/EffScreaming.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test "goat scream":
spawn a goat at test-location:
set {_entity} to entity
make {_entity} scream
assert {_entity} is screaming with "Goat should be screaming"
make {_entity} not scream
assert {_entity} is not screaming with "Goat should not be screaming"
clear entity within {_entity}

test "enderman scream":
spawn an enderman at test-location:
set {_entity} to entity
make {_entity} scream
assert {_entity} is screaming with "Enderman should be screaming"
make {_entity} not scream
assert {_entity} is not screaming with "Enderman should not be screaming"
clear entity within {_entity}