Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Skull Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenmai committed Oct 15, 2017
1 parent 28c2424 commit 3f82a02
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
Expand Up @@ -81,7 +81,7 @@ public void execute(CommandQueue queue, CommandEntry entry) {
else {
Optional<SoundType> opt = Sponge.getRegistry().getType(SoundType.class, soundName);
if (!opt.isPresent()) {
queue.handleError(entry, "Vanilla sound type not found: '" + soundName + "'!");
queue.handleError(entry, "Default sound type not found: '" + soundName + "'!");
return;
}
sound = opt.get();
Expand Down
Expand Up @@ -11,6 +11,9 @@
import com.denizenscript.denizen2sponge.utilities.flags.FlagMap;
import com.denizenscript.denizen2sponge.utilities.flags.FlagMapDataImpl;
import org.spongepowered.api.data.key.Key;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.SkullType;
import org.spongepowered.api.data.type.SkullTypes;
import org.spongepowered.api.item.inventory.ItemStack;

import java.util.HashMap;
Expand Down Expand Up @@ -214,6 +217,42 @@ public ItemStack getInternal() {
}
return ato;
});
// <--[tag]
// @Name ItemTag.skull_type
// @Updated 2017/10/15
// @Group Properties
// @ReturnType TextTag
// @Returns the type of skull this item is.
// -->
handlers.put("skull_type", (dat, obj) -> {
ItemStack item = ((ItemTag) obj).internal;
Optional<SkullType> type = item.get(Keys.SKULL_TYPE);
if (!type.isPresent()) {
if (!dat.hasFallback()) {
dat.error.run("This item is not a skull!");
}
return new NullTag();
}
return new TextTag(type.get().getId());
});
// <--[tag]
// @Name ItemTag.represented_player
// @Updated 2017/10/15
// @Group Properties
// @ReturnType TextTag
// @Returns the represented player of this skull item.
// -->
handlers.put("represented_player", (dat, obj) -> {
ItemStack item = ((ItemTag) obj).internal;
Optional<SkullType> type = item.get(Keys.SKULL_TYPE);
if (!type.isPresent() || type.get() != SkullTypes.PLAYER) {
if (!dat.hasFallback()) {
dat.error.run("This item is not a player skull!");
}
return new NullTag();
}
return new TextTag(item.get(Keys.REPRESENTED_PLAYER).get().getName().get());
});
}

public static ItemTag getFor(Action<String> error, String text) {
Expand Down
Expand Up @@ -11,10 +11,12 @@
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.tileentity.Skull;
import org.spongepowered.api.block.tileentity.TileEntity;
import org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier;
import org.spongepowered.api.data.key.Key;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.SkullTypes;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.util.AABB;
Expand Down Expand Up @@ -417,6 +419,40 @@ && LengthSquared(le.sub(loc.toVector3d())) < range * range) {
}
return new InventoryTag(((TileEntityCarrier) te.get()).getInventory());
});
// <--[tag]
// @Name LocationTag.skull_type
// @Updated 2017/10/15
// @Group Properties
// @ReturnType TextTag
// @Returns the type of skull that this location is holding.
// -->
handlers.put("skull_type", (dat, obj) -> {
Optional<TileEntity> te = ((LocationTag) obj).internal.toLocation().getTileEntity();
if (!te.isPresent() || !(te.get() instanceof Skull)) {
if (!dat.hasFallback()) {
dat.error.run("The block at this location is not a skull tile entity!");
}
return new NullTag();
}
return new TextTag(((Skull) te.get()).skullType().get().getId());
});
// <--[tag]
// @Name LocationTag.represented_player
// @Updated 2017/10/15
// @Group Properties
// @ReturnType TextTag
// @Returns the represented player of the skull that this location is holding.
// -->
handlers.put("represented_player", (dat, obj) -> {
Optional<TileEntity> te = ((LocationTag) obj).internal.toLocation().getTileEntity();
if (!te.isPresent() || !(te.get() instanceof Skull) || ((Skull) te.get()).skullType().get() != SkullTypes.PLAYER) {
if (!dat.hasFallback()) {
dat.error.run("The block at this location is not a player skull tile entity!");
}
return new NullTag();
}
return new TextTag(te.get().get(Keys.REPRESENTED_PLAYER).get().getName().get());
});
}

public static double LengthSquared(Location<World> loc) {
Expand Down

0 comments on commit 3f82a02

Please sign in to comment.