Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAbsolutionism committed Dec 29, 2024
1 parent 0b6cfc0 commit 2feb874
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
19 changes: 19 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ public String toVariableNameString(EnchantmentOffer eo) {
.since("INSERT VERSION"));

if (Skript.classExists("org.bukkit.entity.EntitySnapshot")) {
boolean SUPPORTS_GET_AS = Skript.methodExists(EntitySnapshot.class, "getAsString");
Classes.registerClass(new ClassInfo<>(EntitySnapshot.class, "entitysnapshot")
.user("entity ?snapshots?")
.name("Entity Snapshot")
Expand All @@ -1565,6 +1566,24 @@ public String toVariableNameString(EnchantmentOffer eo) {
"Individual attributes of a snapshot cannot be modified or retrieved.")
.requiredPlugins("Minecraft 1.20.2+")
.since("INSERT VERSION")
.parser(new Parser<EntitySnapshot>() {
@Override
public boolean canParse(ParseContext context) {
return false;
}

@Override
public String toString(EntitySnapshot o, int flags) {
if (SUPPORTS_GET_AS)
return o.getAsString();
return o.getEntityType() + " snapshot";
}

@Override
public String toVariableNameString(EntitySnapshot o) {
return o.getEntityType() + " snapshot";
}
})
);
}

Expand Down
16 changes: 6 additions & 10 deletions src/main/java/ch/njol/skript/classes/data/DefaultConverters.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package ch.njol.skript.classes.data;

import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.EntityUtils;
import ch.njol.skript.command.Commands;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.entity.EntityType;
import ch.njol.skript.entity.XpOrbData;
import ch.njol.skript.util.BlockInventoryHolder;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.Direction;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Experience;
import ch.njol.skript.util.*;
import ch.njol.skript.util.slot.Slot;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
Expand All @@ -24,6 +17,7 @@
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentOffer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntitySnapshot;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -180,6 +174,8 @@ public DefaultConverters() {}

Converters.registerConverter(String.class, World.class, Bukkit::getWorld);

Converters.registerConverter(EntitySnapshot.class, EntityData.class, snapshot -> EntityUtils.toSkriptEntityData(snapshot.getEntityType()));

// // Entity - String (UUID) // Very slow, thus disabled for now
// Converters.registerConverter(String.class, Entity.class, new Converter<String, Entity>() {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ test "entity snapshots" when running minecraft "1.20.2":
set {_snapshot} to entity snapshot of entity
clear entity
assert {_snapshot} is an entity snapshot with "Get entity snapshot is not an entity snapshot"
broadcast "EntityType: %entity type of {_snapshot}%"
assert type of {_snapshot} is a pig with "Entity type of entity snapshot should be a pig"
spawn {_snapshot} at test-location:
assert the max health of entity is 20 with "Max health did not stick to the spawned entity"
assert the health of entity is 20 with "Health did not stick to the spawned entity"
Expand Down

0 comments on commit 2feb874

Please sign in to comment.