Search in sources :

Example 1 with PacketPlayInSteerVehicle

use of net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle 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 PacketPlayInSteerVehicle

use of net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle 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 PacketPlayInSteerVehicle

use of net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle 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 PacketPlayInSteerVehicle

use of net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle in project Warlords by ebicep.

the class Warlords method onEnable.

@Override
public void onEnable() {
    instance = this;
    VERSION = this.getDescription().getVersion();
    serverIP = this.getServer().getIp();
    taskChainFactory = BukkitTaskChainFactory.create(this);
    gameManager = new GameManager();
    /*
         * Each map instance presents a game server, every map can hold up to 3 games at once.
         *
         * Adding a new map must start with -0 at the end and increment from there on out.
         *
         * Adding additional game servers will require a config update in @see MultiWorld Plugin
         */
    gameManager.addGameHolder("Rift-0", GameMap.RIFT, new LocationFactory(Bukkit.getWorld("Rift-0")));
    gameManager.addGameHolder("Rift-1", GameMap.RIFT, new LocationFactory(Bukkit.getWorld("Rift-1")));
    gameManager.addGameHolder("Rift-2", GameMap.RIFT, new LocationFactory(Bukkit.getWorld("Rift-2")));
    gameManager.addGameHolder("Crossfire-0", GameMap.CROSSFIRE, new LocationFactory(Bukkit.getWorld("Crossfire-0")));
    gameManager.addGameHolder("Crossfire-1", GameMap.CROSSFIRE, new LocationFactory(Bukkit.getWorld("Crossfire-1")));
    gameManager.addGameHolder("Crossfire-2", GameMap.CROSSFIRE, new LocationFactory(Bukkit.getWorld("Crossfire-2")));
    gameManager.addGameHolder("Valley-0", GameMap.VALLEY, new LocationFactory(Bukkit.getWorld("Atherrough_Valley-0")));
    gameManager.addGameHolder("Valley-1", GameMap.VALLEY, new LocationFactory(Bukkit.getWorld("Atherrough_Valley-1")));
    gameManager.addGameHolder("Valley-2", GameMap.VALLEY, new LocationFactory(Bukkit.getWorld("Atherrough_Valley-2")));
    gameManager.addGameHolder("Warsong-0", GameMap.WARSONG, new LocationFactory(Bukkit.getWorld("Warsong-0")));
    gameManager.addGameHolder("Warsong-1", GameMap.WARSONG, new LocationFactory(Bukkit.getWorld("Warsong-1")));
    gameManager.addGameHolder("Warsong-2", GameMap.WARSONG, new LocationFactory(Bukkit.getWorld("Warsong-2")));
    gameManager.addGameHolder("Aperture-0", GameMap.APERTURE, new LocationFactory(Bukkit.getWorld("Aperture-0")));
    gameManager.addGameHolder("Aperture-1", GameMap.APERTURE, new LocationFactory(Bukkit.getWorld("Aperture-1")));
    gameManager.addGameHolder("Aperture-2", GameMap.APERTURE, new LocationFactory(Bukkit.getWorld("Aperture-2")));
    gameManager.addGameHolder("Arathi-0", GameMap.ARATHI, new LocationFactory(Bukkit.getWorld("Arathi-0")));
    gameManager.addGameHolder("Arathi-1", GameMap.ARATHI, new LocationFactory(Bukkit.getWorld("Arathi-1")));
    gameManager.addGameHolder("Arathi-2", GameMap.ARATHI, new LocationFactory(Bukkit.getWorld("Arathi-2")));
    // CURRENTLY DISABLED
    // gameManager.addGameHolder("SimulationRift-0", GameMap.SIMULATION_RIFT, new LocationFactory(Bukkit.getWorld("SimulationRift")));
    // gameManager.addGameHolder("SimulationCrossfire-0", GameMap.SIMULATION_CROSSFIRE, new LocationFactory(Bukkit.getWorld("SimulationCrossfire")));
    // gameManager.addGameHolder("Debug-0", GameMap.DEBUG, new LocationFactory(Bukkit.getWorld("TestWorld")));
    // gameManager.addGameHolder("Heaven-0", GameMap.HEAVEN_WILL, new LocationFactory(Bukkit.getWorld("Heaven")));
    Thread.currentThread().setContextClassLoader(getClassLoader());
    ConfigurationSerialization.registerClass(PlayerSettings.class);
    getServer().getPluginManager().registerEvents(new WarlordsEvents(), this);
    getServer().getPluginManager().registerEvents(new MenuEventListener(this), this);
    getServer().getPluginManager().registerEvents(new PartyListener(), this);
    getServer().getPluginManager().registerEvents(new BotListener(), this);
    getServer().getPluginManager().registerEvents(new RecklessCharge(), this);
    getServer().getPluginManager().registerEvents(new FutureMessageManager(), this);
    new GameStartCommand().register(this);
    new GameTerminateCommand().register(this);
    new GameKillCommand().register(this);
    new GameListCommand().register(this);
    new MenuCommand().register(this);
    new ShoutCommand().register(this);
    new HotkeyModeCommand().register(this);
    new DebugCommand().register(this);
    new ClassCommand().register(this);
    new GetPlayersCommand().register(this);
    new TestCommand().register(this);
    new ParticleQualityCommand().register(this);
    new SpawnTestDummyCommand().register(this);
    new PartyCommand().register(this);
    new StreamCommand().register(this);
    new RecordAverageDamage().register(this);
    new ChatChannelCommand().register(this);
    new BotCommands().register(this);
    new LeaderboardCommand().register(this);
    new RecordGamesCommand().register(this);
    new GamesCommand().register(this);
    new SpectateCommand().register(this);
    new DebugModeCommand().register(this);
    new MyLocationCommand().register(this);
    new MessageCommand().register(this);
    new ExperienceCommand().register(this);
    new QueueCommand().register(this);
    new ImposterCommand().register(this);
    new LobbyCommand().register(this);
    new DiscordCommand().register(this);
    new PollCommand().register(this);
    new AchievementsCommand().register(this);
    new FindPlayer().register(this);
    updateHeads();
    readKeysConfig();
    readWeaponConfig();
    saveWeaponConfig();
    TimeZone.setDefault(TimeZone.getTimeZone("EST"));
    holographicDisplaysEnabled = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
    citizensEnabled = Bukkit.getPluginManager().isPluginEnabled("Citizens");
    Bukkit.getOnlinePlayers().forEach(player -> {
        playerScoreboards.put(player.getUniqueId(), new CustomScoreboard(player));
    });
    // connects to the database
    Warlords.newChain().async(DatabaseManager::init).execute();
    try {
        BotManager.connect();
    } catch (LoginException e) {
        e.printStackTrace();
    }
    ProtocolManager protocolManager;
    protocolManager = ProtocolLibrary.getProtocolManager();
    protocolManager.removePacketListeners(this);
    protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.HIGHEST, PacketType.Play.Server.WORLD_PARTICLES) {

        int counter = 0;

        @Override
        public void onPacketSending(PacketEvent event) {
            // Item packets (id: 0x29)
            if (event.getPacketType() == PacketType.Play.Server.WORLD_PARTICLES) {
                Player player = event.getPlayer();
                if (Warlords.hasPlayer(player)) {
                    if (counter++ % playerSettings.get(player.getUniqueId()).getParticleQuality().particleReduction == 0) {
                        event.setCancelled(true);
                    }
                }
            }
        }
    });
    protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.HIGHEST, PacketType.Play.Client.STEER_VEHICLE) {

        @Override
        public void onPacketReceiving(PacketEvent e) {
            if (e.getPacketType() == PacketType.Play.Client.STEER_VEHICLE) {
                if (e.getPacket().getHandle() instanceof PacketPlayInSteerVehicle) {
                    boolean dismount = e.getPacket().getBooleans().read(1);
                    Field f;
                    try {
                        f = PacketPlayInSteerVehicle.class.getDeclaredField("d");
                        f.setAccessible(true);
                        f.set(e.getPacket().getHandle(), false);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                    if (dismount && e.getPlayer().getVehicle() != null) {
                        e.getPlayer().getVehicle().remove();
                    }
                }
            }
        }
    });
    startMainLoop();
    getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[Warlords] Plugin is enabled");
    for (String command : this.getDescription().getCommands().keySet()) {
        if (getCommand(command).getExecutor() == this) {
            getServer().getConsoleSender().sendMessage(ChatColor.GOLD + "[Warlords] Warning, command " + command + " is specified in plugin.yml, but not defined in the plugins");
        }
    }
}
Also used : PartyCommand(com.ebicep.warlords.party.PartyCommand) BotCommands(com.ebicep.jda.BotCommands) PacketAdapter(com.comphenix.protocol.events.PacketAdapter) BotListener(com.ebicep.jda.BotListener) Player(org.bukkit.entity.Player) FireWorkEffectPlayer(com.ebicep.warlords.effects.FireWorkEffectPlayer) QueueCommand(com.ebicep.warlords.queuesystem.QueueCommand) PacketPlayInSteerVehicle(net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle) WarlordsEvents(com.ebicep.warlords.events.WarlordsEvents) ProtocolManager(com.comphenix.protocol.ProtocolManager) LoginException(javax.security.auth.login.LoginException) PartyListener(com.ebicep.warlords.party.PartyListener) Field(java.lang.reflect.Field) LeaderboardCommand(com.ebicep.warlords.database.leaderboards.LeaderboardCommand) PollCommand(com.ebicep.warlords.poll.PollCommand) FutureMessageManager(com.ebicep.warlords.database.FutureMessageManager) LoginException(javax.security.auth.login.LoginException) LocationFactory(com.ebicep.warlords.util.bukkit.LocationFactory) MenuEventListener(com.ebicep.warlords.menu.MenuEventListener) PacketEvent(com.comphenix.protocol.events.PacketEvent) StreamCommand(com.ebicep.warlords.party.StreamCommand)

Example 5 with PacketPlayInSteerVehicle

use of net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle 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)

Aggregations

Seat (me.legofreak107.vehicles.objects.Seat)6 Vehicle (me.legofreak107.vehicles.objects.Vehicle)6 PacketPlayInSteerVehicle (net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle)6 ArmorStand (org.bukkit.entity.ArmorStand)6 EntityArmorStand (net.minecraft.server.v1_12_R1.EntityArmorStand)5 Location (org.bukkit.Location)5 CraftArmorStand (org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand)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)2 PacketAdapter (com.comphenix.protocol.events.PacketAdapter)2 PacketEvent (com.comphenix.protocol.events.PacketEvent)2 Player (org.bukkit.entity.Player)2 BotCommands (com.ebicep.jda.BotCommands)1 BotListener (com.ebicep.jda.BotListener)1 FutureMessageManager (com.ebicep.warlords.database.FutureMessageManager)1 LeaderboardCommand (com.ebicep.warlords.database.leaderboards.LeaderboardCommand)1 FireWorkEffectPlayer (com.ebicep.warlords.effects.FireWorkEffectPlayer)1