use of net.minecraft.server.v1_16_R1.NBTTagCompound in project MyMaid2 by jaoafa.
the class Cmd_Test method onCommand.
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (!(sender instanceof Player)) {
return true;
}
Player player = (Player) sender;
if (args.length != 1) {
SendMessage(sender, cmd, "arg 1 only");
return true;
}
if (args[0].equalsIgnoreCase("get")) {
ItemStack item = new ItemStack(Material.STONE);
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
NBTTagCompound nbttag = nms.getTag();
if (nbttag == null) {
nbttag = new NBTTagCompound();
}
UUID uuid = UUID.randomUUID();
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
SendMessage(sender, cmd, "NoSuchAlgorithmException error");
return true;
}
byte[] digest = md.digest(uuid.toString().getBytes());
String id = DatatypeConverter.printHexBinary(digest);
if (id == null) {
SendMessage(sender, cmd, "id null");
return true;
}
nbttag.setString("MyMaid_testID", id);
nms.setTag(nbttag);
item = CraftItemStack.asBukkitCopy(nms);
player.getInventory().addItem(item);
SendMessage(sender, cmd, "added");
return true;
} else if (args[0].equalsIgnoreCase("check")) {
ItemStack item = player.getInventory().getItemInMainHand();
if (item == null) {
SendMessage(sender, cmd, "item null");
return true;
}
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
NBTTagCompound nbttag = nms.getTag();
if (nbttag == null) {
SendMessage(sender, cmd, "nbttag null");
return true;
}
String id = nbttag.getString("MyMaid_testID");
if (id == null) {
SendMessage(sender, cmd, "ID: null*");
return true;
} else if (id.equals("")) {
// <-
SendMessage(sender, cmd, "ID: notfound");
return true;
}
SendMessage(sender, cmd, "ID: " + id);
return true;
}
SendMessage(sender, cmd, "/test <get|check>");
return true;
}
use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Essentials by EssentialsX.
the class v1_8_R1SpawnerProvider method setEntityType.
@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
net.minecraft.server.v1_8_R1.ItemStack itemStack;
CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null) {
tag = new NBTTagCompound();
itemStack.setTag(tag);
}
if (!tag.hasKey("BlockEntityTag")) {
tag.set("BlockEntityTag", new NBTTagCompound());
}
tag = itemStack.getTag().getCompound("BlockEntityTag");
tag.setString("EntityId", type.getName());
ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
return setDisplayName(bukkitItemStack, type);
}
use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Essentials by EssentialsX.
the class v1_8_R1SpawnerProvider method getEntityType.
@Override
public EntityType getEntityType(ItemStack is) {
net.minecraft.server.v1_8_R1.ItemStack itemStack;
CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("BlockEntityTag")) {
throw new IllegalArgumentException();
}
String name = tag.getCompound("BlockEntityTag").getString("EntityId");
return EntityType.fromName(name);
}
use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Essentials by EssentialsX.
the class v1_8_R2SpawnerProvider method setEntityType.
@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
net.minecraft.server.v1_8_R2.ItemStack itemStack;
CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null) {
tag = new NBTTagCompound();
itemStack.setTag(tag);
}
if (!tag.hasKey("BlockEntityTag")) {
tag.set("BlockEntityTag", new NBTTagCompound());
}
tag = itemStack.getTag().getCompound("BlockEntityTag");
tag.setString("EntityId", type.getName());
ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
return setDisplayName(bukkitItemStack, type);
}
use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Ublisk by Derkades.
the class Item method setNBTValue.
public Item setNBTValue(String key, boolean bool) {
NBTTagCompound compound = this.getNBT();
compound.setBoolean(key, bool);
return this.setNBT(compound);
}
Aggregations