Search in sources :

Example 1 with Confirmation

use of me.legofreak107.vehicles.libs.Confirmation in project VehiclesPlus2.0 by legofreak107.

the class InventoryClick method onClick.

@EventHandler
public void onClick(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();
    if (e.getClickedInventory().getName().contains("Vehicle")) {
        e.setCancelled(true);
        Integer price = Integer.parseInt(e.getCurrentItem().getItemMeta().getLore().get(1).replace("�3Price: ", ""));
        if (plugin.econ.getBalance(p.getName()) >= price) {
            plugin.econ.withdrawPlayer(p, price);
            Vehicle v = plugin.getVehicle(e.getCurrentItem().getItemMeta().getDisplayName().replace("�6", ""));
            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);
            p.sendMessage("�6You bought a " + v.name + " for $" + v.price + "!");
        }
    } else if (e.getClickedInventory().getName().contains("garage")) {
        if (e.getAction() == InventoryAction.PICKUP_ALL) {
            Integer page = Integer.parseInt(e.getClickedInventory().getName().replace("�2" + p.getName() + "'s garage �6(Page: ", "").replace(")", ""));
            e.setCancelled(true);
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("�6")) {
                // Already spawned
                String number = "";
                if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(1) + "")) {
                    number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(1);
                    if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(2) + "")) {
                        number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(2);
                        if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(3) + "")) {
                            number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(3);
                            if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(4) + "")) {
                                number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(4);
                            }
                        }
                    }
                }
                Vehicle v = plugin.playerVehicles.get(p).get(Integer.parseInt(number));
                // Found it
                v.remove();
                if (v.holder != null) {
                    p.getInventory().removeItem(plugin.keys.get(v));
                    v.holder.remove();
                    v.holder = null;
                }
                p.closeInventory();
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("�a")) {
                // Ready to spawn
                String number = "";
                if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(1) + "")) {
                    number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(1);
                    if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(2) + "")) {
                        number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(2);
                        if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(3) + "")) {
                            number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(3);
                            if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(4) + "")) {
                                number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(4);
                            }
                        }
                    }
                }
                if (plugin.carsSpawned.containsKey(p)) {
                    if (plugin.carsSpawned.get(p) < plugin.maxCars) {
                        plugin.carsSpawned.put(p, plugin.carsSpawned.get(p) + 1);
                        Vehicle v = plugin.playerVehicles.get(p).get(Integer.parseInt(number));
                        // Found it
                        v.spawnLoc = e.getWhoClicked().getLocation();
                        ItemStack item = new ItemStack(Material.TRIPWIRE_HOOK);
                        ItemMeta im = item.getItemMeta();
                        im.setDisplayName("�2" + v.name + " key");
                        im.setLore(Arrays.asList("�8Press your vehicle to lock/unlock", "�6Soulbound"));
                        item.setItemMeta(im);
                        p.getInventory().addItem(item);
                        plugin.keys.put(v, item);
                        p.closeInventory();
                        v.spawn2();
                    } else {
                        p.sendMessage("�cYou already have the max amount of vehicles spawned!");
                    }
                } else {
                    plugin.carsSpawned.put(p, 1);
                    Vehicle v = plugin.playerVehicles.get(p).get(Integer.parseInt(number));
                    // Found it
                    v.spawnLoc = e.getWhoClicked().getLocation();
                    ItemStack item = new ItemStack(Material.TRIPWIRE_HOOK);
                    ItemMeta im = item.getItemMeta();
                    im.setDisplayName("�2" + v.name + " key");
                    im.setLore(Arrays.asList("�8Press your vehicle to lock/unlock", "�6Soulbound"));
                    item.setItemMeta(im);
                    p.getInventory().addItem(item);
                    plugin.keys.put(v, item);
                    p.closeInventory();
                    v.spawn2();
                }
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("�c")) {
                // Repair
                String number = "";
                if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(1) + "")) {
                    number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(1);
                    if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(2) + "")) {
                        number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(2);
                        if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(3) + "")) {
                            number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(3);
                            if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(4) + "")) {
                                number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(4);
                            }
                        }
                    }
                }
                Vehicle v = plugin.playerVehicles.get(p).get(Integer.parseInt(number));
                // Found it
                v.spawnLoc = e.getWhoClicked().getLocation();
                new Confirmation(p, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(p) >= v.price / 100) {
                                p.sendMessage("�2Vehicle repaired!");
                                v.repair();
                                p.closeInventory();
                            } else {
                                p.sendMessage("�2You don't have enough money to repair this vehicle!");
                                p.closeInventory();
                            }
                        }
                    }
                }, this, "�2Repair vehicle for $" + v.price / 100);
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Next")) {
                plugin.openGarage(p, page + 1, p);
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Previous")) {
                if (page > 0) {
                    plugin.openGarage(p, page - 1, p);
                }
            }
        } else if (e.getAction() == InventoryAction.PICKUP_HALF) {
            if (p.hasPermission("vp.admin")) {
                if (e.getCurrentItem().getItemMeta().getDisplayName().contains("�c") || e.getCurrentItem().getItemMeta().getDisplayName().contains("�a") || e.getCurrentItem().getItemMeta().getDisplayName().contains("�6")) {
                    e.setCancelled(true);
                    String number = "";
                    if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(1) + "")) {
                        number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(1);
                        if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(2) + "")) {
                            number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(2);
                            if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(3) + "")) {
                                number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(3);
                                if (plugin.checkInt(e.getCurrentItem().getItemMeta().getDisplayName().charAt(4) + "")) {
                                    number = number + e.getCurrentItem().getItemMeta().getDisplayName().charAt(4);
                                }
                            }
                        }
                    }
                    final String number2 = number;
                    if (e.getCurrentItem().getItemMeta().getDisplayName().contains("�c")) {
                        new Confirmation(p, new ConfirmCallback() {

                            public void callback(Player player, CallbackResponse response) {
                                // TODO Auto-generated method stub
                                if (response == CallbackResponse.YES) {
                                    if (p.hasPermission("vp.admin")) {
                                        Vehicle v = plugin.playerVehicles.get(p).get(Integer.parseInt(number2));
                                        plugin.playerVehicles.get(p).remove(v);
                                        p.sendMessage("�2Vehicle removed");
                                    }
                                }
                            }
                        }, this, "�2Remove this vehicle?");
                    } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("�a")) {
                        new Confirmation(p, new ConfirmCallback() {

                            public void callback(Player player, CallbackResponse response) {
                                // TODO Auto-generated method stub
                                if (response == CallbackResponse.YES) {
                                    if (p.hasPermission("vp.admin")) {
                                        Vehicle v = plugin.playerVehicles.get(p).get(Integer.parseInt(number2));
                                        plugin.playerVehicles.get(p).remove(v);
                                        p.sendMessage("�2Vehicle removed");
                                    }
                                }
                            }
                        }, this, "�2Remove this vehicle?");
                    } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("�6")) {
                        new Confirmation(p, new ConfirmCallback() {

                            public void callback(Player player, CallbackResponse response) {
                                // TODO Auto-generated method stub
                                if (response == CallbackResponse.YES) {
                                    if (p.hasPermission("vp.admin")) {
                                        Vehicle v = plugin.playerVehicles.get(p).get(Integer.parseInt(number2));
                                        plugin.playerVehicles.get(p).remove(v);
                                        p.sendMessage("�2Vehicle removed");
                                        v.remove();
                                    }
                                }
                            }
                        }, this, "�2Remove this vehicle?");
                    }
                }
            }
        }
    } else if (e.getClickedInventory().getName().contains("Upgrade menu")) {
        e.setCancelled(true);
        if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Engine") && !e.getCurrentItem().getItemMeta().getLore().get(0).contains("�c")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer tier = v.engineTier;
                Integer price = 0;
                Double toadd = 0D;
                if (tier == 0) {
                    price = 15000;
                    toadd = 0.5;
                    v.engineTier = 1;
                } else if (tier == 1) {
                    price = 30000;
                    toadd = 0.5;
                    v.engineTier = 2;
                } else if (tier == 2) {
                    price = 45000;
                    toadd = 0.5;
                    v.engineTier = 3;
                } else if (tier == 3) {
                    price = 60000;
                    toadd = 0.5;
                    v.engineTier = 4;
                }
                Integer percentage = (int) (0.5 / v.fspeed * 100);
                final int price2 = price;
                final Double toadd2 = toadd;
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price2) {
                                plugin.econ.withdrawPlayer(owner, price2);
                                owner.sendMessage("�2Upgrade confirmed! It should be installed in a couple of splugin.econds!");
                                v.fspeed += toadd2;
                                v.bspeed += toadd2;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Engine upgrade �6$" + price + " �a+" + percentage + "%");
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Gearbox") && !e.getCurrentItem().getItemMeta().getLore().get(0).contains("�c")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 0;
                Double toadd = 0D;
                Integer tier = v.accelerationTier;
                if (tier == 0) {
                    price = 15000;
                    toadd = 0.005;
                    v.accelerationTier = 1;
                } else if (tier == 1) {
                    price = 30000;
                    toadd = 0.005;
                    v.accelerationTier = 2;
                } else if (tier == 2) {
                    price = 45000;
                    toadd = 0.005;
                    v.accelerationTier = 3;
                } else if (tier == 3) {
                    price = 60000;
                    toadd = 0.005;
                    v.accelerationTier = 4;
                }
                final int price2 = price;
                final Double toadd2 = toadd;
                Integer percentage = (int) (0.01 / v.acceleration * 100);
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price2) {
                                plugin.econ.withdrawPlayer(owner, price2);
                                owner.sendMessage("�2Upgrade confirmed! It should be installed in a couple of splugin.econds!");
                                v.acceleration += toadd2;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Acceleration upgrade �6$" + price + " �a+" + percentage + "%");
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Fuel") && !e.getCurrentItem().getItemMeta().getLore().get(0).contains("�c")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 0;
                Double toadd = 0D;
                Integer tier = v.fuelTier;
                if (tier == 0) {
                    price = 15000;
                    toadd = 50D;
                    v.fuelTier = 1;
                } else if (tier == 1) {
                    price = 30000;
                    toadd = 50D;
                    v.fuelTier = 2;
                } else if (tier == 2) {
                    price = 45000;
                    toadd = 50D;
                    v.fuelTier = 3;
                } else if (tier == 3) {
                    price = 60000;
                    toadd = 50D;
                    v.fuelTier = 4;
                }
                final int price2 = price;
                final Double toadd2 = toadd;
                Integer percentage = (int) (50 / v.maxFuel * 100);
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price2) {
                                plugin.econ.withdrawPlayer(owner, price2);
                                owner.sendMessage("�2Upgrade confirmed! It should be installed in a couple of splugin.econds!");
                                v.maxFuel += toadd2;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Fuel upgrade �6$" + price + " �a+" + percentage + "%");
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Steering") && !e.getCurrentItem().getItemMeta().getLore().get(0).contains("�c")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 0;
                Double toadd = 0D;
                Integer tier = v.steeringTier;
                if (tier == 0) {
                    price = 15000;
                    toadd = 0.5D;
                    v.steeringTier = 1;
                } else if (tier == 1) {
                    price = 30000;
                    toadd = 0.5D;
                    v.steeringTier = 2;
                } else if (tier == 2) {
                    price = 45000;
                    toadd = 0.5D;
                    v.steeringTier = 3;
                } else if (tier == 3) {
                    price = 60000;
                    toadd = 0.5D;
                    v.steeringTier = 4;
                }
                final int price2 = price;
                final Double toadd2 = toadd;
                Integer percentage = (int) (0.5 / v.turnSpeed * 100);
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price2) {
                                plugin.econ.withdrawPlayer(owner, price2);
                                owner.sendMessage("�2Upgrade confirmed! It should be installed in a couple of splugin.econds!");
                                v.steering += toadd2;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Steering upgrade �6$" + price + " �a+" + percentage + "%");
            }
        } else {
            p.sendMessage("�cThis part is already the highest tier!");
        }
    } else if (e.getClickedInventory().getName().contains("Select menu")) {
        e.setCancelled(true);
        if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Repair")) {
            if (plugin.select.containsKey(p)) {
                Vehicle v = plugin.select.get(p);
                plugin.openRepairMenu(p, v);
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Upgrade")) {
            if (plugin.select.containsKey(p)) {
                Vehicle v = plugin.select.get(p);
                plugin.openUpgradeMenu(p, v);
            }
        }
    } else if (e.getClickedInventory().getName().contains("Repair menu")) {
        e.setCancelled(true);
        if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Engine")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 2000;
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price) {
                                plugin.econ.withdrawPlayer(owner, price);
                                owner.sendMessage("�2Repair confirmed! The new engine should be installed in a couple of splugin.econds");
                                v.parts.ENGINE = true;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Repair engine? Price: $" + price);
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Wheel Front Right")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 200;
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price) {
                                plugin.econ.withdrawPlayer(owner, price);
                                owner.sendMessage("�2Repair confirmed! The new tire should be installed in a couple of splugin.econds");
                                v.parts.WHEELFR = true;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Replace tire? Price: $" + price);
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Wheel Front Left")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 200;
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price) {
                                plugin.econ.withdrawPlayer(owner, price);
                                owner.sendMessage("�2Repair confirmed! The new tire should be installed in a couple of splugin.econds");
                                v.parts.WHEELFL = true;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Replace tire? Price: $" + price);
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Wheel Rear Right")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 200;
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price) {
                                plugin.econ.withdrawPlayer(owner, price);
                                owner.sendMessage("�2Repair confirmed! The new tire should be installed in a couple of splugin.econds");
                                v.parts.WHEELRR = true;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Replace tire? Price: $" + price);
            }
        } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Wheel Rear Left")) {
            if (plugin.upgrading.containsKey(p)) {
                Vehicle v = plugin.upgrading.get(p);
                Player owner = v.p.p;
                Integer price = 200;
                new Confirmation(owner, new ConfirmCallback() {

                    public void callback(Player player, CallbackResponse response) {
                        // TODO Auto-generated method stub
                        if (response == CallbackResponse.YES) {
                            if (plugin.econ.getBalance(owner) >= price) {
                                plugin.econ.withdrawPlayer(owner, price);
                                owner.sendMessage("�2Repair confirmed! The new tire should be installed in a couple of splugin.econds");
                                v.parts.WHEELRL = true;
                            } else {
                                owner.sendMessage("�2You don't have enough money!");
                            }
                        }
                    }
                }, this, "�2Replace tire? Price: $" + price);
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) Player(org.bukkit.entity.Player) ConfirmCallback(me.legofreak107.vehicles.libs.ConfirmCallback) CallbackResponse(me.legofreak107.vehicles.libs.ConfirmCallback.CallbackResponse) ItemStack(org.bukkit.inventory.ItemStack) Confirmation(me.legofreak107.vehicles.libs.Confirmation) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ConfirmCallback (me.legofreak107.vehicles.libs.ConfirmCallback)1 CallbackResponse (me.legofreak107.vehicles.libs.ConfirmCallback.CallbackResponse)1 Confirmation (me.legofreak107.vehicles.libs.Confirmation)1 Vehicle (me.legofreak107.vehicles.objects.Vehicle)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1