Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 8 additions & 35 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,30 @@
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.bukkitutil.BurgerHelper;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.data.BukkitClasses;
import ch.njol.skript.classes.data.BukkitEventValues;
import ch.njol.skript.classes.data.DefaultComparators;
import ch.njol.skript.classes.data.DefaultConverters;
import ch.njol.skript.classes.data.DefaultFunctions;
import ch.njol.skript.classes.data.DefaultOperations;
import ch.njol.skript.classes.data.JavaClasses;
import ch.njol.skript.classes.data.SkriptClasses;
import ch.njol.skript.classes.data.*;
import ch.njol.skript.command.Commands;
import ch.njol.skript.doc.Documentation;
import ch.njol.skript.events.EvtSkript;
import ch.njol.skript.expressions.arithmetic.ExprArithmetic;
import ch.njol.skript.hooks.Hook;
import ch.njol.skript.lang.*;
import ch.njol.skript.lang.Condition.ConditionType;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.localization.Language;
import ch.njol.skript.localization.Message;
import ch.njol.skript.localization.PluralizingArgsMessage;
import ch.njol.skript.log.BukkitLoggerFilter;
import ch.njol.skript.log.CountingLogHandler;
import ch.njol.skript.log.ErrorDescLogHandler;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.skript.log.LogEntry;
import ch.njol.skript.log.LogHandler;
import ch.njol.skript.log.SkriptLogger;
import ch.njol.skript.log.TestingLogHandler;
import ch.njol.skript.log.Verbosity;
import ch.njol.skript.log.*;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.registrations.Feature;
import ch.njol.skript.test.runner.EffObjectives;
import ch.njol.skript.test.runner.SkriptAsyncJUnitTest;
import ch.njol.skript.test.runner.SkriptJUnitTest;
import ch.njol.skript.test.runner.SkriptTestEvent;
import ch.njol.skript.test.runner.TestMode;
import ch.njol.skript.test.runner.TestTracker;
import ch.njol.skript.test.runner.*;
import ch.njol.skript.timings.SkriptTimings;
import ch.njol.skript.update.ReleaseManifest;
import ch.njol.skript.update.ReleaseStatus;
import ch.njol.skript.update.UpdateManifest;
import ch.njol.skript.util.*;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.EmptyStacktraceException;
import ch.njol.skript.util.ExceptionUtils;
import ch.njol.skript.util.FileUtils;
import ch.njol.skript.util.Task;
import ch.njol.skript.util.Utils;
import ch.njol.skript.util.Version;
import ch.njol.skript.util.chat.BungeeConverter;
import ch.njol.skript.util.chat.ChatMessages;
import ch.njol.skript.variables.Variables;
Expand All @@ -62,12 +38,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -103,6 +74,7 @@
import org.skriptlang.skript.bukkit.itemcomponents.ItemComponentModule;
import org.skriptlang.skript.bukkit.log.runtime.BukkitRuntimeErrorConsumer;
import org.skriptlang.skript.bukkit.loottables.LootTableModule;
import org.skriptlang.skript.bukkit.misc.MiscModule;
import org.skriptlang.skript.bukkit.particles.ParticleModule;
import org.skriptlang.skript.bukkit.potion.PotionModule;
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
Expand Down Expand Up @@ -610,6 +582,7 @@ public void onEnable() {
new InteractionModule(),
new ItemComponentModule(),
new PotionModule(),
new MiscModule(),
new ParticleModule());
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/skriptlang/skript/bukkit/misc/MiscModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.skriptlang.skript.bukkit.misc;

import org.skriptlang.skript.addon.AddonModule;
import org.skriptlang.skript.addon.SkriptAddon;
import org.skriptlang.skript.bukkit.misc.expressions.ExprWithYawPitch;
import org.skriptlang.skript.registration.SyntaxRegistry;

public class MiscModule implements AddonModule {

@Override
public void load(SkriptAddon addon) {
SyntaxRegistry registry = addon.syntaxRegistry();
ExprWithYawPitch.register(registry);
}

@Override
public String name() {
return "bukkit/misc";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.skriptlang.skript.bukkit.misc.expressions;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.SyntaxStringBuilder;
import ch.njol.util.Kleenean;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.jspecify.annotations.Nullable;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxRegistry;

@Name("Location with Yaw/Pitch")
@Description("Returns the given locations with the specified yaw and/or pitch.")
@Example("set {_location} to player's location with yaw 0 and pitch 0")
@Since("INSERT VERSION")
public class ExprWithYawPitch extends PropertyExpression<Location, Location> {

public static void register(SyntaxRegistry registry) {
registry.register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(ExprWithYawPitch.class, Location.class)
.supplier(ExprWithYawPitch::new)
.addPattern("%locations% with [a] (:yaw|:pitch) [of] %number%")
.addPattern("%locations% with [a] yaw [of] %number% and [a] pitch [of] %number%")
.build());
}

private Expression<Number> yaw, pitch;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setExpr((Expression<? extends Location>) expressions[0]);
if (parseResult.hasTag("yaw")) {
yaw = (Expression<Number>) expressions[1];
} else if (parseResult.hasTag("pitch")) {
pitch = (Expression<Number>) expressions[1];
} else {
yaw = (Expression<Number>) expressions[1];
pitch = (Expression<Number>) expressions[2];
}
return true;
}

@Override
protected Location[] get(Event event, Location[] source) {
Number yaw = this.yaw != null ? this.yaw.getSingle(event) : null;
Number pitch = this.pitch != null ? this.pitch.getSingle(event) : null;
return get(source, location -> {
float finalYaw = yaw != null ? yaw.floatValue() : location.getYaw();
float finalPitch = pitch != null ? pitch.floatValue() : location.getPitch();
Location clone = location.clone();
clone.setYaw(finalYaw);
clone.setPitch(finalPitch);
return clone;
});
}

@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return new SyntaxStringBuilder(event, debug)
.append(getExpr(), "with")
.appendIf(yaw != null, "yaw", yaw)
.appendIf(yaw != null && pitch != null, "and")
.appendIf(pitch != null, "pitch", pitch)
.toString();
}

}
12 changes: 12 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprWithYawPitch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test "location with yaw and pitch":
set {_original} to event-location

assert (event-location with yaw 20)'s yaw is 20
assert (event-location with pitch 30)'s pitch is 30

set {_location} to event-location with yaw 40 and pitch 50
assert {_location}'s yaw is 40
assert {_location}'s pitch is 50

assert event-location's yaw is {_original}'s yaw with "Location with yaw mutated the original object"
assert event-location's pitch is {_original}'s pitch with "Location with pitch mutated the original object"