Skip to content

Commit

Permalink
add goat api
Browse files Browse the repository at this point in the history
  • Loading branch information
aabssmc committed Sep 19, 2024
1 parent 9c5f257 commit 44cb9a4
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lol.aabss.skuishy.elements.entities.conditions;

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 lol.aabss.skuishy.other.skript.EntityCondition;
import org.bukkit.entity.Goat;

@Name("Goat - Has Horn")
@Description("True if the goat has the horn:")
@Examples({
"if {_goat} has left horn:",
"\tset left horn of {_goat} to false"
})
@Since("2.8")
public class CondHasGoatHorn extends EntityCondition<Goat> {

static {
register(CondHasGoatHorn.class, PropertyType.HAVE, "[goat] (:left|right) horn", "entities");
}

@Override
protected boolean run(Goat goat) {
return tags.contains("left") ? goat.hasLeftHorn() : goat.hasRightHorn();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package lol.aabss.skuishy.elements.entities.conditions;

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 lol.aabss.skuishy.other.skript.EntityCondition;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;

@Name("Enderman/Goat - Is Screaming")
@Description("True if the enderman or goat is screaming.")
@Examples({
"if {_enderman} is screaming:",
"\tset screaming state of {_enderman} to false"
})
@Since("2.8")
public class CondIsScreaming extends EntityCondition<LivingEntity> {

static {
register(CondIsScreaming.class, "[enderman|goat] screaming", "entities");
}

@Override
protected boolean run(LivingEntity entity) {
if (entity instanceof Enderman) {
return ((Enderman) entity).isScreaming();
} else if (entity instanceof Goat) {
return ((Goat) entity).isScreaming();
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package lol.aabss.skuishy.elements.entities.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 lol.aabss.skuishy.other.skript.EntityEffect;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;

@Name("Goat - Ram")
@Description("Makes a goat ram into a living entity.")
@Examples({
"make {_goat} ram into player"
})
@Since("2.8")
public class EffGoatRam extends EntityEffect<Goat> {

static {
Skript.registerEffect(EffJump.class, "make %livingentities% ram into %livingentities%");
}

@Override
protected void execute(Goat goat, Event event) {
if (exprs.length >= 2 && exprs[1].getSingle(event) != null) {
LivingEntity entity = (LivingEntity) exprs[1].getSingle(event);
if (entity == null) return;
goat.ram(entity);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package lol.aabss.skuishy.elements.entities.expressions;

import ch.njol.skript.classes.Changer;
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 lol.aabss.skuishy.other.skript.EntityExpression;
import org.bukkit.entity.Goat;
import org.jetbrains.annotations.Nullable;

@Name("Goat - Horn")
@Description("Gets/sets the horn state of a goat.")
@Examples({
"set left horn state of {_goat} to true"
})
@Since("2.8")
public class ExprGoatHorn extends EntityExpression<Goat, Boolean> {

static {
register(ExprGoatHorn.class, Boolean.class, "[goat] (:left|right) horn [mode|state]", "entities");
}

@Override
public Boolean get(Goat goat) {
return tags.contains("left") ? goat.hasLeftHorn() : goat.hasRightHorn();
}

@Override
public void change(Goat goat, @Nullable Boolean aBoolean, Changer.ChangeMode mode) {
if (aBoolean != null && mode == Changer.ChangeMode.SET) {
if (tags.contains("left")) {
goat.setLeftHorn(aBoolean);
} else {
goat.setRightHorn(aBoolean);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package lol.aabss.skuishy.elements.entities.expressions.multiple;

import ch.njol.skript.classes.Changer;
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 lol.aabss.skuishy.other.skript.EntityExpression;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Goat;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.Nullable;

@Name("Enderman/Goat - Is Screaming")
@Description("Gets/sets the is screaming state of an enderman or goat.")
@Examples({
"set screaming state of {_enderman} to true"
})
@Since("2.8")
public class ExprIsScreaming extends EntityExpression<LivingEntity, Boolean> {

static {
register(ExprIsScreaming.class, Boolean.class, "[enderman|goat] screaming [state|mode]", "entities");
}

@Override
public Boolean get(LivingEntity entity) {
if (entity instanceof Enderman) {
return ((Enderman) entity).isScreaming();
} else if (entity instanceof Goat) {
return ((Goat) entity).isScreaming();
}
return null;
}

@Override
public void change(LivingEntity entity, @Nullable Boolean aBoolean, Changer.ChangeMode mode) {
if (aBoolean != null && mode == Changer.ChangeMode.SET) {
if (entity instanceof Enderman) {
((Enderman) entity).setScreaming(aBoolean);
} else if (entity instanceof Goat) {
((Goat) entity).setScreaming(aBoolean);
}
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/lol/aabss/skuishy/other/skript/EntityCondition.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package lol.aabss.skuishy.other.skript;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;

import java.util.List;

// not rlly needed but condition didnt wanna feel left out
public abstract class EntityCondition<T extends Entity> extends PropertyCondition<Entity> implements EntityStatement<T> {

protected List<String> tags;

protected abstract boolean run(T t);

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
this.tags = parseResult.tags;
return super.init(exprs, matchedPattern, isDelayed, parseResult);
}

@Override
public boolean check(Entity entity) {
if (accepts(entity)) {
Expand Down

0 comments on commit 44cb9a4

Please sign in to comment.