-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:SkriptLang/Skript
- Loading branch information
Showing
5 changed files
with
136 additions
and
3 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,49 @@ | ||
/** | ||
* 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 2011-2017 Peter Güttinger and contributors | ||
*/ | ||
package ch.njol.skript.conditions; | ||
|
||
import org.bukkit.entity.Entity; | ||
|
||
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; | ||
|
||
@Name("Is Silent") | ||
@Description("Checks whether an entity is silent i.e. its sounds are disabled.") | ||
@Examples("target entity is silent") | ||
@Since("INSERT VERSION") | ||
public class CondIsSilent extends PropertyCondition<Entity> { | ||
|
||
static { | ||
register(CondIsSilent.class, PropertyType.BE, "silent", "entities"); | ||
} | ||
|
||
@Override | ||
public boolean check(Entity entity) { | ||
return entity.isSilent(); | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "silent"; | ||
} | ||
} |
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,73 @@ | ||
/** | ||
* 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 2011-2017 Peter Güttinger and contributors | ||
*/ | ||
package ch.njol.skript.effects; | ||
|
||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.Event; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
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; | ||
|
||
@Name("Silence Entity") | ||
@Description("Controls whether or not an entity is silent.") | ||
@Examples("make target entity silent") | ||
@Since("INSERT VERSION") | ||
public class EffSilence extends Effect { | ||
|
||
static { | ||
Skript.registerEffect(EffSilence.class, | ||
"silence %entities%", | ||
"unsilence %entities%", | ||
"make %entities% silent", | ||
"make %entities% not silent"); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
private Expression<Entity> entities; | ||
private boolean silence; | ||
|
||
@SuppressWarnings({"unchecked", "null"}) | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
entities = (Expression<Entity>) exprs[0]; | ||
silence = matchedPattern % 2 == 0; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event e) { | ||
for (Entity entity : entities.getArray(e)) { | ||
entity.setSilent(silence); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return (silence ? "silence " : "unsilence ") + entities.toString(e, 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
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
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,6 @@ | ||
test "entity silence": | ||
spawn a pig at spawn of "world" | ||
set {_pig} to last spawned pig | ||
make {_pig} silent | ||
assert {_pig} is silent with "failed to make pig silent" | ||
delete {_pig} |