@EventHandler public void onVehicleMove(VehicleMoveEvent event) { Vehicle vehicle = event.getVehicle(); if (vehicle.getPassengers().isEmpty()) return; List<LocalPlayer> playerPassengers = vehicle.getPassengers().stream().filter(ent -> ent instanceof Player).map(ent -> plugin.wrapPlayer((Player) ent)).collect(Collectors.toList()); if (playerPassengers.isEmpty()) { return; } World world = vehicle.getWorld(); ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world)); if (wcfg.useRegions) { // Did we move a block? if (Locations.isDifferentBlock(BukkitAdapter.adapt(event.getFrom()), BukkitAdapter.adapt(event.getTo()))) { for (LocalPlayer player : playerPassengers) { if (null != WorldGuard.getInstance().getPlatform().getSessionManager().get(player) .testMoveTo(player, BukkitAdapter.adapt(event.getTo()), MoveType.RIDE)) { vehicle.setVelocity(new Vector(0, 0, 0)); vehicle.teleport(event.getFrom()); return; } } } } } }
@EventHandler(priority = EventPriority.LOWEST) public void onVehicleMove(VehicleMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); UUID id = event.getVehicle().getUniqueId(); for(Integer threshold : VehicleEvents.GetThresholdList()) { Map<UUID, MCLocation> lastLocations = VehicleEvents.GetLastLocations(threshold); if(!lastLocations.containsKey(id)) { lastLocations.put(id, new BukkitMCLocation(from)); continue; } MCLocation last = lastLocations.get(id); if(!to.getWorld().getName().equals(last.getWorld().getName())) { lastLocations.put(id, new BukkitMCLocation(to)); continue; } BukkitMCLocation movedTo = new BukkitMCLocation(to); if(last.distance(movedTo) > threshold) { BukkitMCVehicleMoveEvent vme = new BukkitMCVehicleMoveEvent(event, threshold, last); EventUtils.TriggerListener(Driver.VEHICLE_MOVE, "vehicle_move", vme); if(!vme.isCancelled()) { lastLocations.put(id, movedTo); } else { event.getVehicle().setVelocity(new Vector(0, 0, 0)); event.getVehicle().teleport(from); } } } }
if (((Minecart) this.getVehicle()).getMaxSpeed() == 0) ((Minecart) this.getVehicle()).setMaxSpeed(0.4d); this.getVehicle().setVelocity((new Vector(this.getCardinal().getModX(), this.getCardinal().getModY(), this.getCardinal().getModZ())).multiply(ByteCart.myPlugin.getConfig().getDouble("BC7001.startvelocity"))); this.getVehicle().setVelocity(new Vector(0,0,0)); ((Minecart) this.getVehicle()).setMaxSpeed(0d); ByteCart.myPlugin.getIsTrainManager().getMap().remove(getBlock().getRelative(getCardinal().getOppositeFace(), 2).getLocation());