Search in sources :

Example 16 with Vehicle

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

the class EntityDamage method onDamage.

@EventHandler
public void onDamage(EntityDamageByEntityEvent e) {
    if (e.getEntity() instanceof ArmorStand && plugin.seatInfo.containsKey(e.getEntity())) {
        Vehicle v = plugin.vehicleInfo.get(plugin.seatInfo.get(e.getEntity()).parent);
        e.setCancelled(true);
        v.damage(10);
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) ArmorStand(org.bukkit.entity.ArmorStand) EventHandler(org.bukkit.event.EventHandler)

Example 17 with Vehicle

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

the class SaveAndLoad method loadVehicles.

public Vehicle loadVehicles(String name) {
    Vehicle v = new Vehicle();
    ItemStack item = new ItemStack(Material.AIR, 1, (Short) Short.parseShort(plugin.getConfig().get("Vehicles." + name + ".skin.data").toString()));
    item.setTypeId((int) plugin.getConfig().get("Vehicles." + name + ".skin.material"));
    item.getItemMeta().setUnbreakable(plugin.getConfig().getBoolean("Vehicles." + name + ".skin.unbreakable"));
    v.skin = item;
    v.name = name;
    v.fspeed = Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".forwardspeed").toString());
    v.bspeed = Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".backwardspeed").toString());
    v.acceleration = Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".acceleration").toString());
    v.maxFuel = Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".maxFuel").toString());
    v.fualUsage = Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".fuelUsage").toString());
    v.turnSpeed = Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".turnSpeed").toString());
    v.type = plugin.getType((String) plugin.getConfig().get("Vehicles." + name + ".type"));
    v.locked = false;
    v.price = plugin.getConfig().getInt("Vehicles." + name + ".price");
    v.maxHealth = plugin.getConfig().getInt("Vehicles." + name + ".maxHealth");
    Fuel f = plugin.getFuel((String) plugin.getConfig().get("Vehicles." + name + ".fuelType"));
    if (f != null) {
        v.fuelType = f;
    } else {
        Bukkit.broadcastMessage("Error loading fuel!");
    }
    Inventory inv = Bukkit.createInventory(null, plugin.getConfig().getInt("Vehicles." + name + ".trunk.size"), "�2" + v.name);
    v.inv = inv;
    ArrayList<Seat> si = new ArrayList<Seat>();
    for (int i = 0; i < plugin.getConfig().getInt("Vehicles." + name + ".seats"); i++) {
        Seat s = new Seat();
        s.offset = new Vector(Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".seat" + i + ".offsetX").toString()), Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".seat" + i + ".offsetY").toString()), Float.parseFloat(plugin.getConfig().get("Vehicles." + name + ".seat" + i + ".offsetZ").toString()));
        s.steer = (Boolean) plugin.getConfig().get("Vehicles." + name + ".seat" + i + ".steer");
        si.add(s);
    }
    v.seats = si;
    return v;
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) Seat(me.legofreak107.vehicles.objects.Seat) Fuel(me.legofreak107.vehicles.objects.Fuel) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Inventory(org.bukkit.inventory.Inventory)

Example 18 with Vehicle

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

the class ChunkUnload method onChunkUnload.

@EventHandler
public void onChunkUnload(ChunkUnloadEvent e) {
    for (Entity en : e.getChunk().getEntities()) {
        if (en instanceof ArmorStand) {
            if (plugin.vehicleInfo.containsKey(en)) {
                Vehicle v = plugin.vehicleInfo.get(en);
                v.p.p.getInventory().removeItem(plugin.keys.get(v));
                v.remove();
                v.holder.remove();
                v.holder = null;
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) Entity(org.bukkit.entity.Entity) ArmorStand(org.bukkit.entity.ArmorStand) EventHandler(org.bukkit.event.EventHandler)

Example 19 with Vehicle

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

the class EntityDismount method onLeave.

@EventHandler
public void onLeave(EntityDismountEvent e) {
    if (e.getDismounted() instanceof ArmorStand) {
        if (plugin.seatInfo.containsKey(e)) {
            if (e.getDismounted().getLocation().getBlock().getType() == Material.STATIONARY_WATER)
                e.getDismounted().addPassenger(e.getEntity());
        }
    }
    if (plugin.seatInfo.containsKey(e.getDismounted())) {
        Vehicle v = plugin.vehicleInfo.get(plugin.seatInfo.get(e.getDismounted()).parent);
        Seat s = plugin.seatInfo.get(e.getDismounted());
        if (v.locked) {
            if (((Player) e.getEntity()).getInventory().getItemInMainHand().hasItemMeta() && ((Player) e.getEntity()).getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("key")) {
                String vpname = ((Player) e.getEntity()).getInventory().getItemInMainHand().getItemMeta().getDisplayName().replace("�2", "").replace(" key", "");
                if (plugin.isValidVehicle(vpname)) {
                    if (v.name.equalsIgnoreCase(vpname) && v.owner.contains(e.getEntity().getName())) {
                    } else {
                        s.seat.addPassenger(e.getEntity());
                    }
                } else {
                    s.seat.addPassenger(e.getEntity());
                }
            } else {
                s.seat.addPassenger(e.getEntity());
            }
        } else {
            if (v.fuelbar != null && v.fuelbar.getPlayers().contains(e.getEntity())) {
                v.fuelbar.removePlayer((Player) e.getEntity());
                v.fuelbar.removeAll();
                v.fuelbar.setVisible(false);
            }
        }
    }
}
Also used : Vehicle(me.legofreak107.vehicles.objects.Vehicle) Seat(me.legofreak107.vehicles.objects.Seat) ArmorStand(org.bukkit.entity.ArmorStand) EventHandler(org.bukkit.event.EventHandler)

Aggregations

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