Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some armour stand syntax #6613

Open
wants to merge 18 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,76 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
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.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Armor Stand - Has Behaviour")
@Description("Allows users to check the behaviour of an armor stand (i.e. whether it is ticking or moving).")
@Examples({
"if {_armorstands::*} are not able to tick:",
"if {_armorstand} is able to move:"
})
@Since("INSERT VERSION")
public class CondArmorStandBehaviour extends Condition {

static {
if (Skript.methodExists(ArmorStand.class, "canTick"))
Skript.registerCondition(CondArmorStandBehaviour.class,
"%livingentities% (is|are) able to (:tick|move)",
"%livingentities% (isn't|is not|aren't|are not) able to (:tick|move)"
);
}

@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<LivingEntity> entities;
private boolean tick;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
entities = (Expression<LivingEntity>) exprs[0];
tick = parseResult.hasTag("tick");
setNegated(matchedPattern == 1);
return true;
}

@Override
public boolean check(Event event) {
if (tick)
return entities.check(event, stand -> stand instanceof ArmorStand && ((ArmorStand) stand).canTick(), isNegated());
return entities.check(event, stand -> stand instanceof ArmorStand && ((ArmorStand) stand).canMove(), isNegated());
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return entities.toString(event, debug) + " is " + (isNegated() ? "not " : "") + "able to " + (tick ? "tick" : "move");
}
}
@@ -0,0 +1,77 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
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.Keywords;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Armor Stand - Has Extremities")
@Description("Allows users to check the extremities of an armor stand (i.e. whether it has arms or a base plate).")
@Examples({
"send true if {_armorstand} has arms",
"if {_armorstand} has no base plate"
})
@Since("INSERT VERSION")
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved
@Keywords({"arms", "base plate"})
public class CondArmorStandExtremities extends Condition {

static {
Skript.registerCondition(CondArmorStandExtremities.class,
"%livingentities% (has|have) (:arms|[a] base[ ]plate)",
"%livingentities% (doesn't|does not|do not|don't) have (:arms|[a] base[ ]plate)"
);
}

@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<LivingEntity> entities;
private boolean arms;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved
entities = (Expression<LivingEntity>) exprs[0];
arms = parseResult.hasTag("arms");
setNegated(matchedPattern == 1);
return true;
}

@Override
public boolean check(Event event) {
if (arms)
return entities.check(event, stand -> stand instanceof ArmorStand && ((ArmorStand) stand).hasArms(), isNegated());
return entities.check(event, stand -> stand instanceof ArmorStand && ((ArmorStand) stand).hasBasePlate(), isNegated());
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return entities.toString(event, debug) + " has " + (isNegated() ? "no " : "") + (arms ? "arms" : "base plate");
}
}
@@ -0,0 +1,75 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
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.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Armor Stand - Has Properties")
@Description("Allows users to check the properties of an armor stand (i.e. whether it's small or a marker).")
@Examples({
"send true if {_armorstand} is small",
"if {_armorstands::*} are not markers:",
})
@Since("INSERT VERSION")
public class CondArmorStandProperties extends Condition {

static {
Skript.registerCondition(CondArmorStandProperties.class,
"%livingentities% (is|are) (:small|[a] marker[s])",
"%livingentities% (isn't|is not|aren't|are not) (:small|[a] marker[s])"
);
}

@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<LivingEntity> entities;
private boolean small;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved
entities = (Expression<LivingEntity>) exprs[0];
small = parseResult.hasTag("small");
setNegated(matchedPattern == 1);
return true;
}

@Override
public boolean check(Event event) {
if (small)
return entities.check(event, stand -> stand instanceof ArmorStand && ((ArmorStand) stand).isSmall(), isNegated());
return entities.check(event, stand -> stand instanceof ArmorStand && ((ArmorStand) stand).isMarker(), isNegated());
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return entities.toString(event, debug) + " is " + (isNegated() ? "not " : "") + (small ? "small" : "a marker");
}
}
83 changes: 83 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffArmorStandBehaviour.java
@@ -0,0 +1,83 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
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.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Armor Stand - Behaviour")
@Description("Allows users to modify the behaviour of an armor stand (i.e. whether it can tick and can move).")
@Examples({
"allow {_armorstand} to move",
"prevent {_armorstands::*} from ticking"
})
@Since("INSERT VERSION")
public class EffArmorStandBehaviour extends Effect {

static {
if (Skript.methodExists(ArmorStand.class, "canTick"))
Skript.registerEffect(EffArmorStandBehaviour.class,
"allow %livingentities% to (:tick|move)",
"prevent %livingentities% from being able to (:tick|move)"
);
}

private boolean prevent;
private boolean ticking;
@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<Entity> entities;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entities = (Expression<Entity>) exprs[0];
prevent = matchedPattern == 1;
ticking = parseResult.hasTag("tick");
return true;
}

@Override
protected void execute(Event event) {
for (Entity entity : entities.getArray(event)) {
if (entity instanceof ArmorStand) {
if (ticking) {
((ArmorStand) entity).setCanTick(!prevent);
} else {
((ArmorStand) entity).setCanMove(!prevent);
}
}
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (prevent ? "prevent " : "allow ") + entities.toString(event, debug) + (prevent ? " from being able to " : " to ") + (ticking ? "tick" : "move");
}
}
84 changes: 84 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffArmorStandExtremities.java
@@ -0,0 +1,84 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
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.Keywords;
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.ArmorStand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Armor Stand - Extremities")
@Description("Allows users to modify the extremities of an armor stand (i.e. whether its has arms or a base plate).")
@Examples({
"show {_armorstand}'s arms",
"hide the base plate of {_armorstands::*}"
})
@Since("INSERT VERSION")
@Keywords({"arms", "base plate"})
public class EffArmorStandExtremities extends Effect {

static {
Skript.registerEffect(EffArmorStandExtremities.class,
"(:show|hide) %livingentities%'[s] (base[ ]plate|:arms)",
"(:show|hide) [the] (base[ ]plate|:arms) of %livingentities%"
);
}

private boolean show;
private boolean arms;
@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<LivingEntity> entities;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entities = (Expression<LivingEntity>) exprs[0];
show = parseResult.hasTag("show");
arms = parseResult.hasTag("arms");
return true;
}

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof ArmorStand) {
if (arms) {
((ArmorStand) entity).setArms(show);
} else {
((ArmorStand) entity).setBasePlate(show);
}
}
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (show ? "show " : "hide ") + "the " + (arms ? "arms " : "base plate ") + "of " + entities.toString(event, debug);
}
}