Skip to content

Commit

Permalink
Just some tiny changes to CondIsWearing
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeezburga committed Sep 3, 2024
1 parent 94af02a commit 9e42efe
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions src/main/java/ch/njol/skript/conditions/CondIsWearing.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
/**
* 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 org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType;
Expand All @@ -35,14 +11,22 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;

/**
* @author Peter Güttinger
*/
@Name("Is Wearing")
@Description("Checks whether a player is wearing some armour.")
@Examples({"player is wearing an iron chestplate and iron leggings",
"player is wearing all diamond armour"})
@Description("Checks whether an entity is wearing some items (usually armor).")
@Examples({
"player is wearing an iron chestplate and iron leggings",
"player is wearing all diamond armour",
"target is wearing wolf armor"
})
@Since("1.0")
public class CondIsWearing extends Condition {

Expand All @@ -57,32 +41,32 @@ public class CondIsWearing extends Condition {

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
public boolean init(Expression<?>[] vars, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entities = (Expression<LivingEntity>) vars[0];
types = (Expression<ItemType>) vars[1];
setNegated(matchedPattern == 1);
return true;
}

@Override
public boolean check(final Event e) {
return entities.check(e,
en -> types.check(e,
t -> {
EntityEquipment equip = en.getEquipment();
public boolean check(Event event) {
return entities.check(event,
entity -> types.check(event,
type -> {
EntityEquipment equip = entity.getEquipment();
if (equip == null)
return false; // No equipment -> not wearing anything
for (final ItemStack is : equip.getArmorContents()) {
if (t.isOfType(is) ^ t.isAll())
return !t.isAll();
for (ItemStack armorContent : equip.getArmorContents()) {
if (type.isOfType(armorContent) ^ type.isAll())
return !type.isAll();
}
return t.isAll();
return type.isAll();
}),
isNegated());
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
public String toString(@Nullable Event e, boolean debug) {
return PropertyCondition.toString(this, PropertyType.BE, e, debug, entities,
"wearing " + types.toString(e, debug));
}
Expand Down

0 comments on commit 9e42efe

Please sign in to comment.