Skip to content
Merged
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
70 changes: 70 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondGoatHasHorns.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package ch.njol.skript.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.*;
import ch.njol.skript.effects.EffGoatHorns.GoatHorn;
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;

@Name("Goat Has Horns")
@Description("Checks to see if a goat has or does not have a left, right, or both horns.")
@Example("""
if last spawned goat does not have both horns:
make last spawned goat have both horns
"""
)
@Example("""
if {_goat} has a right horn:
force {_goat} to not have a right horn
"""
)
@Since("INSERT VERSION")
public class CondGoatHasHorns extends PropertyCondition<LivingEntity> {

static {
register(CondGoatHasHorns.class, PropertyType.HAVE,
"((any|a) horn|left:[a] left horn[s]|right:[a] right horn[s]|both:both horns)", "livingentities");
}

private GoatHorn goatHorn = GoatHorn.ANY;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (parseResult.hasTag("left")) {
goatHorn = GoatHorn.LEFT;
} else if (parseResult.hasTag("right")) {
goatHorn = GoatHorn.RIGHT;
} else if (parseResult.hasTag("both")) {
goatHorn = GoatHorn.BOTH;
}
return super.init(exprs, matchedPattern, isDelayed, parseResult);
}

@Override
public boolean check(LivingEntity entity) {
if (!(entity instanceof Goat goat))
return false;
boolean leftHorn = goat.hasLeftHorn();
boolean rightHorn = goat.hasRightHorn();
return switch (goatHorn) {
case ANY -> leftHorn || rightHorn;
case BOTH -> leftHorn && rightHorn;
case LEFT -> leftHorn;
case RIGHT -> rightHorn;
};
Comment thread
Absolutionism marked this conversation as resolved.
}

@Override
protected String getPropertyName() {
return switch (goatHorn) {
case ANY -> "a horn";
case BOTH -> "both horns";
case LEFT -> "left horn";
case RIGHT -> "right horn";
};
}

}
47 changes: 47 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,47 @@
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 whether a goat or enderman is screaming.")
@Example("""
if last spawned goat is not screaming:
make last spawned goat scream
"""
)
@Example("""
if {_enderman} is screaming:
force {_enderman} to stop screaming
"""
)
@RequiredPlugins("Paper (endermen)")
@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";
}

}
87 changes: 87 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,87 @@
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("Goat Horns")
@Description("Make a goat have or not have a left, right, or both horns.")
@Examples({
"remove the left horn of last spawned goat",
"regrow {_goat}'s horns",
"remove both horns of all goats"
})
@Since("INSERT VERSION")
public class EffGoatHorns extends Effect {
Comment thread
Absolutionism marked this conversation as resolved.

public enum GoatHorn {
LEFT, RIGHT, BOTH, ANY
}

static {
Skript.registerEffect(EffGoatHorns.class,
"remove [the] (left horn[s]|right:right horn[s]|both:both horns) of %livingentities%",
"remove %livingentities%'[s] (left horn[s]|right:right horn[s]|both:horns)",
"(regrow|replace) [the] (left horn[s]|right:right horn[s]|both:both horns) of %livingentities%",
"(regrow|replace) %livingentities%'[s] (left horn[s]|right:right horn[s]|both:horns)");
}

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

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (parseResult.hasTag("right")) {
goatHorn = GoatHorn.RIGHT;
} else if (parseResult.hasTag("both")) {
goatHorn = GoatHorn.BOTH;
}
//noinspection unchecked
entities = (Expression<LivingEntity>) exprs[0];
remove = matchedPattern <= 1;
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(remove);
if (goatHorn != GoatHorn.LEFT)
goat.setRightHorn(remove);
}
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
if (remove) {
builder.append("remove");
} else {
builder.append("regrow");
}
builder.append(switch (goatHorn) {
case LEFT -> "the left horn";
case RIGHT -> "the right horn";
case BOTH -> "both horns";
case ANY -> "any horn";
});
builder.append("of", entities);
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);
}

}
68 changes: 68 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,68 @@
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 start or stop screaming.")
@Example("""
make last spawned goat start screaming
force last spawned goat to stop screaming
"""
)
@Example("""
make {_enderman} scream
force {_enderman} to stop screaming
"""
)
@RequiredPlugins("Paper (endermen)")
@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",
"force %livingentities% to stop screaming");
}

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";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.skriptlang.skript.test.tests.syntaxes.effects;

import ch.njol.skript.test.runner.SkriptJUnitTest;
import org.bukkit.Bukkit;
import org.bukkit.entity.Goat;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class EffGoatHornsTest extends SkriptJUnitTest {

static {
setShutdownDelay(10);
}

private Goat goat;

@Test
public void test() {
goat = getTestWorld().spawn(getTestWorld().getSpawnLocation(), Goat.class);
}

@After
public void after() {
if (goat != null)
goat.remove();
}

}
Loading