Skip to content

Commit

Permalink
Merge branch 'master' of github.com:SkriptLang/Skript
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Nov 4, 2019
2 parents 26ed895 + 78331f1 commit a061999
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 3 deletions.
49 changes: 49 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsSilent.java
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";
}
}
73 changes: 73 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffSilence.java
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);
}
}
10 changes: 7 additions & 3 deletions src/main/java/ch/njol/skript/expressions/ExprPlayerWeather.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ public Class<?>[] acceptChange(final ChangeMode mode) {
@SuppressWarnings("null")
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
final WeatherType type = delta == null ? WeatherType.CLEAR : (WeatherType) delta[0];
for (final Player p : getExpr().getArray(e)) {
type.setWeather(p);
if (delta == null) {
for (Player p : getExpr().getArray(e))
p.resetPlayerWeather();
} else {
WeatherType type = (WeatherType) delta[0];
for (Player p : getExpr().getArray(e))
type.setWeather(p);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/util/WeatherType.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void setWeather(Player player) {
case RAIN:
case THUNDER:
player.setPlayerWeather(org.bukkit.WeatherType.DOWNFALL);
break;
case CLEAR:
player.setPlayerWeather(org.bukkit.WeatherType.CLEAR);
break;
Expand Down
6 changes: 6 additions & 0 deletions src/test/skript/tests/misc/entity-silence.sk
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}

0 comments on commit a061999

Please sign in to comment.