|
| 1 | +/* |
| 2 | + * This file is part of Skript. |
| 3 | + * |
| 4 | + * Skript is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * Skript is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with Skript. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + * |
| 18 | + * Copyright 2011-2016 Peter Güttinger and contributors |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +package ch.njol.skript.expressions; |
| 23 | + |
| 24 | +import org.bukkit.Location; |
| 25 | +import org.bukkit.entity.Entity; |
| 26 | +import org.bukkit.entity.Player; |
| 27 | +import org.bukkit.event.Event; |
| 28 | +import org.eclipse.jdt.annotation.Nullable; |
| 29 | + |
| 30 | +import ch.njol.skript.classes.Changer.ChangeMode; |
| 31 | +import ch.njol.skript.doc.Description; |
| 32 | +import ch.njol.skript.doc.Events; |
| 33 | +import ch.njol.skript.doc.Examples; |
| 34 | +import ch.njol.skript.doc.Name; |
| 35 | +import ch.njol.skript.doc.Since; |
| 36 | +import ch.njol.skript.expressions.base.SimplePropertyExpression; |
| 37 | + |
| 38 | +@Name("Glowing") |
| 39 | +@Description("Indicates if targeted entity is glowing (new 1.9 effect) or not. Glowing entities can be seen through walls.") |
| 40 | +@Examples({"set glowing of player on"}) |
| 41 | +@Since("2.2-dev18") |
| 42 | +public class ExprGlowing extends SimplePropertyExpression<Entity, Boolean> { |
| 43 | + |
| 44 | + static { |
| 45 | + register(ExprGlowing.class, Boolean.class, "glowing", "entities"); |
| 46 | + } |
| 47 | + |
| 48 | + @SuppressWarnings("null") |
| 49 | + @Override |
| 50 | + public Boolean convert(final Entity e) { |
| 51 | + return e.isGlowing(); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected String getPropertyName() { |
| 56 | + return "glowing"; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public Class<Boolean> getReturnType() { |
| 61 | + return Boolean.class; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + @Nullable |
| 66 | + public Class<?>[] acceptChange(final ChangeMode mode) { |
| 67 | + if (mode == ChangeMode.SET || mode == ChangeMode.RESET) |
| 68 | + return new Class[] {Boolean.class}; |
| 69 | + return null; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException { |
| 74 | + for (final Entity entity : getExpr().getArray(e)) |
| 75 | + entity.setGlowing(delta == null ? false : (Boolean) delta[0]); |
| 76 | + } |
| 77 | +} |
0 commit comments