Search in sources :

Example 6 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project MyMaid2 by jaoafa.

the class Event_JoinjaoPoint method OnEvent_JoinjaoPoint.

@EventHandler
public void OnEvent_JoinjaoPoint(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    String uuid = player.getUniqueId().toString();
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    SimpleDateFormat date_full = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    date_full.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
    String today = date_full.format(cal.getTime());
    SimpleDateFormat date = new SimpleDateFormat("yyyy/MM/dd");
    try {
        PreparedStatement statement = MySQL.getNewPreparedStatement("SELECT * FROM login WHERE uuid = ? AND date >= cast(? as datetime) AND login_success = ?");
        statement.setString(1, uuid);
        statement.setString(2, today);
        statement.setBoolean(3, true);
        ResultSet res = statement.executeQuery();
        if (res.next()) {
            return;
        }
    } catch (SQLException | ClassNotFoundException e) {
        BugReporter(e);
    }
    try {
        Pointjao Pjao = new Pointjao(player);
        Pjao.add(10, date.format(new Date()) + "のログインボーナス");
    } catch (NullPointerException e) {
        BugReporter(e);
        return;
    } catch (ClassNotFoundException | SQLException e) {
        BugReporter(e);
        return;
    }
    try {
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date start = format.parse("2019/03/05 00:00:00");
        Date end = format.parse("2019/03/15 23:59:59");
        if (isPeriod(start, end)) {
            String group = PermissionsManager.getPermissionMainGroup(player);
            if (!group.equalsIgnoreCase("Admin") && !group.equalsIgnoreCase("Moderator") && !group.equalsIgnoreCase("Regular") && !group.equalsIgnoreCase("Default")) {
                return;
            }
            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 item_uuid = UUID.randomUUID();
            MessageDigest md;
            try {
                md = MessageDigest.getInstance("SHA-1");
            } catch (NoSuchAlgorithmException e) {
                BugReporter(e);
                player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に失敗しました。(2)");
                return;
            }
            byte[] digest = md.digest(item_uuid.toString().getBytes());
            String id = DatatypeConverter.printHexBinary(digest);
            if (id == null) {
                player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に失敗しました。(3)");
                return;
            }
            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);
                player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に失敗しました。(3)");
                return;
            }
            player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に成功しました。");
            player.sendMessage("[EscapeJail] " + ChatColor.RED + "このアイテムをインベントリの中に配置しておくと、Jail(EBan除く)をアイテム個数分だけ無効化できます!");
            if (player.getInventory().firstEmpty() == -1) {
                player.getLocation().getWorld().dropItem(player.getLocation(), item);
                player.sendMessage("[EscapeJail] " + ChatColor.RED + "インベントリがいっぱいだったため、あなたの足元にアイテムをドロップしました。");
                Bukkit.getLogger().info("[EscapeJail] dropped to " + player.getName());
            } else {
                player.getInventory().addItem(item);
                Bukkit.getLogger().info("[EscapeJail] gived to " + player.getName());
            }
        }
    } catch (ParseException e) {
        BugReporter(e);
    }
}
Also used : SQLException(java.sql.SQLException) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ArrayList(java.util.ArrayList) Pointjao(com.jaoafa.MyMaid2.Lib.Pointjao) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ResultSet(java.sql.ResultSet) UUID(java.util.UUID) MessageDigest(java.security.MessageDigest) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Player(org.bukkit.entity.Player) Calendar(java.util.Calendar) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date) ParseException(java.text.ParseException) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) SimpleDateFormat(java.text.SimpleDateFormat) EventHandler(org.bukkit.event.EventHandler)

Example 7 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project askyblock by tastybento.

the class NMSHandler method setBook.

@Override
public ItemStack setBook(Tag item) {
    ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
    // Bukkit.getLogger().info(item.toString());
    if (((CompoundTag) item).getValue().containsKey("tag")) {
        Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
        // BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
        String author = "";
        if (contents.containsKey("author")) {
            author = ((StringTag) contents.get("author")).getValue();
        }
        // Bukkit.getLogger().info("Author: " + author);
        // bookMeta.setAuthor(author);
        String title = "";
        if (contents.containsKey("title")) {
            title = ((StringTag) contents.get("title")).getValue();
        }
        // Bukkit.getLogger().info("Title: " + title);
        // bookMeta.setTitle(title);
        List<String> lore = new ArrayList<String>();
        if (contents.containsKey("display")) {
            Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
            List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
            for (Tag s : loreTag) {
                lore.add(((StringTag) s).getValue());
            }
        }
        // Bukkit.getLogger().info("Lore: " + lore);
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
        // Pages
        // Create the NMS Stack's NBT (item data)
        NBTTagCompound tag = new NBTTagCompound();
        // Set the book's title
        tag.setString("title", title);
        tag.setString("author", author);
        if (contents.containsKey("pages")) {
            NBTTagList pages = new NBTTagList();
            List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
            for (Tag s : pagesTag) {
                pages.add(new NBTTagString(((StringTag) s).getValue()));
            }
            // Add the pages to the tag
            tag.set("pages", pages);
        }
        // Apply the tag to the item
        stack.setTag(tag);
        chestItem = CraftItemStack.asCraftMirror(stack);
        ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
        bookMeta.setLore(lore);
        chestItem.setItemMeta(bookMeta);
    }
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 8 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project askyblock by tastybento.

the class NMSHandler method isPotion.

/* (non-Javadoc)
     * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#isPotion(org.bukkit.inventory.ItemStack)
     */
@Override
public boolean isPotion(ItemStack item) {
    // Bukkit.getLogger().info("DEBUG:item = " + item);
    if (item.getType().equals(Material.POTION)) {
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = stack.getTag();
        /*
            for (String list : tag.c()) {
                Bukkit.getLogger().info("DEBUG: list = " + list);
            }*/
        if (tag != null && (!tag.getString("Potion").equalsIgnoreCase("minecraft:water") || tag.getString("Potion").isEmpty())) {
            return true;
        }
    }
    return false;
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 9 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project askyblock by tastybento.

the class NMSHandler method getSpawnEgg.

/**
 * Get spawn egg
 * @param type
 * @param amount
 * @return
 */
public ItemStack getSpawnEgg(EntityType type, int amount) {
    // Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString());
    ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
    net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
    NBTTagCompound tagCompound = stack.getTag();
    if (tagCompound == null) {
        tagCompound = new NBTTagCompound();
    }
    // Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
    NBTTagCompound id = new NBTTagCompound();
    if (!bToMConversion.containsKey(type)) {
        id.setString("id", "minecraft:" + type.toString().toLowerCase());
    } else {
        id.setString("id", "minecraft:" + bToMConversion.get(type));
    }
    tagCompound.set("EntityTag", id);
    stack.setTag(tagCompound);
    // Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound);
    return CraftItemStack.asBukkitCopy(stack);
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project VehiclesPlus2.0 by legofreak107.

the class Main method onCommand.

@SuppressWarnings({ "deprecation" })
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("vp")) {
        if (args.length > 0) {
            if (args[0].equalsIgnoreCase("add")) {
                if (sender.hasPermission("vp.add")) {
                    if (args.length == 14) {
                        // vp add <name> <forwardspeed> <backwardspeed> <acceleration> <turnspeed> <seatamount>
                        if (checkFloat(args[2]) && checkFloat(args[3]) && checkFloat(args[4]) && checkFloat(args[5]) && checkInt(args[6]) && checkFloat(args[7]) && checkFloat(args[8]) && checkInt(args[10]) && checkInt(args[11]) && checkInt(args[12])) {
                            Fuel f = getFuel(args[13]);
                            if (isValidType(args[9])) {
                                if (f != null) {
                                    if (((Player) sender).getInventory().getItemInMainHand().getType() != null && ((Player) sender).getInventory().getItemInMainHand().getType() != Material.AIR) {
                                        Vehicle v = new Vehicle();
                                        v.plugin = this;
                                        v.name = args[1];
                                        v.type = getType(args[9]);
                                        v.skin = ((Player) sender).getInventory().getItemInMainHand();
                                        v.fspeed = Float.parseFloat(args[2]);
                                        v.bspeed = Float.parseFloat(args[3]);
                                        v.acceleration = Float.parseFloat(args[4]);
                                        v.turnSpeed = Float.parseFloat(args[5]);
                                        v.maxFuel = Float.parseFloat(args[7]);
                                        v.fualUsage = Float.parseFloat(args[8]);
                                        v.price = Integer.parseInt(args[10]);
                                        v.maxHealth = Integer.parseInt(args[12]);
                                        v.fuelType = f;
                                        Inventory inv = Bukkit.createInventory(null, Integer.parseInt(args[11]), "�2" + v.name);
                                        v.inv = inv;
                                        ArrayList<Seat> si = new ArrayList<Seat>();
                                        for (int i = 0; i < Integer.parseInt(args[6]); i++) {
                                            Seat s = new Seat();
                                            if (i == 0) {
                                                s.steer = true;
                                            } else {
                                                s.steer = false;
                                            }
                                            s.offset = new Vector(0, 0, 0);
                                            si.add(s);
                                        }
                                        v.seats = si;
                                        sal.addVehicle(v);
                                        vehicleTypeList.add(v);
                                        sender.sendMessage("�2Vehicle added!");
                                    } else {
                                        sender.sendMessage("�cMake sure that you are holding an item when you set up a car!");
                                    }
                                } else {
                                    sender.sendMessage("�cThis is not a valid fuel type, please type /vp fuel list for a list of fuels.");
                                }
                            } else {
                                sender.sendMessage("�cThis is not a valid type, please use: Car, Plane, Bike or Helicopter.");
                            }
                        } else {
                            sender.sendMessage("�cError in command syntax, usage: /vp add <@name> <%forwardspeed> <%backwardspeed> <%acceleration> <%turnspeed> <&seatamount> <%maxfuel> <%fuelusage> <@type> <&price> <&trunksize> <&health> <@fuelType>");
                            sender.sendMessage("�cInput types for @ = Text, % = Decimal, & = Number");
                        }
                    } else {
                        sender.sendMessage("�cError in command syntax, usage: /vp add <@name> <%forwardspeed> <%backwardspeed> <%acceleration> <%turnspeed> <&seatamount> <%maxfuel> <%fuelusage> <@type> <&price> <&trunksize> <&health> <@fuelType>");
                        sender.sendMessage("�cInput types for @ = Text, % = Decimal, & = Number");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("seatpos")) {
                if (sender.hasPermission("vp.add")) {
                    if (args.length == 6) {
                        // vp seatpos <name> <seatno> <x> <y> <z>
                        if (isValidVehicle(args[1])) {
                            if (checkInt(args[2]) && checkFloat(args[3]) && checkFloat(args[4]) && checkFloat(args[5])) {
                                float x = Float.parseFloat(args[3]);
                                float y = Float.parseFloat(args[4]);
                                float z = Float.parseFloat(args[5]);
                                Integer no = Integer.parseInt(args[2]);
                                String name = args[1];
                                Vehicle v = getVehicle(name);
                                if (no <= v.seats.size() && no > -1) {
                                    getConfig().set("Vehicles." + name + ".seat" + no + ".offsetX", x);
                                    getConfig().set("Vehicles." + name + ".seat" + no + ".offsetY", y);
                                    getConfig().set("Vehicles." + name + ".seat" + no + ".offsetZ", z);
                                    saveConfig();
                                    sender.sendMessage("�2Pos changed");
                                } else {
                                    sender.sendMessage("�cInvalid seat number!");
                                }
                            } else {
                                sender.sendMessage("�cError in command syntax, usage: /vp seatpos <@name> <&seats> <%x> <%y> <%z>");
                                sender.sendMessage("�cInput types for @ = Text, % = Decimal, & = Number");
                            }
                        } else {
                            sender.sendMessage("�cInvalid vehicle name");
                        }
                    } else {
                        sender.sendMessage("�cNot enough arguments.");
                        sender.sendMessage("�cError in command syntax, usage: /vp seatpos <@name> <&seats> <%x> <%y> <%z>");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("spawn")) {
                if (sender.hasPermission("vp.spawn")) {
                    if (args.length == 2) {
                        // vp spawn <name>
                        if (isValidVehicle(args[1])) {
                            Vehicle v = getVehicle(args[1]);
                            v.owner = sender.getName();
                            v.fuel = 25;
                            VPPlayer pla = new VPPlayer();
                            pla.p = ((Player) sender);
                            v.p = pla;
                            v.spawnLoc = ((Player) sender).getLocation();
                            v.spawn();
                            sender.sendMessage("�2Vehicle spawned!");
                        } else {
                            sender.sendMessage("�cThis is not a valid vehicle, try /vp list for a list of vehicles.");
                        }
                    } else {
                        sender.sendMessage("�cError in command arguments. Usage: /vp spawn <name>");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("reset")) {
                if (sender.hasPermission("vp.reset")) {
                    // vp spawn <name>
                    for (Vehicle v : playerVehicles.get(sender)) {
                        if (v.holder != null) {
                            ((Player) sender).getInventory().removeItem(keys.get(v));
                            v.remove();
                            v.holder.remove();
                            v.holder = null;
                        }
                    }
                    sender.sendMessage("�2All your cars are now back in your garage!");
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("license")) {
                if (sender.hasPermission("vp.license")) {
                    // vp spawn <name>
                    Player p = ((Player) sender);
                    for (Entity e : p.getWorld().getNearbyEntities(p.getLocation(), 2, 2, 2)) {
                        if (e instanceof ArmorStand) {
                            if (vehicleInfo.containsKey(e)) {
                                Vehicle c = vehicleInfo.get(e);
                                sender.sendMessage("�8===========================================");
                                sender.sendMessage("�6Vehicle info:");
                                sender.sendMessage("�6");
                                sender.sendMessage("�6Owner: " + c.owner);
                                sender.sendMessage("�6Type: " + c.type);
                                sender.sendMessage("�6Health: " + c.getHealth());
                                sender.sendMessage("�8===========================================");
                                break;
                            }
                        }
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("list")) {
                if (sender.hasPermission("vp.list")) {
                    if (args.length == 1) {
                        sender.sendMessage("�2Available vehicles:");
                        for (Vehicle v : vehicleTypeList) {
                            sender.sendMessage("�3" + v.name + " �6|| �3" + v.type);
                        }
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("reload")) {
                if (sender.hasPermission("vp.reload")) {
                    if (args.length == 1) {
                        disabe();
                        enable();
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("info")) {
                if (sender.hasPermission("vp.info")) {
                    if (args.length == 2) {
                        if (isValidVehicle(args[1])) {
                            Vehicle v = getVehicle(args[1]);
                            sender.sendMessage("�2Vehicle info:");
                            sender.sendMessage("�3Forward speed: " + v.fspeed);
                            sender.sendMessage("�3Backward speed: " + v.bspeed);
                            sender.sendMessage("�3Acceleration: " + v.acceleration);
                            sender.sendMessage("�3Turn speed: " + v.turnSpeed);
                            sender.sendMessage("�3Seats: " + v.seats.size());
                            sender.sendMessage("�3Item: " + v.skin.getType().toString());
                            sender.sendMessage("�3ItemData: " + v.skin.getData());
                            sender.sendMessage("�3Price: " + v.price);
                        }
                    } else {
                        sender.sendMessage("�cError in command arguments. Usage: /vp info <name>");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("setskin")) {
                if (sender.hasPermission("vp.add")) {
                    if (args.length == 2) {
                        if (isValidVehicle(args[1])) {
                            Vehicle v = getVehicle(args[1]);
                            if (((Player) sender).getInventory().getItemInMainHand() != null && ((Player) sender).getInventory().getItemInMainHand().getType() != Material.AIR) {
                                getConfig().set("Vehicles." + v.name + ".skin.material", ((Player) sender).getInventory().getItemInMainHand().getType().getId());
                                getConfig().set("Vehicles." + v.name + ".skin.data", ((Player) sender).getInventory().getItemInMainHand().getData().getData());
                                saveConfig();
                                sender.sendMessage("�2Updated vehicle skin");
                            } else {
                                sender.sendMessage("�cPlease make sure you are holding an item in your hand");
                            }
                        } else {
                            sender.sendMessage("�cThis is not a valid vehicle, try /vp list for a list of vehicles.");
                        }
                    } else {
                        sender.sendMessage("�cError in command arguments. Usage: /vp setskin <name>");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("give")) {
                if (sender.hasPermission("vp.give")) {
                    if (args.length == 3) {
                        Player p = Bukkit.getPlayer(args[1]);
                        if (p != null && isValidVehicle(args[2])) {
                            Vehicle v = getVehicle(args[2]);
                            ItemStack item = v.skin;
                            ItemMeta im = item.getItemMeta();
                            im.setDisplayName("�2" + v.name);
                            im.setLore(Arrays.asList("�8Place to spawn"));
                            item.setItemMeta(im);
                            p.getInventory().addItem(item);
                        } else {
                            sender.sendMessage("�cError in command arguments. Usage: /vp give <player> <name>");
                        }
                    } else {
                        sender.sendMessage("�cError in command arguments. Usage: /vp give <player> <name>");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("givekey")) {
                if (sender.hasPermission("vp.givekey")) {
                    if (args.length == 3) {
                        Player p = Bukkit.getPlayer(args[1]);
                        if (p != null && isValidVehicle(args[2])) {
                            Vehicle v = getVehicle(args[2]);
                            ItemStack item = new ItemStack(Material.TRIPWIRE_HOOK);
                            ItemMeta im = item.getItemMeta();
                            im.setDisplayName("�2" + v.name + " key");
                            im.setLore(Arrays.asList("�8Press your vp to lock/unlock "));
                            item.setItemMeta(im);
                            p.getInventory().addItem(item);
                        } else {
                            sender.sendMessage("�cError in command arguments. Usage: /vp givekey <player> <name>");
                        }
                    } else {
                        sender.sendMessage("�cError in command arguments. Usage: /vp givekey <player> <name>");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("givewrench")) {
                if (sender.hasPermission("vp.givewrench")) {
                    if (args.length == 2) {
                        Player p = Bukkit.getPlayer(args[1]);
                        if (p != null) {
                            ItemStack item = new ItemStack(Material.STICK);
                            ItemMeta im = item.getItemMeta();
                            im.setDisplayName("�2Wrench");
                            im.setLore(Arrays.asList("�8Press you vehicle to upgrade/repair"));
                            item.setItemMeta(im);
                            p.getInventory().addItem(item);
                        } else {
                            sender.sendMessage("�cError in command arguments. Usage: /vp givewrench <player>");
                        }
                    } else {
                        sender.sendMessage("�cError in command arguments. Usage: /vp givewrench <player>");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            } else if (args[0].equalsIgnoreCase("fuel")) {
                if (args.length > 1) {
                    if (sender.hasPermission("vp.fuel")) {
                        if (args[1].equalsIgnoreCase("list")) {
                            sender.sendMessage("�8=========================================");
                            for (Fuel f : fuelTypes) {
                                sender.sendMessage("    �6" + f.name + " �8| �6$" + f.fuelPrice + " �8| �6Fills: " + f.fuelAmount);
                            }
                            sender.sendMessage("�8=========================================");
                        } else if (args[1].equalsIgnoreCase("give")) {
                            if (args.length == 5) {
                                Player p = Bukkit.getPlayer(args[2]);
                                Fuel f = getFuel(args[3]);
                                if (p != null && checkInt(args[4]) && f != null) {
                                    Integer v = Integer.parseInt(args[4]);
                                    for (int i = 0; i < v; i++) f.give(p);
                                } else {
                                    sender.sendMessage("�cError in command arguments. Usage: /vp fuel give <player> <fuel> <amount>");
                                }
                            } else {
                                sender.sendMessage("�cError in command arguments. Usage: /vp fuel give <player> <fuel> <amount>");
                            }
                        } else if (args[1].equalsIgnoreCase("add")) {
                            if (args.length == 5) {
                                // vp addfuel <name> <price> <amount>
                                if (checkInt(args[3]) && checkInt(args[4])) {
                                    if (((Player) sender).getInventory().getItemInMainHand() != null && ((Player) sender).getInventory().getItemInMainHand().getType() != Material.AIR) {
                                        Fuel f = new Fuel();
                                        f.fuelAmount = Integer.parseInt(args[4]);
                                        f.fuelPrice = Integer.parseInt(args[3]);
                                        f.name = args[2];
                                        f.item = ((Player) sender).getInventory().getItemInMainHand();
                                        f.save(this);
                                        fuelTypes.add(f);
                                        sender.sendMessage("�2Fuel added!");
                                    } else {
                                        sender.sendMessage("�cPlease make sure that you are holding an item in your hand!");
                                    }
                                } else {
                                    sender.sendMessage("�cError in command syntax, usage: /vp fuel add <@name> <&price> <&fuelamount>");
                                    sender.sendMessage("�cInput types for @ = Text, % = Decimal, & = Number");
                                }
                            } else {
                                sender.sendMessage("�cError in command syntax, usage: /vp fuel add <@name> <&price> <&fuelamount>");
                                sender.sendMessage("�cInput types for @ = Text, % = Decimal, & = Number");
                            }
                        }
                    } else {
                        sender.sendMessage("�cYou don't have permissions to perform this command!");
                    }
                } else {
                    sender.sendMessage("�8=====================================================");
                    sender.sendMessage("�6/vp fuel list �8| �6Shows a list of fuels");
                    sender.sendMessage("�6/vp fuel give <player> <fuel> <amount> �8| �6Give fuel to a player");
                    sender.sendMessage("�6/vp fuel add <name> <price> <fillamount> �8| �6Add a new fuel type");
                    sender.sendMessage("�8=====================================================");
                }
            } else if (args[0].equalsIgnoreCase("lock")) {
                if (args.length == 1) {
                    Player p = (Player) sender;
                    if (p.getVehicle() != null) {
                        Seat s = seatInfo.get(p.getVehicle());
                        Vehicle v = vehicleInfo.get(s.parent);
                        if (s.steer) {
                            if (v.owner.equals(p.getName())) {
                                v.locked = true;
                                p.sendMessage("�2Vehicle locked!");
                            } else {
                                p.sendMessage("�2You aren't the owner of this vp!");
                            }
                        } else {
                            p.sendMessage("�2You have to be in the driver's seat to do this!");
                        }
                    } else {
                        p.sendMessage("�2You have to be inside the vp to lock it!");
                    }
                }
            } else if (args[0].equalsIgnoreCase("enter")) {
                if (args.length == 1) {
                    Player p = (Player) sender;
                    for (Entity e : p.getWorld().getNearbyEntities(p.getLocation(), 2, 2, 2)) {
                        if (e instanceof ArmorStand) {
                            if (seatInfo.containsKey(e)) {
                                Seat s = seatInfo.get(e);
                                Vehicle c = vehicleInfo.get(s.parent);
                                if (c.locked == null) {
                                    c.locked = false;
                                }
                                if (!c.locked && !(s.seat.getPassengers().size() > 0)) {
                                    s.seat.addPassenger(p);
                                    break;
                                }
                            }
                        }
                    }
                }
            } else if (args[0].equalsIgnoreCase("trunk")) {
                if (args.length == 1) {
                    Player p = (Player) sender;
                    if (p.getVehicle() != null) {
                        Seat s = seatInfo.get(p.getVehicle());
                        Vehicle v = vehicleInfo.get(s.parent);
                        if (s.steer) {
                            p.openInventory(v.inv);
                        } else {
                            p.sendMessage("�2You have to be in the driver's seat to do this!");
                        }
                    } else {
                        p.sendMessage("�2You have to be inside the vp to use the trunk!");
                    }
                }
            } else if (args[0].equalsIgnoreCase("unlock")) {
                if (args.length == 1) {
                    Player p = (Player) sender;
                    if (p.getVehicle() != null) {
                        Seat s = seatInfo.get(p.getVehicle());
                        Vehicle v = vehicleInfo.get(s.parent);
                        if (s.steer) {
                            if (v.owner.equals(p.getName())) {
                                v.locked = false;
                                p.sendMessage("�2Vehicle unlocked!");
                            } else {
                                p.sendMessage("�2You aren't the owner of this vp!");
                            }
                        } else {
                            p.sendMessage("�2You have to be in the driver's seat to do this!");
                        }
                    } else {
                        p.sendMessage("�2You have to be inside the vp to unlock it!");
                    }
                }
            } else if (args[0].equalsIgnoreCase("shop")) {
                if (args.length == 1) {
                    Player p = (Player) sender;
                    Inventory i = Bukkit.createInventory(p, 9 * 6, "�2Vehicle shop");
                    for (Vehicle v : vehicleTypeList) {
                        if (v.price != 0) {
                            i.addItem(genItem(v.skin, 1, "�6" + v.name, "�aClick to buy@�3Price: " + v.price));
                        }
                    }
                    p.openInventory(i);
                }
            } else if (args[0].equalsIgnoreCase("garage")) {
                if (sender.hasPermission("vp.garage")) {
                    if (args.length == 1) {
                        Player p = (Player) sender;
                        openGarage(p, 0, p);
                    } else if (args.length == 2) {
                        Player p = (Player) sender;
                        Player p2 = Bukkit.getPlayer(args[1]);
                        if (sender.hasPermission("vp.admin")) {
                            if (playerVehicles.containsKey(p2) && p2 != null) {
                                openGarage(p2, 0, p);
                            } else {
                                p.sendMessage("�cThat player is not online");
                            }
                        } else {
                            sender.sendMessage("�cYou don't have permissions to do this!");
                        }
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to do this!");
                }
            } else if (args[0].equalsIgnoreCase("help")) {
                if (sender.hasPermission("vp.help")) {
                    if (args.length == 1) {
                        sender.sendMessage("�2===================={�8Vehicles�6+�2}====================");
                        sender.sendMessage("�8/vp list �6|| �8Shows all vehicles");
                        sender.sendMessage("�8/vp give <name> <vehiclename>�6|| �8Gives vehicle.");
                        sender.sendMessage("�8/vp givekey <name> <vehiclename>�6|| �8Gives vehicle.");
                        sender.sendMessage("�8/vp reload �6|| �8Reloads config.");
                        sender.sendMessage("�8/vp help �6|| �8Shows this");
                        sender.sendMessage("�8/vp killall �6|| �8Kills all vehicles");
                        sender.sendMessage("�8/vp seatpos <name> <seat#> <x> <y> <z> �6|| �8Set the pos of a seat");
                        sender.sendMessage("�8/vp add <name> <forwardspeed> <backwardspeed> <acceleration> <turnspeed> <seatamount> <type> �6|| �8Add a new vehicle");
                        sender.sendMessage("�8/vp setskin <name> �6|| �8Set the skin to item in hand");
                        sender.sendMessage("�8/vp spawn <name> �6|| �8Spawn a vehicle");
                        sender.sendMessage("�8/vp info <name> �6|| �8Shows vehicle info");
                        sender.sendMessage("�8/vp fuel �6|| �8Fuel management");
                        sender.sendMessage("�8/vp givewrench <name> �6|| �8Gives fuel");
                        sender.sendMessage("�8/vp lock�6|| �8Locks vehicle");
                        sender.sendMessage("�8/vp unlock�6|| �8Unlocks vehicle");
                        sender.sendMessage("�8/vp trunk�6|| �8Opens vehicle trunk");
                        sender.sendMessage("�8/vp garage�6|| �8Opens vehicle garage");
                        sender.sendMessage("�8/vp garage <player>�6|| �8Opens vehicle garage (Admin mode)");
                        sender.sendMessage("�8/vp enter �6|| �8Enter the nearest seat within 2 blocks");
                        sender.sendMessage("�2===================={�8Vehicles�6+�2}====================");
                    } else {
                        sender.sendMessage("�cError in command arguments. Usage: /vp help");
                    }
                } else {
                    sender.sendMessage("�cYou don't have permissions to excecute this command!");
                }
            }
        } else {
            if (sender.hasPermission("vp.add")) {
                sender.sendMessage("�2===================={�8Vehicles�6+�2}====================");
                sender.sendMessage("�8/vp list �6|| �8Shows all vehicles");
                sender.sendMessage("�8/vp give <name> <vehiclename>�6|| �8Gives vehicle.");
                sender.sendMessage("�8/vp givekey <name> <vehiclename>�6|| �8Gives vehicle.");
                sender.sendMessage("�8/vp reload �6|| �8Reloads config.");
                sender.sendMessage("�8/vp help �6|| �8Shows this");
                sender.sendMessage("�8/vp killall �6|| �8Kills all vehicles");
                sender.sendMessage("�8/vp seatpos <name> <seat#> <x> <y> <z> �6|| �8Set the pos of a seat");
                sender.sendMessage("�8/vp add <name> <forwardspeed> <backwardspeed> <acceleration> <turnspeed> <seatamount> <type> �6|| �8Add a new vehicle");
                sender.sendMessage("�8/vp setskin <name> �6|| �8Set the skin to item in hand");
                sender.sendMessage("�8/vp spawn <name> �6|| �8Spawn a vehicle");
                sender.sendMessage("�8/vp info <name> �6|| �8Shows vehicle info");
                sender.sendMessage("�8/vp fuel �6|| �8Fuel management");
                sender.sendMessage("�8/vp givewrench <name> �6|| �8Gives fuel");
                sender.sendMessage("�8/vp lock�6|| �8Locks vehicle");
                sender.sendMessage("�8/vp unlock�6|| �8Unlocks vehicle");
                sender.sendMessage("�8/vp trunk�6|| �8Opens vehicle trunk");
                sender.sendMessage("�8/vp garage�6|| �8Opens vehicle garage");
                sender.sendMessage("�8/vp garage <player>�6|| �8Opens vehicle garage (Admin mode)");
                sender.sendMessage("�8/vp enter �6|| �8Enter the nearest seat within 2 blocks");
                sender.sendMessage("�2===================={�8Vehicles�6+�2}====================");
            } else {
                sender.sendMessage("�cYou don't have permissions to excecute this command!");
            }
        }
    }
    return false;
}
Also used : VPPlayer(me.legofreak107.vehicles.objects.VPPlayer) Entity(org.bukkit.entity.Entity) PlayerInteractAtEntity(me.legofreak107.vehicles.events.PlayerInteractAtEntity) VPPlayer(me.legofreak107.vehicles.objects.VPPlayer) Player(org.bukkit.entity.Player) Seat(me.legofreak107.vehicles.objects.Seat) ArrayList(java.util.ArrayList) PacketPlayInSteerVehicle(net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle) Vehicle(me.legofreak107.vehicles.objects.Vehicle) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) ArmorStand(org.bukkit.entity.ArmorStand) Fuel(me.legofreak107.vehicles.objects.Fuel) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Inventory(org.bukkit.inventory.Inventory) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)30 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)27 ItemStack (org.bukkit.inventory.ItemStack)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 ArrayList (java.util.ArrayList)10 Player (org.bukkit.entity.Player)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)8 ChannelPromise (io.netty.channel.ChannelPromise)8 PreparedStatement (java.sql.PreparedStatement)7 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 Item (net.minecraft.server.v1_12_R1.Item)5 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)5 Location (org.bukkit.Location)5 OfflinePlayer (org.bukkit.OfflinePlayer)5 PlayerInventory (org.bukkit.inventory.PlayerInventory)5