Search in sources :

Example 1 with CraftArmorStand

use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftArmorStand 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 2 with CraftArmorStand

use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftArmorStand 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 3 with CraftArmorStand

use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftArmorStand 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 4 with CraftArmorStand

use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftArmorStand in project VehiclesPlus2.0 by legofreak107.

the class Main method onEnable.

@Override
public void onEnable() {
    ChunkUnload cu = new ChunkUnload(this);
    EntityDamage ed = new EntityDamage(this);
    EntityDismount edi = new EntityDismount(this);
    InventoryClick ic = new InventoryClick(this);
    InventoryClose icl = new InventoryClose(this, ic);
    PlayerDropItem pdi = new PlayerDropItem(this);
    PlayerInteract pi = new PlayerInteract(this);
    PlayerInteractAtEntity piae = new PlayerInteractAtEntity(this);
    PlayerJoin pj = new PlayerJoin(this);
    PlayerQuit pq = new PlayerQuit(this);
    SignChange sc = new SignChange(this);
    VehicleExit ve = new VehicleExit(this);
    Bukkit.getPluginManager().registerEvents(cu, this);
    Bukkit.getPluginManager().registerEvents(ed, this);
    Bukkit.getPluginManager().registerEvents(edi, this);
    Bukkit.getPluginManager().registerEvents(ic, this);
    Bukkit.getPluginManager().registerEvents(icl, this);
    Bukkit.getPluginManager().registerEvents(pdi, this);
    Bukkit.getPluginManager().registerEvents(pi, this);
    Bukkit.getPluginManager().registerEvents(piae, this);
    Bukkit.getPluginManager().registerEvents(pj, this);
    Bukkit.getPluginManager().registerEvents(pq, this);
    Bukkit.getPluginManager().registerEvents(sc, this);
    Bukkit.getPluginManager().registerEvents(ve, this);
    if (getCustomSettingsConfig().contains("Garage.maxCarsSpawnedPerPlayer")) {
        maxCars = getCustomSettingsConfig().getInt("Garage.maxCarsSpawnedPerPlayer");
    } else {
        getCustomSettingsConfig().set("Garage.maxCarsSpawnedPerPlayer", 3);
        saveCustomSettingsConfig();
    }
    if (getCustomSettingsConfig().contains("Items.upgrades")) {
        repairMenuItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.repairMenuItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.repairMenuItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.repairMenuItem.unbreakable"));
        upgradeMenuItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.upgradeMenuItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.upgradeMenuItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.upgradeMenuItem.unbreakable"));
        engineUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.engineUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.engineUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.engineUpgradeItem.unbreakable"));
        steeringUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.steeringUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.steeringUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.steeringUpgradeItem.unbreakable"));
        gearboxUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.gearboxUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.gearboxUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.gearboxUpgradeItem.unbreakable"));
        fuelUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.fuelUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.fuelUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.fuelUpgradeItem.unbreakable"));
        engineRepairItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.engineRepairItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.engineRepairItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.engineRepairItem.unbreakable"));
        wheelRepairItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.wheelRepairItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.wheelRepairItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.wheelRepairItem.unbreakable"));
    } else {
        getCustomSettingsConfig().set("Items.upgrades.repairMenuItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.repairMenuItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.repairMenuItem.unbreakable", false);
        getCustomSettingsConfig().set("Items.upgrades.upgradeMenuItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.upgradeMenuItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.upgradeMenuItem.unbreakable", false);
        getCustomSettingsConfig().set("Items.upgrades.engineUpgradeItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.engineUpgradeItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.engineUpgradeItem.unbreakable", false);
        getCustomSettingsConfig().set("Items.upgrades.steeringUpgradeItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.steeringUpgradeItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.steeringUpgradeItem.unbreakable", false);
        getCustomSettingsConfig().set("Items.upgrades.gearboxUpgradeItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.gearboxUpgradeItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.gearboxUpgradeItem.unbreakable", false);
        getCustomSettingsConfig().set("Items.upgrades.fuelUpgradeItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.fuelUpgradeItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.fuelUpgradeItem.unbreakable", false);
        getCustomSettingsConfig().set("Items.upgrades.engineRepairItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.engineRepairItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.engineRepairItem.unbreakable", false);
        getCustomSettingsConfig().set("Items.upgrades.wheelRepairItem.id", 1);
        getCustomSettingsConfig().set("Items.upgrades.wheelRepairItem.data", 0);
        getCustomSettingsConfig().set("Items.upgrades.wheelRepairItem.unbreakable", false);
        repairMenuItem = new ItemStack(Material.STONE, 1);
        upgradeMenuItem = new ItemStack(Material.STONE, 1);
        engineUpgradeItem = new ItemStack(Material.STONE, 1);
        steeringUpgradeItem = new ItemStack(Material.STONE, 1);
        gearboxUpgradeItem = new ItemStack(Material.STONE, 1);
        fuelUpgradeItem = new ItemStack(Material.STONE, 1);
        engineRepairItem = new ItemStack(Material.STONE, 1);
        wheelRepairItem = new ItemStack(Material.STONE, 1);
        saveCustomSettingsConfig();
    }
    Bukkit.getPluginManager().registerEvents(this, this);
    if (!setupEconomy()) {
        this.getLogger().severe("Disabled due to no Vault dependency found!");
        Bukkit.getPluginManager().disablePlugin(this);
        return;
    }
    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
    Bike.plugin = this;
    Plane.plugin = this;
    Car.plugin = this;
    Helicopter.plugin = this;
    Boat.plugin = this;
    sal.plugin = this;
    enable();
    protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.LOWEST, PacketType.Play.Client.STEER_VEHICLE) {

        @Override
        public void onPacketReceiving(PacketEvent event) {
            if (event.getPacketType().equals(PacketType.Play.Client.STEER_VEHICLE)) {
                PacketPlayInSteerVehicle ppisv = (PacketPlayInSteerVehicle) event.getPacket().getHandle();
                for (Seat s2 : seatInfo.values()) {
                    ArmorStand vp = s2.parent;
                    Location locvp = vp.getLocation().clone();
                    Location fbvp = locvp.add(locvp.getDirection().setY(0).normalize().multiply(s2.offset.getX()));
                    float zvp = (float) (fbvp.getZ() + (s2.offset.getZ() * Math.sin(Math.toRadians(fbvp.getYaw() + 90 * 0))));
                    float xvp = (float) (fbvp.getX() + (s2.offset.getZ() * Math.cos(Math.toRadians(fbvp.getYaw() + 90 * 0))));
                    Vehicle v = vehicleInfo.get(vp);
                    EntityArmorStand seat = ((CraftArmorStand) s2.seat).getHandle();
                    seat.setLocation(xvp, vp.getLocation().getY() + s2.offset.getY(), zvp, fbvp.getYaw(), fbvp.getPitch());
                    EntityArmorStand s3 = ((CraftArmorStand) v.skinHolder).getHandle();
                    s3.setLocation(vp.getLocation().getX(), vp.getLocation().getY(), vp.getLocation().getZ(), fbvp.getYaw(), fbvp.getPitch());
                }
                Player p = event.getPlayer();
                if (p.getVehicle() instanceof ArmorStand) {
                    ArmorStand a = (ArmorStand) p.getVehicle();
                    if (seatInfo.containsKey(a)) {
                        Seat s = seatInfo.get(a);
                        if (s.steer) {
                            ArmorStand a2 = s.parent;
                            Vehicle v = vehicleInfo.get(a2);
                            if (v.type == VehicleType.CAR) {
                                Car.Car(ppisv, p);
                            } else if (v.type == VehicleType.PLANE) {
                                Plane.Plane(ppisv, p);
                            } else if (v.type == VehicleType.BIKE) {
                                Bike.Bike(ppisv, p);
                            } else if (v.type == VehicleType.HELICOPTER) {
                                Helicopter.Helicopter(ppisv, p);
                            } else if (v.type == VehicleType.BOAT) {
                                Boat.Boat(ppisv, p);
                            }
                        }
                    }
                }
            }
        }
    });
    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

        public void run() {
            for (Vehicle v : vehicleInfo.values()) {
                if (v.type == VehicleType.CAR) {
                    for (Seat s : v.seats) {
                        for (Entity e : s.seat.getPassengers()) {
                            if (e instanceof Player) {
                                return;
                            }
                        }
                    }
                    Car.CarNonDriveable(v);
                }
            }
            for (Seat s2 : seatInfo.values()) {
                ArmorStand vp = s2.parent;
                Location locvp = vp.getLocation().clone();
                Location fbvp = locvp.add(locvp.getDirection().setY(0).normalize().multiply(s2.offset.getX()));
                float zvp = (float) (fbvp.getZ() + (s2.offset.getZ() * Math.sin(Math.toRadians(fbvp.getYaw() + 90 * 0))));
                float xvp = (float) (fbvp.getX() + (s2.offset.getZ() * Math.cos(Math.toRadians(fbvp.getYaw() + 90 * 0))));
                EntityArmorStand seat = ((CraftArmorStand) s2.seat).getHandle();
                seat.setLocation(xvp, vp.getLocation().getY() + s2.offset.getY(), zvp, fbvp.getYaw(), fbvp.getPitch());
                Vehicle v = vehicleInfo.get(vp);
                if (v.holder.getLocation().getBlock().getType() == Material.STATIONARY_WATER && v.type != VehicleType.BOAT) {
                    v.setHealth(0);
                } else if (v.holder.getLocation().getBlock().getType() == Material.STATIONARY_WATER && v.type == VehicleType.BOAT) {
                    v.holder.setGravity(false);
                }
                EntityArmorStand s3 = ((CraftArmorStand) v.skinHolder).getHandle();
                s3.setLocation(vp.getLocation().getX(), vp.getLocation().getY(), vp.getLocation().getZ(), fbvp.getYaw(), fbvp.getPitch());
            }
        }
    }, 0L, 1L);
}
Also used : EntityDismount(me.legofreak107.vehicles.events.EntityDismount) Entity(org.bukkit.entity.Entity) PlayerInteractAtEntity(me.legofreak107.vehicles.events.PlayerInteractAtEntity) Seat(me.legofreak107.vehicles.objects.Seat) PlayerQuit(me.legofreak107.vehicles.events.PlayerQuit) SignChange(me.legofreak107.vehicles.events.SignChange) PacketPlayInSteerVehicle(net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle) Vehicle(me.legofreak107.vehicles.objects.Vehicle) InventoryClick(me.legofreak107.vehicles.events.InventoryClick) CraftArmorStand(org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) ArmorStand(org.bukkit.entity.ArmorStand) PacketAdapter(com.comphenix.protocol.events.PacketAdapter) PlayerInteract(me.legofreak107.vehicles.events.PlayerInteract) VPPlayer(me.legofreak107.vehicles.objects.VPPlayer) Player(org.bukkit.entity.Player) InventoryClose(me.legofreak107.vehicles.events.InventoryClose) PacketPlayInSteerVehicle(net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) ChunkUnload(me.legofreak107.vehicles.events.ChunkUnload) VehicleExit(me.legofreak107.vehicles.events.VehicleExit) PlayerJoin(me.legofreak107.vehicles.events.PlayerJoin) PlayerInteractAtEntity(me.legofreak107.vehicles.events.PlayerInteractAtEntity) ProtocolManager(com.comphenix.protocol.ProtocolManager) PacketEvent(com.comphenix.protocol.events.PacketEvent) ItemStack(org.bukkit.inventory.ItemStack) PlayerDropItem(me.legofreak107.vehicles.events.PlayerDropItem) EntityDamage(me.legofreak107.vehicles.events.EntityDamage) Location(org.bukkit.Location)

Example 5 with CraftArmorStand

use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftArmorStand 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

Seat (me.legofreak107.vehicles.objects.Seat)5 Vehicle (me.legofreak107.vehicles.objects.Vehicle)5 EntityArmorStand (net.minecraft.server.v1_12_R1.EntityArmorStand)5 PacketPlayInSteerVehicle (net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle)5 Location (org.bukkit.Location)5 CraftArmorStand (org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand)5 ArmorStand (org.bukkit.entity.ArmorStand)5 Vector (org.bukkit.util.Vector)4 BossBar (org.bukkit.boss.BossBar)3 PlayerInventory (org.bukkit.inventory.PlayerInventory)3 EulerAngle (org.bukkit.util.EulerAngle)3 ProtocolManager (com.comphenix.protocol.ProtocolManager)1 PacketAdapter (com.comphenix.protocol.events.PacketAdapter)1 PacketEvent (com.comphenix.protocol.events.PacketEvent)1 ChunkUnload (me.legofreak107.vehicles.events.ChunkUnload)1 EntityDamage (me.legofreak107.vehicles.events.EntityDamage)1 EntityDismount (me.legofreak107.vehicles.events.EntityDismount)1 InventoryClick (me.legofreak107.vehicles.events.InventoryClick)1 InventoryClose (me.legofreak107.vehicles.events.InventoryClose)1 PlayerDropItem (me.legofreak107.vehicles.events.PlayerDropItem)1