-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev/feature' into dev/wolf-variants
- Loading branch information
Showing
7 changed files
with
362 additions
and
35 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
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,74 @@ | ||
/** | ||
* 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.events; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptEvent; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.entity.EntityPotionEffectEvent; | ||
import org.bukkit.potion.PotionEffectType; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class EvtEntityPotion extends SkriptEvent { | ||
|
||
static { | ||
Skript.registerEvent("Entity Potion Effect", EvtEntityPotion.class, EntityPotionEffectEvent.class, | ||
"entity potion effect [modif[y|ication]] [[of] %-potioneffecttypes%] [due to %-entitypotioncause%]") | ||
.description("Called when an entity's potion effect is modified.", "This modification can include adding, removing or changing their potion effect.") | ||
.examples( | ||
"on entity potion effect modification:", | ||
"\t\tbroadcast \"A potion effect was added to %event-entity%!\" ", | ||
"", | ||
"on entity potion effect modification of night vision:") | ||
.since("INSERT VERSION"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private Expression<PotionEffectType> potionEffects; | ||
private Expression<EntityPotionEffectEvent.Cause> cause; | ||
|
||
@Override | ||
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||
potionEffects = (Expression<PotionEffectType>) args[0]; | ||
cause = (Expression<EntityPotionEffectEvent.Cause>) args[1]; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
EntityPotionEffectEvent potionEvent = (EntityPotionEffectEvent) event; | ||
boolean effectMatches = potionEffects == null || | ||
(potionEvent.getOldEffect() != null && potionEffects.check(event, effectType -> effectType.equals(potionEvent.getOldEffect().getType()))) || | ||
(potionEvent.getNewEffect() != null && potionEffects.check(event, effectType -> effectType.equals(potionEvent.getNewEffect().getType()))); | ||
|
||
boolean causeMatches = cause == null || cause.check(event, cause -> cause.equals(potionEvent.getCause())); | ||
|
||
return effectMatches && causeMatches; | ||
} | ||
|
||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "on entity potion effect modification"; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/ch/njol/skript/expressions/ExprPlayerChatCompletions.java
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,93 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.classes.Changer.ChangeMode; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.RequiredPlugins; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.expressions.base.SimplePropertyExpression; | ||
import ch.njol.util.coll.CollectionUtils; | ||
|
||
@Name("Player Chat Completions") | ||
@Description({ | ||
"The custom chat completion suggestions. You can add, set, remove, and clear them. Removing the names of online players with this expression is ineffective.", | ||
"This expression will not return anything due to Bukkit limitations." | ||
}) | ||
@Examples({ | ||
"add \"Skript\" and \"Njol\" to chat completions of all players", | ||
"remove \"text\" from {_p}'s chat completions", | ||
"clear player's chat completions" | ||
}) | ||
@RequiredPlugins("Spigot 1.19+") | ||
@Since("INSERT VERSION") | ||
public class ExprPlayerChatCompletions extends SimplePropertyExpression<Player, String> { | ||
|
||
static { | ||
if (Skript.methodExists(Player.class, "addCustomChatCompletions", Collection.class)) | ||
register(ExprPlayerChatCompletions.class, String.class, "[custom] chat completion[s]", "players"); | ||
} | ||
|
||
@Override | ||
public @Nullable String convert(Player player) { | ||
return null; // Due to Bukkit limitations | ||
} | ||
|
||
@Override | ||
public @Nullable Class<?>[] acceptChange(ChangeMode mode) { | ||
return switch (mode) { | ||
case ADD, SET, REMOVE, DELETE, RESET -> CollectionUtils.array(String[].class); | ||
default -> null; | ||
}; | ||
} | ||
|
||
@Override | ||
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
Player[] players = getExpr().getArray(event); | ||
if (players.length == 0) | ||
return; | ||
List<String> completions = new ArrayList<>(); | ||
if (delta != null && (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET)) { | ||
completions = Arrays.stream(delta) | ||
.filter(String.class::isInstance) | ||
.map(String.class::cast) | ||
.collect(Collectors.toList()); | ||
} | ||
switch (mode) { | ||
case DELETE, RESET, SET -> { | ||
for (Player player : players) | ||
player.setCustomChatCompletions(completions); | ||
} | ||
case ADD -> { | ||
for (Player player : players) | ||
player.addCustomChatCompletions(completions); | ||
} | ||
case REMOVE -> { | ||
for (Player player : players) | ||
player.removeCustomChatCompletions(completions); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Class<? extends String> getReturnType() { | ||
return String.class; | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "custom chat completions"; | ||
} | ||
|
||
} |
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
Oops, something went wrong.