-
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds some more taming syntax (#6850)
* Adds tame syntax * Adds test * Adds Skript doc annotations * NotSoDelayed Suggestions Co-authored-by: NotSoDelayed <72163224+NotSoDelayed@users.noreply.github.com> * Suggestions - Removed 'de' as an option to untame a tameable entity - Adds untaming to test - Deletes value within variables instead of killing * Fixes test * Changed tests slightly * Auggestion Co-authored-by: NotSoDelayed <72163224+NotSoDelayed@users.noreply.github.com> * Suggestions * Changes to JetBrains nullable annotation --------- Co-authored-by: NotSoDelayed <72163224+NotSoDelayed@users.noreply.github.com> Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
- Loading branch information
1 parent
17c77f4
commit bc0fe53
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ch.njol.skript.conditions; | ||
|
||
import ch.njol.skript.conditions.base.PropertyCondition; | ||
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 org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Tameable; | ||
|
||
@Name("Is Tamed") | ||
@Description("Check if a tameable entity is tamed (horse, parrot, cat, etc.).") | ||
@Examples({ | ||
"send true if {_horse} is tamed", | ||
"tame {_horse} if {_horse} is untamed" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class CondIsTamed extends PropertyCondition<Entity> { | ||
|
||
static { | ||
register(CondIsTamed.class, "(tamed|domesticated)", "entities"); | ||
} | ||
|
||
@Override | ||
public boolean check(Entity entity) { | ||
return (entity instanceof Tameable) && ((Tameable) entity).isTamed(); | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "tamed"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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.util.Kleenean; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Tameable; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Tame / Untame") | ||
@Description("Tame a tameable entity (horse, parrot, cat, etc.).") | ||
@Examples({ | ||
"tame {_horse}", | ||
"untame {_horse}" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class EffTame extends Effect { | ||
|
||
static { | ||
Skript.registerEffect(EffTame.class, "[:un](tame|domesticate) %entities%"); | ||
} | ||
|
||
private boolean tame; | ||
private Expression<Entity> entities; | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
tame = !parseResult.hasTag("un"); | ||
entities = (Expression<Entity>) exprs[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
for (Entity entity : entities.getArray(event)) { | ||
if (entity instanceof Tameable) | ||
((Tameable) entity).setTamed(tame); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return (tame ? "tame " : "untame ") + entities.toString(event, debug); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
test "is tamed": | ||
spawn a horse at (spawn of world "world"): | ||
set {_e} to entity | ||
spawn an adult zombie at (spawn of world "world"): | ||
set {_z} to entity | ||
|
||
assert {_e} is not tamed with "a normally spawned horse should not be tamed" | ||
|
||
tame {_e} | ||
assert {_e} is tamed with "taming a horse should do exactly that" | ||
|
||
untame {_e} | ||
assert {_e} is not tamed with "untaming a horse should do exactly that" | ||
|
||
tame {_} | ||
tame {_z} | ||
assert {_} is not tamed with "taming null should do nothing" | ||
assert {_z} is not tamed with "taming an invalid entity should do nothing" | ||
|
||
delete entity within {_e} | ||
delete entity within {_z} |