use of me.legofreak107.vehicles.events.PlayerJoin 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);
}
Aggregations