Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.19.4 displays #5601

Open
wants to merge 138 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
624c802
Fix gradle temp
TheLimeGlass Mar 23, 2023
9fd5a92
Merge branch 'master' of https://github.com/SkriptLang/Skript into fe…
TheLimeGlass Mar 23, 2023
0b69bea
Start on displays
TheLimeGlass Mar 23, 2023
69bad76
Save
TheLimeGlass Mar 23, 2023
b8d1ed8
More work
TheLimeGlass Mar 24, 2023
64c2635
update gradle.build
TheLimeGlass Mar 24, 2023
e98a596
stash
TheLimeGlass Mar 24, 2023
d2fe503
Merge master into feature/displays
TheLimeGlass Apr 6, 2023
6454ad9
Progress so far
TheLimeGlass Apr 11, 2023
5d2da29
Finish bulk add
TheLimeGlass Apr 12, 2023
4a74c8c
Merge branch 'master' of https://github.com/SkriptLang/Skript into fe…
TheLimeGlass Apr 12, 2023
60d9751
Finalize so far
TheLimeGlass Apr 12, 2023
1eb3a69
Minimize adventure api
TheLimeGlass Apr 12, 2023
8223ede
Fix static class check for not 1.19.4
TheLimeGlass Apr 12, 2023
3ee1296
Fix missing display classinfo in pattern under 1.19.4
TheLimeGlass Apr 12, 2023
edebb4a
Fix missing quaternions classinfo in pattern under 1.19.4
TheLimeGlass Apr 12, 2023
20252bb
Make sure test runs on only 1.19.4
TheLimeGlass Apr 12, 2023
6d3fe03
Address reviews and fix java 8
TheLimeGlass Apr 12, 2023
417a0a5
Apply suggestions from code review
TheLimeGlass Apr 13, 2023
50b28ce
Move classes
TheLimeGlass Apr 13, 2023
5ca7598
Apply changes
TheLimeGlass Apr 13, 2023
9e7992a
Move classes
TheLimeGlass Apr 13, 2023
fc8ee31
Class rename
TheLimeGlass Apr 14, 2023
275779f
Update to Spigot's fix to TextAlignment
TheLimeGlass Apr 14, 2023
d4064f7
Return null when using w of vector
TheLimeGlass Apr 15, 2023
6a1fab8
Update src/main/java/ch/njol/skript/expressions/ExprXYZComponent.java
TheLimeGlass Apr 15, 2023
aade8eb
Use brackets
TheLimeGlass Apr 15, 2023
e049f5f
Merge branch 'feature/displays' of https://github.com/SkriptLang/Skri…
TheLimeGlass Apr 15, 2023
178957d
Merge branch 'master' of https://github.com/SkriptLang/Skript into fe…
TheLimeGlass May 24, 2023
f6723dc
Add entity hiding
TheLimeGlass May 24, 2023
ab0e544
Add property init values for displays
TheLimeGlass May 25, 2023
dfcedf5
1.19.4 check
TheLimeGlass May 25, 2023
d35917e
Add rotate syntaxes
TheLimeGlass May 25, 2023
36ab6cd
Change example
TheLimeGlass May 25, 2023
725e9bc
Fix tests
TheLimeGlass May 25, 2023
17ae3c3
shadow syntax missing
TheLimeGlass May 27, 2023
11eefc2
Merge branch 'master' of https://github.com/SkriptLang/Skript into fe…
TheLimeGlass Jun 20, 2023
c43f3ec
Change setting
TheLimeGlass Jun 23, 2023
d6f2d04
Merge branch 'master' of https://github.com/SkriptLang/Skript into fe…
TheLimeGlass Jun 23, 2023
59de80f
Deal with conflicts
TheLimeGlass Jul 7, 2023
e178282
Revert change
TheLimeGlass Jul 7, 2023
47a9fbb
Merge branch 'master' into feature/displays
TheLimeGlass Jul 23, 2023
5c3755d
Merge branch 'master' into feature/displays
TheLimeGlass Jul 31, 2023
e670c84
Merge branch 'master' into feature/displays
TheLimeGlass Aug 5, 2023
c29dea5
Merge branch 'master' into feature/displays
TheLimeGlass Sep 16, 2023
3da7b37
Update src/main/java/ch/njol/skript/conditions/CondCanSee.java
TheLimeGlass Sep 16, 2023
3b50595
Fix imports from master merge
TheLimeGlass Sep 16, 2023
fa7b0d4
Get tests working
TheLimeGlass Sep 16, 2023
8cc5cf9
Merge branch 'dev/feature' into feature/displays
TheLimeGlass Sep 24, 2023
a30eed7
Merge branch 'dev/feature' into feature/displays
TheLimeGlass Sep 25, 2023
1fff7ca
Merge branch 'dev/feature' into feature/displays
TheLimeGlass Oct 1, 2023
2c053eb
Merge branch 'dev/feature' into feature/displays
TheLimeGlass Oct 13, 2023
5c3807a
Add color reset
TheLimeGlass Oct 17, 2023
b1128a6
Update ExprXYZComponent.java
TheLimeGlass Nov 12, 2023
37046ba
Update DisplayData.java
TheLimeGlass Nov 12, 2023
e36b5df
Update DisplayData.java
TheLimeGlass Nov 12, 2023
16a5c6b
Merge branch 'dev/feature' into feature/displays
TheLimeGlass Nov 19, 2023
a5fb080
Merge branch 'feature/displays' of https://github.com/SkriptLang/Skri…
TheLimeGlass Jan 9, 2024
fce4fc3
Change the package naming and merge item into its own class
TheLimeGlass Jan 9, 2024
2c39420
Manually update to dev/feature
TheLimeGlass Jan 9, 2024
a4927cc
Add versioning for hide effect
TheLimeGlass Jan 9, 2024
46202de
Add versioning for hide effect
TheLimeGlass Jan 9, 2024
0eba425
Change tests
TheLimeGlass Jan 9, 2024
6d7bc50
Update submodule skript-aliases
TheLimeGlass Jan 9, 2024
33ecaec
Fix tests
TheLimeGlass Jan 9, 2024
436a9ae
Fix tests
TheLimeGlass Jan 9, 2024
57c06ef
Fix tests
TheLimeGlass Jan 9, 2024
25600ac
Apply suggestions from code review
TheLimeGlass Feb 12, 2024
c112645
Apply changes
TheLimeGlass Feb 23, 2024
22eda32
Update to dev/feature
TheLimeGlass Feb 23, 2024
8400310
Add axis angle
TheLimeGlass Feb 23, 2024
c54fc72
Add axis angle
TheLimeGlass Feb 23, 2024
721aea7
Merge branch 'dev/feature' into feature/displays
Moderocky Apr 8, 2024
de4eb97
Merge branch 'dev/feature' into feature/displays
Moderocky May 3, 2024
1c145f9
Merge remote-tracking branch 'upstream/dev/feature' into feature/disp…
sovdeeth Jul 13, 2024
1384994
Update skript-aliases
sovdeeth Jul 13, 2024
7e33d72
fix merge error
sovdeeth Jul 13, 2024
ad69bbe
Remove axisangle and only present quaternion to users
sovdeeth Jul 13, 2024
ee3d8a5
Add tests for basic quaternion features, cleanup and fix bugs with Ex…
sovdeeth Jul 13, 2024
d1f09ca
Add ExprQuaternionAxisAngle and tests. Change float comparison to use…
sovdeeth Jul 13, 2024
07e6f23
Temporary change to build.gradle for java 17
sovdeeth Jul 13, 2024
2fb8fc2
Revert "Update src/main/java/ch/njol/skript/conditions/CondCanSee.java"
sovdeeth Jul 13, 2024
a02074f
Reverts entity hiding commits in favor of #6867
sovdeeth Jul 13, 2024
bf0b3ab
version check for EQAA and displaydata cleanup
sovdeeth Jul 13, 2024
093fa83
force 'rotation' in EQAA, fix classdef error, add itemtypes to block …
sovdeeth Jul 13, 2024
a00cf5b
Clean up colorOf, add tests, add alpha parameter to rgb function and …
sovdeeth Jul 14, 2024
400d972
update Nullable annotations to jetbrains
sovdeeth Jul 14, 2024
fa9e72b
Fix <1.19 errors (just for actions) and fix subtle issues with xyz co…
sovdeeth Jul 14, 2024
77a843b
rename package to bukkit
sovdeeth Jul 14, 2024
937bb37
finish package refactor
sovdeeth Jul 14, 2024
5c4ecbe
Add tests for billboarding, rework display brightness and add tests, …
sovdeeth Jul 15, 2024
0c15145
tests + allow setting override to a single number
sovdeeth Jul 15, 2024
a9c7110
tests, cleanup, and bug fixes for glow override and hegiht/width
sovdeeth Jul 15, 2024
0c6a293
Merge branch 'dev/feature' into feature/displays
sovdeeth Jul 15, 2024
41c61f1
Interpolation and Shadow tests + correct reset value for shadow stren…
sovdeeth Jul 17, 2024
ed6208c
Tests and cleanup for teleportation duration, remove number from chan…
sovdeeth Jul 17, 2024
d4e1c8d
Transformation tests, cleanup, bugfixes. Removed unnecessary Joml uti…
sovdeeth Jul 18, 2024
9148441
wrong version check for teleportation duration
sovdeeth Jul 18, 2024
124b046
Merge remote-tracking branch 'upstream/dev/feature' into feature/disp…
sovdeeth Jul 19, 2024
655550b
Display view range tests, cleanup, finite guard, switch to Timespan#g…
sovdeeth Jul 21, 2024
2846e4b
strip licenses
sovdeeth Jul 23, 2024
949b454
cleanup, tests for ItemDisplayTransfrom. Fixed default from being FIX…
sovdeeth Jul 23, 2024
c92f75a
Remove ItemOfItemDisplay (redundant), cleanup/test the text display e…
sovdeeth Jul 23, 2024
e089ddc
small cleanup to textdisplayexprs and rename ItemFrameSlot to be more…
sovdeeth Jul 23, 2024
045d75c
rework ExprRotate
sovdeeth Jul 23, 2024
9d94d43
Completely rework rotation with new Rotator API. Add support for quat…
sovdeeth Jul 23, 2024
234be4b
cleanup rotations - java 17 tests will fail until legacy tests are re…
sovdeeth Jul 23, 2024
3436ae8
Merge branch 'dev/feature' into feature/displays
sovdeeth Aug 7, 2024
b180eed
Fix bugs with rotation, adds tests
sovdeeth Aug 8, 2024
df1a43e
Merge branch 'feature/displays' of https://github.com/SkriptLang/Skri…
sovdeeth Aug 8, 2024
49dbe0b
Add drop shadow syntax and small cleanup of ExprTextOf
sovdeeth Aug 14, 2024
a54958a
See through blocks syntax
sovdeeth Aug 14, 2024
568dde5
Update ExprRotate.java
sovdeeth Aug 14, 2024
d7c09af
remove extra [a]'s
sovdeeth Aug 14, 2024
0e105cf
whoops! reverts a change to number accuracy config done for testing
sovdeeth Aug 14, 2024
a0117a9
Module-ize, package infos, remove mc version checks
sovdeeth Aug 16, 2024
a7b31ce
rename display.expressions package, use for loops, move displaydata
sovdeeth Aug 16, 2024
d54d350
display data improvements
sovdeeth Aug 17, 2024
33db584
requested changes 1
sovdeeth Aug 17, 2024
1931b62
update switches and remove banana
sovdeeth Aug 17, 2024
dea8320
requested changes 2
sovdeeth Aug 17, 2024
db3302d
Merge branch 'dev/feature' into feature/displays
sovdeeth Aug 17, 2024
e43eb3d
Apply suggestions from code review
sovdeeth Aug 30, 2024
5b763cc
Apply suggestions from code review
sovdeeth Aug 30, 2024
926ef64
fix expritemofentity description
sovdeeth Aug 30, 2024
371c3d8
Merge branch 'dev/feature' into feature/displays
sovdeeth Aug 30, 2024
a244db1
Apply suggestions from code review
sovdeeth Aug 31, 2024
84f5b6e
Update ExprDisplayHeightWidth.java
sovdeeth Aug 31, 2024
81e4b1e
Merge branch 'dev/feature' into feature/displays
sovdeeth Aug 31, 2024
fdc733f
Merge branch 'dev/feature' into feature/displays
sovdeeth Sep 15, 2024
e8a394f
Merge branch 'dev/feature' into feature/displays
sovdeeth Sep 19, 2024
dc82a4f
Merge branch 'dev/feature' into feature/displays
sovdeeth Sep 21, 2024
9aa4289
Apply suggestions from code review
sovdeeth Sep 21, 2024
f7a7bb6
requested changes 2 + rotator docs
sovdeeth Sep 22, 2024
ca655f4
requested changes
sovdeeth Oct 2, 2024
64656bf
Apply suggestions from code review
sovdeeth Oct 2, 2024
76cca4e
Merge branch 'dev/feature' into feature/displays
sovdeeth Oct 2, 2024
17664a9
requested changes!
sovdeeth Oct 2, 2024
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
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ dependencies {
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.2'

implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21-R0.1-SNAPSHOT'
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'

// Comes from Minecraft including Guava or Gson
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'

// bundled with Minecraft 1.19.4+ for display entity transforms
implementation group: 'org.joml', name: 'joml', version: '1.10.5'

// Plugin hook libraries
implementation group: 'com.sk89q.worldguard', name: 'worldguard-legacy', version: '7.0.0-SNAPSHOT'
implementation group: 'net.milkbowl.vault', name: 'Vault', version: '1.7.3', {
exclude group: 'org.bstats', module: 'bstats-bukkit'
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.skriptlang.skript.bukkit.SkriptMetrics;
import org.skriptlang.skript.bukkit.displays.DisplayModule;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.converter.Converter;
Expand Down Expand Up @@ -541,6 +542,9 @@ public void onEnable() {
try {
getAddonInstance().loadClasses("ch.njol.skript",
"conditions", "effects", "events", "expressions", "entity", "sections", "structures");
getAddonInstance().loadClasses("org.skriptlang.skript.bukkit", "misc");
// todo: become proper module once registry api is merged
DisplayModule.load();
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
setEnabled(false);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/ch/njol/skript/aliases/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,22 @@ public Material getMaterial() {
return data.getType();
}

/**
* @return A random block material this ItemType represents.
* @throws IllegalStateException If {@link #hasBlock()} is false.
*/
public Material getBlockMaterial() {
List<ItemData> blockItemDatas = new ArrayList<>();
for (ItemData d : types) {
if (d.type.isBlock())
blockItemDatas.add(d);
}
if (blockItemDatas.isEmpty())
throw new IllegalStateException("This ItemType does not represent a material. " +
"ItemType#hasBlock() should return true before invoking this method.");
return blockItemDatas.get(random.nextInt(blockItemDatas.size())).getType();
}

/**
* Returns a base item type of this. Essentially, this calls
* {@link ItemData#aliasCopy()} on all datas and creates a new type
Expand All @@ -1427,4 +1443,5 @@ public ItemType getBaseType() {
}
return copy;
}

}
77 changes: 37 additions & 40 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,32 @@
*/
package ch.njol.skript.classes.data;

import java.io.StreamCorruptedException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptConfig;
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.BukkitUtils;
import ch.njol.skript.bukkitutil.EnchantmentUtils;
import ch.njol.skript.bukkitutil.ItemUtils;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.ConfigurationSerializer;
import ch.njol.skript.classes.EnumClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.classes.registry.RegistryClassInfo;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.expressions.ExprDamageCause;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.util.SimpleLiteral;
import ch.njol.skript.localization.Language;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.PotionEffectUtils;
import ch.njol.skript.util.StringMode;
import ch.njol.util.StringUtils;
import ch.njol.yggdrasil.Fields;
import io.papermc.paper.world.MoonPhase;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Difficulty;
Expand Down Expand Up @@ -80,37 +94,19 @@
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.CachedServerIcon;
import org.bukkit.util.Vector;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptConfig;
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.EnchantmentUtils;
import ch.njol.skript.bukkitutil.ItemUtils;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.ConfigurationSerializer;
import ch.njol.skript.classes.EnumClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.classes.registry.RegistryClassInfo;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.expressions.ExprDamageCause;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.util.SimpleLiteral;
import ch.njol.skript.localization.Language;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.PotionEffectUtils;
import ch.njol.skript.util.StringMode;
import ch.njol.util.StringUtils;
import ch.njol.yggdrasil.Fields;
import io.papermc.paper.world.MoonPhase;
import org.jetbrains.annotations.Nullable;

/**
* @author Peter Güttinger
*/
import java.io.StreamCorruptedException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class BukkitClasses {

public BukkitClasses() {}
Expand Down Expand Up @@ -1527,6 +1523,7 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Transform Reason")
.description("Represents a transform reason of an <a href='events.html#entity transform'>entity transform event</a>.")
.since("2.8.0"));

Classes.registerClass(new EnumClassInfo<>(EntityPotionEffectEvent.Cause.class, "entitypotioncause", "entity potion causes")
.user("(entity )?potion ?effect ?cause")
.name("Entity Potion Cause")
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/ch/njol/skript/classes/data/DefaultComparators.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.entity.RabbitData;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.Color;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Experience;
Expand Down Expand Up @@ -75,20 +76,28 @@ public DefaultComparators() {}
static {

// Number - Number
Comparators.registerComparator(Number.class, Number.class, new Comparator<Number, Number>() {
Comparators.registerComparator(Number.class, Number.class, new Comparator<>() {
@Override
public Relation compare(Number n1, Number n2) {
if (n1 instanceof Long && n2 instanceof Long)
return Relation.get(n1.longValue() - n2.longValue());
Double d1 = n1.doubleValue(),
d2 = n2.doubleValue();
double epsilon = Skript.EPSILON;
@SuppressWarnings("WrapperTypeMayBePrimitive") Double d1, d2;
if (n1 instanceof Float || n2 instanceof Float) {
d1 = (double) n1.floatValue();
d2 = (double) n2.floatValue();
epsilon = Math.min(d1, d2) * 1e-6; // dynamic epsilon
} else {
d1 = n1.doubleValue();
d2 = n2.doubleValue();
}
if (d1.isNaN() || d2.isNaN()) {
return Relation.SMALLER;
} else if (d1.isInfinite() || d2.isInfinite()) {
return d1 > d2 ? Relation.GREATER : d1 < d2 ? Relation.SMALLER : Relation.EQUAL;
} else {
double diff = d1 - d2;
if (Math.abs(diff) < Skript.EPSILON)
if (Math.abs(diff) < epsilon)
return Relation.EQUAL;
return Relation.get(diff);
}
Expand Down Expand Up @@ -656,6 +665,11 @@ public boolean supportsOrdering() {

// Potion Effect Type
Comparators.registerComparator(PotionEffectType.class, PotionEffectType.class, (one, two) -> Relation.get(one.equals(two)));

// Color - Color
Comparators.registerComparator(Color.class, Color.class, (one, two) -> Relation.get(one.asBukkitColor().equals(two.asBukkitColor())));
Comparators.registerComparator(Color.class, org.bukkit.Color.class, (one, two) -> Relation.get(one.asBukkitColor().equals(two)));
Comparators.registerComparator(org.bukkit.Color.class, org.bukkit.Color.class, (one, two) -> Relation.get(one.equals(two)));
}

}
67 changes: 60 additions & 7 deletions src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import ch.njol.skript.registrations.DefaultClasses;
import ch.njol.skript.util.Color;
import ch.njol.skript.util.ColorRGB;
import ch.njol.skript.util.Contract;
import ch.njol.skript.util.Date;
import ch.njol.util.Math2;
import ch.njol.util.StringUtils;
Expand All @@ -42,7 +43,9 @@
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.util.Contract;
import org.joml.AxisAngle4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

import java.math.BigDecimal;
import java.math.RoundingMode;
Expand Down Expand Up @@ -525,19 +528,25 @@ public Long[] executeSimple(Object[][] params) {
Functions.registerFunction(new SimpleJavaFunction<Color>("rgb", new Parameter[] {
new Parameter<>("red", DefaultClasses.LONG, true, null),
new Parameter<>("green", DefaultClasses.LONG, true, null),
new Parameter<>("blue", DefaultClasses.LONG, true, null)
new Parameter<>("blue", DefaultClasses.LONG, true, null),
new Parameter<>("alpha", DefaultClasses.LONG, true, new SimpleLiteral<>(255L,true))
}, DefaultClasses.COLOR, true) {
@Override
public ColorRGB[] executeSimple(Object[][] params) {
Long red = (Long) params[0][0];
Long green = (Long) params[1][0];
Long blue = (Long) params[2][0];
Long alpha = (Long) params[3][0];

return CollectionUtils.array(new ColorRGB(red.intValue(), green.intValue(), blue.intValue()));
return CollectionUtils.array(ColorRGB.fromRGBA(red.intValue(), green.intValue(), blue.intValue(), alpha.intValue()));
}
}).description("Returns a RGB color from the given red, green and blue parameters.")
.examples("dye player's leggings rgb(120, 30, 45)")
.since("2.5");
}).description("Returns a RGB color from the given red, green and blue parameters. Alpha values can be added optionally, " +
"but these only take affect in certain situations, like text display backgrounds.")
.examples(
"dye player's leggings rgb(120, 30, 45)",
"set the colour of a text display to rgb(10, 50, 100, 50)"
)
.since("2.5, INSERT VERSION (alpha)");

Functions.registerFunction(new SimpleJavaFunction<Player>("player", new Parameter[] {
new Parameter<>("nameOrUUID", DefaultClasses.STRING, true, null),
Expand Down Expand Up @@ -634,6 +643,50 @@ public String[] executeSimple(Object[][] params) {
"concat(\"foo \", 100, \" bar\") # foo 100 bar"
).since("2.9.0");

// joml functions - for display entities
{
if (Skript.classExists("org.joml.Quaternionf")) {
Functions.registerFunction(new SimpleJavaFunction<>("quaternion", new Parameter[]{
new Parameter<>("w", DefaultClasses.NUMBER, true, null),
new Parameter<>("x", DefaultClasses.NUMBER, true, null),
new Parameter<>("y", DefaultClasses.NUMBER, true, null),
new Parameter<>("z", DefaultClasses.NUMBER, true, null)
}, Classes.getExactClassInfo(Quaternionf.class), true) {
@Override
public Quaternionf[] executeSimple(Object[][] params) {
double w = ((Number) params[0][0]).doubleValue();
double x = ((Number) params[1][0]).doubleValue();
double y = ((Number) params[2][0]).doubleValue();
double z = ((Number) params[3][0]).doubleValue();
return CollectionUtils.array(new Quaternionf(x, y, z, w));
}
})
.description("Returns a quaternion from the given W, X, Y and Z parameters. ")
.examples("quaternion(1, 5.6, 45.21, 10)")
.since("INSERT VERSION");
}

if (Skript.classExists("org.joml.AxisAngle4f")) {
Functions.registerFunction(new SimpleJavaFunction<>("axisAngle", new Parameter[]{
new Parameter<>("angle", DefaultClasses.NUMBER, true, null),
new Parameter<>("axis", DefaultClasses.VECTOR, true, null)
}, Classes.getExactClassInfo(Quaternionf.class), true) {
@Override
public Quaternionf[] executeSimple(Object[][] params) {
float angle = (float) (((Number) params[0][0]).floatValue() / 180 * Math.PI);
Vector v = ((Vector) params[1][0]);
if (v.isZero() || !Double.isFinite(v.getX()) || !Double.isFinite(v.getY()) || !Double.isFinite(v.getZ()))
return new Quaternionf[0];
Vector3f axis = ((Vector) params[1][0]).toVector3f();
return CollectionUtils.array(new Quaternionf(new AxisAngle4f(angle, axis)));
}
})
.description("Returns a quaternion from the given angle (in degrees) and axis (as a vector). This represents a rotation around the given axis by the given angle.")
.examples("axisangle(90, (vector from player's facing))")
.since("INSERT VERSION");
}
} // end joml functions

}

}
38 changes: 38 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/JavaClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/
package ch.njol.skript.classes.data;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptConfig;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.VariableString;
import ch.njol.skript.lang.util.SimpleLiteral;
Expand All @@ -32,6 +34,7 @@
import ch.njol.util.StringUtils;
import ch.njol.yggdrasil.Fields;
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;

import java.util.regex.Pattern;

Expand Down Expand Up @@ -627,5 +630,40 @@ public boolean mustSyncDeserialization() {
return false;
}
}));

// joml type - for display entities
if (Skript.classExists("org.joml.Quaternionf"))
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
Classes.registerClass(new ClassInfo<>(Quaternionf.class, "quaternion")
.user("quaternionf?s?")
.name("Quaternion")
.description("Quaternions are four dimensional vectors, often used for representing rotations.")
.since("INSERT VERSION")
.parser(new Parser<>() {
public boolean canParse(ParseContext context) {
return false;
}

@Override
public String toString(Quaternionf quaternion, int flags) {
return "w:" + Skript.toString(quaternion.w()) + ", x:" + Skript.toString(quaternion.x()) + ", y:" + Skript.toString(quaternion.y()) + ", z:" + Skript.toString(quaternion.z());
}

@Override
public String toVariableNameString(Quaternionf quaternion) {
return quaternion.w() + "," + quaternion.x() + "," + quaternion.y() + "," + quaternion.z();
}
})
.defaultExpression(new EventValueExpression<>(Quaternionf.class))
.cloner(quaternion -> {
try {
// Implements cloneable, but doesn't return a Quaternionf.
// org.joml improper override. Returns Object.
return (Quaternionf) quaternion.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}));

}

}
Loading
Loading