Search in sources :

Example 1 with PlayerInteract

use of me.legofreak107.vehicles.events.PlayerInteract 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

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 PlayerInteract (me.legofreak107.vehicles.events.PlayerInteract)1 PlayerInteractAtEntity (me.legofreak107.vehicles.events.PlayerInteractAtEntity)1 PlayerJoin (me.legofreak107.vehicles.events.PlayerJoin)1 PlayerQuit (me.legofreak107.vehicles.events.PlayerQuit)1 SignChange (me.legofreak107.vehicles.events.SignChange)1 VehicleExit (me.legofreak107.vehicles.events.VehicleExit)1 Seat (me.legofreak107.vehicles.objects.Seat)1 VPPlayer (me.legofreak107.vehicles.objects.VPPlayer)1 Vehicle (me.legofreak107.vehicles.objects.Vehicle)1 EntityArmorStand (net.minecraft.server.v1_12_R1.EntityArmorStand)1 PacketPlayInSteerVehicle (net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle)1