Search in sources :

Example 91 with NBTTagCompound

use of net.minecraft.server.v1_16_R3.NBTTagCompound in project MyMaid2 by jaoafa.

the class Cmd_GetEsc method onCommand.

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (args.length >= 1 && args[0].equalsIgnoreCase("help")) {
        SendUsageMessage(sender, cmd);
        return true;
    }
    if (!(sender instanceof Player)) {
        return true;
    }
    Player player = (Player) sender;
    String group = PermissionsManager.getPermissionMainGroup(player);
    if (!group.equalsIgnoreCase("Admin") && !group.equalsIgnoreCase("Moderator") && !group.equalsIgnoreCase("Regular") && !group.equalsIgnoreCase("Default")) {
        SendMessage(sender, cmd, "このコマンドは管理部・モデレーター・常連・デフォルト権限のプレイヤーのみ使用可能です。");
        return true;
    }
    int REQUIRED_jao = 1000;
    try {
        Pointjao pointjao = new Pointjao(player);
        if (!pointjao.has(REQUIRED_jao)) {
            // 所持していない
            SendMessage(sender, cmd, "新しいEscapeJailアイテムの精製に失敗しました。精製に必要なjaoポイントが足りません!");
            return true;
        }
    } catch (ClassNotFoundException | NullPointerException | SQLException e) {
        BugReporter(e);
        SendMessage(sender, cmd, "新しいEscapeJailアイテムの精製に失敗しました。時間をおいてまたお試しください!(1)");
        return true;
    }
    ItemStack item = new ItemStack(Material.POTATO_ITEM);
    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) {
        BugReporter(e);
        SendMessage(sender, cmd, "新しいEscapeJailアイテムの精製に失敗しました。時間をおいてまたお試しください!(2)");
        return true;
    }
    byte[] digest = md.digest(uuid.toString().getBytes());
    String id = DatatypeConverter.printHexBinary(digest);
    if (id == null) {
        SendMessage(sender, cmd, "新しいEscapeJailアイテムの精製に失敗しました。時間をおいてまたお試しください!(3)");
        return true;
    }
    nbttag.setString("MyMaid_EscapeJailID", id);
    nms.setTag(nbttag);
    item = CraftItemStack.asBukkitCopy(nms);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName("EscapeItem - IMO");
    List<String> lore = new ArrayList<String>();
    lore.add("このアイテムをインベントリ内に配置しておくと、Jail(EBan除く)を無効化できます!(アイテム1つにつき1回限り)");
    lore.add(ChatColor.RED + "NBTデータを削除してしまうと、アイテムは無効となります。また、複製をしても1つしか有効ではありません。");
    meta.setLore(lore);
    meta.addEnchant(Enchantment.LOOT_BONUS_BLOCKS, 999, true);
    item.setItemMeta(meta);
    try {
        PreparedStatement statement = MySQL.getNewPreparedStatement("INSERT INTO uniqueitem (id, type) VALUES (?, ?)");
        statement.setString(1, id);
        statement.setString(2, "MyMaid_EscapeJailID");
        statement.executeUpdate();
    } catch (SQLException | ClassNotFoundException e) {
        BugReporter(e);
        SendMessage(sender, cmd, "新しいEscapeJailアイテムの精製に失敗しました。時間をおいてまたお試しください!(3)");
        return true;
    }
    try {
        Pointjao pointjao = new Pointjao(player);
        pointjao.use(REQUIRED_jao, "EscapeJailアイテムを精製したため");
    } catch (ClassNotFoundException | NullPointerException | SQLException e) {
        BugReporter(e);
        SendMessage(sender, cmd, "新しいEscapeJailアイテムの精製に失敗しました。時間をおいてまたお試しください!(4)");
        return true;
    }
    player.getWorld().createExplosion(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), 5, false, false);
    SendMessage(sender, cmd, "新しいEscapeJailアイテムの精製に成功しました。");
    SendMessage(sender, cmd, "このアイテムをインベントリの中に配置しておくと、Jail(EBan除く)をアイテム個数分だけ無効化できます!");
    if (player.getInventory().firstEmpty() == -1) {
        player.getLocation().getWorld().dropItem(player.getLocation(), item);
        SendMessage(sender, cmd, "インベントリがいっぱいだったため、あなたの足元にアイテムをドロップしました。");
        Bukkit.getLogger().info("[EscapeJail] dropped to " + player.getName());
    } else {
        player.getInventory().addItem(item);
        Bukkit.getLogger().info("[EscapeJail] gived to " + player.getName());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) SQLException(java.sql.SQLException) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ArrayList(java.util.ArrayList) Pointjao(com.jaoafa.MyMaid2.Lib.Pointjao) PreparedStatement(java.sql.PreparedStatement) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) UUID(java.util.UUID) MessageDigest(java.security.MessageDigest) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 92 with NBTTagCompound

use of net.minecraft.server.v1_16_R3.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;
}
Also used : Player(org.bukkit.entity.Player) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) UUID(java.util.UUID) MessageDigest(java.security.MessageDigest)

Example 93 with NBTTagCompound

use of net.minecraft.server.v1_16_R3.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);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 94 with NBTTagCompound

use of net.minecraft.server.v1_16_R3.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);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound)

Example 95 with NBTTagCompound

use of net.minecraft.server.v1_16_R3.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);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)47 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)30 ListTag (com.wasteofplastic.org.jnbt.ListTag)30 StringTag (com.wasteofplastic.org.jnbt.StringTag)30 Tag (com.wasteofplastic.org.jnbt.Tag)30 Map (java.util.Map)30 ItemMeta (org.bukkit.inventory.meta.ItemMeta)29 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)27 ArrayList (java.util.ArrayList)24 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)14 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)13 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)12 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)12 TagCompound (de.keyle.knbt.TagCompound)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 PreparedStatement (java.sql.PreparedStatement)8 HashMap (java.util.HashMap)8 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_9_R1.NBTTagCompound)8