Search in sources :

Example 6 with Fuel

use of me.legofreak107.vehicles.objects.Fuel 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 7 with Fuel

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

Example 8 with Fuel

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

the class PlayerInteractAtEntity method onInteractEntity.

@EventHandler
public void onInteractEntity(PlayerInteractAtEntityEvent e) {
    if (e.getRightClicked().getCustomName() != null) {
        e.setCancelled(true);
    }
    if (plugin.vehicleInfo.containsKey(e.getRightClicked())) {
        e.setCancelled(true);
        if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("key")) {
            Vehicle v = plugin.vehicleInfo.get(e.getRightClicked());
            String vpname = e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().replace("�2", "").replace(" key", "");
            if (plugin.isValidVehicle(vpname)) {
                if (v.name.equalsIgnoreCase(vpname) && v.owner.contains(e.getPlayer().getName())) {
                    v.locked = !v.locked;
                    String str = "Locked";
                    if (v.locked) {
                        str = "locked";
                    } else {
                        str = "unlocked";
                    }
                    e.getPlayer().sendMessage("�2This vehicle is now: �6" + str);
                }
            }
        } else if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && !e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Wrench") && !e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Winch") && !e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Oil") && !e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Paint") && !e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Key")) {
            Fuel fuel = new Fuel();
            fuel.name = "empty";
            for (Fuel f : plugin.fuelTypes) {
                if (f.item.getItemMeta().getDisplayName().contains(e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName())) {
                    fuel = f;
                }
            }
            Vehicle v = plugin.vehicleInfo.get(e.getRightClicked());
            if (v.fuelType.name.equals(fuel.name)) {
                if (v.fuel + fuel.fuelAmount <= v.maxFuel) {
                    v.fuel += fuel.fuelAmount;
                    e.getPlayer().getInventory().removeItem(e.getPlayer().getInventory().getItemInMainHand());
                    e.getPlayer().sendMessage("�2Vehicle fueled to: �6" + (int) (v.fuel / v.maxFuel * 100) + "�2%");
                } else {
                    if (v.fuel != v.maxFuel) {
                        v.fuel = v.maxFuel;
                        e.getPlayer().getInventory().removeItem(e.getPlayer().getInventory().getItemInMainHand());
                        e.getPlayer().sendMessage("�2Vehicle fueled to: �6" + (int) (v.fuel / v.maxFuel * 100) + "�2%");
                    }
                }
            } else {
                e.getPlayer().sendMessage("�cThis vehicle does not operate on this fuel!");
            }
        } else if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Winch")) {
            Vehicle v = plugin.vehicleInfo.get(e.getRightClicked());
            plugin.winching.put(e.getPlayer(), v);
            e.getPlayer().sendMessage("�2Selected vehicle to winch, click a trailer to lock it.");
        } else if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Refined Oil")) {
            Vehicle v = plugin.vehicleInfo.get(e.getRightClicked());
            e.getPlayer().sendMessage("�2Oil changed!");
            e.getPlayer().getInventory().removeItem(e.getPlayer().getInventory().getItemInMainHand());
        } else if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Paint")) {
            Vehicle v = plugin.vehicleInfo.get(e.getRightClicked());
            int r = Integer.parseInt(e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().get(0).replace("�8Red: ", ""));
            int g = Integer.parseInt(e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().get(1).replace("�8Green: ", ""));
            int b = Integer.parseInt(e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().get(2).replace("�8Blue: ", ""));
            ItemStack item = v.skinHolder.getHelmet();
            if (item.getType() == Material.LEATHER_BOOTS) {
                LeatherArmorMeta lm = (LeatherArmorMeta) item.getItemMeta();
                lm.setColor(Color.fromRGB(r, g, b));
                item.setItemMeta(lm);
                v.skinHolder.setHelmet(item);
                v.skin = item;
                e.getPlayer().sendMessage("�2Car painted!");
                e.getPlayer().getInventory().removeItem(e.getPlayer().getInventory().getItemInMainHand());
            }
        } else if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("Wrench")) {
            Vehicle v = plugin.vehicleInfo.get(e.getRightClicked());
            plugin.openSelectMenu(e.getPlayer(), v);
        }
    }
    if (plugin.seatInfo.containsKey(e.getRightClicked())) {
        e.setCancelled(true);
        // Is seat
        if (e.getPlayer().isInsideVehicle()) {
            e.getPlayer().sendMessage("�2You can't switch seats. Please dismount your current seat first!");
        } else {
            Seat s = plugin.seatInfo.get(e.getRightClicked());
            Vehicle v = plugin.vehicleInfo.get(s.parent);
            if (v.locked) {
                if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("key")) {
                    String vpname = e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().replace("�2", "").replace(" key", "");
                    if (plugin.isValidVehicle(vpname)) {
                        if (v.name.equalsIgnoreCase(vpname) && v.owner.contains(e.getPlayer().getName())) {
                            if (s.steer) {
                                e.getPlayer().sendMessage("�2You entered a vehicle.");
                                s.seat.addPassenger(e.getPlayer());
                                e.getPlayer().sendMessage("�2You are in the drivers seat.");
                                e.getPlayer().sendMessage("�2You can control this vehicle with WASD (And space for planes).");
                                if (!v.running) {
                                    e.getPlayer().sendMessage("");
                                    e.getPlayer().sendMessage("�2This vehicle is not started yet...");
                                    e.getPlayer().sendMessage("�2Right click with the key to start it.");
                                }
                            } else {
                                e.getPlayer().sendMessage("�2This vehicle is locked!");
                                e.setCancelled(true);
                            }
                        }
                    }
                } else {
                    e.getPlayer().sendMessage("�2This vehicle is locked!");
                    e.setCancelled(true);
                }
            } else {
                e.getPlayer().sendMessage("�2You entered a vehicle.");
                s.seat.addPassenger(e.getPlayer());
                if (s.steer) {
                    e.getPlayer().sendMessage("�2You are in the drivers seat.");
                    e.getPlayer().sendMessage("�2You can control this vehicle with WASD (And space for planes).");
                    if (!v.running) {
                        e.getPlayer().sendMessage("");
                        e.getPlayer().sendMessage("�2This vehicle is not started yet...");
                        e.getPlayer().sendMessage("�2Right click with the key to start it.");
                    }
                } else {
                    e.getPlayer().sendMessage("�2You are in the passengers seat.");
                }
                e.setCancelled(true);
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) Seat(me.legofreak107.vehicles.objects.Seat) Fuel(me.legofreak107.vehicles.objects.Fuel) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Fuel

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

the class SignChange method onSignPlace.

@EventHandler
public void onSignPlace(SignChangeEvent e) {
    if (e.getLine(0).equalsIgnoreCase("[gas]")) {
        e.setLine(0, "�1[Gas]");
        String fuelname = e.getLine(1);
        Fuel f = plugin.getFuel(fuelname);
        if (f != null) {
            e.setLine(1, "�2" + f.name);
            e.setLine(2, "�3$" + f.fuelPrice);
        }
    } else if (e.getLine(0).equalsIgnoreCase("[garage]")) {
        e.setLine(0, "�1[Garage]");
        e.setLine(1, "�2Click to");
        e.setLine(2, "�2manage vehicles");
    }
}
Also used : Fuel(me.legofreak107.vehicles.objects.Fuel) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Fuel

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

the class Plane method Plane.

public static void Plane(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);
    ArmorStand a3 = (ArmorStand) v.skinHolder;
    float forward = ppisv.b();
    float side = ppisv.a();
    boolean space = ppisv.c();
    v.fuelbar.setTitle("Fuel: " + (int) (v.fuel / v.maxFuel * 100) + "%");
    v.fuelbar.setProgress((v.fuel / v.maxFuel));
    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]
            v.fuel -= v.fualUsage;
            if (v.curSpeed < v.fspeed) {
                v.curSpeed = v.curSpeed + v.acceleration / 20;
            }
            a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
        } else if (forward == 0) {
            if (v.curSpeed > 0) {
                v.curSpeed = v.curSpeed - v.acceleration / 20;
            }
            a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -0.1, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
        } else {
            if (v.curSpeed > 0) {
                v.curSpeed = v.curSpeed - v.acceleration / 20 * 3;
            }
            a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -0.2, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
        }
        if (forward > 0 && space) {
            if (v.curSpeed > (v.fspeed / 5 * 2)) {
                a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0.2, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
            } else {
                if (v.curSpeed < v.fspeed) {
                    v.curSpeed = v.curSpeed + v.acceleration / 20;
                }
                a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), 0, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
            }
        } else {
            a3.setHeadPose(new EulerAngle(0, 0, 0));
        }
        if (side > 0 && forward > 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());
            if (a.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) {
                a3.setHeadPose(new EulerAngle(0, 0, 170));
            }
        } else if (side < 0 && forward > 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());
            if (a.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) {
                a3.setHeadPose(new EulerAngle(0, 0, -170));
            }
        } else {
            a3.setHeadPose(new EulerAngle(0, 0, 0));
        }
        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());
        } 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());
        }
        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);
        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)) {
        }
    }
}
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) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) EulerAngle(org.bukkit.util.EulerAngle) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

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