Skip to content

Commit ca7eb8f

Browse files
authored
Merge branch 'dev/feature' into dev/ExprTestPlayer
2 parents ac8d665 + e2d8a36 commit ca7eb8f

32 files changed

+953
-147
lines changed

src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ch.njol.skript.aliases.ItemType;
55
import ch.njol.skript.bukkitutil.InventoryUtils;
66
import ch.njol.skript.command.CommandEvent;
7+
import ch.njol.skript.entity.EntityData;
78
import ch.njol.skript.events.bukkit.ScriptEvent;
89
import ch.njol.skript.events.bukkit.SkriptStartEvent;
910
import ch.njol.skript.events.bukkit.SkriptStopEvent;
@@ -170,6 +171,8 @@ public final class BukkitEventValues {
170171
"Use 'attacker' and/or 'victim' in damage/death events", EntityDamageEvent.class, EntityDeathEvent.class);
171172
EventValues.registerEventValue(EntityEvent.class, World.class, event -> event.getEntity().getWorld());
172173
EventValues.registerEventValue(EntityEvent.class, Location.class, event -> event.getEntity().getLocation());
174+
EventValues.registerEventValue(EntityEvent.class, EntityData.class, event -> EntityData.fromEntity(event.getEntity()),
175+
TIME_NOW, "Use 'type of attacker/victim' in damage/death events.", EntityDamageEvent.class, EntityDeathEvent.class);
173176
// EntityDamageEvent
174177
EventValues.registerEventValue(EntityDamageEvent.class, DamageCause.class, EntityDamageEvent::getCause);
175178
EventValues.registerEventValue(EntityDamageByEntityEvent.class, Projectile.class, event -> {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ch.njol.skript.conditions;
2+
3+
import ch.njol.skript.conditions.base.PropertyCondition;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import org.bukkit.entity.LivingEntity;
9+
import org.bukkit.entity.Strider;
10+
11+
@Name("Strider Is Shivering")
12+
@Description("Whether a strider is shivering.")
13+
@Example("""
14+
if last spawned strider is shivering:
15+
make last spawned strider stop shivering
16+
""")
17+
@Since("INSERT VERSION")
18+
public class CondStriderIsShivering extends PropertyCondition<LivingEntity> {
19+
20+
static {
21+
register(CondStriderIsShivering.class, "shivering", "livingentities");
22+
}
23+
24+
@Override
25+
public boolean check(LivingEntity entity) {
26+
return entity instanceof Strider strider && strider.isShivering();
27+
}
28+
29+
@Override
30+
protected String getPropertyName() {
31+
return "shivering";
32+
}
33+
34+
}
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,70 @@
11
package ch.njol.skript.effects;
22

3-
import org.bukkit.entity.Entity;
4-
import org.bukkit.event.Event;
5-
import org.bukkit.util.Vector;
6-
import org.jetbrains.annotations.Nullable;
7-
83
import ch.njol.skript.Skript;
94
import ch.njol.skript.doc.Description;
10-
import ch.njol.skript.doc.Examples;
5+
import ch.njol.skript.doc.Example;
116
import ch.njol.skript.doc.Name;
127
import ch.njol.skript.doc.Since;
138
import ch.njol.skript.lang.Effect;
149
import ch.njol.skript.lang.Expression;
1510
import ch.njol.skript.lang.SkriptParser.ParseResult;
1611
import ch.njol.skript.util.Direction;
1712
import ch.njol.util.Kleenean;
13+
import org.bukkit.entity.Entity;
14+
import org.bukkit.event.Event;
15+
import org.bukkit.util.Vector;
16+
import org.jetbrains.annotations.Nullable;
1817

19-
/**
20-
* @author Peter Güttinger
21-
*/
2218
@Name("Push")
2319
@Description("Push entities around.")
24-
@Examples({"push the player upwards",
25-
"push the victim downwards at speed 0.5"})
20+
@Example("push the player upwards")
21+
@Example("push the victim downwards at speed 0.5")
22+
@Example("push player along vector from player to player's target at speed 2")
2623
@Since("1.4.6")
2724
public class EffPush extends Effect {
25+
2826
static {
29-
Skript.registerEffect(EffPush.class, "(push|thrust) %entities% %direction% [(at|with) (speed|velocity|force) %-number%]");
27+
Skript.registerEffect(EffPush.class, "(push|thrust) %entities% [along] %direction% [(at|with) (speed|velocity|force) %-number%]");
3028
}
31-
32-
@SuppressWarnings("null")
29+
3330
private Expression<Entity> entities;
34-
@SuppressWarnings("null")
3531
private Expression<Direction> direction;
36-
@Nullable
37-
private Expression<Number> speed = null;
32+
private @Nullable Expression<Number> speed = null;
3833

3934
@SuppressWarnings({"unchecked", "null"})
4035
@Override
41-
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
36+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
4237
entities = (Expression<Entity>) exprs[0];
4338
direction = (Expression<Direction>) exprs[1];
4439
speed = (Expression<Number>) exprs[2];
4540
return true;
4641
}
4742

4843
@Override
49-
protected void execute(final Event e) {
50-
final Direction d = direction.getSingle(e);
51-
if (d == null)
44+
protected void execute(Event event) {
45+
Direction direction = this.direction.getSingle(event);
46+
if (direction == null)
5247
return;
53-
final Number v = speed != null ? speed.getSingle(e) : null;
54-
if (speed != null && v == null)
48+
Number speed = this.speed != null ? this.speed.getSingle(event) : null;
49+
if (this.speed != null && speed == null)
5550
return;
56-
final Entity[] ents = entities.getArray(e);
57-
for (final Entity en : ents) {
58-
assert en != null;
59-
final Vector mod = d.getDirection(en);
60-
if (v != null)
61-
mod.normalize().multiply(v.doubleValue());
62-
if (!(Double.isFinite(mod.getX()) && Double.isFinite(mod.getY()) && Double.isFinite(mod.getZ()))) {
51+
Entity[] entities = this.entities.getArray(event);
52+
for (Entity entity : entities) {
53+
Vector pushDirection = direction.getDirection(entity);
54+
if (speed != null)
55+
pushDirection.normalize().multiply(speed.doubleValue());
56+
if (!(Double.isFinite(pushDirection.getX()) && Double.isFinite(pushDirection.getY()) && Double.isFinite(pushDirection.getZ()))) {
6357
// Some component of the mod vector is not finite, so just stop
6458
return;
6559
}
66-
en.setVelocity(en.getVelocity().add(mod)); // REMIND add NoCheatPlus exception to players
60+
entity.setVelocity(entity.getVelocity().add(pushDirection));
6761
}
6862
}
6963

7064
@Override
71-
public String toString(final @Nullable Event e, final boolean debug) {
72-
return "push " + entities.toString(e, debug) + " " + direction.toString(e, debug) + (speed != null ? " at speed " + speed.toString(e, debug) : "");
65+
public String toString(@Nullable Event event, boolean debug) {
66+
return "push " + entities.toString(event, debug) + " " + direction.toString(event, debug) +
67+
(speed != null ? " at speed " + speed.toString(event, debug) : "");
7368
}
7469

7570
}

src/main/java/ch/njol/skript/effects/EffScriptFile.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22

33
import ch.njol.skript.ScriptLoader;
44
import ch.njol.skript.Skript;
5+
import ch.njol.skript.SkriptCommand;
6+
import ch.njol.skript.command.ScriptCommand;
57
import ch.njol.skript.doc.Description;
68
import ch.njol.skript.doc.Examples;
79
import ch.njol.skript.doc.Name;
810
import ch.njol.skript.doc.Since;
911
import ch.njol.skript.lang.Effect;
1012
import ch.njol.skript.lang.Expression;
13+
import ch.njol.skript.localization.Language;
14+
import ch.njol.skript.localization.PluralizingArgsMessage;
15+
import ch.njol.skript.log.LogEntry;
16+
import ch.njol.skript.log.LogHandler;
17+
import ch.njol.skript.log.RedirectingLogHandler;
18+
import ch.njol.skript.log.RetainingLogHandler;
19+
import ch.njol.skript.log.TimingLogHandler;
1120
import ch.njol.skript.registrations.Feature;
21+
import ch.njol.skript.util.Utils;
22+
import ch.njol.util.StringUtils;
23+
import org.bukkit.Bukkit;
24+
import org.bukkit.command.CommandSender;
1225
import org.jetbrains.annotations.Nullable;
1326
import org.jetbrains.annotations.UnknownNullability;
1427
import org.skriptlang.skript.lang.script.Script;
@@ -21,7 +34,10 @@
2134
import java.io.File;
2235
import java.io.FileFilter;
2336
import java.io.IOException;
37+
import java.util.HashSet;
2438
import java.util.Set;
39+
import java.util.logging.Level;
40+
import java.util.stream.Collectors;
2541

2642
@Name("Enable/Disable/Unload/Reload Script")
2743
@Description("""
@@ -41,9 +57,9 @@ public class EffScriptFile extends Effect {
4157

4258
static {
4359
Skript.registerEffect(EffScriptFile.class,
44-
"(1:(enable|load)|2:reload|3:disable|4:unload) script [file|named] %string%",
45-
"(1:(enable|load)|2:reload|3:disable|4:unload) skript file %string%",
46-
"(1:(enable|load)|2:reload|3:disable|4:unload) %scripts%"
60+
"(1:(enable|load)|2:reload|3:disable|4:unload) script [file|named] %string% [print:with errors]",
61+
"(1:(enable|load)|2:reload|3:disable|4:unload) skript file %string% [print:with errors]",
62+
"(1:(enable|load)|2:reload|3:disable|4:unload) %scripts% [print:with errors]"
4763
);
4864
/*
4965
The string-pattern must come first (since otherwise `script X` would match the expression)
@@ -57,12 +73,13 @@ public class EffScriptFile extends Effect {
5773

5874
private @UnknownNullability Expression<String> scriptNameExpression;
5975
private @UnknownNullability Expression<Script> scriptExpression;
60-
private boolean scripts, hasReflection;
76+
private boolean scripts, hasReflection, printErrors;
6177

6278
@Override
6379
@SuppressWarnings("unchecked")
6480
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
6581
this.mark = parseResult.mark;
82+
printErrors = parseResult.hasTag("print");
6683
switch (matchedPattern) {
6784
case 0, 1:
6885
this.scriptNameExpression = (Expression<String>) exprs[0];
@@ -77,20 +94,28 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
7794

7895
@Override
7996
protected void execute(Event event) {
97+
Set<CommandSender> recipients = new HashSet<>();
98+
if (printErrors) {
99+
recipients.addAll(Bukkit.getOnlinePlayers().stream()
100+
.filter(player -> player.hasPermission("skript.reloadnotify"))
101+
.collect(Collectors.toSet()));
102+
}
103+
RedirectingLogHandler logHandler = new RedirectingLogHandler(recipients, "").start();
104+
80105
if (scripts) {
81106
for (Script script : scriptExpression.getArray(event)) {
82107
@Nullable File file = script.getConfig().getFile();
83-
this.handle(file, script.getConfig().getFileName());
108+
this.handle(file, script.getConfig().getFileName(), logHandler);
84109
}
85110
} else {
86111
String name = scriptNameExpression.getSingle(event);
87-
if (name == null)
88-
return;
89-
this.handle(ScriptLoader.getScriptFromName(name), name);
112+
if (name != null)
113+
this.handle(ScriptLoader.getScriptFromName(name), name, logHandler);
90114
}
115+
logHandler.close();
91116
}
92117

93-
private void handle(@Nullable File scriptFile, @Nullable String name) {
118+
private void handle(@Nullable File scriptFile, @Nullable String name, OpenCloseable openCloseable) {
94119
if (scriptFile == null || !scriptFile.exists())
95120
return;
96121
if (name == null)
@@ -117,15 +142,15 @@ private void handle(@Nullable File scriptFile, @Nullable String name) {
117142
}
118143
}
119144

120-
ScriptLoader.loadScripts(scriptFile, OpenCloseable.EMPTY);
145+
ScriptLoader.loadScripts(scriptFile, openCloseable);
121146
break;
122147
case RELOAD:
123148
if (filter.accept(scriptFile))
124149
return;
125150

126151
this.unloadScripts(scriptFile);
127152

128-
ScriptLoader.loadScripts(scriptFile, OpenCloseable.EMPTY);
153+
ScriptLoader.loadScripts(scriptFile, openCloseable);
129154
break;
130155
case UNLOAD:
131156
if (hasReflection) { // if we don't use the new features this falls through into DISABLE
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package ch.njol.skript.effects;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Effect;
9+
import ch.njol.skript.lang.Expression;
10+
import ch.njol.skript.lang.SkriptParser.ParseResult;
11+
import ch.njol.skript.lang.SyntaxStringBuilder;
12+
import ch.njol.util.Kleenean;
13+
import org.bukkit.entity.LivingEntity;
14+
import org.bukkit.entity.Strider;
15+
import org.bukkit.event.Event;
16+
import org.jetbrains.annotations.Nullable;
17+
18+
@Name("Strider Shivering")
19+
@Description("Make a strider start/stop shivering.")
20+
@Example("""
21+
if last spawned strider is shivering:
22+
make last spawned strider stop shivering
23+
""")
24+
@Since("INSERT VERSION")
25+
public class EffStriderShivering extends Effect {
26+
27+
static {
28+
Skript.registerEffect(EffStriderShivering.class,
29+
"make %livingentities% start shivering",
30+
"force %livingentities% to start shivering",
31+
"make %livingentities% stop shivering",
32+
"force %livingentities% to stop shivering");
33+
}
34+
35+
private Expression<LivingEntity> entities;
36+
private boolean start;
37+
38+
@Override
39+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
40+
//noinspection unchecked
41+
entities = (Expression<LivingEntity>) exprs[0];
42+
start = matchedPattern <= 1;
43+
return true;
44+
}
45+
46+
@Override
47+
protected void execute(Event event) {
48+
for (LivingEntity entity : entities.getArray(event)) {
49+
if (entity instanceof Strider strider) {
50+
strider.setShivering(start);
51+
}
52+
}
53+
}
54+
55+
@Override
56+
public String toString(@Nullable Event event, boolean debug) {
57+
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
58+
builder.append("make", entities);
59+
if (start) {
60+
builder.append("start");
61+
} else {
62+
builder.append("stop");
63+
}
64+
builder.append("shivering");
65+
return builder.toString();
66+
}
67+
}

0 commit comments

Comments
 (0)