Search in sources :

Example 1 with Seat

use of me.legofreak107.vehicles.objects.Seat 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)

Example 2 with Seat

use of me.legofreak107.vehicles.objects.Seat in project VehiclesPlus2.0 by legofreak107.

the class PlayerInteract method onInteractBlock.

@EventHandler
public void onInteractBlock(PlayerInteractEvent e) {
    if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && !e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("key")) {
            String vpname = e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().replace("�2", "");
            if (plugin.isValidVehicle(vpname)) {
                e.setCancelled(true);
                Vehicle v = plugin.getVehicle(vpname);
                v.fuel = v.maxFuel / 4;
                v.owner = e.getPlayer().getName();
                VPPlayer pla = new VPPlayer();
                pla.p = e.getPlayer();
                v.p = pla;
                v.spawnLoc = e.getClickedBlock().getLocation().add(new Vector(0, 1, 0));
                v.spawn();
                e.getPlayer().getInventory().removeItem(e.getPlayer().getInventory().getItemInMainHand());
            }
        }
    } else if (e.getAction() == Action.RIGHT_CLICK_AIR) {
        if (e.getPlayer().isInsideVehicle()) {
            if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("key")) {
                String vpname = e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().split(" ")[0].replace("�2", "");
                if (plugin.isValidVehicle(vpname)) {
                    e.setCancelled(true);
                    Seat s = plugin.seatInfo.get(e.getPlayer().getVehicle());
                    Vehicle v = plugin.vehicleInfo.get(s.parent);
                    if (v.name.equalsIgnoreCase(vpname)) {
                        v.running = !v.running;
                        if (v.running)
                            e.getPlayer().sendMessage("�2Engine started!");
                        if (!v.running)
                            e.getPlayer().sendMessage("�2Engine turned off!");
                    }
                }
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) VPPlayer(me.legofreak107.vehicles.objects.VPPlayer) Seat(me.legofreak107.vehicles.objects.Seat) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Seat

use of me.legofreak107.vehicles.objects.Seat in project VehiclesPlus2.0 by legofreak107.

the class Boat method Boat.

public static void Boat(PacketPlayInSteerVehicle ppisv, Player p) {
    ArmorStand a2 = (ArmorStand) p.getVehicle();
    a2.setGravity(false);
    Seat s = plugin.seatInfo.get(a2);
    ArmorStand a = (ArmorStand) s.parent;
    Vehicle v = plugin.vehicleInfo.get(a);
    v.holder.setGravity(false);
    if (p.getOpenInventory() != null && p.getOpenInventory() instanceof PlayerInventory) {
        p.openInventory(v.inv);
    }
    float forward = ppisv.b();
    float side = ppisv.a();
    if (v.fuelbar == null) {
        BossBar b = Bukkit.createBossBar("fuel" + v.owner, BarColor.GREEN, BarStyle.SOLID);
        v.fuelbar = b;
    }
    Location tloc = a2.getLocation().clone();
    Location smoke = tloc.add(tloc.getDirection().setY(0).normalize().multiply(-1.5));
    smoke.getWorld().spawnParticle(Particle.SMOKE_LARGE, smoke.getX(), smoke.getY() + 1, smoke.getZ(), 1, 0, 0, 0, 0);
    v.fuelbar.setTitle("Fuel: " + (int) (v.fuel / v.maxFuel * 100) + "%");
    v.fuelbar.setProgress((v.fuel / v.maxFuel));
    if (!v.parts.ENGINE) {
    } else {
        if (v.fuelbar.getPlayers().contains(p)) {
        } else {
            v.fuelbar.addPlayer(p);
            v.fuelbar.setVisible(true);
        }
        if (v.fuel <= 0.5) {
            v.fuelbar.setTitle("Out of fuel!");
        } else {
            v.fuel -= v.fualUsage / 2;
            if (forward > 0) {
                // Forward[W]
                int broken = randInt(0, 20000);
                int brokenEngine = randInt(0, 20000);
                if (brokenEngine == 0) {
                    v.parts.ENGINE = false;
                    p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 10, 10);
                    p.sendMessage("�2It looks like you have blown up your engine...");
                }
                v.fuel -= v.fualUsage / 2;
                if (v.curSpeed <= v.fspeed || v.curSpeed == 0) {
                    v.curSpeed = v.curSpeed += v.acceleration / 2;
                }
                Location fb = v.holder.getLocation().add(v.holder.getLocation().getDirection().setY(0).normalize().multiply(4));
                float z1 = (float) (fb.getZ() + (4 * Math.sin(Math.toRadians(fb.getYaw() + 90 * 0))));
                float x1 = (float) (fb.getX() + (4 * Math.cos(Math.toRadians(fb.getYaw() + 90 * 0))));
                float z2 = (float) (fb.getZ() + (-4 * Math.sin(Math.toRadians(fb.getYaw() + 90 * 0))));
                float x2 = (float) (fb.getX() + (-4 * Math.cos(Math.toRadians(fb.getYaw() + 90 * 0))));
                Location loc1 = new Location(fb.getWorld(), x1, fb.getY(), z1);
                Location loc2 = new Location(fb.getWorld(), x2, fb.getY(), z2);
                if (fb.getBlock().getType() == Material.STATIONARY_WATER) {
                    if (side > 0) {
                        // Side[A]
                        if (loc1.getBlock().getType() == Material.STATIONARY_WATER && loc2.getBlock().getType() == Material.STATIONARY_WATER) {
                            v.skinHolder.setHeadPose(new EulerAngle(0, 0, 170));
                            EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                            Location loc = a.getLocation().clone();
                            loc.setYaw(loc.getYaw() + 90);
                            a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
                            a1.move(EnumMoveType.SELF, new Vector(loc.getDirection().multiply(0.5).getX(), 0, loc.getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(loc.getDirection().multiply(0.5).getX(), 0, loc.getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), new Vector(loc.getDirection().multiply(0.5).getX(), 0, loc.getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                            a1.move(EnumMoveType.SELF, new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                            v.steering = (int) (v.turnSpeed / 2);
                        }
                    } else if (side < 0) {
                        // Side[D]
                        if (loc1.getBlock().getType() == Material.STATIONARY_WATER && loc2.getBlock().getType() == Material.STATIONARY_WATER) {
                            v.skinHolder.setHeadPose(new EulerAngle(0, 0, -170));
                            EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                            Location loc = a.getLocation().clone();
                            loc.setYaw(loc.getYaw() - 90);
                            a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
                            a1.move(EnumMoveType.SELF, new Vector(loc.getDirection().multiply(0.5).getX(), 0, loc.getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(loc.getDirection().multiply(0.5).getX(), 0, loc.getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), new Vector(loc.getDirection().multiply(0.5).getX(), 0, loc.getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                            a1.move(EnumMoveType.SELF, new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                            v.steering = -(int) (v.turnSpeed / 2);
                        }
                    } else {
                        v.steering = 0;
                        v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
                        EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                        a1.move(EnumMoveType.SELF, new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                    }
                } else {
                    v.curSpeed = 0;
                }
            } else if (forward < 0) {
                // Reverse[S]
                Location fb = v.holder.getLocation().add(v.holder.getLocation().getDirection().setY(0).normalize().multiply(-4));
                float z1 = (float) (fb.getZ() + (4 * Math.sin(Math.toRadians(fb.getYaw() + 90 * 0))));
                float x1 = (float) (fb.getX() + (4 * Math.cos(Math.toRadians(fb.getYaw() + 90 * 0))));
                float z2 = (float) (fb.getZ() + (-4 * Math.sin(Math.toRadians(fb.getYaw() + 90 * 0))));
                float x2 = (float) (fb.getX() + (-4 * Math.cos(Math.toRadians(fb.getYaw() + 90 * 0))));
                Location loc1 = new Location(fb.getWorld(), x1, fb.getY(), z1);
                Location loc2 = new Location(fb.getWorld(), x2, fb.getY(), z2);
                if (fb.getBlock().getType() == Material.STATIONARY_WATER) {
                    v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
                    v.fuel -= v.fualUsage / 2;
                    Location loc3 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() + 1);
                    Location loc4 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() - 1);
                    Location loc5 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
                    if (v.curSpeed >= -v.bspeed || v.curSpeed == 0) {
                        v.curSpeed = v.curSpeed -= v.acceleration * 2;
                    }
                    if ((loc1.getBlock().getType() != Material.AIR && loc1.getBlock().getType() != Material.LONG_GRASS && loc1.getBlock().getType() != Material.CHORUS_FLOWER && loc1.getBlock().getType() != Material.YELLOW_FLOWER && loc1.getBlock().getType() != Material.RED_ROSE && loc1.getBlock().getType() != Material.WHEAT) || (loc2.getBlock().getType() != Material.AIR && loc2.getBlock().getType() != Material.LONG_GRASS && loc2.getBlock().getType() != Material.CHORUS_FLOWER && loc2.getBlock().getType() != Material.YELLOW_FLOWER && loc2.getBlock().getType() != Material.RED_ROSE && loc2.getBlock().getType() != Material.WHEAT) || (loc3.getBlock().getType() != Material.AIR && loc3.getBlock().getType() != Material.LONG_GRASS && loc3.getBlock().getType() != Material.CHORUS_FLOWER && loc3.getBlock().getType() != Material.YELLOW_FLOWER && loc3.getBlock().getType() != Material.RED_ROSE && loc3.getBlock().getType() != Material.WHEAT) || (loc4.getBlock().getType() != Material.AIR && loc4.getBlock().getType() != Material.LONG_GRASS && loc4.getBlock().getType() != Material.CHORUS_FLOWER && loc4.getBlock().getType() != Material.YELLOW_FLOWER && loc4.getBlock().getType() != Material.RED_ROSE && loc4.getBlock().getType() != Material.WHEAT) && loc5.getBlock().getType() != Material.AIR) {
                        EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                        a1.move(EnumMoveType.SELF, new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), // a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -1, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(- BwdDriveSpeed.get(a.getUniqueId())));
                        new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                    } else {
                        EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                        a1.move(EnumMoveType.SELF, new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                    }
                    if (side > 0) {
                        // Side[A]
                        if (loc1.getBlock().getType() == Material.STATIONARY_WATER && loc2.getBlock().getType() == Material.STATIONARY_WATER) {
                            EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                            a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
                            v.steering = (int) (v.turnSpeed / 2);
                        }
                    } else if (side < 0) {
                        // Side[D]
                        if (loc1.getBlock().getType() == Material.STATIONARY_WATER && loc2.getBlock().getType() == Material.STATIONARY_WATER) {
                            EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                            a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
                            v.steering = -(int) (v.turnSpeed / 2);
                        }
                    } else {
                        v.steering = 0;
                        v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
                    }
                } else {
                    v.curSpeed = 0;
                }
            } else {
                v.steering = 0;
                if (v.curSpeed > v.acceleration) {
                    v.curSpeed = v.curSpeed -= v.acceleration;
                } else if (v.curSpeed < -v.acceleration) {
                    v.curSpeed = v.curSpeed += v.acceleration;
                } else {
                    v.curSpeed = 0;
                }
                EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                Location fb = v.holder.getLocation().add(v.holder.getLocation().getDirection().setY(0).normalize().multiply(4));
                Location fb2 = v.holder.getLocation().add(v.holder.getLocation().getDirection().setY(0).normalize().multiply(-4));
                if (fb.getBlock().getType() == Material.STATIONARY_WATER && fb2.getBlock().getType() == Material.STATIONARY_WATER) {
                    a1.move(EnumMoveType.SELF, new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getX(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getY(), new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed).getZ());
                } else {
                    v.curSpeed = 0;
                }
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) PacketPlayInSteerVehicle(net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle) Seat(me.legofreak107.vehicles.objects.Seat) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) ArmorStand(org.bukkit.entity.ArmorStand) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) BossBar(org.bukkit.boss.BossBar) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) PlayerInventory(org.bukkit.inventory.PlayerInventory) EulerAngle(org.bukkit.util.EulerAngle) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 4 with Seat

use of me.legofreak107.vehicles.objects.Seat in project VehiclesPlus2.0 by legofreak107.

the class Bike method Bike.

public static void Bike(PacketPlayInSteerVehicle ppisv, Player p) {
    ArmorStand a2 = (ArmorStand) p.getVehicle();
    Seat s = plugin.seatInfo.get(a2);
    ArmorStand a = (ArmorStand) s.parent;
    Vehicle v = plugin.vehicleInfo.get(a);
    if (p.getOpenInventory() != null && p.getOpenInventory() instanceof PlayerInventory) {
        p.openInventory(v.inv);
    }
    float forward = ppisv.b();
    float side = ppisv.a();
    if (v.fuelbar == null) {
        BossBar b = Bukkit.createBossBar("fuel" + v.owner, BarColor.GREEN, BarStyle.SOLID);
        v.fuelbar = b;
    }
    Location tloc = a2.getLocation().clone();
    Location smoke = tloc.add(tloc.getDirection().setY(0).normalize().multiply(-1.5));
    smoke.getWorld().spawnParticle(Particle.SMOKE_LARGE, smoke.getX(), smoke.getY() + 1, smoke.getZ(), 1, 0, 0, 0, 0);
    v.fuelbar.setTitle("Fuel: " + (int) (v.fuel / v.maxFuel * 100) + "%");
    v.fuelbar.setProgress((v.fuel / v.maxFuel));
    if (!v.parts.ENGINE) {
    } else {
        if (v.fuelbar.getPlayers().contains(p)) {
        } else {
            v.fuelbar.addPlayer(p);
            v.fuelbar.setVisible(true);
        }
        if (v.fuel <= 0.5) {
            v.fuelbar.setTitle("Out of fuel!");
        } else {
            v.fuel -= v.fualUsage / 2;
            if (forward > 0) {
                // Forward[W]
                int broken = randInt(0, 20000);
                int brokenEngine = randInt(0, 20000);
                if (brokenEngine == 0) {
                    v.parts.ENGINE = false;
                    p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 10, 10);
                    p.sendMessage("�2It looks like you have blown up your engine...");
                } else if (broken == 1) {
                    v.parts.WHEELFL = false;
                    p.sendMessage("�2It looks like your rear tire is flat.");
                } else if (broken == 2) {
                    v.parts.WHEELFR = false;
                    p.sendMessage("�2It looks like your front tire is flat.");
                }
                v.fuel -= v.fualUsage / 2;
                if (v.curSpeed <= v.fspeed || v.curSpeed == 0) {
                    v.curSpeed = v.curSpeed += v.acceleration / 2;
                }
                if (!v.parts.WHEELFL || !v.parts.WHEELFR || !v.parts.WHEELRL || !v.parts.WHEELRR) {
                    a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed / 4));
                } else {
                    a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
                }
                if (side > 0) {
                    // Side[A]
                    v.skinHolder.setHeadPose(new EulerAngle(0, 0, 170));
                    EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                    a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
                    v.steering = (int) (v.turnSpeed / 2);
                } else if (side < 0) {
                    // Side[D]
                    v.skinHolder.setHeadPose(new EulerAngle(0, 0, -170));
                    EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                    a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
                    v.steering = -(int) (v.turnSpeed / 2);
                } else {
                    v.steering = 0;
                    v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
                }
            } else if (forward < 0) {
                // Reverse[S]
                v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
                v.fuel -= v.fualUsage / 2;
                Location loc1 = new Location(a.getWorld(), a.getLocation().getBlockX() + 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
                Location loc2 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
                Location loc3 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() + 1);
                Location loc4 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() - 1);
                Location loc5 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
                if (v.curSpeed >= -v.bspeed || v.curSpeed == 0) {
                    v.curSpeed = v.curSpeed -= v.acceleration * 2;
                }
                if ((loc1.getBlock().getType() != Material.AIR && loc1.getBlock().getType() != Material.LONG_GRASS && loc1.getBlock().getType() != Material.CHORUS_FLOWER && loc1.getBlock().getType() != Material.YELLOW_FLOWER && loc1.getBlock().getType() != Material.RED_ROSE && loc1.getBlock().getType() != Material.WHEAT) || (loc2.getBlock().getType() != Material.AIR && loc2.getBlock().getType() != Material.LONG_GRASS && loc2.getBlock().getType() != Material.CHORUS_FLOWER && loc2.getBlock().getType() != Material.YELLOW_FLOWER && loc2.getBlock().getType() != Material.RED_ROSE && loc2.getBlock().getType() != Material.WHEAT) || (loc3.getBlock().getType() != Material.AIR && loc3.getBlock().getType() != Material.LONG_GRASS && loc3.getBlock().getType() != Material.CHORUS_FLOWER && loc3.getBlock().getType() != Material.YELLOW_FLOWER && loc3.getBlock().getType() != Material.RED_ROSE && loc3.getBlock().getType() != Material.WHEAT) || (loc4.getBlock().getType() != Material.AIR && loc4.getBlock().getType() != Material.LONG_GRASS && loc4.getBlock().getType() != Material.CHORUS_FLOWER && loc4.getBlock().getType() != Material.YELLOW_FLOWER && loc4.getBlock().getType() != Material.RED_ROSE && loc4.getBlock().getType() != Material.WHEAT) && loc5.getBlock().getType() != Material.AIR) {
                    a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
                // a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -1, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(- BwdDriveSpeed.get(a.getUniqueId())));
                } else {
                    a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
                }
                if (side > 0) {
                    // Side[A]
                    EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                    a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
                    v.steering = (int) (v.turnSpeed / 2);
                } else if (side < 0) {
                    // Side[D]
                    EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                    a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
                    v.steering = -(int) (v.turnSpeed / 2);
                } else {
                    v.steering = 0;
                    v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
                }
            } else {
                v.steering = 0;
                if (v.curSpeed > v.acceleration) {
                    v.curSpeed = v.curSpeed -= v.acceleration;
                } else if (v.curSpeed < -v.acceleration) {
                    v.curSpeed = v.curSpeed += v.acceleration;
                } else {
                    v.curSpeed = 0;
                }
                a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) PacketPlayInSteerVehicle(net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle) Seat(me.legofreak107.vehicles.objects.Seat) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) ArmorStand(org.bukkit.entity.ArmorStand) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) BossBar(org.bukkit.boss.BossBar) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) PlayerInventory(org.bukkit.inventory.PlayerInventory) EulerAngle(org.bukkit.util.EulerAngle) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 5 with Seat

use of me.legofreak107.vehicles.objects.Seat in project VehiclesPlus2.0 by legofreak107.

the class Car method Car.

public static void Car(PacketPlayInSteerVehicle ppisv, Player p) {
    ArmorStand a2 = (ArmorStand) p.getVehicle();
    Seat s = plugin.seatInfo.get(a2);
    ArmorStand a = (ArmorStand) s.parent;
    Vehicle v = plugin.vehicleInfo.get(a);
    if (v.running) {
        if (v.curSpeed > 0)
            v.mileAge += 0.005 * v.curSpeed;
        if (v.curSpeed < 0)
            v.mileAge -= 0.005 * v.curSpeed;
        if (p.getOpenInventory() != null && p.getOpenInventory() instanceof PlayerInventory) {
            p.openInventory(v.inv);
        }
        float forward = ppisv.b();
        float side = ppisv.a();
        if (v.fuelbar == null) {
            BossBar b = Bukkit.createBossBar("fuel" + v.owner, BarColor.GREEN, BarStyle.SOLID);
            v.fuelbar = b;
        }
        Location tloc = a2.getLocation().clone();
        Location smoke = tloc.add(tloc.getDirection().setY(0).normalize().multiply(-1.5));
        smoke.getWorld().spawnParticle(Particle.SMOKE_LARGE, smoke.getX(), smoke.getY() + 1, smoke.getZ(), 1, 0, 0, 0, 0);
        v.fuelbar.setTitle("�2Fuel: " + (int) (v.fuel / v.maxFuel * 100) + "%");
        v.fuelbar.setProgress((v.fuel / v.maxFuel));
        p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder("�6Mileage: " + (int) v.mileAge).create());
        if (!v.parts.ENGINE) {
        } else {
            if (v.fuelbar.getPlayers().contains(p)) {
            } else {
                v.fuelbar.addPlayer(p);
                v.fuelbar.setVisible(true);
            }
            if (v.fuel <= 0.5) {
                v.fuelbar.setTitle("Out of fuel!");
                v.running = false;
            } else {
                v.fuel -= v.fualUsage / 2;
                if (forward > 0) {
                    // Forward[W]
                    int broken = randInt(0, (int) (20000));
                    int brokenEngine = randInt(0, (int) (5000000 / (v.mileAge + 1)));
                    int oil = randInt(0, 100);
                    if (brokenEngine == 0) {
                        v.parts.ENGINE = false;
                        p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 10, 10);
                        p.sendMessage("�2It looks like you have blown up your engine...");
                    } else if (broken == 1) {
                        v.parts.WHEELFL = false;
                        p.sendMessage("�2It looks like your front left tire is flat.");
                    } else if (broken == 2) {
                        v.parts.WHEELFR = false;
                        p.sendMessage("�2It looks like your front right tire is flat.");
                    } else if (broken == 3) {
                        v.parts.WHEELRL = false;
                        p.sendMessage("�2It looks like your rear left tire is flat.");
                    } else if (broken == 4) {
                        v.parts.WHEELRR = false;
                        p.sendMessage("�2It looks like your rear right tire is flat.");
                    }
                    v.fuel -= v.fualUsage / 2;
                    if (v.curSpeed <= v.fspeed || v.curSpeed == 0) {
                        v.curSpeed = v.curSpeed += v.acceleration / 2;
                    }
                    if (!v.parts.WHEELFL || !v.parts.WHEELFR || !v.parts.WHEELRL || !v.parts.WHEELRR) {
                        a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed / 4));
                    } else {
                        a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
                    }
                    if (side > 0) {
                        // Side[A]
                        EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                        a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
                        v.steering = (int) (v.turnSpeed / 2);
                    } else if (side < 0) {
                        // Side[D]
                        EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                        a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
                        v.steering = -(int) (v.turnSpeed / 2);
                    } else {
                        v.steering = 0;
                    }
                } else if (forward < 0) {
                    // Reverse[S]
                    v.fuel -= v.fualUsage / 2;
                    Location loc1 = new Location(a.getWorld(), a.getLocation().getBlockX() + 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
                    Location loc2 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
                    Location loc3 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() + 1);
                    Location loc4 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() - 1);
                    Location loc5 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
                    if (v.curSpeed >= -v.bspeed || v.curSpeed == 0) {
                        v.curSpeed = v.curSpeed -= v.acceleration * 2;
                    }
                    if ((loc1.getBlock().getType() != Material.AIR && loc1.getBlock().getType() != Material.LONG_GRASS && loc1.getBlock().getType() != Material.CHORUS_FLOWER && loc1.getBlock().getType() != Material.YELLOW_FLOWER && loc1.getBlock().getType() != Material.RED_ROSE && loc1.getBlock().getType() != Material.WHEAT) || (loc2.getBlock().getType() != Material.AIR && loc2.getBlock().getType() != Material.LONG_GRASS && loc2.getBlock().getType() != Material.CHORUS_FLOWER && loc2.getBlock().getType() != Material.YELLOW_FLOWER && loc2.getBlock().getType() != Material.RED_ROSE && loc2.getBlock().getType() != Material.WHEAT) || (loc3.getBlock().getType() != Material.AIR && loc3.getBlock().getType() != Material.LONG_GRASS && loc3.getBlock().getType() != Material.CHORUS_FLOWER && loc3.getBlock().getType() != Material.YELLOW_FLOWER && loc3.getBlock().getType() != Material.RED_ROSE && loc3.getBlock().getType() != Material.WHEAT) || (loc4.getBlock().getType() != Material.AIR && loc4.getBlock().getType() != Material.LONG_GRASS && loc4.getBlock().getType() != Material.CHORUS_FLOWER && loc4.getBlock().getType() != Material.YELLOW_FLOWER && loc4.getBlock().getType() != Material.RED_ROSE && loc4.getBlock().getType() != Material.WHEAT) && loc5.getBlock().getType() != Material.AIR) {
                        a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
                    // a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -1, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(- BwdDriveSpeed.get(a.getUniqueId())));
                    } else {
                        a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
                    }
                    if (side > 0) {
                        // Side[A]
                        EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                        a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
                        v.steering = (int) (v.turnSpeed / 2);
                    } else if (side < 0) {
                        // Side[D]
                        EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
                        a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
                        v.steering = -(int) (v.turnSpeed / 2);
                    } else {
                        v.steering = 0;
                    }
                } else {
                    v.steering = 0;
                    if (v.curSpeed > v.acceleration) {
                        v.curSpeed = v.curSpeed -= v.acceleration;
                    } else if (v.curSpeed < -v.acceleration) {
                        v.curSpeed = v.curSpeed += v.acceleration;
                    } else {
                        v.curSpeed = 0;
                    }
                    a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
                }
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) PacketPlayInSteerVehicle(net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle) Seat(me.legofreak107.vehicles.objects.Seat) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) ArmorStand(org.bukkit.entity.ArmorStand) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) BossBar(org.bukkit.boss.BossBar) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) PlayerInventory(org.bukkit.inventory.PlayerInventory) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

Seat (me.legofreak107.vehicles.objects.Seat)12 Vehicle (me.legofreak107.vehicles.objects.Vehicle)12 PacketPlayInSteerVehicle (net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle)8 ArmorStand (org.bukkit.entity.ArmorStand)8 Vector (org.bukkit.util.Vector)7 EntityArmorStand (net.minecraft.server.v1_12_R1.EntityArmorStand)6 CraftArmorStand (org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand)6 Location (org.bukkit.Location)5 ItemStack (org.bukkit.inventory.ItemStack)4 ArrayList (java.util.ArrayList)3 Fuel (me.legofreak107.vehicles.objects.Fuel)3 VPPlayer (me.legofreak107.vehicles.objects.VPPlayer)3 BossBar (org.bukkit.boss.BossBar)3 EventHandler (org.bukkit.event.EventHandler)3 PlayerInventory (org.bukkit.inventory.PlayerInventory)3 EulerAngle (org.bukkit.util.EulerAngle)3 PlayerInteractAtEntity (me.legofreak107.vehicles.events.PlayerInteractAtEntity)2 Entity (org.bukkit.entity.Entity)2 Player (org.bukkit.entity.Player)2 Inventory (org.bukkit.inventory.Inventory)2