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

Armor Expression #4813

Closed
wants to merge 10 commits into from
50 changes: 50 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprGetAllArmor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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.expressions;

import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.ExpressionType;

frackz marked this conversation as resolved.
Show resolved Hide resolved
public class ExprGetAllArmor extends SimplePropertyExpression<LivingEntity, ItemStack[]> {
frackz marked this conversation as resolved.
Show resolved Hide resolved

static {
Skript.registerExpression(ExprGetAllArmor.class, ItemStack[].class, ExpressionType.COMBINED, "%livingentities%'s armor");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of inheriting SimplePropertyExpression is to use SimplePropertyExpression's register method which is register(ExprArmor.class, ItemStack.class, "[full] armor", "livingentities"); this way you will benifit from its features

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't mark reviews as resolved if they're not

}

@Override
protected String getPropertyName() {
return "get all armor";
frackz marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public Class<? extends ItemStack[]> getReturnType() {
return ItemStack[].class;
frackz marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public @Nullable ItemStack[] convert(final LivingEntity f) {
frackz marked this conversation as resolved.
Show resolved Hide resolved
ItemStack[] armor=f.getEquipment().getArmorContents();
return armor;
frackz marked this conversation as resolved.
Show resolved Hide resolved
}
}