Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
518223d
init commit
Burbulinis Dec 29, 2024
7fe97ee
more stuff
Burbulinis Dec 29, 2024
4a46169
Optimize imports
Burbulinis Dec 29, 2024
a0873c8
Trial spawner changes
Burbulinis Dec 29, 2024
8fce16c
Clean up
Burbulinis Dec 30, 2024
f5cbfaa
Merge remote-tracking branch 'origin/dev/feature' into feature/spawner
Burbulinis Dec 30, 2024
c3ff81f
Use new registration API
Burbulinis Dec 30, 2024
96f0fa7
Clean up warnings
Burbulinis Dec 30, 2024
9e0e7cc
Add expression and clean up patterns
Burbulinis Dec 30, 2024
7a1a809
Clean up patterns
Burbulinis Dec 30, 2024
82a8b97
Fix bug with SpawnRuleWrapper
Burbulinis Dec 30, 2024
035c55b
Remove old spawner type expression & clean up
Burbulinis Dec 30, 2024
aab1c96
Fix expression
Burbulinis Dec 30, 2024
7cae29f
Clean up, add AnyWeight and more expressions
Burbulinis Jan 1, 2025
55c97a2
Optimize imports
Burbulinis Jan 1, 2025
f798cca
Effects, conditions and general clean up
Burbulinis Jan 2, 2025
947416c
General clean-up
Burbulinis Jan 2, 2025
45be4ac
Separate events
Burbulinis Jan 2, 2025
3239e51
Optimize imports
Burbulinis Jan 2, 2025
3eef5df
Clean up
Burbulinis Jan 2, 2025
d0d23df
Add missing effects and expressions
Burbulinis Jan 3, 2025
852135a
Indentation
Burbulinis Jan 3, 2025
6779927
Add a default expr to AnyWeight
Burbulinis Jan 3, 2025
f56df91
Merge remote-tracking branch 'origin/dev/feature' into feature/spawner
Burbulinis Jan 3, 2025
366e2c4
Clean up spawn rule light level expressions and add runtime warnings
Burbulinis Jan 4, 2025
2582f60
Fix unnecessary check
Burbulinis Jan 4, 2025
33496a7
Optimize imports
Burbulinis Jan 4, 2025
d56ff41
Clean up and remove redundant checks in SpawnRuleWrapper
Burbulinis Jan 4, 2025
d6e193d
Make sure nothing passes the holy line
Burbulinis Jan 4, 2025
ac136f6
Utilize runtime warnings
Burbulinis Jan 4, 2025
59bcb92
Add effect and fix incorrect name
Burbulinis Jan 4, 2025
87410dc
Add condition and types in default.lang
Burbulinis Jan 4, 2025
233a923
Allow blockdatas in EffMakeOminous and CondIsOminous
Burbulinis Jan 4, 2025
bd034bd
fix
Burbulinis Jan 4, 2025
3687530
le javadocs
Burbulinis Jan 4, 2025
7cabe46
whoooops
Burbulinis Jan 4, 2025
49aaec2
the damn docs
Burbulinis Jan 5, 2025
e01f70e
Optimize imports
Burbulinis Jan 10, 2025
3ac935d
Begin tests
Burbulinis Jan 15, 2025
c6e7dff
more test stuff
Burbulinis Jan 19, 2025
789687f
clean up
Burbulinis Jan 19, 2025
21d3433
delete test file
Burbulinis Jan 19, 2025
631c56f
fix potential npe
Burbulinis Jan 19, 2025
a699071
oopsies
Burbulinis Jan 19, 2025
aaaaacc
clean up ExprSpawnerType
Burbulinis Jan 19, 2025
ee74ca3
Merge branch 'dev/feature' into feature/spawner
Burbulinis Jan 19, 2025
6fdf55a
fix tests
Burbulinis Jan 19, 2025
d90dd25
Merge remote-tracking branch 'fork/feature/spawner' into feature/spawner
Burbulinis Jan 19, 2025
a54d7f0
the tests
Burbulinis Jan 19, 2025
36920d2
fix tests
Burbulinis Jan 19, 2025
e7b273e
Changes
Burbulinis Jan 19, 2025
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
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.skriptlang.skript.bukkit.SkriptMetrics;
import org.skriptlang.skript.bukkit.spawner.SpawnerModule;
import org.skriptlang.skript.bukkit.breeding.BreedingModule;
import org.skriptlang.skript.bukkit.displays.DisplayModule;
import org.skriptlang.skript.bukkit.fishing.FishingModule;
Expand Down Expand Up @@ -560,6 +561,7 @@ public void onEnable() {
TagModule.load();
FurnaceModule.load();
LootTableModule.load();
skript.loadModules(new SpawnerModule());
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
setEnabled(false);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ch.njol.skript.lang.util.common.AnyAmount;
import ch.njol.skript.lang.util.common.AnyContains;
import ch.njol.skript.lang.util.common.AnyNamed;
import ch.njol.skript.lang.util.common.AnyWeighted;
import ch.njol.skript.lang.util.common.AnyValued;
import ch.njol.skript.localization.Noun;
import ch.njol.skript.localization.RegexMessage;
Expand Down Expand Up @@ -916,6 +917,16 @@ public String toVariableNameString(DynamicFunctionReference<?> function) {
.examples("{a} contains {b}")
.since("2.10")
);

Classes.registerClass(new AnyInfo<>(AnyWeighted.class, "weighted")
.user("weighteds?")
.name("Any Weighted Thing")
.description("Something that has a weight.")
.usage("")
.examples("the weight of {_thing}")
.since("INSERT VERSION")
.defaultExpression(new EventValueExpression<>(AnyWeighted.class))
);
}

}
122 changes: 0 additions & 122 deletions src/main/java/ch/njol/skript/expressions/ExprSpawnerType.java

This file was deleted.

64 changes: 64 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprWeight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ch.njol.skript.expressions;

import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.util.common.AnyWeighted;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

public class ExprWeight extends SimplePropertyExpression<Object, Integer> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs


static {
registerDefault(ExprWeight.class, Integer.class, "weight", "weighteds");
}

@Override
public @Nullable Integer convert(Object object) {
if (object instanceof AnyWeighted weighted)
return weighted.weight();
assert false;
return null;
}

@Override
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
return switch (mode) {
case SET, ADD, REMOVE -> CollectionUtils.array(Integer.class);
default -> null;
};
}

@Override
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
assert delta != null;
int weight = (int) delta[0];

for (Object object : getExpr().getArray(event)) {
if (!(object instanceof AnyWeighted weighted))
continue;

if (!weighted.supportsWeightChange()) {
error("The weight of this object cannot be changed.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only problem I have with this, is that it doesn't say what object that was provided cannot be changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It provides the line and file, but sure that is fair

continue;
}

switch (mode) {
case SET -> weighted.setWeight(weight);
case ADD -> weighted.setWeight(weighted.weight() + weight);
case REMOVE -> weighted.setWeight(weighted.weight() - weight);
}
}
}

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

@Override
protected String getPropertyName() {
return "the weight";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "the weight";
return "weight";

}

}
42 changes: 42 additions & 0 deletions src/main/java/ch/njol/skript/lang/util/common/AnyWeighted.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ch.njol.skript.lang.util.common;

import org.jetbrains.annotations.UnknownNullability;

/**
* A provider for anything with a weight.
* Anything implementing this (or convertible to this) can be used by the {@link ch.njol.skript.expressions.ExprWeight}
* property expression.
*
* @see AnyProvider
*/
@FunctionalInterface
public interface AnyWeighted extends AnyProvider {

/**
* @return This thing's weight
*/
@UnknownNullability Integer weight();

/**
* This is called before {@link #setWeight(Integer)}.
* If the result is false, setting the weight will never be attempted.
*
* @return Whether this supports being set
*/
default boolean supportsWeightChange() {
return false;
}

/**
* The behaviour for changing this thing's weight, if possible.
* If not possible, then {@link #supportsWeightChange()} should return false and this
* may throw an error.
*
* @param weight The weight to change
* @throws UnsupportedOperationException If this is impossible
*/
default void setWeight(Integer weight) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}

}
Loading
Loading