Search in sources :

Example 96 with NBTTagCompound

use of net.minecraft.server.v1_9_R2.NBTTagCompound in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
    }
    NBTTagList emptyList = new NBTTagList();
    if (is.getTag() == null) {
        is.setTag(new NBTTagCompound());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // remove item attributes like attack damage
    is.getTag().set("AttributeModifiers", emptyList);
    // add enchantment glowing
    if (icon.isGlowing()) {
        is.getTag().set("ench", emptyList);
    } else {
        is.getTag().remove("ench");
    }
    // Prepare display tag
    NBTTagCompound display;
    if (is.getTag().hasKey("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new NBTTagCompound();
        is.getTag().set("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.setString("Name", icon.getTitle());
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        NBTTagList loreTag = new NBTTagList();
        display.set("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            loreTag.add(new NBTTagString(loreLine));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    if (icon.getTags() != null) {
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_9_R2.NBTTagList) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) ItemStack(net.minecraft.server.v1_9_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)

Example 97 with NBTTagCompound

use of net.minecraft.server.v1_9_R2.NBTTagCompound in project MyPet by xXKeyleXx.

the class ConfigItem method load.

public void load(MaterialHolder material, String data) {
    MinecraftKey key = new MinecraftKey(material.getLegacyName().getName());
    Item item = Item.REGISTRY.get(key);
    if (item == null) {
        return;
    }
    net.minecraft.server.v1_9_R2.ItemStack is = new net.minecraft.server.v1_9_R2.ItemStack(item, 1, material.getLegacyName().getData());
    if (data != null) {
        NBTTagCompound tag = null;
        String nbtString = data.trim();
        if (nbtString.startsWith("{") && nbtString.endsWith("}")) {
            try {
                tag = MojangsonParser.parse(nbtString);
            } catch (Exception e) {
                MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
                MyPetApi.getLogger().warning(item.getName() + " " + nbtString);
            }
            if (tag != null) {
                is.setTag(tag);
            }
        }
    }
    this.item = CraftItemStack.asCraftMirror(is);
}
Also used : Item(net.minecraft.server.v1_9_R2.Item) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_9_R2.MinecraftKey) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 98 with NBTTagCompound

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

the class Jail method JailAdd.

/**
 * Jailに理由つきでプレイヤーを追加
 * @param cmd コマンド情報
 * @param player プレイヤー
 * @param banned_by 追加したプレイヤー
 * @param reason 理由
 * @param InvRemove インベントリを削除するか
 * @return 実行できたかどうか
 * @author mine_book000
 * @throws SQLException
 * @throws NullPointerException
 * @throws ClassNotFoundException
 * @throws EscapeJailException
 */
public static boolean JailAdd(Player player, OfflinePlayer banned_by, String reason, boolean InvRemove) throws ClassNotFoundException, NullPointerException, SQLException, EscapeJailException {
    if (player == null) {
        try {
            throw new java.lang.NullPointerException("JailAdd Player is null...!");
        } catch (java.lang.NullPointerException e) {
            BugReporter(e);
        }
        return false;
    }
    if (banned_by == null) {
        try {
            throw new java.lang.NullPointerException("JailAdd OfflinePlayer(banned_by) is null...!");
        } catch (java.lang.NullPointerException e) {
            BugReporter(e);
        }
        return false;
    }
    if (banned_by instanceof Player) {
        Player banned_by_player = (Player) banned_by;
        Pointjao pointjao = new Pointjao(banned_by_player);
        if (!pointjao.has(REQUIRED_jao)) {
            // 所持していない
            ((Player) banned_by).sendMessage("[JAIL] " + ChatColor.GREEN + "あなたはJailするためのjaoポイントが足りません。");
            return false;
        }
    }
    if (Jail.contains(player.getUniqueId().toString())) {
        // 既に牢獄にいるので無理
        return false;
    }
    // Item Check
    if (player.isOnline()) {
        Boolean EscapeFlag = false;
        Player target = player.getPlayer();
        PlayerInventory inv = target.getInventory();
        for (int n = 0; n < inv.getSize(); n++) {
            ItemStack is = inv.getItem(n);
            if (is == null) {
                continue;
            }
            if (is.getType() == Material.AIR) {
                continue;
            }
            net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(is);
            NBTTagCompound nbttag = nms.getTag();
            if (nbttag == null) {
                continue;
            }
            String id = nbttag.getString("MyMaid_EscapeJailID");
            if (id == null) {
                continue;
            } else if (id.equals("")) {
                continue;
            }
            PreparedStatement statement = MySQL.getNewPreparedStatement("SELECT * FROM uniqueitem WHERE id = ? AND type = ?");
            statement.setString(1, id);
            statement.setString(2, "MyMaid_EscapeJailID");
            ResultSet res = statement.executeQuery();
            if (res.next()) {
                // ある
                if (res.getBoolean("used")) {
                    // 使ってる
                    nbttag.remove("MyMaid_EscapeJailID");
                    nms.setTag(nbttag);
                    is = CraftItemStack.asBukkitCopy(nms);
                    ItemMeta meta = is.getItemMeta();
                    meta.setDisplayName(meta.getDisplayName() + ChatColor.RED + " [使用済]");
                    is.setItemMeta(meta);
                    inv.setItem(n, is);
                    continue;
                }
            } else {
                // ない
                nbttag.remove("MyMaid_EscapeJailID");
                nms.setTag(nbttag);
                is = CraftItemStack.asBukkitCopy(nms);
                ItemMeta meta = is.getItemMeta();
                meta.setDisplayName(meta.getDisplayName() + ChatColor.RED + " [無効]");
                is.setItemMeta(meta);
                inv.setItem(n, is);
                continue;
            }
            // 使ってない
            PreparedStatement statement_disable = MySQL.getNewPreparedStatement("UPDATE uniqueitem SET used = ? WHERE id = ? AND type = ?");
            statement_disable.setBoolean(1, true);
            statement_disable.setString(2, id);
            statement_disable.setString(3, "MyMaid_EscapeJailID");
            statement_disable.executeUpdate();
            nbttag.remove("MyMaid_EscapeJailID");
            nms.setTag(nbttag);
            is = CraftItemStack.asBukkitCopy(nms);
            ItemMeta meta = is.getItemMeta();
            meta.setDisplayName(meta.getDisplayName() + ChatColor.RED + " [使用済]");
            is.setItemMeta(meta);
            inv.setItem(n, is);
            EscapeFlag = true;
            break;
        }
        target.updateInventory();
        if (EscapeFlag) {
            if (banned_by instanceof Player) {
                Player banned_by_player = (Player) banned_by;
                Pointjao pointjao = new Pointjao(banned_by_player);
                pointjao.use(REQUIRED_jao, player.getName() + "をJailに追加しようとしたため。(理由: " + reason + " | EscapeJailによって失敗)");
            }
            throw new EscapeJailException();
        }
    }
    Jail.add(player.getUniqueId().toString());
    // 設置破壊不可
    block.put(player.getUniqueId().toString(), false);
    // 範囲外移動
    area.put(player.getUniqueId().toString(), false);
    // まだ遺言を残してない
    lasttext.put(player.getUniqueId().toString(), false);
    if (InvRemove) {
        player.getInventory().clear();
    // player.getEnderChest().clear(); - さすがにエンダーチェスト消すのはかわいそうかなと思ってきた
    }
    if (player.getGameMode() == GameMode.SPECTATOR)
        player.setGameMode(GameMode.CREATIVE);
    World Jao_Afa = Bukkit.getServer().getWorld("Jao_Afa");
    Location minami = new Location(Jao_Afa, 2856, 69, 2888);
    // テレポート
    player.teleport(minami);
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    SimpleDateFormat allsdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "やあ。" + player.getName() + "クン。どうも君はなにかをして南の楽園に来てしまったみたいなんだ");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "話を聞けば、「" + reason + "」という理由でここにきたみたいだね。");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "ちょっとやったことを反省してみるのもいいかもしれないね");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "あ、そうだ、今の君に人権はないよ。");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "あと、「/testment <LastText>」で遺言を残せるよ!");
    try {
        PreparedStatement statement = MySQL.getNewPreparedStatement("INSERT INTO jail (player, uuid, banned_by, reason, date) VALUES (?, ?, ?, ?, ?)");
        statement.setString(1, player.getName());
        statement.setString(2, player.getUniqueId().toString());
        statement.setString(3, banned_by.getName());
        statement.setString(4, reason);
        statement.setString(5, allsdf.format(new Date()));
        statement.executeUpdate();
    } catch (SQLException | ClassNotFoundException e) {
        BugReporter(e);
    }
    try {
        PreparedStatement statement = MySQL.getNewPreparedStatement("INSERT INTO banlist (player, uuid, type, bannedby, reason, time) VALUES (?, ?, ?, ?, ?, ?)");
        statement.setString(1, player.getName());
        statement.setString(2, player.getUniqueId().toString());
        statement.setString(3, "jail");
        statement.setString(4, banned_by.getName());
        statement.setString(5, reason);
        statement.setString(6, allsdf.format(new Date()));
        statement.executeUpdate();
    } catch (SQLException | ClassNotFoundException e) {
        BugReporter(e);
    }
    Bukkit.broadcastMessage("[JAIL] " + ChatColor.GREEN + "プレイヤー:「" + player.getName() + "」を「" + reason + "」という理由で牢獄リストに追加しました。");
    DiscordSend("223582668132974594", "***Jail[追加]***: プレイヤー「" + player.getName() + "」が「" + banned_by.getName() + "」によって「" + reason + "」という理由でJailリストに追加されました。");
    if (!Achievementjao.getAchievement(player, new AchievementType(20))) {
        player.sendMessage(AchievementAPI.getPrefix() + "実績の解除中に問題が発生しました。");
    }
    if (banned_by instanceof Player) {
        Player banned_by_player = (Player) banned_by;
        Pointjao pointjao = new Pointjao(banned_by_player);
        pointjao.use(REQUIRED_jao, player.getName() + "をJailに追加したため。(理由: " + reason + ")");
    }
    JailBackupSaveTxt(player.getName(), JailType.ADD, banned_by.getName(), reason);
    return true;
}
Also used : SQLException(java.sql.SQLException) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) World(org.bukkit.World) ResultSet(java.sql.ResultSet) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PreparedStatement(java.sql.PreparedStatement) PlayerInventory(org.bukkit.inventory.PlayerInventory) Date(java.util.Date) AchievementType(com.jaoafa.jaoSuperAchievement.jaoAchievement.AchievementType) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) SimpleDateFormat(java.text.SimpleDateFormat) Location(org.bukkit.Location)

Example 99 with NBTTagCompound

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

the class Jail method JailAdd.

/**
 * Jailに理由つきでプレイヤーを追加
 * @param cmd コマンド情報
 * @param player プレイヤー
 * @param banned_by 追加したプレイヤー
 * @param reason 理由
 * @param InvRemove インベントリを削除するか
 * @return 実行できたかどうか
 * @author mine_book000
 * @throws SQLException
 * @throws NullPointerException
 * @throws ClassNotFoundException
 * @throws EscapeJailException
 */
public static boolean JailAdd(Player player, CommandSender banned_by, String reason, boolean InvRemove) throws ClassNotFoundException, NullPointerException, SQLException, EscapeJailException {
    if (player == null) {
        banned_by.sendMessage("[JAIL] " + ChatColor.GREEN + "指定されたプレイヤーは見つかりません。");
        try {
            throw new java.lang.NullPointerException("JailAdd Player is null...!");
        } catch (java.lang.NullPointerException e) {
            BugReporter(e);
        }
        return false;
    }
    if (banned_by instanceof Player) {
        Player banned_by_player = (Player) banned_by;
        Pointjao pointjao = new Pointjao(banned_by_player);
        if (!pointjao.has(REQUIRED_jao)) {
            // 所持していない
            banned_by.sendMessage("[JAIL] " + ChatColor.GREEN + "あなたはJailするためのjaoポイントが足りません。");
            return true;
        }
    }
    if (Jail.contains(player.getUniqueId().toString())) {
        // 既に牢獄にいるので無理
        banned_by.sendMessage("[JAIL] " + ChatColor.GREEN + "指定されたプレイヤーはすでに牢獄にいるため追加できません。");
        return false;
    }
    // Item Check
    if (player.isOnline()) {
        Boolean EscapeFlag = false;
        Player target = player.getPlayer();
        PlayerInventory inv = target.getInventory();
        for (int n = 0; n < inv.getSize(); n++) {
            ItemStack is = inv.getItem(n);
            if (is == null) {
                continue;
            }
            if (is.getType() == Material.AIR) {
                continue;
            }
            net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(is);
            NBTTagCompound nbttag = nms.getTag();
            if (nbttag == null) {
                continue;
            }
            String id = nbttag.getString("MyMaid_EscapeJailID");
            if (id == null) {
                continue;
            } else if (id.equals("")) {
                continue;
            }
            PreparedStatement statement = MySQL.getNewPreparedStatement("SELECT * FROM uniqueitem WHERE id = ? AND type = ?");
            statement.setString(1, id);
            statement.setString(2, "MyMaid_EscapeJailID");
            ResultSet res = statement.executeQuery();
            if (res.next()) {
                // ある
                if (res.getBoolean("used")) {
                    // 使ってる
                    nbttag.remove("MyMaid_EscapeJailID");
                    nms.setTag(nbttag);
                    is = CraftItemStack.asBukkitCopy(nms);
                    ItemMeta meta = is.getItemMeta();
                    meta.setDisplayName(meta.getDisplayName() + ChatColor.RED + " [使用済]");
                    is.setItemMeta(meta);
                    inv.setItem(n, is);
                    continue;
                }
            } else {
                // ない
                nbttag.remove("MyMaid_EscapeJailID");
                nms.setTag(nbttag);
                is = CraftItemStack.asBukkitCopy(nms);
                ItemMeta meta = is.getItemMeta();
                meta.setDisplayName(meta.getDisplayName() + ChatColor.RED + " [無効]");
                is.setItemMeta(meta);
                inv.setItem(n, is);
                continue;
            }
            // 使ってない
            PreparedStatement statement_disable = MySQL.getNewPreparedStatement("UPDATE uniqueitem SET used = ? WHERE id = ? AND type = ?");
            statement_disable.setBoolean(1, true);
            statement_disable.setString(2, id);
            statement_disable.setString(3, "MyMaid_EscapeJailID");
            statement_disable.executeUpdate();
            nbttag.remove("MyMaid_EscapeJailID");
            nms.setTag(nbttag);
            is = CraftItemStack.asBukkitCopy(nms);
            ItemMeta meta = is.getItemMeta();
            meta.setDisplayName(meta.getDisplayName() + ChatColor.RED + " [使用済]");
            is.setItemMeta(meta);
            inv.setItem(n, is);
            EscapeFlag = true;
            break;
        }
        target.updateInventory();
        if (EscapeFlag) {
            if (banned_by instanceof Player) {
                Player banned_by_player = (Player) banned_by;
                Pointjao pointjao = new Pointjao(banned_by_player);
                pointjao.use(REQUIRED_jao, player.getName() + "をJailに追加しようとしたため。(理由: " + reason + " | EscapeJailによって失敗)");
            }
            throw new EscapeJailException();
        }
    }
    Jail.add(player.getUniqueId().toString());
    // 設置破壊不可
    block.put(player.getUniqueId().toString(), false);
    // 範囲外移動
    area.put(player.getUniqueId().toString(), false);
    // まだ遺言を残してない
    lasttext.put(player.getUniqueId().toString(), false);
    if (InvRemove) {
        player.getInventory().clear();
    // player.getEnderChest().clear(); - さすがにエンダーチェスト消すのはかわいそうかなと思ってきた
    }
    if (player.getGameMode() == GameMode.SPECTATOR)
        player.setGameMode(GameMode.CREATIVE);
    World Jao_Afa = Bukkit.getServer().getWorld("Jao_Afa");
    Location minami = new Location(Jao_Afa, 2856, 69, 2888);
    // テレポート
    player.teleport(minami);
    SimpleDateFormat allsdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "やあ。" + player.getName() + "クン。どうも君はなにかをして南の楽園に来てしまったみたいなんだ");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "話を聞けば、「" + reason + "」という理由でここにきたみたいだね。");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "ちょっとやったことを反省してみるのもいいかもしれないね");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "あ、そうだ、今の君に人権はないよ。");
    player.sendMessage(ChatColor.GRAY + "[" + sdf.format(new Date()) + "]" + ChatColor.GOLD + "■jaotan" + ChatColor.WHITE + ": " + "あと、「/testment <LastText>」で遺言を残せるよ!");
    try {
        PreparedStatement statement = MySQL.getNewPreparedStatement("INSERT INTO jail (player, uuid, banned_by, reason, date) VALUES (?, ?, ?, ?, ?)");
        statement.setString(1, player.getName());
        statement.setString(2, player.getUniqueId().toString());
        statement.setString(3, banned_by.getName());
        statement.setString(4, reason);
        statement.setString(5, allsdf.format(new Date()));
        statement.executeUpdate();
    } catch (SQLException | ClassNotFoundException e) {
        BugReporter(e);
    }
    try {
        PreparedStatement statement = MySQL.getNewPreparedStatement("INSERT INTO banlist (player, uuid, type, bannedby, reason, time) VALUES (?, ?, ?, ?, ?, ?)");
        statement.setString(1, player.getName());
        statement.setString(2, player.getUniqueId().toString());
        statement.setString(3, "jail");
        statement.setString(4, banned_by.getName());
        statement.setString(5, reason);
        statement.setString(6, allsdf.format(new Date()));
        statement.executeUpdate();
    } catch (SQLException | ClassNotFoundException e) {
        BugReporter(e);
    }
    Bukkit.broadcastMessage("[JAIL] " + ChatColor.GREEN + "プレイヤー:「" + player.getName() + "」を「" + reason + "」という理由で牢獄リストに追加しました。");
    DiscordSend("223582668132974594", "***Jail[追加]***: プレイヤー「" + player.getName() + "」が「" + banned_by.getName() + "」によって「" + reason + "」という理由でJailリストに追加されました。");
    if (!Achievementjao.getAchievement(player, new AchievementType(20))) {
        player.sendMessage(AchievementAPI.getPrefix() + "実績の解除中に問題が発生しました。");
    }
    if (banned_by instanceof Player) {
        Player banned_by_player = (Player) banned_by;
        Pointjao pointjao = new Pointjao(banned_by_player);
        pointjao.use(REQUIRED_jao, player.getName() + "をJailに追加したため。(理由: " + reason + ")");
    }
    JailBackupSaveTxt(player.getName(), JailType.ADD, banned_by.getName(), reason);
    return true;
}
Also used : SQLException(java.sql.SQLException) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) World(org.bukkit.World) ResultSet(java.sql.ResultSet) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PreparedStatement(java.sql.PreparedStatement) PlayerInventory(org.bukkit.inventory.PlayerInventory) Date(java.util.Date) AchievementType(com.jaoafa.jaoSuperAchievement.jaoAchievement.AchievementType) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) SimpleDateFormat(java.text.SimpleDateFormat) Location(org.bukkit.Location)

Example 100 with NBTTagCompound

use of net.minecraft.server.v1_9_R2.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)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)45 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 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)28 ItemMeta (org.bukkit.inventory.meta.ItemMeta)28 ArrayList (java.util.ArrayList)23 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 NBTTagCompound (net.minecraft.server.v1_9_R1.NBTTagCompound)10 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 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