Skip to content

Commit f96895a

Browse files
committed
Added test for NBT, fixed movement stop for players
1 parent 0cb5249 commit f96895a

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
send %caster nbt "test" = 12 for 12s;

example-plugin/src/main/java/fr/jamailun/examples/citizens/CasterTrait.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fr.jamailun.examples.citizens;
22

3-
import fr.jamailun.examples.ExamplePlugin;
43
import fr.jamailun.ultimatespellsystem.api.entities.SpellEntity;
54
import fr.jamailun.ultimatespellsystem.api.spells.Spell;
65
import net.citizensnpcs.api.trait.Trait;
@@ -10,10 +9,8 @@
109
import org.bukkit.entity.Entity;
1110
import org.bukkit.entity.LivingEntity;
1211
import org.bukkit.event.player.PlayerTeleportEvent;
13-
import org.bukkit.persistence.PersistentDataContainer;
1412
import org.bukkit.potion.PotionEffect;
1513
import org.jetbrains.annotations.NotNull;
16-
import org.jetbrains.annotations.Nullable;
1714

1815
import java.util.Optional;
1916
import java.util.UUID;
@@ -29,11 +26,6 @@ public void cast(Spell spell) {
2926
spell.castNotCancellable(this);
3027
}
3128

32-
@Override
33-
public void onAttach() {
34-
ExamplePlugin.info("Trait attached !");
35-
}
36-
3729
@Override
3830
public @NotNull UUID getUniqueId() {
3931
return getBukkitEntity()

plugin/src/main/java/fr/jamailun/ultimatespellsystem/extension/ExtensionLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static void loadCallbacks(JavaPlugin plugin) {
6161
return;
6262
}
6363
loadedCallbacks = true;
64-
UltimateSpellSystem.logInfo("Loading extension callbacks.");
64+
UltimateSpellSystem.logInfo("Loading extension callbacks and listeners.");
6565

6666
// Load elements
6767
loadCallback(plugin, new ProjectileLandCallbacks());
@@ -71,7 +71,7 @@ public static void loadCallbacks(JavaPlugin plugin) {
7171
// Load listeners
7272
registerEvents(plugin, new EntityMoveListener());
7373

74-
UltimateSpellSystem.logInfo("Loaded extension callbacks.");
74+
UltimateSpellSystem.logInfo("Loaded extension callbacks and listeners.");
7575
}
7676

7777
private static void loadCallback(JavaPlugin plugin, CallbackProvider<?> callbackProvider) {

plugin/src/main/java/fr/jamailun/ultimatespellsystem/extension/listeners/EntityMoveListener.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.event.EventHandler;
77
import org.bukkit.event.EventPriority;
88
import org.bukkit.event.Listener;
9+
import org.bukkit.event.player.PlayerMoveEvent;
910
import org.bukkit.persistence.PersistentDataContainer;
1011
import org.bukkit.persistence.PersistentDataType;
1112
import org.jetbrains.annotations.NotNull;
@@ -15,13 +16,20 @@
1516
*/
1617
public class EntityMoveListener implements Listener {
1718

18-
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
19+
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
1920
void onEntityMove(@NotNull EntityMoveEvent event) {
2021
if(shouldHandle(event.getEntity())) {
2122
event.setCancelled(true);
2223
}
2324
}
2425

26+
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
27+
void onPlayerMove(@NotNull PlayerMoveEvent event) {
28+
if(shouldHandle(event.getPlayer())) {
29+
event.setCancelled(true);
30+
}
31+
}
32+
2533
private boolean shouldHandle(@NotNull Entity entity) {
2634
PersistentDataContainer nbt = entity.getPersistentDataContainer();
2735
Boolean value = nbt.get(UssKeys.custom("cancel-movement"), PersistentDataType.BOOLEAN);

plugin/src/main/java/fr/jamailun/ultimatespellsystem/plugin/runner/nodes/functions/SendNbtNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void run(@NotNull SpellRuntime runtime) {
4141
NamespacedKey key = UssKeys.custom(Objects.requireNonNull(name, "Provided name for a send-NBT cannot be null."));
4242
Duration duration = Objects.requireNonNull(runtime.safeEvaluate(durationRef, Duration.class), "Provided duration for a send-NBT cannot be null.");
4343
Object value = Objects.requireNonNull(valueRef.evaluate(runtime), "Provided value for a send-NBT cannot be null.");
44+
UltimateSpellSystem.logDebug("SET NBT to " + targets + " : [" + key + "] = " + value);
4445

4546
Consumer<PersistentDataContainer> func = switch(value) {
4647
case Boolean bool -> nbt -> nbt.set(key, PersistentDataType.BOOLEAN, bool);
@@ -63,4 +64,8 @@ public void run(@NotNull SpellRuntime runtime) {
6364
}), duration.toTicks());
6465
}
6566

67+
@Override
68+
public String toString() {
69+
return "SEND_NBT(" + targetRef + ", '" + nameRef + "' = " + valueRef + "; for " + durationRef + ")";
70+
}
6671
}

0 commit comments

Comments
 (0)